mirror of
https://github.com/g4klx/DAPNETGateway.git
synced 2026-08-26 12:32:45 -04:00
Optionally suppress time messages when messages are being queued.
This commit is contained in:
parent
25d431ba14
commit
88eacf7422
5 changed files with 39 additions and 24 deletions
9
Conf.cpp
9
Conf.cpp
|
|
@ -48,6 +48,7 @@ m_logFileRoot(),
|
|||
m_dapnetAddress(),
|
||||
m_dapnetPort(0U),
|
||||
m_dapnetAuthKey(),
|
||||
m_dapnetSuppressTime(true),
|
||||
m_dapnetDebug(false)
|
||||
{
|
||||
}
|
||||
|
|
@ -118,6 +119,8 @@ bool CConf::read()
|
|||
m_dapnetPort = (unsigned int)::atoi(value);
|
||||
else if (::strcmp(key, "AuthKey") == 0)
|
||||
m_dapnetAuthKey = value;
|
||||
else if (::strcmp(key, "SuppressTimeWhenBusy") == 0)
|
||||
m_dapnetSuppressTime = ::atoi(value) == 1;
|
||||
else if (::strcmp(key, "Debug") == 0)
|
||||
m_dapnetDebug = ::atoi(value) == 1;
|
||||
}
|
||||
|
|
@ -193,7 +196,13 @@ std::string CConf::getDAPNETAuthKey() const
|
|||
return m_dapnetAuthKey;
|
||||
}
|
||||
|
||||
bool CConf::getDAPNETSuppressTime() const
|
||||
{
|
||||
return m_dapnetSuppressTime;
|
||||
}
|
||||
|
||||
bool CConf::getDAPNETDebug() const
|
||||
{
|
||||
return m_dapnetDebug;
|
||||
}
|
||||
|
||||
|
|
|
|||
2
Conf.h
2
Conf.h
|
|
@ -47,6 +47,7 @@ public:
|
|||
std::string getDAPNETAddress() const;
|
||||
unsigned int getDAPNETPort() const;
|
||||
std::string getDAPNETAuthKey() const;
|
||||
bool getDAPNETSuppressTime() const;
|
||||
bool getDAPNETDebug() const;
|
||||
|
||||
private:
|
||||
|
|
@ -66,6 +67,7 @@ private:
|
|||
std::string m_dapnetAddress;
|
||||
unsigned int m_dapnetPort;
|
||||
std::string m_dapnetAuthKey;
|
||||
bool m_dapnetSuppressTime;
|
||||
bool m_dapnetDebug;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -49,8 +49,6 @@ const char* DEFAULT_INI_FILE = "/etc/DAPNETGateway.ini";
|
|||
const unsigned char FUNCTIONAL_NUMERIC = 0U;
|
||||
const unsigned char FUNCTIONAL_ALPHANUMERIC = 3U;
|
||||
|
||||
const unsigned int FRAME_TIME = 1000U * (17U * 32U) / 1200U;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
const char* iniFile = DEFAULT_INI_FILE;
|
||||
|
|
@ -218,15 +216,11 @@ int CDAPNETGateway::run()
|
|||
|
||||
::LogMessage("Logged into the DAPNET network");
|
||||
|
||||
CTimer messageTimer(1000U, 0U, FRAME_TIME);
|
||||
CTimer messageTimer(1000U, 0U, 200U);
|
||||
|
||||
CStopWatch stopWatch;
|
||||
stopWatch.start();
|
||||
|
||||
unsigned int calls = 0U;
|
||||
|
||||
bool tx = false;
|
||||
|
||||
LogMessage("Starting DAPNETGateway-%s", VERSION);
|
||||
|
||||
for (;;) {
|
||||
|
|
@ -255,8 +249,16 @@ int CDAPNETGateway::run()
|
|||
|
||||
CPOCSAGMessage* message = m_dapnetNetwork->readMessage();
|
||||
if (message != NULL) {
|
||||
LogDebug("Queueing message to %07u, type %u, func %s: \"%.*s\"", message->m_ric, message->m_type, message->m_functional == FUNCTIONAL_NUMERIC ? "Numeric" : "Alphanumeric", message->m_length, message->m_message);
|
||||
m_queue.push_front(message);
|
||||
if (!messageTimer.isRunning() || !m_queue.empty()) {
|
||||
if (!isTimeMessage(message)) {
|
||||
LogDebug("Queueing message to %07u, type %u, func %s: \"%.*s\"", message->m_ric, message->m_type, message->m_functional == FUNCTIONAL_NUMERIC ? "Numeric" : "Alphanumeric", message->m_length, message->m_message);
|
||||
m_queue.push_front(message);
|
||||
} else {
|
||||
LogDebug("Rejecting message to %07u, type %u, func %s: \"%.*s\"", message->m_ric, message->m_type, message->m_functional == FUNCTIONAL_NUMERIC ? "Numeric" : "Alphanumeric", message->m_length, message->m_message);
|
||||
}
|
||||
} else {
|
||||
LogMessage("Sending message to %07u, type %u, func %s: \"%.*s\"", message->m_ric, message->m_type, message->m_functional == FUNCTIONAL_NUMERIC ? "Numeric" : "Alphanumeric", message->m_length, message->m_message);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int ms = stopWatch.elapsed();
|
||||
|
|
@ -264,22 +266,9 @@ int CDAPNETGateway::run()
|
|||
|
||||
messageTimer.clock(ms);
|
||||
if (messageTimer.isRunning() && messageTimer.hasExpired()) {
|
||||
if (!m_queue.empty()) {
|
||||
if (!tx)
|
||||
calls = 0U;
|
||||
|
||||
tx = true;
|
||||
|
||||
if (!m_queue.empty())
|
||||
sendData();
|
||||
|
||||
calls++;
|
||||
} else {
|
||||
if (tx)
|
||||
LogMessage("Sent %u messages within that batch", calls);
|
||||
|
||||
tx = false;
|
||||
}
|
||||
|
||||
messageTimer.start();
|
||||
}
|
||||
|
||||
|
|
@ -305,7 +294,7 @@ bool CDAPNETGateway::sendData()
|
|||
if (!m_queue.empty()) {
|
||||
CPOCSAGMessage* message = m_queue.back();
|
||||
m_queue.pop_back();
|
||||
LogDebug("Sending message to %07u, type %u, func %s: \"%.*s\"", message->m_ric, message->m_type, message->m_functional == FUNCTIONAL_NUMERIC ? "Numeric" : "Alphanumeric", message->m_length, message->m_message);
|
||||
LogMessage("Sending message to %07u, type %u, func %s: \"%.*s\"", message->m_ric, message->m_type, message->m_functional == FUNCTIONAL_NUMERIC ? "Numeric" : "Alphanumeric", message->m_length, message->m_message);
|
||||
m_pocsagNetwork->write(message);
|
||||
delete message;
|
||||
return true;
|
||||
|
|
@ -328,3 +317,15 @@ bool CDAPNETGateway::recover()
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CDAPNETGateway::isTimeMessage(const CPOCSAGMessage* message) const
|
||||
{
|
||||
if (message->m_type == 5U && message->m_functional == FUNCTIONAL_NUMERIC)
|
||||
return true;
|
||||
|
||||
if (message->m_type == 6U && message->m_functional == FUNCTIONAL_ALPHANUMERIC && ::memcmp(message->m_message, "XTIME=", 6U) == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ private:
|
|||
|
||||
bool sendData();
|
||||
bool recover();
|
||||
bool isTimeMessage(const CPOCSAGMessage* message) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -17,4 +17,5 @@ FileRoot=DAPNETGateway
|
|||
Address=dapnet.afu.rwth-aachen.de
|
||||
Port=43434
|
||||
AuthKey=TOPSECRET
|
||||
SuppressTimeWhenBusy=1
|
||||
Debug=0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue