Send signal strenght updates through TCP

Switch to sending signal strength updates through TCP instead of UDP so
that we don't risk loosing a sql close.
This commit is contained in:
Tobias Blomberg 2019-10-13 23:55:16 +02:00
parent 22335ac081
commit 28f577c470
5 changed files with 151 additions and 80 deletions

View File

@ -315,6 +315,9 @@ void ReflectorClient::onFrameReceived(FramedTcpConnection *con,
case MsgNodeInfo::TYPE:
handleNodeInfo(ss);
break;
case MsgSignalStrengthValues::TYPE:
handleMsgSignalStrengthValues(ss);
break;
#if 0
case MsgNodeInfo::TYPE:
handleNodeInfo(ss);
@ -523,6 +526,35 @@ void ReflectorClient::handleNodeInfo(std::istream& is)
} /* ReflectorClient::handleNodeInfo */
void ReflectorClient::handleMsgSignalStrengthValues(std::istream& is)
{
MsgSignalStrengthValues msg;
if (!msg.unpack(is))
{
cerr << "*** WARNING[" << callsign()
<< "]: Could not unpack incoming "
"MsgSignalStrengthValues message" << endl;
return;
}
typedef MsgSignalStrengthValues::Rxs::const_iterator RxsIter;
for (RxsIter it = msg.rxs().begin(); it != msg.rxs().end(); ++it)
{
const MsgSignalStrengthValues::Rx& rx = *it;
//std::cout << "### MsgSignalStrengthValues:"
// << " id=" << rx.id()
// << " siglev=" << rx.siglev()
// << " enabled=" << rx.enabled()
// << " sql_open=" << rx.sqlOpen()
// << " active=" << rx.active()
// << std::endl;
setRxSiglev(rx.id(), rx.siglev());
setRxEnabled(rx.id(), rx.enabled());
setRxSqlOpen(rx.id(), rx.sqlOpen());
setRxActive(rx.id(), rx.active());
}
} /* ReflectorClient::handleMsgSignalStrengthValues */
void ReflectorClient::handleRequestQsy(std::istream& is)
{
MsgRequestQsy msg;

View File

@ -440,6 +440,7 @@ class ReflectorClient
void handleSelectTG(std::istream& is);
void handleTgMonitor(std::istream& is);
void handleNodeInfo(std::istream& is);
void handleMsgSignalStrengthValues(std::istream& is);
void handleRequestQsy(std::istream& is);
void handleStateEvent(std::istream& is);
void handleMsgError(std::istream& is);

View File

@ -6,7 +6,7 @@
\verbatim
SvxReflector - An audio reflector for connecting SvxLink Servers
Copyright (C) 2003-2017 Tobias Blomberg / SM0SVX
Copyright (C) 2003-2019 Tobias Blomberg / SM0SVX
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -948,6 +948,80 @@ class MsgNodeInfo : public ReflectorMsgBase<111>
}; /* MsgNodeInfo */
/**
@brief Signal strength values base
@author Tobias Blomberg / SM0SVX
@date 2019-10-13
This is the base class used by the client for sending signal strength values to
the reflector. This class defines the actual message contents. It should not be
used directly but instead either the TCP- or UDP-version should be used.
*/
class MsgSignalStrengthValuesBase
{
public:
class Rx : public Async::Msg
{
public:
Rx(void) : m_id('?'), m_siglev(-1), m_flags(0) {}
Rx(char id, int16_t siglev) : m_id(id), m_siglev(siglev) {}
void setEnabled(bool is_enabled) { setBit(BIT_ENABLED, is_enabled); }
bool enabled(void) const { return getBit(BIT_ENABLED); }
void setSqlOpen(bool is_open) { setBit(BIT_SQL_OPEN, is_open); }
bool sqlOpen(void) const { return getBit(BIT_SQL_OPEN); }
void setActive(bool is_active) { setBit(BIT_ACTIVE, is_active); }
bool active(void) const { return getBit(BIT_ACTIVE); }
char id(void) const { return m_id; }
int16_t siglev(void) const { return m_siglev; }
ASYNC_MSG_MEMBERS(m_id, m_siglev, m_flags)
private:
typedef enum {BIT_ENABLED=0, BIT_SQL_OPEN, BIT_ACTIVE} Bit;
char m_id;
uint8_t m_siglev;
uint8_t m_flags;
bool getBit(Bit bitno) const
{
uint8_t bit = 1 << static_cast<size_t>(bitno);
return (m_flags & bit) != 0;
}
void setBit(Bit bitno, bool is_enabled)
{
uint8_t bit = 1 << static_cast<size_t>(bitno);
m_flags = (m_flags & ~bit) | (is_enabled ? bit : 0);
}
};
typedef std::vector<Rx> Rxs;
MsgSignalStrengthValuesBase(void) {}
MsgSignalStrengthValuesBase(const Rxs& rxs) : m_rxs(rxs) {}
Rxs& rxs(void) { return m_rxs; }
void pushBack(const Rx& rx) { m_rxs.push_back(rx); }
protected:
Rxs m_rxs;
}; /* MsgSignalStrengthValuesBase */
/**
@brief Signal strength values
@author Tobias Blomberg / SM0SVX
@date 2019-10-13
This message is used by a client to send signal strength values to the
reflector.
*/
struct MsgSignalStrengthValues
: public MsgSignalStrengthValuesBase, public ReflectorMsgBase<112>
{
ASYNC_MSG_MEMBERS(m_rxs)
}; /* MsgSignalStrengthValues */
/***************************** UDP Messages *****************************/
/**
@ -1034,57 +1108,14 @@ class MsgUdpAllSamplesFlushed : public ReflectorUdpMsgBase<103>
This message is used by a client to send signal strength values to the
reflector.
*/
class MsgUdpSignalStrengthValues : public ReflectorUdpMsgBase<104>
struct MsgUdpSignalStrengthValues
: public MsgSignalStrengthValuesBase, public ReflectorUdpMsgBase<104>
{
public:
class Rx : public Async::Msg
{
public:
Rx(void) : m_id('?'), m_siglev(-1), m_flags(0) {}
Rx(char id, int16_t siglev) : m_id(id), m_siglev(siglev) {}
void setEnabled(bool is_enabled) { setBit(BIT_ENABLED, is_enabled); }
bool enabled(void) const { return getBit(BIT_ENABLED); }
void setSqlOpen(bool is_open) { setBit(BIT_SQL_OPEN, is_open); }
bool sqlOpen(void) const { return getBit(BIT_SQL_OPEN); }
void setActive(bool is_active) { setBit(BIT_ACTIVE, is_active); }
bool active(void) const { return getBit(BIT_ACTIVE); }
char id(void) const { return m_id; }
int16_t siglev(void) const { return m_siglev; }
ASYNC_MSG_MEMBERS(m_id, m_siglev, m_flags)
private:
typedef enum {BIT_ENABLED=0, BIT_SQL_OPEN, BIT_ACTIVE} Bit;
char m_id;
uint8_t m_siglev;
uint8_t m_flags;
bool getBit(Bit bitno) const
{
uint8_t bit = 1 << static_cast<size_t>(bitno);
return (m_flags & bit) != 0;
}
void setBit(Bit bitno, bool is_enabled)
{
uint8_t bit = 1 << static_cast<size_t>(bitno);
m_flags = (m_flags & ~bit) | (is_enabled ? bit : 0);
}
};
typedef std::vector<Rx> Rxs;
MsgUdpSignalStrengthValues(void) {}
MsgUdpSignalStrengthValues(const Rxs& rxs) : m_rxs(rxs) {}
Rxs& rxs(void) { return m_rxs; }
void pushBack(const Rx& rx) { m_rxs.push_back(rx); }
ASYNC_MSG_MEMBERS(m_rxs)
private:
Rxs m_rxs;
ASYNC_MSG_MEMBERS(m_rxs)
}; /* MsgUdpSignalStrengthValues */
#if 0
/**
@brief Audio UDP network message V2
@author Tobias Blomberg / SM0SVX
@ -1092,30 +1123,31 @@ class MsgUdpSignalStrengthValues : public ReflectorUdpMsgBase<104>
This is the message used to transmit audio to the other side.
*/
//class MsgUdpAudio : public ReflectorUdpMsgBase<101>
//{
// public:
// MsgUdpAudio(void) : m_tg(0) {}
// MsgUdpAudio(const MsgUdpAudioV1& msg_v1)
// : m_tg(0), m_audio_data(msg_v1.audioData()) {}
// MsgUdpAudio(uint32_t tg, const void *buf, int count)
// : m_tg(tg)
// {
// if (count > 0)
// {
// const uint8_t *bbuf = reinterpret_cast<const uint8_t*>(buf);
// m_audio_data.assign(bbuf, bbuf+count);
// }
// }
// uint32_t tg(void) { return m_tg; }
// std::vector<uint8_t>& audioData(void) { return m_audio_data; }
//
// ASYNC_MSG_MEMBERS(m_tg, m_audio_data)
//
// private:
// uint32_t m_tg;
// std::vector<uint8_t> m_audio_data;
//}; /* MsgUdpAudio */
class MsgUdpAudio : public ReflectorUdpMsgBase<101>
{
public:
MsgUdpAudio(void) : m_tg(0) {}
MsgUdpAudio(const MsgUdpAudioV1& msg_v1)
: m_tg(0), m_audio_data(msg_v1.audioData()) {}
MsgUdpAudio(uint32_t tg, const void *buf, int count)
: m_tg(tg)
{
if (count > 0)
{
const uint8_t *bbuf = reinterpret_cast<const uint8_t*>(buf);
m_audio_data.assign(bbuf, bbuf+count);
}
}
uint32_t tg(void) { return m_tg; }
std::vector<uint8_t>& audioData(void) { return m_audio_data; }
ASYNC_MSG_MEMBERS(m_tg, m_audio_data)
private:
uint32_t m_tg;
std::vector<uint8_t> m_audio_data;
}; /* MsgUdpAudio */
#endif
#endif /* REFLECTOR_MSG_INCLUDED */

