diff --git a/NXDNCRC.cpp b/NXDNCRC.cpp index 12058a2..cccbb84 100644 --- a/NXDNCRC.cpp +++ b/NXDNCRC.cpp @@ -23,15 +23,10 @@ #include const uint8_t BIT_MASK_TABLE1[] = { 0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U }; -const uint16_t BIT_MASK_TABLE2[] = { 0x8000U, 0x4000U, 0x2000U, 0x1000U, 0x0800U, 0x0400U, 0x0200U, 0x0100U, - 0x0080U, 0x0040U, 0x0020U, 0x0010U, 0x0008U, 0x0004U, 0x0002U, 0x0001U }; #define WRITE_BIT1(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE1[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE1[(i)&7]) #define READ_BIT1(p,i) (p[(i)>>3] & BIT_MASK_TABLE1[(i)&7]) -#define WRITE_BIT2(p,i,b) p[(i)>>4] = (b) ? (p[(i)>>4] | BIT_MASK_TABLE2[(i)&15]) : (p[(i)>>3] & ~BIT_MASK_TABLE2[(i)&15]) -#define READ_BIT2(p,i) (p[(i)>>4] & BIT_MASK_TABLE2[(i)&15]) - bool CNXDNCRC::checkCRC6(const unsigned char* in, unsigned int length) { assert(in != NULL); @@ -46,7 +41,7 @@ bool CNXDNCRC::checkCRC6(const unsigned char* in, unsigned int length) WRITE_BIT1(temp, i, b); } - LogMessage("NXDN, CRC6: new:%02X old:%02X", crc, temp[0U]); + // LogMessage("NXDN, CRC6: new:%02X old:%02X", crc, temp[0U]); return crc == temp[0U]; } @@ -58,8 +53,10 @@ void CNXDNCRC::encodeCRC6(unsigned char* in, unsigned int length) uint8_t crc[1U]; crc[0U] = createCRC6(in, length); + // LogMessage("NXDN, CRC6: new:%02X", crc[0U]); + unsigned int n = length; - for (unsigned int i = 0U; i < 6U; i++, n++) { + for (unsigned int i = 2U; i < 8U; i++, n++) { bool b = READ_BIT1(crc, i); WRITE_BIT1(in, n, b); } @@ -70,30 +67,39 @@ bool CNXDNCRC::checkCRC12(const unsigned char* in, unsigned int length) assert(in != NULL); uint16_t crc = createCRC12(in, length); + uint8_t temp1[2U]; + temp1[0U] = (crc >> 8) & 0xFFU; + temp1[1U] = (crc >> 0) & 0xFFU; - uint16_t temp[1U]; - temp[0U] = 0x00U; + uint8_t temp2[2U]; + temp2[0U] = 0x00U; + temp2[1U] = 0x00U; unsigned int j = length; for (unsigned int i = 4U; i < 16U; i++, j++) { bool b = READ_BIT1(in, j); - WRITE_BIT2(temp, i, b); + WRITE_BIT1(temp2, i, b); } - LogMessage("NXDN, CRC12: new:%04X old:%04X", crc, temp[0U]); + // LogMessage("NXDN, CRC12: new:%02X%02X old:%02X%02X", temp1[0U], temp1[1U], temp2[0U], temp2[1U]); - return crc == temp[0U]; + return temp1[0U] == temp2[0U] && temp1[1U] == temp2[1U]; } void CNXDNCRC::encodeCRC12(unsigned char* in, unsigned int length) { assert(in != NULL); - uint16_t crc[1U]; - crc[0U] = createCRC12(in, length); + uint16_t crc = createCRC12(in, length); + + uint8_t temp[2U]; + temp[0U] = (crc >> 8) & 0xFFU; + temp[1U] = (crc >> 0) & 0xFFU; + + // LogMessage("NXDN, CRC12: new:%02X%02X", temp[0U], temp[1U]); unsigned int n = length; - for (unsigned int i = 0U; i < 12U; i++, n++) { - bool b = READ_BIT2(crc, i); + for (unsigned int i = 4U; i < 16U; i++, n++) { + bool b = READ_BIT1(temp, i); WRITE_BIT1(in, n, b); } } @@ -103,30 +109,39 @@ bool CNXDNCRC::checkCRC15(const unsigned char* in, unsigned int length) assert(in != NULL); uint16_t crc = createCRC15(in, length); + uint8_t temp1[2U]; + temp1[0U] = (crc >> 8) & 0xFFU; + temp1[1U] = (crc >> 0) & 0xFFU; - uint16_t temp[1U]; - temp[0U] = 0x00U; + uint16_t temp2[2U]; + temp2[0U] = 0x00U; + temp2[1U] = 0x00U; unsigned int j = length; for (unsigned int i = 1U; i < 16U; i++, j++) { bool b = READ_BIT1(in, j); - WRITE_BIT2(temp, i, b); + WRITE_BIT1(temp2, i, b); } - LogMessage("NXDN, CRC15: new:%04X old:%04X", crc, temp[0U]); + // LogMessage("NXDN, CRC15: new:%02X%02X old:%02X%02X", temp1[0U], temp1[1U], temp2[0U], temp2[1U]); - return crc == temp[0U]; + return temp1[0U] == temp2[0U] && temp1[1U] == temp2[1U]; } void CNXDNCRC::encodeCRC15(unsigned char* in, unsigned int length) { assert(in != NULL); - uint16_t crc[1U]; - crc[0U] = createCRC15(in, length); + uint16_t crc = createCRC15(in, length); + + uint8_t temp[2U]; + temp[0U] = (crc >> 8) & 0xFFU; + temp[1U] = (crc >> 0) & 0xFFU; + + // LogMessage("NXDN, CRC15: new:%02X%02X", temp[0U], temp[1U]); unsigned int n = length; - for (unsigned int i = 0U; i < 15U; i++, n++) { - bool b = READ_BIT2(crc, i); + for (unsigned int i = 1U; i < 16U; i++, n++) { + bool b = READ_BIT1(temp, i); WRITE_BIT1(in, n, b); } } diff --git a/NXDNControl.cpp b/NXDNControl.cpp index b140eb7..5f4b626 100644 --- a/NXDNControl.cpp +++ b/NXDNControl.cpp @@ -175,7 +175,7 @@ bool CNXDNControl::processVoice(unsigned char usc, unsigned char option, unsigne if (ran != m_ran && ran != 0U) return false; } else if (m_rfState == RS_RF_LISTENING) { - // return false; + return false; } // XXX Reconstruct invalid LICH @@ -186,8 +186,8 @@ bool CNXDNControl::processVoice(unsigned char usc, unsigned char option, unsigne bool valid = facch.decode(data + 2U, NXDN_FSW_LENGTH_BITS + NXDN_LICH_LENGTH_BITS + NXDN_SACCH_LENGTH_BITS); if (!valid) valid = facch.decode(data + 2U, NXDN_FSW_LENGTH_BITS + NXDN_LICH_LENGTH_BITS + NXDN_SACCH_LENGTH_BITS + NXDN_FACCH1_LENGTH_BITS); - // if (!valid) - // return false; + if (!valid) + return false; unsigned char buffer[10U]; facch.getData(buffer); @@ -273,8 +273,7 @@ bool CNXDNControl::processVoice(unsigned char usc, unsigned char option, unsigne } return true; - } - else { + } else { // if (valid) { unsigned char message[3U]; sacch.getData(message); @@ -451,24 +450,6 @@ bool CNXDNControl::processVoice(unsigned char usc, unsigned char option, unsigne m_display->writeNXDNRSSI(m_rssi); -#ifdef notdef - // Process end of audio here - if (endofdata) { - if (m_rfState == RS_RF_AUDIO) { - if (m_rssi != 0U) - LogMessage("NXDN, received RF end of transmission, %.1f seconds, BER: %.1f%%, RSSI: -%u/-%u/-%u dBm", float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits), m_minRSSI, m_maxRSSI, m_aveRSSI / m_rssiCount); - else - LogMessage("NXDN, received RF end of transmission, %.1f seconds, BER: %.1f%%", float(m_rfFrames) / 10.0F, float(m_rfErrs * 100U) / float(m_rfBits)); - - writeEndRF(); - } else { - m_rfState = RS_RF_LISTENING; - m_rfMask = 0x00U; - return false; - } - } -#endif - return true; } diff --git a/NXDNFACCH1.cpp b/NXDNFACCH1.cpp index 8080d52..ca2a9fc 100644 --- a/NXDNFACCH1.cpp +++ b/NXDNFACCH1.cpp @@ -115,7 +115,7 @@ bool CNXDNFACCH1::decode(const unsigned char* data, unsigned int offset) conv.chainback(m_data, 96U); - CUtils::dump("NXDN, FACCH1 decoded", m_data, 12U); + // CUtils::dump("NXDN, FACCH1 decoded", m_data, 12U); return CNXDNCRC::checkCRC12(m_data, 80U); } @@ -126,7 +126,7 @@ void CNXDNFACCH1::encode(unsigned char* data, unsigned int offset) const unsigned char temp1[12U]; ::memset(temp1, 0x00U, 12U); - ::memcpy(temp1, data, 10U); + ::memcpy(temp1, m_data, 10U); CNXDNCRC::encodeCRC12(temp1, 80U); diff --git a/NXDNSACCH.cpp b/NXDNSACCH.cpp index 323e48d..b060fa4 100755 --- a/NXDNSACCH.cpp +++ b/NXDNSACCH.cpp @@ -108,7 +108,7 @@ bool CNXDNSACCH::decode(const unsigned char* data) conv.chainback(m_data, 36U); - CUtils::dump("NXDN, SACCH decoded", m_data, 4U); + // CUtils::dump("NXDN, SACCH decoded", m_data, 4U); return CNXDNCRC::checkCRC6(m_data, 26U); } @@ -127,7 +127,7 @@ void CNXDNSACCH::encode(unsigned char* data) const CNXDNCRC::encodeCRC6(temp1, 26U); - CUtils::dump("NXDN, SACCH encoded with CRC", temp1, 5U); + // CUtils::dump("NXDN, SACCH encoded with CRC", temp1, 4U); unsigned char temp2[9U]; diff --git a/NXDNUDCH.cpp b/NXDNUDCH.cpp index 3581474..c4ead27 100644 --- a/NXDNUDCH.cpp +++ b/NXDNUDCH.cpp @@ -93,7 +93,7 @@ bool CNXDNUDCH::decode(const unsigned char* data) { assert(data != NULL); - CUtils::dump("NXDN, UDCH/FACCH2 input", data, 44U); + // CUtils::dump("NXDN, UDCH/FACCH2 input", data, 44U); unsigned char temp1[44U]; @@ -103,7 +103,7 @@ bool CNXDNUDCH::decode(const unsigned char* data) WRITE_BIT1(temp1, i, b); } - CUtils::dump("NXDN, UDCH/FACCH2 de-interleaved", temp1, 44U); + // CUtils::dump("NXDN, UDCH/FACCH2 de-interleaved", temp1, 44U); uint8_t temp2[420U]; @@ -136,7 +136,7 @@ bool CNXDNUDCH::decode(const unsigned char* data) conv.chainback(m_data, 203U); - CUtils::dump("NXDN, UDCH/FACCH2 decoded", m_data, 25U); + // CUtils::dump("NXDN, UDCH/FACCH2 decoded", m_data, 25U); return CNXDNCRC::checkCRC15(m_data, 184U); } @@ -147,18 +147,18 @@ void CNXDNUDCH::encode(unsigned char* data) const unsigned char temp1[25U]; ::memset(temp1, 0x00U, 25U); - ::memcpy(temp1, data, 23U); + ::memcpy(temp1, m_data, 23U); CNXDNCRC::encodeCRC15(temp1, 184U); - CUtils::dump("NXDN, UDCH/FACCH2 encoded with CRC", temp1, 25U); + // CUtils::dump("NXDN, UDCH/FACCH2 encoded with CRC", temp1, 25U); unsigned char temp2[51U]; CNXDNConvolution conv; conv.encode(temp1, temp2, 203U); - CUtils::dump("NXDN, UDCH/FACCH2 convolved", temp2, 51U); + // CUtils::dump("NXDN, UDCH/FACCH2 convolved", temp2, 51U); unsigned char temp3[44U]; @@ -174,7 +174,7 @@ void CNXDNUDCH::encode(unsigned char* data) const } } - CUtils::dump("NXDN, UDCH/FACCH2 punctured", temp3, 44U); + // CUtils::dump("NXDN, UDCH/FACCH2 punctured", temp3, 44U); for (unsigned int i = 0U; i < NXDN_FACCH2_LENGTH_BITS; i++) { unsigned int n = INTERLEAVE_TABLE[i] + NXDN_FSW_LENGTH_BITS + NXDN_LICH_LENGTH_BITS;