1
0
Fork 0

Merge branch 'master' into IPv6

ycs232-kbc
Jonathan Naylor 4 years ago
commit bbe1a50745

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

@ -41,7 +41,7 @@ public:
void write(const unsigned char* data); void write(const unsigned char* data);
void writePoll(unsigned int count = 1U); 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); void writeUnlink(unsigned int count = 1U);
unsigned int read(unsigned char* data); unsigned int read(unsigned char* data);
@ -57,6 +57,7 @@ private:
unsigned int m_addrLen; unsigned int m_addrLen;
unsigned char* m_poll; unsigned char* m_poll;
unsigned char* m_options; unsigned char* m_options;
std::string m_opt;
unsigned char* m_unlink; unsigned char* m_unlink;
CRingBuffer<unsigned char> m_buffer; CRingBuffer<unsigned char> m_buffer;
CTimer m_pollTimer; CTimer m_pollTimer;

@ -89,6 +89,10 @@ unsigned int CNetwork::read(unsigned char* data)
return 0U; return 0U;
} }
// Throw away incoming options messages
if (::memcmp(data, "YSFO", 4U) == 0)
return 0U;
// Handle incoming unlinks // Handle incoming unlinks
if (::memcmp(data, "YSFU", 4U) == 0) if (::memcmp(data, "YSFU", 4U) == 0)
return 0U; return 0U;

@ -104,15 +104,19 @@ unsigned int CNetwork::readData(unsigned char* data, unsigned int length, sockad
if (len <= 0) if (len <= 0)
return 0U; 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 // Handle incoming status requests
if (::memcmp(data, "YSFS", 4U) == 0) { if (::memcmp(data, "YSFS", 4U) == 0) {
m_socket.write(m_status, 42U, addr, addrLen); m_socket.write(m_status, 42U, addr, addrLen);
return 0U; return 0U;
} }
if (m_debug)
CUtils::dump(1U, "YSF Network Data Received", data, len);
return len; return len;
} }

Loading…
Cancel
Save