dsd-fme icon indicating copy to clipboard operation
dsd-fme copied to clipboard

M17 text messages support

Open sp5wwp opened this issue 11 months ago • 40 comments

Is dsd-fme capable of decoding text messages? There's a need for working replacement for SDRAngel's decoder, as it's heavily bugged.

sp5wwp avatar Mar 07 '24 10:03 sp5wwp

I don't have support for it yet, but I'll work it in there eventually. When you say text messages, are you referring to the type that is embedded in the LSF Meta field, or longer SMS messages embedded in a packet stream? If the text is just UTF-8, it should be simple enough, especially for the Stream Meta. As it currently stands, I don't have support yet for Packet Mode decoding.

Honestly, I can understand the bugged portions for the time being, as it stands, I still cannot successfully decode the single LSF frame that comes in at the start of transmission. I'm going to need to probably switch out to a better viterbi decoder (a.k.a., steal yours) and there is probably some underlying demodulation and filtering issues on my end that prevent great symbol conversion. Usually, its fine once it gets into stream mode, and I put together all the LSF chunks from the stream, but that initial LSF is still broken on my end, so no packet mode for the time being.

Also, in packet mode, is the SMS just purely UTF-8 text?

Screenshot from 2024-03-07 07-44-20

lwvmobile avatar Mar 07 '24 12:03 lwvmobile

Longer SMS messages used with packet mode. Yes, the encoding is UTF-8.

Honestly, I can understand the bugged portions for the time being, as it stands, I still cannot successfully decode the single LSF frame that comes in at the start of transmission.

I can can reliably decode every LSF. Expand the LSF syncword that you are looking for with a few (8) symbols from the preamble. That way you reduce false positives and greatly improve the search. See this code.

SDRangel has its own bugs, completely unrelated to the M17 protocol.

sp5wwp avatar Mar 07 '24 13:03 sp5wwp

Okay, thanks, I'll look into your code when I have and see what all can be done on my end to improve false sync patterns. I think I may also have a secondary issue with LSF in general though, even when fed back internally, I can't get a clean decode of it, I could have a coding issue in regards to the puncture, or similar, or just my poor convolutional decoder can't handle the number of punctures. I'll have to revisit that one as well at some point and see what all is broken, troubleshoot it step by step again and see if I can assign a blame to or get a clearer understanding of why the LSF frame decoding is broken.

On a separate note, what do you use to playback your .rrc files usually? I've got code to generate .wav files of M17 signal now, so I'd like to test my output on something known to work well with the .rrc files as a base for comparison for debugging/troubleshooting.

lwvmobile avatar Mar 07 '24 19:03 lwvmobile

GNU Radio. Try using this zipped .grc: M17_tx_plutosdr.zip

sp5wwp avatar Mar 08 '24 10:03 sp5wwp

Okay, thanks, I'll have to fool around with that and M17 Implementations when I get a chance, actually go through all the steps and learn to use it.

I do have a question, though, maybe its just me, but was testing your viterbi code in dsd-fme, and was wondering, does it perform better (less chance of error) if there isn't a long zero fill, like with the zero fill meta field if its not in use? I've noticed that more often than not, I tend to get bad LSF decodes when meta is zero fill, but using a non-zero fill for it and using lsf_es = 3 for the reserved, it seems to consistently decode the beginning LSF frame.

Just was wondering if that was just me, or if there is something in viterbi decoding that works better with non-zero fill?

lwvmobile avatar Mar 08 '24 16:03 lwvmobile

Shouldn't matter since M17 applies bit interleaving and randomization before sending anything over RF. Contents of the META field shouldn't affect the decoder either.

sp5wwp avatar Mar 08 '24 16:03 sp5wwp

Ah, okay, it may just be an issue in my own implementation. I think I found that it may actually clear up if I insert some 'dead air' in the beginning of my created wav files first before reading them back in instead of jumping straight to a preamble and LSF.

lwvmobile avatar Mar 08 '24 16:03 lwvmobile

Consider using libm17. Take a look here for details. Slice, randomize, reorder and decode.

sp5wwp avatar Mar 08 '24 16:03 sp5wwp

I may do that at some point. Honestly, I might would be better to do so in a new project, instead of trying to piggy back off of DSD-FME. The original source code of dsd really wasn't well geared to much outside of P25, and honestly, only handling of P25 and DMR is pretty decent on it, other formats perform to varying levels of success, the demodulator just isn't great at short sync patters, and also, I'd have to rip the entire thing out and re-write it to just get a good buffering system in place in order to just buffer samples and symbols as they arrive and make better decisions based on that, and to me, that definitely screams 'might as well start from scratch' territory, which I do want to do at some point, I was just writing a lot of the M17 stuff as a fun side project to see how it would go.

Another thing I've considered is just to fork one of your projects and just add the voice support onto it, see how that works. Might not be all that hard to just tack on codec2 and the pa_simple api onto M17_Implementations, and play around with that some.

lwvmobile avatar Mar 08 '24 18:03 lwvmobile

hello everyone, who can explain to me what M17 is, and help me with some raw files? Thank you

romanremus avatar Mar 09 '24 03:03 romanremus

hello everyone, who can explain to me what M17 is, and help me with some raw files? Thank you

M17 is an open source ham radio standard being developed by sp5wwp and many others.

https://m17project.org/

Pull the latest source code and try it out for yourself, just run

dsd-fme -fZ -6 m17wav.wav

and it'll encode your voice into M17 stream format. if you have your microphone selected as input (adjust gain appropriately) and you can also replay the wav files you are making by feeding it back in at a later time with.

