From a848f9c0feeb6e9f5ed7f87c51143f13eae11e7e Mon Sep 17 00:00:00 2001 From: lwvmobile <59371473+lwvmobile@users.noreply.github.com> Date: Thu, 12 May 2022 16:54:45 -0400 Subject: [PATCH] More DMR Inversion fixes More DMR Inversion fixes --fix some issues regarding when to invert dibits ---still have random issue of frame syncing to voice type instead of data type immediately after voice ends in TDMA stereo when inverted, guessing the dibit buffer is storing non-inverted dibits causing this? --code will need a round of cleanup once fully tested and going good inverted --- src/dmr_bs.c | 60 ++++++++++++++++++++++++++++++++------------ src/dmr_data.c | 6 ++--- src/dmr_ms.c | 56 ++++++++++++++++++++++++++++++++++------- src/dsd_frame_sync.c | 2 +- 4 files changed, 95 insertions(+), 29 deletions(-) diff --git a/src/dmr_bs.c b/src/dmr_bs.c index 1bc78bc..8c39478 100644 --- a/src/dmr_bs.c +++ b/src/dmr_bs.c @@ -69,7 +69,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state) dibit = getDibit(opts, state); if(opts->inverted_dmr == 1) { - dibit = (dibit ^ 2); + //dibit = (dibit ^ 2); } cachdata[i] = dibit; state->dmr_stereo_payload[i] = dibit; @@ -93,7 +93,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state) dibit = getDibit(opts, state); if(opts->inverted_dmr == 1) { - dibit = (dibit ^ 2); + //dibit = (dibit ^ 2); } state->dmr_stereo_payload[i+12] = dibit; redundancyA[i] = dibit; @@ -135,7 +135,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state) dibit = getDibit(opts, state); if(opts->inverted_dmr == 1) { - dibit = (dibit ^ 2); + //dibit = (dibit ^ 2); } state->dmr_stereo_payload[i+48] = dibit; ambe_fr2[*w][*x] = (1 & (dibit >> 1)); // bit 1 @@ -155,7 +155,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state) dibit = getDibit(opts, state); if(opts->inverted_dmr == 1) { - dibit = (dibit ^ 2); + //dibit = (dibit ^ 2); } state->dmr_stereo_payload[i+66] = dibit; syncdata[(2*i)] = (1 & (dibit >> 1)); // bit 1 @@ -217,7 +217,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state) dibit = getDibit(opts, state); if(opts->inverted_dmr == 1) { - dibit = (dibit ^ 2); + //dibit = (dibit ^ 2); } state->dmr_stereo_payload[i+90] = dibit; ambe_fr2[*w][*x] = (1 & (dibit >> 1)); // bit 1 @@ -243,7 +243,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state) dibit = getDibit(opts, state); if(opts->inverted_dmr == 1) { - dibit = (dibit ^ 2); + //dibit = (dibit ^ 2); } state->dmr_stereo_payload[i+108] = dibit; ambe_fr3[*w][*x] = (1 & (dibit >> 1)); // bit 1 @@ -258,7 +258,9 @@ void dmrBS (dsd_opts * opts, dsd_state * state) //reset vc counters to 1 if new voice sync frame on each slot //fixed to compensate for inverted signal - if ( ((strcmp (sync, DMR_BS_VOICE_SYNC) == 0) && opts->inverted_dmr == 0) || ((strcmp (sync, DMR_BS_DATA_SYNC) == 0) && opts->inverted_dmr == 1) ) + if ( strcmp (sync, DMR_BS_VOICE_SYNC) == 0) + //if ( ( strcmp (sync, DMR_BS_VOICE_SYNC) == 0 && opts->inverted_dmr == 0 ) || + // ( strcmp (sync, DMR_BS_DATA_SYNC) == 0 && opts->inverted_dmr == 1) ) { if (internalslot == 0) { @@ -272,7 +274,9 @@ void dmrBS (dsd_opts * opts, dsd_state * state) //check for sync pattern here after collected the rest of the payload, decide what to do with it //fixed to compensate for inverted signal - if ( ((strcmp (sync, DMR_BS_DATA_SYNC) == 0) && opts->inverted_dmr == 0) || ((strcmp (sync, DMR_BS_VOICE_SYNC) == 0) && opts->inverted_dmr == 1) ) + if ( strcmp (sync, DMR_BS_DATA_SYNC) == 0 ) + //if ( ( strcmp (sync, DMR_BS_DATA_SYNC) == 0 && opts->inverted_dmr == 0) || + // ( strcmp (sync, DMR_BS_VOICE_SYNC) == 0 && opts->inverted_dmr == 1) ) { fprintf (stderr,"%s ", getTime()); if (internalslot == 0) @@ -280,7 +284,12 @@ void dmrBS (dsd_opts * opts, dsd_state * state) sprintf(state->slot1light, "[slot1]"); sprintf(state->slot2light, " slot2 "); //fprintf (stderr,"Sync: +DMR [slot1] slot2 | Color Code=%02d | DMRSTEREO | Data ", state->color_code); - fprintf (stderr,"Sync: +DMR "); + //fprintf (stderr,"Sync: +DMR "); + 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; } @@ -289,7 +298,12 @@ void dmrBS (dsd_opts * opts, dsd_state * state) sprintf(state->slot2light, "[slot2]"); sprintf(state->slot1light, " slot1 "); //fprintf (stderr,"Sync: +DMR slot1 [slot2] | Color Code=%02d | DMRSTEREO | Data ", state->color_code); - fprintf (stderr,"Sync: +DMR "); + //fprintf (stderr,"Sync: +DMR "); + 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; } @@ -299,8 +313,9 @@ void dmrBS (dsd_opts * opts, dsd_state * state) } //only play voice on no data sync //fixed to compensate for inverted signal - //(strcmp (sync, DMR_BS_DATA_SYNC) != 0) - if( ((strcmp (sync, DMR_BS_DATA_SYNC) != 0) && opts->inverted_dmr == 0) || ((strcmp (sync, DMR_BS_VOICE_SYNC) != 0) && opts->inverted_dmr == 1)) + if (strcmp (sync, DMR_BS_DATA_SYNC) != 0) + //if( ( strcmp (sync, DMR_BS_DATA_SYNC) != 0 && opts->inverted_dmr == 0) || + // ( strcmp (sync, DMR_BS_VOICE_SYNC) != 0 && opts->inverted_dmr == 1) ) { if (EmbeddedSignallingOk == 0) { @@ -312,14 +327,22 @@ void dmrBS (dsd_opts * opts, dsd_state * state) { state->dmrburstL = 16; //use 16 for Voice? //fprintf (stderr,"Sync: +DMR [slot1] slot2 | Color Code=%02d | DMRSTEREO | VC%d \n", state->dmr_color_code, vc1); - fprintf (stderr,"Sync: +DMR [slot1] slot2 | | DMRSTEREO | VC%d \n",vc1); + if (opts->inverted_dmr == 0) + { + fprintf (stderr,"Sync: +DMR [slot1] slot2 | | DMRSTEREO | VC%d \n",vc1); + } + else fprintf (stderr,"Sync: -DMR [slot1] slot2 | | DMRSTEREO | VC%d \n",vc1); } if (internalslot == 1) { state->dmrburstR = 16; //use 16 for Voice? //fprintf (stderr,"Sync: +DMR slot1 [slot2] | Color Code=%02d | DMRSTEREO | VC%d \n", state->dmr_color_code, vc2); - fprintf (stderr,"Sync: +DMR [slot1] slot2 | | DMRSTEREO | VC%d \n",vc2); + if (opts->inverted_dmr == 0) + { + fprintf (stderr,"Sync: +DMR [slot1] slot2 | | DMRSTEREO | VC%d \n",vc2); + } + else fprintf (stderr,"Sync: -DMR [slot1] slot2 | | DMRSTEREO | VC%d \n",vc2); } if (internalslot == 0 && vc1 == 6) //presumably when full (and no sync issues) { @@ -452,7 +475,7 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state) dibit = getDibit(opts, state); if(opts->inverted_dmr == 1) { - dibit = (dibit ^ 2); + //dibit = (dibit ^ 2); } ambe_fr3[*w][*x] = (1 & (dibit >> 1)); // bit 1 ambe_fr3[*y][*z] = (1 & dibit); // bit 0 @@ -466,7 +489,12 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state) //fprintf (stderr,"\n%s ", getTime()); fprintf (stderr,"%s ", getTime()); - fprintf (stderr,"Sync: +DMR | Frame Sync | DMRSTEREO | VC1 FS \n"); + if (opts->inverted_dmr == 0) + { + fprintf (stderr,"Sync: +DMR | Frame Sync | DMRSTEREO | VC1 FS \n"); + } + else fprintf (stderr,"Sync: -DMR | Frame Sync | DMRSTEREO | VC1 FS \n"); + //fprintf (stderr,"Sync: +DMR | Frame Sync | DMRSTEREO | VC1 FS \n"); processMbeFrame (opts, state, NULL, ambe_fr3, NULL); dmrBS (opts, state); //bootstrap into full TDMA frame for BS mode diff --git a/src/dmr_data.c b/src/dmr_data.c index 24604a3..e4195c0 100644 --- a/src/dmr_data.c +++ b/src/dmr_data.c @@ -52,7 +52,7 @@ processDMRdata (dsd_opts * opts, dsd_state * state) //using the estimate_symbol method for the dmr_payload_p buffer causes sync //issues with P25, so only do it when frame_p25p1 == 0, or -fr option //temp fix to only use dmr_payload_p buffer when no inversion expected, otherwise use dibit_buf - if (opts->frame_p25p1 == 0 && opts->inverted_dmr == 0) //opts->frame_p25p1 == 0 + if (opts->frame_p25p1 == 0 && opts->inverted_dmr == 0) //opts->frame_p25p1 == 0 && opts->inverted_dmr == 0 { dibit_p = state->dmr_payload_p - 90; } @@ -293,7 +293,7 @@ processDMRdata (dsd_opts * opts, dsd_state * state) } if (opts->inverted_dmr == 1) { - dibit = (dibit ^ 2); + //dibit = (dibit ^ 2); } if (state->dmr_stereo == 1) { @@ -391,7 +391,7 @@ processDMRdata (dsd_opts * opts, dsd_state * state) } if (opts->inverted_dmr == 1) { - dibit = (dibit ^ 2); + //dibit = (dibit ^ 2); } if (state->dmr_stereo == 1) { diff --git a/src/dmr_ms.c b/src/dmr_ms.c index 0ea4ab9..5f9cc69 100644 --- a/src/dmr_ms.c +++ b/src/dmr_ms.c @@ -267,7 +267,10 @@ void dmrMS (dsd_opts * opts, dsd_state * state) } - if ( (strcmp (sync, DMR_MS_VOICE_SYNC) == 0) ) // + //if ( (strcmp (sync, DMR_MS_VOICE_SYNC) == 0) ) + //fixed to compensate for inverted signal + if ( ((strcmp (sync, DMR_MS_VOICE_SYNC) == 0) && opts->inverted_dmr == 0) || ((strcmp (sync, DMR_MS_DATA_SYNC) == 0) && opts->inverted_dmr == 1) ) + { if (internalslot == 0) { @@ -321,7 +324,10 @@ void dmrMS (dsd_opts * opts, dsd_state * state) } //check for sync pattern here after collected the rest of the payload, decide what to do with it - if ( (strcmp (sync, DMR_MS_DATA_SYNC) == 0) ) + //if ( (strcmp (sync, DMR_MS_DATA_SYNC) == 0) ) + //fixed to compensate for inverted signal + if ( ((strcmp (sync, DMR_MS_DATA_SYNC) == 0) && opts->inverted_dmr == 0) || + ((strcmp (sync, DMR_MS_VOICE_SYNC) == 0) && opts->inverted_dmr == 1) ) { fprintf (stderr,"%s ", getTime()); if (internalslot == 0) @@ -329,7 +335,11 @@ void dmrMS (dsd_opts * opts, dsd_state * state) sprintf(state->slot1light, "[slot1]"); sprintf(state->slot2light, " slot2 "); //fprintf (stderr,"Sync: +DMR [slot1] slot2 | Color Code=%02d | DMRSTEREO | MS Data ", state->color_code); - fprintf (stderr,"Sync: +DMR "); + if (opts->inverted_dmr == 0) + { + fprintf (stderr,"Sync: +DMR "); + } + else fprintf (stderr,"Sync: -DMR "); //test with vc1 reset disabled, if all is well, leave disabled //vc1 = 1; } @@ -338,7 +348,11 @@ void dmrMS (dsd_opts * opts, dsd_state * state) sprintf(state->slot2light, "[slot2]"); sprintf(state->slot1light, " slot1 "); //fprintf (stderr,"Sync: +DMR slot1 [slot2] | Color Code=%02d | DMRSTEREO | Data ", state->color_code); - fprintf (stderr,"Sync: +DMR "); + if (opts->inverted_dmr == 0) + { + fprintf (stderr,"Sync: +DMR "); + } + else fprintf (stderr,"Sync: -DMR "); //test with vc1 reset disabled, if all is well, leave disabled //vc2 = 1; } @@ -351,20 +365,35 @@ void dmrMS (dsd_opts * opts, dsd_state * state) goto END; } - if( (strcmp (sync, DMR_MS_DATA_SYNC) != 0) && internalslot == activeslot && vc1 < 7) //only play voice no MS Data Sync and vc1 below 6 (no voice resync) + //if( (strcmp (sync, DMR_MS_DATA_SYNC) != 0) && internalslot == activeslot && vc1 < 7) + //only play voice no MS Data Sync and vc1 below 6 (no voice resync) + //fixed to compensate for inverted signal + if( ( ( ((strcmp (sync, DMR_MS_DATA_SYNC) != 0) && opts->inverted_dmr == 0) || + ((strcmp (sync, DMR_MS_VOICE_SYNC) != 0) && opts->inverted_dmr == 1) ) ) + && internalslot == activeslot && vc1 < 7) + { skipcount = 0; //reset skip count if processing voice frames fprintf (stderr,"%s ", getTime()); - if (internalslot == 0) + if (internalslot == 0 && opts->inverted_dmr == 0) { fprintf (stderr,"Sync: +DMR [slot1] slot2 | Color Code=%02d | DMRSTEREO | VC%d \n", state->color_code, vc1); } - if (internalslot == 1) + if (internalslot == 0 && opts->inverted_dmr == 1) + { + fprintf (stderr,"Sync: -DMR [slot1] slot2 | Color Code=%02d | DMRSTEREO | VC%d \n", state->color_code, vc1); + } + + if (internalslot == 1 && opts->inverted_dmr == 0) { fprintf (stderr,"Sync: +DMR slot1 [slot2] | Color Code=%02d | DMRSTEREO | VC%d \n", state->color_code, vc2); } + if (internalslot == 1 && opts->inverted_dmr == 1) + { + fprintf (stderr,"Sync: -DMR slot1 [slot2] | Color Code=%02d | DMRSTEREO | VC%d \n", state->color_code, vc2); + } if (internalslot == 0 && vc1 == 6) //presumably when full (and no sync issues) { //process voice burst @@ -586,7 +615,12 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state) fprintf (stderr, "MS MODE "); fprintf (stderr,"%s ", getTime()); - fprintf (stderr,"Sync: +DMR | Frame Sync | DMRSTEREO | VC1 FS \n"); + //fprintf (stderr,"Sync: +DMR | Frame Sync | DMRSTEREO | VC1 FS \n"); + if (opts->inverted_dmr == 0) + { + fprintf (stderr,"Sync: +DMR | Frame Sync | DMRSTEREO | VC1 FS \n"); + } + else fprintf (stderr,"Sync: -DMR | Frame Sync | DMRSTEREO | VC1 FS \n"); processMbeFrame (opts, state, NULL, ambe_fr, NULL); processMbeFrame (opts, state, NULL, ambe_fr2, NULL); processMbeFrame (opts, state, NULL, ambe_fr3, NULL); @@ -641,7 +675,11 @@ void dmrMSData (dsd_opts * opts, dsd_state * state) fprintf (stderr, "MS MODE "); fprintf (stderr, "%s ", getTime()); //fprintf (stderr, "Sync: +MS DATA | Color Code=XX | DMRSTEREO | Data "); - fprintf (stderr, "Sync: +DMR "); + if (opts->inverted_dmr == 0) + { + fprintf (stderr,"Sync: +DMR "); + } + else fprintf (stderr,"Sync: -DMR "); //fprintf (stderr, "\n "); //sprintf for slot 1, doesn't matter, just makes print out of data look uniform setting ahead of time diff --git a/src/dsd_frame_sync.c b/src/dsd_frame_sync.c index 63060b2..8a6a9eb 100644 --- a/src/dsd_frame_sync.c +++ b/src/dsd_frame_sync.c @@ -828,7 +828,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state) { pa_simple_flush(opts->pulse_raw_dev_out, NULL); } - return (11); + return (11); //11 } } if(strcmp (synctest, DMR_DIRECT_MODE_TS1_DATA_SYNC) == 0)