mirror of
https://github.com/g4klx/MMDVMHost.git
synced 2025-12-06 05:32:00 +01:00
parent
5a22b3d0a6
commit
5b45767fea
30
NXDNCRC.cpp
30
NXDNCRC.cpp
|
|
@ -133,25 +133,6 @@ void CNXDNCRC::encodeCRC15(unsigned char* in, unsigned int length)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CNXDNCRC::checkLICHParity(unsigned char in)
|
|
||||||
{
|
|
||||||
bool newParity = createLICHParity(in);
|
|
||||||
|
|
||||||
bool oldParity = (in & 0x01U) == 0x01U;
|
|
||||||
|
|
||||||
return newParity == oldParity;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CNXDNCRC::encodeLICHParity(unsigned char& in)
|
|
||||||
{
|
|
||||||
bool parity = createLICHParity(in);
|
|
||||||
|
|
||||||
if (parity)
|
|
||||||
in |= 0x01U;
|
|
||||||
else
|
|
||||||
in &= 0xFEU;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t CNXDNCRC::createCRC6(const unsigned char* in, unsigned int length)
|
uint8_t CNXDNCRC::createCRC6(const unsigned char* in, unsigned int length)
|
||||||
{
|
{
|
||||||
uint8_t crc = 0x3FU;
|
uint8_t crc = 0x3FU;
|
||||||
|
|
@ -202,14 +183,3 @@ uint16_t CNXDNCRC::createCRC15(const unsigned char* in, unsigned int length)
|
||||||
|
|
||||||
return crc & 0x7FFFU;
|
return crc & 0x7FFFU;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CNXDNCRC::createLICHParity(unsigned char in)
|
|
||||||
{
|
|
||||||
switch (in & 0xF0U) {
|
|
||||||
case 0x80U:
|
|
||||||
case 0xB0U:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -33,14 +33,10 @@ public:
|
||||||
static bool checkCRC15(const unsigned char* in, unsigned int length);
|
static bool checkCRC15(const unsigned char* in, unsigned int length);
|
||||||
static void encodeCRC15(unsigned char* in, unsigned int length);
|
static void encodeCRC15(unsigned char* in, unsigned int length);
|
||||||
|
|
||||||
static bool checkLICHParity(unsigned char in);
|
|
||||||
static void encodeLICHParity(unsigned char& in);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static uint8_t createCRC6(const unsigned char* in, unsigned int length);
|
static uint8_t createCRC6(const unsigned char* in, unsigned int length);
|
||||||
static uint16_t createCRC12(const unsigned char* in, unsigned int length);
|
static uint16_t createCRC12(const unsigned char* in, unsigned int length);
|
||||||
static uint16_t createCRC15(const unsigned char* in, unsigned int length);
|
static uint16_t createCRC15(const unsigned char* in, unsigned int length);
|
||||||
static bool createLICHParity(unsigned char in);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
32
NXDNLICH.cpp
32
NXDNLICH.cpp
|
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
#include "NXDNDefines.h"
|
#include "NXDNDefines.h"
|
||||||
#include "NXDNLICH.h"
|
#include "NXDNLICH.h"
|
||||||
#include "NXDNCRC.h"
|
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
@ -51,26 +50,37 @@ bool CNXDNLICH::decode(const unsigned char* bytes)
|
||||||
{
|
{
|
||||||
assert(bytes != NULL);
|
assert(bytes != NULL);
|
||||||
|
|
||||||
unsigned int offset = NXDN_FSW_LENGTH_BITS;
|
bool b[8U];
|
||||||
for (unsigned int i = 0U; i < (NXDN_LICH_LENGTH_BITS / 2U); i++, offset += 2U) {
|
unsigned int offset1 = NXDN_FSW_LENGTH_BITS;
|
||||||
bool b = READ_BIT1(bytes, offset);
|
unsigned int offset2 = 7U;
|
||||||
WRITE_BIT1(m_lich, i, b);
|
for (unsigned int i = 0U; i < (NXDN_LICH_LENGTH_BITS / 2U); i++, offset1 += 2U, offset2--) {
|
||||||
|
b[offset2] = READ_BIT1(bytes, offset1);
|
||||||
|
WRITE_BIT1(m_lich, i, b[offset2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return CNXDNCRC::checkLICHParity(m_lich[0U]);
|
bool parity = b[7U] ^ b[6U] ^ b[5U] ^ b[4U];
|
||||||
|
|
||||||
|
if (parity != b[0U])
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CNXDNLICH::encode(unsigned char* bytes)
|
void CNXDNLICH::encode(unsigned char* bytes)
|
||||||
{
|
{
|
||||||
assert(bytes != NULL);
|
assert(bytes != NULL);
|
||||||
|
|
||||||
CNXDNCRC::encodeLICHParity(m_lich[0U]);
|
bool b[8U];
|
||||||
|
unsigned int offset = 7U;
|
||||||
|
for (unsigned int i = 0U; i < (NXDN_LICH_LENGTH_BITS / 2U); i++, offset--)
|
||||||
|
b[offset] = READ_BIT1(m_lich, i);
|
||||||
|
|
||||||
|
b[0U] = b[7U] ^ b[6U] ^ b[5U] ^ b[4U];
|
||||||
|
|
||||||
unsigned int offset1 = NXDN_FSW_LENGTH_BITS;
|
unsigned int offset1 = NXDN_FSW_LENGTH_BITS;
|
||||||
unsigned int offset2 = 7U;
|
unsigned int offset2 = 7U;
|
||||||
for (unsigned int i = 0U; i < (NXDN_LICH_LENGTH_BITS / 2U); i++, offset2--) {
|
for (unsigned int i = 0U; i < (NXDN_LICH_LENGTH_BITS / 2U); i++, offset2--) {
|
||||||
bool b = READ_BIT1(m_lich, offset2);
|
WRITE_BIT1(bytes, offset1, b[offset2]);
|
||||||
WRITE_BIT1(bytes, offset1, b);
|
|
||||||
offset1++;
|
offset1++;
|
||||||
WRITE_BIT1(bytes, offset1, true);
|
WRITE_BIT1(bytes, offset1, true);
|
||||||
offset1++;
|
offset1++;
|
||||||
|
|
@ -99,8 +109,6 @@ unsigned char CNXDNLICH::getDirection() const
|
||||||
|
|
||||||
unsigned char CNXDNLICH::getRaw() const
|
unsigned char CNXDNLICH::getRaw() const
|
||||||
{
|
{
|
||||||
CNXDNCRC::encodeLICHParity(m_lich[0U]);
|
|
||||||
|
|
||||||
return m_lich[0U];
|
return m_lich[0U];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,7 +127,7 @@ void CNXDNLICH::setFCT(unsigned char usc)
|
||||||
void CNXDNLICH::setOption(unsigned char option)
|
void CNXDNLICH::setOption(unsigned char option)
|
||||||
{
|
{
|
||||||
m_lich[0U] &= 0xF3U;
|
m_lich[0U] &= 0xF3U;
|
||||||
m_lich[0U] |= (option << 2) & 0x0CU;
|
m_lich[0u] |= (option << 2) & 0x0CU;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CNXDNLICH::setDirection(unsigned char direction)
|
void CNXDNLICH::setDirection(unsigned char direction)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue