1
0
Fork 0

Handle YSF network options cleanly.

ycs232-kbc
Jonathan Naylor 4 years ago
parent 8c5d4e161d
commit b55b6b3d31

@ -34,6 +34,7 @@ m_address(),
m_port(0U),
m_poll(NULL),
m_options(NULL),
m_opt(),
m_unlink(NULL),
m_buffer(1000U, "YSF Network Buffer"),
m_pollTimer(1000U, 5U),
@ -66,6 +67,7 @@ m_address(),
m_port(0U),
m_poll(NULL),
m_options(NULL),
m_opt(),
m_unlink(NULL),
m_buffer(1000U, "YSF Network Buffer"),
m_pollTimer(1000U, 5U)
@ -92,6 +94,8 @@ m_pollTimer(1000U, 5U)
CYSFNetwork::~CYSFNetwork()
{
delete[] m_poll;
delete[] m_unlink;
delete[] m_options;
}
bool CYSFNetwork::open()
@ -141,22 +145,23 @@ void CYSFNetwork::writePoll(unsigned int count)
for (unsigned int i = 0U; i < count; i++)
m_socket.write(m_poll, 14U, m_address, m_port);
if (m_options != NULL)
if (!m_opt.empty())
m_socket.write(m_options, 50U, m_address, m_port);
}
void CYSFNetwork::setOptions(const std::string& options)
{
std::string opt = options;
if (opt.size() < 1)
if (options.empty()) {
m_opt.clear();
return;
}
opt.resize(50, ' ');
m_opt = options;
for (unsigned int i = 0U; i < (50 - 4 - YSF_CALLSIGN_LENGTH); i++) {
m_options[i + 4U + YSF_CALLSIGN_LENGTH] = opt.at(i);
}
m_opt.resize(50, ' ');
for (unsigned int i = 0U; i < (50U - 4U - YSF_CALLSIGN_LENGTH); i++)
m_options[i + 4U + YSF_CALLSIGN_LENGTH] = m_opt.at(i);
}
void CYSFNetwork::writeUnlink(unsigned int count)
@ -200,7 +205,7 @@ void CYSFNetwork::clock(unsigned int ms)
m_linked = true;
if (m_options != NULL)
if (!m_opt.empty())
m_socket.write(m_options, 50U, m_address, m_port);
}

@ -41,7 +41,7 @@ public:
void write(const unsigned char* data);
void writePoll(unsigned int count = 1U);
void setOptions(const std::string& options = NULL);
void setOptions(const std::string& options = "");
void writeUnlink(unsigned int count = 1U);
unsigned int read(unsigned char* data);
@ -57,6 +57,7 @@ private:
unsigned int m_port;
unsigned char* m_poll;
unsigned char* m_options;
std::string m_opt;
unsigned char* m_unlink;
CRingBuffer<unsigned char> m_buffer;
CTimer m_pollTimer;

@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014,2016,2018 by Jonathan Naylor G4KLX
* Copyright (C) 2009-2014,2016,2018,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
@ -89,6 +89,10 @@ unsigned int CNetwork::read(unsigned char* data)
return 0U;
}
// Throw away incoming options messages
if (::memcmp(data, "YSFO", 4U) == 0)
return 0U;
// Handle incoming unlinks
if (::memcmp(data, "YSFU", 4U) == 0)
return 0U;

@ -99,15 +99,19 @@ unsigned int CNetwork::readData(unsigned char* data, unsigned int length, in_add
if (len <= 0)
return 0U;
if (m_debug)
CUtils::dump(1U, "YSF Network Data Received", data, len);
// Throw away any options messages
if (::memcmp(data, "YSFO", 4U) == 0)
return 0U;
// Handle incoming status requests
if (::memcmp(data, "YSFS", 4U) == 0) {
m_socket.write(m_status, 42U, address, port);
return 0U;
}
if (m_debug)
CUtils::dump(1U, "YSF Network Data Received", data, len);
return len;
}

Loading…
Cancel
Save