Fix DPlus frame sequencing and some code cleanups

pull/4/head
Doug McLain 2 years ago
parent 371dd2025b
commit a24658ba30

@ -18,11 +18,6 @@
*/ */
#include "CRCenc.h" #include "CRCenc.h"
//#include "Utils.h"
//#include "Log.h"
#include <cstdint>
#include <cstdio> #include <cstdio>
#include <cassert> #include <cassert>
#include <cmath> #include <cmath>
@ -120,18 +115,18 @@ const uint16_t CCITT16_TABLE2[] = {
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 }; 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); assert(in != NULL);
unsigned int crc; uint32_t crc;
//encodeFiveBit(in, crc); //encodeFiveBit(in, crc);
return crc == tcrc; return crc == tcrc;
} }
*/ */
void CCRC::bitsToByteBE(const bool* bits, unsigned char& byte) void CCRC::bitsToByteBE(const bool* bits, uint8_t& byte)
{ {
assert(bits != NULL); assert(bits != NULL);
@ -145,13 +140,13 @@ void CCRC::bitsToByteBE(const bool* bits, unsigned char& byte)
byte |= bits[7U] ? 0x01U : 0x00U; 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); assert(in != NULL);
unsigned short total = 0U; uint16_t total = 0U;
for (unsigned int i = 0U; i < 72U; i += 8U) { for (uint32_t i = 0U; i < 72U; i += 8U) {
unsigned char c; uint8_t c;
bitsToByteBE(in + i, c); bitsToByteBE(in + i, c);
total += c; total += c;
} }
@ -161,7 +156,7 @@ void CCRC::encodeFiveBit(const bool* in, unsigned int& tcrc)
tcrc = total; tcrc = total;
} }
void CCRC::addCCITT162(unsigned char *in, unsigned int length) void CCRC::addCCITT162(uint8_t *in, uint32_t length)
{ {
assert(in != NULL); assert(in != NULL);
assert(length > 2U); assert(length > 2U);
@ -173,7 +168,7 @@ void CCRC::addCCITT162(unsigned char *in, unsigned int length)
crc16 = 0U; 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 = (uint16_t(crc8[0U]) << 8) ^ CCITT16_TABLE2[crc8[1U] ^ in[i]];
crc16 = ~crc16; crc16 = ~crc16;
@ -182,7 +177,7 @@ void CCRC::addCCITT162(unsigned char *in, unsigned int length)
in[length - 2U] = crc8[1U]; 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(in != NULL);
assert(length > 2U); assert(length > 2U);
@ -194,7 +189,7 @@ bool CCRC::checkCCITT162(const unsigned char *in, unsigned int length)
crc16 = 0U; 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 = (uint16_t(crc8[0U]) << 8) ^ CCITT16_TABLE2[crc8[1U] ^ in[i]];
crc16 = ~crc16; crc16 = ~crc16;
@ -202,7 +197,7 @@ bool CCRC::checkCCITT162(const unsigned char *in, unsigned int length)
return crc8[0U] == in[length - 1U] && crc8[1U] == in[length - 2U]; 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(in != NULL);
assert(length > 2U); assert(length > 2U);
@ -214,7 +209,7 @@ void CCRC::addCCITT161(unsigned char *in, unsigned int length)
crc16 = 0xFFFFU; 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 = uint16_t(crc8[1U]) ^ CCITT16_TABLE1[crc8[0U] ^ in[i]];
crc16 = ~crc16; crc16 = ~crc16;
@ -223,7 +218,7 @@ void CCRC::addCCITT161(unsigned char *in, unsigned int length)
in[length - 1U] = crc8[1U]; 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(in != NULL);
assert(length > 2U); assert(length > 2U);
@ -235,7 +230,7 @@ bool CCRC::checkCCITT161(const unsigned char *in, unsigned int length)
crc16 = 0xFFFFU; 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 = uint16_t(crc8[1U]) ^ CCITT16_TABLE1[crc8[0U] ^ in[i]];
crc16 = ~crc16; crc16 = ~crc16;
@ -243,25 +238,25 @@ bool CCRC::checkCCITT161(const unsigned char *in, unsigned int length)
return crc8[0U] == in[length - 2U] && crc8[1U] == in[length - 1U]; 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); assert(in != NULL);
uint8_t crc = 0U; 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]]; crc = CRC8_TABLE[crc ^ in[i]];
return crc; 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); 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]; crc += in[i];
return crc; return crc;

