|
|
@ -33,19 +33,24 @@ m_debug(debug),
|
|
|
|
m_address(),
|
|
|
|
m_address(),
|
|
|
|
m_port(0U),
|
|
|
|
m_port(0U),
|
|
|
|
m_poll(NULL),
|
|
|
|
m_poll(NULL),
|
|
|
|
m_buffer(1000U, "YSF Network Buffer"),
|
|
|
|
m_unlink(NULL),
|
|
|
|
m_timer(1000U, 5U)
|
|
|
|
m_buffer(1000U, "YSF Network Buffer")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
assert(port > 0U);
|
|
|
|
assert(port > 0U);
|
|
|
|
|
|
|
|
|
|
|
|
m_poll = new unsigned char[14U];
|
|
|
|
m_poll = new unsigned char[14U];
|
|
|
|
::memcpy(m_poll + 0U, "YSFP", 4U);
|
|
|
|
::memcpy(m_poll + 0U, "YSFP", 4U);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_unlink = new unsigned char[14U];
|
|
|
|
|
|
|
|
::memcpy(m_unlink + 0U, "YSFU", 4U);
|
|
|
|
|
|
|
|
|
|
|
|
std::string node = callsign;
|
|
|
|
std::string node = callsign;
|
|
|
|
node.resize(YSF_CALLSIGN_LENGTH, ' ');
|
|
|
|
node.resize(YSF_CALLSIGN_LENGTH, ' ');
|
|
|
|
|
|
|
|
|
|
|
|
for (unsigned int i = 0U; i < YSF_CALLSIGN_LENGTH; i++)
|
|
|
|
for (unsigned int i = 0U; i < YSF_CALLSIGN_LENGTH; i++) {
|
|
|
|
m_poll[i + 4U] = node.at(i);
|
|
|
|
m_poll[i + 4U] = node.at(i);
|
|
|
|
|
|
|
|
m_unlink[i + 4U] = node.at(i);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CNetwork::CNetwork(unsigned int port, const std::string& callsign, bool debug) :
|
|
|
|
CNetwork::CNetwork(unsigned int port, const std::string& callsign, bool debug) :
|
|
|
@ -54,19 +59,24 @@ m_debug(debug),
|
|
|
|
m_address(),
|
|
|
|
m_address(),
|
|
|
|
m_port(0U),
|
|
|
|
m_port(0U),
|
|
|
|
m_poll(NULL),
|
|
|
|
m_poll(NULL),
|
|
|
|
m_buffer(1000U, "YSF Network Buffer"),
|
|
|
|
m_unlink(NULL),
|
|
|
|
m_timer(1000U, 5U)
|
|
|
|
m_buffer(1000U, "YSF Network Buffer")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
assert(port > 0U);
|
|
|
|
assert(port > 0U);
|
|
|
|
|
|
|
|
|
|
|
|
m_poll = new unsigned char[14U];
|
|
|
|
m_poll = new unsigned char[14U];
|
|
|
|
::memcpy(m_poll + 0U, "YSFP", 4U);
|
|
|
|
::memcpy(m_poll + 0U, "YSFP", 4U);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_unlink = new unsigned char[14U];
|
|
|
|
|
|
|
|
::memcpy(m_unlink + 0U, "YSFU", 4U);
|
|
|
|
|
|
|
|
|
|
|
|
std::string node = callsign;
|
|
|
|
std::string node = callsign;
|
|
|
|
node.resize(YSF_CALLSIGN_LENGTH, ' ');
|
|
|
|
node.resize(YSF_CALLSIGN_LENGTH, ' ');
|
|
|
|
|
|
|
|
|
|
|
|
for (unsigned int i = 0U; i < YSF_CALLSIGN_LENGTH; i++)
|
|
|
|
for (unsigned int i = 0U; i < YSF_CALLSIGN_LENGTH; i++) {
|
|
|
|
m_poll[i + 4U] = node.at(i);
|
|
|
|
m_poll[i + 4U] = node.at(i);
|
|
|
|
|
|
|
|
m_unlink[i + 4U] = node.at(i);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CNetwork::~CNetwork()
|
|
|
|
CNetwork::~CNetwork()
|
|
|
@ -85,16 +95,12 @@ void CNetwork::setDestination(const in_addr& address, unsigned int port)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_address = address;
|
|
|
|
m_address = address;
|
|
|
|
m_port = port;
|
|
|
|
m_port = port;
|
|
|
|
|
|
|
|
|
|
|
|
m_timer.start();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CNetwork::setDestination()
|
|
|
|
void CNetwork::setDestination()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_address.s_addr = INADDR_NONE;
|
|
|
|
m_address.s_addr = INADDR_NONE;
|
|
|
|
m_port = 0U;
|
|
|
|
m_port = 0U;
|
|
|
|
|
|
|
|
|
|
|
|
m_timer.stop();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CNetwork::write(const unsigned char* data)
|
|
|
|
bool CNetwork::write(const unsigned char* data)
|
|
|
@ -118,14 +124,16 @@ bool CNetwork::writePoll()
|
|
|
|
return m_socket.write(m_poll, 14U, m_address, m_port);
|
|
|
|
return m_socket.write(m_poll, 14U, m_address, m_port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CNetwork::clock(unsigned int ms)
|
|
|
|
bool CNetwork::writeUnlink()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_timer.clock(ms);
|
|
|
|
if (m_port == 0U)
|
|
|
|
if (m_timer.isRunning() && m_timer.hasExpired()) {
|
|
|
|
return true;
|
|
|
|
writePoll();
|
|
|
|
|
|
|
|
m_timer.start();
|
|
|
|
return m_socket.write(m_unlink, 14U, m_address, m_port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CNetwork::clock(unsigned int ms)
|
|
|
|
|
|
|
|
{
|
|
|
|
unsigned char buffer[BUFFER_LENGTH];
|
|
|
|
unsigned char buffer[BUFFER_LENGTH];
|
|
|
|
|
|
|
|
|
|
|
|
in_addr address;
|
|
|
|
in_addr address;
|
|
|
@ -137,20 +145,13 @@ void CNetwork::clock(unsigned int ms)
|
|
|
|
if (address.s_addr != m_address.s_addr || port != m_port)
|
|
|
|
if (address.s_addr != m_address.s_addr || port != m_port)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// Handle incoming polls
|
|
|
|
|
|
|
|
if (::memcmp(buffer, "YSFP", 4U) == 0) {
|
|
|
|
|
|
|
|
// How do we handle a loss of polls?
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Invalid packet type?
|
|
|
|
|
|
|
|
if (::memcmp(buffer, "YSFD", 4U) != 0)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_debug)
|
|
|
|
if (m_debug)
|
|
|
|
CUtils::dump(1U, "YSF Network Data Received", buffer, length);
|
|
|
|
CUtils::dump(1U, "YSF Network Data Received", buffer, length);
|
|
|
|
|
|
|
|
|
|
|
|
m_buffer.addData(buffer, 155U);
|
|
|
|
unsigned char len = length;
|
|
|
|
|
|
|
|
m_buffer.addData(&len, 1U);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_buffer.addData(buffer, length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int CNetwork::read(unsigned char* data)
|
|
|
|
unsigned int CNetwork::read(unsigned char* data)
|
|
|
@ -160,9 +161,12 @@ unsigned int CNetwork::read(unsigned char* data)
|
|
|
|
if (m_buffer.isEmpty())
|
|
|
|
if (m_buffer.isEmpty())
|
|
|
|
return 0U;
|
|
|
|
return 0U;
|
|
|
|
|
|
|
|
|
|
|
|
m_buffer.getData(data, 155U);
|
|
|
|
unsigned char len = 0U;
|
|
|
|
|
|
|
|
m_buffer.getData(&len, 1U);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_buffer.getData(data, len);
|
|
|
|
|
|
|
|
|
|
|
|
return 155U;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CNetwork::close()
|
|
|
|
void CNetwork::close()
|
|
|
|