Fix and Consolidate Date and Time Functions (WIP); #255

This commit is contained in:
lwvmobile 2024-04-24 16:42:25 -04:00
parent 499134bc2d
commit 1ffddf823f
11 changed files with 240 additions and 333 deletions

View File

@ -1246,8 +1246,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_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[]);
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
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
void dmrBS (dsd_opts * opts, dsd_state * state)
{
int i, dibit;
char * timestr;
int i, dibit;
char ambe_fr[4][24];
char ambe_fr2[4][24];
char ambe_fr3[4][24];
@ -55,22 +56,6 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
uint8_t dummy_bits[196];
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
sprintf (state->slot1light, " slot1 ");
sprintf (state->slot2light, " slot2 ");
@ -114,6 +99,8 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
cleanupAndExit (opts, state);
}
timestr = getTimeC();
memset (ambe_fr, 0, sizeof(ambe_fr));
memset (ambe_fr2, 0, sizeof(ambe_fr2));
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 )
{
fprintf (stderr,"%s ", getTime());
fprintf (stderr,"%s ", timestr);
if (internalslot == 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
if (strcmp (sync, DMR_BS_DATA_SYNC) != 0 && internalslot == 0 && vc1 > 6)
{
fprintf (stderr,"%s ", getTime());
fprintf (stderr,"%s ", timestr);
//simplifying things
// 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
if (strcmp (sync, DMR_BS_DATA_SYNC) != 0 && internalslot == 1 && vc2 > 6)
{
fprintf (stderr,"%s ", getTime());
fprintf (stderr,"%s ", timestr);
//simplifying things
// char polarity[3];
@ -374,7 +361,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
skipcount = 0; //reset skip count if processing voice frames
fprintf (stderr,"%s ", getTime());
fprintf (stderr,"%s ", timestr);
//simplifying things
char polarity[3];
@ -585,7 +572,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
if (tact_okay != 1 || emb_ok != 1)
{
fprintf (stderr,"%s ", getTime());
fprintf (stderr,"%s ", timestr);
fprintf (stderr,"Sync: DMR ");
fprintf (stderr, "%s", KRED);
fprintf (stderr, "| VOICE CACH/EMB ERR");
@ -608,6 +595,8 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
}
free (timestr);
}
//Process buffered half frame and 2nd half and then jump to full BS decoding
@ -643,22 +632,9 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
11, 12, 2, 13, 14,
15, 3, 16, 4, 17, 18,
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 * stamp = asctime(localtime( & t));
curr = strtok(stamp, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
curr = strtok(NULL, " ");
return curr;
}
char * timestr = getTimeC();
//payload buffer
//CACH + First Half Payload + Sync = 12 + 54 + 24
@ -807,7 +783,7 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
fclose (pFile);
}
fprintf (stderr,"%s ", getTime());
fprintf (stderr,"%s ", timestr);
char polarity[3];
char light[18];
@ -909,7 +885,7 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
//if we have a tact err, then produce sync pattern/err message
if (tact_okay != 1 || sync_okay != 1)
{
fprintf (stderr,"%s ", getTime());
fprintf (stderr,"%s ", timestr);
fprintf (stderr,"Sync: DMR ");
fprintf (stderr, "%s", KRED);
fprintf (stderr, "| VOICE CACH/SYNC ERR");
@ -931,5 +907,6 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
dmr_reset_blocks (opts, state);
}
free (timestr);
}

View File

@ -13,6 +13,8 @@
void dmrMS (dsd_opts * opts, dsd_state * state)
{
char * timestr = getTimeC();
int i, j, dibit;
char ambe_fr[4][24];
char ambe_fr2[4][24];
@ -55,22 +57,6 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
uint8_t dummy_bits[196];
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;
//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)
{
state->dmr_ms_rc = 1;
fprintf (stderr, "%s ", getTime());
fprintf (stderr, "%s ", timestr);
if (opts->inverted_dmr == 0)
{
fprintf (stderr,"Sync: +DMR MS/DM MODE/MONO ");
@ -387,13 +373,17 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
state->dmr_ms_mode = 0;
state->dmr_ms_rc = 0;
state->directmode = 0; //flag off
free(timestr);
}
//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)
{
char * timestr = getTimeC();
int i, dibit;
int *dibit_p;
@ -417,22 +407,6 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
char cachdata[25];
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->currentslot = 0; //force to slot 0
@ -568,7 +542,7 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
fclose (pFile);
}
fprintf (stderr, "%s ", getTime());
fprintf (stderr, "%s ", timestr);
if (opts->inverted_dmr == 0)
{
fprintf (stderr,"Sync: +DMR MS/DM MODE/MONO ");
@ -644,6 +618,7 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
//errors due to skipping other slot
// cach_err = dmr_cach (opts, state, cachdata);
free (timestr);
skipDibit (opts, state, 144); //skip to next TDMA slot
dmrMS (opts, state); //bootstrap into full TDMA frame
@ -653,27 +628,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
void dmrMSData (dsd_opts * opts, dsd_state * state)
{
char * timestr = getTimeC();
int i;
int dibit;
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
dibit_p = state->dmr_payload_p - 90;
for (i = 0; i < 90; i++) //90
@ -691,7 +652,7 @@ void dmrMSData (dsd_opts * opts, dsd_state * state)
state->dmr_stereo_payload[i+90] = dibit;
}
fprintf (stderr, "%s ", getTime());
fprintf (stderr, "%s ", timestr);
if (opts->inverted_dmr == 0)
{
fprintf (stderr,"Sync: +DMR MS/DM MODE/MONO ");
@ -728,4 +689,6 @@ 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
}
free (timestr);
}

View File

@ -8,33 +8,6 @@
#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[])
{
@ -274,16 +247,21 @@ void dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DM
FILE * pFile; //file pointer
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
pFile = fopen (opts->lrrp_out_file, "a");
//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", getTimeL() ); //current timestamp, 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", 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
//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, "%08d\t", source); //add source form decoded audio if available, else its from the header
free (timestr);
free (datestr);
}
if (pot_report)

View File

@ -17,38 +17,6 @@
#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)
{
int i, j, k;
@ -397,7 +365,10 @@ void openMbeOutFile (dsd_opts * opts, dsd_state * state)
int i, j;
char ext[5];
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
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;
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);
@ -439,6 +410,7 @@ void openMbeOutFile (dsd_opts * opts, dsd_state * state)
fflush (opts->mbe_out_f);
free (timestr); //free allocated memory to prevent memory leak
free (datestr);
}
void openMbeOutFileR (dsd_opts * opts, dsd_state * state)
@ -447,7 +419,10 @@ void openMbeOutFileR (dsd_opts * opts, dsd_state * state)
int i, j;
char ext[5];
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
if ( (state->synctype == 0) || (state->synctype == 1) || (state->synctype == 14) || (state->synctype == 15) )
@ -473,7 +448,7 @@ void openMbeOutFileR (dsd_opts * opts, dsd_state * state)
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);
@ -489,6 +464,7 @@ void openMbeOutFileR (dsd_opts * opts, dsd_state * state)
fflush (opts->mbe_out_fR);
free (timestr); //free allocated memory to prevent memory leak
free (datestr);
}
void openWavOutFile (dsd_opts * opts, dsd_state * state)

