Skip to content

Commit

Permalink
Fix DPlus frame sequencing and some code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
nostar committed Aug 1, 2022
1 parent 371dd20 commit a24658b
Show file tree
Hide file tree
Showing 36 changed files with 626 additions and 609 deletions.
45 changes: 20 additions & 25 deletions CRCenc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
*/

#include "CRCenc.h"

//#include "Utils.h"
//#include "Log.h"

#include <cstdint>
#include <cstdio>
#include <cassert>
#include <cmath>
Expand Down Expand Up @@ -120,18 +115,18 @@ const uint16_t CCITT16_TABLE2[] = {
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 };

/*
bool CCRC::checkFiveBit(bool* in, unsigned int tcrc)
bool CCRC::checkFiveBit(bool* in, uint32_t tcrc)
{
assert(in != NULL);
unsigned int crc;
uint32_t crc;
//encodeFiveBit(in, crc);
return crc == tcrc;
}
*/

void CCRC::bitsToByteBE(const bool* bits, unsigned char& byte)
void CCRC::bitsToByteBE(const bool* bits, uint8_t& byte)
{
assert(bits != NULL);

Expand All @@ -145,13 +140,13 @@ void CCRC::bitsToByteBE(const bool* bits, unsigned char& byte)
byte |= bits[7U] ? 0x01U : 0x00U;
}

