Skip to content

Commit

Permalink
Insert the correct bytes for data transmissions in the Icom protocol.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed May 17, 2018
1 parent 992b0f2 commit 02096f2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 15 deletions.
26 changes: 19 additions & 7 deletions NXDNControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ bool CNXDNControl::processVoice(unsigned char usc, unsigned char option, unsigne

scrambler(data + 2U);

writeNetwork(netData, true);
writeNetwork(netData, data[0U] == TAG_EOT ? NNMT_VOICE_TRAILER : NNMT_VOICE_HEADER);

#if defined(DUMP_NXDN)
writeFile(data + 2U);
Expand Down Expand Up @@ -424,7 +424,7 @@ bool CNXDNControl::processVoice(unsigned char usc, unsigned char option, unsigne

scrambler(start + 2U);

writeNetwork(netData, true);
writeNetwork(netData, NNMT_VOICE_HEADER);

#if defined(DUMP_NXDN)
writeFile(start + 2U);
Expand Down Expand Up @@ -529,7 +529,7 @@ bool CNXDNControl::processVoice(unsigned char usc, unsigned char option, unsigne

scrambler(data + 2U);

writeNetwork(netData, false);
writeNetwork(netData, NNMT_VOICE_BODY);

#if defined(DUMP_NXDN)
writeFile(data + 2U);
Expand Down Expand Up @@ -618,8 +618,10 @@ bool CNXDNControl::processData(unsigned char option, unsigned char *data)

udch.getRaw(netData + 1U);

unsigned char type = NXDN_MESSAGE_TYPE_DCALL_DATA;

if (validUDCH) {
unsigned char type = layer3.getMessageType();
type = layer3.getMessageType();
data[0U] = type == NXDN_MESSAGE_TYPE_TX_REL ? TAG_EOT : TAG_DATA;

udch.setRAN(m_ran);
Expand All @@ -631,7 +633,17 @@ bool CNXDNControl::processData(unsigned char option, unsigned char *data)

scrambler(data + 2U);

writeNetwork(netData, true);
switch (type) {
case NXDN_MESSAGE_TYPE_DCALL_HDR:
writeNetwork(netData, NNMT_DATA_HEADER);
break;
case NXDN_MESSAGE_TYPE_TX_REL:
writeNetwork(netData, NNMT_DATA_TRAILER);
break;
default:
writeNetwork(netData, NNMT_DATA_BODY);
break;
}

if (m_duplex)
writeQueueRF(data);
Expand Down Expand Up @@ -1005,7 +1017,7 @@ void CNXDNControl::writeQueueNet(const unsigned char *data)
m_queue.addData(data, len);
}

void CNXDNControl::writeNetwork(const unsigned char *data, bool single)
void CNXDNControl::writeNetwork(const unsigned char *data, NXDN_NETWORK_MESSAGE_TYPE type)
{
assert(data != NULL);

Expand All @@ -1015,7 +1027,7 @@ void CNXDNControl::writeNetwork(const unsigned char *data, bool single)
if (m_rfTimeoutTimer.isRunning() && m_rfTimeoutTimer.hasExpired())
return;

m_network->write(data, single);
m_network->write(data, type);
}

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

void writeQueueRF(const unsigned char* data);
void writeQueueNet(const unsigned char* data);
void writeNetwork(const unsigned char* data, bool single);
void writeNetwork(const unsigned char* data, NXDN_NETWORK_MESSAGE_TYPE type);
void writeNetwork();

void scrambler(unsigned char* data) const;
Expand Down
27 changes: 23 additions & 4 deletions NXDNNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool CNXDNNetwork::open()
return m_socket.open();
}

bool CNXDNNetwork::write(const unsigned char* data, bool single)
bool CNXDNNetwork::write(const unsigned char* data, NXDN_NETWORK_MESSAGE_TYPE type)
{
assert(data != NULL);

Expand All @@ -72,9 +72,28 @@ bool CNXDNNetwork::write(const unsigned char* data, bool single)
buffer[6U] = 0x08U;
buffer[7U] = 0xE0U;

buffer[37U] = 0x23U;
buffer[38U] = single ? 0x1CU : 0x10U;
buffer[39U] = 0x21U;
switch (type) {
case NNMT_VOICE_HEADER:
case NNMT_VOICE_TRAILER:
buffer[37U] = 0x23U;
buffer[38U] = 0x1CU;
buffer[39U] = 0x21U;
break;
case NNMT_VOICE_BODY:
buffer[37U] = 0x23U;
buffer[38U] = 0x10U;
buffer[39U] = 0x21U;
break;
case NNMT_DATA_HEADER:
case NNMT_DATA_BODY:
case NNMT_DATA_TRAILER:
buffer[37U] = 0x23U;
buffer[38U] = 0x02U;
buffer[39U] = 0x18U;
break;
default:
return false;
}

::memcpy(buffer + 40U, data, 33U);

Expand Down
11 changes: 10 additions & 1 deletion NXDNNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
#include <cstdint>
#include <string>

enum NXDN_NETWORK_MESSAGE_TYPE {
NNMT_VOICE_HEADER,
NNMT_VOICE_BODY,
NNMT_VOICE_TRAILER,
NNMT_DATA_HEADER,
NNMT_DATA_BODY,
NNMT_DATA_TRAILER
};

class CNXDNNetwork {
public:
CNXDNNetwork(const std::string& localAddress, unsigned int localPort, const std::string& gatewayAddress, unsigned int gatewayPort, bool debug);
Expand All @@ -36,7 +45,7 @@ class CNXDNNetwork {

void enable(bool enabled);

bool write(const unsigned char* data, bool single);
bool write(const unsigned char* data, NXDN_NETWORK_MESSAGE_TYPE type);

bool read(unsigned char* data);

Expand Down
2 changes: 0 additions & 2 deletions NXDNUDCH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ void CNXDNUDCH::getRaw(unsigned char* data) const

::memset(data, 0x00U, 25U);
::memcpy(data, m_data, 23U);

CNXDNCRC::encodeCRC15(data, 184U);
}

void CNXDNUDCH::setRAN(unsigned char ran)
Expand Down

0 comments on commit 02096f2

Please sign in to comment.