Add USRP Client file

pull/8/head
Doug McLain 3 years ago
parent 58a4e37ca0
commit 44f6108e0c

@ -15,6 +15,13 @@ Software vocoding of AMBE+2(DMR/YSF/NXDN) is done using md380_vocoder library.
Numerous fixes like late entry recognition from modes like YSF that are otherwise ignored by the original reflector when no header has been received. Numerous fixes like late entry recognition from modes like YSF that are otherwise ignored by the original reflector when no header has been received.
The USRP Clients are read from a file defined in Main.h. The format of this file is ipaddr;port; one host per line, ex:
```bash
192.168.1.100;32000;
192.168.1.101;32001;
```
The rest of this README is unchanged from the original. The rest of this README is unchanged from the original.
## Introduction ## Introduction

@ -168,14 +168,13 @@ enum class EProtocol { any, none, dextra, dplus, dcs, bm, urf, dmrplus, dmrmmdvm
#define NXDN_AUTOLINK_MODULE 'A' // module for client to auto-link to #define NXDN_AUTOLINK_MODULE 'A' // module for client to auto-link to
// USRP // USRP
#define USRP_NODE_ADDRESS "192.168.1.5" #define USRP_PORT 34001 // UDP port
#define USRP_RXPORT 34001 // UDP port
#define USRP_TXPORT 32001 // UDP port
#define USRP_KEEPALIVE_PERIOD 1 // in seconds #define USRP_KEEPALIVE_PERIOD 1 // in seconds
#define USRP_KEEPALIVE_TIMEOUT (USRP_KEEPALIVE_PERIOD*10) // in seconds #define USRP_KEEPALIVE_TIMEOUT (USRP_KEEPALIVE_PERIOD*10) // in seconds
#define USRP_AUTOLINK_ENABLE 1 // 1 = enable, 0 = disable auto-link #define USRP_AUTOLINK_ENABLE 1 // 1 = enable, 0 = disable auto-link
#define USRP_AUTOLINK_MODULE 'A' // module for client to auto-link to #define USRP_AUTOLINK_MODULE 'A' // module for client to auto-link to
#define USRP_DEFAULT_CALLSIGN "ALLSTAR" #define USRP_DEFAULT_CALLSIGN "ALLSTAR"
#define USRPCLIENTS_PATH "/home/pi/USRPClients.txt" // format ip;port; per line for each ALLSTAR/USRP node
#ifndef NO_G3 #ifndef NO_G3
// G3 Terminal // G3 Terminal

@ -90,7 +90,7 @@ bool CProtocols::Init(void)
return false; return false;
m_Protocols.emplace_back(std::unique_ptr<CUSRPProtocol>(new CUSRPProtocol)); m_Protocols.emplace_back(std::unique_ptr<CUSRPProtocol>(new CUSRPProtocol));
if (! m_Protocols.back()->Initialize("USRP", EProtocol::usrp, USRP_RXPORT, USRP_IPV4, USRP_IPV6)) if (! m_Protocols.back()->Initialize("USRP", EProtocol::usrp, USRP_PORT, USRP_IPV4, USRP_IPV6))
return false; return false;
m_Protocols.emplace_back(std::unique_ptr<CURFProtocol>(new CURFProtocol)); m_Protocols.emplace_back(std::unique_ptr<CURFProtocol>(new CURFProtocol));

@ -38,19 +38,61 @@ const uint8_t TLV_TAG_SET_INFO = 8;
bool CUSRPProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) bool CUSRPProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6)
{ {
CBuffer buffer;
m_uiStreamId = 0; m_uiStreamId = 0;
CCallsign cs(USRP_DEFAULT_CALLSIGN);
CClients *clients = g_Reflector.GetClients();
std::ifstream file;
std::streampos size;
// base class // base class
if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6)) if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6))
return false; return false;
file.open(USRPCLIENTS_PATH, std::ios::in | std::ios::binary | std::ios::ate);
if ( file.is_open() )
{
// read file
size = file.tellg();
if ( size > 0 )
{
// read file into buffer
buffer.resize((int)size+1);
file.seekg (0, std::ios::beg);
file.read((char *)buffer.data(), (int)size);
CIp Ip(AF_INET, USRP_TXPORT, USRP_NODE_ADDRESS); // close file
CCallsign cs(USRP_DEFAULT_CALLSIGN); file.close();
CClients *clients = g_Reflector.GetClients(); }
auto newclient = std::make_shared<CUSRPClient>(cs, Ip); }
if ( buffer.size() > 0 )
{
char *ptr1 = (char *)buffer.data();
char *ptr2;
while ( (ptr2 = ::strchr(ptr1, '\n')) != nullptr )
{
*ptr2 = 0;
char *ip;
char *port;
if ((ip = ::strtok(ptr1, ";")) != nullptr)
{
if ( ((port = ::strtok(nullptr, ";")) != nullptr) )
{
uint32_t ui = atoi(port);
CIp Ip(AF_INET, ui, ip);
auto newclient = std::make_shared<CUSRPClient>(cs, Ip);
#if USRP_AUTOLINK_ENABLE #if USRP_AUTOLINK_ENABLE
newclient->SetReflectorModule(USRP_AUTOLINK_MODULE); newclient->SetReflectorModule(USRP_AUTOLINK_MODULE);
#endif #endif
clients->AddClient(newclient); clients->AddClient(newclient);
}
}
ptr1 = ptr2+1;
}
}
g_Reflector.ReleaseClients(); g_Reflector.ReleaseClients();
// update time // update time
m_LastKeepaliveTime.start(); m_LastKeepaliveTime.start();

Loading…
Cancel
Save

Powered by TurnKey Linux.