View File

@ -18,45 +18,14 @@
#include "dsd.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
printFrameSync (dsd_opts * opts, dsd_state * state, char *frametype, int offset, char *modulation)
{
UNUSED3(state, offset, modulation);
char * timestr = getTimeC();
if (opts->verbose > 0)
{
fprintf (stderr,"%s ", getTime());
fprintf (stderr,"%s ", timestr);
fprintf (stderr,"Sync: %s ", frametype);
}
if (opts->verbose > 2)
@ -72,6 +41,8 @@ printFrameSync (dsd_opts * opts, dsd_state * state, char *frametype, int offset,
//fprintf (stderr,"g: %f ", state->aout_gain);
}
free (timestr);
}
int

View File

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

View File

@ -31,6 +31,9 @@ struct stat st_wav = {0};
static char alias_ch[10][50];
int reset = 0;
char * timestr;
char * datestr;
char * timestrC;
char * datestrH;
int tg;
int tgR;
int tgn;
@ -256,65 +259,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;
//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) {
return state->edacs_a_bits != 4 || state->edacs_f_bits != 4 || state->edacs_s_bits != 3;
}
@ -710,7 +656,7 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state)
print_menuc(test_win, highlightc);
if (choicec == 2)
{
sprintf (opts->wav_out_file, "%s %s DSD-FME-DECODED.wav", getDateN(), timestr);
sprintf (opts->wav_out_file, "%s %s DSD-FME-DECODED.wav", datestr, timestr);
openWavOutFile (opts, state);
}
if (choicec == 3)
@ -2004,7 +1950,14 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
uint8_t idas = 0;
int level = 0;
int c = 0;
timestr = getTimeN();
//for filenames (no colons, etc)
timestr = getTime();
datestr = getDate();
//for display
timestrC = getTimeC();
datestrH = getDateH();
if (opts->audio_in_type != 1) //can't run getch/menu when using STDIN -
{
@ -2187,7 +2140,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
{
//close old first, assign name based on time and radio, open wav file
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
}
@ -2232,7 +2185,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
{
//close old first, assign name based on time and radio, open wav file
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
}
@ -2275,7 +2228,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
//close old first, assign name based on time and radio, open wav file
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
}
@ -2317,7 +2270,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
{
//close old first, assign name based on time and radio, open wav file
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
}
@ -2358,7 +2311,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
{
//close old first, assign name based on time and radio, open wav file
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
}
@ -3850,11 +3803,15 @@ 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
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 * timeCH = getTimeN(call_matrix[9-j][5]);
char * dateCH = getDateN(call_matrix[9-j][5]);
printw ("| ");
printw ("%s ", getDateC(call_matrix[9-j][5]) );
printw ("%s ", getTimeC(call_matrix[9-j][5]) );
printw ("%s ", dateCH);
printw ("%s ", timeCH);
free (dateCH);
free (timeCH);
if (lls == 28 || lls == 29)
{
@ -3925,8 +3882,16 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
if (call_matrix[j][2] != 0)
{
printw ("| ");
printw ("%s ", getDateC(call_matrix[j][5]) );
printw ("%s ", getTimeC(call_matrix[j][5]) );
char * timeCHE = getTimeN(call_matrix[j][5]);
char * dateCHE = getDateN(call_matrix[j][5]);
printw ("| ");
printw ("%s ", dateCHE);
printw ("%s ", timeCHE);
free (dateCHE);
free (timeCHE);
printw ("LCN [%2lld] ", call_matrix[j][1]);
if (state->ea_mode == 1)
{
@ -4309,7 +4274,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
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);
}
@ -4881,6 +4846,9 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
//TODO: Redo this in edacs and file, making a seperate char * timestr instead of calling GetTime
//directly from the sprintf command
free (timestr);
free (datestr);
free (timestrC);
free (datestrH);
} //end ncursesPrinter

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, no random crashes on free (timestr)
//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 = (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;
}
//get hh:mm:ss timestamp with colon (Ncurses Display)
char * getTimeC()
{
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;
}
//get hh:mm:ss timestamp with colon (Ncurses Display)
char * getTimeN(time_t t)
{
char * curr = (char *) malloc(9);
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 = (char *) malloc(25);
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 Display)
char * getDateH()
{
char * curr = (char *) malloc(27);
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 = (char *) malloc(27);
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"
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)
{
if (lcn == 26 || lcn == 27)
@ -473,7 +441,9 @@ void edacs(dsd_opts * opts, dsd_state * state)
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
timestr = getTimeE();
char * datestr;
timestr = getTime();
datestr = getDate();
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)
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)
openWavOutFile (opts, state);
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)
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)
openWavOutFile (opts, state);
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)
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)
openWavOutFile (opts, state);
else
@ -1400,7 +1370,7 @@ void edacs(dsd_opts * opts, dsd_state * state)
//openwav file and do per call right here
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
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
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);
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);
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", datestr, timestr, state->edacs_site_id, target, state->lastsrc);
if (is_digital == 0) openWavOutFile48k (opts, state); //analog at 48k
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
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
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
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
else openWavOutFile (opts, state); //digital
}
@ -2166,6 +2136,7 @@ void edacs(dsd_opts * opts, dsd_state * state)
free (timestr); //free allocated memory to prevent memory leak
free (datestr);
fprintf (stderr, "\n");
}

View File

@ -846,22 +846,6 @@ void process_P2_DUID (dsd_opts * opts, dsd_state * state)
vc_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
{
duid_decoded = -2;
@ -884,9 +868,13 @@ void process_P2_DUID (dsd_opts * opts, dsd_state * state)
}
duid_decoded = duid_lookup[p2_duid_complete];
char * timestr = getTimeC();
fprintf (stderr, "\n");
fprintf (stderr,"%s ", getTime());
fprintf (stderr,"%s ", timestr);
fprintf (stderr, " P25p2 ");
free(timestr);
if (state->currentslot == 0 && duid_decoded != 3 && duid_decoded != 12 && duid_decoded != 13 && duid_decoded != 4)
{