dsd-fme -fz -i m17wav.wav

Keep in mind, a lot of the encoder/decoder stuff for M17 is a work in progress, and also, haven't really thoroughly tested it in Cygwin yet, except to initially see if it functioned, which seems to decently enough.

lwvmobile avatar Mar 10 '24 22:03 lwvmobile

Well, may need to scratch that, just went and tested it in Cygwin, having issues that'll need to be investigated at a later time.

lwvmobile avatar Mar 10 '24 22:03 lwvmobile

The suffix is WWP :)

sp5wwp avatar Mar 10 '24 22:03 sp5wwp

The suffix is WWP :)

Yeah, my fingers aren't working today, and neither is my brain.

lwvmobile avatar Mar 10 '24 22:03 lwvmobile

Well, may need to scratch that, just went and tested it in Cygwin, having issues that'll need to be investigated at a later time.

Okay, scratch that scratch, I found the bug, the sync test pattern array was not initialized, and compiling in Cygwin hates it when things aren't initialized, so it wasn't playing nice. So much frustration from not initializing values.

Anyways, you should be able to pull and build in Cygwin now and run the steps as mentioned above, and it'll work for you, Remus.

lwvmobile avatar Mar 11 '24 00:03 lwvmobile

@sp5wwp Can you check my homework so far, and let me know if this is the proper format for PKT SMS messages.

Encoder:

Build Version: AW 2024-61-gd738eee 
MBElib Version: 1.3.4
CODEC2 Support Enabled
Writing raw audio to file m17pkt.wav
Audio In/Out Device: pulse
 STRLEN: 773
 TEXT: When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation. We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness.--That to secure these rights, Governments are instituted among Men, deriving their just powers from the consent of the governed, --That whenever any Form of
 BLOCK: 31; PAD: 00; MOD: 00; K: 6200; PTR: 0773; CRC: FDF6
 M17 Packet      FULL: 05005768656E20696E2074686520436F75727365206F662068
                       756D616E206576656E74732C206974206265636F6D6573206E
                       656365737361727920666F72206F6E652070656F706C652074
                       6F20646973736F6C76652074686520706F6C69746963616C20
                       62616E6473207768696368206861766520636F6E6E65637465
                       64207468656D207769746820616E6F746865722C20616E6420
                       746F20617373756D6520616D6F6E672074686520706F776572
                       73206F66207468652065617274682C20746865207365706172
                       61746520616E6420657175616C2073746174696F6E20746F20
                       776869636820746865204C617773206F66204E617475726520
                       616E64206F66204E6174757265277320476F6420656E746974
                       6C65207468656D2C206120646563656E742072657370656374
                       20746F20746865206F70696E696F6E73206F66206D616E6B69
                       6E64207265717569726573207468617420746865792073686F
                       756C64206465636C6172652074686520636175736573207768
                       69636820696D70656C207468656D20746F2074686520736570
                       61726174696F6E2E20576520686F6C64207468657365207472
                       7574687320746F2062652073656C662D65766964656E742C20
                       7468617420616C6C206D656E20617265206372656174656420
                       657175616C2C207468617420746865792061726520656E646F
                       7765642062792074686569722043726561746F722077697468
                       206365727461696E20756E616C69656E61626C652052696768
                       74732C207468617420616D6F6E672074686573652061726520
                       4C6966652C204C69626572747920616E642074686520707572
                       73756974206F662048617070696E6573732E2D2D5468617420
                       746F20736563757265207468657365207269676874732C2047
                       6F7665726E6D656E74732061726520696E7374697475746564
                       20616D6F6E67204D656E2C206465726976696E672074686569
                       72206A75737420706F776572732066726F6D2074686520636F
                       6E73656E74206F662074686520676F7665726E65642C202D2D
                       54686174207768656E6576657220616E7920466F726D20FDF6
 M17 LSF    (ENCODER): 
 CAN: 7 DST: BROADCAST SRC: DSD-FME   Data
 M17 Packet (ENCODER): 05005768656E20696E2074686520436F75727365206F66206800
 M17 Packet (ENCODER): 756D616E206576656E74732C206974206265636F6D6573206E04
 M17 Packet (ENCODER): 656365737361727920666F72206F6E652070656F706C65207408
 M17 Packet (ENCODER): 6F20646973736F6C76652074686520706F6C69746963616C200C
 M17 Packet (ENCODER): 62616E6473207768696368206861766520636F6E6E6563746510
 M17 Packet (ENCODER): 64207468656D207769746820616E6F746865722C20616E642014
 M17 Packet (ENCODER): 746F20617373756D6520616D6F6E672074686520706F77657218
 M17 Packet (ENCODER): 73206F66207468652065617274682C207468652073657061721C
 M17 Packet (ENCODER): 61746520616E6420657175616C2073746174696F6E20746F2020
 M17 Packet (ENCODER): 776869636820746865204C617773206F66204E61747572652024
 M17 Packet (ENCODER): 616E64206F66204E6174757265277320476F6420656E74697428
 M17 Packet (ENCODER): 6C65207468656D2C206120646563656E7420726573706563742C
 M17 Packet (ENCODER): 20746F20746865206F70696E696F6E73206F66206D616E6B6930
 M17 Packet (ENCODER): 6E64207265717569726573207468617420746865792073686F34
 M17 Packet (ENCODER): 756C64206465636C617265207468652063617573657320776838
 M17 Packet (ENCODER): 69636820696D70656C207468656D20746F20746865207365703C
 M17 Packet (ENCODER): 61726174696F6E2E20576520686F6C6420746865736520747240
 M17 Packet (ENCODER): 7574687320746F2062652073656C662D65766964656E742C2044
 M17 Packet (ENCODER): 7468617420616C6C206D656E2061726520637265617465642048
 M17 Packet (ENCODER): 657175616C2C207468617420746865792061726520656E646F4C
 M17 Packet (ENCODER): 7765642062792074686569722043726561746F72207769746850
 M17 Packet (ENCODER): 206365727461696E20756E616C69656E61626C65205269676854
 M17 Packet (ENCODER): 74732C207468617420616D6F6E67207468657365206172652058
 M17 Packet (ENCODER): 4C6966652C204C69626572747920616E6420746865207075725C
 M17 Packet (ENCODER): 73756974206F662048617070696E6573732E2D2D546861742060
 M17 Packet (ENCODER): 746F20736563757265207468657365207269676874732C204764
 M17 Packet (ENCODER): 6F7665726E6D656E74732061726520696E737469747574656468
 M17 Packet (ENCODER): 20616D6F6E67204D656E2C206465726976696E6720746865696C
 M17 Packet (ENCODER): 72206A75737420706F776572732066726F6D2074686520636F70
 M17 Packet (ENCODER): 6E73656E74206F662074686520676F7665726E65642C202D2D74
 M17 Packet (ENCODER): 54686174207768656E6576657220616E7920466F726D20FDF6E4