void CCRC::encodeFiveBit(const bool* in, unsigned int& tcrc)
void CCRC::encodeFiveBit(const bool* in, uint32_t& tcrc)
{
assert(in != NULL);

unsigned short total = 0U;
for (unsigned int i = 0U; i < 72U; i += 8U) {
unsigned char c;
uint16_t total = 0U;
for (uint32_t i = 0U; i < 72U; i += 8U) {
uint8_t c;
bitsToByteBE(in + i, c);
total += c;
}
Expand All @@ -161,7 +156,7 @@ void CCRC::encodeFiveBit(const bool* in, unsigned int& tcrc)
tcrc = total;
}

void CCRC::addCCITT162(unsigned char *in, unsigned int length)
void CCRC::addCCITT162(uint8_t *in, uint32_t length)
{
assert(in != NULL);
assert(length > 2U);
Expand All @@ -173,7 +168,7 @@ void CCRC::addCCITT162(unsigned char *in, unsigned int length)

crc16 = 0U;

for (unsigned i = 0U; i < (length - 2U); i++)
for (uint32_t i = 0U; i < (length - 2U); i++)
crc16 = (uint16_t(crc8[0U]) << 8) ^ CCITT16_TABLE2[crc8[1U] ^ in[i]];

crc16 = ~crc16;
Expand All @@ -182,7 +177,7 @@ void CCRC::addCCITT162(unsigned char *in, unsigned int length)
in[length - 2U] = crc8[1U];
}

bool CCRC::checkCCITT162(const unsigned char *in, unsigned int length)
bool CCRC::checkCCITT162(const uint8_t *in, uint32_t length)
{
assert(in != NULL);
assert(length > 2U);
Expand All @@ -194,15 +189,15 @@ bool CCRC::checkCCITT162(const unsigned char *in, unsigned int length)

crc16 = 0U;

for (unsigned i = 0U; i < (length - 2U); i++)
for (uint32_t i = 0U; i < (length - 2U); i++)
crc16 = (uint16_t(crc8[0U]) << 8) ^ CCITT16_TABLE2[crc8[1U] ^ in[i]];

crc16 = ~crc16;

return crc8[0U] == in[length - 1U] && crc8[1U] == in[length - 2U];
}

void CCRC::addCCITT161(unsigned char *in, unsigned int length)
void CCRC::addCCITT161(uint8_t *in, uint32_t length)
{
assert(in != NULL);
assert(length > 2U);
Expand All @@ -214,7 +209,7 @@ void CCRC::addCCITT161(unsigned char *in, unsigned int length)

crc16 = 0xFFFFU;

for (unsigned int i = 0U; i < (length - 2U); i++)
for (uint32_t i = 0U; i < (length - 2U); i++)
crc16 = uint16_t(crc8[1U]) ^ CCITT16_TABLE1[crc8[0U] ^ in[i]];

crc16 = ~crc16;
Expand All @@ -223,7 +218,7 @@ void CCRC::addCCITT161(unsigned char *in, unsigned int length)
in[length - 1U] = crc8[1U];
}

bool CCRC::checkCCITT161(const unsigned char *in, unsigned int length)
bool CCRC::checkCCITT161(const uint8_t *in, uint32_t length)
{
assert(in != NULL);
assert(length > 2U);
Expand All @@ -235,33 +230,33 @@ bool CCRC::checkCCITT161(const unsigned char *in, unsigned int length)

crc16 = 0xFFFFU;

for (unsigned int i = 0U; i < (length - 2U); i++)
for (uint32_t i = 0U; i < (length - 2U); i++)
crc16 = uint16_t(crc8[1U]) ^ CCITT16_TABLE1[crc8[0U] ^ in[i]];

crc16 = ~crc16;

return crc8[0U] == in[length - 2U] && crc8[1U] == in[length - 1U];
}

unsigned char CCRC::crc8(const unsigned char *in, unsigned int length)
uint8_t CCRC::crc8(const uint8_t *in, uint32_t length)
{
assert(in != NULL);

uint8_t crc = 0U;

for (unsigned int i = 0U; i < length; i++)
for (uint32_t i = 0U; i < length; i++)
crc = CRC8_TABLE[crc ^ in[i]];

return crc;
}

unsigned char CCRC::addCRC(const unsigned char* in, unsigned int length)
uint8_t CCRC::addCRC(const uint8_t* in, uint32_t length)
{
assert(in != NULL);

unsigned char crc = 0U;
uint8_t crc = 0U;

for (unsigned int i = 0U; i < length; i++)
for (uint32_t i = 0U; i < length; i++)
crc += in[i];

return crc;
Expand Down
19 changes: 10 additions & 9 deletions CRCenc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,24 @@

#if !defined(CRC_H)
#define CRC_H
#include <cstdint>

class CCRC
{
public:
//static bool checkFiveBit(bool* in, unsigned int tcrc);
static void bitsToByteBE(const bool* bits, unsigned char& byte);
static void encodeFiveBit(const bool* in, unsigned int& tcrc);
//static bool checkFiveBit(bool* in, uint32_t tcrc);
static void bitsToByteBE(const bool* bits, uint8_t& byte);
static void encodeFiveBit(const bool* in, uint32_t& tcrc);

static void addCCITT161(unsigned char* in, unsigned int length);
static void addCCITT162(unsigned char* in, unsigned int length);
static void addCCITT161(uint8_t* in, uint32_t length);
static void addCCITT162(uint8_t* in, uint32_t length);

static bool checkCCITT161(const unsigned char* in, unsigned int length);
static bool checkCCITT162(const unsigned char* in, unsigned int length);
static bool checkCCITT161(const uint8_t* in, uint32_t length);
static bool checkCCITT162(const uint8_t* in, uint32_t length);

static unsigned char crc8(const unsigned char* in, unsigned int length);
static unsigned char crc8(const uint8_t* in, uint32_t length);

static unsigned char addCRC(const unsigned char* in, unsigned int length);
static unsigned char addCRC(const uint8_t* in, uint32_t length);
};

#endif
141 changes: 71 additions & 70 deletions DMRDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,100 +18,101 @@

#if !defined(DMRDefines_H)
#define DMRDefines_H
#include <cstdint>

const unsigned char TAG_HEADER = 0x00U;
const unsigned char TAG_DATA = 0x01U;
const unsigned char TAG_LOST = 0x02U;
const unsigned char TAG_EOT = 0x03U;
const unsigned char TAG_NODATA = 0x04U;
const uint8_t TAG_HEADER = 0x00U;
const uint8_t TAG_DATA = 0x01U;
const uint8_t TAG_LOST = 0x02U;
const uint8_t TAG_EOT = 0x03U;
const uint8_t TAG_NODATA = 0x04U;

const unsigned int DMR_FRAME_LENGTH_BITS = 264U;
const unsigned int DMR_FRAME_LENGTH_BYTES = 33U;
const uint32_t DMR_FRAME_LENGTH_BITS = 264U;
const uint32_t DMR_FRAME_LENGTH_BYTES = 33U;

const unsigned int DMR_SYNC_LENGTH_BITS = 48U;
const unsigned int DMR_SYNC_LENGTH_BYTES = 6U;
const uint32_t DMR_SYNC_LENGTH_BITS = 48U;
const uint32_t DMR_SYNC_LENGTH_BYTES = 6U;

const unsigned int DMR_EMB_LENGTH_BITS = 8U;
const unsigned int DMR_EMB_LENGTH_BYTES = 1U;
const uint32_t DMR_EMB_LENGTH_BITS = 8U;
const uint32_t DMR_EMB_LENGTH_BYTES = 1U;

const unsigned int DMR_SLOT_TYPE_LENGTH_BITS = 8U;
const unsigned int DMR_SLOT_TYPE_LENGTH_BYTES = 1U;
const uint32_t DMR_SLOT_TYPE_LENGTH_BITS = 8U;
const uint32_t DMR_SLOT_TYPE_LENGTH_BYTES = 1U;

const unsigned int DMR_EMBEDDED_SIGNALLING_LENGTH_BITS = 32U;
const unsigned int DMR_EMBEDDED_SIGNALLING_LENGTH_BYTES = 4U;
const uint32_t DMR_EMBEDDED_SIGNALLING_LENGTH_BITS = 32U;
const uint32_t DMR_EMBEDDED_SIGNALLING_LENGTH_BYTES = 4U;

const unsigned int DMR_AMBE_LENGTH_BITS = 108U * 2U;
const unsigned int DMR_AMBE_LENGTH_BYTES = 27U;
const uint32_t DMR_AMBE_LENGTH_BITS = 108U * 2U;
const uint32_t DMR_AMBE_LENGTH_BYTES = 27U;

const unsigned char BS_SOURCED_AUDIO_SYNC[] = {0x07U, 0x55U, 0xFDU, 0x7DU, 0xF7U, 0x5FU, 0x70U};
const unsigned char BS_SOURCED_DATA_SYNC[] = {0x0DU, 0xFFU, 0x57U, 0xD7U, 0x5DU, 0xF5U, 0xD0U};
const uint8_t BS_SOURCED_AUDIO_SYNC[] = {0x07U, 0x55U, 0xFDU, 0x7DU, 0xF7U, 0x5FU, 0x70U};
const uint8_t BS_SOURCED_DATA_SYNC[] = {0x0DU, 0xFFU, 0x57U, 0xD7U, 0x5DU, 0xF5U, 0xD0U};

const unsigned char MS_SOURCED_AUDIO_SYNC[] = {0x07U, 0xF7U, 0xD5U, 0xDDU, 0x57U, 0xDFU, 0xD0U};
const unsigned char MS_SOURCED_DATA_SYNC[] = {0x0DU, 0x5DU, 0x7FU, 0x77U, 0xFDU, 0x75U, 0x70U};
const uint8_t MS_SOURCED_AUDIO_SYNC[] = {0x07U, 0xF7U, 0xD5U, 0xDDU, 0x57U, 0xDFU, 0xD0U};
const uint8_t MS_SOURCED_DATA_SYNC[] = {0x0DU, 0x5DU, 0x7FU, 0x77U, 0xFDU, 0x75U, 0x70U};

const unsigned char DIRECT_SLOT1_AUDIO_SYNC[] = {0x05U, 0xD5U, 0x77U, 0xF7U, 0x75U, 0x7FU, 0xF0U};
const unsigned char DIRECT_SLOT1_DATA_SYNC[] = {0x0FU, 0x7FU, 0xDDU, 0x5DU, 0xDFU, 0xD5U, 0x50U};
const uint8_t DIRECT_SLOT1_AUDIO_SYNC[] = {0x05U, 0xD5U, 0x77U, 0xF7U, 0x75U, 0x7FU, 0xF0U};
const uint8_t DIRECT_SLOT1_DATA_SYNC[] = {0x0FU, 0x7FU, 0xDDU, 0x5DU, 0xDFU, 0xD5U, 0x50U};

const unsigned char DIRECT_SLOT2_AUDIO_SYNC[] = {0x07U, 0xDFU, 0xFDU, 0x5FU, 0x55U, 0xD5U, 0xF0U};
const unsigned char DIRECT_SLOT2_DATA_SYNC[] = {0x0DU, 0x75U, 0x57U, 0xF5U, 0xFFU, 0x7FU, 0x50U};
const uint8_t DIRECT_SLOT2_AUDIO_SYNC[] = {0x07U, 0xDFU, 0xFDU, 0x5FU, 0x55U, 0xD5U, 0xF0U};
const uint8_t DIRECT_SLOT2_DATA_SYNC[] = {0x0DU, 0x75U, 0x57U, 0xF5U, 0xFFU, 0x7FU, 0x50U};

const unsigned char SYNC_MASK[] = {0x0FU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xF0U};
const uint8_t SYNC_MASK[] = {0x0FU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xF0U};

// The PR FILL and Data Sync pattern.
const unsigned char DMR_IDLE_DATA[] = {TAG_DATA, 0x00U,
const uint8_t DMR_IDLE_DATA[] = {TAG_DATA, 0x00U,
0x53U, 0xC2U, 0x5EU, 0xABU, 0xA8U, 0x67U, 0x1DU, 0xC7U, 0x38U, 0x3BU, 0xD9U,
0x36U, 0x00U, 0x0DU, 0xFFU, 0x57U, 0xD7U, 0x5DU, 0xF5U, 0xD0U, 0x03U, 0xF6U,
0xE4U, 0x65U, 0x17U, 0x1BU, 0x48U, 0xCAU, 0x6DU, 0x4FU, 0xC6U, 0x10U, 0xB4U};

// A silence frame only
const unsigned char DMR_SILENCE_DATA[] = {0xB9U, 0xE8U, 0x81U, 0x52U, 0x61U, 0x73U, 0x00U, 0x2AU, 0x6BU, 0xB9U, 0xE8U,
const uint8_t DMR_SILENCE_DATA[] = {0xB9U, 0xE8U, 0x81U, 0x52U, 0x61U, 0x73U, 0x00U, 0x2AU, 0x6BU, 0xB9U, 0xE8U,
0x81U, 0x52U, 0x60U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x01U, 0x73U, 0x00U,
0x2AU, 0x6BU, 0xB9U, 0xE8U, 0x81U, 0x52U, 0x61U, 0x73U, 0x00U, 0x2AU, 0x6BU};

const unsigned char PAYLOAD_LEFT_MASK[] = {0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xF0U};
const unsigned char PAYLOAD_RIGHT_MASK[] = {0x0FU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU};

const unsigned char VOICE_LC_HEADER_CRC_MASK[] = {0x96U, 0x96U, 0x96U};
const unsigned char TERMINATOR_WITH_LC_CRC_MASK[] = {0x99U, 0x99U, 0x99U};
const unsigned char PI_HEADER_CRC_MASK[] = {0x69U, 0x69U};
const unsigned char DATA_HEADER_CRC_MASK[] = {0xCCU, 0xCCU};
const unsigned char CSBK_CRC_MASK[] = {0xA5U, 0xA5U};

const unsigned int DMR_SLOT_TIME = 60U;
const unsigned int AMBE_PER_SLOT = 3U;

const unsigned char DT_MASK = 0x0FU;
const unsigned char DT_VOICE_PI_HEADER = 0x00U;
const unsigned char DT_VOICE_LC_HEADER = 0x01U;
const unsigned char DT_TERMINATOR_WITH_LC = 0x02U;
const unsigned char DT_CSBK = 0x03U;
const unsigned char DT_DATA_HEADER = 0x06U;
const unsigned char DT_RATE_12_DATA = 0x07U;
const unsigned char DT_RATE_34_DATA = 0x08U;
const unsigned char DT_IDLE = 0x09U;
const unsigned char DT_RATE_1_DATA = 0x0AU;
const uint8_t PAYLOAD_LEFT_MASK[] = {0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xF0U};
const uint8_t PAYLOAD_RIGHT_MASK[] = {0x0FU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU};

const uint8_t VOICE_LC_HEADER_CRC_MASK[] = {0x96U, 0x96U, 0x96U};
const uint8_t TERMINATOR_WITH_LC_CRC_MASK[] = {0x99U, 0x99U, 0x99U};
const uint8_t PI_HEADER_CRC_MASK[] = {0x69U, 0x69U};
const uint8_t DATA_HEADER_CRC_MASK[] = {0xCCU, 0xCCU};
const uint8_t CSBK_CRC_MASK[] = {0xA5U, 0xA5U};

const uint32_t DMR_SLOT_TIME = 60U;
const uint32_t AMBE_PER_SLOT = 3U;

const uint8_t DT_MASK = 0x0FU;
const uint8_t DT_VOICE_PI_HEADER = 0x00U;
const uint8_t DT_VOICE_LC_HEADER = 0x01U;
const uint8_t DT_TERMINATOR_WITH_LC = 0x02U;
const uint8_t DT_CSBK = 0x03U;
const uint8_t DT_DATA_HEADER = 0x06U;
const uint8_t DT_RATE_12_DATA = 0x07U;
const uint8_t DT_RATE_34_DATA = 0x08U;
const uint8_t DT_IDLE = 0x09U;
const uint8_t DT_RATE_1_DATA = 0x0AU;

// Dummy values
const unsigned char DT_VOICE_SYNC = 0xF0U;
const unsigned char DT_VOICE = 0xF1U;

const unsigned char DMR_IDLE_RX = 0x80U;
const unsigned char DMR_SYNC_DATA = 0x40U;
const unsigned char DMR_SYNC_AUDIO = 0x20U;

const unsigned char DMR_SLOT1 = 0x00U;
const unsigned char DMR_SLOT2 = 0x80U;

const unsigned char DPF_UDT = 0x00U;
const unsigned char DPF_RESPONSE = 0x01U;
const unsigned char DPF_UNCONFIRMED_DATA = 0x02U;
const unsigned char DPF_CONFIRMED_DATA = 0x03U;
const unsigned char DPF_DEFINED_SHORT = 0x0DU;
const unsigned char DPF_DEFINED_RAW = 0x0EU;
const unsigned char DPF_PROPRIETARY = 0x0FU;

const unsigned char FID_ETSI = 0U;
const unsigned char FID_DMRA = 16U;
const uint8_t DT_VOICE_SYNC = 0xF0U;
const uint8_t DT_VOICE = 0xF1U;

const uint8_t DMR_IDLE_RX = 0x80U;
const uint8_t DMR_SYNC_DATA = 0x40U;
const uint8_t DMR_SYNC_AUDIO = 0x20U;

const uint8_t DMR_SLOT1 = 0x00U;
const uint8_t DMR_SLOT2 = 0x80U;

const uint8_t DPF_UDT = 0x00U;
const uint8_t DPF_RESPONSE = 0x01U;
const uint8_t DPF_UNCONFIRMED_DATA = 0x02U;
const uint8_t DPF_CONFIRMED_DATA = 0x03U;
const uint8_t DPF_DEFINED_SHORT = 0x0DU;
const uint8_t DPF_DEFINED_RAW = 0x0EU;
const uint8_t DPF_PROPRIETARY = 0x0FU;

const uint8_t FID_ETSI = 0U;
const uint8_t FID_DMRA = 16U;

enum FLCO {
FLCO_GROUP = 0,
Expand Down
2 changes: 1 addition & 1 deletion DroidStar.pro
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ DEFINES += VERSION_NUMBER=\"\\\"$${VERSION_BUILD}\\\"\"
DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
DEFINES += VOCODER_PLUGIN
DEFINES += USE_FLITE
#DEFINES += USE_FLITE
#DEFINES += USE_EXTERNAL_CODEC2

HEADERS += \
Expand Down
Loading

0 comments on commit a24658b

Please sign in to comment.