Code Cleanup and Tweaks

Code Cleanup and Tweaks
--properly accredit LFSR
--change name from LSFR to LFSR (oops)
--minor code tweaks and OCD Spacing
This commit is contained in:
lwvmobile 2022-05-30 03:19:21 -04:00 committed by GitHub
parent 6ad98fbf69
commit 66ec027bd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 134 additions and 63 deletions

View File

@ -368,6 +368,7 @@ typedef struct
int frame_dpmr;
//
short int dmr_stereo;
//
int frame_ysf;
int inverted_ysf; //not sure if ysf comes in inverted or not, but signal could if IQ flipped
@ -472,7 +473,8 @@ typedef struct
int payload_mfid;
int payload_mfidR;
int payload_mi;
int payload_miR;
int payload_miR; //check to see if anything tied to this still functions appropriately
uint64_t payload_miP;
int payload_lsfr;
int payload_lsfrR;
unsigned long long int K;
@ -570,6 +572,9 @@ typedef struct
short int dmr_ms_mode;
unsigned int dmrburstL;
unsigned int dmrburstR;
int dropL;
int dropR;
unsigned long long int R;
//dstar header for ncurses
unsigned char dstarradioheader[41];
@ -820,7 +825,9 @@ void ProcessMBCData(dsd_opts * opts, dsd_state * state, uint8_t info[196], uint8
void ProcessMBChData(dsd_opts * opts, dsd_state * state, uint8_t info[196], uint8_t syncdata[48], uint8_t SlotType[20]);
void ProcessWTFData(dsd_opts * opts, dsd_state * state, uint8_t info[196], uint8_t syncdata[48], uint8_t SlotType[20]);
void ProcessUnifiedData(dsd_opts * opts, dsd_state * state, uint8_t info[196], uint8_t syncdata[48], uint8_t SlotType[20]);
int LSFR(dsd_state * state);
//LFSR code courtesy of https://github.com/mattames/LFSR/
int LFSR(dsd_state * state);
int LFSRP(dsd_state * state);
void Hamming_7_4_init();
void Hamming_7_4_encode(unsigned char *origBits, unsigned char *encodedBits);

View File

@ -170,10 +170,18 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
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
}
}
sync[24] = 0;
if (internalslot == 0 && vc1 == 6)
{
fprintf (stderr, "\nVC6 Burst = %X\n", syncdata);
}
if (internalslot == 1 && vc2 == 6)
{
fprintf (stderr, "\nVC6 Burst = %X\n", syncdata);
}
EmbeddedSignallingOk = -1;
if(QR_16_7_6_decode(EmbeddedSignalling))
@ -251,10 +259,12 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
if (internalslot == 0)
{
vc1 = 1;
state->dropL = 256;
}
if (internalslot == 1)
{
vc2 = 1;
state->dropR = 256;
}
}
@ -274,6 +284,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
else fprintf (stderr,"Sync: -DMR ");
//constantly reset the vc counter to 1 each data frame in anticipation of new voice frame
vc1 = 1;
state->dropL = 256;
}
if (internalslot == 1)
{
@ -287,6 +298,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
else fprintf (stderr,"Sync: -DMR ");
//constantly reset the vc counter to 1 each data frame in anticipation of new voice frame
vc2 = 1;
state->dropR = 256;
}
processDMRdata (opts, state);
skipcount++; //after 2 data frames, drop back to getFrameSync and process subsequent data with processDMRdata
@ -325,7 +337,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
}
if (vc1 == 1 && state->payload_keyid != 0 && opts->payload == 1)
{
LSFR(state);
LFSR(state);
}
fprintf (stderr, "\n");
}
@ -340,7 +352,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
}
if (vc1 == 1 && state->payload_keyid != 0 && opts->payload == 1)
{
LSFR(state);
LFSR(state);
}
fprintf (stderr, "\n");
}
@ -360,7 +372,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
}
if (vc2 == 1 && state->payload_keyidR != 0 && opts->payload == 1)
{
LSFR(state);
LFSR(state);
}
fprintf (stderr, "\n");
}
@ -375,7 +387,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
}
if (vc2 == 1 && state->payload_keyidR != 0 && opts->payload == 1)
{
LSFR(state);
LFSR(state);
}
fprintf (stderr, "\n");
}
@ -643,6 +655,9 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
}
//these ambe_fr values are set correctly now!
//reset drop values since we don't know which slot (because I'm too lazy to write that part)
state->dropL = 256;
state->dropR = 256;
processMbeFrame (opts, state, NULL, ambe_fr, NULL);
processMbeFrame (opts, state, NULL, ambe_fr2, NULL);
processMbeFrame (opts, state, NULL, ambe_fr3, NULL);

