Example #1
0
// Try to decode morse messages and data frames.
// This should really be done asynchronously by the telemetry pipeline.
func DecodeBlobs(
	satellite_id string, timestamp int64, blobs []pb.Contact_Blob) (
	result []*pb.Contact_Blob, err error) {

	var datums []pb.TelemetryDatum
	var new_frames [][]byte
	for _, b := range blobs {
		if b.Format == nil {
			log.Printf("Missing blob format.")
			continue
		}

		if *b.Format == pb.Contact_Blob_FREEFORM {
			d, f := telemetry.DecodeFreeform(
				satellite_id, b.InlineData, timestamp)
			datums = append(datums, d...)
			new_frames = append(new_frames, f...)
		} else if *b.Format == pb.Contact_Blob_MORSE {
			d, _ := telemetry.DecodeMorse(
				satellite_id,
				(string)(b.InlineData),
				timestamp)
			datums = append(datums, d...)
		} else if *b.Format == pb.Contact_Blob_FRAME {
			d, _ := telemetry.DecodeFrame(
				satellite_id, b.InlineData, timestamp)
			datums = append(datums, d...)
		} else {
			log.Printf("Unknown blob format: %v", *b.Format)
			return nil, NewPopulateContactError(
				http.StatusBadRequest, "Unknown format.")
		}
	}

	for _, f := range new_frames {
		b := &pb.Contact_Blob{}
		b.Format = pb.Contact_Blob_FRAME.Enum()
		b.InlineData = []byte(f)
		result = append(result, b)
	}

	for _, d := range datums {
		b := &pb.Contact_Blob{}
		b.Format = pb.Contact_Blob_DATUM.Enum()
		b.Datum = &pb.TelemetryDatum{}
		*b.Datum = d
		result = append(result, b)
	}

	return result, nil
}
Example #2
0
func decodeHexFrame(satellite_id, data string) {
	frame, err := hex.DecodeString(data)
	if err != nil {
		fmt.Printf("Not a hex frame: %s\n", err.Error())
		return
	}

	pl, err := telemetry.DecodeFrame(satellite_id, frame, 0)
	if err != nil {
		fmt.Printf("DecodeFrame error: %s\n", err.Error())
		return
	}
	for _, p := range pl {
		fmt.Printf("%s\n", proto.MarshalTextString(&p))
	}
}