diff --git a/include/dsd.h b/include/dsd.h index 67ffb25..4e93fb2 100644 --- a/include/dsd.h +++ b/include/dsd.h @@ -277,6 +277,7 @@ typedef struct char wav_out_fileR[1024]; char wav_out_file_raw[1024]; char symbol_out_file[1024]; + char lrrp_out_file[1024]; short int symbol_out; SNDFILE *wav_out_f; SNDFILE *wav_out_fR; @@ -565,7 +566,7 @@ typedef struct // int block_count; short int dmr_encL; short int dmr_encR; - + //dstar header for ncurses unsigned char dstarradioheader[41]; diff --git a/src/dmr_sync.c b/src/dmr_sync.c index 6e9fa13..fa563a8 100644 --- a/src/dmr_sync.c +++ b/src/dmr_sync.c @@ -126,24 +126,21 @@ void Process34Data(dsd_opts * opts, dsd_state * state, unsigned char tdibits[98] //Start Polling the 3/4 Rate Super Frame for Data when byte 0 contains values //LRRP int message_legnth = 0; - if ( (state->dmr_34_rate_sf[slot][0] & 0x7F) == 0x45) //Start LRRP now + if ( ((state->dmr_34_rate_sf[slot][0] & 0x7F) == 0x45) || + ((state->dmr_34_rate_sf[slot][0] & 0x7F) == 0x1F) ) //Start LRRP now, shimmed in 1F for KrisMar testing { + if ( (state->dmr_34_rate_sf[slot][0] & 0x7F) == 0x1F ) + { + message_legnth = 22; //quick shim for KrisMar samples, until I can find a message legnth flag on his + } + //find user home directory and append directory and filename. FILE * pFile; //put this outside of the if statement? if (opts->lrrp_file_output == 1) { - char * filename = "/lrrp.txt"; - char * home_dir = getenv("HOME"); - char * filepath = malloc(strlen(home_dir) + strlen(filename) + 1); - strncpy (filepath, home_dir, strlen(home_dir) + 1); - strncat (filepath, filename, strlen(filename) + 1); - //end find user home directory and append directory and filename - - pFile = fopen (filepath, "a"); - - //hard code filename override for those wanting to use other software - //pFile = fopen("DSDPlus.LRRP", "a"); + //open file by name that is supplied in the ncurses terminal + pFile = fopen (opts->lrrp_out_file, "a"); //seperate these two values since they cause issues with garbage writing to files in some environments (cygwin) fprintf (pFile, "%s\t", getDateL() ); //current date, may find a way to only add this IF no included timestamp in LRRP data? @@ -239,37 +236,39 @@ void Process34Data(dsd_opts * opts, dsd_state * state, unsigned char tdibits[98] } else fprintf (stderr, " (%.5lf, %.5lf)", ((double)lrrplat) * lat_unit , (lrrplon * lon_unit) ); - i = i + 9 + 2; //skip 9 bytes here so we don't accidentally trip another flag with data in these bytes - } + //i = i + 9 + 2; //skip 9 bytes here so we don't accidentally trip another flag with data in these bytes - - if ( state->dmr_34_rate_sf[slot][i] == 0x6C && message_legnth > 13) - { - //either Plus is wrong, or I'm wrong on higher velocities exceeding 0xFF. double check double values? - //fprintf (stderr, "\n LRRP - Vi %02X Vf %02X Velocity Units (hex)", state->dmr_34_rate_sf[i+1], state->dmr_34_rate_sf[i+2]); - double velocity = ( ((double)( (state->dmr_34_rate_sf[slot][i+1] ) + state->dmr_34_rate_sf[slot][i+2] )) / ( (double)128)); - if (opts->lrrp_file_output == 1) + //tuck velocity and track inside the lrrp coordinates? loose false positives on velocity and track without a coord point + if ( state->dmr_34_rate_sf[slot][i+11] == 0x6C && message_legnth > 13) { - fprintf (pFile, "%.3lf\t ", (velocity * 3.6) ); - } - fprintf (stderr, "\n LRRP - Velocity: %.4lf m/s %.4lf km/h %.4lf mph", velocity, (3.6 * velocity), (2.2369 * velocity) ); - sprintf ( state->dmr_lrrp[state->currentslot][4], "Vel: %.4lf kph ", (3.6 * velocity)); + //either Plus is wrong, or I'm wrong on higher velocities exceeding 0xFF. double check double values? + //fprintf (stderr, "\n LRRP - Vi %02X Vf %02X Velocity Units (hex)", state->dmr_34_rate_sf[i+1], state->dmr_34_rate_sf[i+2]); + double velocity = ( ((double)( (state->dmr_34_rate_sf[slot][i+12] ) + state->dmr_34_rate_sf[slot][i+13] )) / ( (double)128)); + if (opts->lrrp_file_output == 1) + { + fprintf (pFile, "%.3lf\t ", (velocity * 3.6) ); + } + fprintf (stderr, "\n LRRP - Velocity: %.4lf m/s %.4lf km/h %.4lf mph", velocity, (3.6 * velocity), (2.2369 * velocity) ); + sprintf ( state->dmr_lrrp[state->currentslot][4], "Vel: %.4lf kph ", (3.6 * velocity)); - i = i + 3; //skip 3 bytes here so we don't accidentally trip another flag with data in these bytes - } - if ( state->dmr_34_rate_sf[slot][i] == 0x56 && message_legnth > 13) - { - //check for appropriate terminology here - Heading, bearing, course, or track? - if (opts->lrrp_file_output == 1) + //i = i + 3; //skip 3 bytes here so we don't accidentally trip another flag with data in these bytes + } + if ( state->dmr_34_rate_sf[slot][i+14] == 0x56 && message_legnth > 13) { - fprintf (pFile, "%d\t", state->dmr_34_rate_sf[slot][i+1] * 2); - } - fprintf (stderr, "\n LRRP - Track: %d Degrees", state->dmr_34_rate_sf[slot][i+1] * 2); - sprintf ( state->dmr_lrrp[state->currentslot][5], "Dir: %d Deg ", state->dmr_34_rate_sf[slot][i+1] * 2); + //check for appropriate terminology here - Heading, bearing, course, or track? + if (opts->lrrp_file_output == 1) + { + fprintf (pFile, "%d\t", state->dmr_34_rate_sf[slot][i+15] * 2); + } + fprintf (stderr, "\n LRRP - Track: %d Degrees", state->dmr_34_rate_sf[slot][i+15] * 2); + sprintf ( state->dmr_lrrp[state->currentslot][5], "Dir: %d Deg ", state->dmr_34_rate_sf[slot][i+15] * 2); - //i = ((blocks+1)*12); //skip to end of loop here so we don't accidentally trip another flag with data in these bytes - i = 99; + i = ((blocks+1)*12); //skip to end of loop here so we don't accidentally trip another flag with data in these bytes + } + + i = i + 15; } + //try for a Control ACK at the very end if nothing else pops, flag still unknown if ( (state->dmr_34_rate_sf[slot][i] == 0x36 || state->dmr_34_rate_sf[slot][i] == 0x37) && message_legnth > 6 ) { @@ -1203,21 +1202,17 @@ void Process12Data(dsd_opts * opts, dsd_state * state, uint8_t info[196], uint8_ if ( (state->dmr_12_rate_sf[slot][0] & 0x7F) == 0x45) //Start LRRP now { + if ( (state->dmr_12_rate_sf[slot][0] & 0x7F) == 0x1F ) + { + message_legnth = 22; //quick shim for KrisMar samples, until I can find a message legnth flag on his + } + //find user home directory and append directory and filename. FILE * pFile; //put this outside of the if statement? if (opts->lrrp_file_output == 1) { - char * filename = "/lrrp.txt"; - char * home_dir = getenv("HOME"); - char * filepath = malloc(strlen(home_dir) + strlen(filename) + 1); - strncpy (filepath, home_dir, strlen(home_dir) + 1); - strncat (filepath, filename, strlen(filename) + 1); - //end find user home directory and append directory and filename - - pFile = fopen (filepath, "a"); - - //hard code filename override for those wanting to use other software - //pFile = fopen("DSDPlus.LRRP", "a"); + //open file by name that is supplied in the ncurses terminal + pFile = fopen (opts->lrrp_out_file, "a"); //seperate these two values since they cause issues with garbage writing to files in some environments (cygwin) fprintf (pFile, "%s\t", getDateL() ); //current date, may find a way to only add this IF no included timestamp in LRRP data? @@ -1313,36 +1308,40 @@ void Process12Data(dsd_opts * opts, dsd_state * state, uint8_t info[196], uint8_ } else fprintf (stderr, " (%.5lf, %.5lf)", ((double)lrrplat) * lat_unit , (lrrplon * lon_unit) ); - i = i + 9 + 2; //skip 9 bytes here so we don't accidentally trip another flag with data in these bytes - } + //i = i + 9 + 2; //skip 9 bytes here so we don't accidentally trip another flag with data in these bytes - - if ( state->dmr_12_rate_sf[slot][i] == 0x6C && message_legnth > 13) - { - //either Plus is wrong, or I'm wrong on higher velocities exceeding 0xFF. double check double values? - //fprintf (stderr, "\n LRRP - Vi %02X Vf %02X Velocity Units (hex)", state->dmr_34_rate_sf[i+1], state->dmr_34_rate_sf[i+2]); - double velocity = ( ((double)( (state->dmr_12_rate_sf[slot][i+1] ) + state->dmr_12_rate_sf[slot][i+2] )) / ( (double)128)); - if (opts->lrrp_file_output == 1) + //tuck velocity and track inside the lrrp coordinates? loose false positives on velocity and track without a coord point + if ( state->dmr_12_rate_sf[slot][i+11] == 0x6C && message_legnth > 13) { - fprintf (pFile, "%.3lf\t ", (velocity * 3.6) ); - } - fprintf (stderr, "\n LRRP - Velocity: %.4lf m/s %.4lf km/h %.4lf mph", velocity, (3.6 * velocity), (2.2369 * velocity) ); - sprintf ( state->dmr_lrrp[state->currentslot][4], "Vel: %.4lf kph ", (3.6 * velocity)); + //either Plus is wrong, or I'm wrong on higher velocities exceeding 0xFF. double check double values? + //fprintf (stderr, "\n LRRP - Vi %02X Vf %02X Velocity Units (hex)", state->dmr_34_rate_sf[i+1], state->dmr_34_rate_sf[i+2]); + double velocity = ( ((double)( (state->dmr_12_rate_sf[slot][i+12] ) + state->dmr_12_rate_sf[slot][i+13] )) / ( (double)128)); + if (opts->lrrp_file_output == 1) + { + fprintf (pFile, "%.3lf\t ", (velocity * 3.6) ); + } + fprintf (stderr, "\n LRRP - Velocity: %.4lf m/s %.4lf km/h %.4lf mph", velocity, (3.6 * velocity), (2.2369 * velocity) ); + sprintf ( state->dmr_lrrp[state->currentslot][4], "Vel: %.4lf kph ", (3.6 * velocity)); - i = i + 3; //skip 3 bytes here so we don't accidentally trip another flag with data in these bytes - } - if ( state->dmr_12_rate_sf[slot][i] == 0x56 && message_legnth > 13) - { - //check for appropriate terminology here - Heading, bearing, course, or track? - if (opts->lrrp_file_output == 1) + //i = i + 3; //skip 3 bytes here so we don't accidentally trip another flag with data in these bytes + } + if ( state->dmr_12_rate_sf[slot][i+14] == 0x56 && message_legnth > 13) { - fprintf (pFile, "%d\t", state->dmr_12_rate_sf[slot][i+1] * 2); - } - fprintf (stderr, "\n LRRP - Track: %d Degrees", state->dmr_12_rate_sf[slot][i+1] * 2); - sprintf ( state->dmr_lrrp[state->currentslot][5], "Dir: %d Deg ", state->dmr_12_rate_sf[slot][i+1] * 2); + //check for appropriate terminology here - Heading, bearing, course, or track? + if (opts->lrrp_file_output == 1) + { + fprintf (pFile, "%d\t", state->dmr_12_rate_sf[slot][i+15] * 2); + } + fprintf (stderr, "\n LRRP - Track: %d Degrees", state->dmr_12_rate_sf[slot][i+15] * 2); + sprintf ( state->dmr_lrrp[state->currentslot][5], "Dir: %d Deg ", state->dmr_12_rate_sf[slot][i+15] * 2); + + i = ((blocks+1)*12); //skip to end of loop here so we don't accidentally trip another flag with data in these bytes + } + + i = i + 15; - i = ((blocks+1)*12); //skip to end of loop here so we don't accidentally trip another flag with data in these bytes } + //try for a Control ACK at the very end if nothing else pops, flag still unknown if ( (state->dmr_12_rate_sf[slot][i] == 0x36 || state->dmr_12_rate_sf[slot][i] == 0x37) && message_legnth > 6 ) { diff --git a/src/dsd_main.c b/src/dsd_main.c index 5ab0e62..5b2ebf9 100644 --- a/src/dsd_main.c +++ b/src/dsd_main.c @@ -224,6 +224,7 @@ initOpts (dsd_opts * opts) opts->wav_out_fileR[0] = 0; opts->wav_out_file_raw[0] = 0; opts->symbol_out_file[0] = 0; + opts->lrrp_out_file[0] = 0; opts->symbol_out_f = NULL; opts->symbol_out = 0; opts->wav_out_f = NULL; diff --git a/src/dsd_ncurses.c b/src/dsd_ncurses.c index d980ddb..c98801f 100644 --- a/src/dsd_ncurses.c +++ b/src/dsd_ncurses.c @@ -211,7 +211,7 @@ char *choices[] = { "Enable Payloads to Console", "Disable Payloads to Console", "Input & Output Options", - "Enable LRRP to ~/lrrp.txt", + "LRRP Data to File", "Exit DSD-FME", // "Test" }; @@ -436,7 +436,7 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state) wscanw(entry_win, "%s", &opts->symbol_out_file); noecho(); - if (opts->symbol_out_file != NULL) + if (opts->symbol_out_file[0] != NULL) { opts->symbol_out = 1; //set flag to 1 openSymbolOutFile (opts, state); @@ -735,7 +735,7 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state) { if (opts->symbol_out == 1) { - if (opts->symbol_out_file != NULL) //check first, or issuing a second fclose will crash the SOFTWARE + if (opts->symbol_out_file[0] != NULL) //check first, or issuing a second fclose will crash the SOFTWARE { fclose(opts->symbol_out_f); //free(): double free detected in tcache 2 (this is a new one) happens when closing more than once sprintf (opts->audio_in_dev, opts->symbol_out_file); //swap output bin filename to input for quick replay @@ -1143,8 +1143,69 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state) } if (choice == 18) { - opts->lrrp_file_output = 1; - fprintf(stderr, "LRRP to text\n"); + short int lrrpchoice = 0; + entry_win = newwin(10, WIDTH+16, starty+10, startx+10); + box (entry_win, 0, 0); + mvwprintw(entry_win, 2, 2, " Enable or Disable LRRP Data File"); + mvwprintw(entry_win, 3, 2, " 1 - ~/lrrp.txt (QGis)"); + mvwprintw(entry_win, 4, 2, " 2 - ./DSDPlus.LRRP (LRRP.exe)"); + mvwprintw(entry_win, 5, 2, " 3 - ./Custom Filename"); + mvwprintw(entry_win, 6, 2, " 4 - Cancel/Stop"); + mvwprintw(entry_win, 7, 2, " "); + mvwprintw(entry_win, 8, 2, " "); + echo(); + refresh(); + wscanw(entry_win, "%d", &lrrpchoice); + noecho(); + + if (lrrpchoice == 1) + { + //find user home directory and append directory and filename. + char * filename = "/lrrp.txt"; + char * home_dir = getenv("HOME"); + char * filepath = malloc(strlen(home_dir) + strlen(filename) + 1); + strncpy (filepath, home_dir, strlen(home_dir) + 1); + strncat (filepath, filename, strlen(filename) + 1); + //assign home directory/filename to lrrp_out_file + sprintf (opts->lrrp_out_file, filepath); + opts->lrrp_file_output = 1; + } + + else if (lrrpchoice == 2) + { + sprintf (opts->lrrp_out_file, "DSDPlus.LRRP"); + opts->lrrp_file_output = 1; + } + + else if (lrrpchoice == 3) + { + //read in filename for symbol capture bin + opts->lrrp_out_file[0] = 0; + entry_win = newwin(6, WIDTH+16, starty+10, startx+10); + box (entry_win, 0, 0); + mvwprintw(entry_win, 2, 2, " Enter LRRP Data Filename"); + mvwprintw(entry_win, 3, 3, " "); + echo(); + refresh(); + wscanw(entry_win, "%s", &opts->lrrp_out_file); + noecho(); + if (opts->lrrp_out_file[0] != NULL) + { + opts->lrrp_file_output = 1; + } + else + { + opts->lrrp_file_output = 0; + sprintf (opts->lrrp_out_file, ""); + opts->lrrp_out_file[0] = 0; + } + } + else + { + opts->lrrp_file_output = 0; + sprintf (opts->lrrp_out_file, ""); + opts->lrrp_out_file[0] = 0; + } } if (choice == 19) {