diff --git a/src/nxdn_deperm.c b/src/nxdn_deperm.c index ae9a2f6..aa8b76e 100644 --- a/src/nxdn_deperm.c +++ b/src/nxdn_deperm.c @@ -52,13 +52,15 @@ void nxdn_descramble(uint8_t dibits[], int len) void nxdn_deperm_facch(dsd_opts * opts, dsd_state * state, uint8_t bits[144]) { - uint8_t deperm[144]; - uint8_t depunc[192]; - uint8_t trellis_buf[96]; + uint8_t deperm[200]; //144 + uint8_t depunc[200]; //192 + uint8_t trellis_buf[400]; //96 uint16_t crc = 0; //crc calculated by function uint16_t check = 0; //crc from payload for comparison int out; - char buf[128]; + + memset (deperm, 0, sizeof(deperm)); + memset (depunc, 0, sizeof(depunc)); for (int i=0; i<144; i++) deperm[PERM_16_9[i]] = bits[i]; @@ -74,7 +76,7 @@ void nxdn_deperm_facch(dsd_opts * opts, dsd_state * state, uint8_t bits[144]) uint8_t temp[210]; uint8_t s0; uint8_t s1; - uint8_t m_data[13]; + uint8_t m_data[20]; //13 memset (temp, 0, sizeof(temp)); memset (m_data, 0, sizeof(m_data)); memset (trellis_buf, 0, sizeof(trellis_buf)); @@ -139,15 +141,14 @@ void nxdn_deperm_facch(dsd_opts * opts, dsd_state * state, uint8_t bits[144]) void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60]) { //see about initializing these variables - uint8_t deperm[60]; - uint8_t depunc[72]; - uint8_t trellis_buf[32]; - uint8_t answer[26]; + uint8_t deperm[200]; //60 + uint8_t depunc[200]; //72 + uint8_t trellis_buf[400]; //32 memset (deperm, 0, sizeof(deperm)); memset (depunc, 0, sizeof(depunc)); memset (trellis_buf, 0, sizeof(trellis_buf)); - memset (answer, 0, sizeof(answer)); + int o = 0; uint8_t crc = 0; //value computed by crc6 on payload uint8_t check = 0; //value pulled from last 6 bits @@ -176,7 +177,7 @@ void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60]) uint8_t temp[90]; uint8_t s0; uint8_t s1; - uint8_t m_data[5]; + uint8_t m_data[10]; //5 memset (temp, 0, sizeof (temp)); memset (m_data, 0, sizeof (m_data)); @@ -229,7 +230,7 @@ void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60]) if (state->nxdn_last_ran != -1) fprintf (stderr, " RAN %02d ", state->nxdn_last_ran); else fprintf (stderr, " "); - uint8_t nsf_sacch[26]; + uint8_t nsf_sacch[400]; memset (nsf_sacch, 0, sizeof(nsf_sacch)); for (int i = 0; i < 26; i++) { @@ -313,13 +314,16 @@ void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60]) void nxdn_deperm_facch2_udch(dsd_opts * opts, dsd_state * state, uint8_t bits[348]) { - uint8_t deperm[348]; - uint8_t depunc[406]; - uint8_t trellis_buf[199]; + uint8_t deperm[500]; //348 + uint8_t depunc[500]; //406 + uint8_t trellis_buf[400]; //199 int id = 0; uint16_t crc = 0; uint16_t check = 0; + memset (deperm, 0, sizeof(deperm)); + memset (depunc, 0, sizeof(depunc)); + for (int i=0; i<348; i++) { deperm[PERM_12_29[i]] = bits[i]; } @@ -341,10 +345,10 @@ void nxdn_deperm_facch2_udch(dsd_opts * opts, dsd_state * state, uint8_t bits[34 } //switch to the convolutional decoder - uint8_t temp[220]; + uint8_t temp[500]; //220, this one was way too small uint8_t s0; uint8_t s1; - uint8_t m_data[26]; + uint8_t m_data[52]; //26 memset (trellis_buf, 0, sizeof(trellis_buf)); memset (temp, 0, sizeof (temp)); memset (m_data, 0, sizeof (m_data)); @@ -390,7 +394,7 @@ void nxdn_deperm_facch2_udch(dsd_opts * opts, dsd_state * state, uint8_t bits[34 check = check | trellis_buf[i+184]; } - uint8_t f2u_message_buffer[199]; + uint8_t f2u_message_buffer[400]; //199 memset (f2u_message_buffer, 0, sizeof(f2u_message_buffer)); //just going to leave this all here in case its needed, like in cac, @@ -403,7 +407,6 @@ void nxdn_deperm_facch2_udch(dsd_opts * opts, dsd_state * state, uint8_t bits[34 if (crc == check) { fprintf (stderr, " F2/U "); - //NXDN_Elements_Content_decode(opts, state, 1, trellis_buf); NXDN_Elements_Content_decode(opts, state, 1, f2u_message_buffer); } else if (opts->aggressive_framesync == 0) NXDN_Elements_Content_decode(opts, state, 0, f2u_message_buffer); @@ -425,12 +428,15 @@ void nxdn_deperm_facch2_udch(dsd_opts * opts, dsd_state * state, uint8_t bits[34 void nxdn_deperm_cac(dsd_opts * opts, dsd_state * state, uint8_t bits[300]) { - uint8_t deperm[300]; - uint8_t depunc[350]; - uint8_t trellis_buf[171]; + uint8_t deperm[500]; //300 + uint8_t depunc[500]; //350 + uint8_t trellis_buf[400]; //171 int id = 0; uint16_t crc = 0; + memset (deperm, 0, sizeof(deperm)); + memset (depunc, 0, sizeof(depunc)); + for (int i=0; i<300; i++) { deperm[PERM_12_25[i]] = bits[i]; } @@ -455,7 +461,7 @@ void nxdn_deperm_cac(dsd_opts * opts, dsd_state * state, uint8_t bits[300]) uint8_t temp[360]; uint8_t s0; uint8_t s1; - uint8_t m_data[26]; + uint8_t m_data[52]; //26 memset (trellis_buf, 0, sizeof(trellis_buf)); memset (temp, 0, sizeof (temp)); memset (m_data, 0, sizeof (m_data)); @@ -490,7 +496,7 @@ void nxdn_deperm_cac(dsd_opts * opts, dsd_state * state, uint8_t bits[300]) crc = crc16cac(trellis_buf, 171); - uint8_t cac_message_buffer[171]; + uint8_t cac_message_buffer[400]; //171 memset (cac_message_buffer, 0, sizeof(cac_message_buffer)); //shift the cac_message into the appropriate byte arrangement for element_decoder -- skip SR field diff --git a/src/nxdn_element.c b/src/nxdn_element.c index b1de2ec..552d3c0 100644 --- a/src/nxdn_element.c +++ b/src/nxdn_element.c @@ -14,10 +14,12 @@ void NXDN_SACCH_Full_decode(dsd_opts * opts, dsd_state * state) { - uint8_t SACCH[72]; + uint8_t SACCH[400]; //72 uint32_t i; uint8_t CrcCorrect = 1; + memset (SACCH, 0, sizeof (SACCH)); + /* Consider all SACCH CRC parts as correct */ CrcCorrect = 1; @@ -53,8 +55,7 @@ void NXDN_Elements_Content_decode(dsd_opts * opts, dsd_state * state, MessageType |= (ElementsContent[6] & 1) << 1; MessageType |= (ElementsContent[7] & 1) << 0; - //only run message type if good CRC? - if (CrcCorrect == 1) nxdn_message_type (opts, state, MessageType); + nxdn_message_type (opts, state, MessageType); /* Save the "F1" and "F2" flags */ state->NxdnElementsContent.F1 = ElementsContent[0]; @@ -239,7 +240,7 @@ void nxdn_location_id_handler (dsd_state * state, uint32_t location_id, uint8_t //type 0 is for current site, type 1 is for adjacent sites if (type == 0) { - state->nxdn_last_ran = site_code; + state->nxdn_last_ran = site_code % 64; //Table 6.3-4 RAN for Trunked Radio Systems if (site_code != 0) state->nxdn_location_site_code = site_code; if (sys_code != 0) state->nxdn_location_sys_code = sys_code; sprintf (state->nxdn_location_category, "%s", category); @@ -848,39 +849,39 @@ void NXDN_decode_adj_site(dsd_opts * opts, dsd_state * state, uint8_t * Message) adj3_site = (uint32_t)ConvertBitIntoBytes(&Message[88], 24); adj3_opt = (uint8_t)ConvertBitIntoBytes(&Message[112], 6); adj3_chan = (uint16_t)ConvertBitIntoBytes(&Message[118], 10); - //4 - adj4_site = (uint32_t)ConvertBitIntoBytes(&Message[128], 24); - adj4_opt = (uint8_t)ConvertBitIntoBytes(&Message[152], 6); - adj4_chan = (uint16_t)ConvertBitIntoBytes(&Message[158], 10); + //4 -- facch2 only + // adj4_site = (uint32_t)ConvertBitIntoBytes(&Message[128], 24); + // adj4_opt = (uint8_t)ConvertBitIntoBytes(&Message[152], 6); + // adj4_chan = (uint16_t)ConvertBitIntoBytes(&Message[158], 10); - if (adj1_site) + if (adj1_opt & 0xF) { - fprintf (stderr, "\n Adjacent Site %d ", adj1_opt & 0xF); + fprintf (stderr, "\n Adjacent Site %d ", adj1_opt & 0xF); fprintf (stderr, "Channel [%03X] [%04d]", adj1_chan, adj1_chan); nxdn_location_id_handler(state, adj1_site, 1); nxdn_channel_to_frequency (opts, state, adj1_chan); } - if (adj2_site) + if (adj2_opt & 0xF) { - fprintf (stderr, "\n Adjacent Site %d ", adj2_opt & 0xF); + fprintf (stderr, "\n Adjacent Site %d ", adj2_opt & 0xF); fprintf (stderr, "Channel [%03X] [%04d]", adj2_chan, adj2_chan); nxdn_location_id_handler(state, adj2_site, 1); nxdn_channel_to_frequency (opts, state, adj2_chan); } - if (adj3_site) + if (adj3_opt & 0xF) { - fprintf (stderr, "\n Adjacent Site %d ", adj3_opt & 0xF); + fprintf (stderr, "\n Adjacent Site %d ", adj3_opt & 0xF); fprintf (stderr, "Channel [%03X] [%04d]", adj3_chan, adj3_chan); nxdn_location_id_handler(state, adj3_site, 1); nxdn_channel_to_frequency (opts, state, adj3_chan); } - if (adj4_site) - { - fprintf (stderr, "\n Adjacent Site %d: ", adj4_opt & 0xF); - fprintf (stderr, "Channel [%03X] [%04d]", adj4_chan, adj4_chan); - nxdn_location_id_handler(state, adj4_site, 1); - nxdn_channel_to_frequency (opts, state, adj4_chan); - } + // if (adj4_opt & 0xF) //facch2 only + // { + // fprintf (stderr, "\n Adjacent Site %d: ", adj4_opt & 0xF); + // fprintf (stderr, "Channel [%03X] [%04d]", adj4_chan, adj4_chan); + // nxdn_location_id_handler(state, adj4_site, 1); + // nxdn_channel_to_frequency (opts, state, adj4_chan); + // } } @@ -897,15 +898,15 @@ void NXDN_decode_adj_site(dsd_opts * opts, dsd_state * state, uint8_t * Message) adj2_opt = (uint8_t)ConvertBitIntoBytes(&Message[80], 6); adj2_bw = (uint8_t)ConvertBitIntoBytes(&Message[86], 2); adj2_chan = (uint16_t)ConvertBitIntoBytes(&Message[88], 16); - //3 - adj3_site = (uint32_t)ConvertBitIntoBytes(&Message[104], 24); - adj3_opt = (uint8_t)ConvertBitIntoBytes(&Message[128], 6); - adj3_bw = (uint8_t)ConvertBitIntoBytes(&Message[134], 2); - adj3_chan = (uint16_t)ConvertBitIntoBytes(&Message[136], 16); + //3 -- facch2 only + // adj3_site = (uint32_t)ConvertBitIntoBytes(&Message[104], 24); + // adj3_opt = (uint8_t)ConvertBitIntoBytes(&Message[128], 6); + // adj3_bw = (uint8_t)ConvertBitIntoBytes(&Message[134], 2); + // adj3_chan = (uint16_t)ConvertBitIntoBytes(&Message[136], 16); - if (adj1_site) + if (adj1_opt & 0xF) { - fprintf (stderr, "\n Adjacent Site %d ", adj1_opt & 0xF); + fprintf (stderr, "\n Adjacent Site %d ", adj1_opt & 0xF); fprintf (stderr, "Channel [%04X] [%05d] ", adj1_chan, adj1_chan); if (adj1_bw == 0) fprintf (stderr, "BW: 6.25 kHz - 4800 bps"); else if (adj1_bw == 1) fprintf (stderr, "BW: 12.5 kHz - 9600 bps"); @@ -913,26 +914,26 @@ void NXDN_decode_adj_site(dsd_opts * opts, dsd_state * state, uint8_t * Message) nxdn_location_id_handler(state, adj1_site, 1); nxdn_channel_to_frequency (opts, state, adj1_chan); } - if (adj2_site) + if (adj2_opt & 0xF) { - fprintf (stderr, "\n Adjacent Site %d ", adj2_opt & 0xF); - fprintf (stderr, "Channel [%04X] [%05d]", adj2_chan, adj2_chan); + fprintf (stderr, "\n Adjacent Site %d ", adj2_opt & 0xF); + fprintf (stderr, "Channel [%04X] [%05d] ", adj2_chan, adj2_chan); if (adj2_bw == 0) fprintf (stderr, "BW: 6.25 kHz - 4800 bps"); else if (adj2_bw == 1) fprintf (stderr, "BW: 12.5 kHz - 9600 bps"); else fprintf (stderr, "BW: %d Reserved Value", adj2_bw); nxdn_location_id_handler(state, adj2_site, 1); nxdn_channel_to_frequency (opts, state, adj2_chan); } - if (adj3_site) - { - fprintf (stderr, "\n Adjacent Site %d: ", adj3_opt & 0xF); - fprintf (stderr, "Channel [%04X] [%05d]", adj3_chan, adj3_chan); - if (adj3_bw == 0) fprintf (stderr, "BW: 6.25 kHz - 4800 bps"); - else if (adj3_bw == 1) fprintf (stderr, "BW: 12.5 kHz - 9600 bps"); - else fprintf (stderr, "BW: %d Reserved Value", adj3_bw); - nxdn_location_id_handler(state, adj3_site, 1); - nxdn_channel_to_frequency (opts, state, adj3_chan); - } + // if (adj3_opt & 0xF) //facch2 only + // { + // fprintf (stderr, "\n Adjacent Site %d: ", adj3_opt & 0xF); + // fprintf (stderr, "Channel [%04X] [%05d] ", adj3_chan, adj3_chan); + // if (adj3_bw == 0) fprintf (stderr, "BW: 6.25 kHz - 4800 bps"); + // else if (adj3_bw == 1) fprintf (stderr, "BW: 12.5 kHz - 9600 bps"); + // else fprintf (stderr, "BW: %d Reserved Value", adj3_bw); + // nxdn_location_id_handler(state, adj3_site, 1); + // nxdn_channel_to_frequency (opts, state, adj3_chan); + // } } fprintf (stderr, "%s", KNRM);