diff --git a/README.md b/README.md index 009b172..d7d1f1b 100644 --- a/README.md +++ b/README.md @@ -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. +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. ## Introduction diff --git a/reflector/Main.h b/reflector/Main.h index e72c4d3..86e9734 100644 --- a/reflector/Main.h +++ b/reflector/Main.h @@ -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 // USRP -#define USRP_NODE_ADDRESS "192.168.1.5" -#define USRP_RXPORT 34001 // UDP port -#define USRP_TXPORT 32001 // UDP port +#define USRP_PORT 34001 // UDP port #define USRP_KEEPALIVE_PERIOD 1 // 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_MODULE 'A' // module for client to auto-link to #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 // G3 Terminal diff --git a/reflector/Protocols.cpp b/reflector/Protocols.cpp index fe07198..c2f10c1 100644 --- a/reflector/Protocols.cpp +++ b/reflector/Protocols.cpp @@ -90,7 +90,7 @@ bool CProtocols::Init(void) return false; m_Protocols.emplace_back(std::unique_ptr(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; m_Protocols.emplace_back(std::unique_ptr(new CURFProtocol)); diff --git a/reflector/USRPProtocol.cpp b/reflector/USRPProtocol.cpp index dde6bb2..75ebdbf 100644 --- a/reflector/USRPProtocol.cpp +++ b/reflector/USRPProtocol.cpp @@ -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) { + CBuffer buffer; m_uiStreamId = 0; + CCallsign cs(USRP_DEFAULT_CALLSIGN); + CClients *clients = g_Reflector.GetClients(); + std::ifstream file; + std::streampos size; + // base class if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6)) 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); - CCallsign cs(USRP_DEFAULT_CALLSIGN); - CClients *clients = g_Reflector.GetClients(); - auto newclient = std::make_shared(cs, Ip); + // close file + file.close(); + } + } + + 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(cs, Ip); #if USRP_AUTOLINK_ENABLE - newclient->SetReflectorModule(USRP_AUTOLINK_MODULE); + newclient->SetReflectorModule(USRP_AUTOLINK_MODULE); #endif - clients->AddClient(newclient); + clients->AddClient(newclient); + } + } + ptr1 = ptr2+1; + } + } + g_Reflector.ReleaseClients(); // update time m_LastKeepaliveTime.start();