Skip to content

Commit

Permalink
Merge pull request g4klx#459 from on7lds/devel
Browse files Browse the repository at this point in the history
Process data from display to MMDVMHost
  • Loading branch information
phl0 authored Sep 13, 2018
2 parents ea08667 + 574343c commit f6cd479
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 27 deletions.
4 changes: 3 additions & 1 deletion MMDVMHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ int CMMDVMHost::run()
LogWarning("Could not open the Transparent data socket, disabling");
delete transparentSocket;
transparentSocket = NULL;
sendFrameType=0;
}
m_modem->setTransparentDataParams(sendFrameType);
}

if (m_conf.getCWIdEnabled()) {
Expand Down Expand Up @@ -887,7 +889,7 @@ int CMMDVMHost::run()
unsigned int port = 0U;
len = transparentSocket->read(data, 200U, address, port);
if (len > 0U)
m_modem->writeTransparentData(data, len, sendFrameType);
m_modem->writeTransparentData(data, len);
}

unsigned int ms = stopWatch.elapsed();
Expand Down
33 changes: 28 additions & 5 deletions Modem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ m_txNXDNData(1000U, "Modem TX NXDN"),
m_txPOCSAGData(1000U, "Modem TX POCSAG"),
m_rxTransparentData(1000U, "Modem RX Transparent"),
m_txTransparentData(1000U, "Modem TX Transparent"),
m_sendTransparentDataFrameType(0U),
m_statusTimer(1000U, 0U, 250U),
m_inactivityTimer(1000U, 2U),
m_playoutTimer(1000U, 0U, 10U),
Expand Down Expand Up @@ -225,6 +226,11 @@ void CModem::setYSFParams(bool loDev, unsigned int txHang)
m_ysfTXHang = txHang;
}

void CModem::setTransparentDataParams(unsigned int sendFrameType)
{
m_sendTransparentDataFrameType = sendFrameType;
}

bool CModem::open()
{
::LogMessage("Opening the MMDVM");
Expand Down Expand Up @@ -553,10 +559,12 @@ void CModem::clock(unsigned int ms)
if (m_trace)
CUtils::dump(1U, "RX Transparent Data", m_buffer, m_length);

unsigned char data = m_length - 3U;
unsigned char offset = m_sendTransparentDataFrameType;
if (offset>1) offset=1;
unsigned char data = m_length - 3U + offset;
m_rxTransparentData.addData(&data, 1U);

m_rxTransparentData.addData(m_buffer + 3U, m_length - 3U);
m_rxTransparentData.addData(m_buffer + 3U - offset, m_length - 3U + offset);
}
break;

Expand All @@ -577,6 +585,21 @@ void CModem::clock(unsigned int ms)
printDebug();
break;

case MMDVM_SERIAL:
//MMDVMHost does not process serial data from the display,
// so we send it to the transparent port if sendFrameType==1
if (m_sendTransparentDataFrameType) {
if (m_trace)
CUtils::dump(1U, "RX Serial Data", m_buffer, m_length);

unsigned char offset = m_sendTransparentDataFrameType;
if (offset>1) offset=1;
unsigned char data = m_length - 3U + offset;
m_rxTransparentData.addData(&data, 1U);

m_rxTransparentData.addData(m_buffer + 3U - offset, m_length - 3U + offset);
break; //only break when sendFrameType>0, else message is unknown
}
default:
LogMessage("Unknown message, type: %02X", m_buffer[2U]);
CUtils::dump("Buffer dump", m_buffer, m_length);
Expand Down Expand Up @@ -1080,7 +1103,7 @@ bool CModem::writePOCSAGData(const unsigned char* data, unsigned int length)
return true;
}