@ -19,23 +19,24 @@
#if !defined(CRC_H) #if !defined(CRC_H)
#define CRC_H #define CRC_H
#include <cstdint>
class CCRC class CCRC
{ {
public: public:
//static bool checkFiveBit(bool* in, unsigned int tcrc); //static bool checkFiveBit(bool* in, uint32_t tcrc);
static void bitsToByteBE(const bool* bits, unsigned char& byte); static void bitsToByteBE(const bool* bits, uint8_t& byte);
static void encodeFiveBit(const bool* in, unsigned int& tcrc); static void encodeFiveBit(const bool* in, uint32_t& tcrc);
static void addCCITT161(unsigned char* in, unsigned int length); static void addCCITT161(uint8_t* in, uint32_t length);
static void addCCITT162(unsigned char* in, unsigned int length); static void addCCITT162(uint8_t* in, uint32_t length);
static bool checkCCITT161(const unsigned char* in, unsigned int length); static bool checkCCITT161(const uint8_t* in, uint32_t length);
static bool checkCCITT162(const unsigned char* in, unsigned int 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 #endif

@ -18,100 +18,101 @@
#if !defined(DMRDefines_H) #if !defined(DMRDefines_H)
#define DMRDefines_H #define DMRDefines_H
#include <cstdint>
const unsigned char TAG_HEADER = 0x00U; const uint8_t TAG_HEADER = 0x00U;
const unsigned char TAG_DATA = 0x01U; const uint8_t TAG_DATA = 0x01U;
const unsigned char TAG_LOST = 0x02U; const uint8_t TAG_LOST = 0x02U;
const unsigned char TAG_EOT = 0x03U; const uint8_t TAG_EOT = 0x03U;
const unsigned char TAG_NODATA = 0x04U; const uint8_t TAG_NODATA = 0x04U;
const unsigned int DMR_FRAME_LENGTH_BITS = 264U; const uint32_t DMR_FRAME_LENGTH_BITS = 264U;
const unsigned int DMR_FRAME_LENGTH_BYTES = 33U; const uint32_t DMR_FRAME_LENGTH_BYTES = 33U;
const unsigned int DMR_SYNC_LENGTH_BITS = 48U; const uint32_t DMR_SYNC_LENGTH_BITS = 48U;
const unsigned int DMR_SYNC_LENGTH_BYTES = 6U; const uint32_t DMR_SYNC_LENGTH_BYTES = 6U;
const unsigned int DMR_EMB_LENGTH_BITS = 8U; const uint32_t DMR_EMB_LENGTH_BITS = 8U;
const unsigned int DMR_EMB_LENGTH_BYTES = 1U; const uint32_t DMR_EMB_LENGTH_BYTES = 1U;
const unsigned int DMR_SLOT_TYPE_LENGTH_BITS = 8U; const uint32_t DMR_SLOT_TYPE_LENGTH_BITS = 8U;
const unsigned int DMR_SLOT_TYPE_LENGTH_BYTES = 1U; const uint32_t DMR_SLOT_TYPE_LENGTH_BYTES = 1U;
const unsigned int DMR_EMBEDDED_SIGNALLING_LENGTH_BITS = 32U; const uint32_t DMR_EMBEDDED_SIGNALLING_LENGTH_BITS = 32U;
const unsigned int DMR_EMBEDDED_SIGNALLING_LENGTH_BYTES = 4U; const uint32_t DMR_EMBEDDED_SIGNALLING_LENGTH_BYTES = 4U;
const unsigned int DMR_AMBE_LENGTH_BITS = 108U * 2U; const uint32_t DMR_AMBE_LENGTH_BITS = 108U * 2U;
const unsigned int DMR_AMBE_LENGTH_BYTES = 27U; const uint32_t DMR_AMBE_LENGTH_BYTES = 27U;
const unsigned char BS_SOURCED_AUDIO_SYNC[] = {0x07U, 0x55U, 0xFDU, 0x7DU, 0xF7U, 0x5FU, 0x70U}; const uint8_t 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_DATA_SYNC[] = {0x0DU, 0xFFU, 0x57U, 0xD7U, 0x5DU, 0xF5U, 0xD0U};
const unsigned char MS_SOURCED_AUDIO_SYNC[] = {0x07U, 0xF7U, 0xD5U, 0xDDU, 0x57U, 0xDFU, 0xD0U}; const uint8_t 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_DATA_SYNC[] = {0x0DU, 0x5DU, 0x7FU, 0x77U, 0xFDU, 0x75U, 0x70U};
const unsigned char DIRECT_SLOT1_AUDIO_SYNC[] = {0x05U, 0xD5U, 0x77U, 0xF7U, 0x75U, 0x7FU, 0xF0U}; const uint8_t 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_DATA_SYNC[] = {0x0FU, 0x7FU, 0xDDU, 0x5DU, 0xDFU, 0xD5U, 0x50U};
const unsigned char DIRECT_SLOT2_AUDIO_SYNC[] = {0x07U, 0xDFU, 0xFDU, 0x5FU, 0x55U, 0xD5U, 0xF0U}; const uint8_t 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_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. // 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, 0x53U, 0xC2U, 0x5EU, 0xABU, 0xA8U, 0x67U, 0x1DU, 0xC7U, 0x38U, 0x3BU, 0xD9U,
0x36U, 0x00U, 0x0DU, 0xFFU, 0x57U, 0xD7U, 0x5DU, 0xF5U, 0xD0U, 0x03U, 0xF6U, 0x36U, 0x00U, 0x0DU, 0xFFU, 0x57U, 0xD7U, 0x5DU, 0xF5U, 0xD0U, 0x03U, 0xF6U,
0xE4U, 0x65U, 0x17U, 0x1BU, 0x48U, 0xCAU, 0x6DU, 0x4FU, 0xC6U, 0x10U, 0xB4U}; 0xE4U, 0x65U, 0x17U, 0x1BU, 0x48U, 0xCAU, 0x6DU, 0x4FU, 0xC6U, 0x10U, 0xB4U};
// A silence frame only // 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, 0x81U, 0x52U, 0x60U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x01U, 0x73U, 0x00U,
0x2AU, 0x6BU, 0xB9U, 0xE8U, 0x81U, 0x52U, 0x61U, 0x73U, 0x00U, 0x2AU, 0x6BU}; 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 uint8_t 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 uint8_t 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 uint8_t VOICE_LC_HEADER_CRC_MASK[] = {0x96U, 0x96U, 0x96U};
const unsigned char TERMINATOR_WITH_LC_CRC_MASK[] = {0x99U, 0x99U, 0x99U}; const uint8_t TERMINATOR_WITH_LC_CRC_MASK[] = {0x99U, 0x99U, 0x99U};
const unsigned char PI_HEADER_CRC_MASK[] = {0x69U, 0x69U}; const uint8_t PI_HEADER_CRC_MASK[] = {0x69U, 0x69U};
const unsigned char DATA_HEADER_CRC_MASK[] = {0xCCU, 0xCCU}; const uint8_t DATA_HEADER_CRC_MASK[] = {0xCCU, 0xCCU};
const unsigned char CSBK_CRC_MASK[] = {0xA5U, 0xA5U}; const uint8_t CSBK_CRC_MASK[] = {0xA5U, 0xA5U};
const unsigned int DMR_SLOT_TIME = 60U; const uint32_t DMR_SLOT_TIME = 60U;
const unsigned int AMBE_PER_SLOT = 3U; const uint32_t AMBE_PER_SLOT = 3U;
const unsigned char DT_MASK = 0x0FU; const uint8_t DT_MASK = 0x0FU;
const unsigned char DT_VOICE_PI_HEADER = 0x00U; const uint8_t DT_VOICE_PI_HEADER = 0x00U;
const unsigned char DT_VOICE_LC_HEADER = 0x01U; const uint8_t DT_VOICE_LC_HEADER = 0x01U;
const unsigned char DT_TERMINATOR_WITH_LC = 0x02U; const uint8_t DT_TERMINATOR_WITH_LC = 0x02U;
const unsigned char DT_CSBK = 0x03U; const uint8_t DT_CSBK = 0x03U;
const unsigned char DT_DATA_HEADER = 0x06U; const uint8_t DT_DATA_HEADER = 0x06U;
const unsigned char DT_RATE_12_DATA = 0x07U; const uint8_t DT_RATE_12_DATA = 0x07U;
const unsigned char DT_RATE_34_DATA = 0x08U; const uint8_t DT_RATE_34_DATA = 0x08U;
const unsigned char DT_IDLE = 0x09U; const uint8_t DT_IDLE = 0x09U;
const unsigned char DT_RATE_1_DATA = 0x0AU; const uint8_t DT_RATE_1_DATA = 0x0AU;
// Dummy values // Dummy values
const unsigned char DT_VOICE_SYNC = 0xF0U; const uint8_t DT_VOICE_SYNC = 0xF0U;
const unsigned char DT_VOICE = 0xF1U; const uint8_t DT_VOICE = 0xF1U;
const unsigned char DMR_IDLE_RX = 0x80U; const uint8_t DMR_IDLE_RX = 0x80U;
const unsigned char DMR_SYNC_DATA = 0x40U; const uint8_t DMR_SYNC_DATA = 0x40U;
const unsigned char DMR_SYNC_AUDIO = 0x20U; const uint8_t DMR_SYNC_AUDIO = 0x20U;
const unsigned char DMR_SLOT1 = 0x00U; const uint8_t DMR_SLOT1 = 0x00U;
const unsigned char DMR_SLOT2 = 0x80U; const uint8_t DMR_SLOT2 = 0x80U;
const unsigned char DPF_UDT = 0x00U; const uint8_t DPF_UDT = 0x00U;
const unsigned char DPF_RESPONSE = 0x01U; const uint8_t DPF_RESPONSE = 0x01U;
const unsigned char DPF_UNCONFIRMED_DATA = 0x02U; const uint8_t DPF_UNCONFIRMED_DATA = 0x02U;
const unsigned char DPF_CONFIRMED_DATA = 0x03U; const uint8_t DPF_CONFIRMED_DATA = 0x03U;
const unsigned char DPF_DEFINED_SHORT = 0x0DU; const uint8_t DPF_DEFINED_SHORT = 0x0DU;
const unsigned char DPF_DEFINED_RAW = 0x0EU; const uint8_t DPF_DEFINED_RAW = 0x0EU;
const unsigned char DPF_PROPRIETARY = 0x0FU; const uint8_t DPF_PROPRIETARY = 0x0FU;
const unsigned char FID_ETSI = 0U; const uint8_t FID_ETSI = 0U;
const unsigned char FID_DMRA = 16U; const uint8_t FID_DMRA = 16U;
enum FLCO { enum FLCO {
FLCO_GROUP = 0, FLCO_GROUP = 0,

@ -31,7 +31,7 @@ DEFINES += VERSION_NUMBER=\"\\\"$${VERSION_BUILD}\\\"\"
DEFINES += QT_DEPRECATED_WARNINGS DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
DEFINES += VOCODER_PLUGIN DEFINES += VOCODER_PLUGIN
DEFINES += USE_FLITE #DEFINES += USE_FLITE
#DEFINES += USE_EXTERNAL_CODEC2 #DEFINES += USE_EXTERNAL_CODEC2
HEADERS += \ HEADERS += \

@ -8,7 +8,7 @@
#include <cstdio> #include <cstdio>
#include <cassert> #include <cassert>
const unsigned int ENCODING_TABLE_23127[] = { const uint32_t ENCODING_TABLE_23127[] = {
0x000000U, 0x0018EAU, 0x00293EU, 0x0031D4U, 0x004A96U, 0x00527CU, 0x0063A8U, 0x007B42U, 0x008DC6U, 0x00952CU, 0x000000U, 0x0018EAU, 0x00293EU, 0x0031D4U, 0x004A96U, 0x00527CU, 0x0063A8U, 0x007B42U, 0x008DC6U, 0x00952CU,
0x00A4F8U, 0x00BC12U, 0x00C750U, 0x00DFBAU, 0x00EE6EU, 0x00F684U, 0x010366U, 0x011B8CU, 0x012A58U, 0x0132B2U, 0x00A4F8U, 0x00BC12U, 0x00C750U, 0x00DFBAU, 0x00EE6EU, 0x00F684U, 0x010366U, 0x011B8CU, 0x012A58U, 0x0132B2U,
0x0149F0U, 0x01511AU, 0x0160CEU, 0x017824U, 0x018EA0U, 0x01964AU, 0x01A79EU, 0x01BF74U, 0x01C436U, 0x01DCDCU, 0x0149F0U, 0x01511AU, 0x0160CEU, 0x017824U, 0x018EA0U, 0x01964AU, 0x01A79EU, 0x01BF74U, 0x01C436U, 0x01DCDCU,
@ -420,7 +420,7 @@ const unsigned int ENCODING_TABLE_23127[] = {
0xFF097AU, 0xFF1190U, 0xFF2044U, 0xFF38AEU, 0xFF43ECU, 0xFF5B06U, 0xFF6AD2U, 0xFF7238U, 0xFF84BCU, 0xFF9C56U, 0xFF097AU, 0xFF1190U, 0xFF2044U, 0xFF38AEU, 0xFF43ECU, 0xFF5B06U, 0xFF6AD2U, 0xFF7238U, 0xFF84BCU, 0xFF9C56U,
0xFFAD82U, 0xFFB568U, 0xFFCE2AU, 0xFFD6C0U, 0xFFE714U, 0xFFFFFEU}; 0xFFAD82U, 0xFFB568U, 0xFFCE2AU, 0xFFD6C0U, 0xFFE714U, 0xFFFFFEU};
static const unsigned int ENCODING_TABLE_24128[] = { static const uint32_t ENCODING_TABLE_24128[] = {
0x000000U, 0x0018EBU, 0x00293EU, 0x0031D5U, 0x004A97U, 0x00527CU, 0x0063A9U, 0x007B42U, 0x008DC6U, 0x00952DU, 0x000000U, 0x0018EBU, 0x00293EU, 0x0031D5U, 0x004A97U, 0x00527CU, 0x0063A9U, 0x007B42U, 0x008DC6U, 0x00952DU,
0x00A4F8U, 0x00BC13U, 0x00C751U, 0x00DFBAU, 0x00EE6FU, 0x00F684U, 0x010367U, 0x011B8CU, 0x012A59U, 0x0132B2U, 0x00A4F8U, 0x00BC13U, 0x00C751U, 0x00DFBAU, 0x00EE6FU, 0x00F684U, 0x010367U, 0x011B8CU, 0x012A59U, 0x0132B2U,
0x0149F0U, 0x01511BU, 0x0160CEU, 0x017825U, 0x018EA1U, 0x01964AU, 0x01A79FU, 0x01BF74U, 0x01C436U, 0x01DCDDU, 0x0149F0U, 0x01511BU, 0x0160CEU, 0x017825U, 0x018EA1U, 0x01964AU, 0x01A79FU, 0x01BF74U, 0x01C436U, 0x01DCDDU,
@ -832,7 +832,7 @@ static const unsigned int ENCODING_TABLE_24128[] = {
0xFF097BU, 0xFF1190U, 0xFF2045U, 0xFF38AEU, 0xFF43ECU, 0xFF5B07U, 0xFF6AD2U, 0xFF7239U, 0xFF84BDU, 0xFF9C56U, 0xFF097BU, 0xFF1190U, 0xFF2045U, 0xFF38AEU, 0xFF43ECU, 0xFF5B07U, 0xFF6AD2U, 0xFF7239U, 0xFF84BDU, 0xFF9C56U,
0xFFAD83U, 0xFFB568U, 0xFFCE2AU, 0xFFD6C1U, 0xFFE714U, 0xFFFFFFU}; 0xFFAD83U, 0xFFB568U, 0xFFCE2AU, 0xFFD6C1U, 0xFFE714U, 0xFFFFFFU};
static const unsigned int DECODING_TABLE_23127[] = { static const uint32_t DECODING_TABLE_23127[] = {
0x000000U, 0x000001U, 0x000002U, 0x000003U, 0x000004U, 0x000005U, 0x000006U, 0x000007U, 0x000008U, 0x000009U, 0x000000U, 0x000001U, 0x000002U, 0x000003U, 0x000004U, 0x000005U, 0x000006U, 0x000007U, 0x000008U, 0x000009U,
0x00000AU, 0x00000BU, 0x00000CU, 0x00000DU, 0x00000EU, 0x024020U, 0x000010U, 0x000011U, 0x000012U, 0x000013U, 0x00000AU, 0x00000BU, 0x00000CU, 0x00000DU, 0x00000EU, 0x024020U, 0x000010U, 0x000011U, 0x000012U, 0x000013U,
0x000014U, 0x000015U, 0x000016U, 0x412000U, 0x000018U, 0x000019U, 0x00001AU, 0x180800U, 0x00001CU, 0x200300U, 0x000014U, 0x000015U, 0x000016U, 0x412000U, 0x000018U, 0x000019U, 0x00001AU, 0x180800U, 0x00001CU, 0x200300U,
@ -1044,7 +1044,7 @@ static const unsigned int DECODING_TABLE_23127[] = {
#define MASK12 0xfffff800 /* auxiliary vector for testing */ #define MASK12 0xfffff800 /* auxiliary vector for testing */
#define GENPOL 0x00000c75 /* generator polinomial, g(x) */ #define GENPOL 0x00000c75 /* generator polinomial, g(x) */
static unsigned int get_syndrome_23127(unsigned int pattern) static uint32_t get_syndrome_23127(uint32_t pattern)
/* /*
* Compute the syndrome corresponding to the given pattern, i.e., the * Compute the syndrome corresponding to the given pattern, i.e., the
* remainder after dividing the pattern (when considering it as the vector * remainder after dividing the pattern (when considering it as the vector
@ -1055,7 +1055,7 @@ static unsigned int get_syndrome_23127(unsigned int pattern)
* obtain its syndrome in decoding. * obtain its syndrome in decoding.
*/ */
{ {
unsigned int aux = X22; uint32_t aux = X22;
if (pattern >= X11) { if (pattern >= X11) {
while (pattern & MASK12) { while (pattern & MASK12) {
@ -1069,36 +1069,36 @@ static unsigned int get_syndrome_23127(unsigned int pattern)
return pattern; return pattern;
} }
unsigned int CGolay24128::encode23127(unsigned int data) uint32_t CGolay24128::encode23127(uint32_t data)
{ {
return ENCODING_TABLE_23127[data]; return ENCODING_TABLE_23127[data];
} }
unsigned int CGolay24128::encode24128(unsigned int data) uint32_t CGolay24128::encode24128(uint32_t data)
{ {
return ENCODING_TABLE_24128[data]; return ENCODING_TABLE_24128[data];
} }
unsigned int CGolay24128::decode23127(unsigned int code) uint32_t CGolay24128::decode23127(uint32_t code)
{ {
unsigned int syndrome = ::get_syndrome_23127(code); uint32_t syndrome = ::get_syndrome_23127(code);
unsigned int error_pattern = DECODING_TABLE_23127[syndrome]; uint32_t error_pattern = DECODING_TABLE_23127[syndrome];
code ^= error_pattern; code ^= error_pattern;
return code >> 11; return code >> 11;
} }
unsigned int CGolay24128::decode24128(unsigned int code) uint32_t CGolay24128::decode24128(uint32_t code)
{ {
return decode23127(code >> 1); return decode23127(code >> 1);
} }
unsigned int CGolay24128::decode24128(unsigned char* bytes) uint32_t CGolay24128::decode24128(uint8_t* bytes)
{ {
assert(bytes != NULL); assert(bytes != NULL);
unsigned int code = bytes[0U]; uint32_t code = bytes[0U];
code <<= 8; code <<= 8;
code |= bytes[1U]; code |= bytes[1U];
code <<= 8; code <<= 8;
@ -1107,10 +1107,10 @@ unsigned int CGolay24128::decode24128(unsigned char* bytes)
return decode23127(code >> 1); return decode23127(code >> 1);
} }
bool CGolay24128::decode24128(unsigned int in, unsigned int& out) bool CGolay24128::decode24128(uint32_t in, uint32_t& out)
{ {
unsigned int syndrome = ::get_syndrome_23127(in >> 1); uint32_t syndrome = ::get_syndrome_23127(in >> 1);
unsigned int error_pattern = DECODING_TABLE_23127[syndrome] << 1; uint32_t error_pattern = DECODING_TABLE_23127[syndrome] << 1;
out = in ^ error_pattern; out = in ^ error_pattern;
@ -1121,18 +1121,18 @@ bool CGolay24128::decode24128(unsigned int in, unsigned int& out)
return valid; return valid;
} }
bool CGolay24128::decode24128(unsigned char* in, unsigned int& out) bool CGolay24128::decode24128(uint8_t* in, uint32_t& out)
{ {
assert(in != NULL); assert(in != NULL);
unsigned int code = (in[0U] << 16) | (in[1U] << 8) | (in[2U] << 0); uint32_t code = (in[0U] << 16) | (in[1U] << 8) | (in[2U] << 0);
return decode24128(code, out); return decode24128(code, out);
} }
unsigned int CGolay24128::countBits(unsigned int v) uint32_t CGolay24128::countBits(uint32_t v)
{ {
unsigned int count = 0U; uint32_t count = 0U;
while (v != 0U) { while (v != 0U) {
v &= v - 1U; v &= v - 1U;

@ -18,18 +18,19 @@
#ifndef Golay24128_H #ifndef Golay24128_H
#define Golay24128_H #define Golay24128_H
#include <cstdint>
class CGolay24128 { class CGolay24128 {
public: public:
static unsigned int encode23127(unsigned int data); static uint32_t encode23127(uint32_t data);
static unsigned int encode24128(unsigned int data); static uint32_t encode24128(uint32_t data);
static unsigned int decode23127(unsigned int code); static uint32_t decode23127(uint32_t code);
static unsigned int decode24128(unsigned int code); static uint32_t decode24128(uint32_t code);
static unsigned int decode24128(unsigned char* bytes); static uint32_t decode24128(uint8_t* bytes);
static bool decode24128(unsigned int in, unsigned int& out); static bool decode24128(uint32_t in, uint32_t& out);
static bool decode24128(unsigned char* in, unsigned int& out); static bool decode24128(uint8_t* in, uint32_t& out);
static unsigned int countBits(unsigned int v); static uint32_t countBits(uint32_t v);
}; };
#endif #endif

@ -23,9 +23,9 @@
#include <cstring> #include <cstring>
#include <cstdlib> #include <cstdlib>
const unsigned int PUNCTURE_LIST_LINK_SETUP_COUNT = 60U; const uint32_t PUNCTURE_LIST_LINK_SETUP_COUNT = 60U;
const unsigned int PUNCTURE_LIST_LINK_SETUP[] = { const uint32_t PUNCTURE_LIST_LINK_SETUP[] = {
2U, 6U, 10U, 14U, 18U, 22U, 26U, 30U, 34U, 38U, 42U, 46U, 50U, 54U, 58U, 63U, 67U, 71U, 75U, 79U, 83U, 2U, 6U, 10U, 14U, 18U, 22U, 26U, 30U, 34U, 38U, 42U, 46U, 50U, 54U, 58U, 63U, 67U, 71U, 75U, 79U, 83U,
87U, 91U, 95U, 99U, 103U, 107U, 111U, 115U, 119U, 124U, 128U, 132U, 136U, 140U, 144U, 148U, 152U, 156U, 160U, 164U, 168U, 87U, 91U, 95U, 99U, 103U, 107U, 111U, 115U, 119U, 124U, 128U, 132U, 136U, 140U, 144U, 148U, 152U, 156U, 160U, 164U, 168U,
172U, 176U, 180U, 185U, 189U, 193U, 197U, 201U, 205U, 209U, 213U, 217U, 221U, 225U, 229U, 233U, 237U, 241U, 246U, 250U, 254U, 172U, 176U, 180U, 185U, 189U, 193U, 197U, 201U, 205U, 209U, 213U, 217U, 221U, 225U, 229U, 233U, 237U, 241U, 246U, 250U, 254U,
@ -33,13 +33,13 @@ const unsigned int PUNCTURE_LIST_LINK_SETUP[] = {
343U, 347U, 351U, 355U, 359U, 363U, 368U, 372U, 376U, 380U, 384U, 388U, 392U, 396U, 400U, 404U, 408U, 412U, 416U, 420U, 424U, 343U, 347U, 351U, 355U, 359U, 363U, 368U, 372U, 376U, 380U, 384U, 388U, 392U, 396U, 400U, 404U, 408U, 412U, 416U, 420U, 424U,
429U, 433U, 437U, 441U, 445U, 449U, 453U, 457U, 461U, 465U, 469U, 473U, 477U, 481U, 485U}; 429U, 433U, 437U, 441U, 445U, 449U, 453U, 457U, 461U, 465U, 469U, 473U, 477U, 481U, 485U};
const unsigned int PUNCTURE_LIST_DATA_COUNT = 12U; const uint32_t PUNCTURE_LIST_DATA_COUNT = 12U;
const unsigned int PUNCTURE_LIST_DATA[] = { const uint32_t PUNCTURE_LIST_DATA[] = {
11U, 23U, 35U, 47U, 59U, 71U, 83U, 95U, 107U, 119U, 131U, 143U, 155U, 167U, 179U, 191U, 203U, 215U, 227U, 239U, 251U, 11U, 23U, 35U, 47U, 59U, 71U, 83U, 95U, 107U, 119U, 131U, 143U, 155U, 167U, 179U, 191U, 203U, 215U, 227U, 239U, 251U,
263U, 275U, 287U}; 263U, 275U, 287U};
const unsigned char BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U}; const uint8_t BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U};
#define WRITE_BIT1(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7]) #define WRITE_BIT1(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7])
#define READ_BIT1(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7]) #define READ_BIT1(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7])
@ -47,10 +47,10 @@ const unsigned char BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U
const uint8_t BRANCH_TABLE1[] = {0U, 0U, 0U, 0U, 2U, 2U, 2U, 2U}; const uint8_t BRANCH_TABLE1[] = {0U, 0U, 0U, 0U, 2U, 2U, 2U, 2U};
const uint8_t BRANCH_TABLE2[] = {0U, 2U, 2U, 0U, 0U, 2U, 2U, 0U}; const uint8_t BRANCH_TABLE2[] = {0U, 2U, 2U, 0U, 0U, 2U, 2U, 0U};
const unsigned int NUM_OF_STATES_D2 = 8U; const uint32_t NUM_OF_STATES_D2 = 8U;
const unsigned int NUM_OF_STATES = 16U; const uint32_t NUM_OF_STATES = 16U;
const uint32_t M = 4U; const uint32_t M = 4U;
const unsigned int K = 5U; const uint32_t K = 5U;
CM17Convolution::CM17Convolution() : CM17Convolution::CM17Convolution() :
m_metrics1(NULL), m_metrics1(NULL),
@ -72,21 +72,21 @@ CM17Convolution::~CM17Convolution()
delete[] m_decisions; delete[] m_decisions;
} }
void CM17Convolution::encodeLinkSetup(const unsigned char* in, unsigned char* out) const void CM17Convolution::encodeLinkSetup(const uint8_t* in, uint8_t* out) const
{ {
assert(in != NULL); assert(in != NULL);
assert(out != NULL); assert(out != NULL);
unsigned char temp1[31U]; uint8_t temp1[31U];
::memset(temp1, 0x00U, 31U); ::memset(temp1, 0x00U, 31U);
::memcpy(temp1, in, 30U); ::memcpy(temp1, in, 30U);
unsigned char temp2[61U]; uint8_t temp2[61U];
encode(temp1, temp2, 244U); encode(temp1, temp2, 244U);
unsigned int n = 0U; uint32_t n = 0U;
unsigned int index = 0U; uint32_t index = 0U;
for (unsigned int i = 0U; i < 488U; i++) { for (uint32_t i = 0U; i < 488U; i++) {
if (i != PUNCTURE_LIST_LINK_SETUP[index]) { if (i != PUNCTURE_LIST_LINK_SETUP[index]) {
bool b = READ_BIT1(temp2, i); bool b = READ_BIT1(temp2, i);
WRITE_BIT1(out, n, b); WRITE_BIT1(out, n, b);
@ -97,21 +97,21 @@ void CM17Convolution::encodeLinkSetup(const unsigned char* in, unsigned char* ou
} }
} }
void CM17Convolution::encodeData(const unsigned char* in, unsigned char* out) const void CM17Convolution::encodeData(const uint8_t* in, uint8_t* out) const
{ {
assert(in != NULL); assert(in != NULL);
assert(out != NULL); assert(out != NULL);
unsigned char temp1[19U]; uint8_t temp1[19U];
::memset(temp1, 0x00U, 19U); ::memset(temp1, 0x00U, 19U);
::memcpy(temp1, in, 18U); ::memcpy(temp1, in, 18U);
unsigned char temp2[37U]; uint8_t temp2[37U];
encode(temp1, temp2, 148U); encode(temp1, temp2, 148U);
unsigned int n = 0U; uint32_t n = 0U;
unsigned int index = 0U; uint32_t index = 0U;
for (unsigned int i = 0U; i < 296U; i++) { for (uint32_t i = 0U; i < 296U; i++) {
if (i != PUNCTURE_LIST_DATA[index]) { if (i != PUNCTURE_LIST_DATA[index]) {
bool b = READ_BIT1(temp2, i); bool b = READ_BIT1(temp2, i);
WRITE_BIT1(out, n, b); WRITE_BIT1(out, n, b);
@ -122,7 +122,7 @@ void CM17Convolution::encodeData(const unsigned char* in, unsigned char* out) co
} }
} }
unsigned int CM17Convolution::decodeLinkSetup(const unsigned char* in, unsigned char* out) uint32_t CM17Convolution::decodeLinkSetup(const uint8_t* in, uint8_t* out)
{ {
assert(in != NULL); assert(in != NULL);
assert(out != NULL); assert(out != NULL);
@ -130,9 +130,9 @@ unsigned int CM17Convolution::decodeLinkSetup(const unsigned char* in, unsigned
uint8_t temp[500U]; uint8_t temp[500U];
::memset(temp, 0x00U, 500U); ::memset(temp, 0x00U, 500U);
unsigned int n = 0U; uint32_t n = 0U;
unsigned int index = 0U; uint32_t index = 0U;
for (unsigned int i = 0U; i < 368U; i++) { for (uint32_t i = 0U; i < 368U; i++) {
if (n == PUNCTURE_LIST_LINK_SETUP[index]) { if (n == PUNCTURE_LIST_LINK_SETUP[index]) {
temp[n++] = 1U; temp[n++] = 1U;
index++; index++;
@ -145,7 +145,7 @@ unsigned int CM17Convolution::decodeLinkSetup(const unsigned char* in, unsigned
start(); start();
n = 0U; n = 0U;
for (unsigned int i = 0U; i < 244U; i++) { for (uint32_t i = 0U; i < 244U; i++) {
uint8_t s0 = temp[n++]; uint8_t s0 = temp[n++];
uint8_t s1 = temp[n++]; uint8_t s1 = temp[n++];
@ -155,7 +155,7 @@ unsigned int CM17Convolution::decodeLinkSetup(const unsigned char* in, unsigned
return chainback(out, 240U) - PUNCTURE_LIST_LINK_SETUP_COUNT; return chainback(out, 240U) - PUNCTURE_LIST_LINK_SETUP_COUNT;
} }
unsigned int CM17Convolution::decodeData(const unsigned char* in, unsigned char* out) uint32_t CM17Convolution::decodeData(const uint8_t* in, uint8_t* out)
{ {
assert(in != NULL); assert(in != NULL);
assert(out != NULL); assert(out != NULL);
@ -163,9 +163,9 @@ unsigned int CM17Convolution::decodeData(const unsigned char* in, unsigned char*
uint8_t temp[300U]; uint8_t temp[300U];
::memset(temp, 0x00U, 300U); ::memset(temp, 0x00U, 300U);
unsigned int n = 0U; uint32_t n = 0U;
unsigned int index = 0U; uint32_t index = 0U;
for (unsigned int i = 0U; i < 272U; i++) { for (uint32_t i = 0U; i < 272U; i++) {
if (n == PUNCTURE_LIST_DATA[index]) { if (n == PUNCTURE_LIST_DATA[index]) {
temp[n++] = 1U; temp[n++] = 1U;
index++; index++;
@ -178,7 +178,7 @@ unsigned int CM17Convolution::decodeData(const unsigned char* in, unsigned char*
start(); start();
n = 0U; n = 0U;
for (unsigned int i = 0U; i < 148U; i++) { for (uint32_t i = 0U; i < 148U; i++) {
uint8_t s0 = temp[n++]; uint8_t s0 = temp[n++];
uint8_t s1 = temp[n++]; uint8_t s1 = temp[n++];
@ -229,7 +229,7 @@ void CM17Convolution::decode(uint8_t s0, uint8_t s1)
m_newMetrics = tmp; m_newMetrics = tmp;
} }
unsigned int CM17Convolution::chainback(unsigned char* out, unsigned int nBits) uint32_t CM17Convolution::chainback(uint8_t* out, uint32_t nBits)
{ {
assert(out != NULL); assert(out != NULL);
@ -245,9 +245,9 @@ unsigned int CM17Convolution::chainback(unsigned char* out, unsigned int nBits)
WRITE_BIT1(out, nBits, bit != 0U); WRITE_BIT1(out, nBits, bit != 0U);
} }
unsigned int minCost = m_oldMetrics[0]; uint32_t minCost = m_oldMetrics[0];
for (unsigned int i = 0U; i < NUM_OF_STATES; i++) { for (uint32_t i = 0U; i < NUM_OF_STATES; i++) {
if (m_oldMetrics[i] < minCost) if (m_oldMetrics[i] < minCost)
minCost = m_oldMetrics[i]; minCost = m_oldMetrics[i];
} }
@ -255,7 +255,7 @@ unsigned int CM17Convolution::chainback(unsigned char* out, unsigned int nBits)
return minCost / (M >> 1); return minCost / (M >> 1);
} }
void CM17Convolution::encode(const unsigned char* in, unsigned char* out, unsigned int nBits) const void CM17Convolution::encode(const uint8_t* in, uint8_t* out, uint32_t nBits) const
{ {
assert(in != NULL); assert(in != NULL);
assert(out != NULL); assert(out != NULL);
@ -263,7 +263,7 @@ void CM17Convolution::encode(const unsigned char* in, unsigned char* out, unsign
uint8_t d1 = 0U, d2 = 0U, d3 = 0U, d4 = 0U; uint8_t d1 = 0U, d2 = 0U, d3 = 0U, d4 = 0U;
uint32_t k = 0U; uint32_t k = 0U;
for (unsigned int i = 0U; i < nBits; i++) { for (uint32_t i = 0U; i < nBits; i++) {
uint8_t d = READ_BIT1(in, i) ? 1U : 0U; uint8_t d = READ_BIT1(in, i) ? 1U : 0U;
uint8_t g1 = (d + d3 + d4) & 1; uint8_t g1 = (d + d3 + d4) & 1;

@ -26,11 +26,11 @@ public:
CM17Convolution(); CM17Convolution();
~CM17Convolution(); ~CM17Convolution();
unsigned int decodeLinkSetup(const unsigned char* in, unsigned char* out); unsigned int decodeLinkSetup(const uint8_t* in, uint8_t* out);
unsigned int decodeData(const unsigned char* in, unsigned char* out); unsigned int decodeData(const uint8_t* in, uint8_t* out);
void encodeLinkSetup(const unsigned char* in, unsigned char* out) const; void encodeLinkSetup(const uint8_t* in, uint8_t* out) const;
void encodeData(const unsigned char* in, unsigned char* out) const; void encodeData(const uint8_t* in, uint8_t* out) const;
private: private:
uint16_t* m_metrics1; uint16_t* m_metrics1;
@ -43,9 +43,9 @@ private:
void start(); void start();
void decode(uint8_t s0, uint8_t s1); void decode(uint8_t s0, uint8_t s1);
unsigned int chainback(unsigned char* out, unsigned int nBits); unsigned int chainback(uint8_t* out, uint32_t nBits);
void encode(const unsigned char* in, unsigned char* out, unsigned int nBits) const; void encode(const uint8_t* in, uint8_t* out, uint32_t nBits) const;
}; };
#endif #endif

@ -18,63 +18,64 @@
#if !defined(M17DEFINES_H) #if !defined(M17DEFINES_H)
#define M17DEFINES_H #define M17DEFINES_H
#include <cstdint>
const unsigned int M17_RADIO_SYMBOL_LENGTH = 5U; // At 24 kHz sample rate const uint32_t M17_RADIO_SYMBOL_LENGTH = 5U; // At 24 kHz sample rate
const unsigned int M17_FRAME_LENGTH_BITS = 384U; const uint32_t M17_FRAME_LENGTH_BITS = 384U;
const unsigned int M17_FRAME_LENGTH_BYTES = M17_FRAME_LENGTH_BITS / 8U; const uint32_t M17_FRAME_LENGTH_BYTES = M17_FRAME_LENGTH_BITS / 8U;
const unsigned char M17_LINK_SETUP_SYNC_BYTES[] = {0x55U, 0xF7U}; const uint8_t M17_LINK_SETUP_SYNC_BYTES[] = {0x55U, 0xF7U};
const unsigned char M17_STREAM_SYNC_BYTES[] = {0xFFU, 0x5DU}; const uint8_t M17_STREAM_SYNC_BYTES[] = {0xFFU, 0x5DU};
const unsigned char M17_EOT_SYNC_BYTES[] = {0x55U, 0x5DU}; const uint8_t M17_EOT_SYNC_BYTES[] = {0x55U, 0x5DU};
const unsigned int M17_SYNC_LENGTH_BITS = 16U; const uint32_t M17_SYNC_LENGTH_BITS = 16U;
const unsigned int M17_SYNC_LENGTH_BYTES = M17_SYNC_LENGTH_BITS / 8U; const uint32_t M17_SYNC_LENGTH_BYTES = M17_SYNC_LENGTH_BITS / 8U;
const unsigned int M17_LSF_LENGTH_BITS = 240U; const uint32_t M17_LSF_LENGTH_BITS = 240U;
const unsigned int M17_LSF_LENGTH_BYTES = M17_LSF_LENGTH_BITS / 8U; const uint32_t M17_LSF_LENGTH_BYTES = M17_LSF_LENGTH_BITS / 8U;
const unsigned int M17_LSF_FRAGMENT_LENGTH_BITS = M17_LSF_LENGTH_BITS / 6U; const uint32_t M17_LSF_FRAGMENT_LENGTH_BITS = M17_LSF_LENGTH_BITS / 6U;
const unsigned int M17_LSF_FRAGMENT_LENGTH_BYTES = M17_LSF_FRAGMENT_LENGTH_BITS / 8U; const uint32_t M17_LSF_FRAGMENT_LENGTH_BYTES = M17_LSF_FRAGMENT_LENGTH_BITS / 8U;
const unsigned int M17_LICH_FRAGMENT_LENGTH_BITS = M17_LSF_FRAGMENT_LENGTH_BITS + 8U; const uint32_t M17_LICH_FRAGMENT_LENGTH_BITS = M17_LSF_FRAGMENT_LENGTH_BITS + 8U;
const unsigned int M17_LICH_FRAGMENT_LENGTH_BYTES = M17_LICH_FRAGMENT_LENGTH_BITS / 8U; const uint32_t M17_LICH_FRAGMENT_LENGTH_BYTES = M17_LICH_FRAGMENT_LENGTH_BITS / 8U;
const unsigned int M17_LSF_FRAGMENT_FEC_LENGTH_BITS = M17_LSF_FRAGMENT_LENGTH_BITS * 2U; const uint32_t M17_LSF_FRAGMENT_FEC_LENGTH_BITS = M17_LSF_FRAGMENT_LENGTH_BITS * 2U;
const unsigned int M17_LSF_FRAGMENT_FEC_LENGTH_BYTES = M17_LSF_FRAGMENT_FEC_LENGTH_BITS / 8U; const uint32_t M17_LSF_FRAGMENT_FEC_LENGTH_BYTES = M17_LSF_FRAGMENT_FEC_LENGTH_BITS / 8U;
const unsigned int M17_LICH_FRAGMENT_FEC_LENGTH_BITS = M17_LICH_FRAGMENT_LENGTH_BITS * 2U; const uint32_t M17_LICH_FRAGMENT_FEC_LENGTH_BITS = M17_LICH_FRAGMENT_LENGTH_BITS * 2U;
const unsigned int M17_LICH_FRAGMENT_FEC_LENGTH_BYTES = M17_LICH_FRAGMENT_FEC_LENGTH_BITS / 8U; const uint32_t M17_LICH_FRAGMENT_FEC_LENGTH_BYTES = M17_LICH_FRAGMENT_FEC_LENGTH_BITS / 8U;
const unsigned int M17_PAYLOAD_LENGTH_BITS = 128U; const uint32_t M17_PAYLOAD_LENGTH_BITS = 128U;
const unsigned int M17_PAYLOAD_LENGTH_BYTES = M17_PAYLOAD_LENGTH_BITS / 8U; const uint32_t M17_PAYLOAD_LENGTH_BYTES = M17_PAYLOAD_LENGTH_BITS / 8U;
const unsigned char M17_NULL_NONCE[] = {0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U}; const uint8_t M17_NULL_NONCE[] = {0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
const unsigned int M17_META_LENGTH_BITS = 112U; const uint32_t M17_META_LENGTH_BITS = 112U;
const unsigned int M17_META_LENGTH_BYTES = M17_META_LENGTH_BITS / 8U; const uint32_t M17_META_LENGTH_BYTES = M17_META_LENGTH_BITS / 8U;
const unsigned int M17_FN_LENGTH_BITS = 16U; const uint32_t M17_FN_LENGTH_BITS = 16U;
const unsigned int M17_FN_LENGTH_BYTES = M17_FN_LENGTH_BITS / 8U; const uint32_t M17_FN_LENGTH_BYTES = M17_FN_LENGTH_BITS / 8U;
const unsigned int M17_CRC_LENGTH_BITS = 16U; const uint32_t M17_CRC_LENGTH_BITS = 16U;
const unsigned int M17_CRC_LENGTH_BYTES = M17_CRC_LENGTH_BITS / 8U; const uint32_t M17_CRC_LENGTH_BYTES = M17_CRC_LENGTH_BITS / 8U;
const unsigned char M17_3200_SILENCE[] = {0x01U, 0x00U, 0x09U, 0x43U, 0x9CU, 0xE4U, 0x21U, 0x08U}; const uint8_t M17_3200_SILENCE[] = {0x01U, 0x00U, 0x09U, 0x43U, 0x9CU, 0xE4U, 0x21U, 0x08U};
const unsigned char M17_1600_SILENCE[] = {0x0CU, 0x41U, 0x09U, 0x03U, 0x0CU, 0x41U, 0x09U, 0x03U}; const uint8_t M17_1600_SILENCE[] = {0x0CU, 0x41U, 0x09U, 0x03U, 0x0CU, 0x41U, 0x09U, 0x03U};
const unsigned char M17_PACKET_TYPE = 0U; const uint8_t M17_PACKET_TYPE = 0U;
const unsigned char M17_STREAM_TYPE = 1U; const uint8_t M17_STREAM_TYPE = 1U;
const unsigned char M17_DATA_TYPE_DATA = 0x01U; const uint8_t M17_DATA_TYPE_DATA = 0x01U;
const unsigned char M17_DATA_TYPE_VOICE = 0x02U; const uint8_t M17_DATA_TYPE_VOICE = 0x02U;
const unsigned char M17_DATA_TYPE_VOICE_DATA = 0x03U; const uint8_t M17_DATA_TYPE_VOICE_DATA = 0x03U;
const unsigned char M17_ENCRYPTION_TYPE_NONE = 0x00U; const uint8_t M17_ENCRYPTION_TYPE_NONE = 0x00U;
const unsigned char M17_ENCRYPTION_TYPE_AES = 0x01U; const uint8_t M17_ENCRYPTION_TYPE_AES = 0x01U;
const unsigned char M17_ENCRYPTION_TYPE_SCRAMBLE = 0x02U; const uint8_t M17_ENCRYPTION_TYPE_SCRAMBLE = 0x02U;
const unsigned char M17_ENCRYPTION_SUB_TYPE_TEXT = 0x00U; const uint8_t M17_ENCRYPTION_SUB_TYPE_TEXT = 0x00U;
const unsigned char M17_ENCRYPTION_SUB_TYPE_GPS = 0x01U; const uint8_t M17_ENCRYPTION_SUB_TYPE_GPS = 0x01U;
const unsigned char M17_ENCRYPTION_SUB_TYPE_CALLSIGNS = 0x02U; const uint8_t M17_ENCRYPTION_SUB_TYPE_CALLSIGNS = 0x02U;
#endif #endif

@ -1,5 +1,6 @@
#ifndef MMDVMDEFINES_H #ifndef MMDVMDEFINES_H
#define MMDVMDEFINES_H #define MMDVMDEFINES_H
#include <cstdint>
enum HW_TYPE { enum HW_TYPE {
HWT_MMDVM, HWT_MMDVM,
@ -32,77 +33,77 @@ enum B_STATUS {
BS_MISSING BS_MISSING
}; };
const unsigned char MMDVM_FRAME_START = 0xE0U; const uint8_t MMDVM_FRAME_START = 0xE0U;
const unsigned char MMDVM_GET_VERSION = 0x00U; const uint8_t MMDVM_GET_VERSION = 0x00U;
const unsigned char MMDVM_GET_STATUS = 0x01U; const uint8_t MMDVM_GET_STATUS = 0x01U;
const unsigned char MMDVM_SET_CONFIG = 0x02U; const uint8_t MMDVM_SET_CONFIG = 0x02U;
const unsigned char MMDVM_SET_MODE = 0x03U; const uint8_t MMDVM_SET_MODE = 0x03U;
const unsigned char MMDVM_SET_FREQ = 0x04U; const uint8_t MMDVM_SET_FREQ = 0x04U;
const unsigned char MMDVM_SEND_CWID = 0x0AU; const uint8_t MMDVM_SEND_CWID = 0x0AU;
const unsigned char MMDVM_DSTAR_HEADER = 0x10U; const uint8_t MMDVM_DSTAR_HEADER = 0x10U;
const unsigned char MMDVM_DSTAR_DATA = 0x11U; const uint8_t MMDVM_DSTAR_DATA = 0x11U;
const unsigned char MMDVM_DSTAR_LOST = 0x12U; const uint8_t MMDVM_DSTAR_LOST = 0x12U;
const unsigned char MMDVM_DSTAR_EOT = 0x13U; const uint8_t MMDVM_DSTAR_EOT = 0x13U;
const unsigned char MMDVM_DMR_DATA1 = 0x18U; const uint8_t MMDVM_DMR_DATA1 = 0x18U;
const unsigned char MMDVM_DMR_LOST1 = 0x19U; const uint8_t MMDVM_DMR_LOST1 = 0x19U;
const unsigned char MMDVM_DMR_DATA2 = 0x1AU; const uint8_t MMDVM_DMR_DATA2 = 0x1AU;
const unsigned char MMDVM_DMR_LOST2 = 0x1BU; const uint8_t MMDVM_DMR_LOST2 = 0x1BU;
const unsigned char MMDVM_DMR_SHORTLC = 0x1CU; const uint8_t MMDVM_DMR_SHORTLC = 0x1CU;
const unsigned char MMDVM_DMR_START = 0x1DU; const uint8_t MMDVM_DMR_START = 0x1DU;
const unsigned char MMDVM_DMR_ABORT = 0x1EU; const uint8_t MMDVM_DMR_ABORT = 0x1EU;
const unsigned char MMDVM_YSF_DATA = 0x20U; const uint8_t MMDVM_YSF_DATA = 0x20U;
const unsigned char MMDVM_YSF_LOST = 0x21U; const uint8_t MMDVM_YSF_LOST = 0x21U;
const unsigned char MMDVM_P25_HDR = 0x30U; const uint8_t MMDVM_P25_HDR = 0x30U;
const unsigned char MMDVM_P25_LDU = 0x31U; const uint8_t MMDVM_P25_LDU = 0x31U;
const unsigned char MMDVM_P25_LOST = 0x32U; const uint8_t MMDVM_P25_LOST = 0x32U;
const unsigned char MMDVM_NXDN_DATA = 0x40U; const uint8_t MMDVM_NXDN_DATA = 0x40U;
const unsigned char MMDVM_NXDN_LOST = 0x41U; const uint8_t MMDVM_NXDN_LOST = 0x41U;
const unsigned char MMDVM_M17_LINK_SETUP = 0x45U; const uint8_t MMDVM_M17_LINK_SETUP = 0x45U;
const unsigned char MMDVM_M17_STREAM = 0x46U; const uint8_t MMDVM_M17_STREAM = 0x46U;
const unsigned char MMDVM_M17_PACKET = 0x47U; const uint8_t MMDVM_M17_PACKET = 0x47U;
const unsigned char MMDVM_M17_LOST = 0x48U; const uint8_t MMDVM_M17_LOST = 0x48U;
const unsigned char MMDVM_M17_EOT = 0x49U; const uint8_t MMDVM_M17_EOT = 0x49U;
const unsigned char MMDVM_POCSAG_DATA = 0x50U; const uint8_t MMDVM_POCSAG_DATA = 0x50U;
const unsigned char MMDVM_FM_PARAMS1 = 0x60U; const uint8_t MMDVM_FM_PARAMS1 = 0x60U;
const unsigned char MMDVM_FM_PARAMS2 = 0x61U; const uint8_t MMDVM_FM_PARAMS2 = 0x61U;
const unsigned char MMDVM_FM_PARAMS3 = 0x62U; const uint8_t MMDVM_FM_PARAMS3 = 0x62U;
const unsigned char MMDVM_ACK = 0x70U; const uint8_t MMDVM_ACK = 0x70U;
const unsigned char MMDVM_NAK = 0x7FU; const uint8_t MMDVM_NAK = 0x7FU;
const unsigned char MMDVM_SERIAL = 0x80U; const uint8_t MMDVM_SERIAL = 0x80U;
const unsigned char MMDVM_TRANSPARENT = 0x90U; const uint8_t MMDVM_TRANSPARENT = 0x90U;
const unsigned char MMDVM_QSO_INFO = 0x91U; const uint8_t MMDVM_QSO_INFO = 0x91U;
const unsigned char MMDVM_DEBUG1 = 0xF1U; const uint8_t MMDVM_DEBUG1 = 0xF1U;
const unsigned char MMDVM_DEBUG2 = 0xF2U; const uint8_t MMDVM_DEBUG2 = 0xF2U;
const unsigned char MMDVM_DEBUG3 = 0xF3U; const uint8_t MMDVM_DEBUG3 = 0xF3U;
const unsigned char MMDVM_DEBUG4 = 0xF4U; const uint8_t MMDVM_DEBUG4 = 0xF4U;
const unsigned char MMDVM_DEBUG5 = 0xF5U; const uint8_t MMDVM_DEBUG5 = 0xF5U;
const unsigned int MAX_RESPONSES = 30U; const uint32_t MAX_RESPONSES = 30U;
const unsigned int BUFFER_LENGTH = 2000U; const uint32_t BUFFER_LENGTH = 2000U;
const unsigned char MODE_IDLE = 0U; const uint8_t MODE_IDLE = 0U;
const unsigned char MODE_DSTAR = 1U; const uint8_t MODE_DSTAR = 1U;
const unsigned char MODE_DMR = 2U; const uint8_t MODE_DMR = 2U;
const unsigned char MODE_YSF = 3U; const uint8_t MODE_YSF = 3U;
const unsigned char MODE_P25 = 4U; const uint8_t MODE_P25 = 4U;
const unsigned char MODE_NXDN = 5U; const uint8_t MODE_NXDN = 5U;
const unsigned char MODE_M17 = 7U; const uint8_t MODE_M17 = 7U;
const unsigned char MODE_CW = 98U; const uint8_t MODE_CW = 98U;
const unsigned char MODE_LOCKOUT = 99U; const uint8_t MODE_LOCKOUT = 99U;
const unsigned char MODE_ERROR = 100U; const uint8_t MODE_ERROR = 100U;
#endif // MMDVMDEFINES_H #endif // MMDVMDEFINES_H

@ -37,7 +37,7 @@
/* This array contains the bytes used to pad the buffer to the next /* This array contains the bytes used to pad the buffer to the next
64-byte boundary. */ 64-byte boundary. */
static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; static const uint8_t fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
/* /*
@ -83,7 +83,7 @@ void CSHA256::init()
/* Copy the value from v into the memory location pointed to by *cp, /* Copy the value from v into the memory location pointed to by *cp,
If your architecture allows unaligned access this is equivalent to If your architecture allows unaligned access this is equivalent to
* (uint32_t *) cp = v */ * (uint32_t *) cp = v */
static inline void set_uint32(unsigned char* cp, uint32_t v) static inline void set_uint32(uint8_t* cp, uint32_t v)
{ {
assert(cp != NULL); assert(cp != NULL);
@ -92,11 +92,11 @@ static inline void set_uint32(unsigned char* cp, uint32_t v)
/* Put result from CTX in first 32 bytes following RESBUF. The result /* Put result from CTX in first 32 bytes following RESBUF. The result
must be in little endian byte order. */ must be in little endian byte order. */
unsigned char* CSHA256::read(unsigned char* resbuf) uint8_t* CSHA256::read(uint8_t* resbuf)
{ {
assert(resbuf != NULL); assert(resbuf != NULL);
for (unsigned int i = 0U; i < 8U; i++) for (uint32_t i = 0U; i < 8U; i++)
set_uint32(resbuf + i * sizeof(m_state[0]), SWAP(m_state[i])); set_uint32(resbuf + i * sizeof(m_state[0]), SWAP(m_state[i]));
return resbuf; return resbuf;
@ -107,8 +107,8 @@ unsigned char* CSHA256::read(unsigned char* resbuf)
void CSHA256::conclude() void CSHA256::conclude()
{ {
/* Take yet unprocessed bytes into account. */ /* Take yet unprocessed bytes into account. */
unsigned int bytes = m_buflen; uint32_t bytes = m_buflen;
unsigned int size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4; uint32_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4;
/* Now count remaining bytes. */ /* Now count remaining bytes. */
m_total[0] += bytes; m_total[0] += bytes;
@ -118,16 +118,16 @@ void CSHA256::conclude()
/* Put the 64-bit file length in *bits* at the end of the buffer. /* Put the 64-bit file length in *bits* at the end of the buffer.
Use set_uint32 rather than a simple assignment, to avoid risk of Use set_uint32 rather than a simple assignment, to avoid risk of
unaligned access. */ unaligned access. */
set_uint32((unsigned char*)&m_buffer[size - 2], SWAP((m_total[1] << 3) | (m_total[0] >> 29))); set_uint32((uint8_t*)&m_buffer[size - 2], SWAP((m_total[1] << 3) | (m_total[0] >> 29)));
set_uint32((unsigned char*)&m_buffer[size - 1], SWAP(m_total[0] << 3)); set_uint32((uint8_t*)&m_buffer[size - 1], SWAP(m_total[0] << 3));
::memcpy(&((char*)m_buffer)[bytes], fillbuf, (size - 2) * 4 - bytes); ::memcpy(&((char*)m_buffer)[bytes], fillbuf, (size - 2) * 4 - bytes);
/* Process last bytes. */ /* Process last bytes. */
processBlock((unsigned char*)m_buffer, size * 4); processBlock((uint8_t*)m_buffer, size * 4);
} }
unsigned char* CSHA256::finish(unsigned char* resbuf) uint8_t* CSHA256::finish(uint8_t* resbuf)
{ {
assert(resbuf != NULL); assert(resbuf != NULL);
@ -140,7 +140,7 @@ unsigned char* CSHA256::finish(unsigned char* resbuf)
result is always in little endian byte order, so that a byte-wise result is always in little endian byte order, so that a byte-wise
output yields to the wanted ASCII representation of the message output yields to the wanted ASCII representation of the message
digest. */ digest. */
unsigned char* CSHA256::buffer(const unsigned char* buffer, unsigned int len, unsigned char* resblock) uint8_t* CSHA256::buffer(const uint8_t* buffer, uint32_t len, uint8_t* resblock)
{ {
assert(buffer != NULL); assert(buffer != NULL);
assert(resblock != NULL); assert(resblock != NULL);
@ -155,21 +155,21 @@ unsigned char* CSHA256::buffer(const unsigned char* buffer, unsigned int len, un
return finish(resblock); return finish(resblock);
} }
void CSHA256::processBytes(const unsigned char* buffer, unsigned int len) void CSHA256::processBytes(const uint8_t* buffer, uint32_t len)
{ {
assert(buffer != NULL); assert(buffer != NULL);
/* When we already have some bits in our internal buffer concatenate /* When we already have some bits in our internal buffer concatenate
both inputs first. */ both inputs first. */
if (m_buflen != 0U) { if (m_buflen != 0U) {
unsigned int left_over = m_buflen; uint32_t left_over = m_buflen;
unsigned int add = 128U - left_over > len ? len : 128U - left_over; uint32_t add = 128U - left_over > len ? len : 128U - left_over;
::memcpy(&((char*)m_buffer)[left_over], buffer, add); ::memcpy(&((char*)m_buffer)[left_over], buffer, add);
m_buflen += add; m_buflen += add;
if (m_buflen > 64U) { if (m_buflen > 64U) {
processBlock((unsigned char*)m_buffer, m_buflen & ~63U); processBlock((uint8_t*)m_buffer, m_buflen & ~63U);
m_buflen &= 63U; m_buflen &= 63U;
@ -185,11 +185,11 @@ void CSHA256::processBytes(const unsigned char* buffer, unsigned int len)
if (len >= 64U) { if (len >= 64U) {
//#if !_STRING_ARCH_unaligned //#if !_STRING_ARCH_unaligned
//# define alignof(type) offsetof (struct { char c; type x; }, x) //# define alignof(type) offsetof (struct { char c; type x; }, x)
//# define UNALIGNED_P(p) (((unsigned int) p) % alignof (uint32_t) != 0) //# define UNALIGNED_P(p) (((uint32_t) p) % alignof (uint32_t) != 0)
// if (UNALIGNED_P (buffer)) { // if (UNALIGNED_P (buffer)) {
// while (len > 64U) { // while (len > 64U) {
// ::memcpy(m_buffer, buffer, 64U); // ::memcpy(m_buffer, buffer, 64U);
// processBlock((unsigned char*)m_buffer, 64U); // processBlock((uint8_t*)m_buffer, 64U);
// buffer += 64U; // buffer += 64U;
// len -= 64U; // len -= 64U;
// } // }
@ -204,13 +204,13 @@ void CSHA256::processBytes(const unsigned char* buffer, unsigned int len)
/* Move remaining bytes in internal buffer. */ /* Move remaining bytes in internal buffer. */
if (len > 0U) { if (len > 0U) {
unsigned int left_over = m_buflen; uint32_t left_over = m_buflen;
::memcpy(&((char*)m_buffer)[left_over], buffer, len); ::memcpy(&((char*)m_buffer)[left_over], buffer, len);
left_over += len; left_over += len;
if (left_over >= 64U) { if (left_over >= 64U) {
processBlock((unsigned char*)m_buffer, 64U); processBlock((uint8_t*)m_buffer, 64U);
left_over -= 64U; left_over -= 64U;
::memcpy(m_buffer, &m_buffer[16], left_over); ::memcpy(m_buffer, &m_buffer[16], left_over);
} }
@ -250,12 +250,12 @@ static const uint32_t roundConstants[64] = {
It is assumed that LEN % 64 == 0. It is assumed that LEN % 64 == 0.
Most of this code comes from GnuPG's cipher/sha1.c. */ Most of this code comes from GnuPG's cipher/sha1.c. */
void CSHA256::processBlock(const unsigned char* buffer, unsigned int len) void CSHA256::processBlock(const uint8_t* buffer, uint32_t len)
{ {
assert(buffer != NULL); assert(buffer != NULL);
const uint32_t* words = (uint32_t*)buffer; const uint32_t* words = (uint32_t*)buffer;
unsigned int nwords = len / sizeof(uint32_t); uint32_t nwords = len / sizeof(uint32_t);
const uint32_t* endp = words + nwords; const uint32_t* endp = words + nwords;
uint32_t x[16]; uint32_t x[16];
uint32_t a = m_state[0]; uint32_t a = m_state[0];
@ -291,7 +291,7 @@ void CSHA256::processBlock(const unsigned char* buffer, unsigned int len)
uint32_t tm; uint32_t tm;
uint32_t t0, t1; uint32_t t0, t1;
/* FIXME: see sha1.c for a better implementation. */ /* FIXME: see sha1.c for a better implementation. */
for (unsigned int t = 0U; t < 16U; t++) { for (uint32_t t = 0U; t < 16U; t++) {
x[t] = SWAP(*words); x[t] = SWAP(*words);
words++; words++;
} }

@ -35,35 +35,35 @@ public:
initialization function update the context for the next LEN bytes initialization function update the context for the next LEN bytes
starting at BUFFER. starting at BUFFER.
It is necessary that LEN is a multiple of 64!!! */ It is necessary that LEN is a multiple of 64!!! */
void processBlock(const unsigned char* buffer, unsigned int len); void processBlock(const uint8_t* buffer, uint32_t len);
/* Starting with the result of former calls of this function (or the /* Starting with the result of former calls of this function (or the
initialization function update the context for the next LEN bytes initialization function update the context for the next LEN bytes
starting at BUFFER. starting at BUFFER.
It is NOT required that LEN is a multiple of 64. */ It is NOT required that LEN is a multiple of 64. */
void processBytes(const unsigned char* buffer, unsigned int len); void processBytes(const uint8_t* buffer, uint32_t len);
/* Process the remaining bytes in the buffer and put result from CTX /* Process the remaining bytes in the buffer and put result from CTX
in first 32 bytes following RESBUF. The result is always in little in first 32 bytes following RESBUF. The result is always in little
endian byte order, so that a byte-wise output yields to the wanted endian byte order, so that a byte-wise output yields to the wanted
ASCII representation of the message digest. */ ASCII representation of the message digest. */
unsigned char* finish(unsigned char* resbuf); uint8_t* finish(uint8_t* resbuf);
/* Put result from CTX in first 32 bytes following RESBUF. The result is /* Put result from CTX in first 32 bytes following RESBUF. The result is
always in little endian byte order, so that a byte-wise output yields always in little endian byte order, so that a byte-wise output yields
to the wanted ASCII representation of the message digest. */ to the wanted ASCII representation of the message digest. */
unsigned char* read(unsigned char* resbuf); uint8_t* read(uint8_t* resbuf);
/* Compute SHA256 message digest for LEN bytes beginning at BUFFER. The /* Compute SHA256 message digest for LEN bytes beginning at BUFFER. The
result is always in little endian byte order, so that a byte-wise result is always in little endian byte order, so that a byte-wise
output yields to the wanted ASCII representation of the message output yields to the wanted ASCII representation of the message
digest. */ digest. */
unsigned char* buffer(const unsigned char* buffer, unsigned int len, unsigned char* resblock); uint8_t* buffer(const uint8_t* buffer, uint32_t len, uint8_t* resblock);
private: private:
uint32_t* m_state; uint32_t* m_state;
uint32_t* m_total; uint32_t* m_total;
unsigned int m_buflen; uint32_t m_buflen;
uint32_t* m_buffer; uint32_t* m_buffer;
void init(); void init();

@ -22,7 +22,7 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
const unsigned char BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U}; const uint8_t BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U};
#define WRITE_BIT1(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7]) #define WRITE_BIT1(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7])
#define READ_BIT1(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7]) #define READ_BIT1(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7])
@ -30,10 +30,10 @@ const unsigned char BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U
const uint8_t BRANCH_TABLE1[] = {0U, 0U, 0U, 0U, 1U, 1U, 1U, 1U}; const uint8_t BRANCH_TABLE1[] = {0U, 0U, 0U, 0U, 1U, 1U, 1U, 1U};
const uint8_t BRANCH_TABLE2[] = {0U, 1U, 1U, 0U, 0U, 1U, 1U, 0U}; const uint8_t BRANCH_TABLE2[] = {0U, 1U, 1U, 0U, 0U, 1U, 1U, 0U};
const unsigned int NUM_OF_STATES_D2 = 8U; const uint32_t NUM_OF_STATES_D2 = 8U;
const unsigned int NUM_OF_STATES = 16U; const uint32_t NUM_OF_STATES = 16U;
const uint32_t M = 2U; const uint32_t M = 2U;
const unsigned int K = 5U; const uint32_t K = 5U;
CYSFConvolution::CYSFConvolution() : CYSFConvolution::CYSFConvolution() :
m_metrics1(nullptr), m_metrics1(nullptr),
@ -96,7 +96,7 @@ void CYSFConvolution::decode(uint8_t s0, uint8_t s1)
m_newMetrics = tmp; m_newMetrics = tmp;
} }
void CYSFConvolution::chainback(unsigned char* out, unsigned int nBits) void CYSFConvolution::chainback(uint8_t* out, uint32_t nBits)
{ {
assert(out != NULL); assert(out != NULL);
@ -113,7 +113,7 @@ void CYSFConvolution::chainback(unsigned char* out, unsigned int nBits)
} }
} }
void CYSFConvolution::encode(const unsigned char* in, unsigned char* out, unsigned int nBits) const void CYSFConvolution::encode(const uint8_t* in, uint8_t* out, uint32_t nBits) const
{ {
assert(in != NULL); assert(in != NULL);
assert(out != NULL); assert(out != NULL);
@ -121,7 +121,7 @@ void CYSFConvolution::encode(const unsigned char* in, unsigned char* out, unsign
uint8_t d1 = 0U, d2 = 0U, d3 = 0U, d4 = 0U; uint8_t d1 = 0U, d2 = 0U, d3 = 0U, d4 = 0U;
uint32_t k = 0U; uint32_t k = 0U;
for (unsigned int i = 0U; i < nBits; i++) { for (uint32_t i = 0U; i < nBits; i++) {
uint8_t d = READ_BIT1(in, i) ? 1U : 0U; uint8_t d = READ_BIT1(in, i) ? 1U : 0U;
uint8_t g1 = (d + d3 + d4) & 1; uint8_t g1 = (d + d3 + d4) & 1;

@ -28,9 +28,9 @@ public:
void start(); void start();
void decode(uint8_t s0, uint8_t s1); void decode(uint8_t s0, uint8_t s1);
void chainback(unsigned char* out, unsigned int nBits); void chainback(uint8_t* out, uint32_t nBits);
void encode(const unsigned char* in, unsigned char* out, unsigned int nBits) const; void encode(const uint8_t* in, uint8_t* out, uint32_t nBits) const;
private: private:
uint16_t* m_metrics1; uint16_t* m_metrics1;

@ -26,12 +26,12 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
const unsigned char BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U}; const uint8_t BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U};
#define WRITE_BIT1(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7]) #define WRITE_BIT1(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7])
#define READ_BIT1(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7]) #define READ_BIT1(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7])
const unsigned int INTERLEAVE_TABLE[] = { const uint32_t INTERLEAVE_TABLE[] = {
0U, 40U, 80U, 120U, 160U, 0U, 40U, 80U, 120U, 160U,
2U, 42U, 82U, 122U, 162U, 2U, 42U, 82U, 122U, 162U,
4U, 44U, 84U, 124U, 164U, 4U, 44U, 84U, 124U, 164U,
@ -53,7 +53,7 @@ const unsigned int INTERLEAVE_TABLE[] = {
36U, 76U, 116U, 156U, 196U, 36U, 76U, 116U, 156U, 196U,
38U, 78U, 118U, 158U, 198U}; 38U, 78U, 118U, 158U, 198U};
const unsigned int YSF_SYNC_LENGTH_BYTES = 5U; const uint32_t YSF_SYNC_LENGTH_BYTES = 5U;
CYSFFICH::CYSFFICH() CYSFFICH::CYSFFICH()
//m_fich(NULL) //m_fich(NULL)
@ -71,7 +71,7 @@ CYSFFICH::~CYSFFICH()
//delete[] m_fich; //delete[] m_fich;
} }
bool CYSFFICH::decode(const unsigned char* bytes) bool CYSFFICH::decode(const uint8_t* bytes)
{ {
assert(bytes != NULL); assert(bytes != NULL);
@ -82,8 +82,8 @@ bool CYSFFICH::decode(const unsigned char* bytes)
viterbi.start(); viterbi.start();
// Deinterleave the FICH and send bits to the Viterbi decoder // Deinterleave the FICH and send bits to the Viterbi decoder
for (unsigned int i = 0U; i < 100U; i++) { for (uint32_t i = 0U; i < 100U; i++) {
unsigned int n = INTERLEAVE_TABLE[i]; uint32_t n = INTERLEAVE_TABLE[i];
uint8_t s0 = READ_BIT1(bytes, n) ? 1U : 0U; uint8_t s0 = READ_BIT1(bytes, n) ? 1U : 0U;
n++; n++;
@ -92,13 +92,13 @@ bool CYSFFICH::decode(const unsigned char* bytes)
viterbi.decode(s0, s1); viterbi.decode(s0, s1);
} }
unsigned char output[13U]; uint8_t output[13U];
viterbi.chainback(output, 96U); viterbi.chainback(output, 96U);
unsigned int b0 = CGolay24128::decode24128(output + 0U); uint32_t b0 = CGolay24128::decode24128(output + 0U);
unsigned int b1 = CGolay24128::decode24128(output + 3U); uint32_t b1 = CGolay24128::decode24128(output + 3U);
unsigned int b2 = CGolay24128::decode24128(output + 6U); uint32_t b2 = CGolay24128::decode24128(output + 6U);
unsigned int b3 = CGolay24128::decode24128(output + 9U); uint32_t b3 = CGolay24128::decode24128(output + 9U);
m_fich[0U] = (b0 >> 4) & 0xFFU; m_fich[0U] = (b0 >> 4) & 0xFFU;
m_fich[1U] = ((b0 << 4) & 0xF0U) | ((b1 >> 8) & 0x0FU); m_fich[1U] = ((b0 << 4) & 0xF0U) | ((b1 >> 8) & 0x0FU);
@ -110,7 +110,7 @@ bool CYSFFICH::decode(const unsigned char* bytes)
return CCRC::checkCCITT162(m_fich, 6U); return CCRC::checkCCITT162(m_fich, 6U);
} }
void CYSFFICH::encode(unsigned char* bytes) void CYSFFICH::encode(uint8_t* bytes)
{ {
assert(bytes != NULL); assert(bytes != NULL);
@ -119,17 +119,17 @@ void CYSFFICH::encode(unsigned char* bytes)
CCRC::addCCITT162(m_fich, 6U); CCRC::addCCITT162(m_fich, 6U);
unsigned int b0 = ((m_fich[0U] << 4) & 0xFF0U) | ((m_fich[1U] >> 4) & 0x00FU); uint32_t b0 = ((m_fich[0U] << 4) & 0xFF0U) | ((m_fich[1U] >> 4) & 0x00FU);
unsigned int b1 = ((m_fich[1U] << 8) & 0xF00U) | ((m_fich[2U] >> 0) & 0x0FFU); uint32_t b1 = ((m_fich[1U] << 8) & 0xF00U) | ((m_fich[2U] >> 0) & 0x0FFU);
unsigned int b2 = ((m_fich[3U] << 4) & 0xFF0U) | ((m_fich[4U] >> 4) & 0x00FU); uint32_t b2 = ((m_fich[3U] << 4) & 0xFF0U) | ((m_fich[4U] >> 4) & 0x00FU);
unsigned int b3 = ((m_fich[4U] << 8) & 0xF00U) | ((m_fich[5U] >> 0) & 0x0FFU); uint32_t b3 = ((m_fich[4U] << 8) & 0xF00U) | ((m_fich[5U] >> 0) & 0x0FFU);
unsigned int c0 = CGolay24128::encode24128(b0); uint32_t c0 = CGolay24128::encode24128(b0);
unsigned int c1 = CGolay24128::encode24128(b1); uint32_t c1 = CGolay24128::encode24128(b1);
unsigned int c2 = CGolay24128::encode24128(b2); uint32_t c2 = CGolay24128::encode24128(b2);
unsigned int c3 = CGolay24128::encode24128(b3); uint32_t c3 = CGolay24128::encode24128(b3);
unsigned char conv[13U]; uint8_t conv[13U];
conv[0U] = (c0 >> 16) & 0xFFU; conv[0U] = (c0 >> 16) & 0xFFU;
conv[1U] = (c0 >> 8) & 0xFFU; conv[1U] = (c0 >> 8) & 0xFFU;
conv[2U] = (c0 >> 0) & 0xFFU; conv[2U] = (c0 >> 0) & 0xFFU;
@ -145,12 +145,12 @@ void CYSFFICH::encode(unsigned char* bytes)
conv[12U] = 0x00U; conv[12U] = 0x00U;
CYSFConvolution convolution; CYSFConvolution convolution;
unsigned char convolved[25U]; uint8_t convolved[25U];
convolution.encode(conv, convolved, 100U); convolution.encode(conv, convolved, 100U);
unsigned int j = 0U; uint32_t j = 0U;
for (unsigned int i = 0U; i < 100U; i++) { for (uint32_t i = 0U; i < 100U; i++) {
unsigned int n = INTERLEAVE_TABLE[i]; uint32_t n = INTERLEAVE_TABLE[i];
bool s0 = READ_BIT1(convolved, j) != 0U; bool s0 = READ_BIT1(convolved, j) != 0U;
j++; j++;
@ -165,47 +165,47 @@ void CYSFFICH::encode(unsigned char* bytes)
} }
} }
unsigned char CYSFFICH::getFI() const uint8_t CYSFFICH::getFI() const
{ {
return (m_fich[0U] >> 6) & 0x03U; return (m_fich[0U] >> 6) & 0x03U;
} }
unsigned char CYSFFICH::getCS() const uint8_t CYSFFICH::getCS() const
{ {
return (m_fich[0U] >> 4) & 0x03U; return (m_fich[0U] >> 4) & 0x03U;
} }
unsigned char CYSFFICH::getCM() const uint8_t CYSFFICH::getCM() const
{ {
return (m_fich[0U] >> 2) & 0x03U; return (m_fich[0U] >> 2) & 0x03U;
} }
unsigned char CYSFFICH::getBN() const uint8_t CYSFFICH::getBN() const
{ {
return m_fich[0U] & 0x03U; return m_fich[0U] & 0x03U;
} }
unsigned char CYSFFICH::getBT() const uint8_t CYSFFICH::getBT() const
{ {
return (m_fich[1U] >> 6) & 0x03U; return (m_fich[1U] >> 6) & 0x03U;
} }
unsigned char CYSFFICH::getFN() const uint8_t CYSFFICH::getFN() const
{ {
return (m_fich[1U] >> 3) & 0x07U; return (m_fich[1U] >> 3) & 0x07U;
} }
unsigned char CYSFFICH::getFT() const uint8_t CYSFFICH::getFT() const
{ {
return m_fich[1U] & 0x07U; return m_fich[1U] & 0x07U;
} }
unsigned char CYSFFICH::getDT() const uint8_t CYSFFICH::getDT() const
{ {
return m_fich[2U] & 0x03U; return m_fich[2U] & 0x03U;
} }
unsigned char CYSFFICH::getMR() const uint8_t CYSFFICH::getMR() const
{ {
return (m_fich[2U] >> 3) & 0x03U; return (m_fich[2U] >> 3) & 0x03U;
} }
@ -225,42 +225,42 @@ bool CYSFFICH::getSQL() const
return (m_fich[3U] & 0x80U) == 0x80U; return (m_fich[3U] & 0x80U) == 0x80U;
} }
unsigned char CYSFFICH::getSQ() const uint8_t CYSFFICH::getSQ() const
{ {
return m_fich[3U] & 0x7FU; return m_fich[3U] & 0x7FU;
} }
void CYSFFICH::setFI(unsigned char fi) void CYSFFICH::setFI(uint8_t fi)
{ {
m_fich[0U] &= 0x3FU; m_fich[0U] &= 0x3FU;
m_fich[0U] |= (fi << 6) & 0xC0U; m_fich[0U] |= (fi << 6) & 0xC0U;
} }
void CYSFFICH::setCS(unsigned char cs) void CYSFFICH::setCS(uint8_t cs)
{ {
m_fich[0U] &= 0xCFU; m_fich[0U] &= 0xCFU;
m_fich[0U] |= (cs << 4) & 0x30U; m_fich[0U] |= (cs << 4) & 0x30U;
} }
void CYSFFICH::setCM(unsigned char cm) void CYSFFICH::setCM(uint8_t cm)
{ {
m_fich[0U] &= 0xF3U; m_fich[0U] &= 0xF3U;
m_fich[0U] |= (cm << 2) & 0x0CU; m_fich[0U] |= (cm << 2) & 0x0CU;
} }
void CYSFFICH::setFN(unsigned char fn) void CYSFFICH::setFN(uint8_t fn)
{ {
m_fich[1U] &= 0xC7U; m_fich[1U] &= 0xC7U;
m_fich[1U] |= (fn << 3) & 0x38U; m_fich[1U] |= (fn << 3) & 0x38U;
} }
void CYSFFICH::setFT(unsigned char ft) void CYSFFICH::setFT(uint8_t ft)
{ {
m_fich[1U] &= 0xF8U; m_fich[1U] &= 0xF8U;
m_fich[1U] |= ft & 0x07U; m_fich[1U] |= ft & 0x07U;
} }
void CYSFFICH::setMR(unsigned char mr) void CYSFFICH::setMR(uint8_t mr)
{ {
m_fich[2U] &= 0xC7U; m_fich[2U] &= 0xC7U;
m_fich[2U] |= (mr << 3) & 0x38U; m_fich[2U] |= (mr << 3) & 0x38U;
@ -282,7 +282,7 @@ void CYSFFICH::setDev(bool on)
m_fich[2U] &= 0xBFU; m_fich[2U] &= 0xBFU;
} }
void CYSFFICH::setDT(unsigned char dt) void CYSFFICH::setDT(uint8_t dt)
{ {
m_fich[2U] &= 0xFCU; m_fich[2U] &= 0xFCU;
m_fich[2U] |= dt & 0x03U; m_fich[2U] |= dt & 0x03U;
@ -296,25 +296,25 @@ void CYSFFICH::setSQL(bool on)
m_fich[3U] &= 0x7FU; m_fich[3U] &= 0x7FU;
} }
void CYSFFICH::setSQ(unsigned char sq) void CYSFFICH::setSQ(uint8_t sq)
{ {
m_fich[3U] &= 0x80U; m_fich[3U] &= 0x80U;
m_fich[3U] |= sq & 0x7FU; m_fich[3U] |= sq & 0x7FU;
} }
void CYSFFICH::setBN(unsigned char bn) void CYSFFICH::setBN(uint8_t bn)
{ {
m_fich[0U] &= 0xFCU; m_fich[0U] &= 0xFCU;
m_fich[0U] |= bn & 0x03U; m_fich[0U] |= bn & 0x03U;
} }
void CYSFFICH::setBT(unsigned char bt) void CYSFFICH::setBT(uint8_t bt)
{ {
m_fich[1U] &= 0x3FU; m_fich[1U] &= 0x3FU;
m_fich[1U] |= (bt << 6) & 0xC0U; m_fich[1U] |= (bt << 6) & 0xC0U;
} }
void CYSFFICH::load(const unsigned char* fich) void CYSFFICH::load(const uint8_t* fich)
{ {
assert(fich != NULL); assert(fich != NULL);

@ -19,49 +19,50 @@
#if !defined(YSFFICH_H) #if !defined(YSFFICH_H)
#define YSFFICH_H #define YSFFICH_H
#include <cstdint>
class CYSFFICH { class CYSFFICH {
public: public:
CYSFFICH(); CYSFFICH();
~CYSFFICH(); ~CYSFFICH();
bool decode(const unsigned char* bytes); bool decode(const uint8_t* bytes);
void encode(unsigned char* bytes); void encode(uint8_t* bytes);
unsigned char getFI() const; uint8_t getFI() const;
unsigned char getCS() const; uint8_t getCS() const;
unsigned char getCM() const; uint8_t getCM() const;
unsigned char getBN() const; uint8_t getBN() const;
unsigned char getBT() const; uint8_t getBT() const;
unsigned char getFN() const; uint8_t getFN() const;
unsigned char getFT() const; uint8_t getFT() const;
unsigned char getDT() const; uint8_t getDT() const;
unsigned char getMR() const; uint8_t getMR() const;
bool getVoIP() const; bool getVoIP() const;
bool getDev() const; bool getDev() const;
bool getSQL() const; bool getSQL() const;
unsigned char getSQ() const; uint8_t getSQ() const;
void setFI(unsigned char fi); void setFI(uint8_t fi);
void setCS(unsigned char cs); void setCS(uint8_t cs);
void setCM(unsigned char cm); void setCM(uint8_t cm);
void setFN(unsigned char fn); void setFN(uint8_t fn);
void setFT(unsigned char ft); void setFT(uint8_t ft);
void setBN(unsigned char bn); void setBN(uint8_t bn);
void setBT(unsigned char bt); void setBT(uint8_t bt);
void setDT(unsigned char dt); void setDT(uint8_t dt);
void setMR(unsigned char mr); void setMR(uint8_t mr);
void setVoIP(bool set); void setVoIP(bool set);
void setDev(bool set); void setDev(bool set);
void setSQL(bool set); void setSQL(bool set);
void setSQ(unsigned char sq); void setSQ(uint8_t sq);
void load(const unsigned char* fich); void load(const uint8_t* fich);
private: private:
unsigned char m_fich[6U]; uint8_t m_fich[6U];
//m_fich = new unsigned char[6U]; //m_fich = new uint8_t[6U];
}; };
#endif #endif

@ -157,6 +157,7 @@ void AudioEngine::start_capture()
m_audioinq.clear(); m_audioinq.clear();
if(m_in != nullptr){ if(m_in != nullptr){
m_indev = m_in->start(); m_indev = m_in->start();
if(MACHAK) m_srm = (float)(m_in->format().sampleRate()) / 8000.0;
connect(m_indev, SIGNAL(readyRead()), SLOT(input_data_received())); connect(m_indev, SIGNAL(readyRead()), SLOT(input_data_received()));
} }
} }
@ -192,7 +193,7 @@ void AudioEngine::input_data_received()
/* /*
fprintf(stderr, "AUDIOIN: "); fprintf(stderr, "AUDIOIN: ");
for(int i = 0; i < len; ++i){ for(int i = 0; i < len; ++i){
fprintf(stderr, "%02x ", (unsigned char)data.data()[i]); fprintf(stderr, "%02x ", (uint8_t)data.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);

@ -18,7 +18,7 @@
#if !defined(BPTC19696_H) #if !defined(BPTC19696_H)
#define BPTC19696_H #define BPTC19696_H
#include <cinttypes> #include <cstdint>
class CBPTC19696 class CBPTC19696
{ {

@ -21,7 +21,7 @@
#include <cstdio> #include <cstdio>
#include <cassert> #include <cassert>
const unsigned int ENCODING_TABLE_2087[] = const uint32_t ENCODING_TABLE_2087[] =
{0x0000U, 0xB08EU, 0xE093U, 0x501DU, 0x70A9U, 0xC027U, 0x903AU, 0x20B4U, 0x60DCU, 0xD052U, 0x804FU, 0x30C1U, {0x0000U, 0xB08EU, 0xE093U, 0x501DU, 0x70A9U, 0xC027U, 0x903AU, 0x20B4U, 0x60DCU, 0xD052U, 0x804FU, 0x30C1U,
0x1075U, 0xA0FBU, 0xF0E6U, 0x4068U, 0x7036U, 0xC0B8U, 0x90A5U, 0x202BU, 0x009FU, 0xB011U, 0xE00CU, 0x5082U, 0x1075U, 0xA0FBU, 0xF0E6U, 0x4068U, 0x7036U, 0xC0B8U, 0x90A5U, 0x202BU, 0x009FU, 0xB011U, 0xE00CU, 0x5082U,
0x10EAU, 0xA064U, 0xF079U, 0x40F7U, 0x6043U, 0xD0CDU, 0x80D0U, 0x305EU, 0xD06CU, 0x60E2U, 0x30FFU, 0x8071U, 0x10EAU, 0xA064U, 0xF079U, 0x40F7U, 0x6043U, 0xD0CDU, 0x80D0U, 0x305EU, 0xD06CU, 0x60E2U, 0x30FFU, 0x8071U,
@ -45,7 +45,7 @@ const unsigned int ENCODING_TABLE_2087[] =
0x90BEU, 0x2030U, 0x702DU, 0xC0A3U, 0xE017U, 0x5099U, 0x0084U, 0xB00AU, 0xF062U, 0x40ECU, 0x10F1U, 0xA07FU, 0x90BEU, 0x2030U, 0x702DU, 0xC0A3U, 0xE017U, 0x5099U, 0x0084U, 0xB00AU, 0xF062U, 0x40ECU, 0x10F1U, 0xA07FU,
0x80CBU, 0x3045U, 0x6058U, 0xD0D6U}; 0x80CBU, 0x3045U, 0x6058U, 0xD0D6U};
const unsigned int DECODING_TABLE_1987[] = const uint32_t DECODING_TABLE_1987[] =
{0x00000U, 0x00001U, 0x00002U, 0x00003U, 0x00004U, 0x00005U, 0x00006U, 0x00007U, 0x00008U, 0x00009U, 0x0000AU, 0x0000BU, 0x0000CU, {0x00000U, 0x00001U, 0x00002U, 0x00003U, 0x00004U, 0x00005U, 0x00006U, 0x00007U, 0x00008U, 0x00009U, 0x0000AU, 0x0000BU, 0x0000CU,
0x0000DU, 0x0000EU, 0x24020U, 0x00010U, 0x00011U, 0x00012U, 0x00013U, 0x00014U, 0x00015U, 0x00016U, 0x00017U, 0x00018U, 0x00019U, 0x0000DU, 0x0000EU, 0x24020U, 0x00010U, 0x00011U, 0x00012U, 0x00013U, 0x00014U, 0x00015U, 0x00016U, 0x00017U, 0x00018U, 0x00019U,
0x0001AU, 0x0001BU, 0x0001CU, 0x0001DU, 0x48040U, 0x01480U, 0x00020U, 0x00021U, 0x00022U, 0x00023U, 0x00024U, 0x00025U, 0x00026U, 0x0001AU, 0x0001BU, 0x0001CU, 0x0001DU, 0x48040U, 0x01480U, 0x00020U, 0x00021U, 0x00022U, 0x00023U, 0x00024U, 0x00025U, 0x00026U,
@ -210,7 +210,7 @@ const unsigned int DECODING_TABLE_1987[] =
#define MASK8 0xfffff800 /* auxiliary vector for testing */ #define MASK8 0xfffff800 /* auxiliary vector for testing */
#define GENPOL 0x00000c75 /* generator polinomial, g(x) */ #define GENPOL 0x00000c75 /* generator polinomial, g(x) */
unsigned int CGolay2087::getSyndrome1987(unsigned int pattern) uint32_t CGolay2087::getSyndrome1987(uint32_t pattern)
/* /*
* Compute the syndrome corresponding to the given pattern, i.e., the * Compute the syndrome corresponding to the given pattern, i.e., the
* remainder after dividing the pattern (when considering it as the vector * remainder after dividing the pattern (when considering it as the vector
@ -221,7 +221,7 @@ unsigned int CGolay2087::getSyndrome1987(unsigned int pattern)
* obtain its syndrome in decoding. * obtain its syndrome in decoding.
*/ */
{ {
unsigned int aux = X18; uint32_t aux = X18;
if (pattern >= X11) { if (pattern >= X11) {
while (pattern & MASK8) { while (pattern & MASK8) {
@ -235,13 +235,13 @@ unsigned int CGolay2087::getSyndrome1987(unsigned int pattern)
return pattern; return pattern;
} }
unsigned char CGolay2087::decode(const unsigned char* data) uint8_t CGolay2087::decode(const uint8_t* data)
{ {
assert(data != NULL); assert(data != NULL);
unsigned int code = (data[0U] << 11) + (data[1U] << 3) + (data[2U] >> 5); uint32_t code = (data[0U] << 11) + (data[1U] << 3) + (data[2U] >> 5);
unsigned int syndrome = getSyndrome1987(code); uint32_t syndrome = getSyndrome1987(code);
unsigned int error_pattern = DECODING_TABLE_1987[syndrome]; uint32_t error_pattern = DECODING_TABLE_1987[syndrome];
if (error_pattern != 0x00U) if (error_pattern != 0x00U)
code ^= error_pattern; code ^= error_pattern;
@ -249,13 +249,13 @@ unsigned char CGolay2087::decode(const unsigned char* data)
return code >> 11; return code >> 11;
} }
void CGolay2087::encode(unsigned char* data) void CGolay2087::encode(uint8_t* data)
{ {
assert(data != NULL); assert(data != NULL);
unsigned int value = data[0U]; uint32_t value = data[0U];
unsigned int cksum = ENCODING_TABLE_2087[value]; uint32_t cksum = ENCODING_TABLE_2087[value];
data[1U] = cksum & 0xFFU; data[1U] = cksum & 0xFFU;
data[2U] = cksum >> 8; data[2U] = cksum >> 8;

@ -18,15 +18,16 @@
#ifndef Golay2087_H #ifndef Golay2087_H
#define Golay2087_H #define Golay2087_H
#include <cstdint>
class CGolay2087 { class CGolay2087 {
public: public:
static void encode(unsigned char* data); static void encode(uint8_t * data);
static unsigned char decode(const unsigned char* data); static uint8_t decode(const uint8_t* data);
private: private:
static unsigned int getSyndrome1987(unsigned int pattern); static uint32_t getSyndrome1987(uint32_t pattern);
}; };
#endif #endif

@ -22,15 +22,15 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
const unsigned int NPAR = 3U; const uint32_t NPAR = 3U;
/* Maximum degree of various polynomials. */ /* Maximum degree of various polynomials. */
//const unsigned int MAXDEG = NPAR * 2U; //const uint32_t MAXDEG = NPAR * 2U;
/* Generator Polynomial */ /* Generator Polynomial */
const unsigned char POLY[] = {64U, 56U, 14U, 1U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U}; const uint8_t POLY[] = {64U, 56U, 14U, 1U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U};
const unsigned char EXP_TABLE[] = { const uint8_t EXP_TABLE[] = {
0x01U, 0x02U, 0x04U, 0x08U, 0x10U, 0x20U, 0x40U, 0x80U, 0x1DU, 0x3AU, 0x74U, 0xE8U, 0xCDU, 0x87U, 0x13U, 0x26U, 0x01U, 0x02U, 0x04U, 0x08U, 0x10U, 0x20U, 0x40U, 0x80U, 0x1DU, 0x3AU, 0x74U, 0xE8U, 0xCDU, 0x87U, 0x13U, 0x26U,
0x4CU, 0x98U, 0x2DU, 0x5AU, 0xB4U, 0x75U, 0xEAU, 0xC9U, 0x8FU, 0x03U, 0x06U, 0x0CU, 0x18U, 0x30U, 0x60U, 0xC0U, 0x4CU, 0x98U, 0x2DU, 0x5AU, 0xB4U, 0x75U, 0xEAU, 0xC9U, 0x8FU, 0x03U, 0x06U, 0x0CU, 0x18U, 0x30U, 0x60U, 0xC0U,
0x9DU, 0x27U, 0x4EU, 0x9CU, 0x25U, 0x4AU, 0x94U, 0x35U, 0x6AU, 0xD4U, 0xB5U, 0x77U, 0xEEU, 0xC1U, 0x9FU, 0x23U, 0x9DU, 0x27U, 0x4EU, 0x9CU, 0x25U, 0x4AU, 0x94U, 0x35U, 0x6AU, 0xD4U, 0xB5U, 0x77U, 0xEEU, 0xC1U, 0x9FU, 0x23U,
@ -64,7 +64,7 @@ const unsigned char EXP_TABLE[] = {
0x24U, 0x48U, 0x90U, 0x3DU, 0x7AU, 0xF4U, 0xF5U, 0xF7U, 0xF3U, 0xFBU, 0xEBU, 0xCBU, 0x8BU, 0x0BU, 0x16U, 0x2CU, 0x24U, 0x48U, 0x90U, 0x3DU, 0x7AU, 0xF4U, 0xF5U, 0xF7U, 0xF3U, 0xFBU, 0xEBU, 0xCBU, 0x8BU, 0x0BU, 0x16U, 0x2CU,
0x58U, 0xB0U, 0x7DU, 0xFAU, 0xE9U, 0xCFU, 0x83U, 0x1BU, 0x36U, 0x6CU, 0xD8U, 0xADU, 0x47U, 0x8EU, 0x01U, 0x00U}; 0x58U, 0xB0U, 0x7DU, 0xFAU, 0xE9U, 0xCFU, 0x83U, 0x1BU, 0x36U, 0x6CU, 0xD8U, 0xADU, 0x47U, 0x8EU, 0x01U, 0x00U};
const unsigned char LOG_TABLE[] = { const uint8_t LOG_TABLE[] = {
0x00U, 0x00U, 0x01U, 0x19U, 0x02U, 0x32U, 0x1AU, 0xC6U, 0x03U, 0xDFU, 0x33U, 0xEEU, 0x1BU, 0x68U, 0xC7U, 0x4BU, 0x00U, 0x00U, 0x01U, 0x19U, 0x02U, 0x32U, 0x1AU, 0xC6U, 0x03U, 0xDFU, 0x33U, 0xEEU, 0x1BU, 0x68U, 0xC7U, 0x4BU,
0x04U, 0x64U, 0xE0U, 0x0EU, 0x34U, 0x8DU, 0xEFU, 0x81U, 0x1CU, 0xC1U, 0x69U, 0xF8U, 0xC8U, 0x08U, 0x4CU, 0x71U, 0x04U, 0x64U, 0xE0U, 0x0EU, 0x34U, 0x8DU, 0xEFU, 0x81U, 0x1CU, 0xC1U, 0x69U, 0xF8U, 0xC8U, 0x08U, 0x4CU, 0x71U,
0x05U, 0x8AU, 0x65U, 0x2FU, 0xE1U, 0x24U, 0x0FU, 0x21U, 0x35U, 0x93U, 0x8EU, 0xDAU, 0xF0U, 0x12U, 0x82U, 0x45U, 0x05U, 0x8AU, 0x65U, 0x2FU, 0xE1U, 0x24U, 0x0FU, 0x21U, 0x35U, 0x93U, 0x8EU, 0xDAU, 0xF0U, 0x12U, 0x82U, 0x45U,
@ -83,13 +83,14 @@ const unsigned char LOG_TABLE[] = {
0x4FU, 0xAEU, 0xD5U, 0xE9U, 0xE6U, 0xE7U, 0xADU, 0xE8U, 0x74U, 0xD6U, 0xF4U, 0xEAU, 0xA8U, 0x50U, 0x58U, 0xAFU}; 0x4FU, 0xAEU, 0xD5U, 0xE9U, 0xE6U, 0xE7U, 0xADU, 0xE8U, 0x74U, 0xD6U, 0xF4U, 0xEAU, 0xA8U, 0x50U, 0x58U, 0xAFU};
/* multiplication using logarithms */ /* multiplication using logarithms */
static unsigned char gmult(unsigned char a, unsigned char b) static uint8_t gmult(uint8_t a, uint8_t b)
{ {
if (a == 0U || b == 0U) if (a == 0U || b == 0U){
return 0U; return 0U;
}
unsigned int i = LOG_TABLE[a]; uint32_t i = LOG_TABLE[a];
unsigned int j = LOG_TABLE[b]; uint32_t j = LOG_TABLE[b];
return EXP_TABLE[i + j]; return EXP_TABLE[i + j];
} }
@ -99,16 +100,16 @@ static unsigned char gmult(unsigned char a, unsigned char b)
* *
* The parity bytes are deposited into parity. * The parity bytes are deposited into parity.
*/ */
void CRS129::encode(const unsigned char* msg, unsigned int nbytes, unsigned char* parity) void CRS129::encode(const uint8_t* msg, uint32_t nbytes, uint8_t* parity)
{ {
assert(msg != NULL); assert(msg != NULL);
assert(parity != NULL); assert(parity != NULL);
for (unsigned int i = 0U; i < NPAR + 1U; i++) for (uint32_t i = 0U; i < NPAR + 1U; i++)
parity[i] = 0x00U; parity[i] = 0x00U;
for (unsigned int i = 0U; i < nbytes; i++) { for (uint32_t i = 0U; i < nbytes; i++) {
unsigned char dbyte = msg[i] ^ parity[NPAR - 1U]; uint8_t dbyte = msg[i] ^ parity[NPAR - 1U];
for (int j = NPAR - 1; j > 0; j--) for (int j = NPAR - 1; j > 0; j--)
parity[j] = parity[j - 1] ^ ::gmult(POLY[j], dbyte); parity[j] = parity[j - 1] ^ ::gmult(POLY[j], dbyte);
@ -118,11 +119,11 @@ void CRS129::encode(const unsigned char* msg, unsigned int nbytes, unsigned char
} }
// Reed-Solomon (12,9) check // Reed-Solomon (12,9) check
bool CRS129::check(const unsigned char* in) bool CRS129::check(const uint8_t* in)
{ {
assert(in != NULL); assert(in != NULL);
unsigned char parity[4U]; uint8_t parity[4U];
encode(in, 9U, parity); encode(in, 9U, parity);
return in[9U] == parity[2U] && in[10U] == parity[1U] && in[11U] == parity[0U]; return in[9U] == parity[2U] && in[10U] == parity[1U] && in[11U] == parity[0U];

@ -18,13 +18,13 @@
#if !defined(RS129_H) #if !defined(RS129_H)
#define RS129_H #define RS129_H
#include <cstdint>
class CRS129 class CRS129
{ {
public: public:
static bool check(const unsigned char* in); static bool check(const uint8_t* in);
static void encode(const uint8_t* msg, uint32_t nbytes, uint8_t* parity);
static void encode(const unsigned char* msg, unsigned int nbytes, unsigned char* parity);
}; };
#endif #endif

@ -26,7 +26,7 @@ class DCS : public Mode
public: public:
DCS(); DCS();
~DCS(); ~DCS();
unsigned char * get_frame(unsigned char *ambe); uint8_t * get_frame(uint8_t *ambe);
private: private:
QString m_txusrtxt; QString m_txusrtxt;
uint8_t packet_size; uint8_t packet_size;

@ -24,7 +24,7 @@
#include "CRCenc.h" #include "CRCenc.h"
#include "MMDVMDefines.h" #include "MMDVMDefines.h"
#define DEBUG //#define DEBUG
const uint32_t ENCODING_TABLE_1676[] = const uint32_t ENCODING_TABLE_1676[] =
{0x0000U, 0x0273U, 0x04E5U, 0x0696U, 0x09C9U, 0x0BBAU, 0x0D2CU, 0x0F5FU, 0x11E2U, 0x1391U, 0x1507U, 0x1774U, {0x0000U, 0x0273U, 0x04E5U, 0x0696U, 0x09C9U, 0x0BBAU, 0x0D2CU, 0x0F5FU, 0x11E2U, 0x1391U, 0x1507U, 0x1774U,
@ -88,7 +88,7 @@ void DMR::process_udp()
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "RECV: "); fprintf(stderr, "RECV: ");
for(int i = 0; i < buf.size(); ++i){ for(int i = 0; i < buf.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)buf.data()[i]); fprintf(stderr, "%02x ", (uint8_t)buf.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -119,7 +119,7 @@ void DMR::process_udp()
out[5] = (m_essid >> 16) & 0xff; out[5] = (m_essid >> 16) & 0xff;
out[6] = (m_essid >> 8) & 0xff; out[6] = (m_essid >> 8) & 0xff;
out[7] = (m_essid >> 0) & 0xff; out[7] = (m_essid >> 0) & 0xff;
sha256.buffer((unsigned char *)in.data(), (unsigned int)(m_password.size() + sizeof(uint32_t)), (unsigned char *)out.data() + 8U); sha256.buffer((uint8_t *)in.data(), (uint32_t)(m_password.size() + sizeof(uint32_t)), (uint8_t *)out.data() + 8U);
break; break;
case DMR_AUTH: case DMR_AUTH:
out.clear(); out.clear();
@ -284,7 +284,7 @@ void DMR::process_udp()
if(out.size() > 0){ if(out.size() > 0){
fprintf(stderr, "SEND: "); fprintf(stderr, "SEND: ");
for(int i = 0; i < out.size(); ++i){ for(int i = 0; i < out.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)out.data()[i]); fprintf(stderr, "%02x ", (uint8_t)out.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -352,7 +352,7 @@ void DMR::hostname_lookup(QHostInfo i)
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "CONN: "); fprintf(stderr, "CONN: ");
for(int i = 0; i < out.size(); ++i){ for(int i = 0; i < out.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)out.data()[i]); fprintf(stderr, "%02x ", (uint8_t)out.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -373,7 +373,7 @@ void DMR::send_ping()
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "PING: "); fprintf(stderr, "PING: ");
for(int i = 0; i < out.size(); ++i){ for(int i = 0; i < out.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)out.data()[i]); fprintf(stderr, "%02x ", (uint8_t)out.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -396,7 +396,7 @@ void DMR::send_disconnect()
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "SEND: "); fprintf(stderr, "SEND: ");
for(int i = 0; i < out.size(); ++i){ for(int i = 0; i < out.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)out.data()[i]); fprintf(stderr, "%02x ", (uint8_t)out.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -440,7 +440,7 @@ void DMR::process_modem_data(QByteArray d)
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "SEND:%d: ", txdata.size()); fprintf(stderr, "SEND:%d: ", txdata.size());
for(int i = 0; i < txdata.size(); ++i){ for(int i = 0; i < txdata.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)txdata.data()[i]); fprintf(stderr, "%02x ", (uint8_t)txdata.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -560,14 +560,14 @@ void DMR::send_frame()
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "SEND:%d: ", txdata.size()); fprintf(stderr, "SEND:%d: ", txdata.size());
for(int i = 0; i < txdata.size(); ++i){ for(int i = 0; i < txdata.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)txdata.data()[i]); fprintf(stderr, "%02x ", (uint8_t)txdata.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
#endif #endif
} }
unsigned char * DMR::get_eot() uint8_t * DMR::get_eot()
{ {
encode_header(DT_TERMINATOR_WITH_LC); encode_header(DT_TERMINATOR_WITH_LC);
m_dmrcnt = 0; m_dmrcnt = 0;
@ -625,7 +625,7 @@ void DMR::encode_header(uint8_t t)
void DMR::encode_data() void DMR::encode_data()
{ {
unsigned int n_dmr = (m_dmrcnt - 1) % 6U; uint32_t n_dmr = (m_dmrcnt - 1) % 6U;
if (!n_dmr) { if (!n_dmr) {
m_dataType = DT_VOICE_SYNC; m_dataType = DT_VOICE_SYNC;

@ -333,9 +333,6 @@ void DroidStar::process_connect()
m_modethread = new QThread; m_modethread = new QThread;
m_mode->moveToThread(m_modethread); m_mode->moveToThread(m_modethread);
m_mode->init(m_callsign, m_dmrid, m_module, m_refname, m_host, m_port, m_ipv6, vocoder, modem, m_capture, m_playback); m_mode->init(m_callsign, m_dmrid, m_module, m_refname, m_host, m_port, m_ipv6, vocoder, modem, m_capture, m_playback);
if(m_protocol == "DMR"){
}
m_mode->set_modem_flags(rxInvert, txInvert, pttInvert, useCOSAsLockout, duplex); m_mode->set_modem_flags(rxInvert, txInvert, pttInvert, useCOSAsLockout, duplex);
m_mode->set_modem_params(m_modemBaud.toUInt(), rxfreq, txfreq, m_modemTxDelay.toInt(), m_modemRxLevel.toFloat(), m_modemRFLevel.toFloat(), ysfTXHang, m_modemCWIdTxLevel.toFloat(), m_modemDstarTxLevel.toFloat(), m_modemDMRTxLevel.toFloat(), m_modemYSFTxLevel.toFloat(), m_modemP25TxLevel.toFloat(), m_modemNXDNTxLevel.toFloat(), pocsagTXLevel, m17TXLevel); m_mode->set_modem_params(m_modemBaud.toUInt(), rxfreq, txfreq, m_modemTxDelay.toInt(), m_modemRxLevel.toFloat(), m_modemRFLevel.toFloat(), ysfTXHang, m_modemCWIdTxLevel.toFloat(), m_modemDstarTxLevel.toFloat(), m_modemDMRTxLevel.toFloat(), m_modemYSFTxLevel.toFloat(), m_modemP25TxLevel.toFloat(), m_modemNXDNTxLevel.toFloat(), pocsagTXLevel, m17TXLevel);
@ -357,6 +354,12 @@ void DroidStar::process_connect()
connect(this, SIGNAL(rptr1_changed(QString)), m_mode, SLOT(rptr1_changed(QString))); connect(this, SIGNAL(rptr1_changed(QString)), m_mode, SLOT(rptr1_changed(QString)));
connect(this, SIGNAL(rptr2_changed(QString)), m_mode, SLOT(rptr2_changed(QString))); connect(this, SIGNAL(rptr2_changed(QString)), m_mode, SLOT(rptr2_changed(QString)));
connect(this, SIGNAL(usrtxt_changed(QString)), m_mode, SLOT(usrtxt_changed(QString))); connect(this, SIGNAL(usrtxt_changed(QString)), m_mode, SLOT(usrtxt_changed(QString)));
emit module_changed(m_module);
emit mycall_changed(m_mycall);
emit urcall_changed(m_urcall);
emit rptr1_changed(m_rptr1);
emit rptr2_changed(m_rptr2);
emit usrtxt_changed(m_dstarusertxt);
if(m_protocol == "DMR"){ if(m_protocol == "DMR"){
QString dmrpass = sl.at(2).simplified(); QString dmrpass = sl.at(2).simplified();

@ -330,7 +330,7 @@ private:
int m_iaxport; int m_iaxport;
bool m_settings_processed; bool m_settings_processed;
bool m_modelchange; bool m_modelchange;
const unsigned char header[5] = {0x80,0x44,0x53,0x56,0x54}; //DVSI packet header const uint8_t header[5] = {0x80,0x44,0x53,0x56,0x54}; //DVSI packet header
uint16_t m_outlevel; uint16_t m_outlevel;
QString m_errortxt; QString m_errortxt;
bool m_xrf2ref; bool m_xrf2ref;

@ -22,7 +22,7 @@
#else #else
#include <arpa/inet.h> #include <arpa/inet.h>
#endif #endif
#define DEBUG //#define DEBUG
#ifdef USE_FLITE #ifdef USE_FLITE
extern "C" { extern "C" {

@ -26,7 +26,7 @@
#define M17CHARACTERS " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-/." #define M17CHARACTERS " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-/."
#define DEBUG //#define DEBUG
const uint8_t SCRAMBLER[] = { const uint8_t SCRAMBLER[] = {
0x00U, 0x00U, 0xD6U, 0xB5U, 0xE2U, 0x30U, 0x82U, 0xFFU, 0x84U, 0x62U, 0xBAU, 0x4EU, 0x96U, 0x90U, 0xD8U, 0x98U, 0xDDU, 0x00U, 0x00U, 0xD6U, 0xB5U, 0xE2U, 0x30U, 0x82U, 0xFFU, 0x84U, 0x62U, 0xBAU, 0x4EU, 0x96U, 0x90U, 0xD8U, 0x98U, 0xDDU,
@ -1030,8 +1030,8 @@ void M17::combineFragmentLICH(uint32_t frag1, uint32_t frag2, uint32_t frag3, ui
{ {
assert(data != NULL); assert(data != NULL);
unsigned int offset = 0U; uint32_t offset = 0U;
unsigned int MASK = 0x800U; uint32_t MASK = 0x800U;
for (uint32_t i = 0U; i < (M17_LICH_FRAGMENT_LENGTH_BITS / 4U); i++, offset++, MASK >>= 1) { for (uint32_t i = 0U; i < (M17_LICH_FRAGMENT_LENGTH_BITS / 4U); i++, offset++, MASK >>= 1) {
bool b = (frag1 & MASK) == MASK; bool b = (frag1 & MASK) == MASK;
WRITE_BIT(data, offset, b); WRITE_BIT(data, offset, b);

@ -119,6 +119,7 @@ void Mode::init(QString callsign, uint32_t dmrid, char module, QString refname,
#else #else
m_rxtimerint = 20; m_rxtimerint = 20;
#endif #endif
m_txtimerint = 19;
#ifdef USE_FLITE #ifdef USE_FLITE
flite_init(); flite_init();
voice_slt = register_cmu_us_slt(nullptr); voice_slt = register_cmu_us_slt(nullptr);

@ -35,7 +35,7 @@ const uint8_t NXDN_LICH_DIRECTION_INBOUND = 0U;
const uint8_t NXDN_MESSAGE_TYPE_VCALL = 1U; const uint8_t NXDN_MESSAGE_TYPE_VCALL = 1U;
const uint8_t NXDN_MESSAGE_TYPE_TX_REL = 8U; const uint8_t NXDN_MESSAGE_TYPE_TX_REL = 8U;
const unsigned char BIT_MASK_TABLE[] = { 0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U }; const uint8_t BIT_MASK_TABLE[] = { 0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U };
#define WRITE_BIT1(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7]) #define WRITE_BIT1(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7])
#define READ_BIT1(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7]) #define READ_BIT1(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7])
@ -62,7 +62,7 @@ void NXDN::process_udp()
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "RECV: "); fprintf(stderr, "RECV: ");
for(int i = 0; i < buf.size(); ++i){ for(int i = 0; i < buf.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)buf.data()[i]); fprintf(stderr, "%02x ", (uint8_t)buf.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -227,7 +227,7 @@ void NXDN::hostname_lookup(QHostInfo i)
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "CONN: "); fprintf(stderr, "CONN: ");
for(int i = 0; i < out.size(); ++i){ for(int i = 0; i < out.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)out.data()[i]); fprintf(stderr, "%02x ", (uint8_t)out.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -251,7 +251,7 @@ void NXDN::send_ping()
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "PING: "); fprintf(stderr, "PING: ");
for(int i = 0; i < out.size(); ++i){ for(int i = 0; i < out.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)out.data()[i]); fprintf(stderr, "%02x ", (uint8_t)out.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -274,7 +274,7 @@ void NXDN::send_disconnect()
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "SEND: "); fprintf(stderr, "SEND: ");
for(int i = 0; i < out.size(); ++i){ for(int i = 0; i < out.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)out.data()[i]); fprintf(stderr, "%02x ", (uint8_t)out.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -339,7 +339,7 @@ void NXDN::transmit()
void NXDN::send_frame() void NXDN::send_frame()
{ {
QByteArray txdata; QByteArray txdata;
unsigned char *temp_nxdn; uint8_t *temp_nxdn;
if(m_tx){ if(m_tx){
m_modeinfo.stream_state = TRANSMITTING; m_modeinfo.stream_state = TRANSMITTING;
temp_nxdn = get_frame(); temp_nxdn = get_frame();
@ -348,7 +348,7 @@ void NXDN::send_frame()
fprintf(stderr, "SEND:%d: ", txdata.size()); fprintf(stderr, "SEND:%d: ", txdata.size());
for(int i = 0; i < txdata.size(); ++i){ for(int i = 0; i < txdata.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)txdata.data()[i]); fprintf(stderr, "%02x ", (uint8_t)txdata.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -522,7 +522,7 @@ void NXDN::deinterleave_ambe(uint8_t *d)
memcpy(d, ambe_data, 7); memcpy(d, ambe_data, 7);
} }
unsigned char NXDN::get_lich_fct(uint8_t lich) uint8_t NXDN::get_lich_fct(uint8_t lich)
{ {
return (lich >> 4) & 0x03U; return (lich >> 4) & 0x03U;
} }
@ -639,7 +639,7 @@ void NXDN::encode_crc6(uint8_t *d, uint8_t len)
{ {
uint8_t crc = 0x3FU; uint8_t crc = 0x3FU;
for (unsigned int i = 0U; i < len; i++) { for (uint32_t i = 0U; i < len; i++) {
bool bit1 = READ_BIT1(d, i) != 0x00U; bool bit1 = READ_BIT1(d, i) != 0x00U;
bool bit2 = (crc & 0x20U) == 0x20U; bool bit2 = (crc & 0x20U) == 0x20U;
crc <<= 1; crc <<= 1;

@ -27,8 +27,8 @@ class NXDN : public Mode
public: public:
NXDN(); NXDN();
~NXDN(); ~NXDN();
unsigned char * get_frame(); uint8_t * get_frame();
unsigned char * get_eot(){m_eot = true; return get_frame();} uint8_t * get_eot(){m_eot = true; return get_frame();}
void set_hwtx(bool hw){m_hwtx = hw;} void set_hwtx(bool hw){m_hwtx = hw;}
private slots: private slots:
void process_udp(); void process_udp();

@ -21,25 +21,25 @@
//#define DEBUG //#define DEBUG
const unsigned char REC62[] = {0x62U, 0x02U, 0x02U, 0x0CU, 0x0BU, 0x12U, 0x64U, 0x00U, 0x00U, 0x80U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,0x00U, 0x00U, 0x00U, 0x00U, 0x00U}; const uint8_t REC62[] = {0x62U, 0x02U, 0x02U, 0x0CU, 0x0BU, 0x12U, 0x64U, 0x00U, 0x00U, 0x80U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
const unsigned char REC63[] = {0x63U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U}; const uint8_t REC63[] = {0x63U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC64[] = {0x64U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U}; const uint8_t REC64[] = {0x64U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC65[] = {0x65U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U}; const uint8_t REC65[] = {0x65U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC66[] = {0x66U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U}; const uint8_t REC66[] = {0x66U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC67[] = {0x67U, 0xF0U, 0x9DU, 0x6AU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U}; const uint8_t REC67[] = {0x67U, 0xF0U, 0x9DU, 0x6AU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC68[] = {0x68U, 0x19U, 0xD4U, 0x26U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U}; const uint8_t REC68[] = {0x68U, 0x19U, 0xD4U, 0x26U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC69[] = {0x69U, 0xE0U, 0xEBU, 0x7BU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U}; const uint8_t REC69[] = {0x69U, 0xE0U, 0xEBU, 0x7BU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC6A[] = {0x6AU, 0x00U, 0x00U, 0x02U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U}; const uint8_t REC6A[] = {0x6AU, 0x00U, 0x00U, 0x02U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
const unsigned char REC6B[] = {0x6BU, 0x02U, 0x02U, 0x0CU, 0x0BU, 0x12U, 0x64U, 0x00U, 0x00U, 0x80U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,0x00U, 0x00U, 0x00U, 0x00U, 0x00U}; const uint8_t REC6B[] = {0x6BU, 0x02U, 0x02U, 0x0CU, 0x0BU, 0x12U, 0x64U, 0x00U, 0x00U, 0x80U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
const unsigned char REC6C[] = {0x6CU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U}; const uint8_t REC6C[] = {0x6CU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC6D[] = {0x6DU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U}; const uint8_t REC6D[] = {0x6DU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC6E[] = {0x6EU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U}; const uint8_t REC6E[] = {0x6EU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC6F[] = {0x6FU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U}; const uint8_t REC6F[] = {0x6FU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC70[] = {0x70U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U}; const uint8_t REC70[] = {0x70U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC71[] = {0x71U, 0xACU, 0xB8U, 0xA4U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U}; const uint8_t REC71[] = {0x71U, 0xACU, 0xB8U, 0xA4U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC72[] = {0x72U, 0x9BU, 0xDCU, 0x75U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U}; const uint8_t REC72[] = {0x72U, 0x9BU, 0xDCU, 0x75U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
const unsigned char REC73[] = {0x73U, 0x00U, 0x00U, 0x02U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U}; const uint8_t REC73[] = {0x73U, 0x00U, 0x00U, 0x02U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
const unsigned char REC80[] = {0x80U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U}; const uint8_t REC80[] = {0x80U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
#define WRITE_BIT(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7]) #define WRITE_BIT(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7])
@ -67,7 +67,7 @@ void P25::process_udp()
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "RCCV: "); fprintf(stderr, "RCCV: ");
for(int i = 0; i < buf.size(); ++i){ for(int i = 0; i < buf.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)buf.data()[i]); fprintf(stderr, "%02x ", (uint8_t)buf.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -188,7 +188,7 @@ void P25::hostname_lookup(QHostInfo i)
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "CONN: "); fprintf(stderr, "CONN: ");
for(int i = 0; i < out.size(); ++i){ for(int i = 0; i < out.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)out.data()[i]); fprintf(stderr, "%02x ", (uint8_t)out.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -206,7 +206,7 @@ void P25::send_ping()
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "PING: "); fprintf(stderr, "PING: ");
for(int i = 0; i < out.size(); ++i){ for(int i = 0; i < out.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)out.data()[i]); fprintf(stderr, "%02x ", (uint8_t)out.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -223,7 +223,7 @@ void P25::send_disconnect()
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "SEND: "); fprintf(stderr, "SEND: ");
for(int i = 0; i < out.size(); ++i){ for(int i = 0; i < out.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)out.data()[i]); fprintf(stderr, "%02x ", (uint8_t)out.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -406,7 +406,7 @@ void P25::transmit()
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "SEND: "); fprintf(stderr, "SEND: ");
for(int i = 0; i < txdata.size(); ++i){ for(int i = 0; i < txdata.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)txdata.data()[i]); fprintf(stderr, "%02x ", (uint8_t)txdata.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);

@ -22,10 +22,10 @@
//#define DEBUG //#define DEBUG
const unsigned char MMDVM_DSTAR_HEADER = 0x10U; const uint8_t MMDVM_DSTAR_HEADER = 0x10U;
const unsigned char MMDVM_DSTAR_DATA = 0x11U; const uint8_t MMDVM_DSTAR_DATA = 0x11U;
const unsigned char MMDVM_DSTAR_LOST = 0x12U; const uint8_t MMDVM_DSTAR_LOST = 0x12U;
const unsigned char MMDVM_DSTAR_EOT = 0x13U; const uint8_t MMDVM_DSTAR_EOT = 0x13U;
REF::REF() REF::REF()
{ {
@ -45,14 +45,14 @@ void REF::process_udp()
static bool sd_sync = 0; static bool sd_sync = 0;
static int sd_seq = 0; static int sd_seq = 0;
static char user_data[21]; static char user_data[21];
const unsigned char header[5] = {0x80,0x44,0x53,0x56,0x54}; const uint8_t header[5] = {0x80,0x44,0x53,0x56,0x54};
buf.resize(m_udp->pendingDatagramSize()); buf.resize(m_udp->pendingDatagramSize());
m_udp->readDatagram(buf.data(), buf.size(), &sender, &senderPort); m_udp->readDatagram(buf.data(), buf.size(), &sender, &senderPort);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "RECV: "); fprintf(stderr, "RECV: ");
for(int i = 0; i < buf.size(); ++i){ for(int i = 0; i < buf.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)buf.data()[i]); fprintf(stderr, "%02x ", (uint8_t)buf.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -80,7 +80,7 @@ void REF::process_udp()
if(out.size()){ if(out.size()){
fprintf(stderr, "SEND: "); fprintf(stderr, "SEND: ");
for(int i = 0; i < out.size(); ++i){ for(int i = 0; i < out.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)out.data()[i]); fprintf(stderr, "%02x ", (uint8_t)out.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -312,7 +312,7 @@ void REF::hostname_lookup(QHostInfo i)
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "CONN: "); fprintf(stderr, "CONN: ");
for(int i = 0; i < out.size(); ++i){ for(int i = 0; i < out.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)out.data()[i]); fprintf(stderr, "%02x ", (uint8_t)out.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -330,7 +330,7 @@ void REF::send_ping()
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "PING: "); fprintf(stderr, "PING: ");
for(int i = 0; i < out.size(); ++i){ for(int i = 0; i < out.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)out.data()[i]); fprintf(stderr, "%02x ", (uint8_t)out.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -349,7 +349,7 @@ void REF::send_disconnect()
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "SEND: "); fprintf(stderr, "SEND: ");
for(int i = 0; i < out.size(); ++i){ for(int i = 0; i < out.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)out.data()[i]); fprintf(stderr, "%02x ", (uint8_t)out.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -417,7 +417,7 @@ void REF::start_tx()
void REF::transmit() void REF::transmit()
{ {
unsigned char ambe[9]; uint8_t ambe[9];
uint8_t ambe_frame[72]; uint8_t ambe_frame[72];
int16_t pcm[160]; int16_t pcm[160];
memset(ambe_frame, 0, 72); memset(ambe_frame, 0, 72);
@ -511,11 +511,19 @@ void REF::send_frame(uint8_t *ambe)
m_modeinfo.gw = m_txrptr1; m_modeinfo.gw = m_txrptr1;
m_modeinfo.gw2 = m_txrptr2; m_modeinfo.gw2 = m_txrptr2;
m_modeinfo.streamid = txstreamid; m_modeinfo.streamid = txstreamid;
m_modeinfo.frame_number = m_txcnt % 21; m_modeinfo.frame_number = m_txcnt;
m_udp->writeDatagram(txdata, m_address, m_modeinfo.port); m_udp->writeDatagram(txdata, m_address, m_modeinfo.port);
#ifdef DEBUG
fprintf(stderr, "SEND:%d: ", txdata.size());
for(int i = 0; i < txdata.size(); ++i){
fprintf(stderr, "%02x ", (uint8_t)txdata.data()[i]);
} }
else { fprintf(stderr, "\n");
fflush(stderr);
#endif
}
txdata.resize(29); txdata.resize(29);
txdata[0] = 0x1d; txdata[0] = 0x1d;
txdata[1] = 0x80; txdata[1] = 0x80;
@ -533,10 +541,10 @@ void REF::send_frame(uint8_t *ambe)
txdata[13] = 0x01; txdata[13] = 0x01;
txdata[14] = (txstreamid >> 8) & 0xff; txdata[14] = (txstreamid >> 8) & 0xff;
txdata[15] = txstreamid & 0xff; txdata[15] = txstreamid & 0xff;
txdata[16] = m_txcnt % 21; txdata[16] = m_txcnt;
memcpy(txdata.data() + 17, ambe, 9); memcpy(txdata.data() + 17, ambe, 9);
m_modeinfo.frame_number = m_txcnt % 21; m_modeinfo.frame_number = m_txcnt;
switch(txdata.data()[16]){ switch(txdata.data()[16]){
case 0: case 0:
@ -591,18 +599,20 @@ void REF::send_frame(uint8_t *ambe)
break; break;
} }
if((m_txcnt % 21) == 0){ if(m_txcnt == 20){
sendheader = 1; sendheader = 1;
} m_txcnt = 0;
if(m_tx){
m_txcnt++;
} }
else{ else{
++m_txcnt;
}
if(!m_tx){
qDebug() << "TX stopped"; qDebug() << "TX stopped";
//txdata[0] = 0x20; txdata[0] = 0x20;
//txdata[6] = 0x20; //txdata[6] = 0x20;
//txdata[16] = m_txcnt % 21; //txdata[16] = m_txcnt % 21;
txdata[16] = 0x40 | txdata[16];
memset(txdata.data() + 17, 0, 9); memset(txdata.data() + 17, 0, 9);
txdata[26] = 0x55; txdata[26] = 0x55;
txdata[27] = 0x55; txdata[27] = 0x55;
@ -622,7 +632,6 @@ void REF::send_frame(uint8_t *ambe)
m_ttscnt = 0; m_ttscnt = 0;
m_modeinfo.stream_state = STREAM_IDLE; m_modeinfo.stream_state = STREAM_IDLE;
} }
}
m_udp->writeDatagram(txdata, m_address, m_modeinfo.port); m_udp->writeDatagram(txdata, m_address, m_modeinfo.port);
emit update_output_level(m_audio->level() * 2); emit update_output_level(m_audio->level() * 2);
@ -630,7 +639,7 @@ void REF::send_frame(uint8_t *ambe)
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "SEND:%d: ", txdata.size()); fprintf(stderr, "SEND:%d: ", txdata.size());
for(int i = 0; i < txdata.size(); ++i){ for(int i = 0; i < txdata.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)txdata.data()[i]); fprintf(stderr, "%02x ", (uint8_t)txdata.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);

@ -26,7 +26,7 @@ class REF : public Mode
public: public:
REF(); REF();
~REF(); ~REF();
unsigned char * get_frame(unsigned char *ambe); uint8_t * get_frame(uint8_t *ambe);
private: private:
uint8_t packet_size; uint8_t packet_size;
private slots: private slots:

@ -46,7 +46,7 @@ void XRF::process_udp()
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "RECV: "); fprintf(stderr, "RECV: ");
for(int i = 0; i < buf.size(); ++i){ for(int i = 0; i < buf.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)buf.data()[i]); fprintf(stderr, "%02x ", (uint8_t)buf.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -266,7 +266,7 @@ void XRF::hostname_lookup(QHostInfo i)
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "CONN: "); fprintf(stderr, "CONN: ");
for(int i = 0; i < out.size(); ++i){ for(int i = 0; i < out.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)out.data()[i]); fprintf(stderr, "%02x ", (uint8_t)out.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -284,7 +284,7 @@ void XRF::send_ping()
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "PING: "); fprintf(stderr, "PING: ");
for(int i = 0; i < out.size(); ++i){ for(int i = 0; i < out.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)out.data()[i]); fprintf(stderr, "%02x ", (uint8_t)out.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -303,7 +303,7 @@ void XRF::send_disconnect()
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "SEND: "); fprintf(stderr, "SEND: ");
for(int i = 0; i < out.size(); ++i){ for(int i = 0; i < out.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)out.data()[i]); fprintf(stderr, "%02x ", (uint8_t)out.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
@ -370,7 +370,7 @@ void XRF::start_tx()
void XRF::transmit() void XRF::transmit()
{ {
unsigned char ambe[9]; uint8_t ambe[9];
uint8_t ambe_frame[72]; uint8_t ambe_frame[72];
int16_t pcm[160]; int16_t pcm[160];
memset(ambe_frame, 0, 72); memset(ambe_frame, 0, 72);
@ -563,7 +563,7 @@ void XRF::send_frame(uint8_t *ambe)
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "SEND:%d: ", txdata.size()); fprintf(stderr, "SEND:%d: ", txdata.size());
for(int i = 0; i < txdata.size(); ++i){ for(int i = 0; i < txdata.size(); ++i){
fprintf(stderr, "%02x ", (unsigned char)txdata.data()[i]); fprintf(stderr, "%02x ", (uint8_t)txdata.data()[i]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);

@ -26,7 +26,7 @@ class XRF : public Mode
public: public:
XRF(); XRF();
~XRF(); ~XRF();
unsigned char * get_frame(unsigned char *ambe); uint8_t * get_frame(uint8_t *ambe);
private: private:
QString m_txusrtxt; QString m_txusrtxt;
uint8_t packet_size; uint8_t packet_size;

Loading…
Cancel
Save