Clean up the DMR sync generation code.

This commit is contained in:
Jonathan Naylor 2016-09-06 08:06:19 +01:00
parent e16c27be61
commit 996db45b45
3 changed files with 39 additions and 111 deletions

View file

@ -168,10 +168,7 @@ void CDMRSlot::writeModem(unsigned char *data, unsigned int len)
slotType.getData(data + 2U); slotType.getData(data + 2U);
// Convert the Data Sync to be from the BS or MS as needed // Convert the Data Sync to be from the BS or MS as needed
if (m_duplex) CSync::addDMRDataSync(data + 2U, m_duplex);
CSync::addDMRBSDataSync(data + 2U);
else
CSync::addDMRMSDataSync(data + 2U);
data[0U] = TAG_DATA; data[0U] = TAG_DATA;
data[1U] = 0x00U; data[1U] = 0x00U;
@ -213,10 +210,7 @@ void CDMRSlot::writeModem(unsigned char *data, unsigned int len)
slotType.getData(data + 2U); slotType.getData(data + 2U);
// Convert the Data Sync to be from the BS or MS as needed // Convert the Data Sync to be from the BS or MS as needed
if (m_duplex) CSync::addDMRDataSync(data + 2U, m_duplex);
CSync::addDMRBSDataSync(data + 2U);
else
CSync::addDMRMSDataSync(data + 2U);
// Regenerate the payload // Regenerate the payload
CBPTC19696 bptc; CBPTC19696 bptc;
@ -243,10 +237,7 @@ void CDMRSlot::writeModem(unsigned char *data, unsigned int len)
slotType.getData(data + 2U); slotType.getData(data + 2U);
// Convert the Data Sync to be from the BS or MS as needed // Convert the Data Sync to be from the BS or MS as needed
if (m_duplex) CSync::addDMRDataSync(data + 2U, m_duplex);
CSync::addDMRBSDataSync(data + 2U);
else
CSync::addDMRMSDataSync(data + 2U);
data[0U] = TAG_EOT; data[0U] = TAG_EOT;
data[1U] = 0x00U; data[1U] = 0x00U;
@ -292,10 +283,7 @@ void CDMRSlot::writeModem(unsigned char *data, unsigned int len)
slotType.getData(data + 2U); slotType.getData(data + 2U);
// Convert the Data Sync to be from the BS or MS as needed // Convert the Data Sync to be from the BS or MS as needed
if (m_duplex) CSync::addDMRDataSync(data + 2U, m_duplex);
CSync::addDMRBSDataSync(data + 2U);
else
CSync::addDMRMSDataSync(data + 2U);
data[0U] = m_rfFrames == 0U ? TAG_EOT : TAG_DATA; data[0U] = m_rfFrames == 0U ? TAG_EOT : TAG_DATA;
data[1U] = 0x00U; data[1U] = 0x00U;
@ -342,10 +330,7 @@ void CDMRSlot::writeModem(unsigned char *data, unsigned int len)
slotType.getData(data + 2U); slotType.getData(data + 2U);
// Convert the Data Sync to be from the BS or MS as needed // Convert the Data Sync to be from the BS or MS as needed
if (m_duplex) CSync::addDMRDataSync(data + 2U, m_duplex);
CSync::addDMRBSDataSync(data + 2U);
else
CSync::addDMRMSDataSync(data + 2U);
m_rfSeqNo = 0U; m_rfSeqNo = 0U;
@ -403,10 +388,7 @@ void CDMRSlot::writeModem(unsigned char *data, unsigned int len)
slotType.getData(data + 2U); slotType.getData(data + 2U);
// Convert the Data Sync to be from the BS or MS as needed // Convert the Data Sync to be from the BS or MS as needed
if (m_duplex) CSync::addDMRDataSync(data + 2U, m_duplex);
CSync::addDMRBSDataSync(data + 2U);
else
CSync::addDMRMSDataSync(data + 2U);
m_rfFrames--; m_rfFrames--;
@ -424,10 +406,7 @@ void CDMRSlot::writeModem(unsigned char *data, unsigned int len)
} else if (audioSync) { } else if (audioSync) {
if (m_rfState == RS_RF_AUDIO) { if (m_rfState == RS_RF_AUDIO) {
// Convert the Audio Sync to be from the BS or MS as needed // Convert the Audio Sync to be from the BS or MS as needed
if (m_duplex) CSync::addDMRAudioSync(data + 2U, m_duplex);
CSync::addDMRBSAudioSync(data + 2U);
else
CSync::addDMRMSAudioSync(data + 2U);
unsigned int errors = 0U; unsigned int errors = 0U;
unsigned char fid = m_rfLC->getFID(); unsigned char fid = m_rfLC->getFID();
@ -511,10 +490,7 @@ void CDMRSlot::writeModem(unsigned char *data, unsigned int len)
// Create a dummy start frame to replace the received frame // Create a dummy start frame to replace the received frame
unsigned char start[DMR_FRAME_LENGTH_BYTES + 2U]; unsigned char start[DMR_FRAME_LENGTH_BYTES + 2U];
if (m_duplex) CSync::addDMRDataSync(start + 2U, m_duplex);
CSync::addDMRBSDataSync(start + 2U);
else
CSync::addDMRMSDataSync(start + 2U);
CDMRFullLC fullLC; CDMRFullLC fullLC;
fullLC.encode(*m_rfLC, start + 2U, DT_VOICE_LC_HEADER); fullLC.encode(*m_rfLC, start + 2U, DT_VOICE_LC_HEADER);
@ -613,10 +589,7 @@ void CDMRSlot::endOfRFData()
if (m_duplex) { if (m_duplex) {
unsigned char bytes[DMR_FRAME_LENGTH_BYTES + 2U]; unsigned char bytes[DMR_FRAME_LENGTH_BYTES + 2U];
if (m_duplex) CSync::addDMRDataSync(bytes + 2U, m_duplex);
CSync::addDMRBSDataSync(bytes + 2U);
else
CSync::addDMRMSDataSync(bytes + 2U);
CDMRSlotType slotType; CDMRSlotType slotType;
slotType.setDataType(DT_TERMINATOR_WITH_LC); slotType.setDataType(DT_TERMINATOR_WITH_LC);
@ -656,10 +629,7 @@ void CDMRSlot::writeEndRF(bool writeEnd)
// Create a dummy start end frame // Create a dummy start end frame
unsigned char data[DMR_FRAME_LENGTH_BYTES + 2U]; unsigned char data[DMR_FRAME_LENGTH_BYTES + 2U];
if (m_duplex) CSync::addDMRDataSync(data + 2U, m_duplex);
CSync::addDMRBSDataSync(data + 2U);
else
CSync::addDMRMSDataSync(data + 2U);
CDMRFullLC fullLC; CDMRFullLC fullLC;
fullLC.encode(*m_rfLC, data + 2U, DT_TERMINATOR_WITH_LC); fullLC.encode(*m_rfLC, data + 2U, DT_TERMINATOR_WITH_LC);
@ -688,10 +658,7 @@ void CDMRSlot::endOfNetData()
if (m_duplex) { if (m_duplex) {
unsigned char bytes[DMR_FRAME_LENGTH_BYTES + 2U]; unsigned char bytes[DMR_FRAME_LENGTH_BYTES + 2U];
if (m_duplex) CSync::addDMRDataSync(bytes + 2U, m_duplex);
CSync::addDMRBSDataSync(bytes + 2U);
else
CSync::addDMRMSDataSync(bytes + 2U);
CDMRSlotType slotType; CDMRSlotType slotType;
slotType.setDataType(DT_TERMINATOR_WITH_LC); slotType.setDataType(DT_TERMINATOR_WITH_LC);
@ -735,10 +702,7 @@ void CDMRSlot::writeEndNet(bool writeEnd)
// Create a dummy start end frame // Create a dummy start end frame
unsigned char data[DMR_FRAME_LENGTH_BYTES + 2U]; unsigned char data[DMR_FRAME_LENGTH_BYTES + 2U];
if (m_duplex) CSync::addDMRDataSync(data + 2U, m_duplex);
CSync::addDMRBSDataSync(data + 2U);
else
CSync::addDMRMSDataSync(data + 2U);
CDMRFullLC fullLC; CDMRFullLC fullLC;
fullLC.encode(*m_netLC, data + 2U, DT_TERMINATOR_WITH_LC); fullLC.encode(*m_netLC, data + 2U, DT_TERMINATOR_WITH_LC);
@ -809,10 +773,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
slotType.getData(data + 2U); slotType.getData(data + 2U);
// Convert the Data Sync to be from the BS or MS as needed // Convert the Data Sync to be from the BS or MS as needed
if (m_duplex) CSync::addDMRDataSync(data + 2U, m_duplex);
CSync::addDMRBSDataSync(data + 2U);
else
CSync::addDMRMSDataSync(data + 2U);
data[0U] = TAG_DATA; data[0U] = TAG_DATA;
data[1U] = 0x00U; data[1U] = 0x00U;
@ -871,10 +832,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
slotType.getData(data + 2U); slotType.getData(data + 2U);
// Convert the Data Sync to be from the BS or MS as needed // Convert the Data Sync to be from the BS or MS as needed
if (m_duplex) CSync::addDMRDataSync(data + 2U, m_duplex);
CSync::addDMRBSDataSync(data + 2U);
else
CSync::addDMRMSDataSync(data + 2U);
// Regenerate the payload // Regenerate the payload
CBPTC19696 bptc; CBPTC19696 bptc;
@ -910,10 +868,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
slotType.getData(data + 2U); slotType.getData(data + 2U);
// Convert the Data Sync to be from the BS or MS as needed // Convert the Data Sync to be from the BS or MS as needed
if (m_duplex) CSync::addDMRDataSync(data + 2U, m_duplex);
CSync::addDMRBSDataSync(data + 2U);
else
CSync::addDMRMSDataSync(data + 2U);
data[0U] = TAG_EOT; data[0U] = TAG_EOT;
data[1U] = 0x00U; data[1U] = 0x00U;
@ -966,10 +921,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
slotType.getData(data + 2U); slotType.getData(data + 2U);
// Convert the Data Sync to be from the BS or MS as needed // Convert the Data Sync to be from the BS or MS as needed
if (m_duplex) CSync::addDMRDataSync(data + 2U, m_duplex);
CSync::addDMRBSDataSync(data + 2U);
else
CSync::addDMRMSDataSync(data + 2U);
data[0U] = m_netFrames == 0U ? TAG_EOT : TAG_DATA; data[0U] = m_netFrames == 0U ? TAG_EOT : TAG_DATA;
data[1U] = 0x00U; data[1U] = 0x00U;
@ -1019,10 +971,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
// Create a dummy start frame // Create a dummy start frame
unsigned char start[DMR_FRAME_LENGTH_BYTES + 2U]; unsigned char start[DMR_FRAME_LENGTH_BYTES + 2U];
if (m_duplex) CSync::addDMRDataSync(start + 2U, m_duplex);
CSync::addDMRBSDataSync(start + 2U);
else
CSync::addDMRMSDataSync(start + 2U);
CDMRFullLC fullLC; CDMRFullLC fullLC;
fullLC.encode(*m_netLC, start + 2U, DT_VOICE_LC_HEADER); fullLC.encode(*m_netLC, start + 2U, DT_VOICE_LC_HEADER);
@ -1069,10 +1018,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
data[1U] = 0x00U; data[1U] = 0x00U;
// Convert the Audio Sync to be from the BS or MS as needed // Convert the Audio Sync to be from the BS or MS as needed
if (m_duplex) CSync::addDMRAudioSync(data + 2U, m_duplex);
CSync::addDMRBSAudioSync(data + 2U);
else
CSync::addDMRMSAudioSync(data + 2U);
// Initialise the lost packet data // Initialise the lost packet data
if (m_netFrames == 0U) { if (m_netFrames == 0U) {
@ -1179,10 +1125,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
slotType.getData(data + 2U); slotType.getData(data + 2U);
// Convert the Data Sync to be from the BS or MS as needed // Convert the Data Sync to be from the BS or MS as needed
if (m_duplex) CSync::addDMRDataSync(data + 2U, m_duplex);
CSync::addDMRBSDataSync(data + 2U);
else
CSync::addDMRMSDataSync(data + 2U);
data[0U] = TAG_DATA; data[0U] = TAG_DATA;
data[1U] = 0x00U; data[1U] = 0x00U;
@ -1240,10 +1183,7 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
slotType.getData(data + 2U); slotType.getData(data + 2U);
// Convert the Data Sync to be from the BS or MS as needed // Convert the Data Sync to be from the BS or MS as needed
if (m_duplex) CSync::addDMRDataSync(data + 2U, m_duplex);
CSync::addDMRBSDataSync(data + 2U);
else
CSync::addDMRMSDataSync(data + 2U);
m_netFrames--; m_netFrames--;
@ -1622,10 +1562,7 @@ void CDMRSlot::insertSilence(unsigned int count)
} }
if (n == 0U) { if (n == 0U) {
if (m_duplex) CSync::addDMRAudioSync(data + 2U, m_duplex);
CSync::addDMRBSAudioSync(data + 2U);
else
CSync::addDMRMSAudioSync(data + 2U);
} else { } else {
unsigned char lcss = m_netEmbeddedLC.getData(data + 2U, n); unsigned char lcss = m_netEmbeddedLC.getData(data + 2U, n);

View file

@ -34,36 +34,30 @@ void CSync::addDStarSync(unsigned char* data)
::memcpy(data + DSTAR_VOICE_FRAME_LENGTH_BYTES, DSTAR_SYNC_BYTES, DSTAR_DATA_FRAME_LENGTH_BYTES); ::memcpy(data + DSTAR_VOICE_FRAME_LENGTH_BYTES, DSTAR_SYNC_BYTES, DSTAR_DATA_FRAME_LENGTH_BYTES);
} }
void CSync::addDMRBSDataSync(unsigned char* data) void CSync::addDMRDataSync(unsigned char* data, bool duplex)
{ {
assert(data != NULL); assert(data != NULL);
if (duplex) {
for (unsigned int i = 0U; i < 7U; i++) for (unsigned int i = 0U; i < 7U; i++)
data[i + 13U] = (data[i + 13U] & ~SYNC_MASK[i]) | BS_SOURCED_DATA_SYNC[i]; data[i + 13U] = (data[i + 13U] & ~SYNC_MASK[i]) | BS_SOURCED_DATA_SYNC[i];
} } else {
void CSync::addDMRBSAudioSync(unsigned char* data)
{
assert(data != NULL);
for (unsigned int i = 0U; i < 7U; i++)
data[i + 13U] = (data[i + 13U] & ~SYNC_MASK[i]) | BS_SOURCED_AUDIO_SYNC[i];
}
void CSync::addDMRMSDataSync(unsigned char* data)
{
assert(data != NULL);
for (unsigned int i = 0U; i < 7U; i++) for (unsigned int i = 0U; i < 7U; i++)
data[i + 13U] = (data[i + 13U] & ~SYNC_MASK[i]) | MS_SOURCED_DATA_SYNC[i]; data[i + 13U] = (data[i + 13U] & ~SYNC_MASK[i]) | MS_SOURCED_DATA_SYNC[i];
}
} }
void CSync::addDMRMSAudioSync(unsigned char* data) void CSync::addDMRAudioSync(unsigned char* data, bool duplex)
{ {
assert(data != NULL); assert(data != NULL);
if (duplex) {
for (unsigned int i = 0U; i < 7U; i++)
data[i + 13U] = (data[i + 13U] & ~SYNC_MASK[i]) | BS_SOURCED_AUDIO_SYNC[i];
} else {
for (unsigned int i = 0U; i < 7U; i++) for (unsigned int i = 0U; i < 7U; i++)
data[i + 13U] = (data[i + 13U] & ~SYNC_MASK[i]) | MS_SOURCED_AUDIO_SYNC[i]; data[i + 13U] = (data[i + 13U] & ~SYNC_MASK[i]) | MS_SOURCED_AUDIO_SYNC[i];
}
} }
void CSync::addYSFSync(unsigned char* data) void CSync::addYSFSync(unsigned char* data)

7
Sync.h
View file

@ -24,11 +24,8 @@ class CSync
public: public:
static void addDStarSync(unsigned char* data); static void addDStarSync(unsigned char* data);
static void addDMRBSDataSync(unsigned char* data); static void addDMRDataSync(unsigned char* data, bool duplex);
static void addDMRBSAudioSync(unsigned char* data); static void addDMRAudioSync(unsigned char* data, bool duplex);
static void addDMRMSDataSync(unsigned char* data);
static void addDMRMSAudioSync(unsigned char* data);
static void addYSFSync(unsigned char* data); static void addYSFSync(unsigned char* data);