Total audio errors: 0
Total header errors: 0
Total irrecoverable header errors: 0
Exiting.

Decoder:

Build Version: AW 2024-61-gd738eee 
MBElib Version: 1.3.4
CODEC2 Support Enabled
Notice: M17 cannot autodetect polarity. 
 Use -xz option if Inverted Signal expected.
Decoding only M17 frames.
Logging Frame Payload to console
Audio In Device: m17pkt.wav
21:02:48 Sync: +M17 PREAMBLE 
21:02:48 Sync: +M17 PREAMBLE 
21:02:48 Sync: +M17 PREAMBLE 
21:02:48 Sync: +M17 PREAMBLE 
21:02:48 Sync: +M17 PREAMBLE 
21:02:48 Sync: +M17 PREAMBLE 
21:02:48 Sync: +M17 PREAMBLE 
21:02:48 Sync: +M17 PREAMBLE 
21:02:48 Sync: +M17 PREAMBLE 
21:02:48 Sync: +M17 PREAMBLE 
21:02:48 Sync: +M17 PREAMBLE 
21:02:48 Sync: +M17 PREAMBLE 
21:02:48 Sync: +M17 LSF 
 CAN: 7 DST: BROADCAST SRC: DSD-FME   Data
 LSF: [7A][0B][65][F1][1A][92][00][05][15][1B][1D][FC][03][82][00]
      [00][00][00][00][00][00][00][00][00][00][00][00][00][66][9F]
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 05 00 57 68 65 6E 20 69 6E 20 74 68 65 20 43 6F 75 72 73 65 20 6F 66 20 68 00 CNT: 00; CT: 00; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 75 6D 61 6E 20 65 76 65 6E 74 73 2C 20 69 74 20 62 65 63 6F 6D 65 73 20 6E 04 CNT: 01; CT: 01; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 65 63 65 73 73 61 72 79 20 66 6F 72 20 6F 6E 65 20 70 65 6F 70 6C 65 20 74 08 CNT: 02; CT: 02; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 6F 20 64 69 73 73 6F 6C 76 65 20 74 68 65 20 70 6F 6C 69 74 69 63 61 6C 20 0C CNT: 03; CT: 03; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 62 61 6E 64 73 20 77 68 69 63 68 20 68 61 76 65 20 63 6F 6E 6E 65 63 74 65 10 CNT: 04; CT: 04; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 64 20 74 68 65 6D 20 77 69 74 68 20 61 6E 6F 74 68 65 72 2C 20 61 6E 64 20 14 CNT: 05; CT: 05; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 74 6F 20 61 73 73 75 6D 65 20 61 6D 6F 6E 67 20 74 68 65 20 70 6F 77 65 72 18 CNT: 06; CT: 06; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 73 20 6F 66 20 74 68 65 20 65 61 72 74 68 2C 20 74 68 65 20 73 65 70 61 72 1C CNT: 07; CT: 07; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 61 74 65 20 61 6E 64 20 65 71 75 61 6C 20 73 74 61 74 69 6F 6E 20 74 6F 20 20 CNT: 08; CT: 08; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 77 68 69 63 68 20 74 68 65 20 4C 61 77 73 20 6F 66 20 4E 61 74 75 72 65 20 24 CNT: 09; CT: 09; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 61 6E 64 20 6F 66 20 4E 61 74 75 72 65 27 73 20 47 6F 64 20 65 6E 74 69 74 28 CNT: 10; CT: 10; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 6C 65 20 74 68 65 6D 2C 20 61 20 64 65 63 65 6E 74 20 72 65 73 70 65 63 74 2C CNT: 11; CT: 11; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 20 74 6F 20 74 68 65 20 6F 70 69 6E 69 6F 6E 73 20 6F 66 20 6D 61 6E 6B 69 30 CNT: 12; CT: 12; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 6E 64 20 72 65 71 75 69 72 65 73 20 74 68 61 74 20 74 68 65 79 20 73 68 6F 34 CNT: 13; CT: 13; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 75 6C 64 20 64 65 63 6C 61 72 65 20 74 68 65 20 63 61 75 73 65 73 20 77 68 38 CNT: 14; CT: 14; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 69 63 68 20 69 6D 70 65 6C 20 74 68 65 6D 20 74 6F 20 74 68 65 20 73 65 70 3C CNT: 15; CT: 15; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 61 72 61 74 69 6F 6E 2E 20 57 65 20 68 6F 6C 64 20 74 68 65 73 65 20 74 72 40 CNT: 16; CT: 16; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 75 74 68 73 20 74 6F 20 62 65 20 73 65 6C 66 2D 65 76 69 64 65 6E 74 2C 20 44 CNT: 17; CT: 17; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 74 68 61 74 20 61 6C 6C 20 6D 65 6E 20 61 72 65 20 63 72 65 61 74 65 64 20 48 CNT: 18; CT: 18; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 65 71 75 61 6C 2C 20 74 68 61 74 20 74 68 65 79 20 61 72 65 20 65 6E 64 6F 4C CNT: 19; CT: 19; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 77 65 64 20 62 79 20 74 68 65 69 72 20 43 72 65 61 74 6F 72 20 77 69 74 68 50 CNT: 20; CT: 20; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 20 63 65 72 74 61 69 6E 20 75 6E 61 6C 69 65 6E 61 62 6C 65 20 52 69 67 68 54 CNT: 21; CT: 21; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 74 73 2C 20 74 68 61 74 20 61 6D 6F 6E 67 20 74 68 65 73 65 20 61 72 65 20 58 CNT: 22; CT: 22; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 4C 69 66 65 2C 20 4C 69 62 65 72 74 79 20 61 6E 64 20 74 68 65 20 70 75 72 5C CNT: 23; CT: 23; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 73 75 69 74 20 6F 66 20 48 61 70 70 69 6E 65 73 73 2E 2D 2D 54 68 61 74 20 60 CNT: 24; CT: 24; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 74 6F 20 73 65 63 75 72 65 20 74 68 65 73 65 20 72 69 67 68 74 73 2C 20 47 64 CNT: 25; CT: 25; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 6F 76 65 72 6E 6D 65 6E 74 73 20 61 72 65 20 69 6E 73 74 69 74 75 74 65 64 68 CNT: 26; CT: 26; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 20 61 6D 6F 6E 67 20 4D 65 6E 2C 20 64 65 72 69 76 69 6E 67 20 74 68 65 69 6C CNT: 27; CT: 27; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 72 20 6A 75 73 74 20 70 6F 77 65 72 73 20 66 72 6F 6D 20 74 68 65 20 63 6F 70 CNT: 28; CT: 28; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 6E 73 65 6E 74 20 6F 66 20 74 68 65 20 67 6F 76 65 72 6E 65 64 2C 20 2D 2D 74 CNT: 29; CT: 29; EOT: 0;
21:02:48 Sync: +M17 PKT 
 pkt_packed: 
 54 68 61 74 20 77 68 65 6E 65 76 65 72 20 61 6E 79 20 46 6F 72 6D 20 FD F6 E4 CNT: 31; CB: 25; EOT: 1; Protocol: SMS;
 TEXT: When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation. We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness.--That to secure these rights, Governments are instituted among Men, deriving their just powers from the consent of the governed, --That whenever any Form 
 pkt_full: 05 00 57 68 65 6E 20 69 6E 20 74 68 65 20 43 6F 75 72 73 65 20 6F 66 20 68
           75 6D 61 6E 20 65 76 65 6E 74 73 2C 20 69 74 20 62 65 63 6F 6D 65 73 20 6E
           65 63 65 73 73 61 72 79 20 66 6F 72 20 6F 6E 65 20 70 65 6F 70 6C 65 20 74
           6F 20 64 69 73 73 6F 6C 76 65 20 74 68 65 20 70 6F 6C 69 74 69 63 61 6C 20
           62 61 6E 64 73 20 77 68 69 63 68 20 68 61 76 65 20 63 6F 6E 6E 65 63 74 65
           64 20 74 68 65 6D 20 77 69 74 68 20 61 6E 6F 74 68 65 72 2C 20 61 6E 64 20
           74 6F 20 61 73 73 75 6D 65 20 61 6D 6F 6E 67 20 74 68 65 20 70 6F 77 65 72
           73 20 6F 66 20 74 68 65 20 65 61 72 74 68 2C 20 74 68 65 20 73 65 70 61 72
           61 74 65 20 61 6E 64 20 65 71 75 61 6C 20 73 74 61 74 69 6F 6E 20 74 6F 20
           77 68 69 63 68 20 74 68 65 20 4C 61 77 73 20 6F 66 20 4E 61 74 75 72 65 20
           61 6E 64 20 6F 66 20 4E 61 74 75 72 65 27 73 20 47 6F 64 20 65 6E 74 69 74
           6C 65 20 74 68 65 6D 2C 20 61 20 64 65 63 65 6E 74 20 72 65 73 70 65 63 74
           20 74 6F 20 74 68 65 20 6F 70 69 6E 69 6F 6E 73 20 6F 66 20 6D 61 6E 6B 69
           6E 64 20 72 65 71 75 69 72 65 73 20 74 68 61 74 20 74 68 65 79 20 73 68 6F
           75 6C 64 20 64 65 63 6C 61 72 65 20 74 68 65 20 63 61 75 73 65 73 20 77 68
           69 63 68 20 69 6D 70 65 6C 20 74 68 65 6D 20 74 6F 20 74 68 65 20 73 65 70
           61 72 61 74 69 6F 6E 2E 20 57 65 20 68 6F 6C 64 20 74 68 65 73 65 20 74 72
           75 74 68 73 20 74 6F 20 62 65 20 73 65 6C 66 2D 65 76 69 64 65 6E 74 2C 20
           74 68 61 74 20 61 6C 6C 20 6D 65 6E 20 61 72 65 20 63 72 65 61 74 65 64 20
           65 71 75 61 6C 2C 20 74 68 61 74 20 74 68 65 79 20 61 72 65 20 65 6E 64 6F
           77 65 64 20 62 79 20 74 68 65 69 72 20 43 72 65 61 74 6F 72 20 77 69 74 68
           20 63 65 72 74 61 69 6E 20 75 6E 61 6C 69 65 6E 61 62 6C 65 20 52 69 67 68
           74 73 2C 20 74 68 61 74 20 61 6D 6F 6E 67 20 74 68 65 73 65 20 61 72 65 20
           4C 69 66 65 2C 20 4C 69 62 65 72 74 79 20 61 6E 64 20 74 68 65 20 70 75 72
           73 75 69 74 20 6F 66 20 48 61 70 70 69 6E 65 73 73 2E 2D 2D 54 68 61 74 20
           74 6F 20 73 65 63 75 72 65 20 74 68 65 73 65 20 72 69 67 68 74 73 2C 20 47
           6F 76 65 72 6E 6D 65 6E 74 73 20 61 72 65 20 69 6E 73 74 69 74 75 74 65 64
           20 61 6D 6F 6E 67 20 4D 65 6E 2C 20 64 65 72 69 76 69 6E 67 20 74 68 65 69
           72 20 6A 75 73 74 20 70 6F 77 65 72 73 20 66 72 6F 6D 20 74 68 65 20 63 6F
           6E 73 65 6E 74 20 6F 66 20 74 68 65 20 67 6F 76 65 72 6E 65 64 2C 20 2D 2D
           54 68 61 74 20 77 68 65 6E 65 76 65 72 20 61 6E 79 20 46 6F 72 6D 20 FD F6