View File

@ -276,6 +276,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
if (internalslot == 0)
{
vc1 = 1;
state->dropL = 256;
fprintf (stderr, "MS Slot 1 Voice Sync \n");
//activeslot = 0;
@ -283,6 +284,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
if (internalslot == 1)
{
vc2 = 1;
state->dropR = 256;
//fprintf (stderr, "MS Slot 2 Voice Sync \n");
//activeslot = 1;
}
@ -390,7 +392,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
}
if (vc1 == 6 && state->payload_keyid != 0 && opts->payload == 1)
{
LSFR(state);
LFSR(state);
}
fprintf (stderr, "\n");
}
@ -406,7 +408,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
}
if (vc1 == 6 && state->payload_keyid != 0 && opts->payload == 1)
{
LSFR(state);
LFSR(state);
}
fprintf (stderr, "\n");
}
@ -422,7 +424,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
}
if (vc2 == 6 && state->payload_keyidR != 0 && opts->payload == 1)
{
LSFR(state);
LFSR(state);
}
fprintf (stderr, "\n");
}
@ -437,7 +439,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
}
if (vc2 == 6 && state->payload_keyidR != 0 && opts->payload == 1)
{
LSFR(state);
LFSR(state);
}
fprintf (stderr, "\n");
}
@ -690,6 +692,9 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
}
fprintf (stderr, "\n");
}
//reset drop values since we don't know which slot (because I'm too lazy to write that part)
state->dropL = 256;
state->dropR = 256;
processMbeFrame (opts, state, NULL, ambe_fr, NULL);
processMbeFrame (opts, state, NULL, ambe_fr2, NULL);
processMbeFrame (opts, state, NULL, ambe_fr3, NULL);
@ -760,6 +765,7 @@ void dmrMSData (dsd_opts * opts, dsd_state * state)
//process data
state->dmr_stereo = 1;
state->dmr_ms_mode = 1;
//only run if payload is set to 1 due to errors with MS data
if (opts->payload == 1)
{
@ -768,6 +774,9 @@ void dmrMSData (dsd_opts * opts, dsd_state * state)
state->dmr_stereo = 0;
state->dmr_ms_mode = 0;
//reset drop values since we don't know which slot (because I'm too lazy to write that part)
state->dropL = 256;
state->dropR = 256;
//get potential first half payload dibits and store them in the payload for the next repitition, MS voice or data.
skipDibit (opts, state, 144);

View File

@ -18,9 +18,11 @@
#include "dsd.h"
#include "dmr_const.h"
#include "p25p1_check_hdu.h"
//
//
//A
//
void ProcessDMR (dsd_opts * opts, dsd_state * state)
{
uint32_t i, j;
@ -116,6 +118,8 @@ if (state->currentslot == 1 && state->K > 0 && state->dmr_soR & 0x40 && state->p
}
}
//
//B
//
if (state->currentslot == 0)
{
if (opts->payload == 1)

View File

@ -2081,14 +2081,24 @@ void ProcessDmrTerminaisonLC(dsd_opts * opts, dsd_state * state, uint8_t info[19
//fprintf(stderr, "FID=0x%02X ", TSVoiceSupFrame->FullLC.FeatureSetID);
//reset alg, keys, mi during a TLC call termination EVENT so we aren't stuck on an old value, PI header will proceed a new call if BP isn't used
state->payload_algid = 0;
state->payload_keyid = 0;
//state->payload_mfid = 0;
state->payload_mi = 0;
state->payload_algidR = 0;
state->payload_keyidR = 0;
//state->payload_mfid = 0;
state->payload_miR = 0;
//assuming the TLC frame comes on the same slot as the call it was terminating? not sure?
if (state->currentslot == 0)
{
state->payload_algid = 0;
state->payload_keyid = 0;
//state->payload_mfid = 0;
//state->payload_mi = 0; //let's try disabling this for a bit
}
if (state->currentslot == 1)
{
state->payload_algidR = 0;
state->payload_keyidR = 0;
//state->payload_mfid = 0;
//state->payload_miR = 0; ////let's try disabling this for a bit
}
//tlc
if((IrrecoverableErrors == 0) && CRCCorrect) //amateur DMR seems to only set radio ID up here I think, figure out best way to set without messing up other DMR types
@ -2537,8 +2547,10 @@ void ProcessVoiceBurstSync(dsd_opts * opts, dsd_state * state)
} /* End ProcessVoiceBurstSync() */
int LSFR(dsd_state * state)
//LFSR code courtesy of https://github.com/mattames/LFSR/
int LFSR(dsd_state * state)
{
//int lfsr = 0;
int lfsr = 0;
if (state->currentslot == 0)
{
@ -2575,6 +2587,7 @@ int LSFR(dsd_state * state)
state->payload_miR = lfsr;
}
}
/*
* @brief : This function compute the CRC-CCITT of the DMR data
* by using the polynomial x^16 + x^12 + x^5 + 1

View File

@ -645,11 +645,11 @@ void processDMRvoice (dsd_opts * opts, dsd_state * state)
/* Perform the DMR voice decoding */
ProcessDMR(opts, state);
//LSFR if required
//LFSR if required, change condition?
if ( (state->currentslot == 0 && state->payload_keyid != 0 && opts->payload == 1) ||
(state->currentslot == 1 && state->payload_keyidR != 0 && opts->payload == 1) )
{
LSFR(state);
LFSR(state);
}
if(opts->errorbars == 1)

View File

@ -133,6 +133,9 @@ noCarrier (dsd_opts * opts, dsd_state * state)
mbe_initMbeParms (state->cur_mp2, state->prev_mp2, state->prev_mp_enhanced2);
state->dmr_ms_mode = 0;
state->dropL = 256; //drop it like its hot
state->dropR = 256; //drop it like its hot
}
void
@ -363,8 +366,8 @@ initState (dsd_state * state)
state->dpmr_caller_id = 0;
state->dpmr_target_id = 0;
state->payload_mi = 0;
state->payload_miR = 0;
//state->payload_mi = 0;
//state->payload_miR = 0;
state->payload_mfid = 0;
state->payload_mfidR = 0;
state->payload_algid = 0;
@ -399,6 +402,7 @@ initState (dsd_state * state)
sprintf (state->dmr_lrrp[1][5], "");
state->K = 0;
state->R = 0; //make configurable later on?
state->dmr_stereo = 0;
state->dmrburstL = 17; //initialize at higher value than possible
state->dmrburstR = 17; //17 in char array is set for ERR
@ -408,6 +412,9 @@ initState (dsd_state * state)
state->dmr_fidR = 0;
state->dmr_ms_mode = 0;
state->dropL = 256; //drop it like its hot
state->dropR = 256; //drop it like its hot
memset(state->dstarradioheader, 0, 41);
#ifdef TRACE_DSD
@ -840,6 +847,10 @@ main (int argc, char **argv)
}
break;
case 'R':
sscanf (optarg, "%lld", &state.R);
break;
case 'G': //Set rtl device gain
sscanf (optarg, "%d", &opts.rtl_gain_value); //multiple value by ten to make it consitent with the way rtl_fm really works
break;
@ -977,10 +988,10 @@ main (int argc, char **argv)
strncpy(opts.serial_dev, optarg, 1023);
opts.serial_dev[1023] = '\0';
break;
case 'R':
sscanf (optarg, "%d", &opts.resume);
fprintf (stderr,"Enabling scan resume after %i TDULC frames\n", opts.resume);
break;
//case 'R':
// sscanf (optarg, "%d", &opts.resume);
// fprintf (stderr,"Enabling scan resume after %i TDULC frames\n", opts.resume);
// break;
case 'f':
if (optarg[0] == 'a')
{

View File

@ -17,7 +17,9 @@
#include "dsd.h"
//static void DecipherData(char * Input, char * KeyStream, char * Output, int NbData);
//
//C
//
void
playMbeFiles (dsd_opts * opts, dsd_state * state, int argc, char **argv)
@ -77,7 +79,7 @@ playMbeFiles (dsd_opts * opts, dsd_state * state, int argc, char **argv)
void
processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char ambe_fr[4][24], char imbe7100_fr[7][24])
{
//is this the best placement for this array?
//
int BP[256] = {
0x0000, 0x1F00, 0xE300, 0xFC00, 0x2503, 0x3A03, 0xC603, 0xD903,
@ -180,7 +182,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
//stereo slots and slot 0 (left slot)
if (state->currentslot == 0 && opts->dmr_stereo == 1)
{
//seperate the ecc, demodulation, slip in xor, and processdata instead?
state->errs = mbe_eccAmbe3600x2450C0 (ambe_fr);
state->errs2 = state->errs;
mbe_demodulateAmbe3600x2450Data (ambe_fr);
@ -195,6 +197,9 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
ambe_d[j] ^= x;
}
}
//
//D
//
mbe_processAmbe2450Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str,
ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality);
@ -208,7 +213,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
//stereo slots and slot 1 (right slot)
if (state->currentslot == 1 && opts->dmr_stereo == 1)
{
//seperate the ecc, demodulation, slip in xor, and processdata instead?
state->errsR = mbe_eccAmbe3600x2450C0 (ambe_fr);
state->errs2R = state->errsR;
mbe_demodulateAmbe3600x2450Data (ambe_fr);
@ -223,6 +228,9 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
ambe_d[j] ^= x;
}
}
//
//E
//
mbe_processAmbe2450Dataf (state->audio_out_temp_bufR, &state->errsR, &state->errs2R, state->err_strR,
ambe_d, state->cur_mp2, state->prev_mp2, state->prev_mp_enhanced2, opts->uvquality);
@ -233,7 +241,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
PrintAMBEData (opts, state, ambe_d);
}
}
//if using older DMR method, dPMR, NXDN?
//if using older DMR method, dPMR, or NXDN
if (opts->dmr_stereo == 0)
{
mbe_processAmbe3600x2450Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_fr, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality);
@ -250,14 +258,6 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
}
if (opts->errorbars == 1)
{
//state->err_buf = state->err_str; //make comy to compare, and only print when comparison differs?? THIS HERE HERE
//strncpy (state->err_buf, state->err_str, sizeof(state->err_str)); //is this the correct placement for this? want it just before err_str is set?
//fprintf (stderr, "%s", state->err_str); //this the actual error 'bar' ==== printer, find way to keep this entire string from printing constantly unless err_str changes
//fprintf (stderr, "%s", state->err_buf);
}
state->debug_audio_errors += state->errs2;
state->debug_audio_errorsR += state->errs2R;
if (opts->dmr_stereo == 1 && state->currentslot == 0)
@ -288,23 +288,5 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
{
writeSynthesizedVoice (opts, state);
}
/*
if (opts->audio_out == 1)
{
playSynthesizedVoice (opts, state);
}
*/
}
/* This function decipher data */
/* //does anything even call this function?
static void DecipherData(char * Input, char * KeyStream, char * Output, int NbData)
{
int i;
for(i = 0; i < NbData; i++)
{
Output[i] = Input[i] ^ KeyStream[i];
}
}
*/

