1
0
Fork 0

Bug fixes mostly,

ycs232-kbc
Jonathan Naylor 7 years ago
parent 64db730870
commit c17ffdbb89

@ -167,30 +167,27 @@ WX_STATUS CDTMF::decodeVDMode2Slice(unsigned char* ambe, bool end)
WX_STATUS CDTMF::validate() const WX_STATUS CDTMF::validate() const
{ {
size_t length = m_command.length(); size_t length = m_command.length();
if (length != 3U && length != 4U && length != 6U)
return WXS_NONE;
char first = m_command.at(0U); char first = m_command.at(0U);
if (first != '#' && first != 'A')
return WXS_NONE;
if (length == 3U) { if (length == 1U && first == '#') {
for (unsigned int i = 1U; i <= 3U; i++) { return WXS_DISCONNECT;
if (m_command.at(1U) < '0' || m_command.at(1U) > '9') } else if (length == 3U && first == 'A') {
for (unsigned int i = 1U; i < 3U; i++) {
if (m_command.at(i) < '0' || m_command.at(i) > '9')
return WXS_NONE; return WXS_NONE;
} }
return WXS_CONNECT_FCS; return WXS_CONNECT_FCS;
} else if (length == 4U) { } else if (length == 4U && first == 'A') {
for (unsigned int i = 1U; i <= 4U; i++) { for (unsigned int i = 1U; i < 4U; i++) {
if (m_command.at(1U) < '0' || m_command.at(1U) > '9') if (m_command.at(i) < '0' || m_command.at(i) > '9')
return WXS_NONE; return WXS_NONE;
} }
return WXS_CONNECT_FCS; return WXS_CONNECT_FCS;
} else { } else if (length == 6U && first == '#') {
for (unsigned int i = 1U; i <= 6U; i++) { for (unsigned int i = 1U; i < 6U; i++) {
if (m_command.at(1U) < '0' || m_command.at(1U) > '9') if (m_command.at(i) < '0' || m_command.at(i) > '9')
return WXS_NONE; return WXS_NONE;
} }
@ -199,6 +196,8 @@ WX_STATUS CDTMF::validate() const
return WXS_CONNECT_YSF; return WXS_CONNECT_YSF;
} }
return WXS_NONE;
} }
std::string CDTMF::getReflector() std::string CDTMF::getReflector()