bool CModem::writeTransparentData(const unsigned char* data, unsigned int length, unsigned int sendFrameType)
bool CModem::writeTransparentData(const unsigned char* data, unsigned int length)
{
assert(data != NULL);
assert(length > 0U);
Expand All @@ -1091,14 +1114,14 @@ bool CModem::writeTransparentData(const unsigned char* data, unsigned int length
buffer[1U] = length + 3U;
buffer[2U] = MMDVM_TRANSPARENT;

if (sendFrameType>0) {
if (m_sendTransparentDataFrameType>0) {
::memcpy(buffer + 2U, data, length);
length--;
buffer[1U]--;
//when sendFrameType==1 , only 0x80 and 0x90 (MMDVM_SERIAL and MMDVM_TRANSPARENT) are allowed
// and reverted to default (MMDVM_TRANSPARENT) for any other value
//when >1, frame type is not checked
if (sendFrameType==1) {
if (m_sendTransparentDataFrameType==1) {
if ((buffer[2U] & 0xE0) != 0x80) buffer[2U] = MMDVM_TRANSPARENT;
}
} else {
Expand Down
4 changes: 3 additions & 1 deletion Modem.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class CModem {
void setLevels(float rxLevel, float cwIdTXLevel, float dstarTXLevel, float dmrTXLevel, float ysfTXLevel, float p25TXLevel, float nxdnTXLevel, float pocsagLevel);
void setDMRParams(unsigned int colorCode);
void setYSFParams(bool loDev, unsigned int txHang);
void setTransparentDataParams(unsigned int sendFrameType);

bool open();

Expand Down Expand Up @@ -77,7 +78,7 @@ class CModem {
bool writeP25Data(const unsigned char* data, unsigned int length);
bool writeNXDNData(const unsigned char* data, unsigned int length);
bool writePOCSAGData(const unsigned char* data, unsigned int length);
bool writeTransparentData(const unsigned char* data, unsigned int length, unsigned int sendFrameType);
bool writeTransparentData(const unsigned char* data, unsigned int length);

bool writeDMRStart(bool tx);
bool writeDMRShortLC(const unsigned char* lc);
Expand Down Expand Up @@ -147,6 +148,7 @@ class CModem {
CRingBuffer<unsigned char> m_txPOCSAGData;
CRingBuffer<unsigned char> m_rxTransparentData;
CRingBuffer<unsigned char> m_txTransparentData;
unsigned int m_sendTransparentDataFrameType;
CTimer m_statusTimer;
CTimer m_inactivityTimer;
CTimer m_playoutTimer;
Expand Down
60 changes: 40 additions & 20 deletions Nextion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ void CNextion::setIdleInt()
sendCommand("page MMDVM");
sendCommandAction(1U);

::sprintf(command, "dim=%u", m_idleBrightness);
sendCommand(command);
if (m_brightness>0) {
::sprintf(command, "dim=%u", m_idleBrightness);
sendCommand(command);
}

::sprintf(command, "t0.txt=\"%s/%u\"", m_callsign.c_str(), m_dmrid);
sendCommand(command);
Expand Down Expand Up @@ -179,8 +181,10 @@ void CNextion::setErrorInt(const char* text)
sendCommandAction(1U);

char command[20];
::sprintf(command, "dim=%u", m_brightness);
sendCommand(command);
if (m_brightness>0) {
::sprintf(command, "dim=%u", m_brightness);
sendCommand(command);
}

::sprintf(command, "t0.txt=\"%s\"", text);
sendCommandAction(13U);
Expand All @@ -200,8 +204,10 @@ void CNextion::setLockoutInt()
sendCommandAction(1U);

char command[20];
::sprintf(command, "dim=%u", m_brightness);
sendCommand(command);
if (m_brightness>0) {
::sprintf(command, "dim=%u", m_brightness);
sendCommand(command);
}

sendCommand("t0.txt=\"LOCKOUT\"");
sendCommandAction(15U);
Expand All @@ -217,8 +223,10 @@ void CNextion::setQuitInt()
sendCommandAction(1U);

char command[100];
::sprintf(command, "dim=%u", m_idleBrightness);
sendCommand(command);
if (m_brightness>0) {
::sprintf(command, "dim=%u", m_idleBrightness);
sendCommand(command);
}

::sprintf(command, "t3.txt=\"%s\"", m_ipaddress.c_str());
sendCommand(command);
Expand Down Expand Up @@ -246,8 +254,10 @@ void CNextion::writeDStarInt(const char* my1, const char* my2, const char* your,
}

char text[50U];
::sprintf(text, "dim=%u", m_brightness);
sendCommand(text);
if (m_brightness>0) {
::sprintf(text, "dim=%u", m_brightness);
sendCommand(text);
}

::sprintf(text, "t0.txt=\"%s %.8s/%4.4s\"", type, my1, my2);
sendCommand(text);
Expand Down Expand Up @@ -341,8 +351,10 @@ void CNextion::writeDMRInt(unsigned int slotNo, const std::string& src, bool gro
}

char text[50U];
::sprintf(text, "dim=%u", m_brightness);
sendCommand(text);
if (m_brightness>0) {
::sprintf(text, "dim=%u", m_brightness);
sendCommand(text);
}

if (slotNo == 1U) {
::sprintf(text, "t0.txt=\"1 %s %s\"", type, src.c_str());
Expand Down Expand Up @@ -542,8 +554,10 @@ void CNextion::writeFusionInt(const char* source, const char* dest, const char*


char text[30U];
::sprintf(text, "dim=%u", m_brightness);
sendCommand(text);
if (m_brightness>0) {
::sprintf(text, "dim=%u", m_brightness);
sendCommand(text);
}

::sprintf(text, "t0.txt=\"%s %.10s\"", type, source);
sendCommand(text);
Expand Down Expand Up @@ -618,8 +632,10 @@ void CNextion::writeP25Int(const char* source, bool group, unsigned int dest, co
}

char text[30U];
::sprintf(text, "dim=%u", m_brightness);
sendCommand(text);
if (m_brightness>0) {
::sprintf(text, "dim=%u", m_brightness);
sendCommand(text);
}

::sprintf(text, "t0.txt=\"%s %.10s\"", type, source);
sendCommand(text);
Expand Down Expand Up @@ -688,8 +704,10 @@ void CNextion::writeNXDNInt(const char* source, bool group, unsigned int dest, c
}

char text[30U];
::sprintf(text, "dim=%u", m_brightness);
sendCommand(text);
if (m_brightness>0) {
::sprintf(text, "dim=%u", m_brightness);
sendCommand(text);
}

::sprintf(text, "t0.txt=\"%s %.10s\"", type, source);
sendCommand(text);
Expand Down Expand Up @@ -755,8 +773,10 @@ void CNextion::writePOCSAGInt(uint32_t ric, const std::string& message)
}

char text[200U];
::sprintf(text, "dim=%u", m_brightness);
sendCommand(text);
if (m_brightness>0) {
::sprintf(text, "dim=%u", m_brightness);
sendCommand(text);
}

::sprintf(text, "t0.txt=\"RIC: %u\"", ric);
sendCommand(text);
Expand Down

0 comments on commit f6cd479

Please sign in to comment.