Skip to content

Commit

Permalink
Opionally allow the checksum to be copied.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Feb 19, 2018
1 parent edbc42e commit 8290db8
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
10 changes: 8 additions & 2 deletions NXDNFACCH1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,17 @@ void CNXDNFACCH1::encode(unsigned char* data, unsigned int offset) const
}
}

void CNXDNFACCH1::getData(unsigned char* data) const
void CNXDNFACCH1::getData(unsigned char* data, bool checksum) const
{
assert(data != NULL);

::memcpy(data, m_data, 10U);
if (checksum) {
::memset(data, 0x00U, 12U);
::memcpy(data, m_data, 10U);
CNXDNCRC::encodeCRC12(data, 80U);
} else {
::memcpy(data, m_data, 10U);
}
}

void CNXDNFACCH1::setData(const unsigned char* data)
Expand Down
2 changes: 1 addition & 1 deletion NXDNFACCH1.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CNXDNFACCH1 {

void encode(unsigned char* data, unsigned int offset) const;

void getData(unsigned char* data) const;
void getData(unsigned char* data, bool checksum = false) const;

void setData(const unsigned char* data);

Expand Down
15 changes: 10 additions & 5 deletions NXDNSACCH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,19 @@ unsigned char CNXDNSACCH::getStructure() const
return (m_data[0U] >> 6) & 0x03U;
}

void CNXDNSACCH::getData(unsigned char* data) const
void CNXDNSACCH::getData(unsigned char* data, bool checksum) const
{
assert(data != NULL);

unsigned int offset = 8U;
for (unsigned int i = 0U; i < 18U; i++, offset++) {
bool b = READ_BIT1(m_data, offset);
WRITE_BIT1(data, i, b);
if (checksum) {
::memcpy(data, m_data, 4U);
CNXDNCRC::encodeCRC6(data, 26U);
} else {
unsigned int offset = 8U;
for (unsigned int i = 0U; i < 18U; i++, offset++) {
bool b = READ_BIT1(m_data, offset);
WRITE_BIT1(data, i, b);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion NXDNSACCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CNXDNSACCH {
unsigned char getRAN() const;
unsigned char getStructure() const;

void getData(unsigned char* data) const;
void getData(unsigned char* data, bool checksum = false) const;

void setRAN(unsigned char ran);
void setStructure(unsigned char structure);
Expand Down
10 changes: 8 additions & 2 deletions NXDNUDCH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,17 @@ unsigned char CNXDNUDCH::getRAN() const
return m_data[0U] & 0x3FU;
}

void CNXDNUDCH::getData(unsigned char* data) const
void CNXDNUDCH::getData(unsigned char* data, bool checksum) const
{
assert(data != NULL);

::memcpy(data, m_data + 1U, 22U);
if (checksum) {
::memset(data, 0x00U, 25U);
::memcpy(data, m_data, 23U);
CNXDNCRC::encodeCRC15(data, 184U);
} else {
::memcpy(data, m_data + 1U, 22U);
}
}

void CNXDNUDCH::setRAN(unsigned char ran)
Expand Down
2 changes: 1 addition & 1 deletion NXDNUDCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CNXDNUDCH {

unsigned char getRAN() const;

void getData(unsigned char* data) const;
void getData(unsigned char* data, bool checksum = false) const;

void setRAN(unsigned char ran);

Expand Down

0 comments on commit 8290db8

Please sign in to comment.