From 837d13d9b43effd1b952662b5ec9dd7d952aa412 Mon Sep 17 00:00:00 2001 From: Luca Marchesano Date: Mon, 19 Nov 2018 12:42:43 +0100 Subject: [PATCH] Added startup systemd, change compiling setting -Added compiling optimization -Fix warning message compiling with -Wall -Added file startup systemd -Updated file README.md --- README.md | 94 ++++++++++++++------------- Systemd/ambed.service | 19 ++++++ Systemd/ambed.timer | 5 ++ Systemd/xlxd | 74 ++++++++++++++++++++++ Systemd/xlxd.service | 15 +++++ Systemd/xlxd.timer | 5 ++ ambed/README.md | 115 ++++++++++++++++++++++++++++++++++ ambed/cbuffer.cpp | 8 +-- ambed/ccallsign.cpp | 8 +-- ambed/ccontroller.cpp | 8 +-- ambed/cusb3000interface.cpp | 4 +- ambed/cusb3003hrinterface.cpp | 6 +- ambed/cusb3003interface.cpp | 4 +- ambed/cusb3xxxinterface.cpp | 8 +-- ambed/cvocodecs.cpp | 24 +++---- ambed/main.h | 4 +- ambed/makefile | 12 ++-- src/cbmpeer.cpp | 4 +- src/cbptc19696.cpp | 10 ++- src/cbptc19696.h | 6 +- src/cbuffer.cpp | 8 +-- src/ccallsign.cpp | 12 ++-- src/ccallsignlist.cpp | 10 +-- src/ccallsignlistitem.cpp | 6 +- src/cclients.cpp | 28 ++++----- src/cdmrmmdvmprotocol.cpp | 2 +- src/cdmrplusprotocol.cpp | 4 +- src/cgolay2087.cpp | 8 +-- src/cpeer.cpp | 10 +-- src/cpeers.cpp | 16 ++--- src/cprotocol.cpp | 4 +- src/cprotocols.cpp | 6 +- src/cqr1676.cpp | 8 +-- src/creflector.cpp | 4 +- src/ctranscoder.cpp | 6 +- src/cusers.cpp | 2 +- src/cxlxpeer.cpp | 4 +- src/cxlxprotocol.cpp | 6 +- src/main.h | 4 +- src/makefile | 12 ++-- 40 files changed, 421 insertions(+), 172 deletions(-) create mode 100644 Systemd/ambed.service create mode 100644 Systemd/ambed.timer create mode 100644 Systemd/xlxd create mode 100644 Systemd/xlxd.service create mode 100644 Systemd/xlxd.timer create mode 100644 ambed/README.md diff --git a/README.md b/README.md index a82d2f1..9331d7c 100644 --- a/README.md +++ b/README.md @@ -1,112 +1,122 @@ # Copyright -© 2016 Luc Engelmann LX1IQ - +© 2016 Luc Engelmann LX1IQ The XLX Multiprotocol Gateway Reflector Server is part of the software system for the D-Star Network. The sources are published under GPL Licenses. - + # Usage - + The packages which are described in this document are designed to install server software which is used for the D-Star network infrastructure. It requires a 24/7 internet connection which can support 20 voice streams or more to connect repeaters and hotspot dongles!! - -- The server requires a fix IP-address ! -- The public IP address should have a DNS record which must be published in the -common host files. - + + - The server requires a fix IP-address ! + - The public IP address should have a DNS record which must be published in the + common host files. + If you want to run this software please make sure that you can provide this service free of charge, like the developer team provides the software and the network infrastructure free of charge! - +Path file running xlxd are: +``` +Exec /xlxd +Config file /xlxd +``` # Requirements The software packages for Linux are tested on Debian7 (Wheezy) 32 and 64bit or newer. Raspbian will work but is not recommended. Please use the stable version listed above, we cannot support others. - + # Installation -## Debian 7 (Wheezy) 32 and 64bit - +## Debian 7 and up 32 and 64bit ###### After a clean installation of debian make sure to run update and upgrade ``` # apt-get update # apt-get upgrade -``` + ``` ###### Install Git ``` # apt-get install git git-core ``` -###### Install webserver with PHP5 support +###### Install webserver with PHP5 support Debian 7 and 8 ``` # apt-get install apache2 php5 ``` - +###### Install webserver with PHP7 support Debian 9 (Stretch) +``` +# apt-get install apache2 php +``` ###### Install g++ compiler ``` - # apt-get install build-essential - # apt-get install g++-4.7 (skip this step on Debian 8.x) -``` +For Debian 8 and 9 +# apt-get install build-essential -###### Download and compile the XLX sources +For Debian 7 +# apt-get install g++-4.7 ``` +###### Download and compile the XLX sources + ``` # git clone https://github.com/LX3JL/xlxd.git # cd xlxd/src/ # make clean # make # make install -``` - + ``` ###### Copy startup script "xlxd" to /etc/init.d ``` -# cp ~/xlxd/scripts/xlxd /etc/init.d/xlxd +# cp ~/xlxd/Systemd/xlxd /etc/init.d/xlxd ``` - ###### Adapt the default startup parameters to your needs ``` # pico /etc/init.d/xlxd ``` -###### Download the dmrid.dat from the XLXAPI server to your xlxd folder -``` -# wget -O /xlxd/dmrid.dat http://xlxapi.rlx.lu/api/exportdmr.php -``` - -###### Check your FTDI driver and install the AMBE service according to the readme in AMBEd +###### Crontab the dmrid.dat from the XLXAPI server to your xlxd folder ``` +Open file: +# nano /etc/crontab +Add at the bottom of the file +0 0 * * * root wget -O /xlxd/dmrid.dat http://xlxapi.rlx.lu/api/exportdmr.php ``` - ###### Last step is to declare the service for automatic startup and shutdown ``` +For Debian 7 # update-rc.d xlxd defaults -``` +For Debian 8 and up +# cp ~/xlxd/Systemd/xlxd.* /lib/systemd/system/ +# systemctl daemon-reload +# systemctl enable xlxd.timer +``` ###### Start or stop the service with ``` # service xlxd start # service xlxd stop +# service xlxd restart +# service xlxd status ``` - ###### Copy dashboard to /var/www ``` +Debian 7 # cp -r ~/xlxd/dashboard /var/www/db -``` +Debian 8 and up +# cp -r ~/xlxd/dashboard /var/www/html/db +``` ###### Give the dashboard read access to the server log file -``` + ``` # chmod +r /var/log/messages -``` - + ``` ###### Reboot server to see if the auto-start is working -``` + ``` # reboot -``` - + ``` # Firewall settings # - + XLX Server requires the following ports to be open and forwarded properly for in- and outgoing network traffic: - TCP port 80 (http) optional TCP port 443 (https) - TCP port 8080 (RepNet) optional @@ -121,4 +131,4 @@ XLX Server requires the following ports to be open and forwarded properly for in - UDP port 10100 (AMBE controller port) - UDP port 10101 - 10199 (AMBE transcoding port) -© 2016 Luc Engelmann LX1IQ +© 2016 Luc Engelmann LX1IQ diff --git a/Systemd/ambed.service b/Systemd/ambed.service new file mode 100644 index 0000000..481ac3f --- /dev/null +++ b/Systemd/ambed.service @@ -0,0 +1,19 @@ +[Unit] +Description=Ambed Service +Requires=network.target +After=systemd-user-session.service network.target + +[Service] +Type=simple +Restart=always +RestartSec=3 +StandardOutput=null +WorkingDirectory=/ambed +ExecStartPre=-/sbin/rmmod ftdi_sio +ExecStartPre=-/sbin/rmmod usbserial +ExecStart=/ambed/ambed 127.0.0.1 +ExecReload=/bin/kill -HUP $MAINPID +KillMode=process + +[Install] +WantedBy=multi-user.target diff --git a/Systemd/ambed.timer b/Systemd/ambed.timer new file mode 100644 index 0000000..af9e527 --- /dev/null +++ b/Systemd/ambed.timer @@ -0,0 +1,5 @@ +[Timer] +OnStartupSec=10 + +[Install] +WantedBy=multi-user.target diff --git a/Systemd/xlxd b/Systemd/xlxd new file mode 100644 index 0000000..6fb788d --- /dev/null +++ b/Systemd/xlxd @@ -0,0 +1,74 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: xlxd service +# Processname: xlxd +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: starts the dstar reflector as a linux service +# Description: dstar reflector by LX3JL +# start script by LX1IQ +### END INIT INFO + + +PATH=/sbin:/bin:/usr/sbin:/usr/bin + +. /lib/lsb/init-functions + +# change below settings according to your system +NAME="xlxd" +DAEMON="/xlxd/xlxd" +ARGUMENTS="XLX270 158.64.26.132 127.0.0.1" +PIDFILE="/var/log/xlxd.pid" +USER=root +GROUP=root + +[ -f $DAEMON ] || exit 0 + +start () { +# start daemon + echo -n "Starting $NAME: " + start-stop-daemon --start --exec $DAEMON --chuid $USER:$GROUP --background -- $ARGUMENTS + RETVAL=$? + echo + sleep 4 + echo `pidof xlxd` > $PIDFILE + return $RETVAL +} + +stop () { + echo -n "Stopping $NAME: " + start-stop-daemon --stop --pidfile $PIDFILE + RETVAL=$? + echo +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + stop + start + ;; + status) + PIDID=`pidof xlxd` + echo $DAEMON $NAME : + if [ $PIDID -gt 0 ] 2>/dev/null; + then + echo running + else + echo not running + fi + + ;; + *) + echo "Usage: $0 {start|stop|restart|status}" + exit 1 +esac + +exit 0 diff --git a/Systemd/xlxd.service b/Systemd/xlxd.service new file mode 100644 index 0000000..6e1d651 --- /dev/null +++ b/Systemd/xlxd.service @@ -0,0 +1,15 @@ +[Unit] +Description=XLXD Server +Requires=network.target +After=systemd-user-session.service network.target + +[Service] +Type=forking +ExecStart=/etc/init.d/xlxd start +ExecReload=/bin/kill -HUP $MAINPID +KillMode=process +Restart=on-failure + +[Install] +WantedBy=multi-user.target +# Alias=xlxd.service diff --git a/Systemd/xlxd.timer b/Systemd/xlxd.timer new file mode 100644 index 0000000..169d0ca --- /dev/null +++ b/Systemd/xlxd.timer @@ -0,0 +1,5 @@ +[Timer] +OnStartupSec=40 + +[Install] +WantedBy=multi-user.target diff --git a/ambed/README.md b/ambed/README.md new file mode 100644 index 0000000..5c16699 --- /dev/null +++ b/ambed/README.md @@ -0,0 +1,115 @@ + + Created by Jean-Luc Deltombe (LX3JL) on 09/07/2017. + Copyright © 2017 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 . + ---------------------------------------------------------------------------- + +VERSION: 1.3.2 +Hardware compatibility. +====================== +This version of ambed is compatible with: +- DF2ET's AMBE3003USB opensource device (https://github.com/phl0/AMBE3003USB) +- LX3JL's USB-3006 opensource device (https://github.com/lx3jl/usb-3006) +- DVSI's USB-3000 device +- DVSI's USB-3003 device +- DVSI's USB-3012 device +- NWDR's ThumbDV device +- NWDR's ThumbDV-3 device +- DVMEGA AMBE3000 device +- DVMEGA AMBE3003 device +- TEAM6160 AMBE3000 device +Available transcoding channels per device: +``` +device DMR->DSTAR DSTAR->DMR Nb Of concurrent channels +------------------------------------------------------------------------------------------------- +3000(pair) 1 1 2 +3003 1 1 2 +3003(pair) 3 3 4 +3003-3000(pair) 2 2 not tested +3006 3 3 6 +3012 6 6 12 +``` +Multiple devices can be used at the same time. +You need to use 3000 by pairs or paired with a 3003 +Do not to use USB hubs as they have proven making +system behaviour unreliable. +Instructions: +============= +1) Installation of FTDI drivers +Download from FTDI web site the latest D2XX driver package http://www.ftdichip.com/Drivers/D2XX.htm +Follow FTDI provided documentation for installation and testing of the drivers. +For macchine x86 x64 +``` +# wget http://www.ftdichip.com/Drivers/D2XX/Linux/libftd2xx-i386-1.4.8.gz +# wget http://www.ftdichip.com/Drivers/D2XX/Linux/libftd2xx-x86_64-1.4.8.gz +``` +For raspberry ARMv6 ARMv7 +``` +# wget http://www.ftdichip.com/Drivers/D2XX/Linux/libftd2xx-arm-v6-hf-1.4.8.gz +# wget http://www.ftdichip.com/Drivers/D2XX/Linux/libftd2xx-arm-v7-hf-1.4.8.gz +``` +Extract files +``` +# tar xfvz libftd2xx-XXX-1.4.8.tgz +# cd /release/build +# cp libftd2xx.* /usr/local/lib +# chmod 0755 /usr/local/lib/libftd2xx.so.1.4.8 +# ln -sf /usr/local/lib/libftd2xx.so.1.4.8 /usr/local/lib/libftd2xx.s +``` +2) installation of g++ compiler +``` +# apt-get install build-essential +``` +Only Debian 7 +``` +# apt-get install g++-4.7 +``` +2) download and compile ambed +``` +# git clone https://github.com/LX3JL/xlxd.git +# cd xlxd/ambed/ +# make clean +# make +# make install +``` +Remove module kernel +``` +# rmmod ftdi_sio +# rmmod usbserial +``` +3) configuring ambed startup service +``` +# cp -r ~/xlxd/Systemd/ambed.* /lib/systemd/system/ +Edit file ambed.service for change IP if xlxd run other PC +N.B If ambed is running on same machine than xlxd, use default 127.0.0.1 +otherwise use the machine own IPs +# pico /lib/systemd/system/ambed.service +Update sevice list +# systemctl daemon-reload +Enable service autostart +# systemctl enable ambed.timer +``` +4) running ambed +note: +Due to specific FTDI driver implementation, ambed must be running +with root privilege, and cannot be run as a daemon. +So ambed will display the information and error messages in the +terminal it has been started from +Command of start/stop/restart/status service +``` +# service ambed start +# service ambed stop +# service ambed restart +# service ambed status +``` diff --git a/ambed/cbuffer.cpp b/ambed/cbuffer.cpp index 550c3df..78f5d0b 100644 --- a/ambed/cbuffer.cpp +++ b/ambed/cbuffer.cpp @@ -120,7 +120,7 @@ void CBuffer::ReplaceAt(int i, uint32 ui) void CBuffer::ReplaceAt(int i, const uint8 *ptr, int len) { - if ( size() < (i+len) ) + if ( size() < (size_t)(i+len) ) { resize(i+len); } @@ -133,7 +133,7 @@ void CBuffer::ReplaceAt(int i, const uint8 *ptr, int len) int CBuffer::Compare(uint8 *buffer, int len) const { int result = -1; - if ( size() >= len ) + if ( size() >= (size_t)len ) { result = ::memcmp(data(), buffer, len); } @@ -143,7 +143,7 @@ int CBuffer::Compare(uint8 *buffer, int len) const int CBuffer::Compare(uint8 *buffer, int off, int len) const { int result = -1; - if ( size() >= (off+len) ) + if ( size() >= (size_t)(off+len) ) { result = ::memcmp(&(data()[off]), buffer, len); } @@ -182,7 +182,7 @@ CBuffer::operator const char *() const void CBuffer::DebugDump(std::ofstream &debugout) { - for ( int i = 0; i < size(); i++ ) + for ( size_t i = 0; i < size(); i++ ) { char sz[16]; sprintf(sz, "%02X", data()[i]); diff --git a/ambed/ccallsign.cpp b/ambed/ccallsign.cpp index aa81c9d..5698d48 100644 --- a/ambed/ccallsign.cpp +++ b/ambed/ccallsign.cpp @@ -93,7 +93,7 @@ void CCallsign::SetCallsign(const uint8 *buffer, int len) // set callsign ::memset(m_Callsign, ' ', sizeof(m_Callsign)); ::memcpy(m_Callsign, buffer, MIN(len, sizeof(m_Callsign))); - for ( int i = 0; i < sizeof(m_Callsign); i++ ) + for ( size_t i = 0; i < sizeof(m_Callsign); i++ ) { if ( m_Callsign[i] == 0 ) { @@ -108,7 +108,7 @@ void CCallsign::SetCallsign(const uint8 *buffer, int len) void CCallsign::PatchCallsign(int off, const uint8 *patch, int len) { - if ( off < sizeof(m_Callsign) ) + if ( (size_t)off < sizeof(m_Callsign) ) { ::memcpy(m_Callsign, patch, MIN(len, sizeof(m_Callsign) - off)); } @@ -125,7 +125,7 @@ void CCallsign::GetCallsign(uint8 *buffer) const void CCallsign::GetCallsignString(char *sz) const { - int i; + size_t i; for ( i = 0; (i < sizeof(m_Callsign)) && (m_Callsign[i] != ' '); i++ ) { sz[i] = m_Callsign[i]; @@ -146,7 +146,7 @@ bool CCallsign::HasSameCallsignWithWildcard(const CCallsign &callsign) const bool same = true; bool done = false; - for ( int i = 0; (i < sizeof(m_Callsign)) && same && !done; i++ ) + for ( size_t i = 0; (i < sizeof(m_Callsign)) && same && !done; i++ ) { if ( !(done = ((m_Callsign[i] == '*') || (callsign[i] == '*'))) ) { diff --git a/ambed/ccontroller.cpp b/ambed/ccontroller.cpp index d6039e8..5748b01 100644 --- a/ambed/ccontroller.cpp +++ b/ambed/ccontroller.cpp @@ -50,7 +50,7 @@ CController::~CController() // close all streams m_Mutex.lock(); { - for ( int i = 0; i < m_Streams.size(); i++ ) + for ( size_t i = 0; i < m_Streams.size(); i++ ) { delete m_Streams[i]; } @@ -178,7 +178,7 @@ void CController::Task(void) // any inactive streams? Lock(); { - for ( int i = 0; (i < m_Streams.size()) && !timeout; i++ ) + for ( size_t i = 0; (i < m_Streams.size()) && !timeout; i++ ) { if ( !(m_Streams[i]->IsActive()) ) { @@ -234,7 +234,7 @@ void CController::CloseStream(CStream *stream) { // look for the stream bool found = false; - for ( int i = 0; (i < m_Streams.size()) && !found; i++ ) + for ( size_t i = 0; (i < m_Streams.size()) && !found; i++ ) { // compare object pointers if ( (m_Streams[i]) == stream ) @@ -258,7 +258,7 @@ void CController::CloseStream(uint16 StreamId) { // look for the stream bool found = false; - for ( int i = 0; (i < m_Streams.size()) && !found; i++ ) + for ( size_t i = 0; (i < m_Streams.size()) && !found; i++ ) { // compare object pointers if ( (m_Streams[i]->GetId()) == StreamId ) diff --git a/ambed/cusb3000interface.cpp b/ambed/cusb3000interface.cpp index b340cba..5712762 100644 --- a/ambed/cusb3000interface.cpp +++ b/ambed/cusb3000interface.cpp @@ -79,7 +79,7 @@ CVocodecChannel *CUsb3000Interface::GetChannelWithChannelIn(int iCh) { CVocodecChannel *Channel = NULL; bool done = false; - for ( int i = 0; (i < m_Channels.size()) && !done; i++ ) + for ( size_t i = 0; (i < m_Channels.size()) && !done; i++ ) { if ( iCh == 0 ) { @@ -97,7 +97,7 @@ CVocodecChannel *CUsb3000Interface::GetChannelWithChannelOut(int iCh) { CVocodecChannel *Channel = NULL; bool done = false; - for ( int i = 0; (i < m_Channels.size()) && !done; i++ ) + for ( size_t i = 0; (i < m_Channels.size()) && !done; i++ ) { if ( (m_Channels[i]->GetChannelOut() == iCh) && (m_Channels[i]->IsInterfaceOut(this)) ) { diff --git a/ambed/cusb3003hrinterface.cpp b/ambed/cusb3003hrinterface.cpp index f096d85..e4767b3 100644 --- a/ambed/cusb3003hrinterface.cpp +++ b/ambed/cusb3003hrinterface.cpp @@ -42,15 +42,15 @@ CUsb3003HRInterface::CUsb3003HRInterface(uint32 uiVid, uint32 uiPid, const char bool CUsb3003HRInterface::ResetDevice(void) { bool ok = false; - FT_STATUS ftStatus; + //FT_STATUS ftStatus; //*** variable ‘ftStatus’ set but not used *** int len; char rxpacket[100]; //if the device is a USB-3003, it supports reset via UART break signal //printf("reset via uart break...\n"); - ftStatus = FT_SetBreakOn( m_FtdiHandle ); + //ftStatus = FT_SetBreakOn( m_FtdiHandle ); CTimePoint::TaskSleepFor(10); - ftStatus = FT_SetBreakOff( m_FtdiHandle ); + //ftStatus = FT_SetBreakOff( m_FtdiHandle ); //CTimePoint::TaskSleepFor(10); len = FTDI_read_packet( m_FtdiHandle, rxpacket, sizeof(rxpacket) ); diff --git a/ambed/cusb3003interface.cpp b/ambed/cusb3003interface.cpp index 471dc39..a499375 100644 --- a/ambed/cusb3003interface.cpp +++ b/ambed/cusb3003interface.cpp @@ -88,7 +88,7 @@ CVocodecChannel *CUsb3003Interface::GetChannelWithChannelIn(int iCh) { CVocodecChannel *Channel = NULL; bool done = false; - for ( int i = 0; (i < m_Channels.size()) && !done; i++ ) + for ( size_t i = 0; (i < m_Channels.size()) && !done; i++ ) { if ( iCh == 2 ) { @@ -114,7 +114,7 @@ CVocodecChannel *CUsb3003Interface::GetChannelWithChannelOut(int iCh) { CVocodecChannel *Channel = NULL; bool done = false; - for ( int i = 0; (i < m_Channels.size()) && !done; i++ ) + for ( size_t i = 0; (i < m_Channels.size()) && !done; i++ ) { if ( (m_Channels[i]->GetChannelOut() == iCh) && (m_Channels[i]->IsInterfaceOut(this)) ) { diff --git a/ambed/cusb3xxxinterface.cpp b/ambed/cusb3xxxinterface.cpp index c8eb461..c4488e7 100644 --- a/ambed/cusb3xxxinterface.cpp +++ b/ambed/cusb3xxxinterface.cpp @@ -53,14 +53,14 @@ CUsb3xxxInterface::CUsb3xxxInterface(uint32 uiVid, uint32 uiPid, const char *szD CUsb3xxxInterface::~CUsb3xxxInterface() { // delete m_SpeechQueues - for ( int i = 0; i < m_SpeechQueues.size(); i++ ) + for ( size_t i = 0; i < m_SpeechQueues.size(); i++ ) { delete m_SpeechQueues[i]; } m_SpeechQueues.clear(); // delete m_ChannelQueues - for ( int i = 0; i < m_ChannelQueues.size(); i++ ) + for ( size_t i = 0; i < m_ChannelQueues.size(); i++ ) { delete m_ChannelQueues[i]; } @@ -184,7 +184,7 @@ void CUsb3xxxInterface::Task(void) do { done = true; - for ( int i = 0; i < m_Channels.size(); i++) + for ( size_t i = 0; i < m_Channels.size(); i++) { // get channel Channel = m_Channels[i]; @@ -276,7 +276,7 @@ void CUsb3xxxInterface::Task(void) // if device fifo level is zero (device idle) // wait that at least 3 packets are in incoming // queue before restarting - if ( ((m_iSpeechFifolLevel+m_iChannelFifolLevel) > 0) || (m_DeviceQueue.size() >= (fifoSize+1)) ) + if (((m_iSpeechFifolLevel+m_iChannelFifolLevel) > 0) || (m_DeviceQueue.size() >= (size_t)(fifoSize+1))) { // any packet to send ? if ( m_DeviceQueue.size() > 0 ) diff --git a/ambed/cvocodecs.cpp b/ambed/cvocodecs.cpp index aa28707..3aea1d4 100644 --- a/ambed/cvocodecs.cpp +++ b/ambed/cvocodecs.cpp @@ -49,7 +49,7 @@ CVocodecs::~CVocodecs() // delete channels m_MutexChannels.lock(); { - for ( int i = 0; i < m_Channels.size(); i++ ) + for ( size_t i = 0; i < m_Channels.size(); i++ ) { delete m_Channels[i]; } @@ -60,7 +60,7 @@ CVocodecs::~CVocodecs() // delete interfaces m_MutexInterfaces.lock(); { - for ( int i = 0; i < m_Interfaces.size(); i++ ) + for ( size_t i = 0; i < m_Interfaces.size(); i++ ) { delete m_Interfaces[i]; } @@ -69,7 +69,7 @@ CVocodecs::~CVocodecs() m_MutexInterfaces.unlock(); // delete ftdi device descriptors - for ( int i = 0; i < m_FtdiDeviceDescrs.size(); i++ ) + for ( size_t i = 0; i < m_FtdiDeviceDescrs.size(); i++ ) { delete m_FtdiDeviceDescrs[i]; } @@ -89,7 +89,7 @@ bool CVocodecs::Init(void) // and create interfaces for the discovered devices // first handle all even number of channels devices std::vector Multi3003DevicesChs; - for ( int i = 0; i < m_FtdiDeviceDescrs.size(); i++ ) + for ( size_t i = 0; i < m_FtdiDeviceDescrs.size(); i++ ) { CFtdiDeviceDescr *descr = m_FtdiDeviceDescrs[i]; if ( !descr->IsUsed() && IsEven(descr->GetNbChannels()) ) @@ -104,7 +104,7 @@ bool CVocodecs::Init(void) // they must be handeled in pair, or in pair with another // even number of channels device. std::vector PairsOf3000DevicesChs; - for ( int i = 0; i < m_FtdiDeviceDescrs.size(); i++ ) + for ( size_t i = 0; i < m_FtdiDeviceDescrs.size(); i++ ) { CFtdiDeviceDescr *descr1 = m_FtdiDeviceDescrs[i]; CFtdiDeviceDescr *descr2 = NULL; @@ -112,7 +112,7 @@ bool CVocodecs::Init(void) { // any other single channel device to pair with ? bool found = false; - int j = i+1; + size_t j = i+1; while ( !found && (j < m_FtdiDeviceDescrs.size()) ) { descr2 = m_FtdiDeviceDescrs[j]; @@ -132,7 +132,7 @@ bool CVocodecs::Init(void) // now we should have only remaining the 3 channels device(s) // and possibly an unique single channel device std::vector Single3003DeviceChannels; - for ( int i = 0; i < m_FtdiDeviceDescrs.size(); i++ ) + for ( size_t i = 0; i < m_FtdiDeviceDescrs.size(); i++ ) { CFtdiDeviceDescr *descr1 = m_FtdiDeviceDescrs[i]; CFtdiDeviceDescr *descr2 = NULL; @@ -141,7 +141,7 @@ bool CVocodecs::Init(void) // any other odd channel device to pair with ? // any other single channel device to pair with ? bool found = false; - int j = i+1; + size_t j = i+1; while ( !found && (j < m_FtdiDeviceDescrs.size()) ) { descr2 = m_FtdiDeviceDescrs[j]; @@ -170,7 +170,7 @@ bool CVocodecs::Init(void) // for proper load sharing // pairs of 300 devices first { - for ( int i = 0; i < PairsOf3000DevicesChs.size(); i++ ) + for ( size_t i = 0; i < PairsOf3000DevicesChs.size(); i++ ) { m_Channels.push_back(PairsOf3000DevicesChs.at(i)); } @@ -178,7 +178,7 @@ bool CVocodecs::Init(void) } // next the left-over single 3003 device { - for ( int i = 0; i < Single3003DeviceChannels.size(); i++ ) + for ( size_t i = 0; i < Single3003DeviceChannels.size(); i++ ) { m_Channels.push_back(Single3003DeviceChannels.at(i)); } @@ -222,7 +222,7 @@ bool CVocodecs::DiscoverFtdiDevices(void) FT_DEVICE_LIST_INFO_NODE *list; // clear vector - for ( int i = 0; i < m_FtdiDeviceDescrs.size(); i++ ) + for ( size_t i = 0; i < m_FtdiDeviceDescrs.size(); i++ ) { delete m_FtdiDeviceDescrs[i]; } @@ -274,7 +274,7 @@ CVocodecChannel *CVocodecs::OpenChannel(uint8 uiCodecIn, uint8 uiCodecOut) // loop on all interface until suitable & available channel found m_MutexChannels.lock(); - for ( int i = 0; (i < m_Channels.size()) && !done; i++ ) + for ( size_t i = 0; (i < m_Channels.size()) && !done; i++ ) { if ( !m_Channels[i]->IsOpen() && (m_Channels[i]->GetCodecIn() == uiCodecIn) && diff --git a/ambed/main.h b/ambed/main.h index a432f36..fb13097 100644 --- a/ambed/main.h +++ b/ambed/main.h @@ -87,8 +87,8 @@ typedef unsigned int uint; //////////////////////////////////////////////////////////////////////////////////////// // macros -#define MIN(a,b) ((a) < (b))?(a):(b) -#define MAX(a,b) ((a) > (b))?(a):(b) +#define MIN(a,b) ((size_t)(a) < (size_t)(b))?(a):(b) +#define MAX(a,b) ((size_t)(a) > (size_t)(b))?(a):(b) #define MAKEWORD(low, high) ((uint16)(((uint8)(low)) | (((uint16)((uint8)(high))) << 8))) #define MAKEDWORD(low, high) ((uint32)(((uint16)(low)) | (((uint32)((uint16)(high))) << 16))) #define LOBYTE(w) ((uint8)(uint16)(w & 0x00FF)) diff --git a/ambed/makefile b/ambed/makefile index c556a28..57ec4db 100644 --- a/ambed/makefile +++ b/ambed/makefile @@ -1,6 +1,6 @@ -CC=g++ -CFLAGS=-c -std=c++11 -pthread -LDFLAGS=-std=c++11 -pthread +CXX=g++ +CFLAGS=-Os -Wall -std=c++11 -pthread +LDFLAGS=-Os -Wall -std=c++11 -pthread SOURCES=$(wildcard *.cpp) OBJECTS=$(SOURCES:.cpp=.o) EXECUTABLE=ambed @@ -8,13 +8,13 @@ EXECUTABLE=ambed all: $(SOURCES) $(EXECUTABLE) $(EXECUTABLE): $(OBJECTS) - $(CC) $(LDFLAGS) $(OBJECTS) -lftd2xx -Wl,-rpath,/usr/local/lib -o $@ + $(CXX) $(LDFLAGS) $(OBJECTS) -lftd2xx -Wl,-rpath,/usr/local/lib -o $@ .cpp.o: - $(CC) $(CFLAGS) $< -o $@ + $(CXX) $(CFLAGS) -c -o $@ $< clean: - $(RM) $(EXECUTABLE) *.o + $(RM) xlxd *.o *.d *.bak install: mkdir -p /ambed diff --git a/src/cbmpeer.cpp b/src/cbmpeer.cpp index 36c38fb..4bc22cb 100644 --- a/src/cbmpeer.cpp +++ b/src/cbmpeer.cpp @@ -40,7 +40,7 @@ CBmPeer::CBmPeer(const CCallsign &callsign, const CIp &ip, char *modules, const std::cout << "Adding BM peer" << std::endl; // and construct all xlx clients - for ( int i = 0; i < ::strlen(modules); i++ ) + for ( size_t i = 0; i < ::strlen(modules); i++ ) { // create CBmClient *client = new CBmClient(callsign, ip, modules[i]); @@ -52,7 +52,7 @@ CBmPeer::CBmPeer(const CCallsign &callsign, const CIp &ip, char *modules, const CBmPeer::CBmPeer(const CBmPeer &peer) : CPeer(peer) { - for ( int i = 0; i < peer.m_Clients.size(); i++ ) + for ( size_t i = 0; i < peer.m_Clients.size(); i++ ) { CBmClient *client = new CBmClient((const CBmClient &)*(peer.m_Clients[i])); // grow vector capacity if needed diff --git a/src/cbptc19696.cpp b/src/cbptc19696.cpp index fb55052..7746ba1 100644 --- a/src/cbptc19696.cpp +++ b/src/cbptc19696.cpp @@ -26,12 +26,18 @@ #include #include -CBPTC19696::CBPTC19696() +CBPTC19696::CBPTC19696(): +m_rawData(NULL), +m_deInterData(NULL) { + m_rawData = new bool[196]; + m_deInterData = new bool[196]; } CBPTC19696::~CBPTC19696() { + delete[] m_rawData; + delete[] m_deInterData; } // The main decode function @@ -165,7 +171,7 @@ void CBPTC19696::decodeErrorCheck() } // Extract the 96 bits of payload -void CBPTC19696::decodeExtractData(unsigned char* data) const +void CBPTC19696::decodeExtractData(unsigned char* data) { bool bData[96U]; unsigned int pos = 0U; diff --git a/src/cbptc19696.h b/src/cbptc19696.h index f1b690c..7995da8 100644 --- a/src/cbptc19696.h +++ b/src/cbptc19696.h @@ -30,13 +30,13 @@ public: void encode(const unsigned char* in, unsigned char* out); private: - bool m_rawData[196]; - bool m_deInterData[196]; + bool* m_rawData; + bool* m_deInterData; void decodeExtractBinary(const unsigned char* in); void decodeErrorCheck(); void decodeDeInterleave(); - void decodeExtractData(unsigned char* data) const; + void decodeExtractData(unsigned char* data); void encodeExtractData(const unsigned char* in); void encodeInterleave(); diff --git a/src/cbuffer.cpp b/src/cbuffer.cpp index 5213155..2d35e87 100644 --- a/src/cbuffer.cpp +++ b/src/cbuffer.cpp @@ -120,7 +120,7 @@ void CBuffer::ReplaceAt(int i, uint32 ui) void CBuffer::ReplaceAt(int i, const uint8 *ptr, int len) { - if ( size() < (i+len) ) + if ( size() < (size_t)(i+len) ) { resize(i+len); } @@ -133,7 +133,7 @@ void CBuffer::ReplaceAt(int i, const uint8 *ptr, int len) int CBuffer::Compare(uint8 *buffer, int len) const { int result = -1; - if ( size() >= len ) + if ( size() >= (size_t)len ) { result = ::memcmp(data(), buffer, len); } @@ -143,7 +143,7 @@ int CBuffer::Compare(uint8 *buffer, int len) const int CBuffer::Compare(uint8 *buffer, int off, int len) const { int result = -1; - if ( size() >= (off+len) ) + if ( size() >= (size_t)(off+len) ) { result = ::memcmp(&(data()[off]), buffer, len); } @@ -182,7 +182,7 @@ CBuffer::operator const char *() const void CBuffer::DebugDump(std::ofstream &debugout) const { - for ( int i = 0; i < size(); i++ ) + for ( size_t i = 0; i < size(); i++ ) { char sz[16]; //sprintf(sz, "%02X", data()[i]); diff --git a/src/ccallsign.cpp b/src/ccallsign.cpp index 23cdb3e..69003bc 100644 --- a/src/ccallsign.cpp +++ b/src/ccallsign.cpp @@ -137,7 +137,7 @@ bool CCallsign::IsValid(void) const bool CCallsign::HasSuffix(void) const { bool has = false; - for ( int i = 0; i < CALLSUFFIX_LEN; i++ ) + for ( size_t i = 0; i < CALLSUFFIX_LEN; i++ ) { has |= (m_Suffix[i] != ' '); } @@ -174,14 +174,14 @@ void CCallsign::SetCallsign(const uint8 *buffer, int len, bool UpdateDmrid) ::memset(m_Callsign, ' ', sizeof(m_Callsign)); m_Module = ' '; ::memcpy(m_Callsign, buffer, MIN(len, sizeof(m_Callsign)-1)); - for ( int i = 0; i < sizeof(m_Callsign); i++ ) + for ( size_t i = 0; i < sizeof(m_Callsign); i++ ) { if ( m_Callsign[i] == 0 ) { m_Callsign[i] = ' '; } } - if ( (len >= sizeof(m_Callsign)) && ((char)buffer[sizeof(m_Callsign)-1] != 0) ) + if ( ((size_t)len >= sizeof(m_Callsign)) && ((char)buffer[sizeof(m_Callsign)-1] != 0) ) { m_Module = (char)buffer[sizeof(m_Callsign)-1]; } @@ -244,7 +244,7 @@ void CCallsign::SetSuffix(const uint8 *buffer, int len) void CCallsign::PatchCallsign(int off, const uint8 *patch, int len) { - if ( off < sizeof(m_Callsign) ) + if ( (size_t)off < sizeof(m_Callsign) ) { ::memcpy(m_Callsign, patch, MIN(len, sizeof(m_Callsign) - off)); } @@ -266,7 +266,7 @@ void CCallsign::GetCallsign(uint8 *buffer) const void CCallsign::GetCallsignString(char *sz) const { int i; - for ( i = 0; (i < sizeof(m_Callsign)) && (m_Callsign[i] != ' '); i++ ) + for ( i = 0; ((size_t)i < sizeof(m_Callsign)) && (m_Callsign[i] != ' '); i++ ) { sz[i] = m_Callsign[i]; } @@ -291,7 +291,7 @@ bool CCallsign::HasSameCallsignWithWildcard(const CCallsign &callsign) const bool same = true; bool done = false; - for ( int i = 0; (i < sizeof(m_Callsign)) && same && !done; i++ ) + for ( size_t i = 0; (i < sizeof(m_Callsign)) && same && !done; i++ ) { if ( !(done = ((m_Callsign[i] == '*') || (callsign[i] == '*'))) ) { diff --git a/src/ccallsignlist.cpp b/src/ccallsignlist.cpp index dfd9d35..3642bda 100644 --- a/src/ccallsignlist.cpp +++ b/src/ccallsignlist.cpp @@ -131,7 +131,7 @@ bool CCallsignList::IsCallsignListedWithWildcard(const CCallsign &callsign) cons { bool listed = false; - for ( int i = 0; (i < size()) && !listed; i++ ) + for ( size_t i = 0; (i < size()) && !listed; i++ ) { listed = (data()[i]).HasSameCallsignWithWildcard(callsign); } @@ -143,7 +143,7 @@ bool CCallsignList::IsCallsignListedWithWildcard(const CCallsign &callsign, char { bool listed = false; - for ( int i = 0; (i < size()) && !listed; i++ ) + for ( size_t i = 0; (i < size()) && !listed; i++ ) { const CCallsignListItem *item = &(data()[i]); listed = (item->HasSameCallsignWithWildcard(callsign) && @@ -158,7 +158,7 @@ bool CCallsignList::IsCallsignListed(const CCallsign &callsign, char module) con { bool listed = false; - for ( int i = 0; (i < size()) && !listed; i++ ) + for ( size_t i = 0; (i < size()) && !listed; i++ ) { const CCallsignListItem *item = &(data()[i]); listed = (item->HasSameCallsign(callsign) && item->HasModuleListed(module)); @@ -172,7 +172,7 @@ bool CCallsignList::IsCallsignListed(const CCallsign &callsign, char *modules) c { bool listed = false; - for ( int i = 0; (i < size()) && !listed; i++ ) + for ( size_t i = 0; (i < size()) && !listed; i++ ) { const CCallsignListItem *item = &(data()[i]); listed = (item->HasSameCallsign(callsign) && item->CheckListedModules(modules)); @@ -190,7 +190,7 @@ CCallsignListItem *CCallsignList::FindListItem(const CCallsign &Callsign) CCallsignListItem *item = NULL; // find client - for ( int i = 0; (i < size()) && (item == NULL); i++ ) + for ( size_t i = 0; (i < size()) && (item == NULL); i++ ) { if ( (data()[i]).GetCallsign().HasSameCallsign(Callsign) ) { diff --git a/src/ccallsignlistitem.cpp b/src/ccallsignlistitem.cpp index ddea21d..e0b98c4 100644 --- a/src/ccallsignlistitem.cpp +++ b/src/ccallsignlistitem.cpp @@ -45,7 +45,7 @@ CCallsignListItem::CCallsignListItem(const CCallsign &callsign, const CIp &ip, c ::memset(m_Modules, 0, sizeof(m_Modules)); if ( modules[0] == '*' ) { - for ( char i = 0; i < NB_OF_MODULES; i++ ) + for ( size_t i = 0; i < NB_OF_MODULES; i++ ) { m_Modules[i] = 'A' + i; } @@ -75,7 +75,7 @@ CCallsignListItem::CCallsignListItem(const CCallsign &callsign, const char *url, ::memset(m_Modules, 0, sizeof(m_Modules)); if ( modules[0] == '*' ) { - for ( char i = 0; i < NB_OF_MODULES; i++ ) + for ( size_t i = 0; i < NB_OF_MODULES; i++ ) { m_Modules[i] = 'A' + i; } @@ -132,7 +132,7 @@ bool CCallsignListItem::CheckListedModules(char *Modules) const char list[NB_MODULES_MAX+1]; list[0] = 0; // - for ( int i = 0; i < ::strlen(Modules); i++ ) + for ( size_t i = 0; i < ::strlen(Modules); i++ ) { if ( HasModuleListed(Modules[i]) ) { diff --git a/src/cclients.cpp b/src/cclients.cpp index 837802a..c8d67b9 100644 --- a/src/cclients.cpp +++ b/src/cclients.cpp @@ -43,7 +43,7 @@ CClients::~CClients() { m_Mutex.lock(); { - for ( int i = 0; i < m_Clients.size(); i++ ) + for ( size_t i = 0; i < m_Clients.size(); i++ ) { delete m_Clients[i]; } @@ -60,7 +60,7 @@ void CClients::AddClient(CClient *client) { // first check if client already exists bool found = false; - for ( int i = 0; (i < m_Clients.size()) && !found; i++ ) + for ( size_t i = 0; (i < m_Clients.size()) && !found; i++ ) { found = (*client == *m_Clients[i]); // if found, just do nothing @@ -100,7 +100,7 @@ void CClients::RemoveClient(CClient *client) { // look for the client bool found = false; - for ( int i = 0; (i < m_Clients.size()) && !found; i++ ) + for ( size_t i = 0; (i < m_Clients.size()) && !found; i++ ) { // compare objetc pointers if ( (m_Clients[i]) == client ) @@ -128,7 +128,7 @@ void CClients::RemoveClient(CClient *client) CClient *CClients::GetClient(int i) { - if ( (i >= 0) && (i < m_Clients.size()) ) + if ( (i >= 0) && ((size_t)i < m_Clients.size()) ) { return m_Clients[i]; } @@ -141,7 +141,7 @@ CClient *CClients::GetClient(int i) bool CClients::IsClient(CClient *client) const { bool found = false; - for ( int i = 0; (i < m_Clients.size()) && !found; i++ ) + for ( size_t i = 0; (i < m_Clients.size()) && !found; i++ ) { found = (m_Clients[i] == client); } @@ -156,7 +156,7 @@ CClient *CClients::FindClient(const CIp &Ip) CClient *client = NULL; // find client - for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ ) + for ( size_t i = 0; (i < m_Clients.size()) && (client == NULL); i++ ) { if ( m_Clients[i]->GetIp() == Ip ) { @@ -173,7 +173,7 @@ CClient *CClients::FindClient(const CIp &Ip, int Protocol) CClient *client = NULL; // find client - for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ ) + for ( size_t i = 0; (i < m_Clients.size()) && (client == NULL); i++ ) { if ( (m_Clients[i]->GetIp() == Ip) && (m_Clients[i]->GetProtocol() == Protocol)) { @@ -190,7 +190,7 @@ CClient *CClients::FindClient(const CIp &Ip, int Protocol, char ReflectorModule) CClient *client = NULL; // find client - for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ ) + for ( size_t i = 0; (i < m_Clients.size()) && (client == NULL); i++ ) { if ( (m_Clients[i]->GetIp() == Ip) && (m_Clients[i]->GetReflectorModule() == ReflectorModule) && @@ -209,7 +209,7 @@ CClient *CClients::FindClient(const CCallsign &Callsign, const CIp &Ip, int Prot CClient *client = NULL; // find client - for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ ) + for ( size_t i = 0; (i < m_Clients.size()) && (client == NULL); i++ ) { if ( m_Clients[i]->GetCallsign().HasSameCallsign(Callsign) && (m_Clients[i]->GetIp() == Ip) && @@ -228,7 +228,7 @@ CClient *CClients::FindClient(const CCallsign &Callsign, char module, const CIp CClient *client = NULL; // find client - for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ ) + for ( size_t i = 0; (i < m_Clients.size()) && (client == NULL); i++ ) { if ( m_Clients[i]->GetCallsign().HasSameCallsign(Callsign) && (m_Clients[i]->GetModule() == module) && @@ -248,7 +248,7 @@ CClient *CClients::FindClient(const CCallsign &Callsign, int Protocol) CClient *client = NULL; // find client - for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ ) + for ( size_t i = 0; (i < m_Clients.size()) && (client == NULL); i++ ) { if ( (m_Clients[i]->GetProtocol() == Protocol) && m_Clients[i]->GetCallsign().HasSameCallsign(Callsign) ) @@ -270,7 +270,7 @@ CClient *CClients::FindNextClient(int Protocol, int *index) // find next client bool found = false; - for ( int i = *index+1; (i < m_Clients.size()) && !found; i++ ) + for ( size_t i = *index+1; (i < m_Clients.size()) && !found; i++ ) { if ( m_Clients[i]->GetProtocol() == Protocol ) { @@ -288,7 +288,7 @@ CClient *CClients::FindNextClient(const CIp &Ip, int Protocol, int *index) // find next client bool found = false; - for ( int i = *index+1; (i < m_Clients.size()) && !found; i++ ) + for ( size_t i = *index+1; (i < m_Clients.size()) && !found; i++ ) { if ( (m_Clients[i]->GetProtocol() == Protocol) && (m_Clients[i]->GetIp() == Ip) ) @@ -307,7 +307,7 @@ CClient *CClients::FindNextClient(const CCallsign &Callsign, const CIp &Ip, int // find next client bool found = false; - for ( int i = *index+1; (i < m_Clients.size()) && !found; i++ ) + for ( size_t i = *index+1; (i < m_Clients.size()) && !found; i++ ) { if ( (m_Clients[i]->GetProtocol() == Protocol) && (m_Clients[i]->GetIp() == Ip) && diff --git a/src/cdmrmmdvmprotocol.cpp b/src/cdmrmmdvmprotocol.cpp index 2398fd1..e1d11d5 100644 --- a/src/cdmrmmdvmprotocol.cpp +++ b/src/cdmrmmdvmprotocol.cpp @@ -46,7 +46,7 @@ static uint8 g_DmrSyncBSVoice[] = { 0x07,0x55,0xFD,0x7D,0xF7,0x5F,0x70 }; static uint8 g_DmrSyncBSData[] = { 0x0D,0xFF,0x57,0xD7,0x5D,0xF5,0xD0 }; -static uint8 g_DmrSyncMSVoice[] = { 0x07,0xF7,0xD5,0xDD,0x57,0xDF,0xD0 }; +//static uint8 g_DmrSyncMSVoice[] = { 0x07,0xF7,0xD5,0xDD,0x57,0xDF,0xD0 }; //not used static uint8 g_DmrSyncMSData[] = { 0x0D,0x5D,0x7F,0x77,0xFD,0x75,0x70 }; diff --git a/src/cdmrplusprotocol.cpp b/src/cdmrplusprotocol.cpp index 1d1180f..26187ca 100644 --- a/src/cdmrplusprotocol.cpp +++ b/src/cdmrplusprotocol.cpp @@ -39,8 +39,8 @@ static uint8 g_DmrSyncBSVoice[] = { 0x07,0x55,0xFD,0x7D,0xF7,0x5F,0x70 }; static uint8 g_DmrSyncBSData[] = { 0x0D,0xFF,0x57,0xD7,0x5D,0xF5,0xD0 }; -static uint8 g_DmrSyncMSVoice[] = { 0x07,0xF7,0xD5,0xDD,0x57,0xDF,0xD0 }; -static uint8 g_DmrSyncMSData[] = { 0x0D,0x5D,0x7F,0x77,0xFD,0x75,0x70 }; +//static uint8 g_DmrSyncMSVoice[] = { 0x07,0xF7,0xD5,0xDD,0x57,0xDF,0xD0 }; //not used +//static uint8 g_DmrSyncMSData[] = { 0x0D,0x5D,0x7F,0x77,0xFD,0x75,0x70 }; //////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/cgolay2087.cpp b/src/cgolay2087.cpp index 7ff6f92..2838d93 100644 --- a/src/cgolay2087.cpp +++ b/src/cgolay2087.cpp @@ -21,8 +21,8 @@ #include #include -const unsigned int ENCODING_TABLE_2087[] = -{0x0000U, 0xB08EU, 0xE093U, 0x501DU, 0x70A9U, 0xC027U, 0x903AU, 0x20B4U, 0x60DCU, 0xD052U, 0x804FU, 0x30C1U, +const unsigned int ENCODING_TABLE_2087[] = { + 0x0000U, 0xB08EU, 0xE093U, 0x501DU, 0x70A9U, 0xC027U, 0x903AU, 0x20B4U, 0x60DCU, 0xD052U, 0x804FU, 0x30C1U, 0x1075U, 0xA0FBU, 0xF0E6U, 0x4068U, 0x7036U, 0xC0B8U, 0x90A5U, 0x202BU, 0x009FU, 0xB011U, 0xE00CU, 0x5082U, 0x10EAU, 0xA064U, 0xF079U, 0x40F7U, 0x6043U, 0xD0CDU, 0x80D0U, 0x305EU, 0xD06CU, 0x60E2U, 0x30FFU, 0x8071U, 0xA0C5U, 0x104BU, 0x4056U, 0xF0D8U, 0xB0B0U, 0x003EU, 0x5023U, 0xE0ADU, 0xC019U, 0x7097U, 0x208AU, 0x9004U, @@ -45,8 +45,8 @@ const unsigned int ENCODING_TABLE_2087[] = 0x90BEU, 0x2030U, 0x702DU, 0xC0A3U, 0xE017U, 0x5099U, 0x0084U, 0xB00AU, 0xF062U, 0x40ECU, 0x10F1U, 0xA07FU, 0x80CBU, 0x3045U, 0x6058U, 0xD0D6U}; -const unsigned int DECODING_TABLE_1987[] = -{0x00000U, 0x00001U, 0x00002U, 0x00003U, 0x00004U, 0x00005U, 0x00006U, 0x00007U, 0x00008U, 0x00009U, 0x0000AU, 0x0000BU, 0x0000CU, +const unsigned int DECODING_TABLE_1987[] = { + 0x00000U, 0x00001U, 0x00002U, 0x00003U, 0x00004U, 0x00005U, 0x00006U, 0x00007U, 0x00008U, 0x00009U, 0x0000AU, 0x0000BU, 0x0000CU, 0x0000DU, 0x0000EU, 0x24020U, 0x00010U, 0x00011U, 0x00012U, 0x00013U, 0x00014U, 0x00015U, 0x00016U, 0x00017U, 0x00018U, 0x00019U, 0x0001AU, 0x0001BU, 0x0001CU, 0x0001DU, 0x48040U, 0x01480U, 0x00020U, 0x00021U, 0x00022U, 0x00023U, 0x00024U, 0x00025U, 0x00026U, 0x24008U, 0x00028U, 0x00029U, 0x0002AU, 0x24004U, 0x0002CU, 0x24002U, 0x24001U, 0x24000U, 0x00030U, 0x00031U, 0x00032U, 0x08180U, diff --git a/src/cpeer.cpp b/src/cpeer.cpp index 037325e..7ebf4e9 100644 --- a/src/cpeer.cpp +++ b/src/cpeer.cpp @@ -68,7 +68,7 @@ CPeer::CPeer(const CPeer &peer) CPeer::~CPeer() { - for ( int i = 0; i < m_Clients.size(); i++ ) + for ( size_t i = 0; i < m_Clients.size(); i++ ) { delete m_Clients[i]; } @@ -85,7 +85,7 @@ bool CPeer::operator ==(const CPeer &peer) const same &= (peer.m_Callsign == m_Callsign); same &= (peer.m_Ip == m_Ip); same &= (peer.m_Version == m_Version); - for ( int i = 0; (i < m_Clients.size()) && same ; i++ ) + for ( size_t i = 0; (i < m_Clients.size()) && same ; i++ ) { same &= (peer.m_Clients[i] == m_Clients[i]); } @@ -99,7 +99,7 @@ bool CPeer::operator ==(const CPeer &peer) const bool CPeer::IsAMaster(void) const { bool master = false; - for ( int i = 0; (i < m_Clients.size()) && !master ; i++ ) + for ( size_t i = 0; (i < m_Clients.size()) && !master ; i++ ) { master |= m_Clients[i]->IsAMaster(); } @@ -109,7 +109,7 @@ bool CPeer::IsAMaster(void) const void CPeer::Alive(void) { m_LastKeepaliveTime.Now();; - for ( int i = 0; i < m_Clients.size(); i++ ) + for ( size_t i = 0; i < m_Clients.size(); i++ ) { m_Clients[i]->Alive(); } @@ -120,7 +120,7 @@ void CPeer::Alive(void) CClient *CPeer::GetClient(int i) { - if ( (i >= 0) && (i < m_Clients.size()) ) + if ( (i >= 0) && ((size_t)i < m_Clients.size()) ) { return m_Clients[i]; } diff --git a/src/cpeers.cpp b/src/cpeers.cpp index 35c5547..94ba41e 100644 --- a/src/cpeers.cpp +++ b/src/cpeers.cpp @@ -43,7 +43,7 @@ CPeers::~CPeers() { m_Mutex.lock(); { - for ( int i = 0; i < m_Peers.size(); i++ ) + for ( size_t i = 0; i < m_Peers.size(); i++ ) { delete m_Peers[i]; } @@ -60,7 +60,7 @@ void CPeers::AddPeer(CPeer *peer) { // first check if peer already exists bool found = false; - for ( int i = 0; (i < m_Peers.size()) && !found; i++ ) + for ( size_t i = 0; (i < m_Peers.size()) && !found; i++ ) { found = (*peer == *m_Peers[i]); // if found, just do nothing @@ -104,7 +104,7 @@ void CPeers::RemovePeer(CPeer *peer) { // look for the client bool found = false; - for ( int i = 0; (i < m_Peers.size()) && !found; i++ ) + for ( size_t i = 0; (i < m_Peers.size()) && !found; i++ ) { // compare objetc pointers if ( (m_Peers[i]) == peer ) @@ -139,7 +139,7 @@ void CPeers::RemovePeer(CPeer *peer) CPeer *CPeers::GetPeer(int i) { - if ( (i >= 0) && (i < m_Peers.size()) ) + if ( (i >= 0) && ((size_t)i < m_Peers.size()) ) { return m_Peers[i]; } @@ -157,7 +157,7 @@ CPeer *CPeers::FindPeer(const CIp &Ip, int Protocol) CPeer *peer = NULL; // find peer - for ( int i = 0; (i < m_Peers.size()) && (peer == NULL); i++ ) + for ( size_t i = 0; (i < m_Peers.size()) && (peer == NULL); i++ ) { if ( (m_Peers[i]->GetIp() == Ip) && (m_Peers[i]->GetProtocol() == Protocol)) { @@ -174,7 +174,7 @@ CPeer *CPeers::FindPeer(const CCallsign &Callsign, const CIp &Ip, int Protocol) CPeer *peer = NULL; // find peer - for ( int i = 0; (i < m_Peers.size()) && (peer == NULL); i++ ) + for ( size_t i = 0; (i < m_Peers.size()) && (peer == NULL); i++ ) { if ( m_Peers[i]->GetCallsign().HasSameCallsign(Callsign) && (m_Peers[i]->GetIp() == Ip) && @@ -193,7 +193,7 @@ CPeer *CPeers::FindPeer(const CCallsign &Callsign, int Protocol) CPeer *peer = NULL; // find peer - for ( int i = 0; (i < m_Peers.size()) && (peer == NULL); i++ ) + for ( size_t i = 0; (i < m_Peers.size()) && (peer == NULL); i++ ) { if ( (m_Peers[i]->GetProtocol() == Protocol) && m_Peers[i]->GetCallsign().HasSameCallsign(Callsign) ) @@ -216,7 +216,7 @@ CPeer *CPeers::FindNextPeer(int Protocol, int *index) // find next peer bool found = false; - for ( int i = *index+1; (i < m_Peers.size()) && !found; i++ ) + for ( size_t i = *index+1; (i < m_Peers.size()) && !found; i++ ) { if ( m_Peers[i]->GetProtocol() == Protocol ) { diff --git a/src/cprotocol.cpp b/src/cprotocol.cpp index a5d2adb..e20fba2 100644 --- a/src/cprotocol.cpp +++ b/src/cprotocol.cpp @@ -172,7 +172,7 @@ CPacketStream *CProtocol::GetStream(uint16 uiStreamId, const CIp *Ip) CPacketStream *stream = NULL; // find if we have a stream with same streamid in our cache - for ( int i = 0; (i < m_Streams.size()) && (stream == NULL); i++ ) + for ( size_t i = 0; (i < m_Streams.size()) && (stream == NULL); i++ ) { if ( m_Streams[i]->GetStreamId() == uiStreamId ) { @@ -189,7 +189,7 @@ CPacketStream *CProtocol::GetStream(uint16 uiStreamId, const CIp *Ip) void CProtocol::CheckStreamsTimeout(void) { - for ( int i = 0; i < m_Streams.size(); i++ ) + for ( size_t i = 0; i < m_Streams.size(); i++ ) { // time out ? m_Streams[i]->Lock(); diff --git a/src/cprotocols.cpp b/src/cprotocols.cpp index 53f5499..d8d7b38 100644 --- a/src/cprotocols.cpp +++ b/src/cprotocols.cpp @@ -37,7 +37,7 @@ CProtocols::CProtocols() { - for ( int i = 0; i < m_Protocols.size(); i++ ) + for ( size_t i = 0; i < m_Protocols.size(); i++ ) { m_Protocols[i] = NULL; } @@ -50,7 +50,7 @@ CProtocols::~CProtocols() { m_Mutex.lock(); { - for ( int i = 0; i < m_Protocols.size(); i++ ) + for ( size_t i = 0; i < m_Protocols.size(); i++ ) { delete m_Protocols[i]; } @@ -107,7 +107,7 @@ void CProtocols::Close(void) { m_Mutex.lock(); { - for ( int i = 0; i < m_Protocols.size(); i++ ) + for ( size_t i = 0; i < m_Protocols.size(); i++ ) { m_Protocols[i]->Close(); } diff --git a/src/cqr1676.cpp b/src/cqr1676.cpp index a05ea3e..71b2e85 100644 --- a/src/cqr1676.cpp +++ b/src/cqr1676.cpp @@ -21,8 +21,8 @@ #include #include -const unsigned int ENCODING_TABLE_1676[] = -{0x0000U, 0x0273U, 0x04E5U, 0x0696U, 0x09C9U, 0x0BBAU, 0x0D2CU, 0x0F5FU, 0x11E2U, 0x1391U, 0x1507U, 0x1774U, +const unsigned int ENCODING_TABLE_1676[] = { + 0x0000U, 0x0273U, 0x04E5U, 0x0696U, 0x09C9U, 0x0BBAU, 0x0D2CU, 0x0F5FU, 0x11E2U, 0x1391U, 0x1507U, 0x1774U, 0x182BU, 0x1A58U, 0x1CCEU, 0x1EBDU, 0x21B7U, 0x23C4U, 0x2552U, 0x2721U, 0x287EU, 0x2A0DU, 0x2C9BU, 0x2EE8U, 0x3055U, 0x3226U, 0x34B0U, 0x36C3U, 0x399CU, 0x3BEFU, 0x3D79U, 0x3F0AU, 0x411EU, 0x436DU, 0x45FBU, 0x4788U, 0x48D7U, 0x4AA4U, 0x4C32U, 0x4E41U, 0x50FCU, 0x528FU, 0x5419U, 0x566AU, 0x5935U, 0x5B46U, 0x5DD0U, 0x5FA3U, @@ -34,8 +34,8 @@ const unsigned int ENCODING_TABLE_1676[] = 0xD97AU, 0xDB09U, 0xDD9FU, 0xDFECU, 0xE0E6U, 0xE295U, 0xE403U, 0xE670U, 0xE92FU, 0xEB5CU, 0xEDCAU, 0xEFB9U, 0xF104U, 0xF377U, 0xF5E1U, 0xF792U, 0xF8CDU, 0xFABEU, 0xFC28U, 0xFE5BU}; -const unsigned int DECODING_TABLE_1576[] = -{0x0000U, 0x0001U, 0x0002U, 0x0003U, 0x0004U, 0x0005U, 0x0006U, 0x4020U, 0x0008U, 0x0009U, 0x000AU, 0x000BU, +const unsigned int DECODING_TABLE_1576[] = { + 0x0000U, 0x0001U, 0x0002U, 0x0003U, 0x0004U, 0x0005U, 0x0006U, 0x4020U, 0x0008U, 0x0009U, 0x000AU, 0x000BU, 0x000CU, 0x000DU, 0x2081U, 0x2080U, 0x0010U, 0x0011U, 0x0012U, 0x0013U, 0x0014U, 0x0C00U, 0x0016U, 0x0C02U, 0x0018U, 0x0120U, 0x001AU, 0x0122U, 0x4102U, 0x0124U, 0x4100U, 0x4101U, 0x0020U, 0x0021U, 0x0022U, 0x4004U, 0x0024U, 0x4002U, 0x4001U, 0x4000U, 0x0028U, 0x0110U, 0x1800U, 0x1801U, 0x002CU, 0x400AU, 0x4009U, 0x4008U, diff --git a/src/creflector.cpp b/src/creflector.cpp index ed6ba58..990556f 100644 --- a/src/creflector.cpp +++ b/src/creflector.cpp @@ -568,7 +568,7 @@ CPacketStream *CReflector::GetStream(char module) bool CReflector::IsStreamOpen(const CDvHeaderPacket *DvHeader) { bool open = false; - for ( int i = 0; (i < m_Streams.size()) && !open; i++ ) + for ( size_t i = 0; (i < m_Streams.size()) && !open; i++ ) { open = ( (m_Streams[i].GetStreamId() == DvHeader->GetStreamId()) && (m_Streams[i].IsOpen())); @@ -579,7 +579,7 @@ bool CReflector::IsStreamOpen(const CDvHeaderPacket *DvHeader) char CReflector::GetStreamModule(CPacketStream *stream) { char module = ' '; - for ( int i = 0; (i < m_Streams.size()) && (module == ' '); i++ ) + for ( size_t i = 0; (i < m_Streams.size()) && (module == ' '); i++ ) { if ( &(m_Streams[i]) == stream ) { diff --git a/src/ctranscoder.cpp b/src/ctranscoder.cpp index 6b810c9..1ca6a9d 100644 --- a/src/ctranscoder.cpp +++ b/src/ctranscoder.cpp @@ -65,7 +65,7 @@ CTranscoder::~CTranscoder() // close all streams m_Mutex.lock(); { - for ( int i = 0; i < m_Streams.size(); i++ ) + for ( size_t i = 0; i < m_Streams.size(); i++ ) { delete m_Streams[i]; } @@ -120,7 +120,7 @@ void CTranscoder::Close(void) // close all streams m_Mutex.lock(); { - for ( int i = 0; i < m_Streams.size(); i++ ) + for ( size_t i = 0; i < m_Streams.size(); i++ ) { delete m_Streams[i]; } @@ -271,7 +271,7 @@ void CTranscoder::ReleaseStream(CCodecStream *stream) bool found = false; Lock(); { - for ( int i = 0; (i < m_Streams.size()) && !found; i++ ) + for ( size_t i = 0; (i < m_Streams.size()) && !found; i++ ) { // compare object pointers if ( (m_Streams[i]) == stream ) diff --git a/src/cusers.cpp b/src/cusers.cpp index c4dddd7..08e143b 100644 --- a/src/cusers.cpp +++ b/src/cusers.cpp @@ -69,7 +69,7 @@ void CUsers::Hearing(const CCallsign &my, const CCallsign &rpt1, const CCallsign // first check if we have this user listed yet bool found = false; - for ( int i = 0; (i < m_Users.size()) && !found; i++ ) + for ( size_t i = 0; (i < m_Users.size()) && !found; i++ ) { found = (m_Users[i] == heard); if ( found ) diff --git a/src/cxlxpeer.cpp b/src/cxlxpeer.cpp index aa214c4..491c038 100644 --- a/src/cxlxpeer.cpp +++ b/src/cxlxpeer.cpp @@ -45,7 +45,7 @@ CXlxPeer::CXlxPeer(const CCallsign &callsign, const CIp &ip, char *modules, cons //std::cout << "Adding XLX peer with protocol revision " << protrev << std::endl; // and construct all xlx clients - for ( int i = 0; i < ::strlen(modules); i++ ) + for ( size_t i = 0; i < ::strlen(modules); i++ ) { // create CXlxClient *client = new CXlxClient(callsign, ip, modules[i], protrev); @@ -57,7 +57,7 @@ CXlxPeer::CXlxPeer(const CCallsign &callsign, const CIp &ip, char *modules, cons CXlxPeer::CXlxPeer(const CXlxPeer &peer) : CPeer(peer) { - for ( int i = 0; i < peer.m_Clients.size(); i++ ) + for ( size_t i = 0; i < peer.m_Clients.size(); i++ ) { CXlxClient *client = new CXlxClient((const CXlxClient &)*(peer.m_Clients[i])); // grow vector capacity if needed diff --git a/src/cxlxprotocol.cpp b/src/cxlxprotocol.cpp index f01fb9a..90c3664 100644 --- a/src/cxlxprotocol.cpp +++ b/src/cxlxprotocol.cpp @@ -381,7 +381,7 @@ void CXlxProtocol::HandlePeerLinks(void) // check if all ours peers listed by gatekeeper are connected // if not, connect or reconnect - for ( int i = 0; i < list->size(); i++ ) + for ( size_t i = 0; i < list->size(); i++ ) { CCallsignListItem *item = &((list->data())[i]); if ( peers->FindPeer(item->GetCallsign(), PROTOCOL_XLX) == NULL ) @@ -501,7 +501,7 @@ bool CXlxProtocol::IsValidConnectPacket(const CBuffer &Buffer, CCallsign *callsi ::strcpy(modules, (const char *)&(Buffer.data()[12])); valid = callsign->IsValid(); *version = CVersion(Buffer.data()[9], Buffer.data()[10], Buffer.data()[11]); - for ( int i = 0; i < ::strlen(modules); i++ ) + for ( size_t i = 0; i < ::strlen(modules); i++ ) { valid &= IsLetter(modules[i]); } @@ -529,7 +529,7 @@ bool CXlxProtocol::IsValidAckPacket(const CBuffer &Buffer, CCallsign *callsign, ::strcpy(modules, (const char *)&(Buffer.data()[12])); valid = callsign->IsValid(); *version = CVersion(Buffer.data()[9], Buffer.data()[10], Buffer.data()[11]); - for ( int i = 0; i < ::strlen(modules); i++ ) + for ( size_t i = 0; i < ::strlen(modules); i++ ) { valid &= IsLetter(modules[i]); } diff --git a/src/main.h b/src/main.h index fa7acab..245061b 100644 --- a/src/main.h +++ b/src/main.h @@ -163,8 +163,8 @@ typedef unsigned int uint; //////////////////////////////////////////////////////////////////////////////////////// // macros -#define MIN(a,b) ((a) < (b))?(a):(b) -#define MAX(a,b) ((a) > (b))?(a):(b) +#define MIN(a,b) ((size_t)(a) < (size_t)(b))?(a):(b) +#define MAX(a,b) ((size_t)(a) > (size_t)(b))?(a):(b) #define MAKEWORD(low, high) ((uint16)(((uint8)(low)) | (((uint16)((uint8)(high))) << 8))) #define MAKEDWORD(low, high) ((uint32)(((uint16)(low)) | (((uint32)((uint16)(high))) << 16))) #define LOBYTE(w) ((uint8)(uint16)(w & 0x00FF)) diff --git a/src/makefile b/src/makefile index de1e0db..66632d5 100644 --- a/src/makefile +++ b/src/makefile @@ -1,6 +1,6 @@ -CC=g++ -CFLAGS=-c -std=c++11 -pthread -LDFLAGS=-std=c++11 -pthread +CXX=g++ +CXXFLAGS=-Os -Wall -std=c++11 -pthread +LDFLAGS=-Os -Wall -std=c++11 -pthread SOURCES=$(wildcard *.cpp) OBJECTS=$(SOURCES:.cpp=.o) EXECUTABLE=xlxd @@ -8,13 +8,13 @@ EXECUTABLE=xlxd all: $(SOURCES) $(EXECUTABLE) $(EXECUTABLE): $(OBJECTS) - $(CC) $(LDFLAGS) $(OBJECTS) -o $@ + $(CXX) $(LDFLAGS) $(OBJECTS) -o $@ .cpp.o: - $(CC) $(CFLAGS) $< -o $@ + $(CXX) $(CXXFLAGS) -c -o $@ $< clean: - $(RM) $(EXECUTABLE) *.o + $(RM) xlxd *.o *.d *.bak install: mkdir -p /xlxd