diff --git a/P25Defines.h b/P25Defines.h index 9aede9e..e4fa287 100644 --- a/P25Defines.h +++ b/P25Defines.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2016,2017 by Jonathan Naylor G4KLX + * Copyright (C) 2018 by Bryan Biedenkapp * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,14 +42,20 @@ const unsigned int P25_TERM_FRAME_LENGTH_BITS = P25_TERM_FRAME_LENGTH_BYTES const unsigned int P25_TERM_FRAME_LENGTH_SYMBOLS = P25_TERM_FRAME_LENGTH_BYTES * 4U; const unsigned int P25_TERM_FRAME_LENGTH_SAMPLES = P25_TERM_FRAME_LENGTH_SYMBOLS * P25_RADIO_SYMBOL_LENGTH; +const unsigned int P25_TSDU_FRAME_LENGTH_BYTES = 45U; +const unsigned int P25_TSDU_FRAME_LENGTH_BITS = P25_TSDU_FRAME_LENGTH_BYTES * 8U; +const unsigned int P25_TSDU_FRAME_LENGTH_SYMBOLS = P25_TSDU_FRAME_LENGTH_BYTES * 4U; +const unsigned int P25_TSDU_FRAME_LENGTH_SAMPLES = P25_TSDU_FRAME_LENGTH_SYMBOLS * P25_RADIO_SYMBOL_LENGTH; + const unsigned int P25_SYNC_LENGTH_BYTES = 6U; const unsigned int P25_SYNC_LENGTH_BITS = P25_SYNC_LENGTH_BYTES * 8U; const unsigned int P25_SYNC_LENGTH_SYMBOLS = P25_SYNC_LENGTH_BYTES * 4U; const unsigned int P25_SYNC_LENGTH_SAMPLES = P25_SYNC_LENGTH_SYMBOLS * P25_RADIO_SYMBOL_LENGTH; -const unsigned int P25_NID_LENGTH_BITS = 64U; -const unsigned int P25_NID_LENGTH_SYMBOLS = 32U; -const unsigned int P25_NID_LENGTH_SAMPLESS = P25_NID_LENGTH_SYMBOLS * P25_RADIO_SYMBOL_LENGTH; +const unsigned int P25_NID_LENGTH_BYTES = 8U; +const unsigned int P25_NID_LENGTH_BITS = P25_NID_LENGTH_BYTES * 8U; +const unsigned int P25_NID_LENGTH_SYMBOLS = P25_NID_LENGTH_BYTES * 4U; +const unsigned int P25_NID_LENGTH_SAMPLES = P25_NID_LENGTH_SYMBOLS * P25_RADIO_SYMBOL_LENGTH; const uint8_t P25_SYNC_BYTES[] = {0x55U, 0x75U, 0xF5U, 0xFFU, 0x77U, 0xFFU}; const uint8_t P25_SYNC_BYTES_LENGTH = 6U; @@ -65,5 +72,13 @@ const int8_t P25_SYNC_SYMBOLS_VALUES[] = {+3, +3, +3, +3, +3, -3, +3, +3, -3, -3 const uint32_t P25_SYNC_SYMBOLS = 0x00FB30A0U; const uint32_t P25_SYNC_SYMBOLS_MASK = 0x00FFFFFFU; +const uint8_t P25_DUID_HDU = 0x00U; // Header Data Unit +const uint8_t P25_DUID_TDU = 0x03U; // Simple Terminator Data Unit +const uint8_t P25_DUID_LDU1 = 0x05U; // Logical Link Data Unit 1 +const uint8_t P25_DUID_TSDU = 0x07U; // Trunking System Data Unit +const uint8_t P25_DUID_LDU2 = 0x0AU; // Logical Link Data Unit 2 +const uint8_t P25_DUID_PDU = 0x0CU; // Packet Data Unit +const uint8_t P25_DUID_TDULC = 0x0FU; // Terminator Data Unit with Link Control + #endif diff --git a/P25RX.cpp b/P25RX.cpp index 9228c5b..c4070d5 100644 --- a/P25RX.cpp +++ b/P25RX.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2009-2017 by Jonathan Naylor G4KLX + * Copyright (C) 2018 by Bryan Biedenkapp * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +24,8 @@ const q15_t SCALING_FACTOR = 18750; // Q15(0.57) +const uint8_t CORRELATION_COUNTDOWN = 10U;//5U; + const uint8_t MAX_SYNC_BIT_START_ERRS = 2U; const uint8_t MAX_SYNC_BIT_RUN_ERRS = 4U; @@ -60,7 +63,8 @@ m_threshold(), m_thresholdVal(0), m_averagePtr(NOAVEPTR), m_rssiAccum(0U), -m_rssiCount(0U) +m_rssiCount(0U), +m_duid(0U) { } @@ -84,6 +88,7 @@ void CP25RX::reset() m_countdown = 0U; m_rssiAccum = 0U; m_rssiCount = 0U; + m_duid = 0U; } void CP25RX::samples(const q15_t* samples, uint16_t* rssi, uint8_t length) @@ -113,8 +118,10 @@ void CP25RX::samples(const q15_t* samples, uint16_t* rssi, uint8_t length) } m_dataPtr++; - if (m_dataPtr >= P25_LDU_FRAME_LENGTH_SAMPLES) + if (m_dataPtr >= P25_LDU_FRAME_LENGTH_SAMPLES) { m_dataPtr = 0U; + m_duid = 0U; + } m_bitPtr++; if (m_bitPtr >= P25_RADIO_SYMBOL_LENGTH) @@ -169,16 +176,67 @@ void CP25RX::processHdr(q15_t sample) } if (m_dataPtr == m_maxSyncPtr) { - if (m_hdrSyncPtr != m_lduSyncPtr) { - calculateLevels(m_hdrStartPtr, P25_HDR_FRAME_LENGTH_SYMBOLS); + uint16_t nidStartPtr = m_hdrStartPtr + P25_SYNC_LENGTH_SAMPLES; + if (nidStartPtr >= P25_LDU_FRAME_LENGTH_SAMPLES) + nidStartPtr -= P25_LDU_FRAME_LENGTH_SAMPLES; - DEBUG4("P25RX: sync found in Hdr pos/centre/threshold", m_hdrSyncPtr, m_centreVal, m_thresholdVal); + uint8_t nid[2U]; + samplesToBits(nidStartPtr, (2U * 4U), nid, 0U, m_centreVal, m_thresholdVal); + // DEBUG3("P25RX: nid (b0 - b1)", nid[0U], nid[1U]); - uint8_t frame[P25_HDR_FRAME_LENGTH_BYTES + 1U]; - samplesToBits(m_hdrStartPtr, P25_HDR_FRAME_LENGTH_SYMBOLS, frame, 8U, m_centreVal, m_thresholdVal); + m_duid = nid[1U] & 0x0F; - frame[0U] = 0x01U; - serial.writeP25Hdr(frame, P25_HDR_FRAME_LENGTH_BYTES + 1U); + switch (m_duid) { + case P25_DUID_HDU: { + calculateLevels(m_hdrStartPtr, P25_HDR_FRAME_LENGTH_SYMBOLS); + + DEBUG4("P25RX: sync found in Hdr pos/centre/threshold", m_hdrSyncPtr, m_centreVal, m_thresholdVal); + + uint8_t frame[P25_HDR_FRAME_LENGTH_BYTES + 1U]; + samplesToBits(m_hdrStartPtr, P25_HDR_FRAME_LENGTH_SYMBOLS, frame, 8U, m_centreVal, m_thresholdVal); + + frame[0U] = 0x01U; + serial.writeP25Hdr(frame, P25_HDR_FRAME_LENGTH_BYTES + 1U); + } + break; + case P25_DUID_TSDU: { + calculateLevels(m_hdrStartPtr, P25_TSDU_FRAME_LENGTH_SYMBOLS); + + DEBUG4("P25RX: sync found in TSDU pos/centre/threshold", m_hdrSyncPtr, m_centreVal, m_thresholdVal); + + uint8_t frame[P25_TSDU_FRAME_LENGTH_BYTES + 1U]; + samplesToBits(m_hdrStartPtr, P25_TSDU_FRAME_LENGTH_SYMBOLS, frame, 8U, m_centreVal, m_thresholdVal); + + frame[0U] = 0x01U; + serial.writeP25Hdr(frame, P25_TSDU_FRAME_LENGTH_BYTES + 1U); + } + break; + case P25_DUID_TDU: { + calculateLevels(m_hdrStartPtr, P25_TERM_FRAME_LENGTH_SYMBOLS); + + DEBUG4("P25RX: sync found in TDU pos/centre/threshold", m_hdrSyncPtr, m_centreVal, m_thresholdVal); + + uint8_t frame[P25_TERM_FRAME_LENGTH_BYTES + 1U]; + samplesToBits(m_hdrStartPtr, P25_TERM_FRAME_LENGTH_SYMBOLS, frame, 8U, m_centreVal, m_thresholdVal); + + frame[0U] = 0x01U; + serial.writeP25Hdr(frame, P25_TERM_FRAME_LENGTH_BYTES + 1U); + } + break; + case P25_DUID_TDULC: { + calculateLevels(m_hdrStartPtr, P25_TERMLC_FRAME_LENGTH_SYMBOLS); + + DEBUG4("P25RX: sync found in TDULC pos/centre/threshold", m_hdrSyncPtr, m_centreVal, m_thresholdVal); + + uint8_t frame[P25_TERMLC_FRAME_LENGTH_BYTES + 1U]; + samplesToBits(m_hdrStartPtr, P25_TERMLC_FRAME_LENGTH_SYMBOLS, frame, 8U, m_centreVal, m_thresholdVal); + + frame[0U] = 0x01U; + serial.writeP25Hdr(frame, P25_TERMLC_FRAME_LENGTH_BYTES + 1U); + } + break; + default: + break; } m_minSyncPtr = m_lduSyncPtr + P25_LDU_FRAME_LENGTH_SAMPLES - 1U; @@ -238,6 +296,7 @@ void CP25RX::processLdu(q15_t sample) m_averagePtr = NOAVEPTR; m_countdown = 0U; m_maxCorr = 0; + m_duid = 0U; } else { frame[0U] = m_lostCount == (MAX_SYNC_FRAMES - 1U) ? 0x01U : 0x00U; writeRSSILdu(frame); diff --git a/P25RX.h b/P25RX.h index 0bdf3c5..7cab1dd 100644 --- a/P25RX.h +++ b/P25RX.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX + * Copyright (C) 2018 by Bryan Biedenkapp * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -59,6 +60,7 @@ private: uint8_t m_averagePtr; uint32_t m_rssiAccum; uint16_t m_rssiCount; + uint8_t m_duid; void processNone(q15_t sample); void processHdr(q15_t sample);