Debugging the Gateway functionality.
This commit is contained in:
parent
5e6b6a4061
commit
9296316ffe
6 changed files with 32 additions and 29 deletions
|
@ -112,9 +112,6 @@ bool CNetwork::writePoll()
|
||||||
buffer[12U] = ' ';
|
buffer[12U] = ' ';
|
||||||
buffer[13U] = ' ';
|
buffer[13U] = ' ';
|
||||||
|
|
||||||
if (m_debug)
|
|
||||||
CUtils::dump(1U, "YSF Network Poll Sent", buffer, 14U);
|
|
||||||
|
|
||||||
return m_socket.write(buffer, 14U, m_address, m_port);
|
return m_socket.write(buffer, 14U, m_address, m_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,8 +31,7 @@ m_socket(port),
|
||||||
m_address(),
|
m_address(),
|
||||||
m_port(0U),
|
m_port(0U),
|
||||||
m_debug(debug),
|
m_debug(debug),
|
||||||
m_buffer(1000U, "YSF Network"),
|
m_buffer(1000U, "YSF Network")
|
||||||
m_pollTimer(1000U, 5U)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,16 +43,14 @@ bool CNetwork::open()
|
||||||
{
|
{
|
||||||
::fprintf(stdout, "Opening YSF network connection\n");
|
::fprintf(stdout, "Opening YSF network connection\n");
|
||||||
|
|
||||||
if (m_address.s_addr == INADDR_NONE)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
m_pollTimer.start();
|
|
||||||
|
|
||||||
return m_socket.open();
|
return m_socket.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CNetwork::write(const unsigned char* data)
|
bool CNetwork::write(const unsigned char* data)
|
||||||
{
|
{
|
||||||
|
if (m_port == 0U)
|
||||||
|
return true;
|
||||||
|
|
||||||
assert(data != NULL);
|
assert(data != NULL);
|
||||||
|
|
||||||
if (m_debug)
|
if (m_debug)
|
||||||
|
@ -62,7 +59,7 @@ bool CNetwork::write(const unsigned char* data)
|
||||||
return m_socket.write(data, 155U, m_address, m_port);
|
return m_socket.write(data, 155U, m_address, m_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CNetwork::writePoll()
|
bool CNetwork::writePoll(const in_addr& address, unsigned int port)
|
||||||
{
|
{
|
||||||
unsigned char buffer[20U];
|
unsigned char buffer[20U];
|
||||||
|
|
||||||
|
@ -82,20 +79,11 @@ bool CNetwork::writePoll()
|
||||||
buffer[12U] = ' ';
|
buffer[12U] = ' ';
|
||||||
buffer[13U] = ' ';
|
buffer[13U] = ' ';
|
||||||
|
|
||||||
if (m_debug)
|
return m_socket.write(buffer, 14U, address, port);
|
||||||
CUtils::dump(1U, "YSF Network Poll Sent", buffer, 14U);
|
|
||||||
|
|
||||||
return m_socket.write(buffer, 14U, m_address, m_port);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CNetwork::clock(unsigned int ms)
|
void CNetwork::clock(unsigned int ms)
|
||||||
{
|
{
|
||||||
m_pollTimer.clock(ms);
|
|
||||||
if (m_pollTimer.hasExpired()) {
|
|
||||||
writePoll();
|
|
||||||
m_pollTimer.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char buffer[BUFFER_LENGTH];
|
unsigned char buffer[BUFFER_LENGTH];
|
||||||
|
|
||||||
in_addr address;
|
in_addr address;
|
||||||
|
@ -104,12 +92,11 @@ void CNetwork::clock(unsigned int ms)
|
||||||
if (length <= 0)
|
if (length <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_address.s_addr = address.s_addr;
|
// Handle incoming polls
|
||||||
m_port = port;
|
if (::memcmp(buffer, "YSFP", 4U) == 0) {
|
||||||
|
writePoll(address, port);
|
||||||
// Ignore incoming polls
|
|
||||||
if (::memcmp(buffer, "YSFP", 4U) == 0)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Handle the status command
|
// Handle the status command
|
||||||
if (::memcmp(buffer, "YSFS", 4U) == 0) {
|
if (::memcmp(buffer, "YSFS", 4U) == 0) {
|
||||||
|
@ -123,6 +110,9 @@ void CNetwork::clock(unsigned int ms)
|
||||||
if (::memcmp(buffer, "YSFD", 4U) != 0)
|
if (::memcmp(buffer, "YSFD", 4U) != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
m_address.s_addr = address.s_addr;
|
||||||
|
m_port = port;
|
||||||
|
|
||||||
if (m_debug)
|
if (m_debug)
|
||||||
CUtils::dump(1U, "YSF Network Data Received", buffer, length);
|
CUtils::dump(1U, "YSF Network Data Received", buffer, length);
|
||||||
|
|
||||||
|
@ -141,6 +131,11 @@ unsigned int CNetwork::read(unsigned char* data)
|
||||||
return 155U;
|
return 155U;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CNetwork::end()
|
||||||
|
{
|
||||||
|
m_port = 0U;
|
||||||
|
}
|
||||||
|
|
||||||
void CNetwork::close()
|
void CNetwork::close()
|
||||||
{
|
{
|
||||||
m_socket.close();
|
m_socket.close();
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
#include "YSFDefines.h"
|
#include "YSFDefines.h"
|
||||||
#include "RingBuffer.h"
|
#include "RingBuffer.h"
|
||||||
#include "UDPSocket.h"
|
#include "UDPSocket.h"
|
||||||
#include "Timer.h"
|
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -38,6 +37,8 @@ public:
|
||||||
|
|
||||||
unsigned int read(unsigned char* data);
|
unsigned int read(unsigned char* data);
|
||||||
|
|
||||||
|
void end();
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
void clock(unsigned int ms);
|
void clock(unsigned int ms);
|
||||||
|
@ -48,9 +49,8 @@ private:
|
||||||
unsigned int m_port;
|
unsigned int m_port;
|
||||||
bool m_debug;
|
bool m_debug;
|
||||||
CRingBuffer<unsigned char> m_buffer;
|
CRingBuffer<unsigned char> m_buffer;
|
||||||
CTimer m_pollTimer;
|
|
||||||
|
|
||||||
bool writePoll();
|
bool writePoll(const in_addr& address, unsigned int port);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -57,6 +57,12 @@ void CParrot::end()
|
||||||
m_ptr = 0U;
|
m_ptr = 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CParrot::clear()
|
||||||
|
{
|
||||||
|
m_used = 0U;
|
||||||
|
m_ptr = 0U;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int CParrot::read(unsigned char* data)
|
unsigned int CParrot::read(unsigned char* data)
|
||||||
{
|
{
|
||||||
assert(data != NULL);
|
assert(data != NULL);
|
||||||
|
|
|
@ -31,6 +31,8 @@ public:
|
||||||
|
|
||||||
void end();
|
void end();
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned char* m_data;
|
unsigned char* m_data;
|
||||||
unsigned int m_length;
|
unsigned int m_length;
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "Parrot.h"
|
#include "Parrot.h"
|
||||||
#include "Network.h"
|
#include "Network.h"
|
||||||
#include "Version.h"
|
#include "Version.h"
|
||||||
|
#include "Timer.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
@ -105,6 +106,8 @@ void CYSFParrot::run()
|
||||||
network.write(buffer);
|
network.write(buffer);
|
||||||
count++;
|
count++;
|
||||||
} else {
|
} else {
|
||||||
|
parrot.clear();
|
||||||
|
network.end();
|
||||||
turnaroundTimer.stop();
|
turnaroundTimer.stop();
|
||||||
playing = false;
|
playing = false;
|
||||||
count = wanted;
|
count = wanted;
|
||||||
|
|
Loading…
Add table
Reference in a new issue