func decodeMorse(satellite_id, data string) { pl, err := telemetry.DecodeMorse(satellite_id, data, 0) if err != nil { fmt.Printf("DecodeMorse error: %s\n", err.Error()) return } for _, p := range pl { fmt.Printf("%s\n", proto.MarshalTextString(&p)) } }
// 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 }