From 5010b5fef899b114401ea6c96cfd97b30c0e1a90 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 12 Oct 2017 15:02:27 +0200 Subject: [PATCH 01/40] Add filter function to repeaters page --- dashboard/pgs/repeaters.php | 229 ++++++++++++++++++++++++++++-------- 1 file changed, 180 insertions(+), 49 deletions(-) diff --git a/dashboard/pgs/repeaters.php b/dashboard/pgs/repeaters.php index 124d59d..bdf8d6f 100755 --- a/dashboard/pgs/repeaters.php +++ b/dashboard/pgs/repeaters.php @@ -1,4 +1,110 @@ - + + +
+ +'; +} + + +?> @@ -22,61 +128,86 @@ $odd = ""; $Reflector->LoadFlags(); for ($i=0;$i<$Reflector->NodeCount();$i++) { - - if ($odd == "#FFFFFF") { $odd = "#F1FAFA"; } else { $odd = "#FFFFFF"; } - - echo ' - - - - - - - - - '; - if ($PageOptions['RepeatersPage']['IPModus'] != 'HideIP') { + + if ($ShowThisStation) { + if ($odd == "#FFFFFF") { $odd = "#F1FAFA"; } else { $odd = "#FFFFFF"; } + echo ' - + + + + '; + else { + switch ($Reflector->Nodes[$i]->GetSuffix()) { + case 'A' : echo '23cm'; break; + case 'B' : echo '70cm'; break; + case 'C' : echo '2m'; break; + case 'D' : echo 'Dongle'; break; + case 'G' : echo 'Internet-Gateway'; break; + default : echo ''; + } + } + echo ' + + + + '; + if ($PageOptions['RepeatersPage']['IPModus'] != 'HideIP') { + echo ' + '; + } + echo ' + '; } - echo ' - '; if ($i == $PageOptions['RepeatersPage']['LimitTo']) { $i = $Reflector->NodeCount()+1; } } From 2a3cd63d53a856fba0fd69e812e146335dd96cf3 Mon Sep 17 00:00:00 2001 From: narspt Date: Fri, 20 Jul 2018 22:23:29 +0100 Subject: [PATCH 02/40] make sure buttons text never word-wrap to avoid them getting fully disarranged in some specific cases... --- dashboard/css/layout.css | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dashboard/css/layout.css b/dashboard/css/layout.css index 3a80aff..26af1ba 100755 --- a/dashboard/css/layout.css +++ b/dashboard/css/layout.css @@ -79,6 +79,7 @@ a.tip:hover span { .menulink { font-size : 14pt; text-decoration : none; + white-space : nowrap; border : 1px #000000 solid; padding-left : 10px; padding-top : 3px; @@ -92,6 +93,7 @@ a.tip:hover span { .menulinkactive { font-size : 14pt; text-decoration : none; + white-space : nowrap; border : 1px #000000 solid; padding-left : 10px; padding-top : 3px; From 767fed2a87fdf958fbccfaa4fde374f074764c34 Mon Sep 17 00:00:00 2001 From: Eddie Date: Sun, 22 Jul 2018 05:18:44 +0800 Subject: [PATCH 03/40] logout session logout session --- dashboard2/log/logout.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 dashboard2/log/logout.php diff --git a/dashboard2/log/logout.php b/dashboard2/log/logout.php new file mode 100644 index 0000000..a369a6c --- /dev/null +++ b/dashboard2/log/logout.php @@ -0,0 +1,28 @@ + + + + + + + +
+ + + + From c6a5ee4c45e1ec1661b722798c71fc052433a4f8 Mon Sep 17 00:00:00 2001 From: Luca Marchesano Date: Tue, 11 Jun 2019 14:05:40 +0200 Subject: [PATCH 04/40] Fixed CPU load if not run as daemon --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 154a53b..59dc3f9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -122,7 +122,8 @@ int main(int argc, const char * argv[]) // wait any key for (;;) { - std::cin.get(); + // sleep 60 seconds + CTimePoint::TaskSleepFor(60000); #ifdef DEBUG_DUMPFILE g_Reflector.m_DebugFile.close(); g_Reflector.m_DebugFile.open("/Users/jeanluc/Desktop/dmrdebug.txt"); From 66bd9aca8a6db46a3b901bf3109c32bf4cdf25b2 Mon Sep 17 00:00:00 2001 From: "Marius Petrescu, YO2LOJ" Date: Thu, 5 Dec 2019 21:49:08 +0200 Subject: [PATCH 05/40] Added G3 Terminal Support Added G3 Terminal Support for ICom-9700 and Icom Plus2 series --- README.md | 4 +- config/xlxd.terminal | 17 + src/cg3client.cpp | 54 +++ src/cg3client.h | 62 +++ src/cg3protocol.cpp | 886 +++++++++++++++++++++++++++++++++++++++++++ src/cg3protocol.h | 135 +++++++ src/cgatekeeper.cpp | 4 +- src/cprotocols.cpp | 9 +- src/cudpsocket.cpp | 46 ++- src/cudpsocket.h | 2 + src/main.h | 13 +- 11 files changed, 1220 insertions(+), 12 deletions(-) create mode 100644 config/xlxd.terminal create mode 100644 src/cg3client.cpp create mode 100644 src/cg3client.h create mode 100644 src/cg3protocol.cpp create mode 100644 src/cg3protocol.h diff --git a/README.md b/README.md index 0ea7920..b61a1dd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Copyright +# Copyright © 2016 Jean-Luc Deltombe LX3JL and Luc Engelmann LX1IQ @@ -127,6 +127,8 @@ XLX Server requires the following ports to be open and forwarded properly for in - UDP port 62030 (MMDVM protocol) - UDP port 10100 (AMBE controller port) - UDP port 10101 - 10199 (AMBE transcoding port) + - UDP port 12345 - 12346 (Icom Terminal presence and request port) + - UDP port 40000 (Icom Terminal dv port) # YSF Master Server diff --git a/config/xlxd.terminal b/config/xlxd.terminal new file mode 100644 index 0000000..e8b0cf5 --- /dev/null +++ b/config/xlxd.terminal @@ -0,0 +1,17 @@ +######################################################################################### +# XLXD terminal option file +# +# one line per entry +# each entry specifies a terminal option +# +# Valid option: +# address - Ip address to be used by the terminal route responder +# By default, the request destination address is used. +# If the system is behind a router, set it to the public IP +# If the system runs on the public IP, leave unset. +# modules - a string with all modules to accept a terminal connection +# Default value is "*", meaning accept all +# +######################################################################################### +#address 193.1.2.3 +#modules BCD diff --git a/src/cg3client.cpp b/src/cg3client.cpp new file mode 100644 index 0000000..02ec339 --- /dev/null +++ b/src/cg3client.cpp @@ -0,0 +1,54 @@ +// +// cg3client.cpp +// xlxd +// +// Created by Marius Petrescu (YO2LOJ) on 03/06/2019. +// Copyright © 2019 Marius Petrescu (YO2LOJ). All rights reserved. +// +// ---------------------------------------------------------------------------- +// This file is part of xlxd. +// +// xlxd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// xlxd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Foobar. If not, see . +// ---------------------------------------------------------------------------- + +#include "main.h" +#include "cg3client.h" + + +//////////////////////////////////////////////////////////////////////////////////////// +// constructors + +CG3Client::CG3Client() +{ +} + +CG3Client::CG3Client(const CCallsign &callsign, const CIp &ip, char reflectorModule) + : CClient(callsign, ip, reflectorModule) +{ + +} + +CG3Client::CG3Client(const CG3Client &client) + : CClient(client) +{ +} + +//////////////////////////////////////////////////////////////////////////////////////// +// status + +bool CG3Client::IsAlive(void) const +{ + return (m_LastKeepaliveTime.DurationSinceNow() < G3_KEEPALIVE_TIMEOUT); +} + diff --git a/src/cg3client.h b/src/cg3client.h new file mode 100644 index 0000000..5e6b486 --- /dev/null +++ b/src/cg3client.h @@ -0,0 +1,62 @@ +// +// cg3client.h +// xlxd +// +// Created by Marius Petrescu (YO2LOJ) on 03/06/2019. +// Copyright © 2019 Marius Petrescu (YO2LOJ). All rights reserved. +// +// ---------------------------------------------------------------------------- +// This file is part of xlxd. +// +// xlxd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// xlxd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Foobar. If not, see . +// ---------------------------------------------------------------------------- + +#ifndef cg3client_h +#define cg3client_h + +#include "cclient.h" + +//////////////////////////////////////////////////////////////////////////////////////// +// define + + +//////////////////////////////////////////////////////////////////////////////////////// +// class + +class CG3Client : public CClient +{ +public: + // constructors + CG3Client(); + CG3Client(const CCallsign &, const CIp &, char = ' '); + CG3Client(const CG3Client &); + + // destructor + virtual ~CG3Client() {}; + + // identity + int GetProtocol(void) const { return PROTOCOL_G3; } + const char *GetProtocolName(void) const { return "Terminal/AP"; } + int GetCodec(void) const { return CODEC_AMBEPLUS; } + bool IsNode(void) const { return true; } + + // status + bool IsAlive(void) const; + +protected: + // data +}; + +//////////////////////////////////////////////////////////////////////////////////////// +#endif /* cg3client_h */ diff --git a/src/cg3protocol.cpp b/src/cg3protocol.cpp new file mode 100644 index 0000000..ed4de34 --- /dev/null +++ b/src/cg3protocol.cpp @@ -0,0 +1,886 @@ +// +// cg3protocol.cpp +// xlxd +// +// Created by Marius Petrescu (YO2LOJ) on 03/06/2019. +// Copyright © 2019 Marius Petrescu (YO2LOJ). All rights reserved. +// +// ---------------------------------------------------------------------------- +// This file is part of xlxd. +// +// xlxd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// xlxd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Foobar. If not, see . +// ---------------------------------------------------------------------------- + +#include "main.h" +#include +#include +#include "cg3client.h" +#include "cg3protocol.h" +#include "creflector.h" +#include "cgatekeeper.h" + +#include +#include + + +//////////////////////////////////////////////////////////////////////////////////////// +// operation + +bool CG3Protocol::Init(void) +{ + bool ok; + + ReadOptions(); + + // base class + ok = CProtocol::Init(); + + // update reflector callsign + m_ReflectorCallsign.PatchCallsign(0, (const uint8 *)"XLX", 3); + + // create our DV socket + ok &= m_Socket.Open(G3_DV_PORT); + if ( !ok ) + { + std::cout << "Error opening socket on port UDP" << G3_DV_PORT << " on ip " << g_Reflector.GetListenIp() << std::endl; + } + + //create helper sockets + ok &= m_PresenceSocket.Open(G3_PRESENCE_PORT); + if ( !ok ) + { + std::cout << "Error opening socket on port UDP" << G3_PRESENCE_PORT << " on ip " << g_Reflector.GetListenIp() << std::endl; + } + + ok &= m_ConfigSocket.Open(G3_CONFIG_PORT); + if ( !ok ) + { + std::cout << "Error opening socket on port UDP" << G3_CONFIG_PORT << " on ip " << g_Reflector.GetListenIp() << std::endl; + } + + ok &= ((m_IcmpRawSocket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) >= 0); + if ( !ok ) + { + std::cout << "Error opening raw socket for ICMP" << std::endl; + } + + if (ok) + { + // start helper threads + m_pPresenceThread = new std::thread(PresenceThread, this); + m_pPresenceThread = new std::thread(ConfigThread, this); + m_pPresenceThread = new std::thread(IcmpThread, this); + } + + // update time + m_LastKeepaliveTime.Now(); + + // done + return ok; +} + +void CG3Protocol::Close(void) +{ + if (m_pPresenceThread != NULL) + { + m_pPresenceThread->join(); + delete m_pPresenceThread; + m_pPresenceThread = NULL; + } + + if (m_pConfigThread != NULL) + { + m_pConfigThread->join(); + delete m_pConfigThread; + m_pConfigThread = NULL; + } + + if (m_pIcmpThread != NULL) + { + m_pIcmpThread->join(); + delete m_pIcmpThread; + m_pIcmpThread = NULL; + } +} + + +//////////////////////////////////////////////////////////////////////////////////////// +// private threads + +void CG3Protocol::PresenceThread(CG3Protocol *This) +{ + while ( !This->m_bStopThread ) + { + This->PresenceTask(); + } +} + +void CG3Protocol::ConfigThread(CG3Protocol *This) +{ + while ( !This->m_bStopThread ) + { + This->ConfigTask(); + } +} + +void CG3Protocol::IcmpThread(CG3Protocol *This) +{ + fcntl(This->m_IcmpRawSocket, F_SETFL, O_NONBLOCK); + + while ( !This->m_bStopThread ) + { + This->IcmpTask(); + } + + close(This->m_IcmpRawSocket); +} + + +//////////////////////////////////////////////////////////////////////////////////////// +// presence task + +void CG3Protocol::PresenceTask(void) +{ + CBuffer Buffer; + CIp ReqIp; + CCallsign Callsign; + CCallsign Owner; + CCallsign Terminal; + + + if ( m_PresenceSocket.Receive(&Buffer, &ReqIp, 20) != -1 ) + { + + CIp Ip(ReqIp); + Ip.GetSockAddr()->sin_port = htons(G3_DV_PORT); + + if (Buffer.size() == 32) + { + Callsign.SetCallsign(&Buffer.data()[8], 8); + Owner.SetCallsign(&Buffer.data()[16], 8); + Terminal.SetCallsign(&Buffer.data()[24], 8); + + std::cout << "Presence from " << Ip << " as " << Callsign << " on terminal " << Terminal << std::endl; + + // accept + Buffer.data()[2] = 0x80; // response + Buffer.data()[3] = 0x00; // ok + + if (m_GwAddress == 0) + { + Buffer.Append(*(uint32 *)m_ConfigSocket.GetLocalAddr()); + } + else + { + Buffer.Append(m_GwAddress); + } + + CClients *clients = g_Reflector.GetClients(); + + int index = -1; + CClient *extant = NULL; + while ( (extant = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) + { + CIp ClIp = extant->GetIp(); + if (ClIp.GetAddr() == Ip.GetAddr()) + { + break; + } + } + + if (extant == NULL) + { + index = -1; + + // do we already have a client with the same call (IP changed)? + while ( (extant = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) + { + { + if (extant->GetCallsign().HasSameCallsign(Terminal)) + { + //delete old client + clients->RemoveClient(extant); + break; + } + } + } + + // create new client + CG3Client *client = new CG3Client(Terminal, Ip); + + // and append + clients->AddClient(client); + } + else + { + // client changed callsign + if (!extant->GetCallsign().HasSameCallsign(Terminal)) + { + //delete old client + clients->RemoveClient(extant); + + // create new client + CG3Client *client = new CG3Client(Terminal, Ip); + + // and append + clients->AddClient(client); + } + } + g_Reflector.ReleaseClients(); + + m_PresenceSocket.Send(Buffer, ReqIp); + } + } +} + + +//////////////////////////////////////////////////////////////////////////////////////// +// configuration task + +void CG3Protocol::ConfigTask(void) +{ + CBuffer Buffer; + CIp Ip; + CCallsign Call; + bool isRepeaterCall; + + if ( m_ConfigSocket.Receive(&Buffer, &Ip, 20) != -1 ) + { + + if (Buffer.size() == 16) + { + if (memcmp(&Buffer.data()[8], " ", 8) == 0) + { + Call.SetCallsign(GetReflectorCallsign(), 8); + } + else + { + Call.SetCallsign(&Buffer.data()[8], 8); + } + + isRepeaterCall = ((Buffer.data()[2] & 0x10) == 0x10); + + std::cout << "Config request from " << Ip << " for " << Call << " (" << ((char *)(isRepeaterCall)?"repeater":"routed") << ")" << std::endl; + + //std::cout << "Local address: " << inet_ntoa(*m_ConfigSocket.GetLocalAddr()) << std::endl; + + Buffer.data()[2] |= 0x80; // response + + if (isRepeaterCall) + { + if ((Call.HasSameCallsign(GetReflectorCallsign())) && (g_Reflector.IsValidModule(Call.GetModule()))) + { + Buffer.data()[3] = 0x00; // ok + } + else + { + std::cout << "Module " << Call << " invalid" << std::endl; + Buffer.data()[3] = 0x01; // reject + } + } + else + { + // reject routed calls for now + Buffer.data()[3] = 0x01; // reject + } + + char module = Call.GetModule(); + + if (!strchr(m_Modules.c_str(), module) && !strchr(m_Modules.c_str(), '*')) + { + // restricted + std::cout << "Module " << Call << " restricted by configuration" << std::endl; + Buffer.data()[3] = 0x01; // reject + } + + // UR + Buffer.resize(8); + Buffer.Append((uint8 *)(const char *)Call, CALLSIGN_LEN - 1); + Buffer.Append((uint8)module); + + // RPT1 + Buffer.Append((uint8 *)(const char *)GetReflectorCallsign(), CALLSIGN_LEN - 1); + Buffer.Append((uint8)'G'); + + // RPT2 + Buffer.Append((uint8 *)(const char *)GetReflectorCallsign(), CALLSIGN_LEN - 1); + + if (isRepeaterCall) + { + Buffer.Append((uint8)Call.GetModule()); + } + else + { + // routed - no module for now + Buffer.Append((uint8)' '); + } + + if (Buffer.data()[3] == 0x00) + { + std::cout << "External G3 gateway address " << inet_ntoa(*(in_addr *)&m_GwAddress) << std::endl; + + if (m_GwAddress == 0) + { + Buffer.Append(*(uint32 *)m_ConfigSocket.GetLocalAddr()); + } + else + { + Buffer.Append(m_GwAddress); + } + } + else + { + Buffer.Append(0u); + } + + m_ConfigSocket.Send(Buffer, Ip); + } + } +} + +//////////////////////////////////////////////////////////////////////////////////////// +// icmp task + +void CG3Protocol::IcmpTask(void) +{ + unsigned char buffer[256]; + + struct sockaddr_in sa; + unsigned int sasize = sizeof(sa); + + fd_set FdSet; + struct timeval tv; + + if (m_IcmpRawSocket != -1) + { + FD_ZERO(&FdSet); + FD_SET(m_IcmpRawSocket, &FdSet); + tv.tv_sec = 0; + tv.tv_usec = 100000; + select(m_IcmpRawSocket + 1, &FdSet, 0, 0, &tv); + + int len = recvfrom(m_IcmpRawSocket, buffer, 255, 0, (struct sockaddr *)&sa, &sasize); + + if (len > 28) + { + struct ip *iph = (struct ip *)buffer; + int iphdrlen = iph->ip_hl * 4; + struct icmp *icmph = (struct icmp *)(buffer + iphdrlen); + + if (icmph->icmp_type == ICMP_DEST_UNREACH) + { + struct ip *remote_iph = (struct ip *)(buffer + iphdrlen + 8); + + CClients *clients = g_Reflector.GetClients(); + + int index = -1; + CClient *client = NULL; + while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) + { + CIp Ip = client->GetIp(); + if (Ip.GetAddr() == remote_iph->ip_dst.s_addr) + { + clients->RemoveClient(client); + } + } + g_Reflector.ReleaseClients(); + + } + } + } +} + + +//////////////////////////////////////////////////////////////////////////////////////// +// DV task + +void CG3Protocol::Task(void) +{ + CBuffer Buffer; + CIp Ip; + CCallsign Callsign; + char ToLinkModule; + int ProtRev; + CDvHeaderPacket *Header; + CDvFramePacket *Frame; + CDvLastFramePacket *LastFrame; + + // any incoming packet ? + if ( m_Socket.Receive(&Buffer, &Ip, 20) != -1 ) + { + CIp ClIp; + CIp *BaseIp = NULL; + CClients *clients = g_Reflector.GetClients(); + int index = -1; + CClient *client = NULL; + while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) + { + ClIp = client->GetIp(); + if (ClIp.GetAddr() == Ip.GetAddr()) + { + BaseIp = &ClIp; + client->Alive(); + // supress host checks + m_LastKeepaliveTime.Now(); + break; + } + } + g_Reflector.ReleaseClients(); + + if (BaseIp != NULL) + { + // crack the packet + if ( (Frame = IsValidDvFramePacket(Buffer)) != NULL ) + { + //std::cout << "Terminal DV frame" << std::endl; + + // handle it + OnDvFramePacketIn(Frame, BaseIp); + } + else if ( (Header = IsValidDvHeaderPacket(Buffer)) != NULL ) + { + //std::cout << "Terminal DV header" << std::endl; + + // callsign muted? + if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, PROTOCOL_G3, Header->GetRpt2Module()) ) + { + // handle it + OnDvHeaderPacketIn(Header, *BaseIp); + } + else + { + delete Header; + } + } + else if ( (LastFrame = IsValidDvLastFramePacket(Buffer)) != NULL ) + { + //std::cout << "Terminal DV last frame" << std::endl; + + // handle it + OnDvLastFramePacketIn(LastFrame, BaseIp); + } + else + { + //std::cout << "Invalid terminal packet (" << Buffer.size() << ")" << std::endl; + //std::cout << Buffer.data() << std::endl; + } + } + else + { + //std::cout << "Invalid client " << Ip << std::endl; + } + } + + // handle end of streaming timeout + CheckStreamsTimeout(); + + // handle queue from reflector + HandleQueue(); + + // keep alive + if ( m_LastKeepaliveTime.DurationSinceNow() > G3_KEEPALIVE_PERIOD ) + { + // handle keep alives + HandleKeepalives(); + + // update time + m_LastKeepaliveTime.Now(); + + // reload option if needed + NeedReload(); + } +} + +//////////////////////////////////////////////////////////////////////////////////////// +// queue helper + +void CG3Protocol::HandleQueue(void) +{ + m_Queue.Lock(); + while ( !m_Queue.empty() ) + { + // supress host checks + m_LastKeepaliveTime.Now(); + + // get the packet + CPacket *packet = m_Queue.front(); + m_Queue.pop(); + + // encode it + CBuffer buffer; + if ( EncodeDvPacket(*packet, &buffer) ) + { + // and push it to all our clients linked to the module and who are not streaming in + CClients *clients = g_Reflector.GetClients(); + int index = -1; + CClient *client = NULL; + while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) + { + // is this client busy ? + if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) + { + // not busy, send the packet + int n = packet->IsDvHeader() ? 5 : 1; + for ( int i = 0; i < n; i++ ) + { + m_Socket.Send(buffer, client->GetIp()); + } + } + } + g_Reflector.ReleaseClients(); + } + + // done + delete packet; + } + m_Queue.Unlock(); +} + +//////////////////////////////////////////////////////////////////////////////////////// +// keepalive helpers + +void CG3Protocol::HandleKeepalives(void) +{ + // G3 Terminal mode does not support keepalive + // We will send some short packed and expect + // A ICMP unreachable on failure + CBuffer keepalive((uint8 *)"PING", 4); + + // iterate on clients + CClients *clients = g_Reflector.GetClients(); + int index = -1; + CClient *client = NULL; + while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) + { + if (!client->IsAlive()) + { + clients->RemoveClient(client); + } + else + { + // send keepalive packet + m_Socket.Send(keepalive, client->GetIp()); + } + } + g_Reflector.ReleaseClients(); +} + +//////////////////////////////////////////////////////////////////////////////////////// +// streams helpers + +bool CG3Protocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip) +{ + bool newstream = false; + + // find the stream + CPacketStream *stream = GetStream(Header->GetStreamId(), &Ip); + + if ( stream == NULL ) + { + // no stream open yet, open a new one + CCallsign via(Header->GetRpt1Callsign()); + + // find this client + CClients *clients = g_Reflector.GetClients(); + + int index = -1; + CClient *client = NULL; + while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) + { + CIp ClIp = client->GetIp(); + if (ClIp.GetAddr() == Ip.GetAddr()) + { + break; + } + } + + if ( client != NULL ) + { + + // move it to the proper module + if (m_ReflectorCallsign.HasSameCallsign(Header->GetRpt2Callsign())) + { + if (client->GetReflectorModule() != Header->GetRpt2Callsign().GetModule()) + { + char new_module = Header->GetRpt2Callsign().GetModule(); + if (strchr(m_Modules.c_str(), '*') || strchr(m_Modules.c_str(), new_module)) + { + client->SetReflectorModule(new_module); + } + else + { + // drop if invalid module + delete Header; + g_Reflector.ReleaseClients(); + return NULL; + } + } + + // get client callsign + via = client->GetCallsign(); + + // and try to open the stream + if ( (stream = g_Reflector.OpenStream(Header, client)) != NULL ) + { + // keep the handle + m_Streams.push_back(stream); + newstream = true; + } + + // update last heard + g_Reflector.GetUsers()->Hearing(Header->GetMyCallsign(), via, Header->GetRpt2Callsign()); + g_Reflector.ReleaseUsers(); + + // delete header if needed + if ( !newstream ) + { + delete Header; + } + + } + else + { + // drop + delete Header; + } + } + // release + g_Reflector.ReleaseClients(); + } + else + { + // stream already open + // skip packet, but tickle the stream + stream->Tickle(); + // and delete packet + delete Header; + } + + // done + return newstream; +} + + +//////////////////////////////////////////////////////////////////////////////////////// +// packet decoding helpers + +CDvHeaderPacket *CG3Protocol::IsValidDvHeaderPacket(const CBuffer &Buffer) +{ + CDvHeaderPacket *header = NULL; + + if ( (Buffer.size() == 56) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) && + (Buffer.data()[4] == 0x10) && (Buffer.data()[8] == 0x20) ) + { + // create packet + header = new CDvHeaderPacket((struct dstar_header *)&(Buffer.data()[15]), + *((uint16 *)&(Buffer.data()[12])), 0x80); + // check validity of packet + if ( !header->IsValid() ) + { + delete header; + header = NULL; + } + } + return header; +} + +CDvFramePacket *CG3Protocol::IsValidDvFramePacket(const CBuffer &Buffer) +{ + CDvFramePacket *dvframe = NULL; + + if ( (Buffer.size() == 27) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) && + (Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) && + ((Buffer.data()[14] & 0x40) == 0) ) + { + // create packet + dvframe = new CDvFramePacket((struct dstar_dvframe *)&(Buffer.data()[15]), + *((uint16 *)&(Buffer.data()[12])), Buffer.data()[14]); + // check validity of packet + if ( !dvframe->IsValid() ) + { + delete dvframe; + dvframe = NULL; + } + } + return dvframe; +} + +CDvLastFramePacket *CG3Protocol::IsValidDvLastFramePacket(const CBuffer &Buffer) +{ + CDvLastFramePacket *dvframe = NULL; + + if ( (Buffer.size() == 27) && (Buffer.Compare((uint8 *)"DSVT", 4) == 0) && + (Buffer.data()[4] == 0x20) && (Buffer.data()[8] == 0x20) && + ((Buffer.data()[14] & 0x40) != 0) ) + { + // create packet + dvframe = new CDvLastFramePacket((struct dstar_dvframe *)&(Buffer.data()[15]), + *((uint16 *)&(Buffer.data()[12])), Buffer.data()[14]); + // check validity of packet + if ( !dvframe->IsValid() ) + { + delete dvframe; + dvframe = NULL; + } + } + return dvframe; +} + +//////////////////////////////////////////////////////////////////////////////////////// +// packet encoding helpers + +bool CG3Protocol::EncodeDvHeaderPacket(const CDvHeaderPacket &Packet, CBuffer *Buffer) const +{ + uint8 tag[] = { 'D','S','V','T',0x10,0x00,0x00,0x00,0x20,0x00,0x01,0x02 }; + struct dstar_header DstarHeader; + + Packet.ConvertToDstarStruct(&DstarHeader); + + Buffer->Set(tag, sizeof(tag)); + Buffer->Append(Packet.GetStreamId()); + Buffer->Append((uint8)0x80); + Buffer->Append((uint8 *)&DstarHeader, sizeof(struct dstar_header)); + + return true; +} + +bool CG3Protocol::EncodeDvFramePacket(const CDvFramePacket &Packet, CBuffer *Buffer) const +{ + uint8 tag[] = { 'D','S','V','T',0x20,0x00,0x00,0x00,0x20,0x00,0x01,0x02 }; + + Buffer->Set(tag, sizeof(tag)); + Buffer->Append(Packet.GetStreamId()); + Buffer->Append((uint8)(Packet.GetPacketId() % 21)); + Buffer->Append((uint8 *)Packet.GetAmbe(), AMBE_SIZE); + Buffer->Append((uint8 *)Packet.GetDvData(), DVDATA_SIZE); + + return true; + +} + +bool CG3Protocol::EncodeDvLastFramePacket(const CDvLastFramePacket &Packet, CBuffer *Buffer) const +{ + uint8 tag1[] = { 'D','S','V','T',0x20,0x00,0x00,0x00,0x20,0x00,0x01,0x02 }; + uint8 tag2[] = { 0x55,0xC8,0x7A,0x00,0x00,0x00,0x00,0x00,0x00,0x25,0x1A,0xC6 }; + + Buffer->Set(tag1, sizeof(tag1)); + Buffer->Append(Packet.GetStreamId()); + Buffer->Append((uint8)((Packet.GetPacketId() % 21) | 0x40)); + Buffer->Append(tag2, sizeof(tag2)); + + return true; +} + +//////////////////////////////////////////////////////////////////////////////////////// +// option helpers + +char *CG3Protocol::TrimWhiteSpaces(char *str) +{ + char *end; + while ((*str == ' ') || (*str == '\t')) str++; + if (*str == 0) + return str; + end = str + strlen(str) - 1; + while ((end > str) && ((*end == ' ') || (*end == '\t') || (*end == '\r'))) end --; + *(end + 1) = 0; + return str; +} + + +void CG3Protocol::NeedReload(void) +{ + struct stat fileStat; + + if (::stat(TERMINALOPTIONS_PATH, &fileStat) != -1) + { + if (m_LastModTime != fileStat.st_mtime) + { + ReadOptions(); + } + } + + // iterate on clients + CClients *clients = g_Reflector.GetClients(); + int index = -1; + CClient *client = NULL; + while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) + { + char module = client->GetReflectorModule(); + if (!strchr(m_Modules.c_str(), module) && !strchr(m_Modules.c_str(), '*')) + { + clients->RemoveClient(client); + } + } + g_Reflector.ReleaseClients(); +} + +void CG3Protocol::ReadOptions(void) +{ + char sz[256]; + int opts = 0; + + + std::ifstream file(TERMINALOPTIONS_PATH); + if (file.is_open()) + { + m_GwAddress = 0u; + m_Modules = "*"; + + while (file.getline(sz, sizeof(sz)).good()) + { + char *szt = TrimWhiteSpaces(sz); + char *szval; + + if ((::strlen(szt) > 0) && szt[0] != '#') + { + if ((szt = ::strtok(szt, " ,\t")) != NULL) + { + if ((szval = ::strtok(NULL, " ,\t")) != NULL) + { + if (::strncmp(szt, "address", 7) == 0) + { + in_addr addr = { .s_addr = inet_addr(szval) }; + if (addr.s_addr) + { + std::cout << "G3 handler address set to " << inet_ntoa(addr) << std::endl; + m_GwAddress = addr.s_addr; + opts++; + } + } + else if (strncmp(szt, "modules", 7) == 0) + { + std::cout << "G3 handler module list set to " << szval << std::endl; + m_Modules = szval; + opts++; + } + else + { + // unknown option - ignore + } + } + } + } + } + std::cout << "G3 handler loaded " << opts << " options from file " << TERMINALOPTIONS_PATH << std::endl; + file.close(); + + struct stat fileStat; + + if (::stat(TERMINALOPTIONS_PATH, &fileStat) != -1) + { + m_LastModTime = fileStat.st_mtime; + } + } +} + diff --git a/src/cg3protocol.h b/src/cg3protocol.h new file mode 100644 index 0000000..7c0da03 --- /dev/null +++ b/src/cg3protocol.h @@ -0,0 +1,135 @@ +// +// cg3protocol.h +// xlxd +// +// Created by Marius Petrescu (YO2LOJ) on 03/06/2019. +// Copyright © 2019 Marius Petrescu (YO2LOJ). All rights reserved. +// +// ---------------------------------------------------------------------------- +// This file is part of xlxd. +// +// xlxd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// xlxd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Foobar. If not, see . +// ---------------------------------------------------------------------------- + +#ifndef cg3protocol_h +#define cg3protocol_h + +#include +#include "ctimepoint.h" +#include "cprotocol.h" +#include "cdvheaderpacket.h" +#include "cdvframepacket.h" +#include "cdvlastframepacket.h" + +//////////////////////////////////////////////////////////////////////////////////////// + +// note on the G3 terminal/AP protocol: +// +// There are 3 steps in handling an incoming connection +// +// 1 - Notification of terminal call on port UDP 12346 +// - Call will be rejected if in blacklisted +// +// 2 - Destination request on port UDP 12345 +// - Calls to specific callsigns will be accepted for a default module +// - Repeater calls will be accepted for local modules +// - All other calls are rehected +// +// 3 - Actual D-star flow like in Dextra to/from port 40000 (2 distint sockets) +// +// Alive monitoring is done via a "PING" to remote port 40000. We will get an +// ICMP unreachable on terminal mode close or on station shut down if routing is done +// correctly. Otherwise a long timeout is used (e.g. 1h) + + +//////////////////////////////////////////////////////////////////////////////////////// +// class + +class CG3Protocol : public CProtocol +{ +public: + // constructor + CG3Protocol() : m_GwAddress(0u), m_Modules("*"), m_LastModTime(0) {}; + + // destructor + virtual ~CG3Protocol() {}; + + // initialization + bool Init(void); + + // close + void Close(void); + + // task + void Task(void); + +protected: + // threads + static void PresenceThread(CG3Protocol *); + static void ConfigThread(CG3Protocol *); + static void IcmpThread(CG3Protocol *); + + // helper tasks + void PresenceTask(void); + void ConfigTask(void); + void IcmpTask(void); + + // config + void ReadOptions(void); + + // helper + char *TrimWhiteSpaces(char *); + void NeedReload(void); + + // queue helper + void HandleQueue(void); + + // keepalive helpers + void HandleKeepalives(void); + + // stream helpers + bool OnDvHeaderPacketIn(CDvHeaderPacket *, const CIp &); + + // packet decoding helpers + CDvHeaderPacket *IsValidDvHeaderPacket(const CBuffer &); + CDvFramePacket *IsValidDvFramePacket(const CBuffer &); + CDvLastFramePacket *IsValidDvLastFramePacket(const CBuffer &); + + // packet encoding helpers + bool EncodeDvHeaderPacket(const CDvHeaderPacket &, CBuffer *) const; + bool EncodeDvFramePacket(const CDvFramePacket &, CBuffer *) const; + bool EncodeDvLastFramePacket(const CDvLastFramePacket &, CBuffer *) const; + +protected: + std::thread *m_pPresenceThread; + std::thread *m_pConfigThread; + std::thread *m_pIcmpThread; + + // time + CTimePoint m_LastKeepaliveTime; + + // sockets + CUdpSocket m_DvOutSocket; + CUdpSocket m_PresenceSocket; + CUdpSocket m_ConfigSocket; + int m_IcmpRawSocket; + + // optional params + uint32 m_GwAddress; + std::string m_Modules; + time_t m_LastModTime; +}; + +//////////////////////////////////////////////////////////////////////////////////////// +#endif /* cg3protocol_h */ diff --git a/src/cgatekeeper.cpp b/src/cgatekeeper.cpp index 8ec8ce1..50c079f 100644 --- a/src/cgatekeeper.cpp +++ b/src/cgatekeeper.cpp @@ -1,4 +1,4 @@ -// +// // cgatekeeper.cpp // xlxd // @@ -102,6 +102,7 @@ bool CGateKeeper::MayLink(const CCallsign &callsign, const CIp &ip, int protocol case PROTOCOL_DMRPLUS: case PROTOCOL_DMRMMDVM: case PROTOCOL_YSF: + case PROTOCOL_G3: // first check is IP & callsigned listed OK ok &= IsNodeListedOk(callsign, ip); // todo: then apply any protocol specific authorisation for the operation @@ -143,6 +144,7 @@ bool CGateKeeper::MayTransmit(const CCallsign &callsign, const CIp &ip, int prot case PROTOCOL_DMRPLUS: case PROTOCOL_DMRMMDVM: case PROTOCOL_YSF: + case PROTOCOL_G3: // first check is IP & callsigned listed OK ok &= IsNodeListedOk(callsign, ip, module); // todo: then apply any protocol specific authorisation for the operation diff --git a/src/cprotocols.cpp b/src/cprotocols.cpp index 92b353f..bc6c4d4 100644 --- a/src/cprotocols.cpp +++ b/src/cprotocols.cpp @@ -1,4 +1,4 @@ -// +// // cprotocols.cpp // xlxd // @@ -30,6 +30,7 @@ #include "cdmrplusprotocol.h" #include "cdmrmmdvmprotocol.h" #include "cysfprotocol.h" +#include "cg3protocol.h" #include "cprotocols.h" @@ -102,6 +103,12 @@ bool CProtocols::Init(void) delete m_Protocols[6]; m_Protocols[6] = new CYsfProtocol; ok &= m_Protocols[6]->Init(); + + // create and initialize G3 + delete m_Protocols[7]; + m_Protocols[7] = new CG3Protocol; + ok &= m_Protocols[7]->Init(); + } m_Mutex.unlock(); diff --git a/src/cudpsocket.cpp b/src/cudpsocket.cpp index 5caa074..3498688 100644 --- a/src/cudpsocket.cpp +++ b/src/cudpsocket.cpp @@ -53,6 +53,7 @@ CUdpSocket::~CUdpSocket() bool CUdpSocket::Open(uint16 uiPort) { bool open = false; + int on = 1; // create socket m_Socket = socket(PF_INET,SOCK_DGRAM,0); @@ -67,6 +68,7 @@ bool CUdpSocket::Open(uint16 uiPort) if ( bind(m_Socket, (struct sockaddr *)&m_SocketAddr, sizeof(struct sockaddr_in)) == 0 ) { fcntl(m_Socket, F_SETFL, O_NONBLOCK); + setsockopt(m_Socket, IPPROTO_IP, IP_PKTINFO, (char *)&on, sizeof(on)); open = true; } else @@ -99,10 +101,34 @@ int CUdpSocket::Receive(CBuffer *Buffer, CIp *Ip, int timeout) unsigned int uiFromLen = sizeof(struct sockaddr_in); int iRecvLen = -1; struct timeval tv; - + + struct msghdr Msg; + struct iovec Iov[1]; + + union { + struct cmsghdr cm; + unsigned char pktinfo_sizer[sizeof(struct cmsghdr) + sizeof(struct in_pktinfo)]; + } Control; + // socket valid ? if ( m_Socket != -1 ) { + // allocate buffer + Buffer->resize(UDP_BUFFER_LENMAX); + + //prepare msghdr + bzero(&Msg, sizeof(Msg)); + Iov[0].iov_base = Buffer->data(); + Iov[0].iov_len = UDP_BUFFER_LENMAX; + + bzero(&Sin, sizeof(Sin)); + Msg.msg_name = &Sin; + Msg.msg_namelen = sizeof(Sin); + Msg.msg_iov = Iov; + Msg.msg_iovlen = 1; + Msg.msg_control = &Control; + Msg.msg_controllen = sizeof(Control); + // control socket FD_ZERO(&FdSet); FD_SET(m_Socket, &FdSet); @@ -110,13 +136,8 @@ int CUdpSocket::Receive(CBuffer *Buffer, CIp *Ip, int timeout) tv.tv_usec = (timeout % 1000) * 1000; select(m_Socket + 1, &FdSet, 0, 0, &tv); - // allocate buffer - Buffer->resize(UDP_BUFFER_LENMAX); - // read - iRecvLen = (int)recvfrom(m_Socket, - (void *)Buffer->data(), UDP_BUFFER_LENMAX, - 0, (struct sockaddr *)&Sin, &uiFromLen); + iRecvLen = (int)recvmsg(m_Socket, &Msg, 0); // handle if ( iRecvLen != -1 ) @@ -126,6 +147,17 @@ int CUdpSocket::Receive(CBuffer *Buffer, CIp *Ip, int timeout) // get IP Ip->SetSockAddr(&Sin); + + // get local IP + struct cmsghdr *Cmsg; + for (Cmsg = CMSG_FIRSTHDR(&Msg); Cmsg != NULL; Cmsg = CMSG_NXTHDR(&Msg, Cmsg)) + { + if (Cmsg->cmsg_level == IPPROTO_IP && Cmsg->cmsg_type == IP_PKTINFO) + { + struct in_pktinfo *PktInfo = (struct in_pktinfo *)CMSG_DATA(Cmsg); + m_LocalAddr.s_addr = PktInfo->ipi_spec_dst.s_addr; + } + } } } diff --git a/src/cudpsocket.h b/src/cudpsocket.h index e91ed80..609450a 100644 --- a/src/cudpsocket.h +++ b/src/cudpsocket.h @@ -68,10 +68,12 @@ public: int Send(const char *, const CIp &); int Send(const char *, const CIp &, uint16); + struct in_addr *GetLocalAddr(void) { return &m_LocalAddr; } protected: // data int m_Socket; struct sockaddr_in m_SocketAddr; + struct in_addr m_LocalAddr; }; //////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/main.h b/src/main.h index e9f627e..29442d3 100644 --- a/src/main.h +++ b/src/main.h @@ -1,4 +1,4 @@ -// +// // main.h // xlxd // @@ -67,7 +67,7 @@ // protocols --------------------------------------------------- -#define NB_OF_PROTOCOLS 7 +#define NB_OF_PROTOCOLS 8 #define PROTOCOL_ANY -1 #define PROTOCOL_NONE 0 @@ -78,6 +78,7 @@ #define PROTOCOL_DMRPLUS 5 #define PROTOCOL_DMRMMDVM 6 #define PROTOCOL_YSF 7 +#define PROTOCOL_G3 8 // DExtra #define DEXTRA_PORT 30001 // UDP port @@ -123,6 +124,13 @@ #define YSF_AUTOLINK_ENABLE 0 // 1 = enable, 0 = disable auto-link #define YSF_AUTOLINK_MODULE 'B' // module for client to auto-link to +// G3 Terminal +#define G3_PRESENCE_PORT 12346 // UDP port +#define G3_CONFIG_PORT 12345 // UDP port +#define G3_DV_PORT 40000 // UDP port +#define G3_KEEPALIVE_PERIOD 10 // in seconds +#define G3_KEEPALIVE_TIMEOUT 3600 // in seconds, 1 hour + // Transcoder server -------------------------------------------- @@ -163,6 +171,7 @@ #define WHITELIST_PATH "/xlxd/xlxd.whitelist" #define BLACKLIST_PATH "/xlxd/xlxd.blacklist" #define INTERLINKLIST_PATH "/xlxd/xlxd.interlink" +#define TERMINALOPTIONS_PATH "/xlxd/xlxd.terminal" #define DEBUGDUMP_PATH "/var/log/xlxd.debug" // system constants --------------------------------------------- From a78c30abfb5c393363fcab6df83151916e58327a Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 27 Jan 2020 16:34:57 +0100 Subject: [PATCH 06/40] Test gain set to -3/+3 --- ambed/main.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ambed/main.h b/ambed/main.h index 931badc..bcfb1f7 100644 --- a/ambed/main.h +++ b/ambed/main.h @@ -68,8 +68,8 @@ #define CODEC_AMBE2PLUS 2 // Transcoding speech gains -#define CODECGAIN_AMBEPLUS -10 // in dB -#define CODECGAIN_AMBE2PLUS +10 // in dB +#define CODECGAIN_AMBEPLUS -3//-10 // in dB +#define CODECGAIN_AMBE2PLUS +3//+10 // in dB // Timeouts ----------------------------------------------------- #define STREAM_ACTIVITY_TIMEOUT 3 // in seconds From 64f5fddf17bdaabc5eebabc48066f10ad029f3f7 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 28 Jan 2020 21:06:43 +0100 Subject: [PATCH 07/40] Add AGC --- ambed/cagc.cpp | 82 +++++++++++++++++++++++++++++++++++++ ambed/cagc.h | 56 +++++++++++++++++++++++++ ambed/cusb3xxxinterface.cpp | 5 ++- ambed/cvocodecchannel.cpp | 2 +- ambed/cvocodecchannel.h | 4 ++ 5 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 ambed/cagc.cpp create mode 100644 ambed/cagc.h diff --git a/ambed/cagc.cpp b/ambed/cagc.cpp new file mode 100644 index 0000000..721d69f --- /dev/null +++ b/ambed/cagc.cpp @@ -0,0 +1,82 @@ +// +// cagc.cpp +// ambed +// +// Created by Jean-Luc Deltombe (LX3JL) on 28/04/2017. +// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved. +// +// ---------------------------------------------------------------------------- +// This file is part of ambed. +// +// xlxd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// xlxd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Foobar. If not, see . +// ---------------------------------------------------------------------------- +// Geoffrey Merck F4FXL / KC3FRA AGC code borrowed from Liquid DSP +// Only took the parts we need qnd recoeded it to be close the XLX coding style +// https://github.com/jgaeddert/liquid-dsp/blob/master/src/agc/src/agc.c + +#include "main.h" +#include +#include "cagc.h" + + +//////////////////////////////////////////////////////////////////////////////////////// +// constructor + +CAGC::CAGC(float initialLeveldB) +{ + // set internal gain appropriately + m_g = powf(10.0f, -initialLeveldB/20.0f); + + // ensure resulting gain is not arbitrarily low + if (m_g < 1e-16f) + m_g = 1e-16f; + + m_scale = 1.0f; + m_bandwidth = 1e-2f; + m_y2_prime = 1.0f; +} + +void CAGC::Apply(uint8 * voice, int size) +{ + for (int i = 0; i < size; i+=2) + { + //Get the sample + float _x = (float)(short)MAKEWORD(voice[i+1], voice[i]); + + //apply AGC + // apply gain to input sample + float _y = _x * m_g; + + // compute output signal energy + float y2 = _y * _y; + + // smooth energy estimate using single-pole low-pass filter + m_y2_prime = (1.0f - m_alpha) * m_y2_prime + m_alpha*y2; + + // update gain according to output energy + if (m_y2_prime > 1e-6f) + m_g *= exp( -0.5f * m_alpha * log(m_y2_prime) ); + + // clamp to 120 dB gain + if (m_g > 1e6f) + m_g = 1e6f; + + // apply output scale + _y *= m_scale; + + //write processed sample back to it + voice[i] = HIBYTE((short)_y); + voice[i+1] = LOBYTE((short)_y); + } +} \ No newline at end of file diff --git a/ambed/cagc.h b/ambed/cagc.h new file mode 100644 index 0000000..20f7800 --- /dev/null +++ b/ambed/cagc.h @@ -0,0 +1,56 @@ +// +// cagc.h +// ambed +// +// Created by Jean-Luc Deltombe (LX3JL) on 26/04/2017. +// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved. +// +// ---------------------------------------------------------------------------- +// This file is part of ambed. +// +// xlxd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// xlxd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Foobar. If not, see . +// ---------------------------------------------------------------------------- +// Geoffrey Merck F4FXL / KC3FRA AGC code borrowed from Liquid DSP +// Only took the parts we need qnd recoeded it to be close the XLX coding style +// https://github.com/jgaeddert/liquid-dsp/blob/master/src/agc/src/agc.c + +#ifndef cagc_h +#define cagc_h + +#include "main.h" + +class CAGC +{ +public: + //Constructor + CAGC(float initialLeveldB); + + //methods + void Apply(uint8 * voice, int size); + float GetGain(){ return m_scale; }//gets current gain (linear) + +private: + // gain variables + float m_g; // current gain value + float m_scale; // output scale value + + // gain control loop filter parameters + float m_bandwidth; // bandwidth-time constant + float m_alpha; // feed-back gain + + // signal level estimate + float m_y2_prime; // filtered output signal energy estimate +}; + +#endif /* cgc_h */ \ No newline at end of file diff --git a/ambed/cusb3xxxinterface.cpp b/ambed/cusb3xxxinterface.cpp index c8eb461..732fe4a 100644 --- a/ambed/cusb3xxxinterface.cpp +++ b/ambed/cusb3xxxinterface.cpp @@ -152,7 +152,10 @@ void CUsb3xxxInterface::Task(void) { Queue = Channel->GetVoiceQueue(); CVoicePacket *clone = new CVoicePacket(VoicePacket); - clone->ApplyGain(Channel->GetSpeechGain()); + CAGC agc = Channel->GetAGC(); + agc.Apply(clone->GetVoice(), clone->GetVoiceSize()); + std::cout << "Gain : " << agc.GetGain(); + //clone->ApplyGain(Channel->GetSpeechGain()); Queue->push(clone); Channel->ReleaseVoiceQueue(); } diff --git a/ambed/cvocodecchannel.cpp b/ambed/cvocodecchannel.cpp index 0212424..04a252c 100644 --- a/ambed/cvocodecchannel.cpp +++ b/ambed/cvocodecchannel.cpp @@ -27,11 +27,11 @@ #include "cvocodecchannel.h" #include "cvocodecinterface.h" - //////////////////////////////////////////////////////////////////////////////////////// // constructor CVocodecChannel::CVocodecChannel(CVocodecInterface *InterfaceIn, int iChIn, CVocodecInterface *InterfaceOut, int iChOut, int iSpeechGain) +: m_AGC((float)iSpeechGain) { m_bOpen = false; m_InterfaceIn = InterfaceIn; diff --git a/ambed/cvocodecchannel.h b/ambed/cvocodecchannel.h index 4848c87..c0983a9 100644 --- a/ambed/cvocodecchannel.h +++ b/ambed/cvocodecchannel.h @@ -27,6 +27,7 @@ #define cvocodecchannel_h #include "cpacketqueue.h" +#include "cagc.h" //////////////////////////////////////////////////////////////////////////////////////// // class @@ -53,6 +54,7 @@ public: int GetChannelIn(void) const { return m_iChannelIn; } int GetChannelOut(void) const { return m_iChannelOut; } int GetSpeechGain(void) const { return m_iSpeechGain; } + CAGC& GetAGC() { return m_AGC; }; // interfaces bool IsInterfaceIn(const CVocodecInterface *interface) { return (interface == m_InterfaceIn); } @@ -92,6 +94,8 @@ protected: // settings int m_iSpeechGain; +private: + CAGC m_AGC; }; //////////////////////////////////////////////////////////////////////////////////////// From 658a47bc4eb010a4f5d437d4d8249511cc869806 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 28 Jan 2020 21:44:51 +0100 Subject: [PATCH 08/40] Avoid Exxposing a reference to the internal AGC, improve debug info --- ambed/cagc.h | 6 +++--- ambed/cusb3xxxinterface.cpp | 4 +--- ambed/cvocodecchannel.cpp | 6 ++++++ ambed/cvocodecchannel.h | 5 ++++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ambed/cagc.h b/ambed/cagc.h index 20f7800..b549197 100644 --- a/ambed/cagc.h +++ b/ambed/cagc.h @@ -29,6 +29,7 @@ #define cagc_h #include "main.h" +#include "math.h" class CAGC { @@ -38,10 +39,9 @@ public: //methods void Apply(uint8 * voice, int size); - float GetGain(){ return m_scale; }//gets current gain (linear) - + float GetGain(){ return -20.0f*log10(m_g); }//gets current gain + private: - // gain variables float m_g; // current gain value float m_scale; // output scale value diff --git a/ambed/cusb3xxxinterface.cpp b/ambed/cusb3xxxinterface.cpp index 732fe4a..210b01f 100644 --- a/ambed/cusb3xxxinterface.cpp +++ b/ambed/cusb3xxxinterface.cpp @@ -152,9 +152,7 @@ void CUsb3xxxInterface::Task(void) { Queue = Channel->GetVoiceQueue(); CVoicePacket *clone = new CVoicePacket(VoicePacket); - CAGC agc = Channel->GetAGC(); - agc.Apply(clone->GetVoice(), clone->GetVoiceSize()); - std::cout << "Gain : " << agc.GetGain(); + Channel->ApplyAGC(*clone); //clone->ApplyGain(Channel->GetSpeechGain()); Queue->push(clone); Channel->ReleaseVoiceQueue(); diff --git a/ambed/cvocodecchannel.cpp b/ambed/cvocodecchannel.cpp index 04a252c..42c3bf8 100644 --- a/ambed/cvocodecchannel.cpp +++ b/ambed/cvocodecchannel.cpp @@ -92,6 +92,12 @@ uint8 CVocodecChannel::GetCodecOut(void) const return m_InterfaceOut->GetChannelCodec(m_iChannelOut); } +void CVocodecChannel::ApplyAGC(CVoicePacket& voicePacket) +{ + m_AGC.Apply(voicePacket.GetVoice(), voicePacket.GetVoiceSize()); + std::cout << "Gain : " << m_AGC.GetGain() << "\n"; +} + //////////////////////////////////////////////////////////////////////////////////////// // queues helpers diff --git a/ambed/cvocodecchannel.h b/ambed/cvocodecchannel.h index c0983a9..58fdfe5 100644 --- a/ambed/cvocodecchannel.h +++ b/ambed/cvocodecchannel.h @@ -28,6 +28,7 @@ #include "cpacketqueue.h" #include "cagc.h" +#include "cvoicepacket.h" //////////////////////////////////////////////////////////////////////////////////////// // class @@ -54,7 +55,9 @@ public: int GetChannelIn(void) const { return m_iChannelIn; } int GetChannelOut(void) const { return m_iChannelOut; } int GetSpeechGain(void) const { return m_iSpeechGain; } - CAGC& GetAGC() { return m_AGC; }; + + //Processing + void ApplyAGC(CVoicePacket& voicePacket); // interfaces bool IsInterfaceIn(const CVocodecInterface *interface) { return (interface == m_InterfaceIn); } From 53384f036c14cbb817148a87154f655124205a48 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 29 Jan 2020 17:30:22 +0100 Subject: [PATCH 09/40] Clamp Gain, Scale input sample Add gain clamping +-dB Scale input Sample --- ambed/cagc.cpp | 31 +++++++++++++++++++++++-------- ambed/cagc.h | 8 ++++---- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/ambed/cagc.cpp b/ambed/cagc.cpp index 721d69f..71dd28d 100644 --- a/ambed/cagc.cpp +++ b/ambed/cagc.cpp @@ -36,17 +36,25 @@ CAGC::CAGC(float initialLeveldB) { // set internal gain appropriately - m_g = powf(10.0f, -initialLeveldB/20.0f); + m_g = pow(10.0f, initialLeveldB/20.0f); // ensure resulting gain is not arbitrarily low if (m_g < 1e-16f) m_g = 1e-16f; - m_scale = 1.0f; - m_bandwidth = 1e-2f; + m_scale = (float)0xFFFF; + m_bandwidth = 1e-2f; //TODO : Move to parameter ? + m_gMax = pow(10.0f, initialLeveldB + 10.0f/20.0f);//+- 10dB Margin, TODO Move margin to constant + m_gMin = pow(10.0f, initialLeveldB - 10.0f/20.0f); + m_alpha = m_bandwidth; m_y2_prime = 1.0f; } +float CAGC::GetGain() +{ + return 20.0f*log10(m_g); +} + void CAGC::Apply(uint8 * voice, int size) { for (int i = 0; i < size; i+=2) @@ -54,6 +62,11 @@ void CAGC::Apply(uint8 * voice, int size) //Get the sample float _x = (float)(short)MAKEWORD(voice[i+1], voice[i]); + //This AGC tries to smooth energy so it does not exceed 1 + //Therefore divide by our max supposed value + //Maybe we could also change y2 prime calculation below, but for now stick with this + _x /= m_scale; + //apply AGC // apply gain to input sample float _y = _x * m_g; @@ -66,16 +79,18 @@ void CAGC::Apply(uint8 * voice, int size) // update gain according to output energy if (m_y2_prime > 1e-6f) - m_g *= exp( -0.5f * m_alpha * log(m_y2_prime) ); + m_g *= exp( -0.5f * m_alpha * log(m_y2_prime) ); - // clamp to 120 dB gain - if (m_g > 1e6f) - m_g = 1e6f; + // clamp gain + if (m_g > m_gMax) + m_g = m_gMax; + else if(m_g < m_gMin) + m_g = m_gMin; // apply output scale _y *= m_scale; - //write processed sample back to it + //write processed sample back voice[i] = HIBYTE((short)_y); voice[i+1] = LOBYTE((short)_y); } diff --git a/ambed/cagc.h b/ambed/cagc.h index b549197..ad8aa6e 100644 --- a/ambed/cagc.h +++ b/ambed/cagc.h @@ -21,7 +21,7 @@ // You should have received a copy of the GNU General Public License // along with Foobar. If not, see . // ---------------------------------------------------------------------------- -// Geoffrey Merck F4FXL / KC3FRA AGC code borrowed from Liquid DSP +// Geoffrey Merck F4FXL / KC3FRA AGC code largely inspired by Liquid DSP // Only took the parts we need qnd recoeded it to be close the XLX coding style // https://github.com/jgaeddert/liquid-dsp/blob/master/src/agc/src/agc.c @@ -29,7 +29,6 @@ #define cagc_h #include "main.h" -#include "math.h" class CAGC { @@ -39,11 +38,12 @@ public: //methods void Apply(uint8 * voice, int size); - float GetGain(){ return -20.0f*log10(m_g); }//gets current gain + float GetGain();//gets current gain private: float m_g; // current gain value - float m_scale; // output scale value + float m_gMax, m_gMin; //gain clamping + float m_scale; // scale value // gain control loop filter parameters float m_bandwidth; // bandwidth-time constant From 7ffc58daaa650bd5742656f1bafe038d9cc343f7 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 29 Jan 2020 18:12:26 +0100 Subject: [PATCH 10/40] Well, forgot some basic maths .... --- ambed/cagc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ambed/cagc.cpp b/ambed/cagc.cpp index 71dd28d..d388442 100644 --- a/ambed/cagc.cpp +++ b/ambed/cagc.cpp @@ -44,8 +44,8 @@ CAGC::CAGC(float initialLeveldB) m_scale = (float)0xFFFF; m_bandwidth = 1e-2f; //TODO : Move to parameter ? - m_gMax = pow(10.0f, initialLeveldB + 10.0f/20.0f);//+- 10dB Margin, TODO Move margin to constant - m_gMin = pow(10.0f, initialLeveldB - 10.0f/20.0f); + m_gMax = pow(10.0f, (initialLeveldB + 10.0f)/20.0f);//+- 10dB Margin, TODO Move margin to constant + m_gMin = pow(10.0f, (initialLeveldB - 10.0f)/20.0f); m_alpha = m_bandwidth; m_y2_prime = 1.0f; } From 0a06b267485f591cb8bc2069dac4447f21507bfd Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 29 Jan 2020 19:37:35 +0100 Subject: [PATCH 11/40] Apply Scale to energy, value still needs to be tweaked --- ambed/cagc.cpp | 12 ++---------- ambed/cagc.h | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/ambed/cagc.cpp b/ambed/cagc.cpp index d388442..477bd7f 100644 --- a/ambed/cagc.cpp +++ b/ambed/cagc.cpp @@ -42,7 +42,7 @@ CAGC::CAGC(float initialLeveldB) if (m_g < 1e-16f) m_g = 1e-16f; - m_scale = (float)0xFFFF; + m_scale = 32768.0f; m_bandwidth = 1e-2f; //TODO : Move to parameter ? m_gMax = pow(10.0f, (initialLeveldB + 10.0f)/20.0f);//+- 10dB Margin, TODO Move margin to constant m_gMin = pow(10.0f, (initialLeveldB - 10.0f)/20.0f); @@ -62,17 +62,12 @@ void CAGC::Apply(uint8 * voice, int size) //Get the sample float _x = (float)(short)MAKEWORD(voice[i+1], voice[i]); - //This AGC tries to smooth energy so it does not exceed 1 - //Therefore divide by our max supposed value - //Maybe we could also change y2 prime calculation below, but for now stick with this - _x /= m_scale; - //apply AGC // apply gain to input sample float _y = _x * m_g; // compute output signal energy - float y2 = _y * _y; + float y2 = (_y * _y) / m_scale; // smooth energy estimate using single-pole low-pass filter m_y2_prime = (1.0f - m_alpha) * m_y2_prime + m_alpha*y2; @@ -87,9 +82,6 @@ void CAGC::Apply(uint8 * voice, int size) else if(m_g < m_gMin) m_g = m_gMin; - // apply output scale - _y *= m_scale; - //write processed sample back voice[i] = HIBYTE((short)_y); voice[i+1] = LOBYTE((short)_y); diff --git a/ambed/cagc.h b/ambed/cagc.h index ad8aa6e..080d665 100644 --- a/ambed/cagc.h +++ b/ambed/cagc.h @@ -43,7 +43,7 @@ public: private: float m_g; // current gain value float m_gMax, m_gMin; //gain clamping - float m_scale; // scale value + float m_scale; // scale value for target energy // gain control loop filter parameters float m_bandwidth; // bandwidth-time constant From fe700f253b43ca3c8aa4da9df477ba14a53c9625 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 29 Jan 2020 19:57:12 +0100 Subject: [PATCH 12/40] Clean up and better names for variables --- ambed/cagc.cpp | 46 ++++++++++++++++++++++------------------------ ambed/cagc.h | 12 ++++++------ 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/ambed/cagc.cpp b/ambed/cagc.cpp index 477bd7f..3ac73c4 100644 --- a/ambed/cagc.cpp +++ b/ambed/cagc.cpp @@ -36,23 +36,21 @@ CAGC::CAGC(float initialLeveldB) { // set internal gain appropriately - m_g = pow(10.0f, initialLeveldB/20.0f); + m_Gain = pow(10.0f, initialLeveldB/20.0f); + //+- 10dB Margin, TODO Move margin to constant + m_GainMax = pow(10.0f, (initialLeveldB + 10.0f)/20.0f); + m_GainMin = pow(10.0f, (initialLeveldB - 10.0f)/20.0f); + + m_EnergyPrime = 1.0f; + m_targetEnergy = 32768.0f;//TODO : Move to parameter ? - // ensure resulting gain is not arbitrarily low - if (m_g < 1e-16f) - m_g = 1e-16f; - - m_scale = 32768.0f; - m_bandwidth = 1e-2f; //TODO : Move to parameter ? - m_gMax = pow(10.0f, (initialLeveldB + 10.0f)/20.0f);//+- 10dB Margin, TODO Move margin to constant - m_gMin = pow(10.0f, (initialLeveldB - 10.0f)/20.0f); - m_alpha = m_bandwidth; - m_y2_prime = 1.0f; + m_Bandwidth = 1e-2f;//TODO : Move to parameter ? + m_Alpha = m_Bandwidth; } float CAGC::GetGain() { - return 20.0f*log10(m_g); + return 20.0f*log10(m_Gain); } void CAGC::Apply(uint8 * voice, int size) @@ -60,30 +58,30 @@ void CAGC::Apply(uint8 * voice, int size) for (int i = 0; i < size; i+=2) { //Get the sample - float _x = (float)(short)MAKEWORD(voice[i+1], voice[i]); + float input = (float)(short)MAKEWORD(voice[i+1], voice[i]); //apply AGC // apply gain to input sample - float _y = _x * m_g; + float output = input * m_Gain; // compute output signal energy - float y2 = (_y * _y) / m_scale; + float instantEnergy = (output * output) / m_targetEnergy; // smooth energy estimate using single-pole low-pass filter - m_y2_prime = (1.0f - m_alpha) * m_y2_prime + m_alpha*y2; + m_EnergyPrime = (1.0f - m_Alpha) * m_EnergyPrime + m_Alpha * instantEnergy; // update gain according to output energy - if (m_y2_prime > 1e-6f) - m_g *= exp( -0.5f * m_alpha * log(m_y2_prime) ); + if (m_EnergyPrime > 1e-6f) + m_Gain *= exp( -0.5f * m_Alpha * log(m_EnergyPrime) ); // clamp gain - if (m_g > m_gMax) - m_g = m_gMax; - else if(m_g < m_gMin) - m_g = m_gMin; + if (m_Gain > m_GainMax) + m_Gain = m_GainMax; + else if(m_Gain < m_GainMin) + m_Gain = m_GainMin; //write processed sample back - voice[i] = HIBYTE((short)_y); - voice[i+1] = LOBYTE((short)_y); + voice[i] = HIBYTE((short)output); + voice[i+1] = LOBYTE((short)output); } } \ No newline at end of file diff --git a/ambed/cagc.h b/ambed/cagc.h index 080d665..c3b1831 100644 --- a/ambed/cagc.h +++ b/ambed/cagc.h @@ -41,16 +41,16 @@ public: float GetGain();//gets current gain private: - float m_g; // current gain value - float m_gMax, m_gMin; //gain clamping - float m_scale; // scale value for target energy + float m_Gain; // current gain value + float m_GainMax, m_GainMin; //gain clamping + float m_targetEnergy; // scale value for target energy // gain control loop filter parameters - float m_bandwidth; // bandwidth-time constant - float m_alpha; // feed-back gain + float m_Bandwidth; // bandwidth-time constant + float m_Alpha; // feed-back gain // signal level estimate - float m_y2_prime; // filtered output signal energy estimate + float m_EnergyPrime; // filtered output signal energy estimate }; #endif /* cgc_h */ \ No newline at end of file From f01c44ed532756e0fedc11bb285413700e67fe19 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 29 Jan 2020 20:02:03 +0100 Subject: [PATCH 13/40] Add comments --- ambed/cagc.cpp | 6 ++++++ ambed/cagc.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ambed/cagc.cpp b/ambed/cagc.cpp index 3ac73c4..619a59f 100644 --- a/ambed/cagc.cpp +++ b/ambed/cagc.cpp @@ -48,11 +48,17 @@ CAGC::CAGC(float initialLeveldB) m_Alpha = m_Bandwidth; } +//////////////////////////////////////////////////////////////////////////////////////// +// get + float CAGC::GetGain() { return 20.0f*log10(m_Gain); } +//////////////////////////////////////////////////////////////////////////////////////// +// process + void CAGC::Apply(uint8 * voice, int size) { for (int i = 0; i < size; i+=2) diff --git a/ambed/cagc.h b/ambed/cagc.h index c3b1831..c1547e3 100644 --- a/ambed/cagc.h +++ b/ambed/cagc.h @@ -23,7 +23,7 @@ // ---------------------------------------------------------------------------- // Geoffrey Merck F4FXL / KC3FRA AGC code largely inspired by Liquid DSP // Only took the parts we need qnd recoeded it to be close the XLX coding style -// https://github.com/jgaeddert/liquid-dsp/blob/master/src/agc/src/agc.c +// https://github.com/jgaeddert/liquid-dsp/blob/master/src/agc/src/agc.c #ifndef cagc_h #define cagc_h From 66eab222c42fa1ab3285a20ad25223a7678f6b88 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 29 Jan 2020 20:08:20 +0100 Subject: [PATCH 14/40] Remove debug information ouput --- ambed/cvocodecchannel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ambed/cvocodecchannel.cpp b/ambed/cvocodecchannel.cpp index 42c3bf8..382c04d 100644 --- a/ambed/cvocodecchannel.cpp +++ b/ambed/cvocodecchannel.cpp @@ -95,7 +95,7 @@ uint8 CVocodecChannel::GetCodecOut(void) const void CVocodecChannel::ApplyAGC(CVoicePacket& voicePacket) { m_AGC.Apply(voicePacket.GetVoice(), voicePacket.GetVoiceSize()); - std::cout << "Gain : " << m_AGC.GetGain() << "\n"; + //std::cout << "Gain : " << m_AGC.GetGain() << "\n"; } //////////////////////////////////////////////////////////////////////////////////////// From 3c06fb0ac12a1bc143b658d9fe6df32e6279963c Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 3 Feb 2020 15:34:08 +0100 Subject: [PATCH 15/40] Do not square energy as we are not complex. Do not clamp gain --- ambed/cagc.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ambed/cagc.cpp b/ambed/cagc.cpp index 619a59f..7cf5e2e 100644 --- a/ambed/cagc.cpp +++ b/ambed/cagc.cpp @@ -42,7 +42,7 @@ CAGC::CAGC(float initialLeveldB) m_GainMin = pow(10.0f, (initialLeveldB - 10.0f)/20.0f); m_EnergyPrime = 1.0f; - m_targetEnergy = 32768.0f;//TODO : Move to parameter ? + m_targetEnergy = 32767.0f;//TODO : Move to parameter ? m_Bandwidth = 1e-2f;//TODO : Move to parameter ? m_Alpha = m_Bandwidth; @@ -70,8 +70,8 @@ void CAGC::Apply(uint8 * voice, int size) // apply gain to input sample float output = input * m_Gain; - // compute output signal energy - float instantEnergy = (output * output) / m_targetEnergy; + // compute output signal energy, scaled to 0 to 1 + float instantEnergy = abs(output) / m_targetEnergy; // smooth energy estimate using single-pole low-pass filter m_EnergyPrime = (1.0f - m_Alpha) * m_EnergyPrime + m_Alpha * instantEnergy; @@ -81,10 +81,10 @@ void CAGC::Apply(uint8 * voice, int size) m_Gain *= exp( -0.5f * m_Alpha * log(m_EnergyPrime) ); // clamp gain - if (m_Gain > m_GainMax) + /*if (m_Gain > m_GainMax) m_Gain = m_GainMax; else if(m_Gain < m_GainMin) - m_Gain = m_GainMin; + m_Gain = m_GainMin;*/ //write processed sample back voice[i] = HIBYTE((short)output); From f936d8ffeb9b2ac1606792b0ee9aa8ad7ce67631 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 3 Feb 2020 20:10:40 +0100 Subject: [PATCH 16/40] Reenable gain clamping --- ambed/cagc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ambed/cagc.cpp b/ambed/cagc.cpp index 7cf5e2e..55294db 100644 --- a/ambed/cagc.cpp +++ b/ambed/cagc.cpp @@ -81,10 +81,10 @@ void CAGC::Apply(uint8 * voice, int size) m_Gain *= exp( -0.5f * m_Alpha * log(m_EnergyPrime) ); // clamp gain - /*if (m_Gain > m_GainMax) + if (m_Gain > m_GainMax) m_Gain = m_GainMax; else if(m_Gain < m_GainMin) - m_Gain = m_GainMin;*/ + m_Gain = m_GainMin; //write processed sample back voice[i] = HIBYTE((short)output); From de961853c7d1724515261232684e72600b711408 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 3 Feb 2020 20:52:14 +0100 Subject: [PATCH 17/40] Add Filtering and defines Add FIR passband Filtering Add defines to swithc features on and off --- ambed/cfirfilter.cpp | 74 +++++++++++++++++++++++++++++++++++++ ambed/cfirfilter.h | 52 ++++++++++++++++++++++++++ ambed/cusb3xxxinterface.cpp | 9 ++++- ambed/cvocodecchannel.cpp | 24 +++++++++++- ambed/cvocodecchannel.h | 17 ++++++++- ambed/main.h | 44 +++++++++++++++++++++- 6 files changed, 214 insertions(+), 6 deletions(-) create mode 100644 ambed/cfirfilter.cpp create mode 100644 ambed/cfirfilter.h diff --git a/ambed/cfirfilter.cpp b/ambed/cfirfilter.cpp new file mode 100644 index 0000000..602e01c --- /dev/null +++ b/ambed/cfirfilter.cpp @@ -0,0 +1,74 @@ +// +// cfirfilter.cpp +// ambed +// +// Created by Jean-Luc Deltombe (LX3JL) on 26/04/2017. +// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved. +// +// ---------------------------------------------------------------------------- +// This file is part of ambed. +// +// xlxd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// xlxd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Foobar. If not, see . +// ---------------------------------------------------------------------------- +// FIRFilter by Geoffrey Merck F4FXL / KC3FRA + +#include "cfirfilter.h" +#include + +CFIRFilter::CFIRFilter(const float* taps, int tapsLength) +{ + m_taps = new float[tapsLength]; + m_buffer = new float[tapsLength]; + + ::memcpy(m_taps, taps, tapsLength * sizeof(float)); + ::memset(m_buffer, 0, tapsLength * sizeof(float)); + m_currentBufferPostion = 0; +} + +CFIRFilter::~CFIRFilter() +{ + delete[] m_taps; + delete[] m_buffer; +} + +inline float CFIRFilter::Process(float inputSample) +{ + // Buffer latest sample + m_buffer[m_currentBufferPostion] = inputSample; + + float outputSample = 0.0f; + for(int i = 0; i < m_tapsLength; i++) + { + outputSample += m_taps[i] * m_buffer[(m_currentBufferPostion + i) % m_tapsLength]; + } + + m_currentBufferPostion = (m_currentBufferPostion + 1) % m_tapsLength; + + return outputSample; +} + +void CFIRFilter::Process(uint8* voice, int length) +{ + for(int i = 0; i < length; i++) + { + //Get the sample + float input = (float)(short)MAKEWORD(voice[i+1], voice[i]); + + float output = Process(input); + + //write processed sample back + voice[i] = HIBYTE((short)output); + voice[i+1] = LOBYTE((short)output); + } +} diff --git a/ambed/cfirfilter.h b/ambed/cfirfilter.h new file mode 100644 index 0000000..aa1dafd --- /dev/null +++ b/ambed/cfirfilter.h @@ -0,0 +1,52 @@ +// +// cfirfilter.h +// ambed +// +// Created by Jean-Luc Deltombe (LX3JL) on 26/04/2017. +// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved. +// +// ---------------------------------------------------------------------------- +// This file is part of ambed. +// +// xlxd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// xlxd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Foobar. If not, see . +// ---------------------------------------------------------------------------- +// FIRFilter by Geoffrey Merck F4FXL / KC3FRA + +#ifndef cfirfilter_h +#define cfirfilter_h + +#include "main.h" + +class CFIRFilter +{ +public : + //Constructor + CFIRFilter(const float* taps, int tapsLength); + + // Destructor + ~CFIRFilter(); + + // Processing + float Process(float inputSample); + void Process(uint8* voice, int length); + +private: + float* m_taps; + int m_tapsLength; + float* m_buffer; + int m_currentBufferPostion; +}; + +#endif //cfirfilter_h + diff --git a/ambed/cusb3xxxinterface.cpp b/ambed/cusb3xxxinterface.cpp index 210b01f..49c1269 100644 --- a/ambed/cusb3xxxinterface.cpp +++ b/ambed/cusb3xxxinterface.cpp @@ -152,8 +152,15 @@ void CUsb3xxxInterface::Task(void) { Queue = Channel->GetVoiceQueue(); CVoicePacket *clone = new CVoicePacket(VoicePacket); +#if USE_BANDPASSFILTER + //Aply band pass before AGC to avoidd amplifying signals we do not want + Channel->ApplyFilter(*clone); +#endif +#if USE_AGC == 1 Channel->ApplyAGC(*clone); - //clone->ApplyGain(Channel->GetSpeechGain()); +#else + clone->ApplyGain(Channel->GetSpeechGain()); +#endif Queue->push(clone); Channel->ReleaseVoiceQueue(); } diff --git a/ambed/cvocodecchannel.cpp b/ambed/cvocodecchannel.cpp index 382c04d..8ce57f8 100644 --- a/ambed/cvocodecchannel.cpp +++ b/ambed/cvocodecchannel.cpp @@ -31,7 +31,6 @@ // constructor CVocodecChannel::CVocodecChannel(CVocodecInterface *InterfaceIn, int iChIn, CVocodecInterface *InterfaceOut, int iChOut, int iSpeechGain) -: m_AGC((float)iSpeechGain) { m_bOpen = false; m_InterfaceIn = InterfaceIn; @@ -39,6 +38,12 @@ CVocodecChannel::CVocodecChannel(CVocodecInterface *InterfaceIn, int iChIn, CVoc m_InterfaceOut = InterfaceOut; m_iChannelOut = iChOut; m_iSpeechGain = iSpeechGain; +#if USE_AGC == 1 + m_AGC = new CAGC((float)iSpeechGain); +#endif +#if USE_BANDPASSFILTER == 1 + m_filter = new CFIRFilter(FILTER_TAPS, FILTER_TAPS_LENGTH); +#endif } //////////////////////////////////////////////////////////////////////////////////////// @@ -47,6 +52,12 @@ CVocodecChannel::CVocodecChannel(CVocodecInterface *InterfaceIn, int iChIn, CVoc CVocodecChannel::~CVocodecChannel() { PurgeAllQueues(); +#if USE_AGC == 1 + delete m_AGC; +#endif +#if USE_BANDPASSFILTER == 1 + delete m_filter; +#endif } //////////////////////////////////////////////////////////////////////////////////////// @@ -92,11 +103,20 @@ uint8 CVocodecChannel::GetCodecOut(void) const return m_InterfaceOut->GetChannelCodec(m_iChannelOut); } +#if USE_AGC == 1 void CVocodecChannel::ApplyAGC(CVoicePacket& voicePacket) { - m_AGC.Apply(voicePacket.GetVoice(), voicePacket.GetVoiceSize()); + m_AGC->Apply(voicePacket.GetVoice(), voicePacket.GetVoiceSize()); //std::cout << "Gain : " << m_AGC.GetGain() << "\n"; } +#endif + +#if USE_BANDPASSFILTER == 1 +void CVocodecChannel::ApplyFilter(CVoicePacket& voicePacket) +{ + m_filter->Process(voicePacket.GetVoice(), voicePacket.GetVoiceSize()); +} +#endif //////////////////////////////////////////////////////////////////////////////////////// // queues helpers diff --git a/ambed/cvocodecchannel.h b/ambed/cvocodecchannel.h index 58fdfe5..735fa00 100644 --- a/ambed/cvocodecchannel.h +++ b/ambed/cvocodecchannel.h @@ -27,7 +27,12 @@ #define cvocodecchannel_h #include "cpacketqueue.h" +#if USE_AGC == 1 #include "cagc.h" +#endif +#if USE_BANDPASSFILTER == 1 +#include "cfirfilter.h" +#endif #include "cvoicepacket.h" //////////////////////////////////////////////////////////////////////////////////////// @@ -57,7 +62,12 @@ public: int GetSpeechGain(void) const { return m_iSpeechGain; } //Processing +#if USE_AGC == 1 void ApplyAGC(CVoicePacket& voicePacket); +#endif +#if USE_BANDPASSFILTER + void ApplyFilter(CVoicePacket& voicePacket); +#endif // interfaces bool IsInterfaceIn(const CVocodecInterface *interface) { return (interface == m_InterfaceIn); } @@ -98,7 +108,12 @@ protected: int m_iSpeechGain; private: - CAGC m_AGC; +#if USE_AGC == 1 + CAGC* m_AGC; +#endif +#if USE_BANDPASSFILTER == 1 + CFIRFilter* m_filter; +#endif }; //////////////////////////////////////////////////////////////////////////////////////// diff --git a/ambed/main.h b/ambed/main.h index bcfb1f7..ef60a2b 100644 --- a/ambed/main.h +++ b/ambed/main.h @@ -68,8 +68,12 @@ #define CODEC_AMBE2PLUS 2 // Transcoding speech gains -#define CODECGAIN_AMBEPLUS -3//-10 // in dB -#define CODECGAIN_AMBE2PLUS +3//+10 // in dB +#define CODECGAIN_AMBEPLUS -10 // in dB +#define CODECGAIN_AMBE2PLUS +10 // in dB + +// Transcoding Tweaks +#define USE_AGC 0 +#define USE_BANDPASSFILTER 1 // Timeouts ----------------------------------------------------- #define STREAM_ACTIVITY_TIMEOUT 3 // in seconds @@ -96,6 +100,42 @@ typedef unsigned int uint; #define LOWORD(dw) ((uint16)(uint32)(dw & 0x0000FFFF)) #define HIWORD(dw) ((uint16)((((uint32)(dw)) >> 16) & 0xFFFF)) +//////////////////////////////////////////////////////////////////////////////////////// +// FIR Filter coefficients computed to be the closest to the recommended filter in +// Documentation +// +// Following GNU Octave script was used +/* +pkg load signal; +fsamp = 8000; +fcuts = [200 300 3000 3400]; +mags = [0 1 0]; +devs = [0.2 1 0.2]; + +[n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,fsamp); +n = n + rem(n,2); +hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale'); + +freqz(hh); +[H,f] = freqz(hh,1,1024,fsamp); +plot(f,abs(H)) +disp(hh); +grid +*/ + +#if USE_BANDPASSFILTER == 1 + +const float FILTER_TAPS[] { +-0.0153779f, 0.0114832f, -0.0060703f, -0.0221526f, 0.0085472f, -0.0449400f, +-0.0068112f, -0.0307485f, -0.0548559f, -0.0022596f, -0.0879344f, -0.0166698f, +-0.0533627f, -0.1015552f, 0.0424673f, -0.2116654f, 0.1267453f, 0.7375000f, +0.1267453f, -0.2116654f, 0.0424673f, -0.1015552f, -0.0533627f, -0.0166698f, +-0.0879344f, -0.0022596f, -0.0548559f, -0.0307485f, -0.0068112f, -0.0449400f, +0.0085472f, -0.0221526f, -0.0060703f, 0.0114832f, -0.0153779f }; +#define FILTER_TAPS_LENGTH 35 + +#endif + //////////////////////////////////////////////////////////////////////////////////////// // global objects From adbea50027abc582fba713b2290509c42f7471c5 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 3 Feb 2020 21:26:41 +0100 Subject: [PATCH 18/40] It is always better to initialize variables --- ambed/cfirfilter.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ambed/cfirfilter.cpp b/ambed/cfirfilter.cpp index 602e01c..f002440 100644 --- a/ambed/cfirfilter.cpp +++ b/ambed/cfirfilter.cpp @@ -30,6 +30,7 @@ CFIRFilter::CFIRFilter(const float* taps, int tapsLength) { m_taps = new float[tapsLength]; m_buffer = new float[tapsLength]; + m_tapsLength = tapsLength; ::memcpy(m_taps, taps, tapsLength * sizeof(float)); ::memset(m_buffer, 0, tapsLength * sizeof(float)); From 4ba6a77ecc3558a8950d6c42dc3f46bfabdf48c5 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 3 Feb 2020 22:23:10 +0100 Subject: [PATCH 19/40] Improve circular buffer --- ambed/cfirfilter.cpp | 8 ++++---- ambed/cfirfilter.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ambed/cfirfilter.cpp b/ambed/cfirfilter.cpp index f002440..9f93db8 100644 --- a/ambed/cfirfilter.cpp +++ b/ambed/cfirfilter.cpp @@ -34,7 +34,7 @@ CFIRFilter::CFIRFilter(const float* taps, int tapsLength) ::memcpy(m_taps, taps, tapsLength * sizeof(float)); ::memset(m_buffer, 0, tapsLength * sizeof(float)); - m_currentBufferPostion = 0; + m_currentBufferPosition = m_tapsLength -1; } CFIRFilter::~CFIRFilter() @@ -46,15 +46,15 @@ CFIRFilter::~CFIRFilter() inline float CFIRFilter::Process(float inputSample) { // Buffer latest sample - m_buffer[m_currentBufferPostion] = inputSample; + m_buffer[m_currentBufferPosition] = inputSample; float outputSample = 0.0f; for(int i = 0; i < m_tapsLength; i++) { - outputSample += m_taps[i] * m_buffer[(m_currentBufferPostion + i) % m_tapsLength]; + outputSample += m_taps[i] * m_buffer[(m_currentBufferPosition + i) % m_tapsLength]; } - m_currentBufferPostion = (m_currentBufferPostion + 1) % m_tapsLength; + m_currentBufferPosition = MAX(0, m_currentBufferPosition - 1); return outputSample; } diff --git a/ambed/cfirfilter.h b/ambed/cfirfilter.h index aa1dafd..9d1d9c4 100644 --- a/ambed/cfirfilter.h +++ b/ambed/cfirfilter.h @@ -45,7 +45,7 @@ private: float* m_taps; int m_tapsLength; float* m_buffer; - int m_currentBufferPostion; + int m_currentBufferPosition; }; #endif //cfirfilter_h From ee1b97a1654e76c548bb3b16a3033c909a7f6309 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 4 Feb 2020 22:21:57 +0100 Subject: [PATCH 20/40] Better FIR Filter implementation, correct sample collecting --- ambed/cfirfilter.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/ambed/cfirfilter.cpp b/ambed/cfirfilter.cpp index 9f93db8..920ffe3 100644 --- a/ambed/cfirfilter.cpp +++ b/ambed/cfirfilter.cpp @@ -34,7 +34,7 @@ CFIRFilter::CFIRFilter(const float* taps, int tapsLength) ::memcpy(m_taps, taps, tapsLength * sizeof(float)); ::memset(m_buffer, 0, tapsLength * sizeof(float)); - m_currentBufferPosition = m_tapsLength -1; + m_currentBufferPosition = 0; } CFIRFilter::~CFIRFilter() @@ -45,23 +45,30 @@ CFIRFilter::~CFIRFilter() inline float CFIRFilter::Process(float inputSample) { - // Buffer latest sample + float output = 0.0f; + int iTaps = 0; + + // Buffer latest sample into delay line m_buffer[m_currentBufferPosition] = inputSample; - float outputSample = 0.0f; - for(int i = 0; i < m_tapsLength; i++) + for(int i = m_currentBufferPosition; i >= 0; i--) { - outputSample += m_taps[i] * m_buffer[(m_currentBufferPosition + i) % m_tapsLength]; + output += m_taps[iTaps++] * m_buffer[i]; } - m_currentBufferPosition = MAX(0, m_currentBufferPosition - 1); + for(int i = m_tapsLength - 1; i > m_currentBufferPosition; i--) + { + output += m_taps[iTaps++] * m_buffer[i]; + } + + m_currentBufferPosition = (m_currentBufferPosition + 1) % m_tapsLength; - return outputSample; + return output; } void CFIRFilter::Process(uint8* voice, int length) { - for(int i = 0; i < length; i++) + for(int i = 0; i < length; i+=2) { //Get the sample float input = (float)(short)MAKEWORD(voice[i+1], voice[i]); From b9d0c6e532b277e11438b5ffe4ebac60f9162850 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 4 Feb 2020 22:23:06 +0100 Subject: [PATCH 21/40] Add AGC clamping constant, turn AGC on, reduce target energy --- ambed/cagc.cpp | 8 +++++--- ambed/main.h | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ambed/cagc.cpp b/ambed/cagc.cpp index 55294db..d5cd58c 100644 --- a/ambed/cagc.cpp +++ b/ambed/cagc.cpp @@ -38,11 +38,13 @@ CAGC::CAGC(float initialLeveldB) // set internal gain appropriately m_Gain = pow(10.0f, initialLeveldB/20.0f); //+- 10dB Margin, TODO Move margin to constant - m_GainMax = pow(10.0f, (initialLeveldB + 10.0f)/20.0f); - m_GainMin = pow(10.0f, (initialLeveldB - 10.0f)/20.0f); + m_GainMax = pow(10.0f, (initialLeveldB + AGC_CLAMPING)/20.0f); + m_GainMin = pow(10.0f, (initialLeveldB - AGC_CLAMPING)/20.0f); m_EnergyPrime = 1.0f; - m_targetEnergy = 32767.0f;//TODO : Move to parameter ? + + // We do not target full scale to avoid stauration + m_targetEnergy = 32767.0f/2.0f;//TODO : Move to parameter ? m_Bandwidth = 1e-2f;//TODO : Move to parameter ? m_Alpha = m_Bandwidth; diff --git a/ambed/main.h b/ambed/main.h index ef60a2b..c66b70c 100644 --- a/ambed/main.h +++ b/ambed/main.h @@ -68,11 +68,12 @@ #define CODEC_AMBE2PLUS 2 // Transcoding speech gains -#define CODECGAIN_AMBEPLUS -10 // in dB -#define CODECGAIN_AMBE2PLUS +10 // in dB +#define CODECGAIN_AMBEPLUS -16 // in dB +#define CODECGAIN_AMBE2PLUS +16 // in dB // Transcoding Tweaks -#define USE_AGC 0 +#define USE_AGC 1 +#define AGC_CLAMPING 3 //clamps the AGC gain to +- this value #define USE_BANDPASSFILTER 1 // Timeouts ----------------------------------------------------- From c44aac0f84ac7e03e8b72cc9543109fcd735b621 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 12 Feb 2020 20:59:11 +0100 Subject: [PATCH 22/40] Default AGC off, restore gains --- ambed/main.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ambed/main.h b/ambed/main.h index c66b70c..62fe65b 100644 --- a/ambed/main.h +++ b/ambed/main.h @@ -68,11 +68,11 @@ #define CODEC_AMBE2PLUS 2 // Transcoding speech gains -#define CODECGAIN_AMBEPLUS -16 // in dB -#define CODECGAIN_AMBE2PLUS +16 // in dB +#define CODECGAIN_AMBEPLUS -10 // in dB +#define CODECGAIN_AMBE2PLUS +10 // in dB // Transcoding Tweaks -#define USE_AGC 1 +#define USE_AGC 0 #define AGC_CLAMPING 3 //clamps the AGC gain to +- this value #define USE_BANDPASSFILTER 1 From 10c796f192ec9e4c9ec01594f2eda93c55c284d9 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Thu, 13 Feb 2020 20:34:51 +0100 Subject: [PATCH 23/40] Make AGC 25dB below saturation --- ambed/cagc.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ambed/cagc.cpp b/ambed/cagc.cpp index d5cd58c..d5b2105 100644 --- a/ambed/cagc.cpp +++ b/ambed/cagc.cpp @@ -44,8 +44,10 @@ CAGC::CAGC(float initialLeveldB) m_EnergyPrime = 1.0f; // We do not target full scale to avoid stauration - m_targetEnergy = 32767.0f/2.0f;//TODO : Move to parameter ? + m_targetEnergy = 32767.0f * pow(10.0f, (initialLeveldB - 25.0)/20.0f);//25 dB below saturation as stated in docs + //we also substract our target gain + //this is the time constant of our AGC... m_Bandwidth = 1e-2f;//TODO : Move to parameter ? m_Alpha = m_Bandwidth; } From 02a583f0b3c9cdecb920bac12e01ae6ce85ec014 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Sat, 22 Feb 2020 06:10:55 +0100 Subject: [PATCH 24/40] Reduce processing delay Process one packet all at once --- ambed/cagc.cpp | 47 ++++++++------------ ambed/cagc.h | 6 +-- ambed/cfirfilter.cpp | 15 +------ ambed/cfirfilter.h | 5 +-- ambed/cfixedgain.cpp | 44 ++++++++++++++++++ ambed/cfixedgain.h | 45 +++++++++++++++++++ ambed/csampleprocessor.h | 36 +++++++++++++++ ambed/csignalprocessor.cpp | 89 +++++++++++++++++++++++++++++++++++++ ambed/csignalprocessor.h | 48 ++++++++++++++++++++ ambed/cusb3xxxinterface.cpp | 10 +---- ambed/cvocodecchannel.cpp | 30 +++---------- ambed/cvocodecchannel.h | 21 ++------- ambed/cvoicepacket.cpp | 15 ------- ambed/cvoicepacket.h | 3 -- 14 files changed, 298 insertions(+), 116 deletions(-) create mode 100644 ambed/cfixedgain.cpp create mode 100644 ambed/cfixedgain.h create mode 100644 ambed/csampleprocessor.h create mode 100644 ambed/csignalprocessor.cpp create mode 100644 ambed/csignalprocessor.h diff --git a/ambed/cagc.cpp b/ambed/cagc.cpp index d5b2105..23ef6e4 100644 --- a/ambed/cagc.cpp +++ b/ambed/cagc.cpp @@ -25,10 +25,9 @@ // Only took the parts we need qnd recoeded it to be close the XLX coding style // https://github.com/jgaeddert/liquid-dsp/blob/master/src/agc/src/agc.c -#include "main.h" #include #include "cagc.h" - +#include "main.h" //////////////////////////////////////////////////////////////////////////////////////// // constructor @@ -63,35 +62,27 @@ float CAGC::GetGain() //////////////////////////////////////////////////////////////////////////////////////// // process -void CAGC::Apply(uint8 * voice, int size) +inline float CAGC::ProcessSample(float input) { - for (int i = 0; i < size; i+=2) - { - //Get the sample - float input = (float)(short)MAKEWORD(voice[i+1], voice[i]); + //apply AGC + // apply gain to input sample + float output = input * m_Gain; - //apply AGC - // apply gain to input sample - float output = input * m_Gain; + // compute output signal energy, scaled to 0 to 1 + float instantEnergy = abs(output) / m_targetEnergy; - // compute output signal energy, scaled to 0 to 1 - float instantEnergy = abs(output) / m_targetEnergy; + // smooth energy estimate using single-pole low-pass filter + m_EnergyPrime = (1.0f - m_Alpha) * m_EnergyPrime + m_Alpha * instantEnergy; - // smooth energy estimate using single-pole low-pass filter - m_EnergyPrime = (1.0f - m_Alpha) * m_EnergyPrime + m_Alpha * instantEnergy; + // update gain according to output energy + if (m_EnergyPrime > 1e-6f) + m_Gain *= exp( -0.5f * m_Alpha * log(m_EnergyPrime) ); - // update gain according to output energy - if (m_EnergyPrime > 1e-6f) - m_Gain *= exp( -0.5f * m_Alpha * log(m_EnergyPrime) ); + // clamp gain + if (m_Gain > m_GainMax) + m_Gain = m_GainMax; + else if(m_Gain < m_GainMin) + m_Gain = m_GainMin; - // clamp gain - if (m_Gain > m_GainMax) - m_Gain = m_GainMax; - else if(m_Gain < m_GainMin) - m_Gain = m_GainMin; - - //write processed sample back - voice[i] = HIBYTE((short)output); - voice[i+1] = LOBYTE((short)output); - } -} \ No newline at end of file + return output; +} diff --git a/ambed/cagc.h b/ambed/cagc.h index c1547e3..db22b22 100644 --- a/ambed/cagc.h +++ b/ambed/cagc.h @@ -28,16 +28,16 @@ #ifndef cagc_h #define cagc_h -#include "main.h" +#include "csampleprocessor.h" -class CAGC +class CAGC : CSampleProcessor { public: //Constructor CAGC(float initialLeveldB); //methods - void Apply(uint8 * voice, int size); + float ProcessSample(float input); float GetGain();//gets current gain private: diff --git a/ambed/cfirfilter.cpp b/ambed/cfirfilter.cpp index 920ffe3..c7bd0ca 100644 --- a/ambed/cfirfilter.cpp +++ b/ambed/cfirfilter.cpp @@ -43,7 +43,7 @@ CFIRFilter::~CFIRFilter() delete[] m_buffer; } -inline float CFIRFilter::Process(float inputSample) +inline float CFIRFilter::ProcessSample(float inputSample) { float output = 0.0f; int iTaps = 0; @@ -66,17 +66,4 @@ inline float CFIRFilter::Process(float inputSample) return output; } -void CFIRFilter::Process(uint8* voice, int length) -{ - for(int i = 0; i < length; i+=2) - { - //Get the sample - float input = (float)(short)MAKEWORD(voice[i+1], voice[i]); - - float output = Process(input); - //write processed sample back - voice[i] = HIBYTE((short)output); - voice[i+1] = LOBYTE((short)output); - } -} diff --git a/ambed/cfirfilter.h b/ambed/cfirfilter.h index 9d1d9c4..43c2c31 100644 --- a/ambed/cfirfilter.h +++ b/ambed/cfirfilter.h @@ -26,7 +26,7 @@ #ifndef cfirfilter_h #define cfirfilter_h -#include "main.h" +#include "csampleprocessor.h" class CFIRFilter { @@ -38,8 +38,7 @@ public : ~CFIRFilter(); // Processing - float Process(float inputSample); - void Process(uint8* voice, int length); + float ProcessSample(float inputSample); private: float* m_taps; diff --git a/ambed/cfixedgain.cpp b/ambed/cfixedgain.cpp new file mode 100644 index 0000000..4e8645c --- /dev/null +++ b/ambed/cfixedgain.cpp @@ -0,0 +1,44 @@ +// +// cfixedgain.cpp +// ambed +// +// Created by Jean-Luc Deltombe (LX3JL) on 28/04/2017. +// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved. +// +// ---------------------------------------------------------------------------- +// This file is part of ambed. +// +// xlxd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// xlxd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Foobar. If not, see . +// ---------------------------------------------------------------------------- +// Geoffrey Merck F4FXL / KC3FRA AGC + +#include "cfixedgain.h" +#include + +//////////////////////////////////////////////////////////////////////////////////////// +// constructor + +CFixedGain::CFixedGain(float gaindB) +{ + m_gaindB = gaindB; + m_gainLinear = pow(10.0f, m_gaindB/20.0f); +} + +//////////////////////////////////////////////////////////////////////////////////////// +// processing + +inline float CFixedGain::ProcessSample(float input) +{ + return input * m_gainLinear; +} \ No newline at end of file diff --git a/ambed/cfixedgain.h b/ambed/cfixedgain.h new file mode 100644 index 0000000..39a2a3f --- /dev/null +++ b/ambed/cfixedgain.h @@ -0,0 +1,45 @@ +// +// cfixedgain.h +// ambed +// +// Created by Jean-Luc Deltombe (LX3JL) on 26/04/2017. +// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved. +// +// ---------------------------------------------------------------------------- +// This file is part of ambed. +// +// xlxd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// xlxd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Foobar. If not, see . +// ---------------------------------------------------------------------------- +// Geoffrey Merck F4FXL / KC3FRA + +#ifndef cfixedgain_h +#define cfixedgain_h + +#include "csampleprocessor.h" + +class CFixedGain : CSampleProcessor +{ +public: + //Constructor + CFixedGain(float gaindB); + + //processing + float ProcessSample(float input); + +private: + float m_gaindB; //gain in dB + float m_gainLinear; //linearized gain +}; + +#endif /* cfixedgain_h */ \ No newline at end of file diff --git a/ambed/csampleprocessor.h b/ambed/csampleprocessor.h new file mode 100644 index 0000000..c9ec932 --- /dev/null +++ b/ambed/csampleprocessor.h @@ -0,0 +1,36 @@ +// +// csampleprocessor.h +// ambed +// +// Created by Jean-Luc Deltombe (LX3JL) on 26/04/2017. +// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved. +// +// ---------------------------------------------------------------------------- +// This file is part of ambed. +// +// xlxd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// xlxd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Foobar. If not, see . +// ---------------------------------------------------------------------------- +// Geoffrey Merck F4FXL / KC3FRA + +#ifndef csampleprocessor_h +#define csampleprocessor_h + +class CSampleProcessor +{ +public: + //processing + virtual float ProcessSample(float input) = 0; +}; + +#endif /* csampleprocessor_h */ \ No newline at end of file diff --git a/ambed/csignalprocessor.cpp b/ambed/csignalprocessor.cpp new file mode 100644 index 0000000..99ed30a --- /dev/null +++ b/ambed/csignalprocessor.cpp @@ -0,0 +1,89 @@ +// +// cagc.cpp +// ambed +// +// Created by Jean-Luc Deltombe (LX3JL) on 28/04/2017. +// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved. +// +// ---------------------------------------------------------------------------- +// This file is part of ambed. +// +// xlxd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by + +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// xlxd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Foobar. If not, see . +// ---------------------------------------------------------------------------- +// Geoffrey Merck F4FXL / KC3FRA AGC + +#include "main.h" +#include "csignalprocessor.h" + +#if USE_AGC == 1 +#include "cagc.h" +#else +#include "cfixedgain.h" +#endif + +#if USE_BANDPASSFILTER == 1 +#include "cfirfilter.h" +#endif + +//////////////////////////////////////////////////////////////////////////////////////// +// constructor + +CSignalProcessor::CSignalProcessor(float gaindB) +{ +#if USE_BANDPASSFILTER + m_sampleProcessors.push_back((CSampleProcessor*)new CFIRFilter(FILTER_TAPS, FILTER_TAPS_LENGTH)); +#endif +#if USE_AGC == 1 + m_sampleProcessors.push_back((CSampleProcessor*)new CAGC(gaindB)); +#else + m_sampleProcessors.push_back((CSampleProcessor*)new CFixedGain(gaindB)); +#endif +} + +//////////////////////////////////////////////////////////////////////////////////////// +// destructor + +CSignalProcessor::~CSignalProcessor() +{ + for(int i = 0; i < m_sampleProcessors.size(); i++) + { + delete m_sampleProcessors[i]; + } +} + +//////////////////////////////////////////////////////////////////////////////////////// +// processing + +void CSignalProcessor::Process(uint8* voice, int length) +{ + float sample; + int i; + auto processorsSize = m_sampleProcessors.size(); + + for(int i = 0; i < length; i += 2) + { + //Get the sample + sample = (float)(short)MAKEWORD(voice[i+1], voice[i]); + + for(i = 0; i < processorsSize; i++) + { + sample = m_sampleProcessors[i]->ProcessSample(sample); + } + + //write processed sample back + voice[i] = HIBYTE((short)sample); + voice[i+1] = LOBYTE((short)sample); + } +} \ No newline at end of file diff --git a/ambed/csignalprocessor.h b/ambed/csignalprocessor.h new file mode 100644 index 0000000..da7cedf --- /dev/null +++ b/ambed/csignalprocessor.h @@ -0,0 +1,48 @@ +// +// csignalprocessor.h +// ambed +// +// Created by Jean-Luc Deltombe (LX3JL) on 26/04/2017. +// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved. +// +// ---------------------------------------------------------------------------- +// This file is part of ambed. +// +// xlxd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// xlxd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Foobar. If not, see . +// ---------------------------------------------------------------------------- +// Geoffrey Merck F4FXL / KC3FRA + +#ifndef csignalprocessor_h +#define csignalprocessor_h + +#include +#include "csampleprocessor.h" + +class CSignalProcessor +{ +public: + //Constructor + CSignalProcessor(float gaindB); + + //Destructor + ~CSignalProcessor(); + + //Processing + void Process(uint8* voice, int length); + +private: + std::vector m_sampleProcessors; +}; + +#endif /* csignalprocessor_h */ \ No newline at end of file diff --git a/ambed/cusb3xxxinterface.cpp b/ambed/cusb3xxxinterface.cpp index 49c1269..c15801c 100644 --- a/ambed/cusb3xxxinterface.cpp +++ b/ambed/cusb3xxxinterface.cpp @@ -152,15 +152,7 @@ void CUsb3xxxInterface::Task(void) { Queue = Channel->GetVoiceQueue(); CVoicePacket *clone = new CVoicePacket(VoicePacket); -#if USE_BANDPASSFILTER - //Aply band pass before AGC to avoidd amplifying signals we do not want - Channel->ApplyFilter(*clone); -#endif -#if USE_AGC == 1 - Channel->ApplyAGC(*clone); -#else - clone->ApplyGain(Channel->GetSpeechGain()); -#endif + Channel->ProcessSignal(*clone); Queue->push(clone); Channel->ReleaseVoiceQueue(); } diff --git a/ambed/cvocodecchannel.cpp b/ambed/cvocodecchannel.cpp index 8ce57f8..7a10d41 100644 --- a/ambed/cvocodecchannel.cpp +++ b/ambed/cvocodecchannel.cpp @@ -38,12 +38,7 @@ CVocodecChannel::CVocodecChannel(CVocodecInterface *InterfaceIn, int iChIn, CVoc m_InterfaceOut = InterfaceOut; m_iChannelOut = iChOut; m_iSpeechGain = iSpeechGain; -#if USE_AGC == 1 - m_AGC = new CAGC((float)iSpeechGain); -#endif -#if USE_BANDPASSFILTER == 1 - m_filter = new CFIRFilter(FILTER_TAPS, FILTER_TAPS_LENGTH); -#endif + m_signalProcessor = new CSignalProcessor((float)m_iSpeechGain); } //////////////////////////////////////////////////////////////////////////////////////// @@ -52,12 +47,7 @@ CVocodecChannel::CVocodecChannel(CVocodecInterface *InterfaceIn, int iChIn, CVoc CVocodecChannel::~CVocodecChannel() { PurgeAllQueues(); -#if USE_AGC == 1 - delete m_AGC; -#endif -#if USE_BANDPASSFILTER == 1 - delete m_filter; -#endif + delete m_signalProcessor; } //////////////////////////////////////////////////////////////////////////////////////// @@ -103,20 +93,14 @@ uint8 CVocodecChannel::GetCodecOut(void) const return m_InterfaceOut->GetChannelCodec(m_iChannelOut); } -#if USE_AGC == 1 -void CVocodecChannel::ApplyAGC(CVoicePacket& voicePacket) -{ - m_AGC->Apply(voicePacket.GetVoice(), voicePacket.GetVoiceSize()); - //std::cout << "Gain : " << m_AGC.GetGain() << "\n"; -} -#endif +//////////////////////////////////////////////////////////////////////////////////////// +// processing -#if USE_BANDPASSFILTER == 1 -void CVocodecChannel::ApplyFilter(CVoicePacket& voicePacket) +void CVocodecChannel::ProcessSignal(CVoicePacket& voicePacket) { - m_filter->Process(voicePacket.GetVoice(), voicePacket.GetVoiceSize()); + m_signalProcessor->Process(voicePacket.GetVoice(), voicePacket.GetVoiceSize()); } -#endif + //////////////////////////////////////////////////////////////////////////////////////// // queues helpers diff --git a/ambed/cvocodecchannel.h b/ambed/cvocodecchannel.h index 735fa00..9726b9d 100644 --- a/ambed/cvocodecchannel.h +++ b/ambed/cvocodecchannel.h @@ -27,12 +27,7 @@ #define cvocodecchannel_h #include "cpacketqueue.h" -#if USE_AGC == 1 -#include "cagc.h" -#endif -#if USE_BANDPASSFILTER == 1 -#include "cfirfilter.h" -#endif +#include "csignalprocessor.h" #include "cvoicepacket.h" //////////////////////////////////////////////////////////////////////////////////////// @@ -62,12 +57,7 @@ public: int GetSpeechGain(void) const { return m_iSpeechGain; } //Processing -#if USE_AGC == 1 - void ApplyAGC(CVoicePacket& voicePacket); -#endif -#if USE_BANDPASSFILTER - void ApplyFilter(CVoicePacket& voicePacket); -#endif + void ProcessSignal(CVoicePacket& voicePacket); // interfaces bool IsInterfaceIn(const CVocodecInterface *interface) { return (interface == m_InterfaceIn); } @@ -108,12 +98,7 @@ protected: int m_iSpeechGain; private: -#if USE_AGC == 1 - CAGC* m_AGC; -#endif -#if USE_BANDPASSFILTER == 1 - CFIRFilter* m_filter; -#endif + CSignalProcessor* m_signalProcessor; }; //////////////////////////////////////////////////////////////////////////////////////// diff --git a/ambed/cvoicepacket.cpp b/ambed/cvoicepacket.cpp index 0fc05f7..3cfb66e 100644 --- a/ambed/cvoicepacket.cpp +++ b/ambed/cvoicepacket.cpp @@ -69,18 +69,3 @@ void CVoicePacket::SetVoice(const uint8 *voice, int size) ::memcpy(m_uiVoice, voice, m_iSize); } - -//////////////////////////////////////////////////////////////////////////////////////// -// gain - -void CVoicePacket::ApplyGain(int dB) -{ - float mult = pow(10, dB/20.0); - for ( int i = 0; i < m_iSize; i += 2 ) - { - float smp = (float)(short)MAKEWORD(m_uiVoice[i+1], m_uiVoice[i]); - smp *= mult; - m_uiVoice[i] = HIBYTE((short)smp); - m_uiVoice[i+1] = LOBYTE((short)smp); - } -} diff --git a/ambed/cvoicepacket.h b/ambed/cvoicepacket.h index 7dbefc3..bb8e6ce 100644 --- a/ambed/cvoicepacket.h +++ b/ambed/cvoicepacket.h @@ -58,9 +58,6 @@ public: // set void SetVoice(const uint8 *, int); - // gain - void ApplyGain(int); - protected: // data int m_iSize; From 6301fe548518955fe2ada97d84b73c632c17a65a Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Sat, 22 Feb 2020 06:20:54 +0100 Subject: [PATCH 25/40] Fixed segmentation fault --- ambed/csignalprocessor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ambed/csignalprocessor.cpp b/ambed/csignalprocessor.cpp index 99ed30a..3f67687 100644 --- a/ambed/csignalprocessor.cpp +++ b/ambed/csignalprocessor.cpp @@ -69,7 +69,7 @@ CSignalProcessor::~CSignalProcessor() void CSignalProcessor::Process(uint8* voice, int length) { float sample; - int i; + int j; auto processorsSize = m_sampleProcessors.size(); for(int i = 0; i < length; i += 2) @@ -77,9 +77,9 @@ void CSignalProcessor::Process(uint8* voice, int length) //Get the sample sample = (float)(short)MAKEWORD(voice[i+1], voice[i]); - for(i = 0; i < processorsSize; i++) + for(j = 0; j < processorsSize; j++) { - sample = m_sampleProcessors[i]->ProcessSample(sample); + sample = m_sampleProcessors[j]->ProcessSample(sample); } //write processed sample back From 5fc2974f9b35dda244c4279c34cb9b686c24c68a Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Sat, 22 Feb 2020 06:44:01 +0100 Subject: [PATCH 26/40] Add missing base class --- ambed/cfirfilter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ambed/cfirfilter.h b/ambed/cfirfilter.h index 43c2c31..52e4b7b 100644 --- a/ambed/cfirfilter.h +++ b/ambed/cfirfilter.h @@ -28,7 +28,7 @@ #include "csampleprocessor.h" -class CFIRFilter +class CFIRFilter : CSampleProcessor { public : //Constructor From 73648794f01cec19e44e62d39ae41ce3177d0d40 Mon Sep 17 00:00:00 2001 From: "Marius Petrescu, YO2LOJ" Date: Sat, 22 Feb 2020 16:38:56 +0200 Subject: [PATCH 27/40] Update and cleanup - created raw socket class - moved udp recv via msg to a derived class - option file read optimized --- src/cg3protocol.cpp | 83 ++++++++-------------- src/cg3protocol.h | 12 ++-- src/crawsocket.cpp | 156 ++++++++++++++++++++++++++++++++++++++++++ src/crawsocket.h | 99 +++++++++++++++++++++++++++ src/cudpmsgsocket.cpp | 102 +++++++++++++++++++++++++++ src/cudpmsgsocket.h | 53 ++++++++++++++ 6 files changed, 447 insertions(+), 58 deletions(-) create mode 100644 src/crawsocket.cpp create mode 100644 src/crawsocket.h create mode 100644 src/cudpmsgsocket.cpp create mode 100644 src/cudpmsgsocket.h diff --git a/src/cg3protocol.cpp b/src/cg3protocol.cpp index ed4de34..053da9d 100644 --- a/src/cg3protocol.cpp +++ b/src/cg3protocol.cpp @@ -69,7 +69,7 @@ bool CG3Protocol::Init(void) std::cout << "Error opening socket on port UDP" << G3_CONFIG_PORT << " on ip " << g_Reflector.GetListenIp() << std::endl; } - ok &= ((m_IcmpRawSocket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) >= 0); + ok &= m_IcmpRawSocket.Open(IPPROTO_ICMP); if ( !ok ) { std::cout << "Error opening raw socket for ICMP" << std::endl; @@ -136,14 +136,10 @@ void CG3Protocol::ConfigThread(CG3Protocol *This) void CG3Protocol::IcmpThread(CG3Protocol *This) { - fcntl(This->m_IcmpRawSocket, F_SETFL, O_NONBLOCK); - while ( !This->m_bStopThread ) { This->IcmpTask(); } - - close(This->m_IcmpRawSocket); } @@ -354,49 +350,27 @@ void CG3Protocol::ConfigTask(void) void CG3Protocol::IcmpTask(void) { - unsigned char buffer[256]; - - struct sockaddr_in sa; - unsigned int sasize = sizeof(sa); + CBuffer Buffer; + CIp Ip; + int iIcmpType; - fd_set FdSet; - struct timeval tv; - - if (m_IcmpRawSocket != -1) + if ((iIcmpType = m_IcmpRawSocket.IcmpReceive(&Buffer, &Ip, 20)) != -1) { - FD_ZERO(&FdSet); - FD_SET(m_IcmpRawSocket, &FdSet); - tv.tv_sec = 0; - tv.tv_usec = 100000; - select(m_IcmpRawSocket + 1, &FdSet, 0, 0, &tv); - - int len = recvfrom(m_IcmpRawSocket, buffer, 255, 0, (struct sockaddr *)&sa, &sasize); - - if (len > 28) + if (iIcmpType == ICMP_DEST_UNREACH) { - struct ip *iph = (struct ip *)buffer; - int iphdrlen = iph->ip_hl * 4; - struct icmp *icmph = (struct icmp *)(buffer + iphdrlen); - - if (icmph->icmp_type == ICMP_DEST_UNREACH) - { - struct ip *remote_iph = (struct ip *)(buffer + iphdrlen + 8); - CClients *clients = g_Reflector.GetClients(); int index = -1; CClient *client = NULL; while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) { - CIp Ip = client->GetIp(); - if (Ip.GetAddr() == remote_iph->ip_dst.s_addr) + CIp ClientIp = client->GetIp(); + if (ClientIp.GetAddr() == Ip.GetAddr()) { clients->RemoveClient(client); } } g_Reflector.ReleaseClients(); - - } } } } @@ -431,7 +405,8 @@ void CG3Protocol::Task(void) { BaseIp = &ClIp; client->Alive(); - // supress host checks + // supress host checks - no ping needed to trigger potential ICMPs + // the regular data flow will do it m_LastKeepaliveTime.Now(); break; } @@ -466,7 +441,7 @@ void CG3Protocol::Task(void) else if ( (LastFrame = IsValidDvLastFramePacket(Buffer)) != NULL ) { //std::cout << "Terminal DV last frame" << std::endl; - + // handle it OnDvLastFramePacketIn(LastFrame, BaseIp); } @@ -484,20 +459,20 @@ void CG3Protocol::Task(void) // handle end of streaming timeout CheckStreamsTimeout(); - + // handle queue from reflector HandleQueue(); - - // keep alive + + // keep alive during idle if needed if ( m_LastKeepaliveTime.DurationSinceNow() > G3_KEEPALIVE_PERIOD ) { // handle keep alives HandleKeepalives(); - + // update time m_LastKeepaliveTime.Now(); - // reload option if needed + // reload option if needed - called once every G3_KEEPALIVE_PERIOD NeedReload(); } } @@ -807,22 +782,22 @@ void CG3Protocol::NeedReload(void) if (m_LastModTime != fileStat.st_mtime) { ReadOptions(); - } - } - // iterate on clients - CClients *clients = g_Reflector.GetClients(); - int index = -1; - CClient *client = NULL; - while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) - { - char module = client->GetReflectorModule(); - if (!strchr(m_Modules.c_str(), module) && !strchr(m_Modules.c_str(), '*')) - { - clients->RemoveClient(client); + // we have new options - iterate on clients for potential removal + CClients *clients = g_Reflector.GetClients(); + int index = -1; + CClient *client = NULL; + while ( (client = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) + { + char module = client->GetReflectorModule(); + if (!strchr(m_Modules.c_str(), module) && !strchr(m_Modules.c_str(), '*')) + { + clients->RemoveClient(client); + } + } + g_Reflector.ReleaseClients(); } } - g_Reflector.ReleaseClients(); } void CG3Protocol::ReadOptions(void) diff --git a/src/cg3protocol.h b/src/cg3protocol.h index 7c0da03..5ffdb79 100644 --- a/src/cg3protocol.h +++ b/src/cg3protocol.h @@ -31,6 +31,8 @@ #include "cdvheaderpacket.h" #include "cdvframepacket.h" #include "cdvlastframepacket.h" +#include "crawsocket.h" +#include "cudpmsgsocket.h" //////////////////////////////////////////////////////////////////////////////////////// @@ -44,9 +46,11 @@ // 2 - Destination request on port UDP 12345 // - Calls to specific callsigns will be accepted for a default module // - Repeater calls will be accepted for local modules -// - All other calls are rehected +// - All other calls are rejected // -// 3 - Actual D-star flow like in Dextra to/from port 40000 (2 distint sockets) +// 3 - Actual D-star flow like in Dextra to/from port 40000 +// 2 distinct sockets where used in the initial protocol +// later firmwares implement a single bidirectional socket // // Alive monitoring is done via a "PING" to remote port 40000. We will get an // ICMP unreachable on terminal mode close or on station shut down if routing is done @@ -122,8 +126,8 @@ protected: // sockets CUdpSocket m_DvOutSocket; CUdpSocket m_PresenceSocket; - CUdpSocket m_ConfigSocket; - int m_IcmpRawSocket; + CUdpMsgSocket m_ConfigSocket; + CRawSocket m_IcmpRawSocket; // optional params uint32 m_GwAddress; diff --git a/src/crawsocket.cpp b/src/crawsocket.cpp new file mode 100644 index 0000000..a30908d --- /dev/null +++ b/src/crawsocket.cpp @@ -0,0 +1,156 @@ +// +// crawsocket.cpp +// xlxd +// +// Created by Marius Petrescu (YO2LOJ) on 22/02/2020. +// Copyright © 2020 Marius Petrescu (YO2LOJ). All rights reserved. +// +// ---------------------------------------------------------------------------- +// This file is part of xlxd. +// +// xlxd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// xlxd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Foobar. If not, see . +// ---------------------------------------------------------------------------- + +#include "main.h" +#include +#include "creflector.h" +#include "crawsocket.h" + + +//////////////////////////////////////////////////////////////////////////////////////// +// constructor + +CRawSocket::CRawSocket() +{ + m_Socket = -1; +} + +//////////////////////////////////////////////////////////////////////////////////////// +// destructor + +CRawSocket::~CRawSocket() +{ + if ( m_Socket != -1 ) + { + Close(); + } +} + +//////////////////////////////////////////////////////////////////////////////////////// +// open & close + +bool CRawSocket::Open(uint16 uiProto) +{ + bool open = false; + int on = 1; + + // create socket + m_Socket = socket(AF_INET,SOCK_RAW,uiProto); + if ( m_Socket != -1 ) + { + fcntl(m_Socket, F_SETFL, O_NONBLOCK); + open = true; + m_Proto = uiProto; + } + + // done + return open; +} + +void CRawSocket::Close(void) +{ + if ( m_Socket != -1 ) + { + close(m_Socket); + m_Socket = -1; + } +} + +//////////////////////////////////////////////////////////////////////////////////////// +// read + +int CRawSocket::Receive(CBuffer *Buffer, CIp *Ip, int timeout) +{ + struct sockaddr_in Sin; + fd_set FdSet; + unsigned int uiFromLen = sizeof(struct sockaddr_in); + int iRecvLen = -1; + struct timeval tv; + + // socket valid ? + if ( m_Socket != -1 ) + { + // allocate buffer + Buffer->resize(UDP_BUFFER_LENMAX); + + // control socket + FD_ZERO(&FdSet); + FD_SET(m_Socket, &FdSet); + tv.tv_sec = timeout / 1000; + tv.tv_usec = (timeout % 1000) * 1000; + select(m_Socket + 1, &FdSet, 0, 0, &tv); + + // read + iRecvLen = (int)recvfrom(m_Socket, + (void *)Buffer->data(), RAW_BUFFER_LENMAX, + 0, (struct sockaddr *)&Sin, &uiFromLen); + + // handle + if ( iRecvLen != -1 ) + { + // adjust buffer size + Buffer->resize(iRecvLen); + + // get IP + Ip->SetSockAddr(&Sin); + } + } + + // done + return iRecvLen; +} + +// protocol specific + +// ICMP + +int CRawSocket::IcmpReceive(CBuffer *Buffer, CIp *Ip, int timeout) +{ + int iIcmpType = -1; + int iRecv; + + if (m_Proto == IPPROTO_ICMP) + { + iRecv = Receive(Buffer, Ip, timeout); + + if (iRecv >= (int)(sizeof(struct ip) + sizeof(struct icmp))) + { + struct ip *iph = (struct ip *)Buffer->data(); + int iphdrlen = iph->ip_hl * 4; + struct icmp *icmph = (struct icmp *)((unsigned char *)iph + iphdrlen); + struct ip *remote_iph = (struct ip *)((unsigned char *)icmph + 8); + + iIcmpType = icmph->icmp_type; + + struct sockaddr_in Sin; + bzero(&Sin, sizeof(Sin)); + Sin.sin_family = AF_INET; + Sin.sin_addr.s_addr = remote_iph->ip_dst.s_addr; + + Ip->SetSockAddr(&Sin); + + } + } + return iIcmpType; +} diff --git a/src/crawsocket.h b/src/crawsocket.h new file mode 100644 index 0000000..1de0f8a --- /dev/null +++ b/src/crawsocket.h @@ -0,0 +1,99 @@ +// +// crawsocket.h +// xlxd +// +// Created by Marius Petrescu (YO2LOJ) on 22/02/2020. +// Copyright © 2020 Marius Petrescu (YO2LOJ). All rights reserved. +// +// ---------------------------------------------------------------------------- +// This file is part of xlxd. +// +// xlxd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// xlxd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Foobar. If not, see . +// ---------------------------------------------------------------------------- + +// Description: +// Raw socket access class with protocol specific + + +#ifndef crawsocket_h +#define crawsocket_h + +#include +#include +#include +#include +#include +#include + +#include +#include +#include "cip.h" +#include "cbuffer.h" + +//////////////////////////////////////////////////////////////////////////////////////// +// define + +#define RAW_BUFFER_LENMAX 65536 + + +//////////////////////////////////////////////////////////////////////////////////////// +// class + +class CRawSocket +{ +public: + // constructor + CRawSocket(); + + // destructor + ~CRawSocket(); + + // open & close + bool Open(uint16); + void Close(void); + int GetSocket(void) { return m_Socket; } + + // read + + // if ETH_P_ALL is used, the received data buffer will hold + // the ethernet header (struct ethhdr) followed by the IP header (struct iphdr), + // the protocol header (e.g tcp, udp, icmp) and the data. + // For specific protocols, the data content may vary depending on the protocol + // Returns the number of received bytes in buffer + + int Receive(CBuffer *, CIp *, int); + + // ICMP receive helper + // parameters: + // buffer - packet receive buffer (starting with ip header) + // ip - remote address (filled in on receive) + // timeout - receive timeout in msec + // return value: + // ICMP type, -1 if nothing was received + + int IcmpReceive(CBuffer *, CIp *, int); + + // write + // no write support - complexity makes it out of scope for now + // to be added if needed + +protected: + // data + int m_Socket; + int m_Proto; + struct sockaddr_in m_SocketAddr; +}; + +//////////////////////////////////////////////////////////////////////////////////////// +#endif /* crawsocket_h */ diff --git a/src/cudpmsgsocket.cpp b/src/cudpmsgsocket.cpp new file mode 100644 index 0000000..daadd17 --- /dev/null +++ b/src/cudpmsgsocket.cpp @@ -0,0 +1,102 @@ +// +// cudpmsgsocket.cpp +// xlxd +// +// Created by Marius Petrescu (YO2LOJ) on 22/02/2020. +// Copyright © 2020 Marius Petrescu (YO2LOJ). All rights reserved. +// +// ---------------------------------------------------------------------------- +// This file is part of xlxd. +// +// xlxd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// xlxd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Foobar. If not, see . +// ---------------------------------------------------------------------------- + +#include "main.h" +#include +#include "cudpmsgsocket.h" + +//////////////////////////////////////////////////////////////////////////////////////// +// read + +int CUdpMsgSocket::Receive(CBuffer *Buffer, CIp *Ip, int timeout) +{ + struct sockaddr_in Sin; + fd_set FdSet; + unsigned int uiFromLen = sizeof(struct sockaddr_in); + int iRecvLen = -1; + struct timeval tv; + + struct msghdr Msg; + struct iovec Iov[1]; + + union { + struct cmsghdr cm; + unsigned char pktinfo_sizer[sizeof(struct cmsghdr) + sizeof(struct in_pktinfo)]; + } Control; + + // socket valid ? + if ( m_Socket != -1 ) + { + // allocate buffer + Buffer->resize(UDP_MSG_BUFFER_LENMAX); + + //prepare msghdr + bzero(&Msg, sizeof(Msg)); + Iov[0].iov_base = Buffer->data(); + Iov[0].iov_len = UDP_MSG_BUFFER_LENMAX; + + bzero(&Sin, sizeof(Sin)); + Msg.msg_name = &Sin; + Msg.msg_namelen = sizeof(Sin); + Msg.msg_iov = Iov; + Msg.msg_iovlen = 1; + Msg.msg_control = &Control; + Msg.msg_controllen = sizeof(Control); + + // control socket + FD_ZERO(&FdSet); + FD_SET(m_Socket, &FdSet); + tv.tv_sec = timeout / 1000; + tv.tv_usec = (timeout % 1000) * 1000; + select(m_Socket + 1, &FdSet, 0, 0, &tv); + + // read + iRecvLen = (int)recvmsg(m_Socket, &Msg, 0); + + // handle + if ( iRecvLen != -1 ) + { + // adjust buffer size + Buffer->resize(iRecvLen); + + // get IP + Ip->SetSockAddr(&Sin); + + // get local IP + struct cmsghdr *Cmsg; + for (Cmsg = CMSG_FIRSTHDR(&Msg); Cmsg != NULL; Cmsg = CMSG_NXTHDR(&Msg, Cmsg)) + { + if (Cmsg->cmsg_level == IPPROTO_IP && Cmsg->cmsg_type == IP_PKTINFO) + { + struct in_pktinfo *PktInfo = (struct in_pktinfo *)CMSG_DATA(Cmsg); + m_LocalAddr.s_addr = PktInfo->ipi_spec_dst.s_addr; + } + } + } + } + + // done + return iRecvLen; +} + diff --git a/src/cudpmsgsocket.h b/src/cudpmsgsocket.h new file mode 100644 index 0000000..657ed21 --- /dev/null +++ b/src/cudpmsgsocket.h @@ -0,0 +1,53 @@ +// +// cudpmsgsocket.h +// xlxd +// +// Created by Marius Petrescu (YO2LOJ) on 22/02/2020. +// Copyright © 2020 Marius Petrescu (YO2LOJ). All rights reserved. +// +// ---------------------------------------------------------------------------- +// This file is part of xlxd. +// +// xlxd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// xlxd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Foobar. If not, see . +// ---------------------------------------------------------------------------- + +// Description: +// Extension of the CUdpSocket class to allow retrieving +// the local target IP for a G3 Terminal mode config request + +#ifndef cudpmsgsocket_h +#define cudpmsgsocket_h + +#include "cudpsocket.h" + +#define UDP_MSG_BUFFER_LENMAX 1024 + +//////////////////////////////////////////////////////////////////////////////////////// +// class + +class CUdpMsgSocket : public CUdpSocket +{ +public: + // read + int Receive(CBuffer *, CIp *, int); + + struct in_addr *GetLocalAddr(void) { return &m_LocalAddr; } + +protected: + // data + struct in_addr m_LocalAddr; +}; + +//////////////////////////////////////////////////////////////////////////////////////// +#endif /* cudpmsgsocket_h */ From a81d1743a8732386f88c6aa417e84cfc43cec60f Mon Sep 17 00:00:00 2001 From: "Marius Petrescu, YO2LOJ" Date: Sat, 22 Feb 2020 16:44:20 +0200 Subject: [PATCH 28/40] Update Revert udpsocket to original --- src/cudpsocket.cpp | 46 +++++++--------------------------------------- src/cudpsocket.h | 2 -- 2 files changed, 7 insertions(+), 41 deletions(-) diff --git a/src/cudpsocket.cpp b/src/cudpsocket.cpp index 3498688..5caa074 100644 --- a/src/cudpsocket.cpp +++ b/src/cudpsocket.cpp @@ -53,7 +53,6 @@ CUdpSocket::~CUdpSocket() bool CUdpSocket::Open(uint16 uiPort) { bool open = false; - int on = 1; // create socket m_Socket = socket(PF_INET,SOCK_DGRAM,0); @@ -68,7 +67,6 @@ bool CUdpSocket::Open(uint16 uiPort) if ( bind(m_Socket, (struct sockaddr *)&m_SocketAddr, sizeof(struct sockaddr_in)) == 0 ) { fcntl(m_Socket, F_SETFL, O_NONBLOCK); - setsockopt(m_Socket, IPPROTO_IP, IP_PKTINFO, (char *)&on, sizeof(on)); open = true; } else @@ -101,34 +99,10 @@ int CUdpSocket::Receive(CBuffer *Buffer, CIp *Ip, int timeout) unsigned int uiFromLen = sizeof(struct sockaddr_in); int iRecvLen = -1; struct timeval tv; - - struct msghdr Msg; - struct iovec Iov[1]; - - union { - struct cmsghdr cm; - unsigned char pktinfo_sizer[sizeof(struct cmsghdr) + sizeof(struct in_pktinfo)]; - } Control; - + // socket valid ? if ( m_Socket != -1 ) { - // allocate buffer - Buffer->resize(UDP_BUFFER_LENMAX); - - //prepare msghdr - bzero(&Msg, sizeof(Msg)); - Iov[0].iov_base = Buffer->data(); - Iov[0].iov_len = UDP_BUFFER_LENMAX; - - bzero(&Sin, sizeof(Sin)); - Msg.msg_name = &Sin; - Msg.msg_namelen = sizeof(Sin); - Msg.msg_iov = Iov; - Msg.msg_iovlen = 1; - Msg.msg_control = &Control; - Msg.msg_controllen = sizeof(Control); - // control socket FD_ZERO(&FdSet); FD_SET(m_Socket, &FdSet); @@ -136,8 +110,13 @@ int CUdpSocket::Receive(CBuffer *Buffer, CIp *Ip, int timeout) tv.tv_usec = (timeout % 1000) * 1000; select(m_Socket + 1, &FdSet, 0, 0, &tv); + // allocate buffer + Buffer->resize(UDP_BUFFER_LENMAX); + // read - iRecvLen = (int)recvmsg(m_Socket, &Msg, 0); + iRecvLen = (int)recvfrom(m_Socket, + (void *)Buffer->data(), UDP_BUFFER_LENMAX, + 0, (struct sockaddr *)&Sin, &uiFromLen); // handle if ( iRecvLen != -1 ) @@ -147,17 +126,6 @@ int CUdpSocket::Receive(CBuffer *Buffer, CIp *Ip, int timeout) // get IP Ip->SetSockAddr(&Sin); - - // get local IP - struct cmsghdr *Cmsg; - for (Cmsg = CMSG_FIRSTHDR(&Msg); Cmsg != NULL; Cmsg = CMSG_NXTHDR(&Msg, Cmsg)) - { - if (Cmsg->cmsg_level == IPPROTO_IP && Cmsg->cmsg_type == IP_PKTINFO) - { - struct in_pktinfo *PktInfo = (struct in_pktinfo *)CMSG_DATA(Cmsg); - m_LocalAddr.s_addr = PktInfo->ipi_spec_dst.s_addr; - } - } } } diff --git a/src/cudpsocket.h b/src/cudpsocket.h index 609450a..e91ed80 100644 --- a/src/cudpsocket.h +++ b/src/cudpsocket.h @@ -68,12 +68,10 @@ public: int Send(const char *, const CIp &); int Send(const char *, const CIp &, uint16); - struct in_addr *GetLocalAddr(void) { return &m_LocalAddr; } protected: // data int m_Socket; struct sockaddr_in m_SocketAddr; - struct in_addr m_LocalAddr; }; //////////////////////////////////////////////////////////////////////////////////////// From 887edaf00d00d217ec5b15c678946db0ac57a07c Mon Sep 17 00:00:00 2001 From: "Marius Petrescu, YO2LOJ" Date: Sat, 22 Feb 2020 17:47:08 +0200 Subject: [PATCH 29/40] UDM Msg update Fix for sockopt on open --- src/cudpmsgsocket.cpp | 14 ++++++++++++++ src/cudpmsgsocket.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/src/cudpmsgsocket.cpp b/src/cudpmsgsocket.cpp index daadd17..45d438d 100644 --- a/src/cudpmsgsocket.cpp +++ b/src/cudpmsgsocket.cpp @@ -26,6 +26,20 @@ #include #include "cudpmsgsocket.h" +//////////////////////////////////////////////////////////////////////////////////////// +// open +bool CUdpMsgSocket::Open(uint16 uiPort) +{ + bool ret; + int on = 1; + + ret = CUdpSocket::Open(uiPort); + setsockopt(m_Socket, IPPROTO_IP, IP_PKTINFO, (char *)&on, sizeof(on)); + + return ret; +} + + //////////////////////////////////////////////////////////////////////////////////////// // read diff --git a/src/cudpmsgsocket.h b/src/cudpmsgsocket.h index 657ed21..f4245c1 100644 --- a/src/cudpmsgsocket.h +++ b/src/cudpmsgsocket.h @@ -39,6 +39,9 @@ class CUdpMsgSocket : public CUdpSocket { public: + // open + bool Open(uint16); + // read int Receive(CBuffer *, CIp *, int); From b8bda1ccc7b6651ae9f77f9661e04f58a8d57168 Mon Sep 17 00:00:00 2001 From: K2IE Date: Wed, 25 Mar 2020 17:54:36 -0400 Subject: [PATCH 30/40] YSF module display fix for U/C only radios such as FT-70DR --- src/cwiresxcmdhandler.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cwiresxcmdhandler.cpp b/src/cwiresxcmdhandler.cpp index b1f272a..0f7af53 100644 --- a/src/cwiresxcmdhandler.cpp +++ b/src/cwiresxcmdhandler.cpp @@ -274,7 +274,7 @@ bool CWiresxCmdHandler::ReplyToWiresxDxReqPacket(const CIp &Ip, const CWiresxInf ::memcpy(data + 36U, item, 5U); // refl->name ::memset(item, ' ', 16U); - ::memcpy(item, "Module", 6U); + ::memcpy(item, "MODULE", 6U); // K2IE fix for U/C only radios item[7] = 'A' + RoomId; ::memcpy(data + 41U, item, 16U); // refl->count @@ -368,7 +368,7 @@ bool CWiresxCmdHandler::ReplyToWiresxAllReqPacket(const CIp &Ip, const CWiresxIn ::memcpy(data + offset + 1U, item, 5U); // refl->name ::memset(item, ' ', 16U); - ::memcpy(item, "Module", 6U); + ::memcpy(item, "MODULE", 6U); // K2IE fix for U/C only radios item[7] = 'A' + RoomId; ::memcpy(data + offset + 6U, item, 16U); // refl->count @@ -465,7 +465,7 @@ bool CWiresxCmdHandler::ReplyToWiresxConnReqPacket(const CIp &Ip, const CWiresxI ::memcpy(data + 36U, item, 5U); // refl->name ::memset(item, ' ', 16U); - ::memcpy(item, "Module", 6U); + ::memcpy(item, "MODULE", 6U); // K2IE fix for U/C only radios item[7] = 'A' + RoomId; ::memcpy(data + 41U, item, 16U); // refl->count From 1770dc188f0aacb08861964f17bba5a6fe52456a Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Sat, 4 Apr 2020 05:35:10 +0200 Subject: [PATCH 31/40] Tryning a different filter, might save some CPU --- ambed/main.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/ambed/main.h b/ambed/main.h index 62fe65b..bdd512f 100644 --- a/ambed/main.h +++ b/ambed/main.h @@ -109,7 +109,7 @@ typedef unsigned int uint; /* pkg load signal; fsamp = 8000; -fcuts = [200 300 3000 3400]; +fcuts = [300 400 3000 3400]; mags = [0 1 0]; devs = [0.2 1 0.2]; @@ -127,13 +127,10 @@ grid #if USE_BANDPASSFILTER == 1 const float FILTER_TAPS[] { --0.0153779f, 0.0114832f, -0.0060703f, -0.0221526f, 0.0085472f, -0.0449400f, --0.0068112f, -0.0307485f, -0.0548559f, -0.0022596f, -0.0879344f, -0.0166698f, --0.0533627f, -0.1015552f, 0.0424673f, -0.2116654f, 0.1267453f, 0.7375000f, -0.1267453f, -0.2116654f, 0.0424673f, -0.1015552f, -0.0533627f, -0.0166698f, --0.0879344f, -0.0022596f, -0.0548559f, -0.0307485f, -0.0068112f, -0.0449400f, -0.0085472f, -0.0221526f, -0.0060703f, 0.0114832f, -0.0153779f }; -#define FILTER_TAPS_LENGTH 35 +-0.05063341f, -0.00060337f, -0.08892498f, -0.02026701f, -0.05940750f, -0.10977641f, 0.03244024f, -0.22304499f, +0.11452865f, 0.72500000f, 0.11452865f, -0.22304499f, 0.03244024f, -0.10977641f, -0.05940750f, -0.02026701f, +-0.08892498f, -0.00060337f, -0.05063341f }; +#define FILTER_TAPS_LENGTH 19 #endif From 042188770b869b18bb2e9138d100ead73f0ee84d Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Sat, 4 Apr 2020 16:16:46 +0200 Subject: [PATCH 32/40] Back to block processing, more efficient and does not introduce delay --- ambed/cagc.cpp | 40 +++++++++++-------- ambed/cagc.h | 6 +-- ambed/cfirfilter.cpp | 38 ++++++++++-------- ambed/cfirfilter.h | 6 +-- ambed/cfixedgain.cpp | 13 +++++- ambed/cfixedgain.h | 6 +-- ...pleprocessor.h => csampleblockprocessor.h} | 10 +++-- ambed/csignalprocessor.cpp | 17 +++++--- ambed/csignalprocessor.h | 4 +- 9 files changed, 84 insertions(+), 56 deletions(-) rename ambed/{csampleprocessor.h => csampleblockprocessor.h} (83%) diff --git a/ambed/cagc.cpp b/ambed/cagc.cpp index 23ef6e4..880323d 100644 --- a/ambed/cagc.cpp +++ b/ambed/cagc.cpp @@ -62,27 +62,33 @@ float CAGC::GetGain() //////////////////////////////////////////////////////////////////////////////////////// // process -inline float CAGC::ProcessSample(float input) +inline void CAGC::ProcessSampleBlock(uint8* voice, int length) { - //apply AGC - // apply gain to input sample - float output = input * m_Gain; + for(int i = 0; i < length; i += 2) + { + float input = (float)(short)MAKEWORD(voice[i+1], voice[i]); + //apply AGC + // apply gain to input sample + float output = input * m_Gain; - // compute output signal energy, scaled to 0 to 1 - float instantEnergy = abs(output) / m_targetEnergy; + // compute output signal energy, scaled to 0 to 1 + float instantEnergy = abs(output) / m_targetEnergy; - // smooth energy estimate using single-pole low-pass filter - m_EnergyPrime = (1.0f - m_Alpha) * m_EnergyPrime + m_Alpha * instantEnergy; + // smooth energy estimate using single-pole low-pass filter + m_EnergyPrime = (1.0f - m_Alpha) * m_EnergyPrime + m_Alpha * instantEnergy; - // update gain according to output energy - if (m_EnergyPrime > 1e-6f) - m_Gain *= exp( -0.5f * m_Alpha * log(m_EnergyPrime) ); + // update gain according to output energy + if (m_EnergyPrime > 1e-6f) + m_Gain *= exp( -0.5f * m_Alpha * log(m_EnergyPrime) ); - // clamp gain - if (m_Gain > m_GainMax) - m_Gain = m_GainMax; - else if(m_Gain < m_GainMin) - m_Gain = m_GainMin; + // clamp gain + if (m_Gain > m_GainMax) + m_Gain = m_GainMax; + else if(m_Gain < m_GainMin) + m_Gain = m_GainMin; - return output; + //write processed sample back + voice[i] = HIBYTE((short)output); + voice[i+1] = LOBYTE((short)output); + } } diff --git a/ambed/cagc.h b/ambed/cagc.h index db22b22..f0ebf75 100644 --- a/ambed/cagc.h +++ b/ambed/cagc.h @@ -28,16 +28,16 @@ #ifndef cagc_h #define cagc_h -#include "csampleprocessor.h" +#include "csampleblockprocessor.h" -class CAGC : CSampleProcessor +class CAGC : CSampleBlockProcessor { public: //Constructor CAGC(float initialLeveldB); //methods - float ProcessSample(float input); + void ProcessSampleBlock(uint8* voice, int length) ; float GetGain();//gets current gain private: diff --git a/ambed/cfirfilter.cpp b/ambed/cfirfilter.cpp index c7bd0ca..1b704c2 100644 --- a/ambed/cfirfilter.cpp +++ b/ambed/cfirfilter.cpp @@ -43,27 +43,33 @@ CFIRFilter::~CFIRFilter() delete[] m_buffer; } -inline float CFIRFilter::ProcessSample(float inputSample) +inline void CFIRFilter::ProcessSampleBlock(uint8* voice, int length) { - float output = 0.0f; - int iTaps = 0; + for(int i = 0; i < length; i++) + { + float input = (float)(short)MAKEWORD(voice[i+1], voice[i]); + float output = 0.0f; + int iTaps = 0; - // Buffer latest sample into delay line - m_buffer[m_currentBufferPosition] = inputSample; + // Buffer latest sample into delay line + m_buffer[m_currentBufferPosition] = input; - for(int i = m_currentBufferPosition; i >= 0; i--) - { - output += m_taps[iTaps++] * m_buffer[i]; - } + for(int i = m_currentBufferPosition; i >= 0; i--) + { + output += m_taps[iTaps++] * m_buffer[i]; + } - for(int i = m_tapsLength - 1; i > m_currentBufferPosition; i--) - { - output += m_taps[iTaps++] * m_buffer[i]; - } - - m_currentBufferPosition = (m_currentBufferPosition + 1) % m_tapsLength; + for(int i = m_tapsLength - 1; i > m_currentBufferPosition; i--) + { + output += m_taps[iTaps++] * m_buffer[i]; + } + + m_currentBufferPosition = (m_currentBufferPosition + 1) % m_tapsLength; - return output; + //write processed sample back + voice[i] = HIBYTE((short)output); + voice[i+1] = LOBYTE((short)output); + } } diff --git a/ambed/cfirfilter.h b/ambed/cfirfilter.h index 52e4b7b..85026fb 100644 --- a/ambed/cfirfilter.h +++ b/ambed/cfirfilter.h @@ -26,9 +26,9 @@ #ifndef cfirfilter_h #define cfirfilter_h -#include "csampleprocessor.h" +#include "csampleblockprocessor.h" -class CFIRFilter : CSampleProcessor +class CFIRFilter : CSampleBlockProcessor { public : //Constructor @@ -38,7 +38,7 @@ public : ~CFIRFilter(); // Processing - float ProcessSample(float inputSample); + void ProcessSampleBlock(uint8* voice, int length); private: float* m_taps; diff --git a/ambed/cfixedgain.cpp b/ambed/cfixedgain.cpp index 4e8645c..55faebc 100644 --- a/ambed/cfixedgain.cpp +++ b/ambed/cfixedgain.cpp @@ -38,7 +38,16 @@ CFixedGain::CFixedGain(float gaindB) //////////////////////////////////////////////////////////////////////////////////////// // processing -inline float CFixedGain::ProcessSample(float input) +inline void CFixedGain::ProcessSampleBlock(uint8* voice, int length) { - return input * m_gainLinear; + for(int i = 0; i < length; i++) + { + float input = (float)(short)MAKEWORD(voice[i+1], voice[i]); + //apply gain + float output = input * m_gainLinear; + + //write processed sample back + voice[i] = HIBYTE((short)output); + voice[i+1] = LOBYTE((short)output); + } } \ No newline at end of file diff --git a/ambed/cfixedgain.h b/ambed/cfixedgain.h index 39a2a3f..eadac47 100644 --- a/ambed/cfixedgain.h +++ b/ambed/cfixedgain.h @@ -26,16 +26,16 @@ #ifndef cfixedgain_h #define cfixedgain_h -#include "csampleprocessor.h" +#include "csampleblockprocessor.h" -class CFixedGain : CSampleProcessor +class CFixedGain : CSampleBlockProcessor { public: //Constructor CFixedGain(float gaindB); //processing - float ProcessSample(float input); + void ProcessSampleBlock(uint8* voice, int length); private: float m_gaindB; //gain in dB diff --git a/ambed/csampleprocessor.h b/ambed/csampleblockprocessor.h similarity index 83% rename from ambed/csampleprocessor.h rename to ambed/csampleblockprocessor.h index c9ec932..2c57f5f 100644 --- a/ambed/csampleprocessor.h +++ b/ambed/csampleblockprocessor.h @@ -23,14 +23,16 @@ // ---------------------------------------------------------------------------- // Geoffrey Merck F4FXL / KC3FRA -#ifndef csampleprocessor_h -#define csampleprocessor_h +#ifndef csamplebloclprocessor_h +#define csamplebloclprocessor_h -class CSampleProcessor +#include "main.h" + +class CSampleBlockProcessor { public: //processing - virtual float ProcessSample(float input) = 0; + virtual void ProcessSampleBlock(uint8* voice, int length) = 0; }; #endif /* csampleprocessor_h */ \ No newline at end of file diff --git a/ambed/csignalprocessor.cpp b/ambed/csignalprocessor.cpp index 3f67687..dbb88c2 100644 --- a/ambed/csignalprocessor.cpp +++ b/ambed/csignalprocessor.cpp @@ -43,12 +43,12 @@ CSignalProcessor::CSignalProcessor(float gaindB) { #if USE_BANDPASSFILTER - m_sampleProcessors.push_back((CSampleProcessor*)new CFIRFilter(FILTER_TAPS, FILTER_TAPS_LENGTH)); + m_sampleProcessors.push_back((CSampleBlockProcessor*)new CFIRFilter(FILTER_TAPS, FILTER_TAPS_LENGTH)); #endif #if USE_AGC == 1 m_sampleProcessors.push_back((CSampleProcessor*)new CAGC(gaindB)); #else - m_sampleProcessors.push_back((CSampleProcessor*)new CFixedGain(gaindB)); + m_sampleProcessors.push_back((CSampleBlockProcessor*)new CFixedGain(gaindB)); #endif } @@ -68,11 +68,16 @@ CSignalProcessor::~CSignalProcessor() void CSignalProcessor::Process(uint8* voice, int length) { - float sample; - int j; + /*float sample; + int j;*/ auto processorsSize = m_sampleProcessors.size(); - for(int i = 0; i < length; i += 2) + for(int j = 0; j < processorsSize; j++) + { + m_sampleProcessors[j]->ProcessSampleBlock(voice, length); + } + + /*for(int i = 0; i < length; i += 2) { //Get the sample sample = (float)(short)MAKEWORD(voice[i+1], voice[i]); @@ -85,5 +90,5 @@ void CSignalProcessor::Process(uint8* voice, int length) //write processed sample back voice[i] = HIBYTE((short)sample); voice[i+1] = LOBYTE((short)sample); - } + }*/ } \ No newline at end of file diff --git a/ambed/csignalprocessor.h b/ambed/csignalprocessor.h index da7cedf..a1081d7 100644 --- a/ambed/csignalprocessor.h +++ b/ambed/csignalprocessor.h @@ -27,7 +27,7 @@ #define csignalprocessor_h #include -#include "csampleprocessor.h" +#include "csampleblockprocessor.h" class CSignalProcessor { @@ -42,7 +42,7 @@ public: void Process(uint8* voice, int length); private: - std::vector m_sampleProcessors; + std::vector m_sampleProcessors; }; #endif /* csignalprocessor_h */ \ No newline at end of file From 5cbb115ddb5a61a35db4ed01c0a31b5b498717a5 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Sat, 4 Apr 2020 16:25:17 +0200 Subject: [PATCH 33/40] Clean up --- ambed/csignalprocessor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ambed/csignalprocessor.cpp b/ambed/csignalprocessor.cpp index dbb88c2..21fba81 100644 --- a/ambed/csignalprocessor.cpp +++ b/ambed/csignalprocessor.cpp @@ -46,7 +46,7 @@ CSignalProcessor::CSignalProcessor(float gaindB) m_sampleProcessors.push_back((CSampleBlockProcessor*)new CFIRFilter(FILTER_TAPS, FILTER_TAPS_LENGTH)); #endif #if USE_AGC == 1 - m_sampleProcessors.push_back((CSampleProcessor*)new CAGC(gaindB)); + m_sampleProcessors.push_back((CSampleBlockProcessor*)new CAGC(gaindB)); #else m_sampleProcessors.push_back((CSampleBlockProcessor*)new CFixedGain(gaindB)); #endif From 11bc4cb7c7f7e55b362ccc1b81837cb784c50182 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Sat, 4 Apr 2020 17:51:08 +0200 Subject: [PATCH 34/40] Correct looping through samples --- ambed/cfirfilter.cpp | 2 +- ambed/cfixedgain.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ambed/cfirfilter.cpp b/ambed/cfirfilter.cpp index 1b704c2..67a0fb1 100644 --- a/ambed/cfirfilter.cpp +++ b/ambed/cfirfilter.cpp @@ -45,7 +45,7 @@ CFIRFilter::~CFIRFilter() inline void CFIRFilter::ProcessSampleBlock(uint8* voice, int length) { - for(int i = 0; i < length; i++) + for(int i = 0; i < length; i += 2) { float input = (float)(short)MAKEWORD(voice[i+1], voice[i]); float output = 0.0f; diff --git a/ambed/cfixedgain.cpp b/ambed/cfixedgain.cpp index 55faebc..600df13 100644 --- a/ambed/cfixedgain.cpp +++ b/ambed/cfixedgain.cpp @@ -40,7 +40,7 @@ CFixedGain::CFixedGain(float gaindB) inline void CFixedGain::ProcessSampleBlock(uint8* voice, int length) { - for(int i = 0; i < length; i++) + for(int i = 0; i < length; i += 2) { float input = (float)(short)MAKEWORD(voice[i+1], voice[i]); //apply gain From 83e7a73f254257290c9201d9578e85f353d0dd60 Mon Sep 17 00:00:00 2001 From: LX3JL Date: Mon, 6 Apr 2020 11:34:11 +0200 Subject: [PATCH 35/40] ambed 1.3.5 Merged F4FXL signal processor --- ambed/main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ambed/main.h b/ambed/main.h index bdd512f..364bb93 100644 --- a/ambed/main.h +++ b/ambed/main.h @@ -49,7 +49,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 -#define VERSION_REVISION 4 +#define VERSION_REVISION 5 // global ------------------------------------------------------ From 2f239d6746ed9b8ea10d43e94ac8f1c94c41ee6f Mon Sep 17 00:00:00 2001 From: LX3JL Date: Tue, 7 Apr 2020 09:51:03 +0200 Subject: [PATCH 36/40] xlxd 2.4.0 Added G3 protocol --- src/main.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main.h b/src/main.h index f7c8226..03c3af1 100644 --- a/src/main.h +++ b/src/main.h @@ -1,4 +1,4 @@ -// +// // main.h // xlxd // @@ -48,8 +48,8 @@ // version ----------------------------------------------------- #define VERSION_MAJOR 2 -#define VERSION_MINOR 3 -#define VERSION_REVISION 5 +#define VERSION_MINOR 4 +#define VERSION_REVISION 0 // global ------------------------------------------------------ @@ -57,12 +57,13 @@ #define JSON_MONITOR // debug ------------------------------------------------------- + //#define DEBUG_NO_ERROR_ON_XML_OPEN_FAIL //#define DEBUG_DUMPFILE // reflector --------------------------------------------------- -#define NB_OF_MODULES 10 +#define NB_OF_MODULES 10 //#define NB_OF_MODULES NB_MODULES_MAX // protocols --------------------------------------------------- From 3271247d471453f1b6271db584d49b0ac1bf7ece Mon Sep 17 00:00:00 2001 From: LX1IQ Date: Tue, 7 Apr 2020 11:53:36 +0200 Subject: [PATCH 37/40] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b61a1dd..ef3f33a 100644 --- a/README.md +++ b/README.md @@ -136,4 +136,4 @@ Pay attention, the XLX Server acts as an YSF Master, which provides 26 wires-x r It has nothing to do with the regular YSFReflector network, hence you don’t need to register your XLX at ysfreflector.de ! -© 2016 Jean-Luc Deltombe and Luc Engelmann LX1IQ +© 2016 Jean-Luc Deltombe (LX3JL) and Luc Engelmann (LX1IQ) From 3ee08dc49ef145a8ce9d3c0b327b81b1b1948257 Mon Sep 17 00:00:00 2001 From: LX1IQ Date: Sun, 12 Apr 2020 09:53:47 +0200 Subject: [PATCH 38/40] Create ambed.service start ambed server as a service on debian --- scripts/ambed.service | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 scripts/ambed.service diff --git a/scripts/ambed.service b/scripts/ambed.service new file mode 100644 index 0000000..8332fae --- /dev/null +++ b/scripts/ambed.service @@ -0,0 +1,15 @@ +[Unit] +Description=AMBE Transcoder Daemon +After=network.target + +[Service] +Type=simple +User=root +Group=root +ExecStartPre=-/sbin/rmmod ftdi_sio +ExecStartPre=-/sbin/rmmod usb_serial +ExecStart=/ambed/ambed 127.0.0.1 +Restart=on-abnormal + +[Install] +WantedBy=multi-user.target From 3713ab92ce86b877da32b9a0d6f2b88dcf1691ba Mon Sep 17 00:00:00 2001 From: LX1IQ Date: Sun, 12 Apr 2020 10:04:44 +0200 Subject: [PATCH 39/40] Create scripts.readme.txt --- scripts/scripts.readme.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 scripts/scripts.readme.txt diff --git a/scripts/scripts.readme.txt b/scripts/scripts.readme.txt new file mode 100644 index 0000000..4008da3 --- /dev/null +++ b/scripts/scripts.readme.txt @@ -0,0 +1,20 @@ +************************************************* +*copy xlxd into /etc.init.d/ +*copy ambed.service into /etc/systemd/system/ +* +************************************************* +* xlxd executable must be in /xlxd/ folder +* ambed executable must be in /ambed/ folder +* +************************************************* +* possible options: +* +* #systemctl start ambed /starts ambed +* #systemctl status ambed /shows status of ambed +* #systemctl stop ambed /stops ambed +* # systemctl restart ambed /restarts ambed +* +* automatically get it to start on boot: +* #systemctl enable ambed +* +************************************************* From 3c9549e11ae02deb075258b535a67e5690f48dfc Mon Sep 17 00:00:00 2001 From: 9W2LWK Date: Fri, 17 Apr 2020 15:08:28 +0800 Subject: [PATCH 40/40] Update country.csv --- dashboard2/pgs/country.csv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dashboard2/pgs/country.csv b/dashboard2/pgs/country.csv index 5038fd9..9847c24 100755 --- a/dashboard2/pgs/country.csv +++ b/dashboard2/pgs/country.csv @@ -82,7 +82,7 @@ Djibouti;DJ;J2 Dodecanese;GR;SV5-J45 Dominica;DM;J7 Dominican Republic;DO;HI -East Malaysia;MY;9M6-9M8 +East Malaysia;MY;9M6-9M8-9W6-9W8 Easter Island;CL;CE0 Eastern Kiribati (Line Island);KI;T32 Ecuador;EC;HC-HD @@ -299,7 +299,7 @@ Virgin Islands U.S.;VI;KP2 Wake Island;US;KH9 Wales;WL;2W-GC-GW-MW Wallis and Futuna;WF;FW -West Malaysia;MY;9M2-9M4-9W2 +West Malaysia;MY;9M2-9M4-9W2-9W4 Western Kiribati (Gilbert Island);KI;T30 Western Sahara;EH;S0 Willis Island;AU;VK9W
+ + + '; + if (($_SESSION['FilterModule'] != null) || ($_SESSION['FilterCallSign'] != null) || ($_SESSION['FilterProtocol'] != null)) { + echo ' + '; + } + echo ' + + +
+
+ + + +
+
Disable filters +
+ + + +
+
+
+ + + +
+
+
# Flag
'.($i+1).''; - list ($Flag, $Name) = $Reflector->GetFlag($Reflector->Nodes[$i]->GetCallSign()); - if (file_exists("./img/flags/".$Flag.".png")) { - echo ''.$Name.''.$Name.''; - } - echo 'Nodes[$i]->GetSuffix(); - echo '" class="pl" target="_blank">'.$Reflector->Nodes[$i]->GetCallSign(); - if ($Reflector->Nodes[$i]->GetSuffix() != "") { echo '-'.$Reflector->Nodes[$i]->GetSuffix(); } - echo ''; - if (($Reflector->Nodes[$i]->GetPrefix() == 'REF') || ($Reflector->Nodes[$i]->GetPrefix() == 'XRF')) { - switch ($Reflector->Nodes[$i]->GetPrefix()) { - case 'REF' : echo 'REF-Link'; break; - case 'XRF' : echo 'XRF-Link'; break; + $ShowThisStation = true; + if ($PageOptions['UserPage']['ShowFilter']) { + $CS = true; + if ($_SESSION['FilterCallSign'] != null) { + if (!fnmatch($_SESSION['FilterCallSign'], $Reflector->Nodes[$i]->GetCallSign(), FNM_CASEFOLD)) { + $CS = false; + } } - } - else { - switch ($Reflector->Nodes[$i]->GetSuffix()) { - case 'A' : echo '23cm'; break; - case 'B' : echo '70cm'; break; - case 'C' : echo '2m'; break; - case 'D' : echo 'Dongle'; break; - case 'G' : echo 'Internet-Gateway'; break; - default : echo ''; + $MO = true; + if ($_SESSION['FilterModule'] != null) { + if (trim(strtolower($_SESSION['FilterModule'])) != strtolower($Reflector->Nodes[$i]->GetLinkedModule())) { + $MO = false; + } + } + $PR = true; + if ($_SESSION['FilterProtocol'] != null) { + if (trim(strtolower($_SESSION['FilterProtocol'])) != strtolower($Reflector->Nodes[$i]->GetProtocol())) { + $PR = false; + } } + + $ShowThisStation = ($CS && $MO && $PR); } - echo ''.date("d.m.Y H:i", $Reflector->Nodes[$i]->GetLastHeardTime()).''.FormatSeconds(time()-$Reflector->Nodes[$i]->GetConnectTime()).' s'.$Reflector->Nodes[$i]->GetProtocol().''.$Reflector->Nodes[$i]->GetLinkedModule().''; - $Bytes = explode(".", $Reflector->Nodes[$i]->GetIP()); - if ($Bytes !== false && count($Bytes) == 4) { - switch ($PageOptions['RepeatersPage']['IPModus']) { - case 'ShowLast1ByteOfIP' : echo $PageOptions['RepeatersPage']['MasqueradeCharacter'].'.'.$PageOptions['RepeatersPage']['MasqueradeCharacter'].'.'.$PageOptions['RepeatersPage']['MasqueradeCharacter'].'.'.$Bytes[3]; break; - case 'ShowLast2ByteOfIP' : echo $PageOptions['RepeatersPage']['MasqueradeCharacter'].'.'.$PageOptions['RepeatersPage']['MasqueradeCharacter'].'.'.$Bytes[2].'.'.$Bytes[3]; break; - case 'ShowLast3ByteOfIP' : echo $PageOptions['RepeatersPage']['MasqueradeCharacter'].'.'.$Bytes[1].'.'.$Bytes[2].'.'.$Bytes[3]; break; - default : echo $Reflector->Nodes[$i]->GetIP(); +
'.($i+1).''; + list ($Flag, $Name) = $Reflector->GetFlag($Reflector->Nodes[$i]->GetCallSign()); + if (file_exists("./img/flags/".$Flag.".png")) { + echo ''.$Name.''.$Name.''; + } + echo 'Nodes[$i]->GetSuffix(); + echo '" class="pl" target="_blank">'.$Reflector->Nodes[$i]->GetCallSign(); + if ($Reflector->Nodes[$i]->GetSuffix() != "") { echo '-'.$Reflector->Nodes[$i]->GetSuffix(); } + echo ''; + if (($Reflector->Nodes[$i]->GetPrefix() == 'REF') || ($Reflector->Nodes[$i]->GetPrefix() == 'XRF')) { + switch ($Reflector->Nodes[$i]->GetPrefix()) { + case 'REF' : echo 'REF-Link'; break; + case 'XRF' : echo 'XRF-Link'; break; } } - echo ''.date("d.m.Y H:i", $Reflector->Nodes[$i]->GetLastHeardTime()).''.FormatSeconds(time()-$Reflector->Nodes[$i]->GetConnectTime()).' s'.$Reflector->Nodes[$i]->GetProtocol().''.$Reflector->Nodes[$i]->GetLinkedModule().''; + $Bytes = explode(".", $Reflector->Nodes[$i]->GetIP()); + if ($Bytes !== false && count($Bytes) == 4) { + switch ($PageOptions['RepeatersPage']['IPModus']) { + case 'ShowLast1ByteOfIP' : echo $PageOptions['RepeatersPage']['MasqueradeCharacter'].'.'.$PageOptions['RepeatersPage']['MasqueradeCharacter'].'.'.$PageOptions['RepeatersPage']['MasqueradeCharacter'].'.'.$Bytes[3]; break; + case 'ShowLast2ByteOfIP' : echo $PageOptions['RepeatersPage']['MasqueradeCharacter'].'.'.$PageOptions['RepeatersPage']['MasqueradeCharacter'].'.'.$Bytes[2].'.'.$Bytes[3]; break; + case 'ShowLast3ByteOfIP' : echo $PageOptions['RepeatersPage']['MasqueradeCharacter'].'.'.$Bytes[1].'.'.$Bytes[2].'.'.$Bytes[3]; break; + default : echo $Reflector->Nodes[$i]->GetIP(); + } + } + echo '