From 11b6cd7cf5eecf451cdf5e3dd38404c01ec4df48 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Wed, 14 Mar 2018 19:24:18 +0000 Subject: [PATCH] Fix small issues. --- NXDNGateway/NXDNGateway.cpp | 9 ++++++--- NXDNGateway/NXDNNetwork.cpp | 2 +- NXDNGateway/Voice.cpp | 28 +++++++++++++++++----------- NXDNGateway/Voice.h | 2 ++ NXDNReflector/NXCoreNetwork.cpp | 2 +- NXDNReflector/NXDNReflector.ini | 3 ++- README.md | 4 +++- 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/NXDNGateway/NXDNGateway.cpp b/NXDNGateway/NXDNGateway.cpp index eca6cf1..85677c6 100644 --- a/NXDNGateway/NXDNGateway.cpp +++ b/NXDNGateway/NXDNGateway.cpp @@ -268,6 +268,9 @@ void CNXDNGateway::run() if (currentId != 9999U) { LogMessage("Unlinked from reflector %u by %s", currentId, callsign.c_str()); + if (voice != NULL && dstId == 9999U) + voice->unlinked(); + remoteNetwork.writeUnlink(currentAddr, currentPort); remoteNetwork.writeUnlink(currentAddr, currentPort); remoteNetwork.writeUnlink(currentAddr, currentPort); @@ -277,9 +280,6 @@ void CNXDNGateway::run() lostTimer.stop(); } - if (voice != NULL) - voice->linkedTo(dstId); - currentId = dstId; } @@ -292,6 +292,9 @@ void CNXDNGateway::run() std::string callsign = lookup->find(srcId); LogMessage("Linked to reflector %u by %s", currentId, callsign.c_str()); + if (voice != NULL) + voice->linkedTo(currentId); + remoteNetwork.writePoll(currentAddr, currentPort); remoteNetwork.writePoll(currentAddr, currentPort); remoteNetwork.writePoll(currentAddr, currentPort); diff --git a/NXDNGateway/NXDNNetwork.cpp b/NXDNGateway/NXDNNetwork.cpp index 915eecb..ee9dc54 100644 --- a/NXDNGateway/NXDNNetwork.cpp +++ b/NXDNGateway/NXDNNetwork.cpp @@ -49,7 +49,7 @@ bool CNXDNNetwork::writeData(const unsigned char* data, unsigned int length, uns assert(length > 0U); assert(port > 0U); - unsigned char buffer[20U]; + unsigned char buffer[50U]; buffer[0U] = 'N'; buffer[1U] = 'X'; diff --git a/NXDNGateway/Voice.cpp b/NXDNGateway/Voice.cpp index 6e8362d..60f19dc 100644 --- a/NXDNGateway/Voice.cpp +++ b/NXDNGateway/Voice.cpp @@ -30,7 +30,7 @@ const unsigned char HEADER[] = { 0x83U, 0x01U, 0x10U, 0x00U, 0x0FU, 0x01U, 0x00U, 0x20U }; const unsigned char TRAILER[] = { 0x83U, 0x01U, 0x10U, 0x00U, 0x0FU, 0x08U, 0x00U, 0x20U }; -const unsigned char SILENCE[] = {0xACU, 0xAAU, 0x40U, 0x20U, 0x00U, 0x44U, 0x40U, 0x80U, 0x80U}; +const unsigned char SILENCE[] = { 0xF0U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x78U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U }; const unsigned char NXDN_FRAME_LENGTH = 33U; @@ -53,9 +53,9 @@ m_timer(1000U, 1U), m_stopWatch(), m_sent(0U), m_ambe(NULL), -m_positions(), m_voiceData(NULL), -m_voiceLength(0U) +m_voiceLength(0U), +m_positions() { #if defined(_WIN32) || defined(_WIN64) m_indxFile = directory + "\\" + language + ".indx"; @@ -172,12 +172,9 @@ void CVoice::createVoice(unsigned int tg, const std::vector& words) } } - // Ensure that the AMBE is an integer number of DMR frames - if ((ambeLength % (2U * AMBE_LENGTH)) != 0U) { - unsigned int frames = ambeLength / (2U * AMBE_LENGTH); - frames++; - ambeLength = frames * (2U * AMBE_LENGTH); - } + // Ensure that the AMBE is an integer number of NXDN frames + if ((ambeLength % (2U * AMBE_LENGTH)) != 0U) + ambeLength++; // Add space for silence before and after the voice ambeLength += SILENCE_LENGTH * AMBE_LENGTH; @@ -189,7 +186,7 @@ void CVoice::createVoice(unsigned int tg, const std::vector& words) for (unsigned int i = 0U; i < ambeLength; i += AMBE_LENGTH) ::memcpy(ambeData + i, SILENCE, AMBE_LENGTH); - // Put offset in for silence at the beginning + // Put offset in for silence at the beginning unsigned int pos = SILENCE_LENGTH * AMBE_LENGTH; for (std::vector::const_iterator it = words.begin(); it != words.end(); ++it) { if (m_positions.count(*it) > 0U) { @@ -207,7 +204,7 @@ void CVoice::createVoice(unsigned int tg, const std::vector& words) unsigned char sacch[12U]; ::memset(sacch, 0x00U, 12U); - + sacch[0U] = 0x01U; sacch[2U] = 0x20U; sacch[3U] = (m_srcId >> 8) & 0xFFU; @@ -268,6 +265,8 @@ bool CVoice::read(unsigned char* data) if (m_sent < count) { unsigned int offset = m_sent * NXDN_FRAME_LENGTH; ::memcpy(data, m_voiceData + offset, NXDN_FRAME_LENGTH); + + offset += NXDN_FRAME_LENGTH; m_sent++; if (offset >= m_voiceLength) { @@ -282,6 +281,13 @@ bool CVoice::read(unsigned char* data) return false; } +void CVoice::abort() +{ + m_status = VS_NONE; + m_voiceLength = 0U; + m_sent = 0U; +} + void CVoice::clock(unsigned int ms) { m_timer.clock(ms); diff --git a/NXDNGateway/Voice.h b/NXDNGateway/Voice.h index 168ac2e..2284bd4 100644 --- a/NXDNGateway/Voice.h +++ b/NXDNGateway/Voice.h @@ -49,6 +49,8 @@ public: bool read(unsigned char* data); + void abort(); + void clock(unsigned int ms); private: diff --git a/NXDNReflector/NXCoreNetwork.cpp b/NXDNReflector/NXCoreNetwork.cpp index 6fba2ed..de5eb2b 100644 --- a/NXDNReflector/NXCoreNetwork.cpp +++ b/NXDNReflector/NXCoreNetwork.cpp @@ -29,7 +29,7 @@ const unsigned int BUFFER_LENGTH = 200U; const unsigned int NXCORE_PORT = 41300U; CNXCoreNetwork::CNXCoreNetwork(const std::string& address, bool debug) : -m_socket("", NXCORE_PORT), +m_socket(NXCORE_PORT), m_address(), m_debug(debug), m_buffer(1000U, "NXCore Network") diff --git a/NXDNReflector/NXDNReflector.ini b/NXDNReflector/NXDNReflector.ini index 87b8eb1..1757c3a 100644 --- a/NXDNReflector/NXDNReflector.ini +++ b/NXDNReflector/NXDNReflector.ini @@ -18,5 +18,6 @@ Debug=0 [NXCore] Enabled=0 -Address=127.0.0.1 +# Address=208.111.3.45 +Address=44.131.4.1 Debug=0 diff --git a/README.md b/README.md index cb67c93..6f32ee5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,9 @@ These programs are clients for the NXDN networking now built into the MMDVM Host The Parrot is very simple minded and can only handle one client at a time and is therefore not suitable for use as a shared resource via the Internet. -The Gateway allows for use of NXDN Talk Groups to control the access to the various NXDN reflectors. +The Reflector is used as a single talk group in the same way that it is with P25. It also includes the option to link it to NXCore to allow for interchange of audio between the two. At the NXCore end, it should be set up to receive the traffic from only one talk group. + +The Gateway allows for use of NXDN Talk Groups to control the access to the various NXDN reflectors. It speaks the same language as Icom repeaters to the MMDVM so could theoretically be used as a gateway for a real Icom NXDN repeater. This has not been tested. The Gateway has an ini file that contain the parameters for running the software. The filename of the ini file is passed as a parameter on the command line. The Parrot takes the UDP port number to listen on as an argument.