1
0
Fork 0

Try to avoid creating duplicates with the YSFReflector.

ycs232-kbc
Jonathan Naylor 8 years ago
parent a7bfca4d45
commit 935492c5a4

@ -27,30 +27,59 @@
const unsigned int BUFFER_LENGTH = 200U; const unsigned int BUFFER_LENGTH = 200U;
CNetwork::CNetwork(const std::string& address, unsigned int port, bool debug) : CNetwork::CNetwork(const std::string& address, unsigned int port, const std::string& callsign, const std::string& suffix, bool debug) :
m_socket(address, port), m_socket(address, port),
m_debug(debug), m_debug(debug),
m_address(), m_address(),
m_port(0U), m_port(0U),
m_poll(NULL),
m_buffer(1000U, "YSF Network Buffer"), m_buffer(1000U, "YSF Network Buffer"),
m_timer(1000U, 5U) m_timer(1000U, 5U)
{ {
assert(port > 0U); assert(port > 0U);
m_poll = new unsigned char[14U];
::memcpy(m_poll + 0U, "YSFP", 4U);
std::string node = callsign;
if (suffix.size() > 0U) {
node.append("-");
node.append(suffix);
}
node.resize(YSF_CALLSIGN_LENGTH, ' ');
for (unsigned int i = 0U; i < YSF_CALLSIGN_LENGTH; i++)
m_poll[i + 4U] = node.at(i);
} }
CNetwork::CNetwork(unsigned int port, bool debug) : CNetwork::CNetwork(unsigned int port, const std::string& callsign, const std::string& suffix, bool debug) :
m_socket(port), m_socket(port),
m_debug(debug), m_debug(debug),
m_address(), m_address(),
m_port(0U), m_port(0U),
m_poll(NULL),
m_buffer(1000U, "YSF Network Buffer"), m_buffer(1000U, "YSF Network Buffer"),
m_timer(1000U, 5U) m_timer(1000U, 5U)
{ {
assert(port > 0U); assert(port > 0U);
m_poll = new unsigned char[14U];
::memcpy(m_poll + 0U, "YSFP", 4U);
std::string node = callsign;
if (suffix.size() > 0U) {
node.append("-");
node.append(suffix);
}
node.resize(YSF_CALLSIGN_LENGTH, ' ');
for (unsigned int i = 0U; i < YSF_CALLSIGN_LENGTH; i++)
m_poll[i + 4U] = node.at(i);
} }
CNetwork::~CNetwork() CNetwork::~CNetwork()
{ {
delete[] m_poll;
} }
bool CNetwork::open() bool CNetwork::open()
@ -94,25 +123,7 @@ bool CNetwork::writePoll()
if (m_port == 0U) if (m_port == 0U)
return true; return true;
unsigned char buffer[20U]; return m_socket.write(m_poll, 14U, m_address, m_port);
buffer[0] = 'Y';
buffer[1] = 'S';
buffer[2] = 'F';
buffer[3] = 'P';
buffer[4U] = 'G';
buffer[5U] = 'A';
buffer[6U] = 'T';
buffer[7U] = 'E';
buffer[8U] = 'W';
buffer[9U] = 'A';
buffer[10U] = 'Y';
buffer[11U] = ' ';
buffer[12U] = ' ';
buffer[13U] = ' ';
return m_socket.write(buffer, 14U, m_address, m_port);
} }
void CNetwork::clock(unsigned int ms) void CNetwork::clock(unsigned int ms)

@ -29,8 +29,8 @@
class CNetwork { class CNetwork {
public: public:
CNetwork(const std::string& address, unsigned int port, bool debug); CNetwork(const std::string& address, unsigned int port, const std::string& callsign, const std::string& suffix, bool debug);
CNetwork(unsigned int port, bool debug); CNetwork(unsigned int port, const std::string& callsign, const std::string& suffix, bool debug);
~CNetwork(); ~CNetwork();
bool open(); bool open();
@ -51,6 +51,7 @@ private:
bool m_debug; bool m_debug;
in_addr m_address; in_addr m_address;
unsigned int m_port; unsigned int m_port;
unsigned char* m_poll;
CRingBuffer<unsigned char> m_buffer; CRingBuffer<unsigned char> m_buffer;
CTimer m_timer; CTimer m_timer;

@ -40,7 +40,7 @@ const unsigned char ALL_RESP[] = {0x5DU, 0x46U, 0x5FU, 0x26U};
const unsigned char DEFAULT_FICH[] = {0x20U, 0x00U, 0x01U, 0x00U}; const unsigned char DEFAULT_FICH[] = {0x20U, 0x00U, 0x01U, 0x00U};
const unsigned char NET_HEADER[] = "YSFDGATEWAY ALL "; const unsigned char NET_HEADER[] = "YSFD ALL ";
CWiresX::CWiresX(const std::string& callsign, const std::string& suffix, CNetwork* network, const std::string& hostsFile, unsigned int statusPort) : CWiresX::CWiresX(const std::string& callsign, const std::string& suffix, CNetwork* network, const std::string& hostsFile, unsigned int statusPort) :
m_callsign(callsign), m_callsign(callsign),
@ -141,8 +141,10 @@ void CWiresX::setInfo(const std::string& name, unsigned int txFrequency, unsigne
for (unsigned int i = 0U; i < 34U; i++) for (unsigned int i = 0U; i < 34U; i++)
m_header[i] = NET_HEADER[i]; m_header[i] = NET_HEADER[i];
for (unsigned int i = 0U; i < 10U; i++) for (unsigned int i = 0U; i < 10U; i++) {
m_header[i + 4U] = m_node.at(i);
m_header[i + 14U] = m_node.at(i); m_header[i + 14U] = m_node.at(i);
}
} }
bool CWiresX::start() bool CWiresX::start()

@ -174,7 +174,7 @@ int CYSFGateway::run()
std::string myAddress = m_conf.getMyAddress(); std::string myAddress = m_conf.getMyAddress();
unsigned int myPort = m_conf.getMyPort(); unsigned int myPort = m_conf.getMyPort();
CNetwork rptNetwork(myAddress, myPort, debug); CNetwork rptNetwork(myAddress, myPort, m_callsign, m_suffix, debug);
rptNetwork.setDestination(rptAddress, rptPort); rptNetwork.setDestination(rptAddress, rptPort);
ret = rptNetwork.open(); ret = rptNetwork.open();
@ -185,7 +185,7 @@ int CYSFGateway::run()
unsigned int netPort = m_conf.getNetworkDataPort(); unsigned int netPort = m_conf.getNetworkDataPort();
m_netNetwork = new CNetwork(netPort, debug); m_netNetwork = new CNetwork(netPort, m_callsign, m_suffix, debug);
ret = m_netNetwork->open(); ret = m_netNetwork->open();
if (!ret) { if (!ret) {
::LogError("Cannot open the reflector network port"); ::LogError("Cannot open the reflector network port");

Loading…
Cancel
Save