Sync: no sync

End of m17pkt.wav

Total audio errors: 0
Total header errors: 0
Total irrecoverable header errors: 0
Exiting.

lwvmobile avatar Mar 11 '24 01:03 lwvmobile

CRC mismatch. Probable cause: you encode DST: BROADCAST into 0x7A0B65F11A92 instead of 0xFFFFFFFFFFFF. It is a special destination address that shouldn't be encoded 'as is'.

I'm getting this:

Data CRC: 6A1B
LSF CRC: F126

I'll dump the data later and see where the difference is.

sp5wwp avatar Mar 11 '24 07:03 sp5wwp

You seem to be using 2-byte data type identifier 0x0500, when it should be 1-byte for SMS - 0x05. The 0x00 termination should come after the string - I can't see that in your payload. CRC calculation is based on the data alone (with the trailing null), make sure you don't include the type indicator in it.

sp5wwp avatar Mar 11 '24 08:03 sp5wwp

Okay, thanks, I'll make some revisions and update you when I think I have those issues you mentioned resolved.

lwvmobile avatar Mar 11 '24 09:03 lwvmobile

@romanremus , please be sure to send any DMR or other related issues to their appropriate issue, or create a new one if there isn't one available. Please don't randomly reply to email messages from this issue about other issues and requests not regarding M17. Thanks. There are already two open issues regarding DMR messages, so add your request to one of those.

