1
0
Fork 0

Handle loss of lnks.

ycs232-kbc
Jonathan Naylor 4 years ago
parent 4c59b42c20
commit 5015ad9ed8

@ -242,7 +242,7 @@ int CDGIdGateway::run()
std::string locator = calculateLocator(); std::string locator = calculateLocator();
unsigned int id = m_conf.getId(); unsigned int id = m_conf.getId();
dgIdNetwork[dgid] = new CFCSNetwork(name, local, m_callsign, rxFrequency, txFrequency, locator, id, debug); dgIdNetwork[dgid] = new CFCSNetwork(name, local, m_callsign, rxFrequency, txFrequency, locator, id, statc, debug);
dgIdNetwork[dgid]->m_modes = DT_VD_MODE1 | DT_VD_MODE2 | DT_VOICE_FR_MODE | DT_DATA_FR_MODE; dgIdNetwork[dgid]->m_modes = DT_VD_MODE1 | DT_VD_MODE2 | DT_VOICE_FR_MODE | DT_DATA_FR_MODE;
dgIdNetwork[dgid]->m_static = statc; dgIdNetwork[dgid]->m_static = statc;
dgIdNetwork[dgid]->m_rfHangTime = rfHangTime; dgIdNetwork[dgid]->m_rfHangTime = rfHangTime;
@ -255,7 +255,7 @@ int CDGIdGateway::run()
CYSFReflector* reflector = reflectors->findByName(name); CYSFReflector* reflector = reflectors->findByName(name);
if (reflector != NULL) { if (reflector != NULL) {
dgIdNetwork[dgid] = new CYSFNetwork(local, reflector->m_name, reflector->m_addr, reflector->m_addrLen, m_callsign, debug); dgIdNetwork[dgid] = new CYSFNetwork(local, reflector->m_name, reflector->m_addr, reflector->m_addrLen, m_callsign, statc, debug);
dgIdNetwork[dgid]->m_modes = DT_VD_MODE1 | DT_VD_MODE2 | DT_VOICE_FR_MODE | DT_DATA_FR_MODE; dgIdNetwork[dgid]->m_modes = DT_VD_MODE1 | DT_VD_MODE2 | DT_VOICE_FR_MODE | DT_DATA_FR_MODE;
dgIdNetwork[dgid]->m_static = statc; dgIdNetwork[dgid]->m_static = statc;
dgIdNetwork[dgid]->m_rfHangTime = rfHangTime; dgIdNetwork[dgid]->m_rfHangTime = rfHangTime;
@ -276,7 +276,7 @@ int CDGIdGateway::run()
CYSFReflector* reflector = reflectors->findByName(name); CYSFReflector* reflector = reflectors->findByName(name);
if (reflector != NULL) { if (reflector != NULL) {
dgIdNetwork[dgid] = new CYCSNetwork(local, reflector->m_name, reflector->m_addr, reflector->m_addrLen, m_callsign, rxFrequency, txFrequency, locator, description, id, (*it)->m_netDGId, debug); dgIdNetwork[dgid] = new CYCSNetwork(local, reflector->m_name, reflector->m_addr, reflector->m_addrLen, m_callsign, rxFrequency, txFrequency, locator, description, id, (*it)->m_netDGId, statc, debug);
dgIdNetwork[dgid]->m_modes = DT_VD_MODE1 | DT_VD_MODE2 | DT_VOICE_FR_MODE | DT_DATA_FR_MODE; dgIdNetwork[dgid]->m_modes = DT_VD_MODE1 | DT_VD_MODE2 | DT_VOICE_FR_MODE | DT_DATA_FR_MODE;
dgIdNetwork[dgid]->m_static = statc; dgIdNetwork[dgid]->m_static = statc;
dgIdNetwork[dgid]->m_rfHangTime = rfHangTime; dgIdNetwork[dgid]->m_rfHangTime = rfHangTime;
@ -323,7 +323,7 @@ int CDGIdGateway::run()
sockaddr_storage addr; sockaddr_storage addr;
unsigned int addrLen; unsigned int addrLen;
if (CUDPSocket::lookup((*it)->m_address, (*it)->m_port, addr, addrLen) == 0) { if (CUDPSocket::lookup((*it)->m_address, (*it)->m_port, addr, addrLen) == 0) {
dgIdNetwork[dgid] = new CYSFNetwork(local, "PARROT", addr, addrLen, m_callsign, debug); dgIdNetwork[dgid] = new CYSFNetwork(local, "PARROT", addr, addrLen, m_callsign, statc, debug);
dgIdNetwork[dgid]->m_modes = DT_VD_MODE1 | DT_VD_MODE2 | DT_VOICE_FR_MODE | DT_DATA_FR_MODE; dgIdNetwork[dgid]->m_modes = DT_VD_MODE1 | DT_VD_MODE2 | DT_VOICE_FR_MODE | DT_DATA_FR_MODE;
dgIdNetwork[dgid]->m_static = statc; dgIdNetwork[dgid]->m_static = statc;
dgIdNetwork[dgid]->m_rfHangTime = rfHangTime; dgIdNetwork[dgid]->m_rfHangTime = rfHangTime;
@ -339,7 +339,7 @@ int CDGIdGateway::run()
sockaddr_storage addr; sockaddr_storage addr;
unsigned int addrLen; unsigned int addrLen;
if (CUDPSocket::lookup((*it)->m_address, (*it)->m_port, addr, addrLen) == 0) { if (CUDPSocket::lookup((*it)->m_address, (*it)->m_port, addr, addrLen) == 0) {
dgIdNetwork[dgid] = new CYSFNetwork(local, "YSF2DMR", addr, addrLen, m_callsign, debug); dgIdNetwork[dgid] = new CYSFNetwork(local, "YSF2DMR", addr, addrLen, m_callsign, statc, debug);
dgIdNetwork[dgid]->m_modes = DT_VD_MODE1 | DT_VD_MODE2; dgIdNetwork[dgid]->m_modes = DT_VD_MODE1 | DT_VD_MODE2;
dgIdNetwork[dgid]->m_static = statc; dgIdNetwork[dgid]->m_static = statc;
dgIdNetwork[dgid]->m_rfHangTime = rfHangTime; dgIdNetwork[dgid]->m_rfHangTime = rfHangTime;
@ -355,7 +355,7 @@ int CDGIdGateway::run()
sockaddr_storage addr; sockaddr_storage addr;
unsigned int addrLen; unsigned int addrLen;
if (CUDPSocket::lookup((*it)->m_address, (*it)->m_port, addr, addrLen) == 0) { if (CUDPSocket::lookup((*it)->m_address, (*it)->m_port, addr, addrLen) == 0) {
dgIdNetwork[dgid] = new CYSFNetwork(local, "YSF2NXDN", addr, addrLen, m_callsign, debug); dgIdNetwork[dgid] = new CYSFNetwork(local, "YSF2NXDN", addr, addrLen, m_callsign, statc, debug);
dgIdNetwork[dgid]->m_modes = DT_VD_MODE1 | DT_VD_MODE2; dgIdNetwork[dgid]->m_modes = DT_VD_MODE1 | DT_VD_MODE2;
dgIdNetwork[dgid]->m_static = statc; dgIdNetwork[dgid]->m_static = statc;
dgIdNetwork[dgid]->m_rfHangTime = rfHangTime; dgIdNetwork[dgid]->m_rfHangTime = rfHangTime;
@ -371,7 +371,7 @@ int CDGIdGateway::run()
sockaddr_storage addr; sockaddr_storage addr;
unsigned int addrLen; unsigned int addrLen;
if (CUDPSocket::lookup((*it)->m_address, (*it)->m_port, addr, addrLen) == 0) { if (CUDPSocket::lookup((*it)->m_address, (*it)->m_port, addr, addrLen) == 0) {
dgIdNetwork[dgid] = new CYSFNetwork(local, "YSF2P25", addr, addrLen, m_callsign, debug); dgIdNetwork[dgid] = new CYSFNetwork(local, "YSF2P25", addr, addrLen, m_callsign, statc, debug);
dgIdNetwork[dgid]->m_modes = DT_VOICE_FR_MODE; dgIdNetwork[dgid]->m_modes = DT_VOICE_FR_MODE;
dgIdNetwork[dgid]->m_static = statc; dgIdNetwork[dgid]->m_static = statc;
dgIdNetwork[dgid]->m_rfHangTime = rfHangTime; dgIdNetwork[dgid]->m_rfHangTime = rfHangTime;
@ -416,89 +416,85 @@ int CDGIdGateway::run()
memset(buffer, 0U, 200U); memset(buffer, 0U, 200U);
if (rptNetwork.read(0U, buffer) > 0U) { if (rptNetwork.read(0U, buffer) > 0U) {
if (::memcmp(buffer + 0U, "YSFD", 4U) == 0) { CYSFFICH fich;
CYSFFICH fich; bool valid = fich.decode(buffer + 35U);
bool valid = fich.decode(buffer + 35U); if (valid) {
if (valid) { unsigned char fi = fich.getFI();
unsigned char fi = fich.getFI(); unsigned char dt = fich.getDT();
unsigned char dt = fich.getDT(); unsigned char fn = fich.getFN();
unsigned char fn = fich.getFN(); unsigned char ft = fich.getFT();
unsigned char ft = fich.getFT(); unsigned char dgId = fich.getDGId();
unsigned char dgId = fich.getDGId();
if (dgId != 0U && dgId != currentDGId) {
if (dgId != 0U && dgId != currentDGId) { if (dgIdNetwork[currentDGId] != NULL && !dgIdNetwork[currentDGId]->m_static) {
if (dgIdNetwork[currentDGId] != NULL && !dgIdNetwork[currentDGId]->m_static) { dgIdNetwork[currentDGId]->unlink();
dgIdNetwork[currentDGId]->unlink(); dgIdNetwork[currentDGId]->unlink();
dgIdNetwork[currentDGId]->unlink(); dgIdNetwork[currentDGId]->unlink();
dgIdNetwork[currentDGId]->unlink(); }
}
if (dgIdNetwork[dgId] != NULL && !dgIdNetwork[dgId]->m_static) {
dgIdNetwork[dgId]->link();
dgIdNetwork[dgId]->link();
dgIdNetwork[dgId]->link();
}
std::string desc = dgIdNetwork[dgId]->getDesc(dgId); if (dgIdNetwork[dgId] != NULL && !dgIdNetwork[dgId]->m_static) {
LogMessage("DG-ID set to %u (%s) via RF", dgId, desc.c_str()); dgIdNetwork[dgId]->link();
currentDGId = dgId; dgIdNetwork[dgId]->link();
state = DS_NOTLINKED; dgIdNetwork[dgId]->link();
fromRF = true;
} }
if (m_gps != NULL) std::string desc = dgIdNetwork[dgId]->getDesc(dgId);
m_gps->data(buffer + 14U, buffer + 35U, fi, dt, fn, ft); LogMessage("DG-ID set to %u (%s) via RF", dgId, desc.c_str());
currentDGId = dgId;
state = DS_NOTLINKED;
fromRF = true;
}
if (currentDGId != 0U && dgIdNetwork[currentDGId] != NULL) { if (m_gps != NULL)
// Only allow the wanted modes through m_gps->data(buffer + 14U, buffer + 35U, fi, dt, fn, ft);
if ((dt == YSF_DT_VD_MODE1 && (dgIdNetwork[currentDGId]->m_modes & DT_VD_MODE1) != 0U) ||
(dt == YSF_DT_DATA_FR_MODE && (dgIdNetwork[currentDGId]->m_modes & DT_DATA_FR_MODE) != 0U) ||
(dt == YSF_DT_VD_MODE2 && (dgIdNetwork[currentDGId]->m_modes & DT_VD_MODE2) != 0U) ||
(dt == YSF_DT_VOICE_FR_MODE && (dgIdNetwork[currentDGId]->m_modes & DT_VOICE_FR_MODE) != 0U)) {
unsigned int dgId = dgIdNetwork[currentDGId]->getDGId();
fich.setDGId(dgId);
fich.encode(buffer + 35U);
dgIdNetwork[currentDGId]->write(currentDGId, buffer); if (currentDGId != 0U && dgIdNetwork[currentDGId] != NULL) {
} // Only allow the wanted modes through
if ((dt == YSF_DT_VD_MODE1 && (dgIdNetwork[currentDGId]->m_modes & DT_VD_MODE1) != 0U) ||
(dt == YSF_DT_DATA_FR_MODE && (dgIdNetwork[currentDGId]->m_modes & DT_DATA_FR_MODE) != 0U) ||
(dt == YSF_DT_VD_MODE2 && (dgIdNetwork[currentDGId]->m_modes & DT_VD_MODE2) != 0U) ||
(dt == YSF_DT_VOICE_FR_MODE && (dgIdNetwork[currentDGId]->m_modes & DT_VOICE_FR_MODE) != 0U)) {
unsigned int dgId = dgIdNetwork[currentDGId]->getDGId();
fich.setDGId(dgId);
fich.encode(buffer + 35U);
inactivityTimer.setTimeout(dgIdNetwork[currentDGId]->m_rfHangTime); dgIdNetwork[currentDGId]->write(currentDGId, buffer);
inactivityTimer.start();
} }
}
if ((buffer[34U] & 0x01U) == 0x01U) { inactivityTimer.setTimeout(dgIdNetwork[currentDGId]->m_rfHangTime);
if (m_gps != NULL) inactivityTimer.start();
m_gps->reset();
if (nPips > 0U && fromRF)
bleepTimer.start();
} }
} }
if ((buffer[34U] & 0x01U) == 0x01U) {
if (m_gps != NULL)
m_gps->reset();
if (nPips > 0U && fromRF)
bleepTimer.start();
}
} }
for (unsigned int i = 1U; i < 100U; i++) { for (unsigned int i = 1U; i < 100U; i++) {
if (dgIdNetwork[i] != NULL) { if (dgIdNetwork[i] != NULL) {
unsigned int len = dgIdNetwork[i]->read(i, buffer); unsigned int len = dgIdNetwork[i]->read(i, buffer);
if (len > 0U && (i == currentDGId || currentDGId == 0U)) { if (len > 0U && (i == currentDGId || currentDGId == 0U)) {
if (::memcmp(buffer + 0U, "YSFD", 4U) == 0) { CYSFFICH fich;
CYSFFICH fich; bool valid = fich.decode(buffer + 35U);
bool valid = fich.decode(buffer + 35U); if (valid) {
if (valid) { fich.setDGId(i);
fich.setDGId(i); fich.encode(buffer + 35U);
fich.encode(buffer + 35U);
rptNetwork.write(0U, buffer);
rptNetwork.write(0U, buffer);
inactivityTimer.setTimeout(dgIdNetwork[i]->m_netHangTime);
inactivityTimer.setTimeout(dgIdNetwork[i]->m_netHangTime); inactivityTimer.start();
inactivityTimer.start();
if (currentDGId == 0U) {
if (currentDGId == 0U) { std::string desc = dgIdNetwork[i]->getDesc(i);
std::string desc = dgIdNetwork[i]->getDesc(i); LogMessage("DG-ID set to %u (%s) via Network", i, desc.c_str());
LogMessage("DG-ID set to %u (%s) via Network", i, desc.c_str()); currentDGId = i;
currentDGId = i; state = DS_LINKED;
state = DS_LINKED; fromRF = false;
fromRF = false;
}
} }
} }
} }
@ -547,7 +543,10 @@ int CDGIdGateway::run()
if (dgIdNetwork[currentDGId] != NULL) { if (dgIdNetwork[currentDGId] != NULL) {
DGID_STATUS netState = dgIdNetwork[currentDGId]->getStatus(); DGID_STATUS netState = dgIdNetwork[currentDGId]->getStatus();
if (fromRF && state != DS_LINKED && netState == DS_LINKED) bool statc = dgIdNetwork[currentDGId]->m_static;
if (fromRF && state != DS_LINKED && netState != DS_LINKED && statc)
nPips = 3U;
else if (fromRF && state != DS_LINKED && netState == DS_LINKED)
nPips = 1U; nPips = 1U;
else if (fromRF && state == DS_LINKED && netState != DS_LINKED) else if (fromRF && state == DS_LINKED && netState != DS_LINKED)
nPips = 3U; nPips = 3U;

@ -29,18 +29,20 @@ const char* FCS_VERSION = "MMDVM";
const unsigned int BUFFER_LENGTH = 200U; const unsigned int BUFFER_LENGTH = 200U;
CFCSNetwork::CFCSNetwork(const std::string& reflector, unsigned int port, const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, const std::string& locator, unsigned int id, bool debug) : CFCSNetwork::CFCSNetwork(const std::string& reflector, unsigned int port, const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, const std::string& locator, unsigned int id, bool statc, bool debug) :
m_socket(port), m_socket(port),
m_debug(debug), m_debug(debug),
m_addr(), m_addr(),
m_addrLen(0U), m_addrLen(0U),
m_static(statc),
m_ping(NULL), m_ping(NULL),
m_info(NULL), m_info(NULL),
m_reflector(reflector), m_reflector(reflector),
m_print(), m_print(),
m_buffer(1000U, "FCS Network Buffer"), m_buffer(1000U, "FCS Network Buffer"),
m_n(0U), m_n(0U),
m_pingTimer(1000U, 0U, 800U), m_sendPollTimer(1000U, 0U, 800U),
m_recvPollTimer(1000U, 60U),
m_resetTimer(1000U, 1U), m_resetTimer(1000U, 1U),
m_state(DS_NOTOPEN) m_state(DS_NOTOPEN)
{ {
@ -130,9 +132,10 @@ void CFCSNetwork::link()
m_state = DS_LINKING; m_state = DS_LINKING;
m_pingTimer.start(); m_sendPollTimer.start();
m_recvPollTimer.start();
writePing(); writePoll();
} }
void CFCSNetwork::unlink() void CFCSNetwork::unlink()
@ -142,7 +145,8 @@ void CFCSNetwork::unlink()
m_socket.write((unsigned char*)"CLOSE ", 11U, m_addr, m_addrLen); m_socket.write((unsigned char*)"CLOSE ", 11U, m_addr, m_addrLen);
m_pingTimer.stop(); m_sendPollTimer.stop();
m_recvPollTimer.stop();
LogMessage("Unlinked from %s", m_print.c_str()); LogMessage("Unlinked from %s", m_print.c_str());
@ -154,10 +158,23 @@ void CFCSNetwork::clock(unsigned int ms)
if (m_state == DS_NOTOPEN) if (m_state == DS_NOTOPEN)
return; return;
m_pingTimer.clock(ms); m_recvPollTimer.clock(ms);
if (m_pingTimer.isRunning() && m_pingTimer.hasExpired()) { if (m_recvPollTimer.isRunning() && m_recvPollTimer.hasExpired()) {
writePing(); if (m_static) {
m_pingTimer.start(); m_state = DS_LINKING;
} else {
m_state = DS_NOTLINKED;
m_sendPollTimer.stop();
}
LogMessage("Lost link to %s", m_print.c_str());
m_recvPollTimer.stop();
}
m_sendPollTimer.clock(ms);
if (m_sendPollTimer.isRunning() && m_sendPollTimer.hasExpired()) {
writePoll();
m_sendPollTimer.start();
} }
m_resetTimer.clock(ms); m_resetTimer.clock(ms);
@ -185,30 +202,24 @@ void CFCSNetwork::clock(unsigned int ms)
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 || length == 10) {
if (m_state == DS_LINKING) m_recvPollTimer.start();
if (m_state == DS_LINKING) {
LogMessage("Linked to %s", m_print.c_str()); LogMessage("Linked to %s", m_print.c_str());
m_state = DS_LINKED; m_state = DS_LINKED;
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_addr, m_addrLen); m_socket.write(m_info, 100U, m_addr, m_addrLen);
}
} }
if (length == 10 && m_state == DS_LINKING) { if (length == 130) {
LogMessage("Linked to %s", m_print.c_str()); m_recvPollTimer.start();
m_state = DS_LINKED;
if (m_debug)
CUtils::dump(1U, "FCS Network Data Sent", m_info, 100U);
m_socket.write(m_info, 100U, m_addr, m_addrLen);
}
if (length == 7 || length == 10 || length == 130) {
unsigned char len = length; unsigned char len = length;
m_buffer.addData(&len, 1U); m_buffer.addData(&len, 1U);
m_buffer.addData(buffer, len); m_buffer.addData(buffer, len);
@ -225,16 +236,6 @@ unsigned int CFCSNetwork::read(unsigned int dgid, unsigned char* data)
unsigned char len = 0U; unsigned char len = 0U;
m_buffer.getData(&len, 1U); m_buffer.getData(&len, 1U);
if (len != 130U) {
m_buffer.getData(data, len);
::memset(data + 0U, ' ', 14U);
::memcpy(data + 0U, "YSFP", 4U);
::memcpy(data + 4U, m_print.c_str(), 8U);
return 14U;
}
m_resetTimer.start(); m_resetTimer.start();
unsigned char buffer[130U]; unsigned char buffer[130U];
@ -262,7 +263,7 @@ void CFCSNetwork::close()
m_state = DS_NOTOPEN; m_state = DS_NOTOPEN;
} }
void CFCSNetwork::writePing() void CFCSNetwork::writePoll()
{ {
if (m_state != DS_LINKING && m_state != DS_LINKED) if (m_state != DS_LINKING && m_state != DS_LINKED)
return; return;

@ -30,7 +30,7 @@
class CFCSNetwork : public CDGIdNetwork { class CFCSNetwork : public CDGIdNetwork {
public: public:
CFCSNetwork(const std::string& reflector, unsigned int port, const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, const std::string& locator, unsigned int id, bool debug); CFCSNetwork(const std::string& reflector, unsigned int port, const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, const std::string& locator, unsigned int id, bool statc, bool debug);
virtual ~CFCSNetwork(); virtual ~CFCSNetwork();
virtual std::string getDesc(unsigned int dgId); virtual std::string getDesc(unsigned int dgId);
@ -58,17 +58,19 @@ private:
bool m_debug; bool m_debug;
sockaddr_storage m_addr; sockaddr_storage m_addr;
unsigned int m_addrLen; unsigned int m_addrLen;
bool m_static;
unsigned char* m_ping; unsigned char* m_ping;
unsigned char* m_info; unsigned char* m_info;
std::string m_reflector; std::string m_reflector;
std::string m_print; std::string m_print;
CRingBuffer<unsigned char> m_buffer; CRingBuffer<unsigned char> m_buffer;
unsigned char m_n; unsigned char m_n;
CTimer m_pingTimer; CTimer m_sendPollTimer;
CTimer m_recvPollTimer;
CTimer m_resetTimer; CTimer m_resetTimer;
DGID_STATUS m_state; DGID_STATUS m_state;
void writePing(); void writePoll();
}; };
#endif #endif

@ -19,6 +19,6 @@
#if !defined(VERSION_H) #if !defined(VERSION_H)
#define VERSION_H #define VERSION_H
const char* VERSION = "20200925"; const char* VERSION = "20200926";
#endif #endif

@ -28,17 +28,19 @@
const unsigned int BUFFER_LENGTH = 200U; const unsigned int BUFFER_LENGTH = 200U;
CYCSNetwork::CYCSNetwork(unsigned int localPort, const std::string& name, const sockaddr_storage& addr, unsigned int addrLen, const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, const std::string& locator, const std::string& description, unsigned int id, unsigned int dgId, bool debug) : CYCSNetwork::CYCSNetwork(unsigned int localPort, const std::string& name, const sockaddr_storage& addr, unsigned int addrLen, const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, const std::string& locator, const std::string& description, unsigned int id, unsigned int dgId, bool statc, bool debug) :
m_socket(localPort), m_socket(localPort),
m_debug(debug), m_debug(debug),
m_addr(addr), m_addr(addr),
m_addrLen(addrLen), m_addrLen(addrLen),
m_static(statc),
m_poll(NULL), m_poll(NULL),
m_options(NULL), m_options(NULL),
m_info(NULL), m_info(NULL),
m_unlink(NULL), m_unlink(NULL),
m_buffer(1000U, "YCS Network Buffer"), m_buffer(1000U, "YCS Network Buffer"),
m_pollTimer(1000U, 5U), m_sendPollTimer(1000U, 5U),
m_recvPollTimer(1000U, 60U),
m_name(name), m_name(name),
m_state(DS_NOTOPEN), m_state(DS_NOTOPEN),
m_dgId(dgId) m_dgId(dgId)
@ -142,6 +144,9 @@ void CYCSNetwork::link()
m_state = DS_LINKING; m_state = DS_LINKING;
m_sendPollTimer.start();
m_recvPollTimer.start();
writePoll(); writePoll();
} }
@ -150,8 +155,6 @@ void CYCSNetwork::writePoll()
if (m_state != DS_LINKING && m_state != DS_LINKED) if (m_state != DS_LINKING && m_state != DS_LINKED)
return; return;
m_pollTimer.start();
if (m_debug) if (m_debug)
CUtils::dump(1U, "YCS Network Data Sent", m_poll, 14U); CUtils::dump(1U, "YCS Network Data Sent", m_poll, 14U);
@ -163,7 +166,8 @@ void CYCSNetwork::unlink()
if (m_state != DS_LINKED) if (m_state != DS_LINKED)
return; return;
m_pollTimer.stop(); m_sendPollTimer.stop();
m_recvPollTimer.stop();
if (m_debug) if (m_debug)
CUtils::dump(1U, "YCS Network Data Sent", m_unlink, 14U); CUtils::dump(1U, "YCS Network Data Sent", m_unlink, 14U);
@ -180,9 +184,24 @@ void CYCSNetwork::clock(unsigned int ms)
if (m_state == DS_NOTOPEN) if (m_state == DS_NOTOPEN)
return; return;
m_pollTimer.clock(ms); m_recvPollTimer.clock(ms);
if (m_pollTimer.isRunning() && m_pollTimer.hasExpired()) if (m_recvPollTimer.isRunning() && m_recvPollTimer.hasExpired()) {
if (m_static) {
m_state = DS_LINKING;
} else {
m_state = DS_NOTLINKED;
m_sendPollTimer.stop();
}
LogMessage("Lost link to %s", m_name.c_str());
m_recvPollTimer.stop();
}
m_sendPollTimer.clock(ms);
if (m_sendPollTimer.isRunning() && m_sendPollTimer.hasExpired()) {
writePoll(); writePoll();
m_sendPollTimer.start();
}
unsigned char buffer[BUFFER_LENGTH]; unsigned char buffer[BUFFER_LENGTH];
sockaddr_storage addr; sockaddr_storage addr;
@ -201,6 +220,8 @@ void CYCSNetwork::clock(unsigned int ms)
CUtils::dump(1U, "YCS Network Data Received", buffer, length); CUtils::dump(1U, "YCS Network Data Received", buffer, length);
if (::memcmp(buffer, "YSFP", 4U) == 0) { if (::memcmp(buffer, "YSFP", 4U) == 0) {
m_recvPollTimer.start();
if (m_state == DS_LINKING) { if (m_state == DS_LINKING) {
LogMessage("Linked to %s", m_name.c_str()); LogMessage("Linked to %s", m_name.c_str());
@ -216,14 +237,11 @@ void CYCSNetwork::clock(unsigned int ms)
m_socket.write(m_info, 80U, m_addr, m_addrLen); m_socket.write(m_info, 80U, m_addr, m_addrLen);
} }
unsigned char len = length;
m_buffer.addData(&len, 1U);
m_buffer.addData(buffer, length);
} }
if (::memcmp(buffer, "YSFD", 4U) == 0) { if (::memcmp(buffer, "YSFD", 4U) == 0) {
m_recvPollTimer.start();
CYSFFICH fich; CYSFFICH fich;
bool valid = fich.decode(buffer + 35U); bool valid = fich.decode(buffer + 35U);
if (!valid) if (!valid)

@ -30,7 +30,7 @@
class CYCSNetwork : public CDGIdNetwork { class CYCSNetwork : public CDGIdNetwork {
public: public:
CYCSNetwork(unsigned int localPort, const std::string& name, const sockaddr_storage& addr, unsigned int addrLen, const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, const std::string& locator, const std::string& description, unsigned int id, unsigned int dgId, bool debug); CYCSNetwork(unsigned int localPort, const std::string& name, const sockaddr_storage& addr, unsigned int addrLen, const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, const std::string& locator, const std::string& description, unsigned int id, unsigned int dgId, bool statc, bool debug);
virtual ~CYCSNetwork(); virtual ~CYCSNetwork();
virtual std::string getDesc(unsigned int dgId); virtual std::string getDesc(unsigned int dgId);
@ -58,12 +58,14 @@ private:
bool m_debug; bool m_debug;
sockaddr_storage m_addr; sockaddr_storage m_addr;
unsigned int m_addrLen; unsigned int m_addrLen;
bool m_static;
unsigned char* m_poll; unsigned char* m_poll;
unsigned char* m_options; unsigned char* m_options;
unsigned char* m_info; unsigned char* m_info;
unsigned char* m_unlink; unsigned char* m_unlink;
CRingBuffer<unsigned char> m_buffer; CRingBuffer<unsigned char> m_buffer;
CTimer m_pollTimer; CTimer m_sendPollTimer;
CTimer m_recvPollTimer;
std::string m_name; std::string m_name;
DGID_STATUS m_state; DGID_STATUS m_state;
unsigned int m_dgId; unsigned int m_dgId;

@ -32,10 +32,12 @@ m_socket(localAddress, localPort),
m_debug(debug), m_debug(debug),
m_addr(addr), m_addr(addr),
m_addrLen(addrLen), m_addrLen(addrLen),
m_static(true),
m_poll(NULL), m_poll(NULL),
m_unlink(NULL), m_unlink(NULL),
m_buffer(1000U, "YSF Network Buffer"), m_buffer(1000U, "YSF Network Buffer"),
m_pollTimer(1000U, 5U), m_sendPollTimer(1000U, 5U),
m_recvPollTimer(1000U, 60U),
m_name(name), m_name(name),
m_state(DS_NOTOPEN) m_state(DS_NOTOPEN)
{ {
@ -54,15 +56,17 @@ m_state(DS_NOTOPEN)
} }
} }
CYSFNetwork::CYSFNetwork(unsigned int localPort, const std::string& name, const sockaddr_storage& addr, unsigned int addrLen, const std::string& callsign, bool debug) : CYSFNetwork::CYSFNetwork(unsigned int localPort, const std::string& name, const sockaddr_storage& addr, unsigned int addrLen, const std::string& callsign, bool statc, bool debug) :
m_socket(localPort), m_socket(localPort),
m_debug(debug), m_debug(debug),
m_addr(addr), m_addr(addr),
m_addrLen(addrLen), m_addrLen(addrLen),
m_static(statc),
m_poll(NULL), m_poll(NULL),
m_unlink(NULL), m_unlink(NULL),
m_buffer(1000U, "YSF Network Buffer"), m_buffer(1000U, "YSF Network Buffer"),
m_pollTimer(1000U, 5U), m_sendPollTimer(1000U, 5U),
m_recvPollTimer(1000U, 60U),
m_name(name), m_name(name),
m_state(DS_NOTOPEN) m_state(DS_NOTOPEN)
{ {
@ -142,6 +146,9 @@ void CYSFNetwork::link()
m_state = DS_LINKING; m_state = DS_LINKING;
m_sendPollTimer.start();
m_recvPollTimer.start();
writePoll(); writePoll();
} }
@ -150,8 +157,6 @@ void CYSFNetwork::writePoll()
if (m_state != DS_LINKING && m_state != DS_LINKED) if (m_state != DS_LINKING && m_state != DS_LINKED)
return; return;
m_pollTimer.start();
if (m_debug) if (m_debug)
CUtils::dump(1U, "YSF Network Data Sent", m_poll, 14U); CUtils::dump(1U, "YSF Network Data Sent", m_poll, 14U);
@ -163,7 +168,8 @@ void CYSFNetwork::unlink()
if (m_state != DS_LINKED) if (m_state != DS_LINKED)
return; return;
m_pollTimer.stop(); m_sendPollTimer.stop();
m_recvPollTimer.stop();
if (m_debug) if (m_debug)
CUtils::dump(1U, "YSF Network Data Sent", m_unlink, 14U); CUtils::dump(1U, "YSF Network Data Sent", m_unlink, 14U);
@ -180,9 +186,24 @@ void CYSFNetwork::clock(unsigned int ms)
if (m_state == DS_NOTOPEN) if (m_state == DS_NOTOPEN)
return; return;
m_pollTimer.clock(ms); m_recvPollTimer.clock(ms);
if (m_pollTimer.isRunning() && m_pollTimer.hasExpired()) if (m_recvPollTimer.isRunning() && m_recvPollTimer.hasExpired()) {
if (m_static) {
m_state = DS_LINKING;
} else {
m_state = DS_NOTLINKED;
m_sendPollTimer.stop();
}
LogMessage("Lost link to %s", m_name.c_str());
m_recvPollTimer.stop();
}
m_sendPollTimer.clock(ms);
if (m_sendPollTimer.isRunning() && m_sendPollTimer.hasExpired()) {
writePoll(); writePoll();
m_sendPollTimer.start();
}
unsigned char buffer[BUFFER_LENGTH]; unsigned char buffer[BUFFER_LENGTH];
sockaddr_storage addr; sockaddr_storage addr;
@ -200,27 +221,27 @@ void CYSFNetwork::clock(unsigned int ms)
if (m_debug) if (m_debug)
CUtils::dump(1U, "YSF Network Data Received", buffer, length); CUtils::dump(1U, "YSF Network Data Received", buffer, length);
// Throw away any options messages if (::memcmp(buffer, "YSFP", 4U) == 0) {
if (::memcmp(buffer, "YSFO", 4U) == 0) m_recvPollTimer.start();
return;
// Throw away any info messages
if (::memcmp(buffer, "YSFI", 4U) == 0)
return;
if (::memcmp(buffer, "YSFP", 4U) == 0 && m_state == DS_LINKING) { if (m_state == DS_LINKING) {
if (strcmp(m_name.c_str(),"MMDVM")== 0) if (strcmp(m_name.c_str(), "MMDVM") == 0)
LogMessage("Link successful to %s", m_name.c_str()); LogMessage("Link successful to %s", m_name.c_str());
else else
LogMessage("Linked to %s", m_name.c_str()); LogMessage("Linked to %s", m_name.c_str());
m_state = DS_LINKED; m_state = DS_LINKED;
}
} }
unsigned char len = length; if (::memcmp(buffer, "YSFD", 4U) == 0) {
m_buffer.addData(&len, 1U); m_recvPollTimer.start();
m_buffer.addData(buffer, length); unsigned char len = length;
m_buffer.addData(&len, 1U);
m_buffer.addData(buffer, length);
}
} }
unsigned int CYSFNetwork::read(unsigned int dgid, unsigned char* data) unsigned int CYSFNetwork::read(unsigned int dgid, unsigned char* data)

@ -31,7 +31,7 @@
class CYSFNetwork : public CDGIdNetwork { class CYSFNetwork : public CDGIdNetwork {
public: public:
CYSFNetwork(const std::string& localAddress, unsigned int localPort, const std::string& name, const sockaddr_storage& addr, unsigned int addrLen, const std::string& callsign, bool debug); CYSFNetwork(const std::string& localAddress, unsigned int localPort, const std::string& name, const sockaddr_storage& addr, unsigned int addrLen, const std::string& callsign, bool debug);
CYSFNetwork(unsigned int localPort, const std::string& name, const sockaddr_storage& addr, unsigned int addrLen, const std::string& callsign, bool debug); CYSFNetwork(unsigned int localPort, const std::string& name, const sockaddr_storage& addr, unsigned int addrLen, const std::string& callsign, bool statc, bool debug);
virtual ~CYSFNetwork(); virtual ~CYSFNetwork();
virtual std::string getDesc(unsigned int dgId); virtual std::string getDesc(unsigned int dgId);
@ -59,10 +59,12 @@ private:
bool m_debug; bool m_debug;
sockaddr_storage m_addr; sockaddr_storage m_addr;
unsigned int m_addrLen; unsigned int m_addrLen;
bool m_static;
unsigned char* m_poll; unsigned char* m_poll;
unsigned char* m_unlink; unsigned char* m_unlink;
CRingBuffer<unsigned char> m_buffer; CRingBuffer<unsigned char> m_buffer;
CTimer m_pollTimer; CTimer m_sendPollTimer;
CTimer m_recvPollTimer;
std::string m_name; std::string m_name;
DGID_STATUS m_state; DGID_STATUS m_state;

Loading…
Cancel
Save