diff --git a/DGIdGateway/DGIdGateway.cpp b/DGIdGateway/DGIdGateway.cpp index 88be328..98e13b3 100644 --- a/DGIdGateway/DGIdGateway.cpp +++ b/DGIdGateway/DGIdGateway.cpp @@ -375,7 +375,7 @@ int CDGIdGateway::run() fich.setDGId(0U); fich.encode(buffer + 35U); - dgIdNetwork[currentDGId]->write(currentDGId, dt, buffer); + dgIdNetwork[currentDGId]->write(currentDGId, buffer); } inactivityTimer.setTimeout(dgIdNetwork[currentDGId]->m_rfHangTime); @@ -401,7 +401,7 @@ int CDGIdGateway::run() fich.setDGId(i); fich.encode(buffer + 35U); - rptNetwork.write(0U, 0U, buffer); + rptNetwork.write(0U, buffer); inactivityTimer.setTimeout(dgIdNetwork[i]->m_netHangTime); inactivityTimer.start(); diff --git a/DGIdGateway/DGIdNetwork.h b/DGIdGateway/DGIdNetwork.h index 04bd821..f553d31 100644 --- a/DGIdGateway/DGIdNetwork.h +++ b/DGIdGateway/DGIdNetwork.h @@ -28,7 +28,7 @@ public: virtual void link() = 0; - virtual void write(unsigned int dgId, unsigned char dt, const unsigned char* data) = 0; + virtual void write(unsigned int dgId, const unsigned char* data) = 0; virtual unsigned int read(unsigned int dgid, unsigned char* data) = 0; diff --git a/DGIdGateway/FCSNetwork.cpp b/DGIdGateway/FCSNetwork.cpp index 60e48e9..d48aa54 100644 --- a/DGIdGateway/FCSNetwork.cpp +++ b/DGIdGateway/FCSNetwork.cpp @@ -81,7 +81,7 @@ bool CFCSNetwork::open() return m_socket.open(); } -void CFCSNetwork::write(unsigned int dgid, unsigned char dt, const unsigned char* data) +void CFCSNetwork::write(unsigned int dgid, const unsigned char* data) { assert(data != NULL); diff --git a/DGIdGateway/FCSNetwork.h b/DGIdGateway/FCSNetwork.h index 1929ef2..9cb61d1 100644 --- a/DGIdGateway/FCSNetwork.h +++ b/DGIdGateway/FCSNetwork.h @@ -44,7 +44,7 @@ public: virtual void link(); - virtual void write(unsigned int dgId, unsigned char dt, const unsigned char* data); + virtual void write(unsigned int dgId, const unsigned char* data); virtual unsigned int read(unsigned int dgId, unsigned char* data); diff --git a/DGIdGateway/IMRSNetwork.cpp b/DGIdGateway/IMRSNetwork.cpp index 77567fa..75d34ee 100644 --- a/DGIdGateway/IMRSNetwork.cpp +++ b/DGIdGateway/IMRSNetwork.cpp @@ -18,6 +18,7 @@ #include "IMRSNetwork.h" #include "YSFDefines.h" +#include "YSFFICH.h" #include "Utils.h" #include "Log.h" @@ -55,7 +56,7 @@ bool CIMRSNetwork::open() return m_socket.open(); } -void CIMRSNetwork::write(unsigned int dgId, unsigned char dt, const unsigned char* data) +void CIMRSNetwork::write(unsigned int dgId, const unsigned char* data) { assert(data != NULL); @@ -63,13 +64,51 @@ void CIMRSNetwork::write(unsigned int dgId, unsigned char dt, const unsigned cha if (ptr == NULL) return; + CYSFFICH fich; + fich.decode(data + 35U); + unsigned char buffer[200U]; + switch (fich.getDT()) { // XXX + case YSF_DT_VD_MODE1: + buffer[0U] = '0'; + buffer[1U] = '0'; + buffer[2U] = '0'; + break; + case YSF_DT_DATA_FR_MODE: + buffer[0U] = '1'; + buffer[1U] = '1'; + buffer[2U] = '1'; + break; + case YSF_DT_VD_MODE2: + buffer[0U] = '2'; + buffer[1U] = '2'; + buffer[2U] = '2'; + break; + case YSF_DT_VOICE_FR_MODE: + buffer[0U] = '3'; + buffer[1U] = '3'; + buffer[2U] = '3'; + break; + default: + return; + } + + // Copy the raw DCH + + // Copy the audio + ::memcpy(buffer + 35U, data + 45U, 130U); // XXX + for (std::vector::const_iterator it = ptr->m_destinations.begin(); it != ptr->m_destinations.end(); ++it) { + // Set the correct DG-ID for this destination + fich.setDGId((*it)->m_dgId); + // Copy the raw FICH + fich.getRaw(buffer + 7U); + if (ptr->m_debug) - CUtils::dump(1U, "IMRS Network Data Sent", buffer, 130U); + CUtils::dump(1U, "IMRS Network Data Sent", buffer, 165U); - m_socket.write(buffer, 130U, (*it)->m_address, IMRS_PORT); + m_socket.write(buffer, 165U, (*it)->m_address, IMRS_PORT); } } diff --git a/DGIdGateway/IMRSNetwork.h b/DGIdGateway/IMRSNetwork.h index 93bf165..f03b7ee 100644 --- a/DGIdGateway/IMRSNetwork.h +++ b/DGIdGateway/IMRSNetwork.h @@ -58,7 +58,7 @@ public: virtual void link(); - virtual void write(unsigned int dgId, unsigned char dt, const unsigned char* data); + virtual void write(unsigned int dgId, const unsigned char* data); virtual unsigned int read(unsigned int dgId, unsigned char* data); diff --git a/DGIdGateway/YSFFICH.cpp b/DGIdGateway/YSFFICH.cpp index 8f99b05..9975404 100644 --- a/DGIdGateway/YSFFICH.cpp +++ b/DGIdGateway/YSFFICH.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016,2017,2019 by Jonathan Naylor G4KLX + * Copyright (C) 2016,2017,2019,2020 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -169,6 +169,18 @@ void CYSFFICH::encode(unsigned char* bytes) } } +void CYSFFICH::setRaw(const unsigned char* bytes) +{ + ::memcpy(m_fich, bytes, 6U); +} + +void CYSFFICH::getRaw(unsigned char* bytes) const +{ + ::memcpy(bytes, m_fich, 6U); + + CCRC::addCCITT16(bytes, 6U); +} + unsigned char CYSFFICH::getFI() const { return (m_fich[0U] >> 6) & 0x03U; diff --git a/DGIdGateway/YSFFICH.h b/DGIdGateway/YSFFICH.h index b7d623c..4a15250 100644 --- a/DGIdGateway/YSFFICH.h +++ b/DGIdGateway/YSFFICH.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016,2017,2019 by Jonathan Naylor G4KLX + * Copyright (C) 2016,2017,2019,2020 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,6 +29,10 @@ public: void encode(unsigned char* bytes); + void setRaw(const unsigned char* bytes); + + void getRaw(unsigned char* bytes) const; + unsigned char getFI() const; unsigned char getCM() const; unsigned char getBN() const; diff --git a/DGIdGateway/YSFNetwork.cpp b/DGIdGateway/YSFNetwork.cpp index 296ecff..23384fc 100644 --- a/DGIdGateway/YSFNetwork.cpp +++ b/DGIdGateway/YSFNetwork.cpp @@ -93,7 +93,7 @@ bool CYSFNetwork::open() return m_socket.open(); } -void CYSFNetwork::write(unsigned int dgid, unsigned char dt, const unsigned char* data) +void CYSFNetwork::write(unsigned int dgid, const unsigned char* data) { assert(data != NULL); diff --git a/DGIdGateway/YSFNetwork.h b/DGIdGateway/YSFNetwork.h index 5507d09..6b774fb 100644 --- a/DGIdGateway/YSFNetwork.h +++ b/DGIdGateway/YSFNetwork.h @@ -38,7 +38,7 @@ public: virtual void link(); - virtual void write(unsigned int dgId, unsigned char dt, const unsigned char* data); + virtual void write(unsigned int dgId, const unsigned char* data); virtual unsigned int read(unsigned int dgId, unsigned char* data);