lwvmobile avatar Mar 11 '24 12:03 lwvmobile

Okay @sp5wwp I've made a few revisions if you want to check again.

Encoding:

Build Version: AW 2024-63-g051a65f 
MBElib Version: 1.3.4
CODEC2 Support Enabled
Writing raw audio to file m17pkt.wav
Logging Frame Payload to console
Audio In/Out Device: pulse
 STRLEN: 445; MLEN: 0;
 SMS:
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
      tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim ve
      niam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea c
      ommodo consequat. Duis aute irure dolor in reprehenderit in voluptate v
      elit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaec
      at cupidatat non proident, sunt in culpa qui officia deserunt mollit an
      im id est laborum.
 BLOCK: 18; PAD: 02; K: 3568; PTR: 0446; CRC: 7441
 M17 Packet      FULL: 054C6F72656D20697073756D20646F6C6F722073697420616D
                       65742C20636F6E73656374657475722061646970697363696E
                       6720656C69742C2073656420646F20656975736D6F64207465
                       6D706F7220696E6369646964756E74207574206C61626F7265
                       20657420646F6C6F7265206D61676E6120616C697175612E20
                       557420656E696D206164206D696E696D2076656E69616D2C20
                       71756973206E6F737472756420657865726369746174696F6E
                       20756C6C616D636F206C61626F726973206E69736920757420
                       616C697175697020657820656120636F6D6D6F646F20636F6E
                       7365717561742E204475697320617574652069727572652064
                       6F6C6F7220696E20726570726568656E646572697420696E20
                       766F6C7570746174652076656C697420657373652063696C6C
                       756D20646F6C6F726520657520667567696174206E756C6C61
                       2070617269617475722E204578636570746575722073696E74
                       206F6363616563617420637570696461746174206E6F6E2070
                       726F6964656E742C2073756E7420696E2063756C7061207175
                       69206F666669636961206465736572756E74206D6F6C6C6974
                       20616E696D20696420657374206C61626F72756D2E00007441
 M17 LSF    (ENCODER): 
 CAN: 7 DST: DSD-FME   SRC: DSD-FME   Data
 LSF: [00][05][15][1B][1D][FC][00][05][15][1B][1D][FC][03][82][00]
      [00][00][00][00][00][00][00][00][00][00][00][00][00][FA][35]
 M17 Packet (ENCODER): 054C6F72656D20697073756D20646F6C6F722073697420616D00
 M17 Packet (ENCODER): 65742C20636F6E73656374657475722061646970697363696E04
 M17 Packet (ENCODER): 6720656C69742C2073656420646F20656975736D6F6420746508
 M17 Packet (ENCODER): 6D706F7220696E6369646964756E74207574206C61626F72650C
 M17 Packet (ENCODER): 20657420646F6C6F7265206D61676E6120616C697175612E2010
 M17 Packet (ENCODER): 557420656E696D206164206D696E696D2076656E69616D2C2014
 M17 Packet (ENCODER): 71756973206E6F737472756420657865726369746174696F6E18
 M17 Packet (ENCODER): 20756C6C616D636F206C61626F726973206E697369207574201C
 M17 Packet (ENCODER): 616C697175697020657820656120636F6D6D6F646F20636F6E20
 M17 Packet (ENCODER): 7365717561742E20447569732061757465206972757265206424
 M17 Packet (ENCODER): 6F6C6F7220696E20726570726568656E646572697420696E2028
 M17 Packet (ENCODER): 766F6C7570746174652076656C697420657373652063696C6C2C
 M17 Packet (ENCODER): 756D20646F6C6F726520657520667567696174206E756C6C6130
 M17 Packet (ENCODER): 2070617269617475722E204578636570746575722073696E7434
 M17 Packet (ENCODER): 206F6363616563617420637570696461746174206E6F6E207038
 M17 Packet (ENCODER): 726F6964656E742C2073756E7420696E2063756C70612071753C
 M17 Packet (ENCODER): 69206F666669636961206465736572756E74206D6F6C6C697440
 M17 Packet (ENCODER): 20616E696D20696420657374206C61626F72756D2E00007441D4
