1
0
Fork 0

Debugging the gateway.

ycs232-kbc
Jonathan Naylor 9 years ago
parent 02b6f5342e
commit 64bf2108ee

@ -38,7 +38,10 @@ enum SECTION {
CConf::CConf(const std::string& file) :
m_file(file),
m_callsign(),
m_port(0U),
m_rptAddress(),
m_rptPort(0U),
m_myAddress(),
m_myPort(0U),
m_daemon(false),
m_rxFrequency(0U),
m_txFrequency(0U),
@ -111,8 +114,14 @@ bool CConf::read()
for (unsigned int i = 0U; value[i] != 0; i++)
value[i] = ::toupper(value[i]);
m_callsign = value;
} else if (::strcmp(key, "Port") == 0)
m_port = (unsigned int)::atoi(value);
} else if (::strcmp(key, "RptAddress") == 0)
m_rptAddress = value;
else if (::strcmp(key, "RptPort") == 0)
m_rptPort = (unsigned int)::atoi(value);
else if (::strcmp(key, "MyAddress") == 0)
m_myAddress = value;
else if (::strcmp(key, "MyPort") == 0)
m_myPort = (unsigned int)::atoi(value);
else if (::strcmp(key, "Daemon") == 0)
m_daemon = ::atoi(value) == 1;
} else if (section == SECTION_INFO) {
@ -174,9 +183,24 @@ std::string CConf::getCallsign() const
return m_callsign;
}
unsigned int CConf::getPort() const
std::string CConf::getRptAddress() const
{
return m_port;
return m_rptAddress;
}
unsigned int CConf::getRptPort() const
{
return m_rptPort;
}
std::string CConf::getMyAddress() const
{
return m_myAddress;
}
unsigned int CConf::getMyPort() const
{
return m_myPort;
}
bool CConf::getDaemon() const

@ -32,7 +32,10 @@ public:
// The General section
std::string getCallsign() const;
unsigned int getPort() const;
std::string getRptAddress() const;
unsigned int getRptPort() const;
std::string getMyAddress() const;
unsigned int getMyPort() const;
bool getDaemon() const;
// The Info section
@ -67,7 +70,10 @@ public:
private:
std::string m_file;
std::string m_callsign;
unsigned int m_port;
std::string m_rptAddress;
unsigned int m_rptPort;
std::string m_myAddress;
unsigned int m_myPort;
bool m_daemon;
unsigned int m_rxFrequency;

@ -27,6 +27,17 @@
const unsigned int BUFFER_LENGTH = 200U;
CNetwork::CNetwork(const std::string& address, unsigned int port, bool debug) :
m_socket(address, port),
m_debug(debug),
m_address(),
m_port(0U),
m_buffer(1000U, "YSF Network Buffer"),
m_timer(1000U, 5U)
{
assert(port > 0U);
}
CNetwork::CNetwork(unsigned int port, bool debug) :
m_socket(port),
m_debug(debug),
@ -123,8 +134,11 @@ void CNetwork::clock(unsigned int ms)
if (length <= 0)
return;
if (address.s_addr != m_address.s_addr || port != m_port)
if (address.s_addr != m_address.s_addr || port != m_port) {
LogDebug("Addr: %u != %u || Port: %u != %u", address.s_addr, m_address.s_addr, port, m_port);
CUtils::dump("Data from unknown address/port", buffer, length);
return;
}
// Handle incoming polls
if (::memcmp(buffer, "YSFP", 4U) == 0) {

@ -29,6 +29,7 @@
class CNetwork {
public:
CNetwork(const std::string& address, unsigned int port, bool debug);
CNetwork(unsigned int port, bool debug);
~CNetwork();

@ -69,14 +69,11 @@ CYSFReflector* CReflectors::find(const std::string& id)
{
for (std::vector<CYSFReflector*>::iterator it = m_reflectors.begin(); it != m_reflectors.end(); ++it) {
if (id == (*it)->m_id)
if ((*it)->m_timer.isRunning() && (*it)->m_timer.hasExpired()) {
LogDebug("Found id %s, but it has expired", id.c_str());
return NULL;
} else {
return *it;
}
return *it;
}
LogMessage("Trying to find non existent reflector with an id of %s", id.c_str());
return NULL;
}
@ -105,7 +102,9 @@ void CReflectors::clock(unsigned int ms)
std::string id = std::string((char*)(buffer + 4U), 5U);
std::string name = std::string((char*)(buffer + 9U), 16U);
std::string desc = std::string((char*)(buffer + 25U), 14U);
unsigned int cnt = ::atoi((char*)(buffer + 39U));
std::string cnt = std::string((char*)(buffer + 39U), 3U);
LogDebug("Have YSFS reply from %s/%s/%s/%s", id.c_str(), name.c_str(), desc.c_str(), cnt.c_str());
for (std::vector<CYSFReflector*>::iterator it = m_reflectors.begin(); it != m_reflectors.end(); ++it) {
in_addr itAddr = (*it)->m_address;
@ -117,6 +116,7 @@ void CReflectors::clock(unsigned int ms)
(*it)->m_desc = desc;
(*it)->m_count = cnt;
(*it)->m_timer.start();
LogDebug("Updating %s", id.c_str());
break;
}
}

@ -31,7 +31,7 @@ public:
m_id(),
m_name(),
m_desc(),
m_count(0U),
m_count("000"),
m_address(),
m_port(0U),
m_timer(1000U, 700U)
@ -41,7 +41,7 @@ public:
std::string m_id;
std::string m_name;
std::string m_desc;
unsigned int m_count;
std::string m_count;
in_addr m_address;
unsigned int m_port;
CTimer m_timer;

@ -151,6 +151,8 @@ bool CUDPSocket::open()
#endif
return false;
}
LogInfo("Opening UDP port on %u", m_port);
}
return true;

