Merge pull request #256 from lwvmobile/aw_dev_timefix

Consolidate and Fix Time and Date Functions #255
This commit is contained in:
lwvmobile
2024-04-26 21:47:47 -04:00
committed by GitHub
13 changed files with 424 additions and 361 deletions

View File

@@ -588,6 +588,7 @@ typedef struct
unsigned int debug_audio_errorsR; unsigned int debug_audio_errorsR;
unsigned int debug_header_errors; unsigned int debug_header_errors;
unsigned int debug_header_critical_errors; unsigned int debug_header_critical_errors;
int debug_mode; //debug misc things
// Last dibit read // Last dibit read
int last_dibit; int last_dibit;
@@ -1246,8 +1247,14 @@ void dmr_pdu (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DMR
void dmr_reset_blocks (dsd_opts * opts, dsd_state * state); void dmr_reset_blocks (dsd_opts * opts, dsd_state * state);
void dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DMR_PDU[]); void dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DMR_PDU[]);
void dmr_locn (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DMR_PDU[]); void dmr_locn (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DMR_PDU[]);
char * getTimeL(void);
char * getDateL(void); //Time and Date Functions
char * getTime();
char * getTimeC();
char * getTimeN(time_t t);
char * getDate();
char * getDateH();
char * getDateN(time_t t);
//dmr alg stuff //dmr alg stuff
void dmr_alg_reset (dsd_opts * opts, dsd_state * state); void dmr_alg_reset (dsd_opts * opts, dsd_state * state);

View File

@@ -13,8 +13,9 @@
//processing voice and/or data on both BS slots (channels) simultaneously //processing voice and/or data on both BS slots (channels) simultaneously
void dmrBS (dsd_opts * opts, dsd_state * state) void dmrBS (dsd_opts * opts, dsd_state * state)
{ {
int i, dibit; char * timestr = NULL;
int i, dibit;
char ambe_fr[4][24]; char ambe_fr[4][24];
char ambe_fr2[4][24]; char ambe_fr2[4][24];
char ambe_fr3[4][24]; char ambe_fr3[4][24];
@@ -55,22 +56,6 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
uint8_t dummy_bits[196]; uint8_t dummy_bits[196];
memset (dummy_bits, 0, sizeof(dummy_bits)); memset (dummy_bits, 0, sizeof(dummy_bits));
//add time to mirror printFrameSync
char * getTime(void) //get pretty hh:mm:ss timestamp
{
time_t t = time(NULL);
char * curr;
char * stamp = asctime(localtime( & t));
curr = strtok(stamp, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
return curr;
}
//Init slot lights //Init slot lights
sprintf (state->slot1light, " slot1 "); sprintf (state->slot1light, " slot1 ");
sprintf (state->slot2light, " slot2 "); sprintf (state->slot2light, " slot2 ");
@@ -114,6 +99,8 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
cleanupAndExit (opts, state); cleanupAndExit (opts, state);
} }
timestr = getTimeC();
memset (ambe_fr, 0, sizeof(ambe_fr)); memset (ambe_fr, 0, sizeof(ambe_fr));
memset (ambe_fr2, 0, sizeof(ambe_fr2)); memset (ambe_fr2, 0, sizeof(ambe_fr2));
memset (ambe_fr3, 0, sizeof(ambe_fr3)); memset (ambe_fr3, 0, sizeof(ambe_fr3));
@@ -279,7 +266,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
if ( strcmp (sync, DMR_BS_DATA_SYNC) == 0 ) if ( strcmp (sync, DMR_BS_DATA_SYNC) == 0 )
{ {
fprintf (stderr,"%s ", getTime()); fprintf (stderr,"%s ", timestr);
if (internalslot == 0) if (internalslot == 0)
{ {
if (opts->inverted_dmr == 0) if (opts->inverted_dmr == 0)
@@ -315,7 +302,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
//check to see if we are expecting a VC at this point vc > 7 //check to see if we are expecting a VC at this point vc > 7
if (strcmp (sync, DMR_BS_DATA_SYNC) != 0 && internalslot == 0 && vc1 > 6) if (strcmp (sync, DMR_BS_DATA_SYNC) != 0 && internalslot == 0 && vc1 > 6)
{ {
fprintf (stderr,"%s ", getTime()); fprintf (stderr,"%s ", timestr);
//simplifying things //simplifying things
// char polarity[3]; // char polarity[3];
@@ -336,7 +323,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
//check to see if we are expecting a VC at this point vc > 7 //check to see if we are expecting a VC at this point vc > 7
if (strcmp (sync, DMR_BS_DATA_SYNC) != 0 && internalslot == 1 && vc2 > 6) if (strcmp (sync, DMR_BS_DATA_SYNC) != 0 && internalslot == 1 && vc2 > 6)
{ {
fprintf (stderr,"%s ", getTime()); fprintf (stderr,"%s ", timestr);
//simplifying things //simplifying things
// char polarity[3]; // char polarity[3];
@@ -374,7 +361,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
skipcount = 0; //reset skip count if processing voice frames skipcount = 0; //reset skip count if processing voice frames
fprintf (stderr,"%s ", getTime()); fprintf (stderr,"%s ", timestr);
//simplifying things //simplifying things
char polarity[3]; char polarity[3];
@@ -562,6 +549,13 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
ncursesPrinter(opts, state); ncursesPrinter(opts, state);
} }
//
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
} // while loop } // while loop
END: END:
@@ -585,7 +579,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
if (tact_okay != 1 || emb_ok != 1) if (tact_okay != 1 || emb_ok != 1)
{ {
fprintf (stderr,"%s ", getTime()); fprintf (stderr,"%s ", timestr);
fprintf (stderr,"Sync: DMR "); fprintf (stderr,"Sync: DMR ");
fprintf (stderr, "%s", KRED); fprintf (stderr, "%s", KRED);
fprintf (stderr, "| VOICE CACH/EMB ERR"); fprintf (stderr, "| VOICE CACH/EMB ERR");
@@ -608,6 +602,13 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
} }
//
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
} }
//Process buffered half frame and 2nd half and then jump to full BS decoding //Process buffered half frame and 2nd half and then jump to full BS decoding
@@ -644,21 +645,8 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
15, 3, 16, 4, 17, 18, 15, 3, 16, 4, 17, 18,
19, 5, 20, 21, 22, 6, 23 19, 5, 20, 21, 22, 6, 23
}; };
//add time to mirror printFrameSync
char * getTime(void) //get pretty hh:mm:ss timestamp
{
time_t t = time(NULL);
char * curr; char * timestr = getTimeC();
char * stamp = asctime(localtime( & t));
curr = strtok(stamp, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
return curr;
}
//payload buffer //payload buffer
//CACH + First Half Payload + Sync = 12 + 54 + 24 //CACH + First Half Payload + Sync = 12 + 54 + 24
@@ -807,7 +795,7 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
fclose (pFile); fclose (pFile);
} }
fprintf (stderr,"%s ", getTime()); fprintf (stderr,"%s ", timestr);
char polarity[3]; char polarity[3];
char light[18]; char light[18];
@@ -909,7 +897,7 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
//if we have a tact err, then produce sync pattern/err message //if we have a tact err, then produce sync pattern/err message
if (tact_okay != 1 || sync_okay != 1) if (tact_okay != 1 || sync_okay != 1)
{ {
fprintf (stderr,"%s ", getTime()); fprintf (stderr,"%s ", timestr);
fprintf (stderr,"Sync: DMR "); fprintf (stderr,"Sync: DMR ");
fprintf (stderr, "%s", KRED); fprintf (stderr, "%s", KRED);
fprintf (stderr, "| VOICE CACH/SYNC ERR"); fprintf (stderr, "| VOICE CACH/SYNC ERR");
@@ -931,5 +919,10 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
dmr_reset_blocks (opts, state); dmr_reset_blocks (opts, state);
} }
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
} }

