P25 P2 Frame Stabilization and Tweaks

This commit is contained in:
lwvmobile 2022-10-22 18:45:25 -04:00
parent 3086b7852e
commit c8aafb1be0
2 changed files with 190 additions and 177 deletions

View File

@ -1,6 +1,6 @@
/*-------------------------------------------------------------------------------
* p25_p2.c
* Phase 2 TDMA Voice Processing
* p25p2_frame.c
* Phase 2 TDMA Frame Processing
*
* original copyrights for portions used below (OP25 DUID table, MAC len table)
*
@ -92,8 +92,9 @@ int sacch_rs[2][132] = {0};
//store an entire p2 superframe worth of dibits into a bit buffer
void p2_dibit_buffer (dsd_opts * opts, dsd_state * state)
{
for (int i = 0; i < 2140; i++) //2160 for an entire superframe of dibits - 20 sync dibits
//we used to grab 2140 (entire superframe minus sync)
//now we grab 700 (4 Timeslots minus sync)
for (int i = 0; i < 700; i++) //2160 for an entire superframe of dibits - 20 sync dibits
{
//symbol capture reading now handled directly by getSymbol and getDibit
dibit = getDibit(opts, state);
@ -103,16 +104,7 @@ void p2_dibit_buffer (dsd_opts * opts, dsd_state * state)
}
//grab the entire VCH S-ISCH from the buffer and tack it onto the very end of the bitstream for reference?
int *dibit_p;
dibit_p = state->dibit_buf_p - 20; //rewind 20 dibits
for (int i = 2140; i < 2160; i++) //2160 for an entire superframe of dibits (Symbols)
{
dibit = *dibit_p;
dibit_p++;
p2bit[i*2] = (dibit >> 1) & 1;
p2bit[i*2+1] = (dibit & 1);
}
}
void process_Frame_Scramble (dsd_opts * opts, dsd_state * state)
@ -385,19 +377,31 @@ void process_ISCH (dsd_opts * opts, dsd_state * state)
int chan_num = (isch_decoded >> 5) & 0x3;
state->p2_vch_chan_num = chan_num;
//old rules for entire superframe worth
//determine where the offset should be by first finding TS 0
//this rule doesn't seem to work properly on LCCH,
//duke always showed a chan 1 loc 0, so offset 12 - frame
if (chan_num == 0 && isch_loc == 0)
{
state->p2_scramble_offset = 11 - framing_counter;
}
//additional rule for odd chan number offset,
//fixes duke, and no issues with other samples
else if (chan_num == 1 && isch_loc == 0)
// if (chan_num == 0 && isch_loc == 0)
// {
// state->p2_scramble_offset = 11 - framing_counter;
// }
// //find TS1 if TS0 isn't found
// else if (chan_num == 1 && isch_loc == 0)
// {
// state->p2_scramble_offset = 12 - framing_counter;
// }
//new rules for relative position to the only chan 1 we should see
if (chan_num == 1 && isch_loc == 0)
{
state->p2_scramble_offset = 12 - framing_counter;
}
else if (chan_num == 1 && isch_loc == 1)
{
state->p2_scramble_offset = 4 - framing_counter;
}
else if (chan_num == 1 && isch_loc == 2)
{
state->p2_scramble_offset = 8 - framing_counter;
}
}
else
@ -405,9 +409,8 @@ void process_ISCH (dsd_opts * opts, dsd_state * state)
//if -2(no return value) or -1(fec error)
}
}
// fprintf (stderr, "\n");
}
@ -653,7 +656,7 @@ void process_P2_DUID (dsd_opts * opts, dsd_state * state)
return curr;
}
for (ts_counter = 0; ts_counter < 12; ts_counter++)
for (ts_counter = 0; ts_counter < 4; ts_counter++) //12
{
p2_duid[0] = p2bit[0+(ts_counter*360)];
@ -678,15 +681,6 @@ void process_P2_DUID (dsd_opts * opts, dsd_state * state)
fprintf (stderr,"%s ", getTime());
fprintf (stderr, " P25p2 ");
if (state->currentslot == 0)
{
state->currentslot = 1;
}
else
{
state->currentslot = 0;
}
//print our VCH channel number, or print S for SACCH since its inverted
if (state->currentslot == 0 && duid_decoded != 3 && duid_decoded != 12)
{
@ -788,6 +782,16 @@ void process_P2_DUID (dsd_opts * opts, dsd_state * state)
//add 360 bits to each counter
vc_counter = vc_counter + 360;
//flip slots after each TS processed
if (state->currentslot == 0)
{
state->currentslot = 1;
}
else
{
state->currentslot = 0;
}
}
END:
if (1 == 2)
@ -800,16 +804,23 @@ void process_P2_DUID (dsd_opts * opts, dsd_state * state)
void processP2 (dsd_opts * opts, dsd_state * state)
{
state->dmr_stereo = 1;
state->currentslot = 1;
//state->currentslot = 1;
p2_dibit_buffer (opts, state);
//look at our ISCH values and determine location in superframe before running frame scramble
for (framing_counter = 0; framing_counter < 11; framing_counter++) //11, or 12
for (framing_counter = 0; framing_counter < 4; framing_counter++) //12
{
process_ISCH (opts, state); //run ISCH in here so we know when to start descramble offset
}
//set initial current slot depending on offset value
if (state->p2_scramble_offset % 2)
{
state->currentslot = 0;
}
else state->currentslot = 1;
//frame_scramble runs lfsr and creates an array of unscrambled bits to pull from
process_Frame_Scramble (opts, state);

View File

@ -75,6 +75,8 @@ void process_SACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[180]
if (SMAC[1] == 0x0) //NULL PDU Check, pass if NULL type
{
//fprintf (stderr, " NULL ");
state->p2_is_lcch = 0; //turn flag off here
goto END_SMAC;
}
else //permit MAC_SIGNAL on CRC ERR if -F option called
{