View File

@ -163,8 +163,8 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
state->payload_keyidR = 0;
state->payload_algidR = 0;
//state->payload_mfid = 0;
state->payload_mi = 0;
state->payload_miR = 0;
//state->payload_mi = 0;
//state->payload_miR = 0;
state->nxdn_key = 0;
state->nxdn_cipher_type = 0;

View File

@ -373,6 +373,9 @@ processLDU2 (dsd_opts * opts, dsd_state * state)
mihex1 = (unsigned long long int)ConvertBitIntoBytes(&mi[0], 32);
mihex2 = (unsigned long long int)ConvertBitIntoBytes(&mi[32], 32);
mihex3 = (unsigned long long int)ConvertBitIntoBytes(&mi[64], 8);
//need to check this for accuracy, may be incorrect, MI may also be incorrect, I have 72, but LFSR shows 64
state->payload_miP = (mihex1 << 40) | (mihex2 << 8) | mihex3;
}
if (1 == 1) //print on payload == 1
@ -381,10 +384,37 @@ processLDU2 (dsd_opts * opts, dsd_state * state)
fprintf (stderr, " LDU2 ALG ID: 0x%02X KEY ID: 0x%02X MI: 0x%08llX%08llX%02llX\n", algidhex, kidhex, mihex1, mihex2, mihex3);
fprintf (stderr, "%s", KNRM);
}
if (opts->payload == 1)
{
//LFSRP(state);
}
//why am I doing this part below again?
if (opts->payload == 0)
{
algidhex = strtol (algid, NULL, 2);
kidhex = strtol (kid, NULL, 2);
}
}
//needs some work to make mi value fit in there since its a 72 bit value, need to check this over
//LFSR code courtesy of https://github.com/mattames/LFSR/
int LFSRP(dsd_state * state)
{
uint64_t lfsr = 0;
lfsr = state->payload_miP;
uint8_t cnt = 0;
for(cnt=0;cnt<32;cnt++)
{
// Polynomial is C(x) = x^64 + x^62 + x^46 + x^38 + x^27 + x^15 + 1
uint64_t bit = ((lfsr >> 63) ^ (lfsr >> 61) ^ (lfsr >> 45) ^ (lfsr >> 37) ^ (lfsr >> 26) ^ (lfsr >> 14)) & 0x1;
lfsr = (lfsr << 1) | (bit);
}
fprintf (stderr, "%s", KYEL);
fprintf (stderr, " LDU2 ALG ID: 0x%02X KEY ID: 0x%02X", state->payload_algid, state->payload_keyid);
fprintf(stderr, " Next MI: 0x%016X \n", lfsr);
fprintf (stderr, "%s", KNRM);
state->payload_miP = lfsr;
}