View File

@@ -13,6 +13,8 @@
void dmrMS (dsd_opts * opts, dsd_state * state) void dmrMS (dsd_opts * opts, dsd_state * state)
{ {
char * timestr = getTimeC();
int i, j, dibit; int i, j, dibit;
char ambe_fr[4][24]; char ambe_fr[4][24];
char ambe_fr2[4][24]; char ambe_fr2[4][24];
@@ -55,22 +57,6 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
uint8_t dummy_bits[196]; uint8_t dummy_bits[196];
memset (dummy_bits, 0, sizeof (dummy_bits)); memset (dummy_bits, 0, sizeof (dummy_bits));
//add time to mirror printFrameSync
char * getTime(void) //get pretty hh:mm:ss timestamp
{
time_t t = time(NULL);
char * curr;
char * stamp = asctime(localtime( & t));
curr = strtok(stamp, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
return curr;
}
vc = 2; vc = 2;
//Hardset variables for MS/Mono //Hardset variables for MS/Mono
@@ -187,7 +173,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
if ( strcmp (sync, DMR_RC_DATA_SYNC) == 0) if ( strcmp (sync, DMR_RC_DATA_SYNC) == 0)
{ {
state->dmr_ms_rc = 1; state->dmr_ms_rc = 1;
fprintf (stderr, "%s ", getTime()); fprintf (stderr, "%s ", timestr);
if (opts->inverted_dmr == 0) if (opts->inverted_dmr == 0)
{ {
fprintf (stderr,"Sync: +DMR MS/DM MODE/MONO "); fprintf (stderr,"Sync: +DMR MS/DM MODE/MONO ");
@@ -388,12 +374,20 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
state->dmr_ms_rc = 0; state->dmr_ms_rc = 0;
state->directmode = 0; //flag off state->directmode = 0; //flag off
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
} }
//collect buffered 1st half and get 2nd half voice payload and then jump to full MS Voice decoding. //collect buffered 1st half and get 2nd half voice payload and then jump to full MS Voice decoding.
void dmrMSBootstrap (dsd_opts * opts, dsd_state * state) void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
{ {
char * timestr = getTimeC();
int i, dibit; int i, dibit;
int *dibit_p; int *dibit_p;
@@ -417,22 +411,6 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
char cachdata[25]; char cachdata[25];
UNUSED(cachdata); UNUSED(cachdata);
//add time to mirror sync
char * getTime(void) //get pretty hh:mm:ss timestamp
{
time_t t = time(NULL);
char * curr;
char * stamp = asctime(localtime( & t));
curr = strtok(stamp, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
return curr;
}
state->dmrburstL = 16; state->dmrburstL = 16;
state->currentslot = 0; //force to slot 0 state->currentslot = 0; //force to slot 0
@@ -568,7 +546,7 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
fclose (pFile); fclose (pFile);
} }
fprintf (stderr, "%s ", getTime()); fprintf (stderr, "%s ", timestr);
if (opts->inverted_dmr == 0) if (opts->inverted_dmr == 0)
{ {
fprintf (stderr,"Sync: +DMR MS/DM MODE/MONO "); fprintf (stderr,"Sync: +DMR MS/DM MODE/MONO ");
@@ -644,6 +622,11 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
//errors due to skipping other slot //errors due to skipping other slot
// cach_err = dmr_cach (opts, state, cachdata); // cach_err = dmr_cach (opts, state, cachdata);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
skipDibit (opts, state, 144); //skip to next TDMA slot skipDibit (opts, state, 144); //skip to next TDMA slot
dmrMS (opts, state); //bootstrap into full TDMA frame dmrMS (opts, state); //bootstrap into full TDMA frame
@@ -653,27 +636,13 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
//simplied to a simple data collector, and then passed on to dmr_data_sync for the usual processing //simplied to a simple data collector, and then passed on to dmr_data_sync for the usual processing
void dmrMSData (dsd_opts * opts, dsd_state * state) void dmrMSData (dsd_opts * opts, dsd_state * state)
{ {
char * timestr = getTimeC();
int i; int i;
int dibit; int dibit;
int *dibit_p; int *dibit_p;
//add time to mirror sync
char * getTime(void) //get pretty hh:mm:ss timestamp
{
time_t t = time(NULL);
char * curr;
char * stamp = asctime(localtime( & t));
curr = strtok(stamp, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
return curr;
}
//CACH + First Half Payload + Sync = 12 + 54 + 24 //CACH + First Half Payload + Sync = 12 + 54 + 24
dibit_p = state->dmr_payload_p - 90; dibit_p = state->dmr_payload_p - 90;
for (i = 0; i < 90; i++) //90 for (i = 0; i < 90; i++) //90
@@ -691,7 +660,7 @@ void dmrMSData (dsd_opts * opts, dsd_state * state)
state->dmr_stereo_payload[i+90] = dibit; state->dmr_stereo_payload[i+90] = dibit;
} }
fprintf (stderr, "%s ", getTime()); fprintf (stderr, "%s ", timestr);
if (opts->inverted_dmr == 0) if (opts->inverted_dmr == 0)
{ {
fprintf (stderr,"Sync: +DMR MS/DM MODE/MONO "); fprintf (stderr,"Sync: +DMR MS/DM MODE/MONO ");
@@ -728,4 +697,10 @@ void dmrMSData (dsd_opts * opts, dsd_state * state)
state->dmr_stereo_payload[i+66] = 1; ////set to one so first frame will fail intentionally instead of zero fill state->dmr_stereo_payload[i+66] = 1; ////set to one so first frame will fail intentionally instead of zero fill
} }
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
} }

View File

@@ -8,33 +8,6 @@
#include "dsd.h" #include "dsd.h"
char * getTimeL(void) //get pretty hh:mm:ss timestamp
{
time_t t = time(NULL);
char * curr;
char * stamp = asctime(localtime( & t));
curr = strtok(stamp, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
return curr;
}
char * getDateL(void) {
char datename[120];
char * curr2;
struct tm * to;
time_t t;
t = time(NULL);
to = localtime( & t);
strftime(datename, sizeof(datename), "%Y/%m/%d", to);
curr2 = strtok(datename, " ");
return curr2;
}
void dmr_pdu (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DMR_PDU[]) void dmr_pdu (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DMR_PDU[])
{ {
@@ -274,16 +247,29 @@ void dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DM
FILE * pFile; //file pointer FILE * pFile; //file pointer
if (opts->lrrp_file_output == 1) if (opts->lrrp_file_output == 1)
{ {
char * timestr = getTime();
char * datestr = getDate();
//open file by name that is supplied in the ncurses terminal, or cli //open file by name that is supplied in the ncurses terminal, or cli
pFile = fopen (opts->lrrp_out_file, "a"); pFile = fopen (opts->lrrp_out_file, "a");
//write current date/time if not present in LRRP data //write current date/time if not present in LRRP data
if (!year) fprintf (pFile, "%s\t", getDateL() ); //current date, only add this IF no included timestamp in LRRP data? if (!year) fprintf (pFile, "%s\t", datestr ); //current date, only add this IF no included timestamp in LRRP data?
if (!year) fprintf (pFile, "%s\t", getTimeL() ); //current timestamp, only add this IF no included timestamp in LRRP data? if (!year) fprintf (pFile, "%s\t", timestr ); //current timestamp, only add this IF no included timestamp in LRRP data?
if (year) fprintf (pFile, "%04d/%02d/%02d\t%02d:%02d:%02d\t", year, month, day, hour, minute, second); //add timestamp from decoded audio if available if (year) fprintf (pFile, "%04d/%02d/%02d\t%02d:%02d:%02d\t", year, month, day, hour, minute, second); //add timestamp from decoded audio if available
//write data header source if not available in lrrp data //write data header source if not available in lrrp data
if (!source) fprintf (pFile, "%08lld\t", state->dmr_lrrp_source[state->currentslot]); //source address from data header if (!source) fprintf (pFile, "%08lld\t", state->dmr_lrrp_source[state->currentslot]); //source address from data header
if (source) fprintf (pFile, "%08d\t", source); //add source form decoded audio if available, else its from the header if (source) fprintf (pFile, "%08d\t", source); //add source form decoded audio if available, else its from the header
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
} }
if (pot_report) if (pot_report)

View File

@@ -17,38 +17,6 @@
#include "dsd.h" #include "dsd.h"
//fix from YorgosTheodorakis fork -- https://github.com/YorgosTheodorakis/dsd-fme/commit/7884ee555521a887d388152b3b1f11f20433a94b
char * getTimeF(void) //get pretty hhmmss timestamp
{
char * curr = (char *) malloc(9);
time_t t = time(NULL);
struct tm * ptm = localtime(& t);
sprintf(
curr,
"%02d%02d%02d",
ptm->tm_hour,
ptm->tm_min,
ptm->tm_sec
);
return curr;
}
char * getDateF(void) {
#ifdef AERO_BUILD
char datename[80];
#else
char datename[99];
#endif
char * curr2;
struct tm * to;
time_t t;
t = time(NULL);
to = localtime( & t);
strftime(datename, sizeof(datename), "%Y%m%d", to);
curr2 = strtok(datename, " ");
return curr2;
}
void saveImbe4400Data (dsd_opts * opts, dsd_state * state, char *imbe_d) void saveImbe4400Data (dsd_opts * opts, dsd_state * state, char *imbe_d)
{ {
int i, j, k; int i, j, k;
@@ -397,7 +365,10 @@ void openMbeOutFile (dsd_opts * opts, dsd_state * state)
int i, j; int i, j;
char ext[5]; char ext[5];
char * timestr; //add timestr here, so we can assign it and also free it to prevent memory leak char * timestr; //add timestr here, so we can assign it and also free it to prevent memory leak
timestr = getTimeF(); char * datestr;
timestr = getTime();
datestr = getDate();
//phase 1 and provoice //phase 1 and provoice
if ( (state->synctype == 0) || (state->synctype == 1) || (state->synctype == 14) || (state->synctype == 15) ) if ( (state->synctype == 0) || (state->synctype == 1) || (state->synctype == 14) || (state->synctype == 15) )
@@ -423,7 +394,7 @@ void openMbeOutFile (dsd_opts * opts, dsd_state * state)
state->tgcount = 0; state->tgcount = 0;
sprintf (opts->mbe_out_file, "%s %s S1%s", getDateF(), timestr, ext); sprintf (opts->mbe_out_file, "%s %s S1%s", datestr, timestr, ext);
sprintf (opts->mbe_out_path, "%s%s", opts->mbe_out_dir, opts->mbe_out_file); sprintf (opts->mbe_out_path, "%s%s", opts->mbe_out_dir, opts->mbe_out_file);
@@ -438,7 +409,16 @@ void openMbeOutFile (dsd_opts * opts, dsd_state * state)
fprintf (opts->mbe_out_f, "%s", ext); fprintf (opts->mbe_out_f, "%s", ext);
fflush (opts->mbe_out_f); fflush (opts->mbe_out_f);
free (timestr); //free allocated memory to prevent memory leak if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
} }
void openMbeOutFileR (dsd_opts * opts, dsd_state * state) void openMbeOutFileR (dsd_opts * opts, dsd_state * state)
@@ -447,7 +427,10 @@ void openMbeOutFileR (dsd_opts * opts, dsd_state * state)
int i, j; int i, j;
char ext[5]; char ext[5];
char * timestr; //add timestr here, so we can assign it and also free it to prevent memory leak char * timestr; //add timestr here, so we can assign it and also free it to prevent memory leak
timestr = getTimeF(); char * datestr;
timestr = getTime();
datestr = getDate();
//phase 1 and provoice //phase 1 and provoice
if ( (state->synctype == 0) || (state->synctype == 1) || (state->synctype == 14) || (state->synctype == 15) ) if ( (state->synctype == 0) || (state->synctype == 1) || (state->synctype == 14) || (state->synctype == 15) )
@@ -473,7 +456,7 @@ void openMbeOutFileR (dsd_opts * opts, dsd_state * state)
state->tgcount = 0; state->tgcount = 0;
sprintf (opts->mbe_out_fileR, "%s %s S2%s", getDateF(), timestr, ext); sprintf (opts->mbe_out_fileR, "%s %s S2%s", datestr, timestr, ext);
sprintf (opts->mbe_out_path, "%s%s", opts->mbe_out_dir, opts->mbe_out_fileR); sprintf (opts->mbe_out_path, "%s%s", opts->mbe_out_dir, opts->mbe_out_fileR);
@@ -488,7 +471,16 @@ void openMbeOutFileR (dsd_opts * opts, dsd_state * state)
fprintf (opts->mbe_out_fR, "%s", ext); fprintf (opts->mbe_out_fR, "%s", ext);
fflush (opts->mbe_out_fR); fflush (opts->mbe_out_fR);
free (timestr); //free allocated memory to prevent memory leak if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
} }
void openWavOutFile (dsd_opts * opts, dsd_state * state) void openWavOutFile (dsd_opts * opts, dsd_state * state)

View File

@@ -18,58 +18,32 @@
#include "dsd.h" #include "dsd.h"
#include <locale.h> #include <locale.h>
char * getTime(void) //get pretty hh:mm:ss timestamp
{
time_t t = time(NULL);
char * curr;
char * stamp = asctime(localtime( & t));
curr = strtok(stamp, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
return curr;
}
char * getDate(void) {
#ifdef AERO_BUILD
char datename[80];
#else
char datename[99];
#endif
char * curr2;
struct tm * to;
time_t t;
t = time(NULL);
to = localtime( & t);
strftime(datename, sizeof(datename), "%Y-%m-%d", to);
curr2 = strtok(datename, " ");
return curr2;
}
void void
printFrameSync (dsd_opts * opts, dsd_state * state, char *frametype, int offset, char *modulation) printFrameSync (dsd_opts * opts, dsd_state * state, char *frametype, int offset, char *modulation)
{ {
UNUSED3(state, offset, modulation); UNUSED3(state, offset, modulation);
char * timestr = getTimeC();
if (opts->verbose > 0) if (opts->verbose > 0)
{ {
fprintf (stderr,"%s ", getTime()); fprintf (stderr,"%s ", timestr);
fprintf (stderr,"Sync: %s ", frametype); fprintf (stderr,"Sync: %s ", frametype);
} }
if (opts->verbose > 2)
{ //oops, that made a nested if-if-if-if statement,
//causing a memory leak
// if (opts->verbose > 2)
//fprintf (stderr,"o: %4i ", offset); //fprintf (stderr,"o: %4i ", offset);
} // if (opts->verbose > 1)
if (opts->verbose > 1)
{
//fprintf (stderr,"mod: %s ", modulation); //fprintf (stderr,"mod: %s ", modulation);
} // if (opts->verbose > 2)
if (opts->verbose > 2)
{
//fprintf (stderr,"g: %f ", state->aout_gain); //fprintf (stderr,"g: %f ", state->aout_gain);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
} }
} }

View File

@@ -119,10 +119,14 @@ void lip_protocol_decoder (dsd_opts * opts, dsd_state * state, uint8_t * input)
FILE * pFile; //file pointer FILE * pFile; //file pointer
if (opts->lrrp_file_output == 1) if (opts->lrrp_file_output == 1)
{ {
char * datestr = getDate();
char * timestr = getTime();
//open file by name that is supplied in the ncurses terminal, or cli //open file by name that is supplied in the ncurses terminal, or cli
pFile = fopen (opts->lrrp_out_file, "a"); pFile = fopen (opts->lrrp_out_file, "a");
fprintf (pFile, "%s\t", getDateL() ); fprintf (pFile, "%s\t", datestr );
fprintf (pFile, "%s\t", getTimeL() ); fprintf (pFile, "%s\t", timestr );
fprintf (pFile, "%08d\t", add_hash); fprintf (pFile, "%08d\t", add_hash);
fprintf (pFile, "%.5lf\t", latitude); fprintf (pFile, "%.5lf\t", latitude);
fprintf (pFile, "%.5lf\t", longitude); fprintf (pFile, "%.5lf\t", longitude);
@@ -131,6 +135,17 @@ void lip_protocol_decoder (dsd_opts * opts, dsd_state * state, uint8_t * input)
fprintf (pFile, "\n"); fprintf (pFile, "\n");
fclose (pFile); fclose (pFile);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
} }
} }
@@ -219,14 +234,18 @@ void nmea_iec_61162_1 (dsd_opts * opts, dsd_state * state, uint8_t * input, uint
FILE * pFile; //file pointer FILE * pFile; //file pointer
if (opts->lrrp_file_output == 1) if (opts->lrrp_file_output == 1)
{ {
char * datestr = getDate();
char * timestr = getTime();
int s = (int)fkph; //rounded interger format for the log report int s = (int)fkph; //rounded interger format for the log report
int a = 0; int a = 0;
if (type == 2) if (type == 2)
a = nmea_cog; //long format only a = nmea_cog; //long format only
//open file by name that is supplied in the ncurses terminal, or cli //open file by name that is supplied in the ncurses terminal, or cli
pFile = fopen (opts->lrrp_out_file, "a"); pFile = fopen (opts->lrrp_out_file, "a");
fprintf (pFile, "%s\t", getDateL() ); fprintf (pFile, "%s\t", datestr );
fprintf (pFile, "%s\t", getTimeL() ); //could switch to UTC time if desired, but would require local user offset fprintf (pFile, "%s\t", timestr ); //could switch to UTC time if desired, but would require local user offset
fprintf (pFile, "%08d\t", src); fprintf (pFile, "%08d\t", src);
fprintf (pFile, "%.6lf\t", latitude); fprintf (pFile, "%.6lf\t", latitude);
fprintf (pFile, "%.6lf\t", longitude); fprintf (pFile, "%.6lf\t", longitude);
@@ -235,6 +254,17 @@ void nmea_iec_61162_1 (dsd_opts * opts, dsd_state * state, uint8_t * input, uint
fprintf (pFile, "\n"); fprintf (pFile, "\n");
fclose (pFile); fclose (pFile);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
} }
} }
@@ -337,14 +367,18 @@ void nmea_harris (dsd_opts * opts, dsd_state * state, uint8_t * input, uint32_t
FILE * pFile; //file pointer FILE * pFile; //file pointer
if (opts->lrrp_file_output == 1) if (opts->lrrp_file_output == 1)
{ {
char * datestr = getDate();
char * timestr = getTime();
//rounded interger formats for the log report //rounded interger formats for the log report
int s = (int)fkph; int s = (int)fkph;
int a = nmea_cog; int a = nmea_cog;
//open file by name that is supplied in the ncurses terminal, or cli //open file by name that is supplied in the ncurses terminal, or cli
pFile = fopen (opts->lrrp_out_file, "a"); pFile = fopen (opts->lrrp_out_file, "a");
fprintf (pFile, "%s\t", getDateL() ); fprintf (pFile, "%s\t", datestr );
fprintf (pFile, "%s\t", getTimeL() ); //could switch to UTC time on PDU if desired fprintf (pFile, "%s\t", timestr ); //could switch to UTC time on PDU if desired
fprintf (pFile, "%08d\t", src); fprintf (pFile, "%08d\t", src);
fprintf (pFile, "%.6lf\t", latitude); fprintf (pFile, "%.6lf\t", latitude);
fprintf (pFile, "%.6lf\t", longitude); fprintf (pFile, "%.6lf\t", longitude);
@@ -353,6 +387,17 @@ void nmea_harris (dsd_opts * opts, dsd_state * state, uint8_t * input, uint32_t
fprintf (pFile, "\n"); fprintf (pFile, "\n");
fclose (pFile); fclose (pFile);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
} }
//NOTE: There seems to be a few more octets left undecoded in this PDU //NOTE: There seems to be a few more octets left undecoded in this PDU
@@ -464,10 +509,14 @@ void harris_gps(dsd_opts * opts, dsd_state * state, int slot, uint8_t * input)
FILE * pFile; //file pointer FILE * pFile; //file pointer
if (opts->lrrp_file_output == 1) if (opts->lrrp_file_output == 1)
{ {
char * datestr = getDate();
char * timestr = getTime();
//open file by name that is supplied in the ncurses terminal, or cli //open file by name that is supplied in the ncurses terminal, or cli
pFile = fopen (opts->lrrp_out_file, "a"); pFile = fopen (opts->lrrp_out_file, "a");
fprintf (pFile, "%s\t", getDateL() ); fprintf (pFile, "%s\t", datestr );
fprintf (pFile, "%s\t", getTimeL() ); fprintf (pFile, "%s\t", timestr );
fprintf (pFile, "%08d\t", src); fprintf (pFile, "%08d\t", src);
fprintf (pFile, "%.6lf\t", lat_dec); fprintf (pFile, "%.6lf\t", lat_dec);
fprintf (pFile, "%.6lf\t", lon_dec); fprintf (pFile, "%.6lf\t", lon_dec);
@@ -476,6 +525,17 @@ void harris_gps(dsd_opts * opts, dsd_state * state, int slot, uint8_t * input)
fprintf (pFile, "\n"); fprintf (pFile, "\n");
fclose (pFile); fclose (pFile);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
} }
//NOTE: Thanks to DSheirer (SDRTrunk) for helping me work out a few of the things in here //NOTE: Thanks to DSheirer (SDRTrunk) for helping me work out a few of the things in here
@@ -561,14 +621,18 @@ void dmr_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[])
FILE * pFile; //file pointer FILE * pFile; //file pointer
if (opts->lrrp_file_output == 1) if (opts->lrrp_file_output == 1)
{ {
char * datestr = getDate();
char * timestr = getTime();
int src = 0; int src = 0;
if (slot == 0) src = state->lasttg; if (slot == 0) src = state->lasttg;
if (slot == 1) src = state->lasttgR; if (slot == 1) src = state->lasttgR;
//open file by name that is supplied in the ncurses terminal, or cli //open file by name that is supplied in the ncurses terminal, or cli
pFile = fopen (opts->lrrp_out_file, "a"); pFile = fopen (opts->lrrp_out_file, "a");
fprintf (pFile, "%s\t", getDateL() ); fprintf (pFile, "%s\t", datestr );
fprintf (pFile, "%s\t", getTimeL() ); fprintf (pFile, "%s\t", timestr );
fprintf (pFile, "%08d\t", src); fprintf (pFile, "%08d\t", src);
fprintf (pFile, "%.5lf\t", latitude); fprintf (pFile, "%.5lf\t", latitude);
fprintf (pFile, "%.5lf\t", longitude); fprintf (pFile, "%.5lf\t", longitude);
@@ -667,10 +731,13 @@ void apx_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[])
if (slot == 0) src = state->lastsrc; if (slot == 0) src = state->lastsrc;
if (slot == 1) src = state->lastsrcR; if (slot == 1) src = state->lastsrcR;
char * datestr = getDate();
char * timestr = getTime();
//open file by name that is supplied in the ncurses terminal, or cli //open file by name that is supplied in the ncurses terminal, or cli
pFile = fopen (opts->lrrp_out_file, "a"); pFile = fopen (opts->lrrp_out_file, "a");
fprintf (pFile, "%s\t", getDateL() ); fprintf (pFile, "%s\t", datestr );
fprintf (pFile, "%s\t", getTimeL() ); fprintf (pFile, "%s\t", timestr );
fprintf (pFile, "%08d\t", src); fprintf (pFile, "%08d\t", src);
fprintf (pFile, "%.5lf\t", latitude); fprintf (pFile, "%.5lf\t", latitude);
fprintf (pFile, "%.5lf\t", longitude); fprintf (pFile, "%.5lf\t", longitude);
@@ -679,6 +746,17 @@ void apx_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[])
fprintf (pFile, "\n"); fprintf (pFile, "\n");
fclose (pFile); fclose (pFile);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
} }
} }

View File

@@ -948,6 +948,7 @@ initState (dsd_state * state)
state->debug_audio_errorsR = 0; state->debug_audio_errorsR = 0;
state->debug_header_errors = 0; state->debug_header_errors = 0;
state->debug_header_critical_errors = 0; state->debug_header_critical_errors = 0;
state->debug_mode = 0;
state->nxdn_last_ran = -1; state->nxdn_last_ran = -1;
state->nxdn_last_rid = 0; state->nxdn_last_rid = 0;
@@ -1694,7 +1695,7 @@ main (int argc, char **argv)
exitflag = 0; exitflag = 0;
while ((c = getopt (argc, argv, "yhaepPqs:t:v:z:i:o:d:c:g:n:w:B:C:R:f:m:u:x:A:S:M:G:D:L:V:U:YK:b:H:X:NQ:WrlZTF01:2:345:6:7:89Ek:I:")) != -1) while ((c = getopt (argc, argv, "yhaepPqs:t:v:z:i:o:d:c:g:n:w:B:C:R:f:m:u:x:A:S:M:G:D:L:V:U:YK:b:H:X:NQ:WrlZTF01:2:345:6:7:89Ek:I:J")) != -1)
{ {
opterr = 0; opterr = 0;
switch (c) switch (c)
@@ -1708,8 +1709,8 @@ main (int argc, char **argv)
opts.call_alert = 1; opts.call_alert = 1;
break; break;
//Free'd up switches include: I, J, j, n, O, v, y //Free'd up switches include: j, O,
//all numerals have reclaimed, except for 4 and 0,1 (rc4 enforcement and single key) //
//make sure to put a colon : after each if they need an argument //make sure to put a colon : after each if they need an argument
//or remove colon if no argument required //or remove colon if no argument required
@@ -1717,6 +1718,12 @@ main (int argc, char **argv)
//NOTE: The 'K' option for single BP key has been swapped to 'b' //NOTE: The 'K' option for single BP key has been swapped to 'b'
//'K' is now used for hexidecimal key.csv imports //'K' is now used for hexidecimal key.csv imports
//this is a debug option hidden from users, but use it to replay .bin files on loop
case 'J':
state.debug_mode = 1;
fprintf (stderr, "Debug Mode Enabled; \n");
break;
//Specify M17 encoder User Data (CAN, DST, SRC values) //Specify M17 encoder User Data (CAN, DST, SRC values)
//NOTE: Disabled QPSK settings by borrowing these switches (nobody probalby used them anyways) //NOTE: Disabled QPSK settings by borrowing these switches (nobody probalby used them anyways)
case 'M': case 'M':

View File

@@ -30,7 +30,8 @@ uint32_t temp_freq = -1;
struct stat st_wav = {0}; struct stat st_wav = {0};
static char alias_ch[10][50]; static char alias_ch[10][50];
int reset = 0; int reset = 0;
char * timestr;
int tg; int tg;
int tgR; int tgR;
int tgn; int tgn;
@@ -256,65 +257,8 @@ void beeper (dsd_opts * opts, dsd_state * state, int lr)
} }
char * getDateN(void) {
#ifdef AERO_BUILD
char datename[80];
#else
char datename[99];
#endif
char * curr2;
struct tm * to;
time_t t;
t = time(NULL);
to = localtime( & t);
strftime(datename, sizeof(datename), "%Y%m%d", to);
curr2 = strtok(datename, " ");
return curr2;
}
time_t nowN; time_t nowN;
//fix from YorgosTheodorakis fork -- https://github.com/YorgosTheodorakis/dsd-fme/commit/7884ee555521a887d388152b3b1f11f20433a94b
char * getTimeN(void) //get pretty hhmmss timestamp
{
char * curr = (char *) malloc(9);
time_t t = time(NULL);
struct tm * ptm = localtime(& t);
sprintf(
curr,
"%02d%02d%02d",
ptm->tm_hour,
ptm->tm_min,
ptm->tm_sec
);
return curr;
}
//this version is broken now in Cygwin with the 80 value, reverted back
char * getDateC(time_t t) {
char datename[99];
char * curr2;
struct tm * to;
to = localtime( & t);
strftime(datename, sizeof(datename), "%Y-%m-%d", to);
curr2 = strtok(datename, " ");
return curr2;
}
char * getTimeC(time_t t) //get pretty hh:mm:ss timestamp
{
char * curr;
char * stamp = asctime(localtime( & t));
curr = strtok(stamp, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
return curr;
}
int isCustomAfsString(dsd_state * state) { int isCustomAfsString(dsd_state * state) {
return state->edacs_a_bits != 4 || state->edacs_f_bits != 4 || state->edacs_s_bits != 3; return state->edacs_a_bits != 4 || state->edacs_f_bits != 4 || state->edacs_s_bits != 3;
} }
@@ -710,7 +654,19 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state)
print_menuc(test_win, highlightc); print_menuc(test_win, highlightc);
if (choicec == 2) if (choicec == 2)
{ {
sprintf (opts->wav_out_file, "%s %s DSD-FME-DECODED.wav", getDateN(), timestr); char * timestr = getTime();
char * datestr = getDate();
sprintf (opts->wav_out_file, "%s %s DSD-FME-DECODED.wav", datestr, timestr);
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
openWavOutFile (opts, state); openWavOutFile (opts, state);
} }
if (choicec == 3) if (choicec == 3)
@@ -2004,7 +1960,14 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
uint8_t idas = 0; uint8_t idas = 0;
int level = 0; int level = 0;
int c = 0; int c = 0;
timestr = getTimeN();
//for filenames (no colons, etc)
char * timestr = getTime();
char * datestr = getDate();
//NOTE: Any times associates with call history are stored
//in the array and need to be set by passing those values into
//getTimeN and getDateN
if (opts->audio_in_type != 1) //can't run getch/menu when using STDIN - if (opts->audio_in_type != 1) //can't run getch/menu when using STDIN -
{ {
@@ -2187,7 +2150,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
{ {
//close old first, assign name based on time and radio, open wav file //close old first, assign name based on time and radio, open wav file
closeWavOutFileL (opts, state); closeWavOutFileL (opts, state);
sprintf (opts->wav_out_file, "./%s/%s %s NXDN - RAN %d - TGT %d - SRC %d.wav", opts->wav_out_dir, getDateN(), timestr, rn, tgn, src); sprintf (opts->wav_out_file, "./%s/%s %s NXDN - RAN %d - TGT %d - SRC %d.wav", opts->wav_out_dir, datestr, timestr, rn, tgn, src);
openWavOutFileL (opts, state); //testing for now, will want to move to per call later openWavOutFileL (opts, state); //testing for now, will want to move to per call later
} }
@@ -2232,7 +2195,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
{ {
//close old first, assign name based on time and radio, open wav file //close old first, assign name based on time and radio, open wav file
closeWavOutFileL (opts, state); closeWavOutFileL (opts, state);
sprintf (opts->wav_out_file, "./%s/%s %s MS - CC %d - TG %d - RD %d.wav", opts->wav_out_dir, getDateN(), timestr, dcc, tg, rd); sprintf (opts->wav_out_file, "./%s/%s %s MS - CC %d - TG %d - RD %d.wav", opts->wav_out_dir, datestr, timestr, dcc, tg, rd);
openWavOutFileL (opts, state); //testing for now, will want to move to per call later openWavOutFileL (opts, state); //testing for now, will want to move to per call later
} }
@@ -2275,7 +2238,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
//close old first, assign name based on time and radio, open wav file //close old first, assign name based on time and radio, open wav file
closeWavOutFileL (opts, state); closeWavOutFileL (opts, state);
sprintf (opts->wav_out_file, "./%s/%s %s CC %d - TG %d - RD %d.wav", opts->wav_out_dir, getDateN(), timestr, dcc, tg, rd); sprintf (opts->wav_out_file, "./%s/%s %s CC %d - TG %d - RD %d.wav", opts->wav_out_dir, datestr, timestr, dcc, tg, rd);
openWavOutFileL (opts, state); //testing for now, will want to move to per call later openWavOutFileL (opts, state); //testing for now, will want to move to per call later
} }
@@ -2317,7 +2280,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
{ {
//close old first, assign name based on time and radio, open wav file //close old first, assign name based on time and radio, open wav file
closeWavOutFileR (opts, state); closeWavOutFileR (opts, state);
sprintf (opts->wav_out_fileR, "./%s/%s %s CC %d - TG %d - RD %d.wav", opts->wav_out_dir, getDateN(), timestr, dcc, tgR, rdR); sprintf (opts->wav_out_fileR, "./%s/%s %s CC %d - TG %d - RD %d.wav", opts->wav_out_dir, datestr, timestr, dcc, tgR, rdR);
openWavOutFileR (opts, state); //testing for now, will want to move to per call later openWavOutFileR (opts, state); //testing for now, will want to move to per call later
} }
@@ -2358,7 +2321,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
{ {
//close old first, assign name based on time and radio, open wav file //close old first, assign name based on time and radio, open wav file
closeWavOutFileL (opts, state); closeWavOutFileL (opts, state);
sprintf (opts->wav_out_file, "./%s/%s %s P1 - NAC %X - TGT %d - SRC %d.wav", opts->wav_out_dir, getDateN(), timestr, nc, tg, rd); sprintf (opts->wav_out_file, "./%s/%s %s P1 - NAC %X - TGT %d - SRC %d.wav", opts->wav_out_dir, datestr, timestr, nc, tg, rd);
openWavOutFileL (opts, state); //testing for now, will want to move to per call later openWavOutFileL (opts, state); //testing for now, will want to move to per call later
} }
@@ -2431,6 +2394,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
printw("%s", FM_bannerN[i]); printw("%s", FM_bannerN[i]);
if (i == 1) printw (" ESC to Menu"); if (i == 1) printw (" ESC to Menu");
if (i == 2) printw (" 'q' to Quit "); if (i == 2) printw (" 'q' to Quit ");
if (i == 3 && state->debug_mode == 1) printw (" DEBUG MODE!");
if (i == 4 && opts->frame_m17 == 0) printw (" MBElib %s", versionstr); if (i == 4 && opts->frame_m17 == 0) printw (" MBElib %s", versionstr);
#ifdef USE_CODEC2 #ifdef USE_CODEC2
if (i == 4 && opts->frame_m17 == 1) printw (" CODEC2"); if (i == 4 && opts->frame_m17 == 1) printw (" CODEC2");
@@ -3850,11 +3814,23 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
//only print if a valid time was assigned to the matrix, and not EDACS/PV, and source is not zero //only print if a valid time was assigned to the matrix, and not EDACS/PV, and source is not zero
if ( ((time(NULL) - call_matrix[9-j][5]) < 999999) && call_matrix[9-j][0] != 14 && call_matrix[9-j][0] != 15 && call_matrix[9-j][0] != 37 && call_matrix[9-j][0] != 38 && call_matrix[9-j][2] != 0) // if ( ((time(NULL) - call_matrix[9-j][5]) < 999999) && call_matrix[9-j][0] != 14 && call_matrix[9-j][0] != 15 && call_matrix[9-j][0] != 37 && call_matrix[9-j][0] != 38 && call_matrix[9-j][2] != 0) //
{ {
// printw ("| %s ", SyncTypes[call_matrix[9-j][0]]); //sync type char * timestrCH = getTimeN(call_matrix[9-j][5]);
char * datestrCH = getDateN(call_matrix[9-j][5]);
printw ("| "); printw ("| ");
printw ("%s ", getDateC(call_matrix[9-j][5]) ); printw ("%s ", datestrCH);
printw ("%s ", getTimeC(call_matrix[9-j][5]) ); printw ("%s ", timestrCH);
if (datestrCH != NULL)
{
free (datestrCH);
datestrCH = NULL;
}
if (timestrCH != NULL)
{
free (timestrCH);
timestrCH = NULL;
}
if (lls == 28 || lls == 29) if (lls == 28 || lls == 29)
{ {
@@ -3925,8 +3901,23 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
if (call_matrix[j][2] != 0) if (call_matrix[j][2] != 0)
{ {
printw ("| "); printw ("| ");
printw ("%s ", getDateC(call_matrix[j][5]) ); char * timestrCHE = getTimeN(call_matrix[j][5]);
printw ("%s ", getTimeC(call_matrix[j][5]) ); char * datestrCHE = getDateN(call_matrix[j][5]);
printw ("%s ", datestrCHE);
printw ("%s ", timestrCHE);
if (datestrCHE != NULL)
{
free (datestrCHE);
datestrCHE = NULL;
}
if (timestrCHE != NULL)
{
free (timestrCHE);
timestrCHE = NULL;
}
printw ("LCN [%2lld] ", call_matrix[j][1]); printw ("LCN [%2lld] ", call_matrix[j][1]);
if (state->ea_mode == 1) if (state->ea_mode == 1)
{ {
@@ -4309,7 +4300,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
if (c == 82) //'R', save symbol capture bin with date/time string as name if (c == 82) //'R', save symbol capture bin with date/time string as name
{ {
sprintf (opts->symbol_out_file, "%s %s.bin", getDateN(), timestr); sprintf (opts->symbol_out_file, "%s %s.bin", datestr, timestr);
openSymbolOutFile (opts, state); openSymbolOutFile (opts, state);
} }
@@ -4876,11 +4867,20 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
//so probably just write a function to handle c input, and when c = certain values //so probably just write a function to handle c input, and when c = certain values
//needing an entry box, then stop all of those //needing an entry box, then stop all of those
//allocated memory pointer needs to be free'd each time
//if issues arise, just delete this line.
//TODO: Redo this in edacs and file, making a seperate char * timestr instead of calling GetTime
//directly from the sprintf command //allocated memory pointer needs to be free'd
if (timestr != NULL)
{
free (timestr); free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
} //end ncursesPrinter } //end ncursesPrinter

View File

@@ -658,8 +658,15 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync)
// opts->audio_in_type = 0; //switch to pulse after playback, ncurses terminal can initiate replay if wanted // opts->audio_in_type = 0; //switch to pulse after playback, ncurses terminal can initiate replay if wanted
fclose(opts->symbolfile); fclose(opts->symbolfile);
fprintf (stderr, "\nEnd of %s\n", opts->audio_in_dev); fprintf (stderr, "\nEnd of %s\n", opts->audio_in_dev);
//in debug mode, re-run .bin files over and over (look for memory leaks, etc)
if (state->debug_mode == 1)
{
opts->symbolfile = NULL;
opts->symbolfile = fopen(opts->audio_in_dev, "r");
opts->audio_in_type = 4; //symbol capture bin files
}
//open pulse input if we are pulse output AND using ncurses terminal //open pulse input if we are pulse output AND using ncurses terminal
if (opts->audio_out_type == 0 && opts->use_ncurses_terminal == 1) else if (opts->audio_out_type == 0 && opts->use_ncurses_terminal == 1)
{ {
opts->audio_in_type = 0; //set input type opts->audio_in_type = 0; //set input type
openPulseInput(opts); //open pulse input openPulseInput(opts); //open pulse input

71
src/dsd_time.c Normal file
View File

@@ -0,0 +1,71 @@
/*-------------------------------------------------------------------------------
* dsd_time.c
* Time and Date Functions
*
* LWVMOBILE
* 2024-04 DSD-FME Florida Man Edition
*-----------------------------------------------------------------------------*/
//TODO: Make sure everything still works as intended, every free(timestr) has a NULL check first,
//make sure no other loose or random time functions embedded in other files or functions, etc
#include "dsd.h"
//get HHmmss timestamp no colon (file operations)
char * getTime()
{
char * curr = calloc(7, sizeof(char));
time_t t = time(NULL);
struct tm * ptm = localtime(& t);
sprintf(curr,"%02d%02d%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
return curr;
}
//get HH:mm:ss timestamp with colon (Sync/Console Display)
char * getTimeC()
{
char * curr = calloc(9, sizeof(char));
time_t t = time(NULL);
struct tm * ptm = localtime(& t);
sprintf(curr, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
return curr;
}
//get HH:mm:ss timestamp with colon (Ncurses Call History)
char * getTimeN(time_t t)
{
char * curr = calloc(9, sizeof(char));
struct tm * ptm = localtime(& t);
sprintf(curr, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
return curr;
}
//get YYYYMMDD without hyphen (file operations)
char * getDate()
{
char * curr = calloc(25, sizeof(char));
time_t t = time(NULL);
struct tm * ptm = localtime(& t);
sprintf(curr,"%04d%02d%02d", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday);
return curr;
}
//get YYYY-MM-DD with hyphen (Sync/Console Display)
char * getDateH()
{
char * curr = calloc(27, sizeof(char));
time_t t = time(NULL);
struct tm * ptm = localtime(& t);
sprintf(curr, "%04d-%02d-%02d", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday);
return curr;
}
//get YYYY-MM-DD with hyphen (Ncurses Call History)
char * getDateN(time_t t)
{
char * curr = calloc(27, sizeof(char));
struct tm * ptm = localtime(& t);
sprintf(curr, "%04d-%02d-%02d", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday);
return curr;
}

View File

@@ -21,38 +21,6 @@
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
#include "dsd.h" #include "dsd.h"
char * getDateE(void) {
#ifdef AERO_BUILD
char datename[80];
#else
char datename[99];
#endif
char * curr2;
struct tm * to;
time_t t;
t = time(NULL);
to = localtime( & t);
strftime(datename, sizeof(datename), "%Y%m%d", to);
curr2 = strtok(datename, " ");
return curr2;
}
//fix from YorgosTheodorakis fork -- https://github.com/YorgosTheodorakis/dsd-fme/commit/7884ee555521a887d388152b3b1f11f20433a94b
char * getTimeE(void) //get pretty hhmmss timestamp
{
char * curr = (char *) malloc(9);
time_t t = time(NULL);
struct tm * ptm = localtime(& t);
sprintf(
curr,
"%02d%02d%02d",
ptm->tm_hour,
ptm->tm_min,
ptm->tm_sec
);
return curr;
}
char * getLcnStatusString(int lcn) char * getLcnStatusString(int lcn)
{ {
if (lcn == 26 || lcn == 27) if (lcn == 26 || lcn == 27)
@@ -472,8 +440,10 @@ void edacs(dsd_opts * opts, dsd_state * state)
state->edacs_f_mask = (1 << state->edacs_f_bits) - 1; state->edacs_f_mask = (1 << state->edacs_f_bits) - 1;
state->edacs_s_mask = (1 << state->edacs_s_bits) - 1; state->edacs_s_mask = (1 << state->edacs_s_bits) - 1;
char * timestr; //add timestr here, so we can assign it and also free it to prevent memory leak char * timestr = NULL;
timestr = getTimeE(); char * datestr = NULL;
timestr = getTime();
datestr = getDate();
state->edacs_vc_lcn = -1; //init on negative for ncurses and tuning state->edacs_vc_lcn = -1; //init on negative for ncurses and tuning
@@ -1000,7 +970,7 @@ void edacs(dsd_opts * opts, dsd_state * state)
//openwav file and do per call right here, should probably check as well to make sure we have a valid trunking method active (rigctl, rtl) //openwav file and do per call right here, should probably check as well to make sure we have a valid trunking method active (rigctl, rtl)
if (opts->dmr_stereo_wav == 1 && (opts->use_rigctl == 1 || opts->audio_in_type == 3)) if (opts->dmr_stereo_wav == 1 && (opts->use_rigctl == 1 || opts->audio_in_type == 3))
{ {
sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld TG %d SRC %d.wav", getDateE(), timestr, state->edacs_site_id, group, source); sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld TG %d SRC %d.wav", datestr, timestr, state->edacs_site_id, group, source);
if (is_digital == 1) if (is_digital == 1)
openWavOutFile (opts, state); openWavOutFile (opts, state);
else else
@@ -1115,7 +1085,7 @@ void edacs(dsd_opts * opts, dsd_state * state)
//openwav file and do per call right here, should probably check as well to make sure we have a valid trunking method active (rigctl, rtl) //openwav file and do per call right here, should probably check as well to make sure we have a valid trunking method active (rigctl, rtl)
if (opts->dmr_stereo_wav == 1 && (opts->use_rigctl == 1 || opts->audio_in_type == 3)) if (opts->dmr_stereo_wav == 1 && (opts->use_rigctl == 1 || opts->audio_in_type == 3))
{ {
sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld TGT %d SRC %d I-Call.wav", getDateE(), timestr, state->edacs_site_id, target, source); sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld TGT %d SRC %d I-Call.wav", datestr, timestr, state->edacs_site_id, target, source);
if (is_digital == 1) if (is_digital == 1)
openWavOutFile (opts, state); openWavOutFile (opts, state);
else else
@@ -1221,7 +1191,7 @@ void edacs(dsd_opts * opts, dsd_state * state)
//openwav file and do per call right here, should probably check as well to make sure we have a valid trunking method active (rigctl, rtl) //openwav file and do per call right here, should probably check as well to make sure we have a valid trunking method active (rigctl, rtl)
if (opts->dmr_stereo_wav == 1 && (opts->use_rigctl == 1 || opts->audio_in_type == 3)) if (opts->dmr_stereo_wav == 1 && (opts->use_rigctl == 1 || opts->audio_in_type == 3))
{ {
sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld SRC %d All-Call.wav", getDateE(), timestr, state->edacs_site_id, source); sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld SRC %d All-Call.wav", datestr, timestr, state->edacs_site_id, source);
if (is_digital == 1) if (is_digital == 1)
openWavOutFile (opts, state); openWavOutFile (opts, state);
else else
@@ -1400,7 +1370,7 @@ void edacs(dsd_opts * opts, dsd_state * state)
//openwav file and do per call right here //openwav file and do per call right here
if (opts->dmr_stereo_wav == 1 && (opts->use_rigctl == 1 || opts->audio_in_type == 3)) if (opts->dmr_stereo_wav == 1 && (opts->use_rigctl == 1 || opts->audio_in_type == 3))
{ {
sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld TG %04d SRC %05d.wav", getDateE(), timestr, state->edacs_site_id, group, lid); sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld TG %04d SRC %05d.wav", datestr, timestr, state->edacs_site_id, group, lid);
if (is_digital == 0) openWavOutFile48k (opts, state); //analog at 48k if (is_digital == 0) openWavOutFile48k (opts, state); //analog at 48k
else openWavOutFile (opts, state); //digital else openWavOutFile (opts, state); //digital
} }
@@ -1652,8 +1622,8 @@ void edacs(dsd_opts * opts, dsd_state * state)
//openwav file and do per call right here //openwav file and do per call right here
if (opts->dmr_stereo_wav == 1 && (opts->use_rigctl == 1 || opts->audio_in_type == 3)) if (opts->dmr_stereo_wav == 1 && (opts->use_rigctl == 1 || opts->audio_in_type == 3))
{ {
if (is_individual == 0) sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld TG %04d SRC %05d.wav", getDateE(), timestr, state->edacs_site_id, target, state->lastsrc); if (is_individual == 0) sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld TG %04d SRC %05d.wav", datestr, timestr, state->edacs_site_id, target, state->lastsrc);
else sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld TGT %05d SRC %05d I-Call.wav", getDateE(), timestr, state->edacs_site_id, target, state->lastsrc); else sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld TGT %05d SRC %05d I-Call.wav", datestr, timestr, state->edacs_site_id, target, state->lastsrc);
if (is_digital == 0) openWavOutFile48k (opts, state); //analog at 48k if (is_digital == 0) openWavOutFile48k (opts, state); //analog at 48k
else openWavOutFile (opts, state); //digital else openWavOutFile (opts, state); //digital
} }
@@ -1763,7 +1733,7 @@ void edacs(dsd_opts * opts, dsd_state * state)
//openwav file and do per call right here //openwav file and do per call right here
if (opts->dmr_stereo_wav == 1 && (opts->use_rigctl == 1 || opts->audio_in_type == 3)) if (opts->dmr_stereo_wav == 1 && (opts->use_rigctl == 1 || opts->audio_in_type == 3))
{ {
sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld TGT %05d SRC %05d I-Call.wav", getDateE(), timestr, state->edacs_site_id, target, state->lastsrc); sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld TGT %05d SRC %05d I-Call.wav", datestr, timestr, state->edacs_site_id, target, state->lastsrc);
if (is_digital == 0) openWavOutFile48k (opts, state); //analog at 48k if (is_digital == 0) openWavOutFile48k (opts, state); //analog at 48k
else openWavOutFile (opts, state); //digital else openWavOutFile (opts, state); //digital
} }
@@ -2056,7 +2026,7 @@ void edacs(dsd_opts * opts, dsd_state * state)
//openwav file and do per call right here //openwav file and do per call right here
if (opts->dmr_stereo_wav == 1 && (opts->use_rigctl == 1 || opts->audio_in_type == 3)) if (opts->dmr_stereo_wav == 1 && (opts->use_rigctl == 1 || opts->audio_in_type == 3))
{ {
sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld SRC %05d All-Call.wav", getDateE(), timestr, state->edacs_site_id, state->lastsrc); sprintf (opts->wav_out_file, "./WAV/%s %s EDACS Site %lld SRC %05d All-Call.wav", datestr, timestr, state->edacs_site_id, state->lastsrc);
if (is_digital == 0) openWavOutFile48k (opts, state); //analog at 48k if (is_digital == 0) openWavOutFile48k (opts, state); //analog at 48k
else openWavOutFile (opts, state); //digital else openWavOutFile (opts, state); //digital
} }
@@ -2165,7 +2135,17 @@ void edacs(dsd_opts * opts, dsd_state * state)
} }
free (timestr); //free allocated memory to prevent memory leak if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (datestr != NULL)
{
free (datestr);
datestr = NULL;
}
fprintf (stderr, "\n"); fprintf (stderr, "\n");
} }

View File

@@ -846,22 +846,6 @@ void process_P2_DUID (dsd_opts * opts, dsd_state * state)
vc_counter = 0; vc_counter = 0;
int err_counter = 0; int err_counter = 0;
//add time to mirror printFrameSync
char * getTime(void) //get pretty hh:mm:ss timestamp
{
time_t t = time(NULL);
char * curr;
char * stamp = asctime(localtime( & t));
curr = strtok(stamp, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
return curr;
}
for (ts_counter = 0; ts_counter < 4; ts_counter++) //12 for (ts_counter = 0; ts_counter < 4; ts_counter++) //12
{ {
duid_decoded = -2; duid_decoded = -2;
@@ -884,10 +868,19 @@ void process_P2_DUID (dsd_opts * opts, dsd_state * state)
} }
duid_decoded = duid_lookup[p2_duid_complete]; duid_decoded = duid_lookup[p2_duid_complete];
char * timestr = getTimeC();
fprintf (stderr, "\n"); fprintf (stderr, "\n");
fprintf (stderr,"%s ", getTime()); fprintf (stderr,"%s ", timestr);
fprintf (stderr, " P25p2 "); fprintf (stderr, " P25p2 ");
if (timestr != NULL)
{
free (timestr);
timestr = NULL;
}
if (state->currentslot == 0 && duid_decoded != 3 && duid_decoded != 12 && duid_decoded != 13 && duid_decoded != 4) if (state->currentslot == 0 && duid_decoded != 3 && duid_decoded != 12 && duid_decoded != 13 && duid_decoded != 4)
{ {
fprintf (stderr, "LCH 0 "); fprintf (stderr, "LCH 0 ");