Total audio errors: 0
Total header errors: 0
Total irrecoverable header errors: 0
Exiting.

Decoding:

Build Version: AW 2024-63-g051a65f 
MBElib Version: 1.3.4
CODEC2 Support Enabled
Notice: M17 cannot autodetect polarity. 
 Use -xz option if Inverted Signal expected.
Decoding only M17 frames.
Logging Frame Payload to console
Audio In Device: m17pkt.wav
09:12:47 Sync: +M17 PREAMBLE 
09:12:47 Sync: +M17 PREAMBLE 
09:12:47 Sync: +M17 PREAMBLE 
09:12:47 Sync: +M17 PREAMBLE 
09:12:47 Sync: +M17 PREAMBLE 
09:12:47 Sync: +M17 PREAMBLE 
09:12:47 Sync: +M17 PREAMBLE 
09:12:47 Sync: +M17 PREAMBLE 
09:12:47 Sync: +M17 PREAMBLE 
09:12:47 Sync: +M17 PREAMBLE 
09:12:47 Sync: +M17 PREAMBLE 
09:12:47 Sync: +M17 PREAMBLE 
09:12:47 Sync: +M17 LSF 
 CAN: 7 DST: DSD-FME   SRC: DSD-FME   Data
 LSF: [00][05][15][1B][1D][FC][00][05][15][1B][1D][FC][03][82][00]
      [00][00][00][00][00][00][00][00][00][00][00][00][00][FA][35]
09:12:47 Sync: +M17 PKT 
 pkt_packed: 
 05 4C 6F 72 65 6D 20 69 70 73 75 6D 20 64 6F 6C 6F 72 20 73 69 74 20 61 6D 00 CNT: 00; CT: 00; EOT: 0;
09:12:47 Sync: +M17 PKT 
 pkt_packed: 
 65 74 2C 20 63 6F 6E 73 65 63 74 65 74 75 72 20 61 64 69 70 69 73 63 69 6E 04 CNT: 01; CT: 01; EOT: 0;
09:12:47 Sync: +M17 PKT 
 pkt_packed: 
 67 20 65 6C 69 74 2C 20 73 65 64 20 64 6F 20 65 69 75 73 6D 6F 64 20 74 65 08 CNT: 02; CT: 02; EOT: 0;
09:12:47 Sync: +M17 PKT 
 pkt_packed: 
 6D 70 6F 72 20 69 6E 63 69 64 69 64 75 6E 74 20 75 74 20 6C 61 62 6F 72 65 0C CNT: 03; CT: 03; EOT: 0;
09:12:47 Sync: +M17 PKT 
 pkt_packed: 
 20 65 74 20 64 6F 6C 6F 72 65 20 6D 61 67 6E 61 20 61 6C 69 71 75 61 2E 20 10 CNT: 04; CT: 04; EOT: 0;
09:12:47 Sync: +M17 PKT 
 pkt_packed: 
 55 74 20 65 6E 69 6D 20 61 64 20 6D 69 6E 69 6D 20 76 65 6E 69 61 6D 2C 20 14 CNT: 05; CT: 05; EOT: 0;
09:12:47 Sync: +M17 PKT 
 pkt_packed: 
 71 75 69 73 20 6E 6F 73 74 72 75 64 20 65 78 65 72 63 69 74 61 74 69 6F 6E 18 CNT: 06; CT: 06; EOT: 0;
09:12:47 Sync: +M17 PKT 
 pkt_packed: 
 20 75 6C 6C 61 6D 63 6F 20 6C 61 62 6F 72 69 73 20 6E 69 73 69 20 75 74 20 1C CNT: 07; CT: 07; EOT: 0;
09:12:47 Sync: +M17 PKT 
 pkt_packed: 
 61 6C 69 71 75 69 70 20 65 78 20 65 61 20 63 6F 6D 6D 6F 64 6F 20 63 6F 6E 20 CNT: 08; CT: 08; EOT: 0;