@ -33,13 +33,12 @@ CFCSNetwork::CFCSNetwork(unsigned int port, const std::string& callsign, unsigne
m_socket(port), m_socket(port),
m_debug(debug), m_debug(debug),
m_address(), m_address(),
m_port(0U),
m_ping(NULL), m_ping(NULL),
m_info(NULL), m_info(NULL),
m_reflector(), m_reflector(),
m_buffer(1000U, "FCS Network Buffer"), m_buffer(1000U, "FCS Network Buffer"),
m_n(0U), m_n(0U),
m_pingTimer(1000U, 5U), m_pingTimer(1000U, 0U, 800U),
m_state(FCS_UNLINKED) m_state(FCS_UNLINKED)
{ {
m_info = new unsigned char[100U]; m_info = new unsigned char[100U];
@ -73,9 +72,6 @@ bool CFCSNetwork::open()
void CFCSNetwork::clearDestination() void CFCSNetwork::clearDestination()
{ {
m_address.s_addr = INADDR_NONE;
m_port = 0U;
m_pingTimer.stop(); m_pingTimer.stop();
m_state = FCS_UNLINKED; m_state = FCS_UNLINKED;
@ -85,9 +81,6 @@ void CFCSNetwork::write(const unsigned char* data)
{ {
assert(data != NULL); assert(data != NULL);
if (m_port == 0U)
return;
if (m_state != FCS_LINKED) if (m_state != FCS_LINKED)
return; return;
@ -99,12 +92,12 @@ void CFCSNetwork::write(const unsigned char* data)
if (m_debug) if (m_debug)
CUtils::dump(1U, "FCS Network Data Sent", buffer, 130U); CUtils::dump(1U, "FCS Network Data Sent", buffer, 130U);
m_socket.write(buffer, 130U, m_address, m_port); m_socket.write(buffer, 130U, m_address, FCS_PORT);
} }
bool CFCSNetwork::writeLink(const std::string& reflector) bool CFCSNetwork::writeLink(const std::string& reflector)
{ {
if (m_port == 0U) { if (m_state != FCS_LINKED) {
std::string name = reflector.substr(0U, 6U); std::string name = reflector.substr(0U, 6U);
if (m_addresses.count(name) == 0U) { if (m_addresses.count(name) == 0U) {
LogError("Unknown FCS reflector - %s", name.c_str()); LogError("Unknown FCS reflector - %s", name.c_str());
@ -118,32 +111,25 @@ bool CFCSNetwork::writeLink(const std::string& reflector)
} }
} }
m_port = FCS_PORT;
m_reflector = reflector; m_reflector = reflector;
::memcpy(m_ping + 10U, m_reflector.c_str(), 8U); ::memcpy(m_ping + 10U, m_reflector.c_str(), 8U);
writePing(); m_state = FCS_LINKING;
m_pingTimer.start(); m_pingTimer.start();
m_state = FCS_LINKING; writePing();
return true; return true;
} }
void CFCSNetwork::writeUnlink(unsigned int count) void CFCSNetwork::writeUnlink(unsigned int count)
{ {
if (m_port == 0U) if (m_state != FCS_LINKED)
return; return;
for (unsigned int i = 0U; i < count; i++) for (unsigned int i = 0U; i < count; i++)
m_socket.write((unsigned char*)"CLOSE ", 11U, m_address, m_port); m_socket.write((unsigned char*)"CLOSE ", 11U, m_address, FCS_PORT);
m_pingTimer.stop();
m_state = FCS_UNLINKED;
} }
void CFCSNetwork::clock(unsigned int ms) void CFCSNetwork::clock(unsigned int ms)
@ -156,7 +142,7 @@ void CFCSNetwork::clock(unsigned int ms)
if (length <= 0) if (length <= 0)
return; return;
if (m_port == 0U) if (m_state == FCS_UNLINKED)
return; return;
m_pingTimer.clock(ms); m_pingTimer.clock(ms);
@ -165,18 +151,20 @@ void CFCSNetwork::clock(unsigned int ms)
m_pingTimer.start(); m_pingTimer.start();
} }
if (address.s_addr != m_address.s_addr || port != m_port) if (address.s_addr != m_address.s_addr || port != FCS_PORT)
return; return;
if (m_debug) if (m_debug)
CUtils::dump(1U, "FCS Network Data Received", buffer, length); CUtils::dump(1U, "FCS Network Data Received", buffer, length);
if (length == 7) { if (length == 7) {
LogMessage("Linked to %s", m_reflector.c_str());
m_state = FCS_LINKED; m_state = FCS_LINKED;
writeInfo(); writeInfo();
} }
if (length == 10 && m_state == FCS_LINKING) { if (length == 10 && m_state == FCS_LINKING) {
LogMessage("Linked to %s", m_reflector.c_str());
m_state = FCS_LINKED; m_state = FCS_LINKED;
writeInfo(); writeInfo();
} }
@ -201,17 +189,22 @@ unsigned int CFCSNetwork::read(unsigned char* data)
// Pass pings up to the gateway to reset the lost timer. // Pass pings up to the gateway to reset the lost timer.
if (len == 10U) { if (len == 10U) {
m_buffer.getData(data, len); m_buffer.getData(data, len);
return 10U;
::memset(data + 0U, ' ', 14U);
::memcpy(data + 0U, "YSFP", 4U);
::memcpy(data + 4U, m_reflector.c_str(), 8U);
return 14U;
} }
unsigned char buffer[130U]; unsigned char buffer[130U];
m_buffer.getData(buffer, len); m_buffer.getData(buffer, len);
::memcpy(data + 0U, "YSFDDB0SAT DB0SAT-RPTALL ", 35U); ::memcpy(data + 0U, "YSFD ALL ", 35U);
::memcpy(data + 35U, buffer, 120U); ::memcpy(data + 35U, buffer, 120U);
// Put the reflector name as the via callsign. // Put the reflector name as the via callsign.
::memcpy(data + 4U, buffer + 121U, 8U); ::memcpy(data + 4U, m_reflector.c_str(), 8U);
data[34U] = m_n; data[34U] = m_n;
m_n += 2U; m_n += 2U;
@ -228,22 +221,22 @@ void CFCSNetwork::close()
void CFCSNetwork::writeInfo() void CFCSNetwork::writeInfo()
{ {
if (m_port == 0U) if (m_state != FCS_LINKED)
return; return;
if (m_debug) if (m_debug)
CUtils::dump(1U, "FCS Network Data Sent", m_info, 100U); CUtils::dump(1U, "FCS Network Data Sent", m_info, 100U);
m_socket.write(m_info, 100U, m_address, m_port); m_socket.write(m_info, 100U, m_address, FCS_PORT);
} }
void CFCSNetwork::writePing() void CFCSNetwork::writePing()
{ {
if (m_port == 0U) if (m_state == FCS_UNLINKED)
return; return;
if (m_debug) if (m_debug)
CUtils::dump(1U, "FCS Network Data Sent", m_ping, 25U); CUtils::dump(1U, "FCS Network Data Sent", m_ping, 25U);
m_socket.write(m_ping, 25U, m_address, m_port); m_socket.write(m_ping, 25U, m_address, FCS_PORT);
} }

@ -59,7 +59,6 @@ private:
CUDPSocket m_socket; CUDPSocket m_socket;
bool m_debug; bool m_debug;
in_addr m_address; in_addr m_address;
unsigned int m_port;
unsigned char* m_ping; unsigned char* m_ping;
unsigned char* m_info; unsigned char* m_info;
std::string m_reflector; std::string m_reflector;

@ -564,11 +564,16 @@ void CYSFGateway::processDTMF(unsigned char* buffer, unsigned char dt)
} }
break; break;
case WXS_CONNECT_FCS: { case WXS_CONNECT_FCS: {
std::string id = m_dtmf.getReflector(); std::string raw = m_dtmf.getReflector();
if (id.length() == 2U) std::string id = "FCS00";
id = "FCS00" + id.at(0U) + std::string("0") + id.at(1U); if (raw.length() == 2U) {
else id += raw.at(0U) + std::string("0") + raw.at(1U);
id = "FCS00" + id.at(0U) + id.at(1U) + id.at(2U); } else if (raw.length() == 3U) {
id += raw;
} else {
LogWarning("Nonsense from the DTMF decoder - \"%s\"", raw.c_str());
return;
}
if (m_linkType == LINK_YSF) { if (m_linkType == LINK_YSF) {
m_ysfNetwork->writeUnlink(3U); m_ysfNetwork->writeUnlink(3U);

Loading…
Cancel
Save