View File

@ -456,7 +456,8 @@ void ReflectorLogic::remoteReceivedPublishStateEvent(
if (event_name == "Voter:sql_state")
{
MsgUdpSignalStrengthValues msg;
//MsgUdpSignalStrengthValues msg;
MsgSignalStrengthValues msg;
std::istringstream is(data);
Json::Value rx_arr;
is >> rx_arr;
@ -475,17 +476,20 @@ void ReflectorLogic::remoteReceivedPublishStateEvent(
bool is_enabled = rx_data.get("enabled", false).asBool();
bool sql_open = rx_data.get("sql_open", false).asBool();
bool is_active = rx_data.get("active", false).asBool();
MsgUdpSignalStrengthValues::Rx rx(id, siglev);
//MsgUdpSignalStrengthValues::Rx rx(id, siglev);
MsgSignalStrengthValues::Rx rx(id, siglev);
rx.setEnabled(is_enabled);
rx.setSqlOpen(sql_open);
rx.setActive(is_active);
msg.pushBack(rx);
}
sendUdpMsg(msg);
//sendUdpMsg(msg);
sendMsg(msg);
}
else if (event_name == "LocalRx:sql_state")
{
MsgUdpSignalStrengthValues msg;
//MsgUdpSignalStrengthValues msg;
MsgSignalStrengthValues msg;
std::istringstream is(data);
Json::Value rx_data;
is >> rx_data;
@ -499,12 +503,14 @@ void ReflectorLogic::remoteReceivedPublishStateEvent(
int siglev = rx_data.get("siglev", 0).asInt();
siglev = std::min(std::max(siglev, 0), 100);
bool sql_open = rx_data.get("sql_open", false).asBool();
MsgUdpSignalStrengthValues::Rx rx(id, siglev);
//MsgUdpSignalStrengthValues::Rx rx(id, siglev);
MsgSignalStrengthValues::Rx rx(id, siglev);
rx.setEnabled(true);
rx.setSqlOpen(sql_open);
rx.setActive(true);
msg.pushBack(rx);
sendUdpMsg(msg);
//sendUdpMsg(msg);
sendMsg(msg);
}
} /* ReflectorLogic::remoteReceivedPublishStateEvent */

View File

@ -11,7 +11,7 @@ LIBECHOLIB=1.3.3
LIBASYNC=1.6.0.99.3-reflector_tg
# SvxLink versions
SVXLINK=1.7.99.8-reflector_tg
SVXLINK=1.7.99.9-reflector_tg
MODULE_HELP=1.0.0
MODULE_PARROT=1.1.1
MODULE_ECHO_LINK=1.5.0
@ -37,4 +37,4 @@ DEVCAL=1.0.2.99.0-reflector_tg
SVXSERVER=0.0.6
# Version for SvxReflector
SVXREFLECTOR=1.0.99.2-reflector_tg
SVXREFLECTOR=1.0.99.3-reflector_tg