09:12:47 Sync: +M17 PKT 
 pkt_packed: 
 73 65 71 75 61 74 2E 20 44 75 69 73 20 61 75 74 65 20 69 72 75 72 65 20 64 24 CNT: 09; CT: 09; EOT: 0;
09:12:47 Sync: +M17 PKT 
 pkt_packed: 
 6F 6C 6F 72 20 69 6E 20 72 65 70 72 65 68 65 6E 64 65 72 69 74 20 69 6E 20 28 CNT: 10; CT: 10; EOT: 0;
09:12:47 Sync: +M17 PKT 
 pkt_packed: 
 76 6F 6C 75 70 74 61 74 65 20 76 65 6C 69 74 20 65 73 73 65 20 63 69 6C 6C 2C CNT: 11; CT: 11; EOT: 0;
09:12:47 Sync: +M17 PKT 
 pkt_packed: 
 75 6D 20 64 6F 6C 6F 72 65 20 65 75 20 66 75 67 69 61 74 20 6E 75 6C 6C 61 30 CNT: 12; CT: 12; EOT: 0;
09:12:47 Sync: +M17 PKT 
 pkt_packed: 
 20 70 61 72 69 61 74 75 72 2E 20 45 78 63 65 70 74 65 75 72 20 73 69 6E 74 34 CNT: 13; CT: 13; EOT: 0;
09:12:47 Sync: +M17 PKT 
 pkt_packed: 
 20 6F 63 63 61 65 63 61 74 20 63 75 70 69 64 61 74 61 74 20 6E 6F 6E 20 70 38 CNT: 14; CT: 14; EOT: 0;
09:12:47 Sync: +M17 PKT 
 pkt_packed: 
 72 6F 69 64 65 6E 74 2C 20 73 75 6E 74 20 69 6E 20 63 75 6C 70 61 20 71 75 3C CNT: 15; CT: 15; EOT: 0;
09:12:47 Sync: +M17 PKT 
 pkt_packed: 
 69 20 6F 66 66 69 63 69 61 20 64 65 73 65 72 75 6E 74 20 6D 6F 6C 6C 69 74 40 CNT: 16; CT: 16; EOT: 0;
09:12:47 Sync: +M17 PKT 
 pkt_packed: 
 20 61 6E 69 6D 20 69 64 20 65 73 74 20 6C 61 62 6F 72 75 6D 2E 00 00 74 41 D4 CNT: 18; CB: 21; EOT: 1; Protocol: SMS;
 SMS:
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
       tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim v
      eniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea 
      commodo consequat. Duis aute irure dolor in reprehenderit in voluptate 
      velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occae
      cat cupidatat non proident, sunt in culpa qui officia deserunt mollit a
      nim id est laborum.
 PKT: 05 4C 6F 72 65 6D 20 69 70 73 75 6D 20 64 6F 6C 6F 72 20 73 69 74 20 61 6D
      65 74 2C 20 63 6F 6E 73 65 63 74 65 74 75 72 20 61 64 69 70 69 73 63 69 6E
      67 20 65 6C 69 74 2C 20 73 65 64 20 64 6F 20 65 69 75 73 6D 6F 64 20 74 65
      6D 70 6F 72 20 69 6E 63 69 64 69 64 75 6E 74 20 75 74 20 6C 61 62 6F 72 65
      20 65 74 20 64 6F 6C 6F 72 65 20 6D 61 67 6E 61 20 61 6C 69 71 75 61 2E 20
      55 74 20 65 6E 69 6D 20 61 64 20 6D 69 6E 69 6D 20 76 65 6E 69 61 6D 2C 20
      71 75 69 73 20 6E 6F 73 74 72 75 64 20 65 78 65 72 63 69 74 61 74 69 6F 6E
      20 75 6C 6C 61 6D 63 6F 20 6C 61 62 6F 72 69 73 20 6E 69 73 69 20 75 74 20
      61 6C 69 71 75 69 70 20 65 78 20 65 61 20 63 6F 6D 6D 6F 64 6F 20 63 6F 6E
      73 65 71 75 61 74 2E 20 44 75 69 73 20 61 75 74 65 20 69 72 75 72 65 20 64
      6F 6C 6F 72 20 69 6E 20 72 65 70 72 65 68 65 6E 64 65 72 69 74 20 69 6E 20
      76 6F 6C 75 70 74 61 74 65 20 76 65 6C 69 74 20 65 73 73 65 20 63 69 6C 6C
      75 6D 20 64 6F 6C 6F 72 65 20 65 75 20 66 75 67 69 61 74 20 6E 75 6C 6C 61
      20 70 61 72 69 61 74 75 72 2E 20 45 78 63 65 70 74 65 75 72 20 73 69 6E 74
      20 6F 63 63 61 65 63 61 74 20 63 75 70 69 64 61 74 61 74 20 6E 6F 6E 20 70
      72 6F 69 64 65 6E 74 2C 20 73 75 6E 74 20 69 6E 20 63 75 6C 70 61 20 71 75
      69 20 6F 66 66 69 63 69 61 20 64 65 73 65 72 75 6E 74 20 6D 6F 6C 6C 69 74
      20 61 6E 69 6D 20 69 64 20 65 73 74 20 6C 61 62 6F 72 75 6D 2E 00 00 74 41
      CRC - C: 7441; E: 7441
Sync: no sync

End of m17pkt.wav

Total audio errors: 0
Total header errors: 0
Total irrecoverable header errors: 0
Exiting.

lwvmobile avatar Mar 11 '24 13:03 lwvmobile

I'm getting the following CRCs:

Data CRC:	2F6F
LSF CRC:	FA35

LSF CRC matches yours, but for the payload, the value is different. The data CRC should cover all bytes from 0x4C to 0x2E, so excluding padding. Is this what you do?

sp5wwp avatar Mar 11 '24 17:03 sp5wwp

Is this what you do?

I included the padding, so I'll have to change it to just run the payload. Does that not include the terminating 0x00 though? Wouldn't that still be part of the completed message.

lwvmobile avatar Mar 11 '24 17:03 lwvmobile

I'll check that tomorrow and if it doesn't, I'll update my code accordingly. I think it does contain the initial 0x05 byte and the trailing 0x00 null byte (just one) after all. Try doing that and then compare CRCs.

sp5wwp avatar Mar 11 '24 17:03 sp5wwp

I'll make some changes and do it with and without the terminating byte and see what happens.

lwvmobile avatar Mar 11 '24 17:03 lwvmobile

Anyways, with the initial 0x05 and the terminating 0x00, I'm getting this now, if this isn't right, I'm going to stop beating my head over the desk for one day working on it.

 SMS:
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
      tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim ve
      niam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea c
      ommodo consequat. Duis aute irure dolor in reprehenderit in voluptate v
      elit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaec
      at cupidatat non proident, sunt in culpa qui officia deserunt mollit an
      im id est laborum.
 LAST: 2E; TERM: 00; CRC: C7A6
 M17 Packet      FULL: 054C6F72656D20697073756D20646F6C6F722073697420616D
                       65742C20636F6E73656374657475722061646970697363696E
                       6720656C69742C2073656420646F20656975736D6F64207465
                       6D706F7220696E6369646964756E74207574206C61626F7265
                       20657420646F6C6F7265206D61676E6120616C697175612E20
                       557420656E696D206164206D696E696D2076656E69616D2C20
                       71756973206E6F737472756420657865726369746174696F6E
                       20756C6C616D636F206C61626F726973206E69736920757420
                       616C697175697020657820656120636F6D6D6F646F20636F6E
                       7365717561742E204475697320617574652069727572652064
                       6F6C6F7220696E20726570726568656E646572697420696E20
                       766F6C7570746174652076656C697420657373652063696C6C
                       756D20646F6C6F726520657520667567696174206E756C6C61
                       2070617269617475722E204578636570746575722073696E74
                       206F6363616563617420637570696461746174206E6F6E2070
                       726F6964656E742C2073756E7420696E2063756C7061207175
                       69206F666669636961206465736572756E74206D6F6C6C6974
                       20616E696D20696420657374206C61626F72756D2E0000C7A6

lwvmobile avatar Mar 11 '24 18:03 lwvmobile

LAST: 2E; TERM: 00; CRC: C7A6

"LAST" value suggests that you take 1 byte less than needed. Add the 0x00 to your CRC calc and it should be fine (0x2F6F). I calculated it without the trailing null and got a match (0xC7A6).

sp5wwp avatar Mar 13 '24 13:03 sp5wwp

After this is solved, we will need to compare our type-4 bitstreams (type-4 bits are the ones that are converted to symbols).

sp5wwp avatar Mar 13 '24 13:03 sp5wwp

Build Version: AW 2024-74-gd35144e 
MBElib Version: 1.3.4
CODEC2 Support Enabled
Writing raw audio to file m17pkt2.wav
Audio In/Out Device: pulse

 SMS:
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
      tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim ve
      niam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea c
      ommodo consequat. Duis aute irure dolor in reprehenderit in voluptate v
      elit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaec
      at cupidatat non proident, sunt in culpa qui officia deserunt mollit an
      im id est laborum.
 BLOCK: 18; PAD: 01; LST: 22; K: 3576; PTR: 0445; X: 446; LAST: 2E; TERM: 00; CRC: 2F6F
 M17 Packet      FULL: 054C6F72656D20697073756D20646F6C6F722073697420616D
                       65742C20636F6E73656374657475722061646970697363696E
                       6720656C69742C2073656420646F20656975736D6F64207465
                       6D706F7220696E6369646964756E74207574206C61626F7265
                       20657420646F6C6F7265206D61676E6120616C697175612E20
                       557420656E696D206164206D696E696D2076656E69616D2C20
                       71756973206E6F737472756420657865726369746174696F6E
                       20756C6C616D636F206C61626F726973206E69736920757420
                       616C697175697020657820656120636F6D6D6F646F20636F6E
                       7365717561742E204475697320617574652069727572652064
                       6F6C6F7220696E20726570726568656E646572697420696E20
                       766F6C7570746174652076656C697420657373652063696C6C
                       756D20646F6C6F726520657520667567696174206E756C6C61
                       2070617269617475722E204578636570746575722073696E74
                       206F6363616563617420637570696461746174206E6F6E2070
                       726F6964656E742C2073756E7420696E2063756C7061207175
                       69206F666669636961206465736572756E74206D6F6C6C6974
                       20616E696D20696420657374206C61626F72756D2E00002F6F

lwvmobile avatar Mar 13 '24 14:03 lwvmobile

Does M17 Implementations have a method for reading in a file written in binary chars to be decoded? I seem to remember seeing that functionality int he code the other day, but went to review it just a bit ago, and couldn't find it again. Anyways, I wrote in a method to just dump the type 4 as binary to a file, but if its not of the right format, it can be changed. Right now, its using fputc to put the uint8_t binary bits into a file, didn't know if that will work, or if we just want to fprintf them into the file like text, or do something else.

lwvmobile avatar Mar 13 '24 14:03 lwvmobile