mirror of
https://github.com/lwvmobile/dsd-fme.git
synced 2026-11-16 18:57:24 -05:00
DMR Reorganization; Initial Trunking Support;
This commit is contained in:
689
src/dmr_bs.c
689
src/dmr_bs.c
@@ -1,3 +1,11 @@
|
||||
/*-------------------------------------------------------------------------------
|
||||
* dmr_bs.c
|
||||
* DMR BS Voice Handling and Data Gathering Routines - "DMR STEREO"
|
||||
*
|
||||
* LWVMOBILE
|
||||
* 2022-12 DSD-FME Florida Man Edition
|
||||
*-----------------------------------------------------------------------------*/
|
||||
|
||||
#include "dsd.h"
|
||||
#include "dmr_const.h"
|
||||
|
||||
@@ -7,32 +15,37 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
||||
{
|
||||
int i, j, k, l, dibit;
|
||||
int *dibit_p;
|
||||
char ambe_fr[4][24] = {0};
|
||||
char ambe_fr2[4][24] = {0};
|
||||
char ambe_fr3[4][24] = {0};
|
||||
|
||||
char ambe_fr[4][24];
|
||||
char ambe_fr2[4][24];
|
||||
char ambe_fr3[4][24];
|
||||
|
||||
const int *w, *x, *y, *z;
|
||||
char sync[25] = {0};
|
||||
char syncdata[48] = {0};
|
||||
//char cachdata[13] = {0};
|
||||
int mutecurrentslot;
|
||||
int msMode;
|
||||
char cc[4];
|
||||
unsigned char EmbeddedSignalling[16] = {0};
|
||||
int EmbeddedSignallingOk;
|
||||
unsigned int internalcolorcode;
|
||||
int internalslot;
|
||||
//redundancy check (carrier signal loss event)
|
||||
char redundancyA[36];
|
||||
char redundancyB[36];
|
||||
unsigned short int vc1;
|
||||
unsigned short int vc2;
|
||||
int cach_okay = 0;
|
||||
|
||||
//cach fec
|
||||
char cachdata[25] = {0}; //increased from 24 to 25 to see if this fixes ubuntu 32 bug
|
||||
int cachInterleave[24] = {0, 7, 8, 9, 1, 10, 11, 12, 2, 13, 14, 15, 3, 16, 4, 17, 18, 19, 5, 20, 21, 22, 6, 23};
|
||||
//memcpy of ambe_fr for late entry
|
||||
char m1[4][24];
|
||||
char m2[4][24];
|
||||
char m3[4][24];
|
||||
|
||||
const int *w, *x, *y, *z;
|
||||
char sync[25];
|
||||
char syncdata[48];
|
||||
char EmbeddedSignalling[16];
|
||||
|
||||
uint8_t emb_ok = 0;
|
||||
uint8_t tact_okay = 0;
|
||||
uint8_t cach_err = 0;
|
||||
|
||||
uint8_t internalslot;
|
||||
uint8_t vc1;
|
||||
uint8_t vc2;
|
||||
|
||||
//would be ideal to grab all dibits and break them into bits to pass to new data handler?
|
||||
uint8_t dummy_bits[196];
|
||||
memset (dummy_bits, 0, sizeof(dummy_bits));
|
||||
|
||||
//add time to mirror printFrameSync
|
||||
time_t now;
|
||||
char * getTime(void) //get pretty hh:mm:ss timestamp
|
||||
@@ -63,10 +76,21 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
||||
short int loop = 1;
|
||||
short int skipcount = 0;
|
||||
|
||||
//cach
|
||||
char cachdata[25];
|
||||
int cachInterleave[24] =
|
||||
{0, 7, 8, 9, 1, 10,
|
||||
11, 12, 2, 13, 14,
|
||||
15, 3, 16, 4, 17, 18,
|
||||
19, 5, 20, 21, 22, 6, 23
|
||||
};
|
||||
|
||||
//cach tact bits
|
||||
uint8_t tact_bits[7];
|
||||
|
||||
//Run Loop while the getting is good
|
||||
while (loop == 1) {
|
||||
|
||||
// CACH
|
||||
internalslot = -1; //reset here so we know if this value is being set properly
|
||||
for(i = 0; i < 12; i++)
|
||||
{
|
||||
@@ -77,30 +101,23 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
||||
cachdata[cachInterleave[(i*2)+1]] = (1 & dibit); // bit 0
|
||||
}
|
||||
|
||||
//decode and correct cach and compare
|
||||
cach_okay = 69;
|
||||
if ( Hamming_7_4_decode (cachdata) ) //see if we need to de-interleave this...probably do.
|
||||
for (i = 0; i < 7; i++)
|
||||
{
|
||||
cach_okay = 1;
|
||||
tact_bits[i] = cachdata[i];
|
||||
}
|
||||
if (cach_okay == 1)
|
||||
|
||||
//disabled for dmr_cach testing
|
||||
tact_okay = 0;
|
||||
if ( Hamming_7_4_decode (tact_bits) ) tact_okay = 1;
|
||||
if (tact_okay != 1)
|
||||
{
|
||||
//fprintf (stderr, "CACH Okay ");
|
||||
}
|
||||
if (cach_okay != 1)
|
||||
{
|
||||
//fprintf (stderr, "CACH FEC Error %d", cach_okay);
|
||||
if (opts->aggressive_framesync == 1)
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
state->currentslot = cachdata[1];
|
||||
internalslot = cachdata[1];
|
||||
|
||||
//this cach fec seems to work quite well, really helps on shaky signals
|
||||
internalslot = state->currentslot = tact_bits[1];
|
||||
|
||||
//Setup for first AMBE Frame
|
||||
//Interleave Schedule
|
||||
@@ -115,6 +132,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
||||
dibit = getDibit(opts, state);
|
||||
state->dmr_stereo_payload[i+12] = dibit;
|
||||
redundancyA[i] = dibit;
|
||||
|
||||
ambe_fr[*w][*x] = (1 & (dibit >> 1)); // bit 1
|
||||
ambe_fr[*y][*z] = (1 & dibit); // bit 0
|
||||
|
||||
@@ -134,11 +152,9 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
// end redundancy test, set B to A
|
||||
for(i = 0; i < 36; i++)
|
||||
{
|
||||
redundancyB[i] = redundancyA[i];
|
||||
}
|
||||
|
||||
//end redundancy test, set B to A
|
||||
memcpy (redundancyB, redundancyA, sizeof (redundancyA));
|
||||
|
||||
//Setup for Second AMBE Frame
|
||||
//Interleave Schedule
|
||||
@@ -162,90 +178,39 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
||||
|
||||
}
|
||||
|
||||
//short int l = 0; //do I still use this?
|
||||
// signaling data or sync
|
||||
long long int late_entry_pi[24] = {0};
|
||||
short int m = 0;
|
||||
//signaling data or sync
|
||||
for(i = 0; i < 24; i++)
|
||||
{
|
||||
dibit = getDibit(opts, state);
|
||||
|
||||
state->dmr_stereo_payload[i+66] = dibit;
|
||||
sync[i] = (dibit | 1) + 48; //how does this work again?
|
||||
|
||||
syncdata[(2*i)] = (1 & (dibit >> 1)); // bit 1
|
||||
syncdata[(2*i)+1] = (1 & dibit); // bit 0
|
||||
sync[i] = (dibit | 1) + 48;
|
||||
syncdata[(2*i)+1] = (1 & dibit); // bit 0
|
||||
|
||||
if (i < 4 || i > 19)
|
||||
{
|
||||
// fprintf(stderr, "\n EMB = ");
|
||||
EmbeddedSignalling[(2*i)] = (1 & (dibit >> 1)); // bit 1
|
||||
//fprintf (stderr, "%02b", dibit);
|
||||
EmbeddedSignalling[(2*i)+1] = (1 & dibit); // bit 0
|
||||
|
||||
}
|
||||
|
||||
//Used for ProcessVoiceBurstSync
|
||||
//embedded link control
|
||||
if(internalslot == 0 && vc1 > 1 && vc1 < 6) //grab on vc1 values 2-5 B C D and E
|
||||
{
|
||||
/* Time slot 1 superframe buffer filling => SYNC data */
|
||||
state->TS1SuperFrame.TimeSlotRawVoiceFrame[vc1-1].Sync[i*2] = (1 & (dibit >> 1)); // bit 1
|
||||
state->TS1SuperFrame.TimeSlotRawVoiceFrame[vc1-1].Sync[i*2+1] = (1 & dibit); // bit 0
|
||||
state->dmr_embedded_signalling[internalslot][vc1-1][i*2] = (1 & (dibit >> 1)); // bit 1
|
||||
state->dmr_embedded_signalling[internalslot][vc1-1][i*2+1] = (1 & dibit); // bit 0
|
||||
}
|
||||
|
||||
if(internalslot == 1 && vc2 > 1 && vc2 < 6) //grab on vc2 values 2-5 B C D and E
|
||||
{
|
||||
/* Time slot 2 superframe buffer filling => SYNC data */
|
||||
state->TS2SuperFrame.TimeSlotRawVoiceFrame[vc2-1].Sync[i*2] = (1 & (dibit >> 1)); // bit 1
|
||||
state->TS2SuperFrame.TimeSlotRawVoiceFrame[vc2-1].Sync[i*2+1] = (1 & dibit); // bit 0
|
||||
state->dmr_embedded_signalling[internalslot][vc2-1][i*2] = (1 & (dibit >> 1)); // bit 1
|
||||
state->dmr_embedded_signalling[internalslot][vc2-1][i*2+1] = (1 & dibit); // bit 0
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sync[24] = 0;
|
||||
|
||||
EmbeddedSignallingOk = -1;
|
||||
if(QR_16_7_6_decode(EmbeddedSignalling))
|
||||
{
|
||||
EmbeddedSignallingOk = 1;
|
||||
}
|
||||
for(i = 0; i < 8; i++) EmbeddedSignalling[i] = syncdata[i];
|
||||
for(i = 0; i < 8; i++) EmbeddedSignalling[i + 8] = syncdata[i + 40];
|
||||
|
||||
internalcolorcode = 69; //set so we know if this value is being set properly
|
||||
|
||||
if( EmbeddedSignallingOk == 1 ) //don't set on 1?
|
||||
{
|
||||
//state->color_code = (unsigned int)((EmbeddedSignalling[0] << 3) + (EmbeddedSignalling[1] << 2) + (EmbeddedSignalling[2] << 1) + EmbeddedSignalling[3]);
|
||||
internalcolorcode = (unsigned int)((EmbeddedSignalling[0] << 3) + (EmbeddedSignalling[1] << 2) + (EmbeddedSignalling[2] << 1) + EmbeddedSignalling[3]);
|
||||
state->color_code_ok = EmbeddedSignallingOk;
|
||||
|
||||
//Power Indicator, not the other PI (header)
|
||||
state->PI = (unsigned int)EmbeddedSignalling[4];
|
||||
state->PI_ok = EmbeddedSignallingOk;
|
||||
|
||||
//Link Control Start Stop Indicator
|
||||
state->LCSS = (unsigned int)((EmbeddedSignalling[5] << 1) + EmbeddedSignalling[6]);
|
||||
state->LCSS_ok = EmbeddedSignallingOk;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
//fprintf (stderr, " %b", EmbeddedSignalling[i]);
|
||||
}
|
||||
|
||||
}
|
||||
//else skipcount++;
|
||||
else
|
||||
{
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
//fprintf (stderr, " %b", EmbeddedSignalling[i]);
|
||||
}
|
||||
}
|
||||
//Continue Second AMBE Frame, 18 after Sync or EmbeddedSignalling
|
||||
for(i = 0; i < 18; i++)
|
||||
{
|
||||
dibit = getDibit(opts, state);
|
||||
if(opts->inverted_dmr == 1)
|
||||
{
|
||||
//dibit = (dibit ^ 2);
|
||||
}
|
||||
state->dmr_stereo_payload[i+90] = dibit;
|
||||
ambe_fr2[*w][*x] = (1 & (dibit >> 1)); // bit 1
|
||||
ambe_fr2[*y][*z] = (1 & dibit); // bit 0
|
||||
@@ -268,10 +233,6 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
||||
for(i = 0; i < 36; i++)
|
||||
{
|
||||
dibit = getDibit(opts, state);
|
||||
if(opts->inverted_dmr == 1)
|
||||
{
|
||||
//dibit = (dibit ^ 2);
|
||||
}
|
||||
state->dmr_stereo_payload[i+108] = dibit;
|
||||
ambe_fr3[*w][*x] = (1 & (dibit >> 1)); // bit 1
|
||||
ambe_fr3[*y][*z] = (1 & dibit); // bit 0
|
||||
@@ -286,305 +247,137 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
||||
//reset vc counters to 1 if new voice sync frame on each slot
|
||||
if ( strcmp (sync, DMR_BS_VOICE_SYNC) == 0)
|
||||
{
|
||||
if (internalslot == 0)
|
||||
{
|
||||
vc1 = 1;
|
||||
state->DMRvcL = 0; //reset here if internal sync forces reset
|
||||
}
|
||||
if (internalslot == 1)
|
||||
{
|
||||
vc2 = 1;
|
||||
state->DMRvcR = 0; //reset here if internal sync forces reset
|
||||
}
|
||||
if (internalslot == 0) vc1 = 1;
|
||||
if (internalslot == 1) vc2 = 1;
|
||||
}
|
||||
|
||||
// if( strcmp (sync, DMR_DIRECT_MODE_TS1_DATA_SYNC) == 0)
|
||||
// {
|
||||
// fprintf (stderr,"%s ", getTime());
|
||||
// fprintf (stderr, " Sync: DMR TDMA Direct Mode TS 1 \n");
|
||||
// goto SKIP;
|
||||
// }
|
||||
//
|
||||
// if( strcmp (sync, DMR_DIRECT_MODE_TS2_DATA_SYNC) == 0)
|
||||
// {
|
||||
// fprintf (stderr,"%s ", getTime());
|
||||
// fprintf (stderr, " Sync: DMR TDMA Direct Mode TS 2 \n");
|
||||
// goto SKIP;
|
||||
// }
|
||||
|
||||
//check for sync pattern here after collected the rest of the payload, decide what to do with it
|
||||
if ( strcmp (sync, DMR_BS_DATA_SYNC) == 0 )
|
||||
{
|
||||
|
||||
fprintf (stderr,"%s ", getTime());
|
||||
if (internalslot == 0)
|
||||
{
|
||||
sprintf(state->slot1light, "[slot1]");
|
||||
sprintf(state->slot2light, " slot2 ");
|
||||
|
||||
if (opts->inverted_dmr == 0)
|
||||
{
|
||||
fprintf (stderr,"Sync: +DMR ");
|
||||
}
|
||||
else fprintf (stderr,"Sync: -DMR ");
|
||||
//constantly reset the vc counter to 1 each data frame in anticipation of new voice frame
|
||||
|
||||
vc1 = 1;
|
||||
|
||||
}
|
||||
if (internalslot == 1)
|
||||
{
|
||||
sprintf(state->slot2light, "[slot2]");
|
||||
sprintf(state->slot1light, " slot1 ");
|
||||
|
||||
if (opts->inverted_dmr == 0)
|
||||
{
|
||||
fprintf (stderr,"Sync: +DMR ");
|
||||
}
|
||||
else fprintf (stderr,"Sync: -DMR ");
|
||||
//constantly reset the vc counter to 1 each data frame in anticipation of new voice frame
|
||||
|
||||
vc2 = 1;
|
||||
|
||||
}
|
||||
processDMRdata (opts, state);
|
||||
skipcount++; //after 2 data frames, drop back to getFrameSync and process subsequent data with processDMRdata
|
||||
goto SKIP;
|
||||
}
|
||||
|
||||
//find way to mitigate or correct coming back here after leaving in inverted signal
|
||||
if ( strcmp (sync, DMR_BS_DATA_SYNC) == 0 && opts->inverted_dmr == 1)
|
||||
{
|
||||
dmr_data_sync (opts, state);
|
||||
skipcount++;
|
||||
goto SKIP;
|
||||
}
|
||||
|
||||
//extra check to see if we have missed a voice/data frame sync at this point and then exit if required
|
||||
if (1 == 1) //opts->aggressive_framesync
|
||||
{
|
||||
//extremely aggressive
|
||||
if ( vc1 > 7 || vc2 > 7 )
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//only play voice on no data sync
|
||||
if (strcmp (sync, DMR_BS_DATA_SYNC) != 0)
|
||||
if (strcmp (sync, DMR_BS_DATA_SYNC) != 0) //we already have a tact ecc check, so we won't get here without that, see if there is any other eccs we can run just to make sure
|
||||
{
|
||||
|
||||
if (EmbeddedSignallingOk == 0)
|
||||
//check the embedded signalling, if bad at this point, we probably aren't quite in sync
|
||||
if(QR_16_7_6_decode(EmbeddedSignalling)) emb_ok = 1;
|
||||
else emb_ok = 0;
|
||||
|
||||
//disable the goto END; if this causes more problems than fixing on late entry dual voices i.e., lots of forced resyncs
|
||||
if ( (strcmp (sync, DMR_BS_VOICE_SYNC) != 0) && emb_ok == 0) goto END; //fprintf (stderr, "EMB BAD? ");
|
||||
else if (emb_ok == 1)
|
||||
{
|
||||
//goto END;
|
||||
uint8_t cc = ((EmbeddedSignalling[0] << 3) + (EmbeddedSignalling[1] << 2) + (EmbeddedSignalling[2] << 1) + EmbeddedSignalling[3]);
|
||||
uint8_t power = EmbeddedSignalling[4];
|
||||
uint8_t lcss = ((EmbeddedSignalling[5] << 1) + EmbeddedSignalling[6]);
|
||||
}
|
||||
|
||||
|
||||
skipcount = 0; //reset skip count if processing voice frames
|
||||
fprintf (stderr,"%s ", getTime());
|
||||
|
||||
//simplifying things
|
||||
char polarity[3];
|
||||
char light[18];
|
||||
uint8_t vc;
|
||||
if (internalslot == 0)
|
||||
{
|
||||
state->dmrburstL = 16; //use 16 for Voice?
|
||||
|
||||
if (opts->inverted_dmr == 0)
|
||||
{
|
||||
fprintf (stderr,"Sync: +DMR [SLOT1] slot2 | | DMRSTEREO | VC%d ",vc1);
|
||||
if (state->K > 0 && state->dmr_so & 0x40 && state->payload_keyid == 0 && state->dmr_fid == 0x10)
|
||||
{
|
||||
fprintf (stderr, "%s", KYEL);
|
||||
fprintf(stderr, " PrK %lld", state->K);
|
||||
fprintf (stderr, "%s", KNRM);
|
||||
}
|
||||
if (state->DMRvcL == 0 && state->K1 > 0 && state->dmr_so & 0x40 && state->payload_keyid == 0 && state->dmr_fid == 0x68)
|
||||
{
|
||||
fprintf (stderr, "\n");
|
||||
fprintf (stderr, "%s", KYEL);
|
||||
fprintf(stderr, " SPT %016llX", state->K1);
|
||||
if (state->K2 != 0)
|
||||
{
|
||||
fprintf(stderr, " %016llX", state->K2);
|
||||
}
|
||||
if (state->K3 != 0)
|
||||
{
|
||||
fprintf(stderr, " %016llX", state->K3);
|
||||
}
|
||||
if (state->K4 != 0)
|
||||
{
|
||||
fprintf(stderr, " %016llX", state->K4);
|
||||
}
|
||||
fprintf (stderr, "%s", KNRM);
|
||||
}
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr,"Sync: -DMR [SLOT1] slot2 | | DMRSTEREO | VC%d ",vc1);
|
||||
if (state->K > 0 && state->dmr_so & 0x40 && state->payload_keyid == 0 && state->dmr_fid == 0x10)
|
||||
{
|
||||
fprintf (stderr, "%s", KYEL);
|
||||
fprintf(stderr, " PrK %lld", state->K);
|
||||
fprintf (stderr, "%s", KNRM);
|
||||
}
|
||||
if (state->DMRvcL == 0 && state->K1 > 0 && state->dmr_so & 0x40 && state->payload_keyid == 0 && state->dmr_fid == 0x68)
|
||||
{
|
||||
fprintf (stderr, "\n");
|
||||
fprintf (stderr, "%s", KYEL);
|
||||
fprintf(stderr, " SPT %016llX", state->K1);
|
||||
if (state->K2 != 0)
|
||||
{
|
||||
fprintf(stderr, " %016llX", state->K2);
|
||||
}
|
||||
if (state->K3 != 0)
|
||||
{
|
||||
fprintf(stderr, " %016llX", state->K3);
|
||||
}
|
||||
if (state->K4 != 0)
|
||||
{
|
||||
fprintf(stderr, " %016llX", state->K4);
|
||||
}
|
||||
fprintf (stderr, "%s", KNRM);
|
||||
}
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (internalslot == 1)
|
||||
state->dmrburstL = 16;
|
||||
vc = vc1;
|
||||
sprintf (light, "%s", " [SLOT1] slot2 ");
|
||||
}
|
||||
else
|
||||
{
|
||||
state->dmrburstR = 16; //use 16 for Voice?
|
||||
if (opts->inverted_dmr == 0)
|
||||
{
|
||||
fprintf (stderr,"Sync: +DMR slot1 [SLOT2] | | DMRSTEREO | VC%d ",vc2);
|
||||
if (state->K > 0 && state->dmr_soR & 0x40 && state->payload_keyidR == 0 && state->dmr_fidR == 0x10)
|
||||
{
|
||||
fprintf (stderr, "%s", KYEL);
|
||||
fprintf(stderr, " PrK %lld", state->K);
|
||||
fprintf (stderr, "%s", KNRM);
|
||||
}
|
||||
if (state->DMRvcR == 0 && state->K1 > 0 && state->dmr_soR & 0x40 && state->payload_keyidR == 0 && state->dmr_fidR == 0x68)
|
||||
{
|
||||
fprintf (stderr, "\n");
|
||||
fprintf (stderr, "%s", KYEL);
|
||||
fprintf(stderr, " SPT %016llX", state->K1);
|
||||
if (state->K2 != 0)
|
||||
{
|
||||
fprintf(stderr, " %016llX", state->K2);
|
||||
}
|
||||
if (state->K3 != 0)
|
||||
{
|
||||
fprintf(stderr, " %016llX", state->K3);
|
||||
}
|
||||
if (state->K4 != 0)
|
||||
{
|
||||
fprintf(stderr, " %016llX", state->K4);
|
||||
}
|
||||
fprintf (stderr, "%s", KNRM);
|
||||
}
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr,"Sync: -DMR slot1 [SLOT2] | | DMRSTEREO | VC%d ",vc2);
|
||||
if (state->K > 0 && state->dmr_soR & 0x40 && state->payload_keyidR == 0 && state->dmr_fidR == 0x10)
|
||||
{
|
||||
fprintf (stderr, "%s", KYEL);
|
||||
fprintf(stderr, " PrK %lld", state->K);
|
||||
fprintf (stderr, "%s", KNRM);
|
||||
}
|
||||
if (state->DMRvcR == 0 && state->K1 > 0 && state->dmr_soR & 0x40 && state->payload_keyidR == 0 && state->dmr_fidR == 0x68)
|
||||
{
|
||||
fprintf (stderr, "\n");
|
||||
fprintf (stderr, "%s", KYEL);
|
||||
fprintf(stderr, " SPT %016llX", state->K1);
|
||||
if (state->K2 != 0)
|
||||
{
|
||||
fprintf(stderr, " %016llX", state->K2);
|
||||
}
|
||||
if (state->K3 != 0)
|
||||
{
|
||||
fprintf(stderr, " %016llX", state->K3);
|
||||
}
|
||||
if (state->K4 != 0)
|
||||
{
|
||||
fprintf(stderr, " %016llX", state->K4);
|
||||
}
|
||||
fprintf (stderr, "%s", KNRM);
|
||||
}
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
}
|
||||
if (internalslot == 0 && vc1 == 6) //presumably when full (and no sync issues)
|
||||
state->dmrburstR = 16;
|
||||
vc = vc2;
|
||||
sprintf (light, "%s", " slot1 [SLOT2] ");
|
||||
}
|
||||
if (opts->inverted_dmr == 0) sprintf (polarity, "%s", "+");
|
||||
else sprintf (polarity, "%s", "-");
|
||||
|
||||
fprintf (stderr,"Sync: %sDMR %s| Color Code=%02d | VC%d ", polarity, light, state->dmr_color_code, vc);
|
||||
|
||||
if (internalslot == 0 && vc1 == 6)
|
||||
{
|
||||
//process voice burst
|
||||
ProcessVoiceBurstSync(opts, state);
|
||||
//process embedded link control
|
||||
fprintf (stderr, "\n");
|
||||
dmr_data_burst_handler(opts, state, (uint8_t *)dummy_bits, 0xEB);
|
||||
}
|
||||
|
||||
if (internalslot == 1 && vc2 == 6) //presumably when full (and no sync issues)
|
||||
if (internalslot == 1 && vc2 == 6)
|
||||
{
|
||||
//process voice burst
|
||||
ProcessVoiceBurstSync(opts, state);
|
||||
//process embedded link control
|
||||
fprintf (stderr, "\n");
|
||||
dmr_data_burst_handler(opts, state, (uint8_t *)dummy_bits, 0xEB);
|
||||
}
|
||||
|
||||
if (opts->payload == 1) fprintf (stderr, "\n"); //extra line break necessary here
|
||||
|
||||
//copy ambe_fr frames first, running process mbe will correct them,
|
||||
//but this also leads to issues extracting good le mi values when
|
||||
//we go to do correction on them there too
|
||||
memcpy (m1, ambe_fr, sizeof(m1));
|
||||
memcpy (m2, ambe_fr2, sizeof(m2));
|
||||
memcpy (m3, ambe_fr3, sizeof(m3));
|
||||
|
||||
processMbeFrame (opts, state, NULL, ambe_fr, NULL);
|
||||
processMbeFrame (opts, state, NULL, ambe_fr2, NULL);
|
||||
processMbeFrame (opts, state, NULL, ambe_fr3, NULL);
|
||||
|
||||
if (internalslot == 0 && vc1 == 6)
|
||||
{
|
||||
state->DMRvcL = 0;
|
||||
if (state->payload_algid >= 0x21)
|
||||
{
|
||||
cach_err = dmr_cach (opts, state, cachdata);
|
||||
fprintf (stderr, "\n");
|
||||
|
||||
if (state->payload_mi != 0 && state->payload_algid >= 0x21)
|
||||
{
|
||||
LFSR(state);
|
||||
}
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
}
|
||||
// run alg refresh after vc6 ambe processing
|
||||
if (internalslot == 0 && vc1 == 6) dmr_alg_refresh (opts, state);
|
||||
if (internalslot == 1 && vc2 == 6) dmr_alg_refresh (opts, state);
|
||||
|
||||
if (internalslot == 1 && vc2 == 6)
|
||||
{
|
||||
state->DMRvcR = 0;
|
||||
if (state->payload_algidR >= 0x21)
|
||||
{
|
||||
if (state->payload_miR != 0 && state->payload_algidR >= 0x21)
|
||||
{
|
||||
LFSR(state);
|
||||
}
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
}
|
||||
dmr_late_entry_mi_fragment (opts, state, vc, m1, m2, m3);
|
||||
|
||||
if (internalslot == 0)
|
||||
{
|
||||
vc1++;
|
||||
}
|
||||
if (internalslot == 1)
|
||||
{
|
||||
vc2++;
|
||||
}
|
||||
//increment the vc counters
|
||||
if (internalslot == 0) vc1++;
|
||||
if (internalslot == 1) vc2++;
|
||||
|
||||
//reset err checks
|
||||
cach_err = 1;
|
||||
tact_okay = 0;
|
||||
emb_ok = 0;
|
||||
|
||||
}
|
||||
|
||||
// recalibrate center/umid/lmid, not sure this helps or does anything particularly in this case
|
||||
state->center = ((state->max) + (state->min)) / 2;
|
||||
state->umid = (((state->max) - state->center) * 5 / 8) + state->center;
|
||||
state->lmid = (((state->min) - state->center) * 5 / 8) + state->center;
|
||||
|
||||
//Escape conditions to break the loop
|
||||
//7 seems optimal, allows for an extra frame each in case of late entry on dual voices
|
||||
if ( (vc1 > 7 && vc2 > 7) )
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
//14 probably allows a few more in case of a bit of jitter but eventually breaks loop (1 second?)
|
||||
if ( (vc1 > 14 || vc2 > 14) )
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
|
||||
//earlier skip conditions teleport us here to process further skip conditions before restarting while loop
|
||||
SKIP:
|
||||
if (skipcount > 2) //after 2 consecutive data frames, drop back to getFrameSync and process with processDMRdata
|
||||
if (skipcount > 2) //after 2 consecutive data frames, drop back to getFrameSync and process with dmr_data_sync
|
||||
{
|
||||
//set tests to all good so we don't get a bogus/redundant voice error
|
||||
cach_err = 0;
|
||||
tact_okay = 1;
|
||||
emb_ok = 1;
|
||||
goto END;
|
||||
}
|
||||
|
||||
@@ -595,26 +388,37 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
||||
}
|
||||
|
||||
} // while loop
|
||||
//Teleport here on END condition, set or reset variables and return to look for new frame sync
|
||||
|
||||
END:
|
||||
state->dmr_stereo = 0;
|
||||
state->errs = 0;
|
||||
state->errs2 = 0;
|
||||
state->errs2R = 0;
|
||||
state->errs2 = 0;
|
||||
|
||||
//if we have a cach err, then produce sync pattern/err message
|
||||
if (cach_okay != 1)
|
||||
//if we have a tact or emb err, then produce sync pattern/err message
|
||||
if (tact_okay != 1 || emb_ok != 1)
|
||||
{
|
||||
fprintf (stderr,"%s ", getTime());
|
||||
fprintf (stderr,"Sync: DMR ");
|
||||
fprintf (stderr, "%s", KRED);
|
||||
fprintf (stderr, "| ** VOICE CACH ERR ** ");
|
||||
fprintf (stderr, "| VOICE CACH/EMB ERR");
|
||||
fprintf (stderr, "%s", KNRM);
|
||||
//run LFSR if either slot had an active MI in it.
|
||||
state->currentslot = 0;
|
||||
if (state->payload_algid >= 0x21) LFSR(state);
|
||||
state->currentslot = 1;
|
||||
if (state->payload_algidR >= 0x21) LFSR(state);
|
||||
fprintf (stderr, "\n");
|
||||
//run LFSR if either slot had an active MI in it.
|
||||
if (state->payload_algid >= 0x21)
|
||||
{
|
||||
state->currentslot = 0;
|
||||
LFSR(state);
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
if (state->payload_algidR >= 0x21)
|
||||
{
|
||||
state->currentslot = 1;
|
||||
LFSR(state);
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -624,22 +428,28 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
|
||||
{
|
||||
int i, j, k, l, dibit;
|
||||
int *dibit_p;
|
||||
char ambe_fr[4][24] = {0};
|
||||
char ambe_fr2[4][24] = {0};
|
||||
char ambe_fr3[4][24] = {0};
|
||||
char ambe_fr[4][24];
|
||||
char ambe_fr2[4][24];
|
||||
char ambe_fr3[4][24];
|
||||
|
||||
//memcpy of ambe_fr for late entry
|
||||
char m1[4][24];
|
||||
char m2[4][24];
|
||||
char m3[4][24];
|
||||
|
||||
const int *w, *x, *y, *z;
|
||||
char sync[25];
|
||||
char syncdata[48];
|
||||
int mutecurrentslot;
|
||||
int msMode;
|
||||
char cc[4];
|
||||
unsigned char EmbeddedSignalling[16];
|
||||
unsigned int EmbeddedSignallingOk;
|
||||
uint8_t tact_okay = 0;
|
||||
uint8_t cach_err = 0;
|
||||
|
||||
//cach fec
|
||||
char cachdata[25] = {0}; //increased from 24 to 25 to see if this fixes ubuntu 32 bug
|
||||
int cachInterleave[24] = {0, 7, 8, 9, 1, 10, 11, 12, 2, 13, 14, 15, 3, 16, 4, 17, 18, 19, 5, 20, 21, 22, 6, 23};
|
||||
|
||||
char cachdata[25];
|
||||
int cachInterleave[24] =
|
||||
{0, 7, 8, 9, 1, 10,
|
||||
11, 12, 2, 13, 14,
|
||||
15, 3, 16, 4, 17, 18,
|
||||
19, 5, 20, 21, 22, 6, 23
|
||||
};
|
||||
//add time to mirror printFrameSync
|
||||
time_t now;
|
||||
char * getTime(void) //get pretty hh:mm:ss timestamp
|
||||
@@ -678,27 +488,24 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
|
||||
cachdata[cachInterleave[(i*2)+1]] = (1 & dibit); // bit 0
|
||||
}
|
||||
|
||||
//decode and correct cach and compare
|
||||
int cach_okay = 69;
|
||||
if ( Hamming_7_4_decode (cachdata) ) //see if we need to de-interleave this...probably do.
|
||||
//cach tact bits
|
||||
uint8_t tact_bits[7];
|
||||
for (i = 0; i < 7; i++)
|
||||
{
|
||||
cach_okay = 1;
|
||||
tact_bits[i] = cachdata[i];
|
||||
}
|
||||
if (cach_okay == 1)
|
||||
|
||||
//decode and correct tact and compare
|
||||
if ( Hamming_7_4_decode (tact_bits) ) tact_okay = 1;
|
||||
if (tact_okay != 1)
|
||||
{
|
||||
//fprintf (stderr, "CACH Okay ");
|
||||
}
|
||||
if (cach_okay != 1)
|
||||
{
|
||||
//fprintf (stderr, "CACH FEC Error %d", cach_okay);
|
||||
if (opts->aggressive_framesync == 1)
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
state->currentslot = cachdata[1];
|
||||
state->currentslot = tact_bits[1];
|
||||
|
||||
//Setup for first AMBE Frame
|
||||
|
||||
@@ -751,12 +558,8 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
|
||||
sync[i] = (dibit | 1) + 48;
|
||||
}
|
||||
sync[24] = 0;
|
||||
//this method seems to work to make sure we aren't in a data sync especially when inverted signal
|
||||
//consider only testing this when inverted signal if this causes issues with sync later on
|
||||
if ( strcmp (sync, DMR_BS_VOICE_SYNC) != 0)
|
||||
{
|
||||
goto END;
|
||||
}
|
||||
|
||||
if ( strcmp (sync, DMR_BS_VOICE_SYNC) != 0) goto END;
|
||||
|
||||
//Continue Second AMBE Frame, 18 after Sync or EmbeddedSignalling
|
||||
for(i = 0; i < 18; i++)
|
||||
@@ -795,95 +598,65 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
|
||||
}
|
||||
|
||||
fprintf (stderr,"%s ", getTime());
|
||||
if (opts->inverted_dmr == 0)
|
||||
{
|
||||
fprintf (stderr,"Sync: +DMR | Frame Sync | DMRSTEREO | VC1 ");
|
||||
if ( (state->K > 0 && state->dmr_so & 0x40 && state->payload_keyid == 0 && state->dmr_fid == 0x10) ||
|
||||
(state->K > 0 && state->dmr_soR & 0x40 && state->payload_keyidR == 0 && state->dmr_fidR == 0x10) )
|
||||
{
|
||||
fprintf (stderr, "%s", KYEL);
|
||||
fprintf(stderr, " PrK %lld", state->K);
|
||||
fprintf (stderr, "%s", KNRM);
|
||||
char polarity[3];
|
||||
char light[18];
|
||||
|
||||
}
|
||||
if ( (state->K1 > 0 && state->dmr_so & 0x40 && state->payload_keyid == 0 && state->dmr_fid == 0x68) ||
|
||||
(state->K1 > 0 && state->dmr_soR & 0x40 && state->payload_keyidR == 0 && state->dmr_fidR == 0x68) )
|
||||
{
|
||||
fprintf (stderr, "\n");
|
||||
fprintf (stderr, "%s", KYEL);
|
||||
fprintf(stderr, " SPT %016llX", state->K1);
|
||||
if (state->K2 != 0)
|
||||
{
|
||||
fprintf(stderr, " %016llX", state->K2);
|
||||
}
|
||||
if (state->K3 != 0)
|
||||
{
|
||||
fprintf(stderr, " %016llX", state->K3);
|
||||
}
|
||||
if (state->K4 != 0)
|
||||
{
|
||||
fprintf(stderr, " %016llX", state->K4);
|
||||
}
|
||||
fprintf (stderr, "%s", KNRM);
|
||||
}
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
if (state->currentslot == 0)
|
||||
{
|
||||
sprintf (light, "%s", " [SLOT1] slot2 ");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr,"Sync: -DMR | Frame Sync | DMRSTEREO | VC1 ");
|
||||
if ( (state->K > 0 && state->dmr_so & 0x40 && state->payload_keyid == 0 && state->dmr_fid == 0x10) ||
|
||||
(state->K > 0 && state->dmr_soR & 0x40 && state->payload_keyidR == 0 && state->dmr_fidR == 0x10) )
|
||||
{
|
||||
fprintf (stderr, "%s", KYEL);
|
||||
fprintf(stderr, " PrK %lld", state->K);
|
||||
fprintf (stderr, "%s", KNRM);
|
||||
sprintf (light, "%s", " slot1 [SLOT2] ");
|
||||
}
|
||||
if (opts->inverted_dmr == 0) sprintf (polarity, "%s", "+");
|
||||
else sprintf (polarity, "%s", "-");
|
||||
|
||||
}
|
||||
if ( (state->K1 > 0 && state->dmr_so & 0x40 && state->payload_keyid == 0 && state->dmr_fid == 0x68) ||
|
||||
(state->K1 > 0 && state->dmr_soR & 0x40 && state->payload_keyidR == 0 && state->dmr_fidR == 0x68) )
|
||||
{
|
||||
fprintf (stderr, "\n");
|
||||
fprintf (stderr, "%s", KYEL);
|
||||
fprintf(stderr, " SPT %016llX", state->K1);
|
||||
if (state->K2 != 0)
|
||||
{
|
||||
fprintf(stderr, " %016llX", state->K2);
|
||||
}
|
||||
if (state->K3 != 0)
|
||||
{
|
||||
fprintf(stderr, " %016llX", state->K3);
|
||||
}
|
||||
if (state->K4 != 0)
|
||||
{
|
||||
fprintf(stderr, " %016llX", state->K4);
|
||||
}
|
||||
fprintf (stderr, "%s", KNRM);
|
||||
}
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
fprintf (stderr,"Sync: %sDMR %s| Color Code=%02d | VC1*", polarity, light, state->dmr_color_code);
|
||||
|
||||
state->DMRvcL = 0;
|
||||
state->DMRvcR = 0;
|
||||
dmr_alg_reset (opts, state);
|
||||
|
||||
//copy ambe_fr frames first, running process mbe will correct them,
|
||||
//but this also leads to issues extracting good le mi values when
|
||||
//we go to do correction on them there too
|
||||
memcpy (m1, ambe_fr, sizeof(m1));
|
||||
memcpy (m2, ambe_fr2, sizeof(m2));
|
||||
memcpy (m3, ambe_fr3, sizeof(m3));
|
||||
|
||||
if (opts->payload == 1) fprintf (stderr, "\n"); //extra line break necessary here
|
||||
processMbeFrame (opts, state, NULL, ambe_fr, NULL);
|
||||
processMbeFrame (opts, state, NULL, ambe_fr2, NULL);
|
||||
processMbeFrame (opts, state, NULL, ambe_fr3, NULL);
|
||||
|
||||
//collect the mi fragment
|
||||
dmr_late_entry_mi_fragment (opts, state, 1, ambe_fr, ambe_fr2, ambe_fr3);
|
||||
|
||||
cach_err = dmr_cach (opts, state, cachdata);
|
||||
fprintf (stderr, "\n");
|
||||
|
||||
dmrBS (opts, state); //bootstrap into full TDMA frame for BS mode
|
||||
END:
|
||||
//if we have a cach err, then produce sync pattern/err message
|
||||
if (cach_okay != 1)
|
||||
//if we have a tact err, then produce sync pattern/err message
|
||||
if (tact_okay != 1)
|
||||
{
|
||||
fprintf (stderr,"%s ", getTime());
|
||||
fprintf (stderr,"Sync: DMR ");
|
||||
fprintf (stderr, "%s", KRED);
|
||||
fprintf (stderr, "| ** VOICE CACH ERR ** ");
|
||||
fprintf (stderr, "| VOICE CACH/EMB ERR");
|
||||
fprintf (stderr, "%s", KNRM);
|
||||
//run LFSR if either slot had an active MI in it.
|
||||
state->currentslot = 0;
|
||||
if (state->payload_algid >= 0x21) LFSR(state);
|
||||
state->currentslot = 1;
|
||||
if (state->payload_algidR >= 0x21) LFSR(state);
|
||||
fprintf (stderr, "\n");
|
||||
if (state->payload_algid >= 0x21)
|
||||
{
|
||||
state->currentslot = 0;
|
||||
LFSR(state);
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
if (state->payload_algidR >= 0x21)
|
||||
{
|
||||
state->currentslot = 1;
|
||||
LFSR(state);
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user