M17 - Fix PKT CRC +1 on len value; Output Binary Bitstream to file with -Q option;

This commit is contained in:
lwvmobile
2024-03-13 10:22:55 -04:00
parent f7fe1e066c
commit d35144e0e9
2 changed files with 22 additions and 5 deletions

View File

@@ -1274,6 +1274,7 @@ usage ()
printf (" (Warning! Might be annoying.)\n");
printf (" -L <file> Specify Filename for LRRP Data Output.\n");
printf (" -Q <file> Specify Filename for OK-DMRlib Structured File Output. (placed in DSP folder)\n");
printf (" -Q <file> Specify Filename for M17 Binary File Output. (placed in DSP folder)\n");
printf (" -c <file> Output symbol capture to .bin file\n");
printf (" -q Reverse Mute - Mute Unencrypted Voice and Unmute Encrypted Voice\n");
printf (" -V <num> Enable TDMA Voice Synthesis on Slot 1 (1), Slot 2 (2), or Both (3); Default is 3; \n");
@@ -1739,14 +1740,14 @@ main (int argc, char **argv)
if (stat(wav_file_directory, &st) == -1)
{
fprintf (stderr, "-Q %s DSP file directory does not exist\n", wav_file_directory);
fprintf (stderr, "Creating directory %s to save DSP Structured files\n", wav_file_directory);
fprintf (stderr, "Creating directory %s to save DSP Structured or M17 Binary Stream files\n", wav_file_directory);
mkdir(wav_file_directory, 0700); //user read write execute, needs execute for some reason or segfault
}
//read in filename
//sprintf (opts.wav_out_file, "./WAV/DSD-FME-X1.wav");
strncpy(dsp_filename, optarg, 1023);
sprintf(opts.dsp_out_file, "%s/%s", wav_file_directory, dsp_filename);
fprintf (stderr, "Saving DSP Structured files to %s\n", opts.dsp_out_file);
fprintf (stderr, "Saving DSP Structured or M17 Binary Stream files to %s\n", opts.dsp_out_file);
opts.use_dsp_output = 1;
break;

View File

@@ -1300,12 +1300,28 @@ void encodeM17RF (dsd_opts * opts, dsd_state * state, uint8_t * input, int type)
}
//save symbols (dibits, actually) to symbol capture bin file format
if (opts->symbol_out_f)
if (opts->symbol_out_f) //use -c output.bin to use this format (default type for DSD-FME)
{
for (i = 0; i < 192; i++)
fputc (output_dibits[i], opts->symbol_out_f);
}
//save binary format (M17_Implementations Compatible? Untested as of yet)
if (opts->use_dsp_output) //use -Q output.bin to use this format, will be placed in the DSP folder (reusing DSP)
{
FILE * pFile; //file pointer
pFile = fopen (opts->dsp_out_file, "w");
uint8_t output_binary[384]; memset (output_binary, 0, sizeof(output_binary));
for (i = 0; i < 192; i++)
{
output_binary[i*2+0] = (output_dibits[i] >> 1) & 1;
output_binary[i*2+1] = (output_dibits[i] >> 0) & 1;
fputc (output_binary[i*2+0], pFile);
fputc (output_dibits[i*2+1], pFile);
}
fclose(pFile);
}
//playing back signal audio into device/udp
//NOTE: Open the analog output device, use -8
if (opts->monitor_input_audio == 1)
@@ -2593,7 +2609,7 @@ void encodeM17PKT(dsd_opts * opts, dsd_state * state)
if (m17_p1_packed[x] == 0) break; //stop at the termination byte
x++;
}
crc_cmp = crc16m17(m17_p1_packed+1, x-1);
crc_cmp = crc16m17(m17_p1_packed, x+1); //+1 on len to make it match Woj's calculated value of 0x2F6F on the default sample
//debug dump CRC (when pad is literally zero)
fprintf (stderr, " X: %d; LAST: %02X; TERM: %02X; CRC: %04X", x, m17_p1_packed[x-1], m17_p1_packed[x], crc_cmp);
@@ -2885,7 +2901,7 @@ void processM17PKT(dsd_opts * opts, dsd_state * state)
if (eot)
{
//do a CRC check
uint16_t crc_cmp = crc16m17(state->m17_pkt+1, total-1);
uint16_t crc_cmp = crc16m17(state->m17_pkt, total+1); //+1 on len to make it match Woj's calculated value of 0x2F6F on the default sample
uint16_t crc_ext = (state->m17_pkt[end-2] << 8) + state->m17_pkt[end-1];
if (crc_cmp == crc_ext)