From a24658ba301b26ae585943f07e878ac07d28dc57 Mon Sep 17 00:00:00 2001 From: Doug McLain Date: Mon, 1 Aug 2022 15:50:48 -0400 Subject: [PATCH] Fix DPlus frame sequencing and some code cleanups --- CRCenc.cpp | 45 ++++----- CRCenc.h | 19 ++-- DMRDefines.h | 141 +++++++++++++------------- DroidStar.pro | 2 +- Golay24128.cpp | 40 ++++---- Golay24128.h | 17 ++-- M17Convolution.cpp | 70 ++++++------- M17Convolution.h | 12 +-- M17Defines.h | 81 +++++++-------- MMDVMDefines.h | 145 ++++++++++++++------------- SHA256.cpp | 44 ++++---- SHA256.h | 12 +-- YSFConvolution.cpp | 14 +-- YSFConvolution.h | 4 +- YSFFICH.cpp | 92 ++++++++--------- YSFFICH.h | 51 +++++----- audioengine.cpp | 3 +- cbptc19696.h | 2 +- cgolay2087.cpp | 22 ++-- cgolay2087.h | 7 +- crs129.cpp | 31 +++--- crs129.h | 6 +- dcs.h | 2 +- dmr.cpp | 22 ++-- droidstar.cpp | 9 +- droidstar.h | 2 +- iax.cpp | 2 +- m17.cpp | 6 +- mode.cpp | 1 + nxdn.cpp | 18 ++-- nxdn.h | 4 +- p25.cpp | 48 ++++----- ref.cpp | 245 +++++++++++++++++++++++---------------------- ref.h | 2 +- xrf.cpp | 12 +-- xrf.h | 2 +- 36 files changed, 626 insertions(+), 609 deletions(-) diff --git a/CRCenc.cpp b/CRCenc.cpp index 4433317..7e6fd80 100644 --- a/CRCenc.cpp +++ b/CRCenc.cpp @@ -18,11 +18,6 @@ */ #include "CRCenc.h" - -//#include "Utils.h" -//#include "Log.h" - -#include #include #include #include @@ -120,18 +115,18 @@ const uint16_t CCITT16_TABLE2[] = { 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 }; /* -bool CCRC::checkFiveBit(bool* in, unsigned int tcrc) +bool CCRC::checkFiveBit(bool* in, uint32_t tcrc) { assert(in != NULL); - unsigned int crc; + uint32_t crc; //encodeFiveBit(in, crc); return crc == tcrc; } */ -void CCRC::bitsToByteBE(const bool* bits, unsigned char& byte) +void CCRC::bitsToByteBE(const bool* bits, uint8_t& byte) { assert(bits != NULL); @@ -145,13 +140,13 @@ void CCRC::bitsToByteBE(const bool* bits, unsigned char& byte) byte |= bits[7U] ? 0x01U : 0x00U; } -void CCRC::encodeFiveBit(const bool* in, unsigned int& tcrc) +void CCRC::encodeFiveBit(const bool* in, uint32_t& tcrc) { assert(in != NULL); - unsigned short total = 0U; - for (unsigned int i = 0U; i < 72U; i += 8U) { - unsigned char c; + uint16_t total = 0U; + for (uint32_t i = 0U; i < 72U; i += 8U) { + uint8_t c; bitsToByteBE(in + i, c); total += c; } @@ -161,7 +156,7 @@ void CCRC::encodeFiveBit(const bool* in, unsigned int& tcrc) tcrc = total; } -void CCRC::addCCITT162(unsigned char *in, unsigned int length) +void CCRC::addCCITT162(uint8_t *in, uint32_t length) { assert(in != NULL); assert(length > 2U); @@ -173,7 +168,7 @@ void CCRC::addCCITT162(unsigned char *in, unsigned int length) crc16 = 0U; - for (unsigned i = 0U; i < (length - 2U); i++) + for (uint32_t i = 0U; i < (length - 2U); i++) crc16 = (uint16_t(crc8[0U]) << 8) ^ CCITT16_TABLE2[crc8[1U] ^ in[i]]; crc16 = ~crc16; @@ -182,7 +177,7 @@ void CCRC::addCCITT162(unsigned char *in, unsigned int length) in[length - 2U] = crc8[1U]; } -bool CCRC::checkCCITT162(const unsigned char *in, unsigned int length) +bool CCRC::checkCCITT162(const uint8_t *in, uint32_t length) { assert(in != NULL); assert(length > 2U); @@ -194,7 +189,7 @@ bool CCRC::checkCCITT162(const unsigned char *in, unsigned int length) crc16 = 0U; - for (unsigned i = 0U; i < (length - 2U); i++) + for (uint32_t i = 0U; i < (length - 2U); i++) crc16 = (uint16_t(crc8[0U]) << 8) ^ CCITT16_TABLE2[crc8[1U] ^ in[i]]; crc16 = ~crc16; @@ -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]; } -void CCRC::addCCITT161(unsigned char *in, unsigned int length) +void CCRC::addCCITT161(uint8_t *in, uint32_t length) { assert(in != NULL); assert(length > 2U); @@ -214,7 +209,7 @@ void CCRC::addCCITT161(unsigned char *in, unsigned int length) crc16 = 0xFFFFU; - for (unsigned int i = 0U; i < (length - 2U); i++) + for (uint32_t i = 0U; i < (length - 2U); i++) crc16 = uint16_t(crc8[1U]) ^ CCITT16_TABLE1[crc8[0U] ^ in[i]]; crc16 = ~crc16; @@ -223,7 +218,7 @@ void CCRC::addCCITT161(unsigned char *in, unsigned int length) in[length - 1U] = crc8[1U]; } -bool CCRC::checkCCITT161(const unsigned char *in, unsigned int length) +bool CCRC::checkCCITT161(const uint8_t *in, uint32_t length) { assert(in != NULL); assert(length > 2U); @@ -235,7 +230,7 @@ bool CCRC::checkCCITT161(const unsigned char *in, unsigned int length) crc16 = 0xFFFFU; - for (unsigned int i = 0U; i < (length - 2U); i++) + for (uint32_t i = 0U; i < (length - 2U); i++) crc16 = uint16_t(crc8[1U]) ^ CCITT16_TABLE1[crc8[0U] ^ in[i]]; crc16 = ~crc16; @@ -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]; } -unsigned char CCRC::crc8(const unsigned char *in, unsigned int length) +uint8_t CCRC::crc8(const uint8_t *in, uint32_t length) { assert(in != NULL); uint8_t crc = 0U; - for (unsigned int i = 0U; i < length; i++) + for (uint32_t i = 0U; i < length; i++) crc = CRC8_TABLE[crc ^ in[i]]; return crc; } -unsigned char CCRC::addCRC(const unsigned char* in, unsigned int length) +uint8_t CCRC::addCRC(const uint8_t* in, uint32_t length) { assert(in != NULL); - unsigned char crc = 0U; + uint8_t crc = 0U; - for (unsigned int i = 0U; i < length; i++) + for (uint32_t i = 0U; i < length; i++) crc += in[i]; return crc; diff --git a/CRCenc.h b/CRCenc.h index 99d6d5f..0a72aab 100644 --- a/CRCenc.h +++ b/CRCenc.h @@ -19,23 +19,24 @@ #if !defined(CRC_H) #define CRC_H +#include class CCRC { public: - //static bool checkFiveBit(bool* in, unsigned int tcrc); - static void bitsToByteBE(const bool* bits, unsigned char& byte); - static void encodeFiveBit(const bool* in, unsigned int& tcrc); + //static bool checkFiveBit(bool* in, uint32_t tcrc); + static void bitsToByteBE(const bool* bits, uint8_t& byte); + static void encodeFiveBit(const bool* in, uint32_t& tcrc); - static void addCCITT161(unsigned char* in, unsigned int length); - static void addCCITT162(unsigned char* in, unsigned int length); + static void addCCITT161(uint8_t* in, uint32_t length); + static void addCCITT162(uint8_t* in, uint32_t length); - static bool checkCCITT161(const unsigned char* in, unsigned int length); - static bool checkCCITT162(const unsigned char* in, unsigned int length); + static bool checkCCITT161(const uint8_t* in, uint32_t length); + static bool checkCCITT162(const uint8_t* in, uint32_t length); - static unsigned char crc8(const unsigned char* in, unsigned int length); + static unsigned char crc8(const uint8_t* in, uint32_t length); - static unsigned char addCRC(const unsigned char* in, unsigned int length); + static unsigned char addCRC(const uint8_t* in, uint32_t length); }; #endif diff --git a/DMRDefines.h b/DMRDefines.h index cc97151..c83ec47 100644 --- a/DMRDefines.h +++ b/DMRDefines.h @@ -18,100 +18,101 @@ #if !defined(DMRDefines_H) #define DMRDefines_H +#include -const unsigned char TAG_HEADER = 0x00U; -const unsigned char TAG_DATA = 0x01U; -const unsigned char TAG_LOST = 0x02U; -const unsigned char TAG_EOT = 0x03U; -const unsigned char TAG_NODATA = 0x04U; +const uint8_t TAG_HEADER = 0x00U; +const uint8_t TAG_DATA = 0x01U; +const uint8_t TAG_LOST = 0x02U; +const uint8_t TAG_EOT = 0x03U; +const uint8_t TAG_NODATA = 0x04U; -const unsigned int DMR_FRAME_LENGTH_BITS = 264U; -const unsigned int DMR_FRAME_LENGTH_BYTES = 33U; +const uint32_t DMR_FRAME_LENGTH_BITS = 264U; +const uint32_t DMR_FRAME_LENGTH_BYTES = 33U; -const unsigned int DMR_SYNC_LENGTH_BITS = 48U; -const unsigned int DMR_SYNC_LENGTH_BYTES = 6U; +const uint32_t DMR_SYNC_LENGTH_BITS = 48U; +const uint32_t DMR_SYNC_LENGTH_BYTES = 6U; -const unsigned int DMR_EMB_LENGTH_BITS = 8U; -const unsigned int DMR_EMB_LENGTH_BYTES = 1U; +const uint32_t DMR_EMB_LENGTH_BITS = 8U; +const uint32_t DMR_EMB_LENGTH_BYTES = 1U; -const unsigned int DMR_SLOT_TYPE_LENGTH_BITS = 8U; -const unsigned int DMR_SLOT_TYPE_LENGTH_BYTES = 1U; +const uint32_t DMR_SLOT_TYPE_LENGTH_BITS = 8U; +const uint32_t DMR_SLOT_TYPE_LENGTH_BYTES = 1U; -const unsigned int DMR_EMBEDDED_SIGNALLING_LENGTH_BITS = 32U; -const unsigned int DMR_EMBEDDED_SIGNALLING_LENGTH_BYTES = 4U; +const uint32_t DMR_EMBEDDED_SIGNALLING_LENGTH_BITS = 32U; +const uint32_t DMR_EMBEDDED_SIGNALLING_LENGTH_BYTES = 4U; -const unsigned int DMR_AMBE_LENGTH_BITS = 108U * 2U; -const unsigned int DMR_AMBE_LENGTH_BYTES = 27U; +const uint32_t DMR_AMBE_LENGTH_BITS = 108U * 2U; +const uint32_t DMR_AMBE_LENGTH_BYTES = 27U; -const unsigned char BS_SOURCED_AUDIO_SYNC[] = {0x07U, 0x55U, 0xFDU, 0x7DU, 0xF7U, 0x5FU, 0x70U}; -const unsigned char BS_SOURCED_DATA_SYNC[] = {0x0DU, 0xFFU, 0x57U, 0xD7U, 0x5DU, 0xF5U, 0xD0U}; +const uint8_t BS_SOURCED_AUDIO_SYNC[] = {0x07U, 0x55U, 0xFDU, 0x7DU, 0xF7U, 0x5FU, 0x70U}; +const uint8_t BS_SOURCED_DATA_SYNC[] = {0x0DU, 0xFFU, 0x57U, 0xD7U, 0x5DU, 0xF5U, 0xD0U}; -const unsigned char MS_SOURCED_AUDIO_SYNC[] = {0x07U, 0xF7U, 0xD5U, 0xDDU, 0x57U, 0xDFU, 0xD0U}; -const unsigned char MS_SOURCED_DATA_SYNC[] = {0x0DU, 0x5DU, 0x7FU, 0x77U, 0xFDU, 0x75U, 0x70U}; +const uint8_t MS_SOURCED_AUDIO_SYNC[] = {0x07U, 0xF7U, 0xD5U, 0xDDU, 0x57U, 0xDFU, 0xD0U}; +const uint8_t MS_SOURCED_DATA_SYNC[] = {0x0DU, 0x5DU, 0x7FU, 0x77U, 0xFDU, 0x75U, 0x70U}; -const unsigned char DIRECT_SLOT1_AUDIO_SYNC[] = {0x05U, 0xD5U, 0x77U, 0xF7U, 0x75U, 0x7FU, 0xF0U}; -const unsigned char DIRECT_SLOT1_DATA_SYNC[] = {0x0FU, 0x7FU, 0xDDU, 0x5DU, 0xDFU, 0xD5U, 0x50U}; +const uint8_t DIRECT_SLOT1_AUDIO_SYNC[] = {0x05U, 0xD5U, 0x77U, 0xF7U, 0x75U, 0x7FU, 0xF0U}; +const uint8_t DIRECT_SLOT1_DATA_SYNC[] = {0x0FU, 0x7FU, 0xDDU, 0x5DU, 0xDFU, 0xD5U, 0x50U}; -const unsigned char DIRECT_SLOT2_AUDIO_SYNC[] = {0x07U, 0xDFU, 0xFDU, 0x5FU, 0x55U, 0xD5U, 0xF0U}; -const unsigned char DIRECT_SLOT2_DATA_SYNC[] = {0x0DU, 0x75U, 0x57U, 0xF5U, 0xFFU, 0x7FU, 0x50U}; +const uint8_t DIRECT_SLOT2_AUDIO_SYNC[] = {0x07U, 0xDFU, 0xFDU, 0x5FU, 0x55U, 0xD5U, 0xF0U}; +const uint8_t DIRECT_SLOT2_DATA_SYNC[] = {0x0DU, 0x75U, 0x57U, 0xF5U, 0xFFU, 0x7FU, 0x50U}; -const unsigned char SYNC_MASK[] = {0x0FU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xF0U}; +const uint8_t SYNC_MASK[] = {0x0FU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xF0U}; // The PR FILL and Data Sync pattern. -const unsigned char DMR_IDLE_DATA[] = {TAG_DATA, 0x00U, +const uint8_t DMR_IDLE_DATA[] = {TAG_DATA, 0x00U, 0x53U, 0xC2U, 0x5EU, 0xABU, 0xA8U, 0x67U, 0x1DU, 0xC7U, 0x38U, 0x3BU, 0xD9U, 0x36U, 0x00U, 0x0DU, 0xFFU, 0x57U, 0xD7U, 0x5DU, 0xF5U, 0xD0U, 0x03U, 0xF6U, 0xE4U, 0x65U, 0x17U, 0x1BU, 0x48U, 0xCAU, 0x6DU, 0x4FU, 0xC6U, 0x10U, 0xB4U}; // A silence frame only -const unsigned char DMR_SILENCE_DATA[] = {0xB9U, 0xE8U, 0x81U, 0x52U, 0x61U, 0x73U, 0x00U, 0x2AU, 0x6BU, 0xB9U, 0xE8U, +const uint8_t DMR_SILENCE_DATA[] = {0xB9U, 0xE8U, 0x81U, 0x52U, 0x61U, 0x73U, 0x00U, 0x2AU, 0x6BU, 0xB9U, 0xE8U, 0x81U, 0x52U, 0x60U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x01U, 0x73U, 0x00U, 0x2AU, 0x6BU, 0xB9U, 0xE8U, 0x81U, 0x52U, 0x61U, 0x73U, 0x00U, 0x2AU, 0x6BU}; -const unsigned char PAYLOAD_LEFT_MASK[] = {0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xF0U}; -const unsigned char PAYLOAD_RIGHT_MASK[] = {0x0FU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU}; - -const unsigned char VOICE_LC_HEADER_CRC_MASK[] = {0x96U, 0x96U, 0x96U}; -const unsigned char TERMINATOR_WITH_LC_CRC_MASK[] = {0x99U, 0x99U, 0x99U}; -const unsigned char PI_HEADER_CRC_MASK[] = {0x69U, 0x69U}; -const unsigned char DATA_HEADER_CRC_MASK[] = {0xCCU, 0xCCU}; -const unsigned char CSBK_CRC_MASK[] = {0xA5U, 0xA5U}; - -const unsigned int DMR_SLOT_TIME = 60U; -const unsigned int AMBE_PER_SLOT = 3U; - -const unsigned char DT_MASK = 0x0FU; -const unsigned char DT_VOICE_PI_HEADER = 0x00U; -const unsigned char DT_VOICE_LC_HEADER = 0x01U; -const unsigned char DT_TERMINATOR_WITH_LC = 0x02U; -const unsigned char DT_CSBK = 0x03U; -const unsigned char DT_DATA_HEADER = 0x06U; -const unsigned char DT_RATE_12_DATA = 0x07U; -const unsigned char DT_RATE_34_DATA = 0x08U; -const unsigned char DT_IDLE = 0x09U; -const unsigned char DT_RATE_1_DATA = 0x0AU; +const uint8_t PAYLOAD_LEFT_MASK[] = {0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xF0U}; +const uint8_t PAYLOAD_RIGHT_MASK[] = {0x0FU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU}; + +const uint8_t VOICE_LC_HEADER_CRC_MASK[] = {0x96U, 0x96U, 0x96U}; +const uint8_t TERMINATOR_WITH_LC_CRC_MASK[] = {0x99U, 0x99U, 0x99U}; +const uint8_t PI_HEADER_CRC_MASK[] = {0x69U, 0x69U}; +const uint8_t DATA_HEADER_CRC_MASK[] = {0xCCU, 0xCCU}; +const uint8_t CSBK_CRC_MASK[] = {0xA5U, 0xA5U}; + +const uint32_t DMR_SLOT_TIME = 60U; +const uint32_t AMBE_PER_SLOT = 3U; + +const uint8_t DT_MASK = 0x0FU; +const uint8_t DT_VOICE_PI_HEADER = 0x00U; +const uint8_t DT_VOICE_LC_HEADER = 0x01U; +const uint8_t DT_TERMINATOR_WITH_LC = 0x02U; +const uint8_t DT_CSBK = 0x03U; +const uint8_t DT_DATA_HEADER = 0x06U; +const uint8_t DT_RATE_12_DATA = 0x07U; +const uint8_t DT_RATE_34_DATA = 0x08U; +const uint8_t DT_IDLE = 0x09U; +const uint8_t DT_RATE_1_DATA = 0x0AU; // Dummy values -const unsigned char DT_VOICE_SYNC = 0xF0U; -const unsigned char DT_VOICE = 0xF1U; - -const unsigned char DMR_IDLE_RX = 0x80U; -const unsigned char DMR_SYNC_DATA = 0x40U; -const unsigned char DMR_SYNC_AUDIO = 0x20U; - -const unsigned char DMR_SLOT1 = 0x00U; -const unsigned char DMR_SLOT2 = 0x80U; - -const unsigned char DPF_UDT = 0x00U; -const unsigned char DPF_RESPONSE = 0x01U; -const unsigned char DPF_UNCONFIRMED_DATA = 0x02U; -const unsigned char DPF_CONFIRMED_DATA = 0x03U; -const unsigned char DPF_DEFINED_SHORT = 0x0DU; -const unsigned char DPF_DEFINED_RAW = 0x0EU; -const unsigned char DPF_PROPRIETARY = 0x0FU; - -const unsigned char FID_ETSI = 0U; -const unsigned char FID_DMRA = 16U; +const uint8_t DT_VOICE_SYNC = 0xF0U; +const uint8_t DT_VOICE = 0xF1U; + +const uint8_t DMR_IDLE_RX = 0x80U; +const uint8_t DMR_SYNC_DATA = 0x40U; +const uint8_t DMR_SYNC_AUDIO = 0x20U; + +const uint8_t DMR_SLOT1 = 0x00U; +const uint8_t DMR_SLOT2 = 0x80U; + +const uint8_t DPF_UDT = 0x00U; +const uint8_t DPF_RESPONSE = 0x01U; +const uint8_t DPF_UNCONFIRMED_DATA = 0x02U; +const uint8_t DPF_CONFIRMED_DATA = 0x03U; +const uint8_t DPF_DEFINED_SHORT = 0x0DU; +const uint8_t DPF_DEFINED_RAW = 0x0EU; +const uint8_t DPF_PROPRIETARY = 0x0FU; + +const uint8_t FID_ETSI = 0U; +const uint8_t FID_DMRA = 16U; enum FLCO { FLCO_GROUP = 0, diff --git a/DroidStar.pro b/DroidStar.pro index f3c60cc..b35ced5 100644 --- a/DroidStar.pro +++ b/DroidStar.pro @@ -31,7 +31,7 @@ DEFINES += VERSION_NUMBER=\"\\\"$${VERSION_BUILD}\\\"\" DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 DEFINES += VOCODER_PLUGIN -DEFINES += USE_FLITE +#DEFINES += USE_FLITE #DEFINES += USE_EXTERNAL_CODEC2 HEADERS += \ diff --git a/Golay24128.cpp b/Golay24128.cpp index 6d0e19a..ab4f248 100644 --- a/Golay24128.cpp +++ b/Golay24128.cpp @@ -8,7 +8,7 @@ #include #include -const unsigned int ENCODING_TABLE_23127[] = { +const uint32_t ENCODING_TABLE_23127[] = { 0x000000U, 0x0018EAU, 0x00293EU, 0x0031D4U, 0x004A96U, 0x00527CU, 0x0063A8U, 0x007B42U, 0x008DC6U, 0x00952CU, 0x00A4F8U, 0x00BC12U, 0x00C750U, 0x00DFBAU, 0x00EE6EU, 0x00F684U, 0x010366U, 0x011B8CU, 0x012A58U, 0x0132B2U, 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, 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, 0x00A4F8U, 0x00BC13U, 0x00C751U, 0x00DFBAU, 0x00EE6FU, 0x00F684U, 0x010367U, 0x011B8CU, 0x012A59U, 0x0132B2U, 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, 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, 0x00000AU, 0x00000BU, 0x00000CU, 0x00000DU, 0x00000EU, 0x024020U, 0x000010U, 0x000011U, 0x000012U, 0x000013U, 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 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 * 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. */ { - unsigned int aux = X22; + uint32_t aux = X22; if (pattern >= X11) { while (pattern & MASK12) { @@ -1069,36 +1069,36 @@ static unsigned int get_syndrome_23127(unsigned int pattern) return pattern; } -unsigned int CGolay24128::encode23127(unsigned int data) +uint32_t CGolay24128::encode23127(uint32_t 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]; } -unsigned int CGolay24128::decode23127(unsigned int code) +uint32_t CGolay24128::decode23127(uint32_t code) { - unsigned int syndrome = ::get_syndrome_23127(code); - unsigned int error_pattern = DECODING_TABLE_23127[syndrome]; + uint32_t syndrome = ::get_syndrome_23127(code); + uint32_t error_pattern = DECODING_TABLE_23127[syndrome]; code ^= error_pattern; return code >> 11; } -unsigned int CGolay24128::decode24128(unsigned int code) +uint32_t CGolay24128::decode24128(uint32_t code) { return decode23127(code >> 1); } -unsigned int CGolay24128::decode24128(unsigned char* bytes) +uint32_t CGolay24128::decode24128(uint8_t* bytes) { assert(bytes != NULL); - unsigned int code = bytes[0U]; + uint32_t code = bytes[0U]; code <<= 8; code |= bytes[1U]; code <<= 8; @@ -1107,10 +1107,10 @@ unsigned int CGolay24128::decode24128(unsigned char* bytes) 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); - unsigned int error_pattern = DECODING_TABLE_23127[syndrome] << 1; + uint32_t syndrome = ::get_syndrome_23127(in >> 1); + uint32_t error_pattern = DECODING_TABLE_23127[syndrome] << 1; out = in ^ error_pattern; @@ -1121,18 +1121,18 @@ bool CGolay24128::decode24128(unsigned int in, unsigned int& out) return valid; } -bool CGolay24128::decode24128(unsigned char* in, unsigned int& out) +bool CGolay24128::decode24128(uint8_t* in, uint32_t& out) { 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); } -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) { v &= v - 1U; diff --git a/Golay24128.h b/Golay24128.h index fc90496..a0535db 100644 --- a/Golay24128.h +++ b/Golay24128.h @@ -18,18 +18,19 @@ #ifndef Golay24128_H #define Golay24128_H +#include class CGolay24128 { public: - static unsigned int encode23127(unsigned int data); - static unsigned int encode24128(unsigned int data); + static uint32_t encode23127(uint32_t data); + static uint32_t encode24128(uint32_t data); - static unsigned int decode23127(unsigned int code); - static unsigned int decode24128(unsigned int code); - static unsigned int decode24128(unsigned char* bytes); - static bool decode24128(unsigned int in, unsigned int& out); - static bool decode24128(unsigned char* in, unsigned int& out); - static unsigned int countBits(unsigned int v); + static uint32_t decode23127(uint32_t code); + static uint32_t decode24128(uint32_t code); + static uint32_t decode24128(uint8_t* bytes); + static bool decode24128(uint32_t in, uint32_t& out); + static bool decode24128(uint8_t* in, uint32_t& out); + static uint32_t countBits(uint32_t v); }; #endif diff --git a/M17Convolution.cpp b/M17Convolution.cpp index 56e689d..dd7e52a 100644 --- a/M17Convolution.cpp +++ b/M17Convolution.cpp @@ -23,9 +23,9 @@ #include #include -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, 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, @@ -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, 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, 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 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_TABLE2[] = {0U, 2U, 2U, 0U, 0U, 2U, 2U, 0U}; -const unsigned int NUM_OF_STATES_D2 = 8U; -const unsigned int NUM_OF_STATES = 16U; +const uint32_t NUM_OF_STATES_D2 = 8U; +const uint32_t NUM_OF_STATES = 16U; const uint32_t M = 4U; -const unsigned int K = 5U; +const uint32_t K = 5U; CM17Convolution::CM17Convolution() : m_metrics1(NULL), @@ -72,21 +72,21 @@ CM17Convolution::~CM17Convolution() 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(out != NULL); - unsigned char temp1[31U]; + uint8_t temp1[31U]; ::memset(temp1, 0x00U, 31U); ::memcpy(temp1, in, 30U); - unsigned char temp2[61U]; + uint8_t temp2[61U]; encode(temp1, temp2, 244U); - unsigned int n = 0U; - unsigned int index = 0U; - for (unsigned int i = 0U; i < 488U; i++) { + uint32_t n = 0U; + uint32_t index = 0U; + for (uint32_t i = 0U; i < 488U; i++) { if (i != PUNCTURE_LIST_LINK_SETUP[index]) { bool b = READ_BIT1(temp2, i); 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(out != NULL); - unsigned char temp1[19U]; + uint8_t temp1[19U]; ::memset(temp1, 0x00U, 19U); ::memcpy(temp1, in, 18U); - unsigned char temp2[37U]; + uint8_t temp2[37U]; encode(temp1, temp2, 148U); - unsigned int n = 0U; - unsigned int index = 0U; - for (unsigned int i = 0U; i < 296U; i++) { + uint32_t n = 0U; + uint32_t index = 0U; + for (uint32_t i = 0U; i < 296U; i++) { if (i != PUNCTURE_LIST_DATA[index]) { bool b = READ_BIT1(temp2, i); 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(out != NULL); @@ -130,9 +130,9 @@ unsigned int CM17Convolution::decodeLinkSetup(const unsigned char* in, unsigned uint8_t temp[500U]; ::memset(temp, 0x00U, 500U); - unsigned int n = 0U; - unsigned int index = 0U; - for (unsigned int i = 0U; i < 368U; i++) { + uint32_t n = 0U; + uint32_t index = 0U; + for (uint32_t i = 0U; i < 368U; i++) { if (n == PUNCTURE_LIST_LINK_SETUP[index]) { temp[n++] = 1U; index++; @@ -145,7 +145,7 @@ unsigned int CM17Convolution::decodeLinkSetup(const unsigned char* in, unsigned start(); 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 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; } -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(out != NULL); @@ -163,9 +163,9 @@ unsigned int CM17Convolution::decodeData(const unsigned char* in, unsigned char* uint8_t temp[300U]; ::memset(temp, 0x00U, 300U); - unsigned int n = 0U; - unsigned int index = 0U; - for (unsigned int i = 0U; i < 272U; i++) { + uint32_t n = 0U; + uint32_t index = 0U; + for (uint32_t i = 0U; i < 272U; i++) { if (n == PUNCTURE_LIST_DATA[index]) { temp[n++] = 1U; index++; @@ -178,7 +178,7 @@ unsigned int CM17Convolution::decodeData(const unsigned char* in, unsigned char* start(); 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 s1 = temp[n++]; @@ -229,7 +229,7 @@ void CM17Convolution::decode(uint8_t s0, uint8_t s1) 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); @@ -245,9 +245,9 @@ unsigned int CM17Convolution::chainback(unsigned char* out, unsigned int nBits) 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) minCost = m_oldMetrics[i]; } @@ -255,7 +255,7 @@ unsigned int CM17Convolution::chainback(unsigned char* out, unsigned int nBits) 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(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; 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 g1 = (d + d3 + d4) & 1; diff --git a/M17Convolution.h b/M17Convolution.h index 0c5c7c3..21ea486 100644 --- a/M17Convolution.h +++ b/M17Convolution.h @@ -26,11 +26,11 @@ public: CM17Convolution(); ~CM17Convolution(); - unsigned int decodeLinkSetup(const unsigned char* in, unsigned char* out); - unsigned int decodeData(const unsigned char* in, unsigned char* out); + unsigned int decodeLinkSetup(const uint8_t* in, uint8_t* out); + unsigned int decodeData(const uint8_t* in, uint8_t* out); - void encodeLinkSetup(const unsigned char* in, unsigned char* out) const; - void encodeData(const unsigned char* in, unsigned char* out) const; + void encodeLinkSetup(const uint8_t* in, uint8_t* out) const; + void encodeData(const uint8_t* in, uint8_t* out) const; private: uint16_t* m_metrics1; @@ -43,9 +43,9 @@ private: void start(); 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 diff --git a/M17Defines.h b/M17Defines.h index 0543d8e..3fdc4aa 100644 --- a/M17Defines.h +++ b/M17Defines.h @@ -18,63 +18,64 @@ #if !defined(M17DEFINES_H) #define M17DEFINES_H +#include -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 unsigned int M17_FRAME_LENGTH_BYTES = M17_FRAME_LENGTH_BITS / 8U; +const uint32_t M17_FRAME_LENGTH_BITS = 384U; +const uint32_t M17_FRAME_LENGTH_BYTES = M17_FRAME_LENGTH_BITS / 8U; -const unsigned char M17_LINK_SETUP_SYNC_BYTES[] = {0x55U, 0xF7U}; -const unsigned char M17_STREAM_SYNC_BYTES[] = {0xFFU, 0x5DU}; -const unsigned char M17_EOT_SYNC_BYTES[] = {0x55U, 0x5DU}; +const uint8_t M17_LINK_SETUP_SYNC_BYTES[] = {0x55U, 0xF7U}; +const uint8_t M17_STREAM_SYNC_BYTES[] = {0xFFU, 0x5DU}; +const uint8_t M17_EOT_SYNC_BYTES[] = {0x55U, 0x5DU}; -const unsigned int M17_SYNC_LENGTH_BITS = 16U; -const unsigned int M17_SYNC_LENGTH_BYTES = M17_SYNC_LENGTH_BITS / 8U; +const uint32_t M17_SYNC_LENGTH_BITS = 16U; +const uint32_t M17_SYNC_LENGTH_BYTES = M17_SYNC_LENGTH_BITS / 8U; -const unsigned int M17_LSF_LENGTH_BITS = 240U; -const unsigned int M17_LSF_LENGTH_BYTES = M17_LSF_LENGTH_BITS / 8U; +const uint32_t M17_LSF_LENGTH_BITS = 240U; +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 unsigned int M17_LSF_FRAGMENT_LENGTH_BYTES = M17_LSF_FRAGMENT_LENGTH_BITS / 8U; +const uint32_t M17_LSF_FRAGMENT_LENGTH_BITS = M17_LSF_LENGTH_BITS / 6U; +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 unsigned int M17_LICH_FRAGMENT_LENGTH_BYTES = M17_LICH_FRAGMENT_LENGTH_BITS / 8U; +const uint32_t M17_LICH_FRAGMENT_LENGTH_BITS = M17_LSF_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 unsigned int M17_LSF_FRAGMENT_FEC_LENGTH_BYTES = M17_LSF_FRAGMENT_FEC_LENGTH_BITS / 8U; +const uint32_t M17_LSF_FRAGMENT_FEC_LENGTH_BITS = M17_LSF_FRAGMENT_LENGTH_BITS * 2U; +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 unsigned int M17_LICH_FRAGMENT_FEC_LENGTH_BYTES = M17_LICH_FRAGMENT_FEC_LENGTH_BITS / 8U; +const uint32_t M17_LICH_FRAGMENT_FEC_LENGTH_BITS = M17_LICH_FRAGMENT_LENGTH_BITS * 2U; +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 unsigned int M17_PAYLOAD_LENGTH_BYTES = M17_PAYLOAD_LENGTH_BITS / 8U; +const uint32_t M17_PAYLOAD_LENGTH_BITS = 128U; +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 unsigned int M17_META_LENGTH_BITS = 112U; -const unsigned int M17_META_LENGTH_BYTES = M17_META_LENGTH_BITS / 8U; +const uint8_t M17_NULL_NONCE[] = {0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U}; +const uint32_t M17_META_LENGTH_BITS = 112U; +const uint32_t M17_META_LENGTH_BYTES = M17_META_LENGTH_BITS / 8U; -const unsigned int M17_FN_LENGTH_BITS = 16U; -const unsigned int M17_FN_LENGTH_BYTES = M17_FN_LENGTH_BITS / 8U; +const uint32_t M17_FN_LENGTH_BITS = 16U; +const uint32_t M17_FN_LENGTH_BYTES = M17_FN_LENGTH_BITS / 8U; -const unsigned int M17_CRC_LENGTH_BITS = 16U; -const unsigned int M17_CRC_LENGTH_BYTES = M17_CRC_LENGTH_BITS / 8U; +const uint32_t M17_CRC_LENGTH_BITS = 16U; +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 unsigned char M17_1600_SILENCE[] = {0x0CU, 0x41U, 0x09U, 0x03U, 0x0CU, 0x41U, 0x09U, 0x03U}; +const uint8_t M17_3200_SILENCE[] = {0x01U, 0x00U, 0x09U, 0x43U, 0x9CU, 0xE4U, 0x21U, 0x08U}; +const uint8_t M17_1600_SILENCE[] = {0x0CU, 0x41U, 0x09U, 0x03U, 0x0CU, 0x41U, 0x09U, 0x03U}; -const unsigned char M17_PACKET_TYPE = 0U; -const unsigned char M17_STREAM_TYPE = 1U; +const uint8_t M17_PACKET_TYPE = 0U; +const uint8_t M17_STREAM_TYPE = 1U; -const unsigned char M17_DATA_TYPE_DATA = 0x01U; -const unsigned char M17_DATA_TYPE_VOICE = 0x02U; -const unsigned char M17_DATA_TYPE_VOICE_DATA = 0x03U; +const uint8_t M17_DATA_TYPE_DATA = 0x01U; +const uint8_t M17_DATA_TYPE_VOICE = 0x02U; +const uint8_t M17_DATA_TYPE_VOICE_DATA = 0x03U; -const unsigned char M17_ENCRYPTION_TYPE_NONE = 0x00U; -const unsigned char M17_ENCRYPTION_TYPE_AES = 0x01U; -const unsigned char M17_ENCRYPTION_TYPE_SCRAMBLE = 0x02U; +const uint8_t M17_ENCRYPTION_TYPE_NONE = 0x00U; +const uint8_t M17_ENCRYPTION_TYPE_AES = 0x01U; +const uint8_t M17_ENCRYPTION_TYPE_SCRAMBLE = 0x02U; -const unsigned char M17_ENCRYPTION_SUB_TYPE_TEXT = 0x00U; -const unsigned char M17_ENCRYPTION_SUB_TYPE_GPS = 0x01U; -const unsigned char M17_ENCRYPTION_SUB_TYPE_CALLSIGNS = 0x02U; +const uint8_t M17_ENCRYPTION_SUB_TYPE_TEXT = 0x00U; +const uint8_t M17_ENCRYPTION_SUB_TYPE_GPS = 0x01U; +const uint8_t M17_ENCRYPTION_SUB_TYPE_CALLSIGNS = 0x02U; #endif diff --git a/MMDVMDefines.h b/MMDVMDefines.h index 8140ae1..6de5498 100644 --- a/MMDVMDefines.h +++ b/MMDVMDefines.h @@ -1,5 +1,6 @@ #ifndef MMDVMDEFINES_H #define MMDVMDEFINES_H +#include enum HW_TYPE { HWT_MMDVM, @@ -32,77 +33,77 @@ enum B_STATUS { BS_MISSING }; -const unsigned char MMDVM_FRAME_START = 0xE0U; - -const unsigned char MMDVM_GET_VERSION = 0x00U; -const unsigned char MMDVM_GET_STATUS = 0x01U; -const unsigned char MMDVM_SET_CONFIG = 0x02U; -const unsigned char MMDVM_SET_MODE = 0x03U; -const unsigned char MMDVM_SET_FREQ = 0x04U; - -const unsigned char MMDVM_SEND_CWID = 0x0AU; - -const unsigned char MMDVM_DSTAR_HEADER = 0x10U; -const unsigned char MMDVM_DSTAR_DATA = 0x11U; -const unsigned char MMDVM_DSTAR_LOST = 0x12U; -const unsigned char MMDVM_DSTAR_EOT = 0x13U; - -const unsigned char MMDVM_DMR_DATA1 = 0x18U; -const unsigned char MMDVM_DMR_LOST1 = 0x19U; -const unsigned char MMDVM_DMR_DATA2 = 0x1AU; -const unsigned char MMDVM_DMR_LOST2 = 0x1BU; -const unsigned char MMDVM_DMR_SHORTLC = 0x1CU; -const unsigned char MMDVM_DMR_START = 0x1DU; -const unsigned char MMDVM_DMR_ABORT = 0x1EU; - -const unsigned char MMDVM_YSF_DATA = 0x20U; -const unsigned char MMDVM_YSF_LOST = 0x21U; - -const unsigned char MMDVM_P25_HDR = 0x30U; -const unsigned char MMDVM_P25_LDU = 0x31U; -const unsigned char MMDVM_P25_LOST = 0x32U; - -const unsigned char MMDVM_NXDN_DATA = 0x40U; -const unsigned char MMDVM_NXDN_LOST = 0x41U; - -const unsigned char MMDVM_M17_LINK_SETUP = 0x45U; -const unsigned char MMDVM_M17_STREAM = 0x46U; -const unsigned char MMDVM_M17_PACKET = 0x47U; -const unsigned char MMDVM_M17_LOST = 0x48U; -const unsigned char MMDVM_M17_EOT = 0x49U; - -const unsigned char MMDVM_POCSAG_DATA = 0x50U; - -const unsigned char MMDVM_FM_PARAMS1 = 0x60U; -const unsigned char MMDVM_FM_PARAMS2 = 0x61U; -const unsigned char MMDVM_FM_PARAMS3 = 0x62U; - -const unsigned char MMDVM_ACK = 0x70U; -const unsigned char MMDVM_NAK = 0x7FU; - -const unsigned char MMDVM_SERIAL = 0x80U; - -const unsigned char MMDVM_TRANSPARENT = 0x90U; -const unsigned char MMDVM_QSO_INFO = 0x91U; - -const unsigned char MMDVM_DEBUG1 = 0xF1U; -const unsigned char MMDVM_DEBUG2 = 0xF2U; -const unsigned char MMDVM_DEBUG3 = 0xF3U; -const unsigned char MMDVM_DEBUG4 = 0xF4U; -const unsigned char MMDVM_DEBUG5 = 0xF5U; - -const unsigned int MAX_RESPONSES = 30U; - -const unsigned int BUFFER_LENGTH = 2000U; -const unsigned char MODE_IDLE = 0U; -const unsigned char MODE_DSTAR = 1U; -const unsigned char MODE_DMR = 2U; -const unsigned char MODE_YSF = 3U; -const unsigned char MODE_P25 = 4U; -const unsigned char MODE_NXDN = 5U; -const unsigned char MODE_M17 = 7U; -const unsigned char MODE_CW = 98U; -const unsigned char MODE_LOCKOUT = 99U; -const unsigned char MODE_ERROR = 100U; +const uint8_t MMDVM_FRAME_START = 0xE0U; + +const uint8_t MMDVM_GET_VERSION = 0x00U; +const uint8_t MMDVM_GET_STATUS = 0x01U; +const uint8_t MMDVM_SET_CONFIG = 0x02U; +const uint8_t MMDVM_SET_MODE = 0x03U; +const uint8_t MMDVM_SET_FREQ = 0x04U; + +const uint8_t MMDVM_SEND_CWID = 0x0AU; + +const uint8_t MMDVM_DSTAR_HEADER = 0x10U; +const uint8_t MMDVM_DSTAR_DATA = 0x11U; +const uint8_t MMDVM_DSTAR_LOST = 0x12U; +const uint8_t MMDVM_DSTAR_EOT = 0x13U; + +const uint8_t MMDVM_DMR_DATA1 = 0x18U; +const uint8_t MMDVM_DMR_LOST1 = 0x19U; +const uint8_t MMDVM_DMR_DATA2 = 0x1AU; +const uint8_t MMDVM_DMR_LOST2 = 0x1BU; +const uint8_t MMDVM_DMR_SHORTLC = 0x1CU; +const uint8_t MMDVM_DMR_START = 0x1DU; +const uint8_t MMDVM_DMR_ABORT = 0x1EU; + +const uint8_t MMDVM_YSF_DATA = 0x20U; +const uint8_t MMDVM_YSF_LOST = 0x21U; + +const uint8_t MMDVM_P25_HDR = 0x30U; +const uint8_t MMDVM_P25_LDU = 0x31U; +const uint8_t MMDVM_P25_LOST = 0x32U; + +const uint8_t MMDVM_NXDN_DATA = 0x40U; +const uint8_t MMDVM_NXDN_LOST = 0x41U; + +const uint8_t MMDVM_M17_LINK_SETUP = 0x45U; +const uint8_t MMDVM_M17_STREAM = 0x46U; +const uint8_t MMDVM_M17_PACKET = 0x47U; +const uint8_t MMDVM_M17_LOST = 0x48U; +const uint8_t MMDVM_M17_EOT = 0x49U; + +const uint8_t MMDVM_POCSAG_DATA = 0x50U; + +const uint8_t MMDVM_FM_PARAMS1 = 0x60U; +const uint8_t MMDVM_FM_PARAMS2 = 0x61U; +const uint8_t MMDVM_FM_PARAMS3 = 0x62U; + +const uint8_t MMDVM_ACK = 0x70U; +const uint8_t MMDVM_NAK = 0x7FU; + +const uint8_t MMDVM_SERIAL = 0x80U; + +const uint8_t MMDVM_TRANSPARENT = 0x90U; +const uint8_t MMDVM_QSO_INFO = 0x91U; + +const uint8_t MMDVM_DEBUG1 = 0xF1U; +const uint8_t MMDVM_DEBUG2 = 0xF2U; +const uint8_t MMDVM_DEBUG3 = 0xF3U; +const uint8_t MMDVM_DEBUG4 = 0xF4U; +const uint8_t MMDVM_DEBUG5 = 0xF5U; + +const uint32_t MAX_RESPONSES = 30U; + +const uint32_t BUFFER_LENGTH = 2000U; +const uint8_t MODE_IDLE = 0U; +const uint8_t MODE_DSTAR = 1U; +const uint8_t MODE_DMR = 2U; +const uint8_t MODE_YSF = 3U; +const uint8_t MODE_P25 = 4U; +const uint8_t MODE_NXDN = 5U; +const uint8_t MODE_M17 = 7U; +const uint8_t MODE_CW = 98U; +const uint8_t MODE_LOCKOUT = 99U; +const uint8_t MODE_ERROR = 100U; #endif // MMDVMDEFINES_H diff --git a/SHA256.cpp b/SHA256.cpp index b3366e0..17355b6 100644 --- a/SHA256.cpp +++ b/SHA256.cpp @@ -37,7 +37,7 @@ /* This array contains the bytes used to pad the buffer to the next 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, If your architecture allows unaligned access this is equivalent to * (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); @@ -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 must be in little endian byte order. */ -unsigned char* CSHA256::read(unsigned char* resbuf) +uint8_t* CSHA256::read(uint8_t* resbuf) { 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])); return resbuf; @@ -107,8 +107,8 @@ unsigned char* CSHA256::read(unsigned char* resbuf) void CSHA256::conclude() { /* Take yet unprocessed bytes into account. */ - unsigned int bytes = m_buflen; - unsigned int size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4; + uint32_t bytes = m_buflen; + uint32_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4; /* Now count remaining 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. Use set_uint32 rather than a simple assignment, to avoid risk of unaligned access. */ - set_uint32((unsigned char*)&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 - 2], SWAP((m_total[1] << 3) | (m_total[0] >> 29))); + set_uint32((uint8_t*)&m_buffer[size - 1], SWAP(m_total[0] << 3)); ::memcpy(&((char*)m_buffer)[bytes], fillbuf, (size - 2) * 4 - 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); @@ -140,7 +140,7 @@ unsigned char* CSHA256::finish(unsigned char* resbuf) result is always in little endian byte order, so that a byte-wise output yields to the wanted ASCII representation of the message 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(resblock != NULL); @@ -155,21 +155,21 @@ unsigned char* CSHA256::buffer(const unsigned char* buffer, unsigned int len, un 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); /* When we already have some bits in our internal buffer concatenate both inputs first. */ if (m_buflen != 0U) { - unsigned int left_over = m_buflen; - unsigned int add = 128U - left_over > len ? len : 128U - left_over; + uint32_t left_over = m_buflen; + uint32_t add = 128U - left_over > len ? len : 128U - left_over; ::memcpy(&((char*)m_buffer)[left_over], buffer, add); m_buflen += add; if (m_buflen > 64U) { - processBlock((unsigned char*)m_buffer, m_buflen & ~63U); + processBlock((uint8_t*)m_buffer, m_buflen & ~63U); m_buflen &= 63U; @@ -185,11 +185,11 @@ void CSHA256::processBytes(const unsigned char* buffer, unsigned int len) if (len >= 64U) { //#if !_STRING_ARCH_unaligned //# 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)) { // while (len > 64U) { // ::memcpy(m_buffer, buffer, 64U); -// processBlock((unsigned char*)m_buffer, 64U); +// processBlock((uint8_t*)m_buffer, 64U); // buffer += 64U; // len -= 64U; // } @@ -204,13 +204,13 @@ void CSHA256::processBytes(const unsigned char* buffer, unsigned int len) /* Move remaining bytes in internal buffer. */ if (len > 0U) { - unsigned int left_over = m_buflen; + uint32_t left_over = m_buflen; ::memcpy(&((char*)m_buffer)[left_over], buffer, len); left_over += len; if (left_over >= 64U) { - processBlock((unsigned char*)m_buffer, 64U); + processBlock((uint8_t*)m_buffer, 64U); left_over -= 64U; ::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. 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); 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; uint32_t x[16]; 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 t0, t1; /* 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); words++; } diff --git a/SHA256.h b/SHA256.h index 7c48f19..01d2bc7 100644 --- a/SHA256.h +++ b/SHA256.h @@ -35,35 +35,35 @@ public: initialization function update the context for the next LEN bytes starting at BUFFER. 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 initialization function update the context for the next LEN bytes starting at BUFFER. 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 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 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 always in little endian byte order, so that a byte-wise output yields 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 result is always in little endian byte order, so that a byte-wise output yields to the wanted ASCII representation of the message 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: uint32_t* m_state; uint32_t* m_total; - unsigned int m_buflen; + uint32_t m_buflen; uint32_t* m_buffer; void init(); diff --git a/YSFConvolution.cpp b/YSFConvolution.cpp index 8e40854..e4872a4 100644 --- a/YSFConvolution.cpp +++ b/YSFConvolution.cpp @@ -22,7 +22,7 @@ #include #include -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 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_TABLE2[] = {0U, 1U, 1U, 0U, 0U, 1U, 1U, 0U}; -const unsigned int NUM_OF_STATES_D2 = 8U; -const unsigned int NUM_OF_STATES = 16U; +const uint32_t NUM_OF_STATES_D2 = 8U; +const uint32_t NUM_OF_STATES = 16U; const uint32_t M = 2U; -const unsigned int K = 5U; +const uint32_t K = 5U; CYSFConvolution::CYSFConvolution() : m_metrics1(nullptr), @@ -96,7 +96,7 @@ void CYSFConvolution::decode(uint8_t s0, uint8_t s1) m_newMetrics = tmp; } -void CYSFConvolution::chainback(unsigned char* out, unsigned int nBits) +void CYSFConvolution::chainback(uint8_t* out, uint32_t nBits) { 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(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; 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 g1 = (d + d3 + d4) & 1; diff --git a/YSFConvolution.h b/YSFConvolution.h index 457103c..1f87ccd 100644 --- a/YSFConvolution.h +++ b/YSFConvolution.h @@ -28,9 +28,9 @@ public: void start(); 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: uint16_t* m_metrics1; diff --git a/YSFFICH.cpp b/YSFFICH.cpp index 475b8d5..4f6dbf4 100644 --- a/YSFFICH.cpp +++ b/YSFFICH.cpp @@ -26,12 +26,12 @@ #include #include -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 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, 2U, 42U, 82U, 122U, 162U, 4U, 44U, 84U, 124U, 164U, @@ -53,7 +53,7 @@ const unsigned int INTERLEAVE_TABLE[] = { 36U, 76U, 116U, 156U, 196U, 38U, 78U, 118U, 158U, 198U}; -const unsigned int YSF_SYNC_LENGTH_BYTES = 5U; +const uint32_t YSF_SYNC_LENGTH_BYTES = 5U; CYSFFICH::CYSFFICH() //m_fich(NULL) @@ -71,7 +71,7 @@ CYSFFICH::~CYSFFICH() //delete[] m_fich; } -bool CYSFFICH::decode(const unsigned char* bytes) +bool CYSFFICH::decode(const uint8_t* bytes) { assert(bytes != NULL); @@ -82,8 +82,8 @@ bool CYSFFICH::decode(const unsigned char* bytes) viterbi.start(); // Deinterleave the FICH and send bits to the Viterbi decoder - for (unsigned int i = 0U; i < 100U; i++) { - unsigned int n = INTERLEAVE_TABLE[i]; + for (uint32_t i = 0U; i < 100U; i++) { + uint32_t n = INTERLEAVE_TABLE[i]; uint8_t s0 = READ_BIT1(bytes, n) ? 1U : 0U; n++; @@ -92,13 +92,13 @@ bool CYSFFICH::decode(const unsigned char* bytes) viterbi.decode(s0, s1); } - unsigned char output[13U]; + uint8_t output[13U]; viterbi.chainback(output, 96U); - unsigned int b0 = CGolay24128::decode24128(output + 0U); - unsigned int b1 = CGolay24128::decode24128(output + 3U); - unsigned int b2 = CGolay24128::decode24128(output + 6U); - unsigned int b3 = CGolay24128::decode24128(output + 9U); + uint32_t b0 = CGolay24128::decode24128(output + 0U); + uint32_t b1 = CGolay24128::decode24128(output + 3U); + uint32_t b2 = CGolay24128::decode24128(output + 6U); + uint32_t b3 = CGolay24128::decode24128(output + 9U); m_fich[0U] = (b0 >> 4) & 0xFFU; 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); } -void CYSFFICH::encode(unsigned char* bytes) +void CYSFFICH::encode(uint8_t* bytes) { assert(bytes != NULL); @@ -119,17 +119,17 @@ void CYSFFICH::encode(unsigned char* bytes) CCRC::addCCITT162(m_fich, 6U); - unsigned int b0 = ((m_fich[0U] << 4) & 0xFF0U) | ((m_fich[1U] >> 4) & 0x00FU); - unsigned int b1 = ((m_fich[1U] << 8) & 0xF00U) | ((m_fich[2U] >> 0) & 0x0FFU); - unsigned int 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 b0 = ((m_fich[0U] << 4) & 0xFF0U) | ((m_fich[1U] >> 4) & 0x00FU); + uint32_t b1 = ((m_fich[1U] << 8) & 0xF00U) | ((m_fich[2U] >> 0) & 0x0FFU); + uint32_t b2 = ((m_fich[3U] << 4) & 0xFF0U) | ((m_fich[4U] >> 4) & 0x00FU); + uint32_t b3 = ((m_fich[4U] << 8) & 0xF00U) | ((m_fich[5U] >> 0) & 0x0FFU); - unsigned int c0 = CGolay24128::encode24128(b0); - unsigned int c1 = CGolay24128::encode24128(b1); - unsigned int c2 = CGolay24128::encode24128(b2); - unsigned int c3 = CGolay24128::encode24128(b3); + uint32_t c0 = CGolay24128::encode24128(b0); + uint32_t c1 = CGolay24128::encode24128(b1); + uint32_t c2 = CGolay24128::encode24128(b2); + uint32_t c3 = CGolay24128::encode24128(b3); - unsigned char conv[13U]; + uint8_t conv[13U]; conv[0U] = (c0 >> 16) & 0xFFU; conv[1U] = (c0 >> 8) & 0xFFU; conv[2U] = (c0 >> 0) & 0xFFU; @@ -145,12 +145,12 @@ void CYSFFICH::encode(unsigned char* bytes) conv[12U] = 0x00U; CYSFConvolution convolution; - unsigned char convolved[25U]; + uint8_t convolved[25U]; convolution.encode(conv, convolved, 100U); - unsigned int j = 0U; - for (unsigned int i = 0U; i < 100U; i++) { - unsigned int n = INTERLEAVE_TABLE[i]; + uint32_t j = 0U; + for (uint32_t i = 0U; i < 100U; i++) { + uint32_t n = INTERLEAVE_TABLE[i]; bool s0 = READ_BIT1(convolved, j) != 0U; 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; } -unsigned char CYSFFICH::getCS() const +uint8_t CYSFFICH::getCS() const { return (m_fich[0U] >> 4) & 0x03U; } -unsigned char CYSFFICH::getCM() const +uint8_t CYSFFICH::getCM() const { return (m_fich[0U] >> 2) & 0x03U; } -unsigned char CYSFFICH::getBN() const +uint8_t CYSFFICH::getBN() const { return m_fich[0U] & 0x03U; } -unsigned char CYSFFICH::getBT() const +uint8_t CYSFFICH::getBT() const { return (m_fich[1U] >> 6) & 0x03U; } -unsigned char CYSFFICH::getFN() const +uint8_t CYSFFICH::getFN() const { return (m_fich[1U] >> 3) & 0x07U; } -unsigned char CYSFFICH::getFT() const +uint8_t CYSFFICH::getFT() const { return m_fich[1U] & 0x07U; } -unsigned char CYSFFICH::getDT() const +uint8_t CYSFFICH::getDT() const { return m_fich[2U] & 0x03U; } -unsigned char CYSFFICH::getMR() const +uint8_t CYSFFICH::getMR() const { return (m_fich[2U] >> 3) & 0x03U; } @@ -225,42 +225,42 @@ bool CYSFFICH::getSQL() const return (m_fich[3U] & 0x80U) == 0x80U; } -unsigned char CYSFFICH::getSQ() const +uint8_t CYSFFICH::getSQ() const { return m_fich[3U] & 0x7FU; } -void CYSFFICH::setFI(unsigned char fi) +void CYSFFICH::setFI(uint8_t fi) { m_fich[0U] &= 0x3FU; 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] |= (cs << 4) & 0x30U; } -void CYSFFICH::setCM(unsigned char cm) +void CYSFFICH::setCM(uint8_t cm) { m_fich[0U] &= 0xF3U; 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] |= (fn << 3) & 0x38U; } -void CYSFFICH::setFT(unsigned char ft) +void CYSFFICH::setFT(uint8_t ft) { m_fich[1U] &= 0xF8U; m_fich[1U] |= ft & 0x07U; } -void CYSFFICH::setMR(unsigned char mr) +void CYSFFICH::setMR(uint8_t mr) { m_fich[2U] &= 0xC7U; m_fich[2U] |= (mr << 3) & 0x38U; @@ -282,7 +282,7 @@ void CYSFFICH::setDev(bool on) m_fich[2U] &= 0xBFU; } -void CYSFFICH::setDT(unsigned char dt) +void CYSFFICH::setDT(uint8_t dt) { m_fich[2U] &= 0xFCU; m_fich[2U] |= dt & 0x03U; @@ -296,25 +296,25 @@ void CYSFFICH::setSQL(bool on) m_fich[3U] &= 0x7FU; } -void CYSFFICH::setSQ(unsigned char sq) +void CYSFFICH::setSQ(uint8_t sq) { m_fich[3U] &= 0x80U; m_fich[3U] |= sq & 0x7FU; } -void CYSFFICH::setBN(unsigned char bn) +void CYSFFICH::setBN(uint8_t bn) { m_fich[0U] &= 0xFCU; m_fich[0U] |= bn & 0x03U; } -void CYSFFICH::setBT(unsigned char bt) +void CYSFFICH::setBT(uint8_t bt) { m_fich[1U] &= 0x3FU; m_fich[1U] |= (bt << 6) & 0xC0U; } -void CYSFFICH::load(const unsigned char* fich) +void CYSFFICH::load(const uint8_t* fich) { assert(fich != NULL); diff --git a/YSFFICH.h b/YSFFICH.h index 96c6e5f..30deaa0 100644 --- a/YSFFICH.h +++ b/YSFFICH.h @@ -19,49 +19,50 @@ #if !defined(YSFFICH_H) #define YSFFICH_H +#include class CYSFFICH { public: 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; - unsigned char getCS() const; - unsigned char getCM() const; - unsigned char getBN() const; - unsigned char getBT() const; - unsigned char getFN() const; - unsigned char getFT() const; - unsigned char getDT() const; - unsigned char getMR() const; + uint8_t getFI() const; + uint8_t getCS() const; + uint8_t getCM() const; + uint8_t getBN() const; + uint8_t getBT() const; + uint8_t getFN() const; + uint8_t getFT() const; + uint8_t getDT() const; + uint8_t getMR() const; bool getVoIP() const; bool getDev() const; bool getSQL() const; - unsigned char getSQ() const; + uint8_t getSQ() const; - void setFI(unsigned char fi); - void setCS(unsigned char cs); - void setCM(unsigned char cm); - void setFN(unsigned char fn); - void setFT(unsigned char ft); - void setBN(unsigned char bn); - void setBT(unsigned char bt); - void setDT(unsigned char dt); - void setMR(unsigned char mr); + void setFI(uint8_t fi); + void setCS(uint8_t cs); + void setCM(uint8_t cm); + void setFN(uint8_t fn); + void setFT(uint8_t ft); + void setBN(uint8_t bn); + void setBT(uint8_t bt); + void setDT(uint8_t dt); + void setMR(uint8_t mr); void setVoIP(bool set); void setDev(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: - unsigned char m_fich[6U]; - //m_fich = new unsigned char[6U]; + uint8_t m_fich[6U]; + //m_fich = new uint8_t[6U]; }; #endif diff --git a/audioengine.cpp b/audioengine.cpp index 31c98e2..b35acbd 100644 --- a/audioengine.cpp +++ b/audioengine.cpp @@ -157,6 +157,7 @@ void AudioEngine::start_capture() m_audioinq.clear(); if(m_in != nullptr){ 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())); } } @@ -192,7 +193,7 @@ void AudioEngine::input_data_received() /* fprintf(stderr, "AUDIOIN: "); 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"); fflush(stderr); diff --git a/cbptc19696.h b/cbptc19696.h index a4e890b..d94fc81 100644 --- a/cbptc19696.h +++ b/cbptc19696.h @@ -18,7 +18,7 @@ #if !defined(BPTC19696_H) #define BPTC19696_H -#include +#include class CBPTC19696 { diff --git a/cgolay2087.cpp b/cgolay2087.cpp index 7ff6f92..1104b98 100644 --- a/cgolay2087.cpp +++ b/cgolay2087.cpp @@ -21,7 +21,7 @@ #include #include -const unsigned int ENCODING_TABLE_2087[] = +const uint32_t ENCODING_TABLE_2087[] = {0x0000U, 0xB08EU, 0xE093U, 0x501DU, 0x70A9U, 0xC027U, 0x903AU, 0x20B4U, 0x60DCU, 0xD052U, 0x804FU, 0x30C1U, 0x1075U, 0xA0FBU, 0xF0E6U, 0x4068U, 0x7036U, 0xC0B8U, 0x90A5U, 0x202BU, 0x009FU, 0xB011U, 0xE00CU, 0x5082U, 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, 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, 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, @@ -210,7 +210,7 @@ const unsigned int DECODING_TABLE_1987[] = #define MASK8 0xfffff800 /* auxiliary vector for testing */ #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 * 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. */ { - unsigned int aux = X18; + uint32_t aux = X18; if (pattern >= X11) { while (pattern & MASK8) { @@ -235,13 +235,13 @@ unsigned int CGolay2087::getSyndrome1987(unsigned int pattern) return pattern; } -unsigned char CGolay2087::decode(const unsigned char* data) +uint8_t CGolay2087::decode(const uint8_t* data) { assert(data != NULL); - unsigned int code = (data[0U] << 11) + (data[1U] << 3) + (data[2U] >> 5); - unsigned int syndrome = getSyndrome1987(code); - unsigned int error_pattern = DECODING_TABLE_1987[syndrome]; + uint32_t code = (data[0U] << 11) + (data[1U] << 3) + (data[2U] >> 5); + uint32_t syndrome = getSyndrome1987(code); + uint32_t error_pattern = DECODING_TABLE_1987[syndrome]; if (error_pattern != 0x00U) code ^= error_pattern; @@ -249,13 +249,13 @@ unsigned char CGolay2087::decode(const unsigned char* data) return code >> 11; } -void CGolay2087::encode(unsigned char* data) +void CGolay2087::encode(uint8_t* data) { 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[2U] = cksum >> 8; diff --git a/cgolay2087.h b/cgolay2087.h index 22c5c16..495063d 100644 --- a/cgolay2087.h +++ b/cgolay2087.h @@ -18,15 +18,16 @@ #ifndef Golay2087_H #define Golay2087_H +#include class CGolay2087 { 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: - static unsigned int getSyndrome1987(unsigned int pattern); + static uint32_t getSyndrome1987(uint32_t pattern); }; #endif diff --git a/crs129.cpp b/crs129.cpp index 182a438..fca5569 100644 --- a/crs129.cpp +++ b/crs129.cpp @@ -22,15 +22,15 @@ #include #include -const unsigned int NPAR = 3U; +const uint32_t NPAR = 3U; /* Maximum degree of various polynomials. */ -//const unsigned int MAXDEG = NPAR * 2U; +//const uint32_t MAXDEG = NPAR * 2U; /* 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, 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, @@ -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, 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, 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, @@ -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}; /* 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; + } - unsigned int i = LOG_TABLE[a]; - unsigned int j = LOG_TABLE[b]; + uint32_t i = LOG_TABLE[a]; + uint32_t j = LOG_TABLE[b]; 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. */ -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(parity != NULL); - for (unsigned int i = 0U; i < NPAR + 1U; i++) + for (uint32_t i = 0U; i < NPAR + 1U; i++) parity[i] = 0x00U; - for (unsigned int i = 0U; i < nbytes; i++) { - unsigned char dbyte = msg[i] ^ parity[NPAR - 1U]; + for (uint32_t i = 0U; i < nbytes; i++) { + uint8_t dbyte = msg[i] ^ parity[NPAR - 1U]; for (int j = NPAR - 1; j > 0; j--) 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 -bool CRS129::check(const unsigned char* in) +bool CRS129::check(const uint8_t* in) { assert(in != NULL); - unsigned char parity[4U]; + uint8_t parity[4U]; encode(in, 9U, parity); return in[9U] == parity[2U] && in[10U] == parity[1U] && in[11U] == parity[0U]; diff --git a/crs129.h b/crs129.h index 57fb848..5c9ef8d 100644 --- a/crs129.h +++ b/crs129.h @@ -18,13 +18,13 @@ #if !defined(RS129_H) #define RS129_H +#include class CRS129 { public: - static bool check(const unsigned char* in); - - static void encode(const unsigned char* msg, unsigned int nbytes, unsigned char* parity); + static bool check(const uint8_t* in); + static void encode(const uint8_t* msg, uint32_t nbytes, uint8_t* parity); }; #endif diff --git a/dcs.h b/dcs.h index eb2c9d5..788d912 100644 --- a/dcs.h +++ b/dcs.h @@ -26,7 +26,7 @@ class DCS : public Mode public: DCS(); ~DCS(); - unsigned char * get_frame(unsigned char *ambe); + uint8_t * get_frame(uint8_t *ambe); private: QString m_txusrtxt; uint8_t packet_size; diff --git a/dmr.cpp b/dmr.cpp index 6b05aa4..ebd9f42 100755 --- a/dmr.cpp +++ b/dmr.cpp @@ -24,7 +24,7 @@ #include "CRCenc.h" #include "MMDVMDefines.h" -#define DEBUG +//#define DEBUG const uint32_t ENCODING_TABLE_1676[] = {0x0000U, 0x0273U, 0x04E5U, 0x0696U, 0x09C9U, 0x0BBAU, 0x0D2CU, 0x0F5FU, 0x11E2U, 0x1391U, 0x1507U, 0x1774U, @@ -88,7 +88,7 @@ void DMR::process_udp() #ifdef DEBUG fprintf(stderr, "RECV: "); 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"); fflush(stderr); @@ -119,7 +119,7 @@ void DMR::process_udp() out[5] = (m_essid >> 16) & 0xff; out[6] = (m_essid >> 8) & 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; case DMR_AUTH: out.clear(); @@ -284,7 +284,7 @@ void DMR::process_udp() if(out.size() > 0){ fprintf(stderr, "SEND: "); 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"); fflush(stderr); @@ -352,7 +352,7 @@ void DMR::hostname_lookup(QHostInfo i) #ifdef DEBUG fprintf(stderr, "CONN: "); 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"); fflush(stderr); @@ -373,7 +373,7 @@ void DMR::send_ping() #ifdef DEBUG fprintf(stderr, "PING: "); 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"); fflush(stderr); @@ -396,7 +396,7 @@ void DMR::send_disconnect() #ifdef DEBUG fprintf(stderr, "SEND: "); 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"); fflush(stderr); @@ -440,7 +440,7 @@ void DMR::process_modem_data(QByteArray d) #ifdef DEBUG fprintf(stderr, "SEND:%d: ", txdata.size()); 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"); fflush(stderr); @@ -560,14 +560,14 @@ void DMR::send_frame() #ifdef DEBUG fprintf(stderr, "SEND:%d: ", txdata.size()); 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"); fflush(stderr); #endif } -unsigned char * DMR::get_eot() +uint8_t * DMR::get_eot() { encode_header(DT_TERMINATOR_WITH_LC); m_dmrcnt = 0; @@ -625,7 +625,7 @@ void DMR::encode_header(uint8_t t) void DMR::encode_data() { - unsigned int n_dmr = (m_dmrcnt - 1) % 6U; + uint32_t n_dmr = (m_dmrcnt - 1) % 6U; if (!n_dmr) { m_dataType = DT_VOICE_SYNC; diff --git a/droidstar.cpp b/droidstar.cpp index bb3e4de..d750c71 100644 --- a/droidstar.cpp +++ b/droidstar.cpp @@ -333,9 +333,6 @@ void DroidStar::process_connect() m_modethread = new QThread; 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); - if(m_protocol == "DMR"){ - - } 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); @@ -357,6 +354,12 @@ void DroidStar::process_connect() 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(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"){ QString dmrpass = sl.at(2).simplified(); diff --git a/droidstar.h b/droidstar.h index 9099856..3e408b5 100644 --- a/droidstar.h +++ b/droidstar.h @@ -330,7 +330,7 @@ private: int m_iaxport; bool m_settings_processed; 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; QString m_errortxt; bool m_xrf2ref; diff --git a/iax.cpp b/iax.cpp index 0abb8d2..942e3f1 100644 --- a/iax.cpp +++ b/iax.cpp @@ -22,7 +22,7 @@ #else #include #endif -#define DEBUG +//#define DEBUG #ifdef USE_FLITE extern "C" { diff --git a/m17.cpp b/m17.cpp index f4379be..ed50f2e 100755 --- a/m17.cpp +++ b/m17.cpp @@ -26,7 +26,7 @@ #define M17CHARACTERS " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-/." -#define DEBUG +//#define DEBUG const uint8_t SCRAMBLER[] = { 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); - unsigned int offset = 0U; - unsigned int MASK = 0x800U; + uint32_t offset = 0U; + uint32_t MASK = 0x800U; for (uint32_t i = 0U; i < (M17_LICH_FRAGMENT_LENGTH_BITS / 4U); i++, offset++, MASK >>= 1) { bool b = (frag1 & MASK) == MASK; WRITE_BIT(data, offset, b); diff --git a/mode.cpp b/mode.cpp index 3f56456..05a30c7 100644 --- a/mode.cpp +++ b/mode.cpp @@ -119,6 +119,7 @@ void Mode::init(QString callsign, uint32_t dmrid, char module, QString refname, #else m_rxtimerint = 20; #endif + m_txtimerint = 19; #ifdef USE_FLITE flite_init(); voice_slt = register_cmu_us_slt(nullptr); diff --git a/nxdn.cpp b/nxdn.cpp index fa2b807..41f96d2 100755 --- a/nxdn.cpp +++ b/nxdn.cpp @@ -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_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 READ_BIT1(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7]) @@ -62,7 +62,7 @@ void NXDN::process_udp() #ifdef DEBUG fprintf(stderr, "RECV: "); 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"); fflush(stderr); @@ -227,7 +227,7 @@ void NXDN::hostname_lookup(QHostInfo i) #ifdef DEBUG fprintf(stderr, "CONN: "); 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"); fflush(stderr); @@ -251,7 +251,7 @@ void NXDN::send_ping() #ifdef DEBUG fprintf(stderr, "PING: "); 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"); fflush(stderr); @@ -274,7 +274,7 @@ void NXDN::send_disconnect() #ifdef DEBUG fprintf(stderr, "SEND: "); 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"); fflush(stderr); @@ -339,7 +339,7 @@ void NXDN::transmit() void NXDN::send_frame() { QByteArray txdata; - unsigned char *temp_nxdn; + uint8_t *temp_nxdn; if(m_tx){ m_modeinfo.stream_state = TRANSMITTING; temp_nxdn = get_frame(); @@ -348,7 +348,7 @@ void NXDN::send_frame() fprintf(stderr, "SEND:%d: ", txdata.size()); 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"); fflush(stderr); @@ -522,7 +522,7 @@ void NXDN::deinterleave_ambe(uint8_t *d) 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; } @@ -639,7 +639,7 @@ void NXDN::encode_crc6(uint8_t *d, uint8_t len) { 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 bit2 = (crc & 0x20U) == 0x20U; crc <<= 1; diff --git a/nxdn.h b/nxdn.h index afb5413..a146a2b 100644 --- a/nxdn.h +++ b/nxdn.h @@ -27,8 +27,8 @@ class NXDN : public Mode public: NXDN(); ~NXDN(); - unsigned char * get_frame(); - unsigned char * get_eot(){m_eot = true; return get_frame();} + uint8_t * get_frame(); + uint8_t * get_eot(){m_eot = true; return get_frame();} void set_hwtx(bool hw){m_hwtx = hw;} private slots: void process_udp(); diff --git a/p25.cpp b/p25.cpp index a93b352..61d0355 100755 --- a/p25.cpp +++ b/p25.cpp @@ -21,25 +21,25 @@ //#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 unsigned char 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 unsigned char 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 unsigned char 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 unsigned char 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 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 unsigned char 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 unsigned char 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 unsigned char 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 unsigned char 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 unsigned char REC80[] = {0x80U, 0x00U, 0x00U, 0x00U, 0x00U, 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 uint8_t REC63[] = {0x63U, 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 uint8_t REC65[] = {0x65U, 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 uint8_t REC67[] = {0x67U, 0xF0U, 0x9DU, 0x6AU, 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 uint8_t REC69[] = {0x69U, 0xE0U, 0xEBU, 0x7BU, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U}; +const uint8_t REC6A[] = {0x6AU, 0x00U, 0x00U, 0x02U, 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 uint8_t REC6C[] = {0x6CU, 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 uint8_t REC6E[] = {0x6EU, 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 uint8_t REC70[] = {0x70U, 0x00U, 0x00U, 0x00U, 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 uint8_t REC72[] = {0x72U, 0x9BU, 0xDCU, 0x75U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U}; +const uint8_t REC73[] = {0x73U, 0x00U, 0x00U, 0x02U, 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]) @@ -67,7 +67,7 @@ void P25::process_udp() #ifdef DEBUG fprintf(stderr, "RCCV: "); 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"); fflush(stderr); @@ -188,7 +188,7 @@ void P25::hostname_lookup(QHostInfo i) #ifdef DEBUG fprintf(stderr, "CONN: "); 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"); fflush(stderr); @@ -206,7 +206,7 @@ void P25::send_ping() #ifdef DEBUG fprintf(stderr, "PING: "); 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"); fflush(stderr); @@ -223,7 +223,7 @@ void P25::send_disconnect() #ifdef DEBUG fprintf(stderr, "SEND: "); 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"); fflush(stderr); @@ -406,7 +406,7 @@ void P25::transmit() #ifdef DEBUG fprintf(stderr, "SEND: "); 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"); fflush(stderr); diff --git a/ref.cpp b/ref.cpp index b863191..6b4b85e 100755 --- a/ref.cpp +++ b/ref.cpp @@ -22,10 +22,10 @@ //#define DEBUG -const unsigned char MMDVM_DSTAR_HEADER = 0x10U; -const unsigned char MMDVM_DSTAR_DATA = 0x11U; -const unsigned char MMDVM_DSTAR_LOST = 0x12U; -const unsigned char MMDVM_DSTAR_EOT = 0x13U; +const uint8_t MMDVM_DSTAR_HEADER = 0x10U; +const uint8_t MMDVM_DSTAR_DATA = 0x11U; +const uint8_t MMDVM_DSTAR_LOST = 0x12U; +const uint8_t MMDVM_DSTAR_EOT = 0x13U; REF::REF() { @@ -45,14 +45,14 @@ void REF::process_udp() static bool sd_sync = 0; static int sd_seq = 0; 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()); m_udp->readDatagram(buf.data(), buf.size(), &sender, &senderPort); #ifdef DEBUG fprintf(stderr, "RECV: "); 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"); fflush(stderr); @@ -80,7 +80,7 @@ void REF::process_udp() if(out.size()){ fprintf(stderr, "SEND: "); 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"); fflush(stderr); @@ -312,7 +312,7 @@ void REF::hostname_lookup(QHostInfo i) #ifdef DEBUG fprintf(stderr, "CONN: "); 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"); fflush(stderr); @@ -330,7 +330,7 @@ void REF::send_ping() #ifdef DEBUG fprintf(stderr, "PING: "); 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"); fflush(stderr); @@ -349,7 +349,7 @@ void REF::send_disconnect() #ifdef DEBUG fprintf(stderr, "SEND: "); 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"); fflush(stderr); @@ -417,7 +417,7 @@ void REF::start_tx() void REF::transmit() { - unsigned char ambe[9]; + uint8_t ambe[9]; uint8_t ambe_frame[72]; int16_t pcm[160]; memset(ambe_frame, 0, 72); @@ -511,117 +511,126 @@ void REF::send_frame(uint8_t *ambe) m_modeinfo.gw = m_txrptr1; m_modeinfo.gw2 = m_txrptr2; 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); +#ifdef DEBUG + fprintf(stderr, "SEND:%d: ", txdata.size()); + for(int i = 0; i < txdata.size(); ++i){ + fprintf(stderr, "%02x ", (uint8_t)txdata.data()[i]); + } + fprintf(stderr, "\n"); + fflush(stderr); +#endif } - else { - txdata.resize(29); - txdata[0] = 0x1d; - txdata[1] = 0x80; - txdata[2] = 0x44; - txdata[3] = 0x53; - txdata[4] = 0x56; - txdata[5] = 0x54; - txdata[6] = 0x20; - txdata[7] = 0x00; - txdata[8] = 0x00; - txdata[9] = 0x00; - txdata[10] = 0x20; - txdata[11] = 0x00; - txdata[12] = 0x02; - txdata[13] = 0x01; - txdata[14] = (txstreamid >> 8) & 0xff; - txdata[15] = txstreamid & 0xff; - txdata[16] = m_txcnt % 21; - memcpy(txdata.data() + 17, ambe, 9); - - m_modeinfo.frame_number = m_txcnt % 21; - - switch(txdata.data()[16]){ - case 0: - txdata[26] = 0x55; - txdata[27] = 0x2d; - txdata[28] = 0x16; - break; - case 1: - txdata[26] = 0x40 ^ 0x70; - txdata[27] = m_txusrtxt.toLocal8Bit().data()[0] ^ 0x4f; - txdata[28] = m_txusrtxt.toLocal8Bit().data()[1] ^ 0x93; - break; - case 2: - txdata[26] = m_txusrtxt.toLocal8Bit().data()[2] ^ 0x70; - txdata[27] = m_txusrtxt.toLocal8Bit().data()[3] ^ 0x4f; - txdata[28] = m_txusrtxt.toLocal8Bit().data()[4] ^ 0x93; - break; - case 3: - txdata[26] = 0x41 ^ 0x70; - txdata[27] = m_txusrtxt.toLocal8Bit().data()[5] ^ 0x4f; - txdata[28] = m_txusrtxt.toLocal8Bit().data()[6] ^ 0x93; - break; - case 4: - txdata[26] = m_txusrtxt.toLocal8Bit().data()[7] ^ 0x70; - txdata[27] = m_txusrtxt.toLocal8Bit().data()[8] ^ 0x4f; - txdata[28] = m_txusrtxt.toLocal8Bit().data()[9] ^ 0x93; - break; - case 5: - txdata[26] = 0x42 ^ 0x70; - txdata[27] = m_txusrtxt.toLocal8Bit().data()[10] ^ 0x4f; - txdata[28] = m_txusrtxt.toLocal8Bit().data()[11] ^ 0x93; - break; - case 6: - txdata[26] = m_txusrtxt.toLocal8Bit().data()[12] ^ 0x70; - txdata[27] = m_txusrtxt.toLocal8Bit().data()[13] ^ 0x4f; - txdata[28] = m_txusrtxt.toLocal8Bit().data()[14] ^ 0x93; - break; - case 7: - txdata[26] = 0x43 ^ 0x70; - txdata[27] = m_txusrtxt.toLocal8Bit().data()[15] ^ 0x4f; - txdata[28] = m_txusrtxt.toLocal8Bit().data()[16] ^ 0x93; - break; - case 8: - txdata[26] = m_txusrtxt.toLocal8Bit().data()[17] ^ 0x70; - txdata[27] = m_txusrtxt.toLocal8Bit().data()[18] ^ 0x4f; - txdata[28] = m_txusrtxt.toLocal8Bit().data()[19] ^ 0x93; - break; - default: - txdata[26] = 0x16; - txdata[27] = 0x29; - txdata[28] = 0xf5; - break; - } - - if((m_txcnt % 21) == 0){ - sendheader = 1; - } - - if(m_tx){ - m_txcnt++; - } - else{ - qDebug() << "TX stopped"; - //txdata[0] = 0x20; - //txdata[6] = 0x20; - //txdata[16] = m_txcnt % 21; - memset(txdata.data() + 17, 0, 9); - txdata[26] = 0x55; - txdata[27] = 0x55; - txdata[28] = 0x55; - txdata.append(0x55); - txdata.append(0xc8); - txdata.append(0x7a); - m_txcnt = 0; - txstreamid = 0; - m_modeinfo.streamid = 0; - sendheader = 1; - m_txtimer->stop(); - if((m_ttsid == 0) && (m_modeinfo.stream_state == TRANSMITTING) ){ - m_audio->stop_capture(); - } - m_ttscnt = 0; - m_modeinfo.stream_state = STREAM_IDLE; + txdata.resize(29); + txdata[0] = 0x1d; + txdata[1] = 0x80; + txdata[2] = 0x44; + txdata[3] = 0x53; + txdata[4] = 0x56; + txdata[5] = 0x54; + txdata[6] = 0x20; + txdata[7] = 0x00; + txdata[8] = 0x00; + txdata[9] = 0x00; + txdata[10] = 0x20; + txdata[11] = 0x00; + txdata[12] = 0x02; + txdata[13] = 0x01; + txdata[14] = (txstreamid >> 8) & 0xff; + txdata[15] = txstreamid & 0xff; + txdata[16] = m_txcnt; + memcpy(txdata.data() + 17, ambe, 9); + + m_modeinfo.frame_number = m_txcnt; + + switch(txdata.data()[16]){ + case 0: + txdata[26] = 0x55; + txdata[27] = 0x2d; + txdata[28] = 0x16; + break; + case 1: + txdata[26] = 0x40 ^ 0x70; + txdata[27] = m_txusrtxt.toLocal8Bit().data()[0] ^ 0x4f; + txdata[28] = m_txusrtxt.toLocal8Bit().data()[1] ^ 0x93; + break; + case 2: + txdata[26] = m_txusrtxt.toLocal8Bit().data()[2] ^ 0x70; + txdata[27] = m_txusrtxt.toLocal8Bit().data()[3] ^ 0x4f; + txdata[28] = m_txusrtxt.toLocal8Bit().data()[4] ^ 0x93; + break; + case 3: + txdata[26] = 0x41 ^ 0x70; + txdata[27] = m_txusrtxt.toLocal8Bit().data()[5] ^ 0x4f; + txdata[28] = m_txusrtxt.toLocal8Bit().data()[6] ^ 0x93; + break; + case 4: + txdata[26] = m_txusrtxt.toLocal8Bit().data()[7] ^ 0x70; + txdata[27] = m_txusrtxt.toLocal8Bit().data()[8] ^ 0x4f; + txdata[28] = m_txusrtxt.toLocal8Bit().data()[9] ^ 0x93; + break; + case 5: + txdata[26] = 0x42 ^ 0x70; + txdata[27] = m_txusrtxt.toLocal8Bit().data()[10] ^ 0x4f; + txdata[28] = m_txusrtxt.toLocal8Bit().data()[11] ^ 0x93; + break; + case 6: + txdata[26] = m_txusrtxt.toLocal8Bit().data()[12] ^ 0x70; + txdata[27] = m_txusrtxt.toLocal8Bit().data()[13] ^ 0x4f; + txdata[28] = m_txusrtxt.toLocal8Bit().data()[14] ^ 0x93; + break; + case 7: + txdata[26] = 0x43 ^ 0x70; + txdata[27] = m_txusrtxt.toLocal8Bit().data()[15] ^ 0x4f; + txdata[28] = m_txusrtxt.toLocal8Bit().data()[16] ^ 0x93; + break; + case 8: + txdata[26] = m_txusrtxt.toLocal8Bit().data()[17] ^ 0x70; + txdata[27] = m_txusrtxt.toLocal8Bit().data()[18] ^ 0x4f; + txdata[28] = m_txusrtxt.toLocal8Bit().data()[19] ^ 0x93; + break; + default: + txdata[26] = 0x16; + txdata[27] = 0x29; + txdata[28] = 0xf5; + break; + } + + if(m_txcnt == 20){ + sendheader = 1; + m_txcnt = 0; + } + else{ + ++m_txcnt; + } + + if(!m_tx){ + qDebug() << "TX stopped"; + txdata[0] = 0x20; + //txdata[6] = 0x20; + //txdata[16] = m_txcnt % 21; + txdata[16] = 0x40 | txdata[16]; + memset(txdata.data() + 17, 0, 9); + txdata[26] = 0x55; + txdata[27] = 0x55; + txdata[28] = 0x55; + txdata.append(0x55); + txdata.append(0xc8); + txdata.append(0x7a); + m_txcnt = 0; + txstreamid = 0; + m_modeinfo.streamid = 0; + sendheader = 1; + m_txtimer->stop(); + + if((m_ttsid == 0) && (m_modeinfo.stream_state == TRANSMITTING) ){ + m_audio->stop_capture(); } + m_ttscnt = 0; + m_modeinfo.stream_state = STREAM_IDLE; } m_udp->writeDatagram(txdata, m_address, m_modeinfo.port); @@ -630,7 +639,7 @@ void REF::send_frame(uint8_t *ambe) #ifdef DEBUG fprintf(stderr, "SEND:%d: ", txdata.size()); 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"); fflush(stderr); diff --git a/ref.h b/ref.h index ce14062..93de776 100644 --- a/ref.h +++ b/ref.h @@ -26,7 +26,7 @@ class REF : public Mode public: REF(); ~REF(); - unsigned char * get_frame(unsigned char *ambe); + uint8_t * get_frame(uint8_t *ambe); private: uint8_t packet_size; private slots: diff --git a/xrf.cpp b/xrf.cpp index 9c79358..e399397 100755 --- a/xrf.cpp +++ b/xrf.cpp @@ -46,7 +46,7 @@ void XRF::process_udp() #ifdef DEBUG fprintf(stderr, "RECV: "); 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"); fflush(stderr); @@ -266,7 +266,7 @@ void XRF::hostname_lookup(QHostInfo i) #ifdef DEBUG fprintf(stderr, "CONN: "); 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"); fflush(stderr); @@ -284,7 +284,7 @@ void XRF::send_ping() #ifdef DEBUG fprintf(stderr, "PING: "); 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"); fflush(stderr); @@ -303,7 +303,7 @@ void XRF::send_disconnect() #ifdef DEBUG fprintf(stderr, "SEND: "); 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"); fflush(stderr); @@ -370,7 +370,7 @@ void XRF::start_tx() void XRF::transmit() { - unsigned char ambe[9]; + uint8_t ambe[9]; uint8_t ambe_frame[72]; int16_t pcm[160]; memset(ambe_frame, 0, 72); @@ -563,7 +563,7 @@ void XRF::send_frame(uint8_t *ambe) #ifdef DEBUG fprintf(stderr, "SEND:%d: ", txdata.size()); 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"); fflush(stderr); diff --git a/xrf.h b/xrf.h index 2481355..e22e4db 100644 --- a/xrf.h +++ b/xrf.h @@ -26,7 +26,7 @@ class XRF : public Mode public: XRF(); ~XRF(); - unsigned char * get_frame(unsigned char *ambe); + uint8_t * get_frame(uint8_t *ambe); private: QString m_txusrtxt; uint8_t packet_size;