@ -19,6 +19,7 @@
#include "WiresX.h"
#include "YSFPayload.h"
#include "YSFFICH.h"
#include "Utils.h"
#include "Sync.h"
#include "CRC.h"
#include "Log.h"
@ -40,41 +41,53 @@ const unsigned char DEFAULT_FICH[] = {0x20U, 0x00U, 0x01U, 0x00U};
const unsigned char NET_HEADER[] = "YSFDGATEWAY ALL ";
CWiresX::CWiresX(CNetwork* network, const std::string& hostsFile, unsigned int statusPort) :
CWiresX::CWiresX(const std::string& callsign, CNetwork* network, const std::string& hostsFile, unsigned int statusPort) :
m_callsign(callsign),
m_network(network),
m_reflectors(hostsFile, statusPort),
m_reflector(NULL),
m_id(),
m_name(),
m_description(),
m_txFrequency(0U),
m_rxFrequency(0U),
m_timer(1000U, 0U, 100U + 750U),
m_seqNo(0U),
m_source(NULL),
m_csd1(NULL),
m_csd2(NULL),
m_csd3(NULL),
m_status(WXSI_NONE)
{
assert(network != NULL);
assert(statusPort > 0U);
m_csd1 = new unsigned char[20U];
m_callsign.resize(YSF_CALLSIGN_LENGTH, ' ');
m_source = new unsigned char[20U];
m_csd1 = new unsigned char[20U];
m_csd2 = new unsigned char[20U];
m_csd3 = new unsigned char[20U];
}
CWiresX::~CWiresX()
{
delete[] m_csd3;
delete[] m_csd2;
delete[] m_csd1;
delete[] m_source;
}
void CWiresX::setInfo(const std::string& name, const std::string& description, unsigned int txFrequency, unsigned int rxFrequency)
void CWiresX::setInfo(const std::string& name, unsigned int txFrequency, unsigned int rxFrequency)
{
assert(txFrequency > 0U);
assert(rxFrequency > 0U);
m_name = name;
m_description = description;
m_txFrequency = txFrequency;
m_rxFrequency = rxFrequency;
m_name.resize(14U, ' ');
unsigned int hash = 0U;
for (unsigned int i = 0U; i < name.size(); i++) {
@ -94,6 +107,20 @@ void CWiresX::setInfo(const std::string& name, const std::string& description, u
LogInfo("The ID of this repeater is %s", id);
m_id = std::string(id);
::memset(m_csd1, '*', 20U);
::memset(m_csd2, ' ', 20U);
::memset(m_csd3, ' ', 20U);
for (unsigned int i = 0U; i < 10U; i++) {
m_csd1[i + 10U] = m_callsign.at(i);
m_csd2[i + 0U] = m_callsign.at(i);
}
for (unsigned int i = 0U; i < 5U; i++) {
m_csd3[i + 0U] = m_id.at(i);
m_csd3[i + 10U] = m_id.at(i);
}
}
bool CWiresX::start()
@ -111,19 +138,13 @@ WX_STATUS CWiresX::process(const unsigned char* data, unsigned char fi, unsigned
CYSFPayload payload;
if (fi == YSF_FI_HEADER) {
payload.readDataFRModeData1(data, m_csd1);
payload.readDataFRModeData1(data, m_source);
return WXS_NONE;
}
if (fi == YSF_FI_COMMUNICATIONS && fn == 0U) {
if (::memcmp(m_csd1, " ", 20U) == 0)
payload.readDataFRModeData1(data, m_csd1);
return WXS_NONE;
}
if (fi == YSF_FI_TERMINATOR) {
if (::memcmp(m_csd1, " ", 20U) == 0)
payload.readDataFRModeData1(data, m_csd1);
if (::memcmp(m_source, " ", 20U) == 0)
payload.readDataFRModeData1(data, m_source);
return WXS_NONE;
}
@ -131,7 +152,7 @@ WX_STATUS CWiresX::process(const unsigned char* data, unsigned char fi, unsigned
unsigned char buffer[20U];
bool valid = payload.readDataFRModeData2(data, buffer);
if (!valid) {
::memset(m_csd1, ' ', 20U);
::memset(m_source, ' ', 20U);
return WXS_NONE;
}
@ -147,7 +168,7 @@ WX_STATUS CWiresX::process(const unsigned char* data, unsigned char fi, unsigned
processDisconnect();
return WXS_DISCONNECT;
} else {
::memset(m_csd1, ' ', 20U);
::memset(m_source, ' ', 20U);
return WXS_NONE;
}
}
@ -162,7 +183,7 @@ CYSFReflector* CWiresX::getReflector() const
void CWiresX::processDX()
{
::LogDebug("Received DX from %10.10s", m_csd1 + 10U);
::LogDebug("Received DX from %10.10s", m_source + 10U);
m_status = WXSI_DX;
m_timer.start();
@ -176,7 +197,7 @@ void CWiresX::processAll()
WX_STATUS CWiresX::processConnect(const unsigned char* data)
{
::LogDebug("Received Connect to %5.5s from %10.10s", data + 5U, m_csd1 + 10U);
::LogDebug("Received Connect to %5.5s from %10.10s", data + 5U, m_source + 10U);
std::string id = std::string((char*)(data + 4U), 5U);
@ -192,7 +213,7 @@ WX_STATUS CWiresX::processConnect(const unsigned char* data)
void CWiresX::processDisconnect()
{
::LogDebug("Received Disconect from %10.10s", m_csd1 + 10U);
::LogDebug("Received Disconect from %10.10s", m_source + 10U);
m_status = WXSI_DISCONNECT;
m_timer.start();
@ -200,10 +221,10 @@ void CWiresX::processDisconnect()
void CWiresX::clock(unsigned int ms)
{
m_reflectors.clock(ms);
m_timer.clock(ms);
if (m_timer.isRunning() && m_timer.hasExpired()) {
LogDebug("Send reply");
switch (m_status) {
case WXSI_DX:
sendDXReply();
@ -250,7 +271,7 @@ void CWiresX::createReply(const unsigned char* data, unsigned int length)
CYSFPayload payload;
payload.writeDataFRModeData1(m_csd1, buffer + 35U);
// payload.writeDataFRModeData2(" ", buffer + 35U);
payload.writeDataFRModeData2(m_csd2, buffer + 35U);
m_network->write(buffer);
@ -266,11 +287,11 @@ void CWiresX::createReply(const unsigned char* data, unsigned int length)
unsigned int len = length - offset;
ft = calculateFT(len);
payload.writeDataFRModeData1(m_csd1, buffer + 35U);
// payload.writeDataFRModeData2(" ", buffer + 35U);
payload.writeDataFRModeData2(m_csd2, buffer + 35U);
}
break;
case 1U:
// payload.writeDataFRModeData1(" ", buffer + 35U);
payload.writeDataFRModeData1(m_csd3, buffer + 35U);
payload.writeDataFRModeData2(data + offset, buffer + 35U);
offset += 20U;
break;
@ -306,7 +327,7 @@ void CWiresX::createReply(const unsigned char* data, unsigned int length)
fich.encode(buffer + 35U);
payload.writeDataFRModeData1(m_csd1, buffer + 35U);
// payload.writeDataFRModeData2(" ", buffer + 35U);
payload.writeDataFRModeData2(m_csd2, buffer + 35U);
m_network->write(buffer);
}
@ -335,11 +356,47 @@ void CWiresX::sendDXReply()
::memset(data, ' ', 128U);
data[0U] = m_seqNo;
::memcmp(data + 1U, DX_RESP, 4U);
for (unsigned int i = 0U; i < 4U; i++)
data[i + 1U] = DX_RESP[i];
for (unsigned int i = 0U; i < 5U; i++)
data[i + 5U] = m_id.at(i);
for (unsigned int i = 0U; i < 10U; i++)
data[i + 10U] = m_callsign.at(i);
for (unsigned int i = 0U; i < 14U; i++)
data[i + 20U] = m_name.at(i);
data[34U] = '1';
data[35U] = '2';
data[57U] = '0';
data[58U] = '0';
data[59U] = '0';
unsigned int offset;
char sign;
if (m_txFrequency >= m_rxFrequency) {
offset = m_txFrequency - m_rxFrequency;
sign = '-';
} else {
offset = m_rxFrequency - m_txFrequency;
sign = '+';
}
char freq[30U];
::sprintf(freq, "%05u.%06u%c%03u.%06u", m_txFrequency / 1000000U, m_txFrequency % 1000000U, sign, offset / 1000000U, offset % 1000000U);
for (unsigned int i = 0U; i < 23U; i++)
data[i + 84U] = freq[i];
data[127U] = 0x03U; // End of data marker
data[128U] = CCRC::addCRC(data, 128U);
CUtils::dump(1U, "DX Reply", data, 140U);
createReply(data, 140U);
m_seqNo++;
@ -347,12 +404,93 @@ void CWiresX::sendDXReply()
void CWiresX::sendConnectReply()
{
assert(m_reflector != NULL);
unsigned char data[110U];
::memset(data, 0x00U, 110U);
::memset(data, ' ', 90U);
data[0U] = m_seqNo;
for (unsigned int i = 0U; i < 4U; i++)
data[i + 1U] = CONN_RESP[i];
for (unsigned int i = 0U; i < 5U; i++)
data[i + 5U] = m_id.at(i);
for (unsigned int i = 0U; i < 10U; i++)
data[i + 10U] = m_callsign.at(i);
for (unsigned int i = 0U; i < 14U; i++)
data[i + 20U] = m_name.at(i);
data[34U] = '1';
data[35U] = '5';
for (unsigned int i = 0U; i < 5U; i++)
data[i + 36U] = m_reflector->m_id.at(i);
for (unsigned int i = 0U; i < 16U; i++)
data[i + 41U] = m_reflector->m_name.at(i);
for (unsigned int i = 0U; i < 3U; i++)
data[i + 57U] = m_reflector->m_count.at(i);
for (unsigned int i = 0U; i < 14U; i++)
data[i + 70U] = m_reflector->m_desc.at(i);
data[84U] = '0';
data[85U] = '0';
data[86U] = '0';
data[87U] = '0';
data[88U] = '0';
data[89U] = '0';
data[90U] = 0x03U; // End of data marker
data[91U] = CCRC::addCRC(data, 91U);
CUtils::dump(1U, "CONNECT Reply", data, 100U);
createReply(data, 100U);
m_seqNo++;
}
void CWiresX::sendDisconnectReply()
{
unsigned char data[110U];
::memset(data, 0x00U, 110U);
::memset(data, ' ', 90U);
data[0U] = m_seqNo;
for (unsigned int i = 0U; i < 4U; i++)
data[i + 1U] = DISC_RESP[i];
for (unsigned int i = 0U; i < 5U; i++)
data[i + 5U] = m_id.at(i);
for (unsigned int i = 0U; i < 10U; i++)
data[i + 10U] = m_callsign.at(i);
for (unsigned int i = 0U; i < 14U; i++)
data[i + 20U] = m_name.at(i);
data[34U] = '1';
data[35U] = '2';
data[57U] = '0';
data[58U] = '0';
data[59U] = '0';
data[89U] = 0x03U; // End of data marker
data[90U] = CCRC::addCRC(data, 90U);
CUtils::dump(1U, "DISCONNECT Reply", data, 100U);
createReply(data, 100U);
m_seqNo++;
}
void CWiresX::sendAllReply()

@ -41,10 +41,10 @@ enum WXSI_STATUS {
class CWiresX {
public:
CWiresX(CNetwork* network, const std::string& hostsFile, unsigned int statusPort);
CWiresX(const std::string& callsign, CNetwork* network, const std::string& hostsFile, unsigned int statusPort);
~CWiresX();
void setInfo(const std::string& name, const std::string& description, unsigned int txFrequency, unsigned int rxFrequency);
void setInfo(const std::string& name, unsigned int txFrequency, unsigned int rxFrequency);
bool start();
@ -55,17 +55,20 @@ public:
void clock(unsigned int ms);
private:
std::string m_callsign;
CNetwork* m_network;
CReflectors m_reflectors;
CYSFReflector* m_reflector;
std::string m_id;
std::string m_name;
std::string m_description;
unsigned int m_txFrequency;
unsigned int m_rxFrequency;
CTimer m_timer;
unsigned char m_seqNo;
unsigned char* m_source;
unsigned char* m_csd1;
unsigned char* m_csd2;
unsigned char* m_csd3;
WXSI_STATUS m_status;
WX_STATUS processConnect(const unsigned char* data);

@ -18,6 +18,7 @@
#include "YSFGateway.h"
#include "Reflectors.h"
#include "UDPSocket.h"
#include "StopWatch.h"
#include "Version.h"
#include "YSFFICH.h"
@ -157,12 +158,16 @@ int CYSFGateway::run()
}
#endif
std::string callsign = m_conf.getCallsign();
bool debug = m_conf.getNetworkDebug();
unsigned int rptPort = m_conf.getPort();
unsigned int netPort = m_conf.getNetworkDataPort();
in_addr rptAddress = CUDPSocket::lookup(m_conf.getRptAddress());
unsigned int rptPort = m_conf.getRptPort();
std::string myAddress = m_conf.getMyAddress();
unsigned int myPort = m_conf.getMyPort();
CNetwork rptNetwork(rptPort, debug);
m_netNetwork = new CNetwork(netPort, debug);
CNetwork rptNetwork(myAddress, myPort, debug);
rptNetwork.setDestination(rptAddress, rptPort);
ret = rptNetwork.open();
if (!ret) {
@ -170,6 +175,9 @@ int CYSFGateway::run()
return 1;
}
unsigned int netPort = m_conf.getNetworkDataPort();
m_netNetwork = new CNetwork(netPort, debug);
ret = m_netNetwork->open();
if (!ret) {
::LogError("Cannot open the reflector network port");
@ -181,7 +189,15 @@ int CYSFGateway::run()
std::string fileName = m_conf.getNetworkHosts();
unsigned int port = m_conf.getNetworkStatusPort();
m_wiresX = new CWiresX(&rptNetwork, fileName, port);
m_wiresX = new CWiresX(callsign, &rptNetwork, fileName, port);
std::string name = m_conf.getName();
unsigned int txFrequency = m_conf.getTxFrequency();
unsigned int rxFrequency = m_conf.getRxFrequency();
m_wiresX->setInfo(name, txFrequency, rxFrequency);
m_wiresX->start();
}
CStopWatch stopWatch;

@ -1,12 +1,14 @@
[General]
Callsign=G9BF
Node=123456
Port=4200
RptAddress=127.0.0.1
RptPort=3200
MyAddress=127.0.0.1
MyPort=4200
Daemon=0
[Info]
RXFrequency=435000000
TXFrequency=435000000
RXFrequency=430475000
TXFrequency=439475000
Power=1
Latitude=0.0
Longitude=0.0
@ -22,7 +24,7 @@ FilePath=.
FileRoot=YSFGateway
[aprs.fi]
Enable=1
Enable=0
# Server=noam.aprs2.net
Server=euro.aprs2.net
Port=14580

@ -26,9 +26,6 @@
<ClInclude Include="UDPSocket.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Utils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Version.h">
<Filter>Header Files</Filter>
</ClInclude>
@ -83,6 +80,9 @@
<ClInclude Include="Reflectors.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Utils.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Network.cpp">
@ -97,9 +97,6 @@
<ClCompile Include="UDPSocket.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Log.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -148,5 +145,8 @@
<ClCompile Include="Reflectors.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

@ -282,7 +282,7 @@ void CYSFPayload::writeDataFRModeData1(const unsigned char* dt, unsigned char* d
data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES;
unsigned char output[20U];
unsigned char output[25U];
for (unsigned int i = 0U; i < 20U; i++)
output[i] = dt[i] ^ WHITENING_DATA[i];
@ -326,7 +326,7 @@ void CYSFPayload::writeDataFRModeData2(const unsigned char* dt, unsigned char* d
data += YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES;
unsigned char output[20U];
unsigned char output[25U];
for (unsigned int i = 0U; i < 20U; i++)
output[i] = dt[i] ^ WHITENING_DATA[i];

Loading…
Cancel
Save