skeleton mmdvm_modem

pull/1/head
Tom Early 8 years ago
parent dc6bea7afd
commit 53c0596232

2
.gitignore vendored

@ -1,7 +1,9 @@
*.o *.o
*.d
dvap_rptr dvap_rptr
dvrptr dvrptr
g2_link g2_link
g2_ircddb g2_ircddb
g2link_test g2link_test
g2link_test_audio g2link_test_audio
mmdvm_modem

@ -1,3 +1,4 @@
# Copyright (c) 2018 by Thomas A. Early N7TAE
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -11,160 +12,130 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# locations for the executibles and other files are set here # locations for the executibles and other files are set here
# NOTE: IF YOU CHANGE THESE, YOU WILL NEED TO UPDATE THE service.* FILES AND # NOTE: IF YOU CHANGE THESE, YOU WILL NEED TO UPDATE THE service.* FILES AND
# SOME OF THE *.sh FILES TOO! # if you change these locations, make sure the sgs.service file is updated!
BINDIR=/usr/local/bin BINDIR=/usr/local/bin
CFGDIR=/usr/local/etc CFGDIR=/usr/local/etc
LOGDIR=/var/log
CPPFLAGS=-W -Wall -I/usr/include -std=c++11
LDFLAGS=-L/usr/lib -lconfig++
PROGRAMS=g2_ircddb g2_link dvap_rptr dvrptr g2link_test g2link_test_audio
IRCDDBOBJS = IRCDDB.o IRCClient.o IRCReceiver.o IRCMessageQueue.o IRCProtocol.o IRCMessage.o IRCDDBApp.o IRCutils.o golay23.o dstar_dv.o aprs.o
all : $(PROGRAMS)
g2_ircddb : g2_ircddb.cpp $(IRCDDBOBJS) aprs.h g2_typedefs.h versions.h g2_ircddb.h
g++ $(CPPFLAGS) -o g2_ircddb g2_ircddb.cpp $(IRCDDBOBJS) $(LDFLAGS) -pthread
g2_link : g2_link.cpp versions.h # use this if you want debugging help in the case of a crash
g++ $(CPPFLAGS) -o g2_link g2_link.cpp -lrt -lconfig++ -pthread #CPPFLAGS=-g -ggdb -W -Wall -std=c++11 -DCFG_DIR=\"$(CFGDIR)\"
dvap_rptr : dvap_rptr.cpp DVAPDongle.o dstar_dv.o golay23.o DVAPDongle.h g2_typedefs.h versions.h # or, you can choose this for a much smaller executable without debugging help
g++ $(CPPFLAGS) -o dvap_rptr dvap_rptr.cpp DVAPDongle.o golay23.o dstar_dv.o -I/usr/include -L/usr/lib -lrt -lconfig++ -pthread CPPFLAGS=-W -Wall -std=c++11
dvrptr : dvrptr.cpp dstar_dv.o golay23.o LDFLAGS=-L/usr/lib -lconfig++ -lrt
g++ $(CPPFLAGS) -o dvrptr dvrptr.cpp golay23.o dstar_dv.o -I/usr/include -L/usr/lib -lconfig++ -lrt
IRCutils.o : IRCutils.cpp IRCutils.h DSTROBJS = dstar_dv.o golay23.o
g++ -c $(CPPFLAGS) IRCutils.cpp IRCOBJS = IRCDDB.o IRCClient.o IRCReceiver.o IRCMessageQueue.o IRCProtocol.o IRCMessage.o IRCDDBApp.o IRCutils.o $(DSTROBJS)
SRCS = $(wildcard *.cpp)
OBJS = $(SRCS:.cpp=.o)
DEPS = $(SRCS:.cpp=.d)
PROGRAMS=g2_ircddb g2_link dvap_rptr dvrptr g2link_test g2link_test_audio mmdvm_modem
IRCDDB.o : IRCDDB.cpp IRCDDB.h IRCutils.h all : $(PROGRAMS)
g++ -c $(CPPFLAGS) IRCDDB.cpp
IRCClient.o : IRCClient.cpp IRCClient.h IRCutils.h
g++ -c $(CPPFLAGS) IRCClient.cpp
IRCReceiver.o : IRCReceiver.cpp IRCReceiver.h IRCMessageQueue.h IRCutils.h
g++ -c $(CPPFLAGS) IRCReceiver.cpp
IRCMessageQueue.o : IRCMessageQueue.cpp IRCMessageQueue.h IRCMessage.h
g++ -c $(CPPFLAGS) IRCMessageQueue.cpp
IRCProtocol.o : IRCProtocol.cpp IRCProtocol.h IRCutils.h
g++ -c $(CPPFLAGS) IRCProtocol.cpp
IRCMessage.o : IRCMessage.cpp IRCMessage.h g2_ircddb : $(IRCOBJS) g2_ircddb.o aprs.o
g++ -c $(CPPFLAGS) IRCMessage.cpp g++ $(CPPFLAGS) -o g2_ircddb g2_ircddb.o aprs.o $(IRCOBJS) $(LDFLAGS) -pthread
IRCDDBApp.o : IRCDDBApp.cpp IRCDDBApp.h IRCutils.h g2_link : g2_link.o
g++ -c $(CPPFLAGS) IRCDDBApp.cpp g++ $(CPPFLAGS) -o g2_link g2_link.o $(LDFLAGS) -pthread
aprs.o : aprs.cpp aprs.h mmdvm_modem : mmdvm_modem.o
g++ -c $(CPPFLAGS) aprs.cpp g++ $(CPPFLAGS) -o mmdvm_modem mmdvm_modem.o $(LDFLAGS) -pthread
DVAPDongle.o : DVAPDongle.cpp DVAPDongle.h dvap_rptr : dvap_rptr.o DVAPDongle.o $(DSTROBJS)
g++ -c $(CPPFLAGS) DVAPDongle.cpp g++ $(CPPFLAGS) -o dvap_rptr dvap_rptr.o DVAPDongle.o $(DSTROBJS) $(LDFLAGS) -pthread
golay23.o : golay23.cpp golay23.h dvrptr : dvrptr.o $(DSTROBJS)
g++ -c $(CPPFLAGS) golay23.cpp g++ $(CPPFLAGS) -o dvrptr dvrptr.o $(DSTROBJS) $(LDFLAGS)
dstar_dv.o : dstar_dv.cpp dstar_dv.h golay23.h g2link_test : g2link_test.o
g++ -c $(CPPFLAGS) dstar_dv.cpp g++ $(CPPFLAGS) -o g2link_test g2link_test.o -lrt
g2link_test : g2link_test.cpp g2link_test_audio : g2link_test_audio.o
g++ $(CPPFLAGS) -o g2link_test g2link_test.cpp -lrt g++ $(CPPFLAGS) -o g2link_test_audio g2link_test_audio.o -lrt
g2link_test_audio : g2link_test_audio.cpp %.o : %.cpp
g++ $(CPPFLAGS) -o g2link_test_audio g2link_test_audio.cpp -lrt g++ $(CPPFLAGS) -MMD -MD -c $< -o $@
IRCApplication.h : IRCMessageQueue.h .PHONY: clean
IRCClient.h : IRCReceiver.h IRCMessageQueue.h IRCProtocol.h IRCApplication.h
IRCDDBApp.h : IRCDDB.h IRCApplication.h
IRCMessageQueue.h : IRCMessage.h
IRCProtocol.h : IRCMessageQueue.h IRCApplication.h
IRCReceiver.h : IRCMessageQueue.h
clean : clean:
/bin/rm -f *.o $(RM) $(OBJS) $(DEPS) $(PROGRAMS)
realclean : -include $(DEPS)
/bin/rm -f *.o $(PROGRAMS)
installdvap : dvap_rptr g2_link g2_ircddb installdvap : dvap_rptr g2_link g2_ircddb
######### g2_ircddb ######### ######### g2_ircddb #########
/bin/cp -f g2_ircddb $(BINDIR) /bin/cp -f g2_ircddb $(BINDIR)
/bin/cp -f g2.cfg $(CFGDIR) /bin/cp -f g2.cfg $(CFGDIR)
/bin/cp -f service.g2_ircddb /etc/init.d/g2_ircddb /bin/cp -f service.g2_ircddb /etc/init.d/g2_ircddb
/usr/sbin/update-rc.d g2_ircddb defaults # /usr/sbin/update-rc.d g2_ircddb defaults
/usr/sbin/update-rc.d g2_ircddb enable # /usr/sbin/update-rc.d g2_ircddb enable
######### g2_link ######### ######### g2_link #########
/bin/cp -f g2_link $(BINDIR) /bin/cp -f g2_link $(BINDIR)
/bin/cp -f announce/*.dat $(CFGDIR) /bin/cp -f announce/*.dat $(CFGDIR)
/bin/cp -f gwys.txt $(CFGDIR) /bin/cp -f gwys.txt $(CFGDIR)
/bin/cp -f exec_?.sh $(CFGDIR) /bin/cp -f exec_?.sh $(CFGDIR)
/bin/cp -f service.g2_link /etc/init.d/g2_link /bin/cp -f service.g2_link /etc/init.d/g2_link
/usr/sbin/update-rc.d g2_link defaults # /usr/sbin/update-rc.d g2_link defaults
/usr/sbin/update-rc.d g2_link enable # /usr/sbin/update-rc.d g2_link enable
######### dvap_rptr ######### ######### dvap_rptr #########
/bin/cp -f dvap_rptr $(BINDIR) /bin/cp -f dvap_rptr $(BINDIR)
/bin/cp -f dvap_rptr.sh $(BINDIR) /bin/cp -f dvap_rptr.sh $(BINDIR)
/bin/cp -f service.dvap_rptr /etc/init.d/dvap_rptr /bin/cp -f service.dvap_rptr /etc/init.d/dvap_rptr
/usr/sbin/update-rc.d dvap_rptr defaults # /usr/sbin/update-rc.d dvap_rptr defaults
/usr/sbin/update-rc.d dvap_rptr enable # /usr/sbin/update-rc.d dvap_rptr enable
installdvrptr : dvrptr g2_link g2_ircddb installdvrptr : dvrptr g2_link g2_ircddb
######### g2_ircddb ######### ######### g2_ircddb #########
/bin/cp -f g2_ircddb $(BINDIR) /bin/cp -f g2_ircddb $(BINDIR)
/bin/cp -f g2.cfg $(CFGDIR) /bin/cp -f g2.cfg $(CFGDIR)
/bin/cp -f service.g2_ircddb /etc/init.d/g2_ircddb /bin/cp -f service.g2_ircddb /etc/init.d/g2_ircddb
/usr/sbin/update-rc.d g2_ircddb defaults # /usr/sbin/update-rc.d g2_ircddb defaults
/usr/sbin/update-rc.d g2_ircddb enable # /usr/sbin/update-rc.d g2_ircddb enable
######### g2_link ######### ######### g2_link #########
/bin/cp -f g2_link $(BINDIR) /bin/cp -f g2_link $(BINDIR)
/bin/cp -f announce/*.dat $(CFGDIR) /bin/cp -f announce/*.dat $(CFGDIR)
/bin/cp -f gwys.txt $(CFGDIR) /bin/cp -f gwys.txt $(CFGDIR)
/bin/cp -f exec_?.sh $(CFGDIR) /bin/cp -f exec_?.sh $(CFGDIR)
/bin/cp -f service.g2_link /etc/init.d/g2_link /bin/cp -f service.g2_link /etc/init.d/g2_link
/usr/sbin/update-rc.d g2_link defaults # /usr/sbin/update-rc.d g2_link defaults
/usr/sbin/update-rc.d g2_link enable # /usr/sbin/update-rc.d g2_link enable
######### dvrptr ########## ######### dvrptr ##########
/bin/cp -f dvrptr $(BINDIR) /bin/cp -f dvrptr $(BINDIR)
/bin/cp -f dvrptr.sh $(BINDIR) /bin/cp -f dvrptr.sh $(BINDIR)
/bin/cp -f service.dvrptr /etc/init.d/dvrptr /bin/cp -f service.dvrptr /etc/init.d/dvrptr
/usr/sbin/update-rc.d dvrptr defaults # /usr/sbin/update-rc.d dvrptr defaults
/usr/sbin/update-rc.d dvrptr enable # /usr/sbin/update-rc.d dvrptr enable
installdtmfs : g2link_test installdtmfs : g2link_test
/bin/cp -f g2link_test $(BINDIR) /bin/cp -f g2link_test $(BINDIR)
/bin/cp -f proc_g2_ircddb_dtmfs.sh $(BINDIR) /bin/cp -f proc_g2_ircddb_dtmfs.sh $(BINDIR)
/bin/cp -f service.proc_g2_ircddb_dtmfs /etc/init.d/proc_g2_ircddb_dtmfs /bin/cp -f service.proc_g2_ircddb_dtmfs /etc/init.d/proc_g2_ircddb_dtmfs
/usr/sbin/update-rc.d proc_g2_ircddb_dtmfs defaults # /usr/sbin/update-rc.d proc_g2_ircddb_dtmfs defaults
/usr/sbin/update-rc.d proc_g2_ircddb_dtmfs enable # /usr/sbin/update-rc.d proc_g2_ircddb_dtmfs enable
uninstalldtmfs: uninstalldtmfs:
/usr/sbin/service proc_g2_ircddb_dtmfs stop # /usr/sbin/service proc_g2_ircddb_dtmfs stop
/bin/rm -f /etc/init.d/proc_g2_ircddb_dtmfs # /bin/rm -f /etc/init.d/proc_g2_ircddb_dtmfs
/usr/sbin/update-rc.d proc_g2_ircddb_dtmfs remove # /usr/sbin/update-rc.d proc_g2_ircddb_dtmfs remove
/bin/rm -f $(BINDIR)/proc_g2_ircddb_dtmfs.sh /bin/rm -f $(BINDIR)/proc_g2_ircddb_dtmfs.sh
/bin/rm -f $(BINDIR)/g2link_test /bin/rm -f $(BINDIR)/g2link_test
uninstalldvap : uninstalldvap :
######### g2_ircddb ######### ######### g2_ircddb #########
/usr/sbin/service g2_ircddb stop # /usr/sbin/service g2_ircddb stop
/bin/rm -f /etc/init.d/g2_ircddb # /bin/rm -f /etc/init.d/g2_ircddb
/usr/sbin/update-rc.d g2_ircddb remove # /usr/sbin/update-rc.d g2_ircddb remove
/bin/rm -f $(BINDIR)/g2_ircddb /bin/rm -f $(BINDIR)/g2_ircddb
/bin/rm -f $(CFGDIR)/g2.cfg /bin/rm -f $(CFGDIR)/g2.cfg
######### g2_link ######### ######### g2_link #########
/usr/sbin/service g2_link stop # /usr/sbin/service g2_link stop
/bin/rm -f /etc/init.d/g2_link # /bin/rm -f /etc/init.d/g2_link
/usr/sbin/update-rc.d g2_link remove # /usr/sbin/update-rc.d g2_link remove
/bin/rm -f $(BINDIR)/g2_link /bin/rm -f $(BINDIR)/g2_link
/bin/rm -f $(CFGDIR)/already_linked.dat /bin/rm -f $(CFGDIR)/already_linked.dat
/bin/rm -f $(CFGDIR)/already_unlinked.dat /bin/rm -f $(CFGDIR)/already_unlinked.dat
@ -177,23 +148,23 @@ uninstalldvap :
/bin/rm -f $(CFGDIR)/exec_?.sh /bin/rm -f $(CFGDIR)/exec_?.sh
/bin/rm -f /var/log/g2_link.log /bin/rm -f /var/log/g2_link.log
######### dvap_rptr ######### ######### dvap_rptr #########
/usr/sbin/service dvap_rptr stop # /usr/sbin/service dvap_rptr stop
/bin/rm -f /etc/init.d/dvap_rptr # /bin/rm -f /etc/init.d/dvap_rptr
/usr/sbin/update-rc.d dvap_rptr remove # /usr/sbin/update-rc.d dvap_rptr remove
/bin/rm -f $(BINDIR)/dvap_rptr # /bin/rm -f $(BINDIR)/dvap_rptr
/bin/rm -f $(BINDIR)/dvap_rptr.sh # /bin/rm -f $(BINDIR)/dvap_rptr.sh
uninstalldvrptr: uninstalldvrptr:
######### g2_ircddb ######### ######### g2_ircddb #########
/usr/sbin/service g2_ircddb stop # /usr/sbin/service g2_ircddb stop
/bin/rm -f /etc/init.d/g2_ircddb # /bin/rm -f /etc/init.d/g2_ircddb
/usr/sbin/update-rc.d g2_ircddb remove # /usr/sbin/update-rc.d g2_ircddb remove
/bin/rm -f $(BINDIR)/g2_ircddb # /bin/rm -f $(BINDIR)/g2_ircddb
/bin/rm -f $(CFGDIR)/g2.cfg # /bin/rm -f $(CFGDIR)/g2.cfg
######### g2_link ######### ######### g2_link #########
/usr/sbin/service g2_link stop # /usr/sbin/service g2_link stop
/bin/rm -f /etc/init.d/g2_link # /bin/rm -f /etc/init.d/g2_link
/usr/sbin/update-rc.d g2_link remove # /usr/sbin/update-rc.d g2_link remove
/bin/rm -f $(BINDIR)/g2_link /bin/rm -f $(BINDIR)/g2_link
/bin/rm -f $(CFGDIR)/already_linked.dat /bin/rm -f $(CFGDIR)/already_linked.dat
/bin/rm -f $(CFGDIR)/already_unlinked.dat /bin/rm -f $(CFGDIR)/already_unlinked.dat
@ -206,8 +177,8 @@ uninstalldvrptr:
/bin/rm -f $(CFGDIR)/exec_?.sh /bin/rm -f $(CFGDIR)/exec_?.sh
/bin/rm -f /var/log/g2_link.log /bin/rm -f /var/log/g2_link.log
######### dvrptr ########## ######### dvrptr ##########
/usr/sbin/service dvrptr stop # /usr/sbin/service dvrptr stop
/bin/rm -f /etc/init.d/dvrptr # /bin/rm -f /etc/init.d/dvrptr
/usr/sbin/update-rc.d dvrtpr remove # /usr/sbin/update-rc.d dvrtpr remove
/bin/rm -f $(BINDIR)/dvrptr /bin/rm -f $(BINDIR)/dvrptr
/bin/rm -f $(BINDIR)/dvrptr.sh /bin/rm -f $(BINDIR)/dvrptr.sh

@ -320,7 +320,7 @@ static int read_config(const char *cfgFile)
return 1; return 1;
} }
get_value(cfg, "gateway.internal.port", G2_PORT, 10000, 65535, 19000); get_value(cfg, "gateway.internal.port", G2_PORT, 10000, 65535, 20010);
if (get_value(cfg, std::string(dvap_path+".serial_number").c_str(), value, 8, 10, "APXXXXXX")) if (get_value(cfg, std::string(dvap_path+".serial_number").c_str(), value, 8, 10, "APXXXXXX"))
strcpy(DVP_SERIAL, value.c_str()); strcpy(DVP_SERIAL, value.c_str());

@ -1976,7 +1976,7 @@ static int read_config(const char *cfgFile)
return 1; return 1;
} }
get_value(cfg, "gateway.internal.port", GATEWAY_PORT, 10000, 65535, 19000); get_value(cfg, "gateway.internal.port", GATEWAY_PORT, 10000, 65535, 20010);
get_value(cfg, std::string(path+".rf_tx_level").c_str(), RF_AUDIO_Level, 1, 100, 80); get_value(cfg, std::string(path+".rf_tx_level").c_str(), RF_AUDIO_Level, 1, 100, 80);

@ -21,7 +21,7 @@ gateway = {
internal = { internal = {
# ip = "0.0.0.0" # ip = "0.0.0.0"
# port = 19000 # port = 20010
} }
} }

@ -314,7 +314,7 @@ bool CG2_ircddb::read_config(char *cfgFile)
if (! get_value(cfg, "gateway.internal.ip", g2_internal.ip, 7, IP_SIZE, "0.0.0.0")) if (! get_value(cfg, "gateway.internal.ip", g2_internal.ip, 7, IP_SIZE, "0.0.0.0"))
return true; return true;
get_value(cfg, "gateway.internal.port", g2_internal.port, 16000, 65535, 19000); get_value(cfg, "gateway.internal.port", g2_internal.port, 16000, 65535, 20010);
if (! get_value(cfg, "g2_link.outgoing_ip", g2_link.ip, 7, IP_SIZE, "127.0.0.1")) if (! get_value(cfg, "g2_link.outgoing_ip", g2_link.ip, 7, IP_SIZE, "127.0.0.1"))
return true; return true;

@ -148,10 +148,10 @@ int main(int argc, char **argv)
if (argc != 10) { if (argc != 10) {
printf("Usage: g2link_test <IPaddress> <port> <textMessage> <repeaterCallsign> <module> <delay_between> <delay_before> <MYCALL> <YRCALL>\n"); printf("Usage: g2link_test <IPaddress> <port> <textMessage> <repeaterCallsign> <module> <delay_between> <delay_before> <MYCALL> <YRCALL>\n");
printf("Example: g2link_test 127.0.0.1 19000 \"HELLO\" KJ4NHF B 20 2 KI4LKF XRF005AL\n"); printf("Example: g2link_test 127.0.0.1 20010 \"HELLO\" KJ4NHF B 20 2 KI4LKF XRF005AL\n");
printf("Where...\n\n"); printf("Where...\n\n");
printf(" 127.0.0.1 is the G2 INTERNAL IP of the G2 gateway\n"); printf(" 127.0.0.1 is the G2 INTERNAL IP of the G2 gateway\n");
printf(" 19000 is the the G2 INTERNAL port of the G2 gateway\n"); printf(" 20010 is the the G2 INTERNAL port of the G2 gateway\n");
printf(" HELLO is the text message that we will send, no more than 20 characters\n"); printf(" HELLO is the text message that we will send, no more than 20 characters\n");
printf(" Note: the text message will be converted to UPPERCASE\n"); printf(" Note: the text message will be converted to UPPERCASE\n");
printf(" KJ4NHF is your dstar repeater callsign\n"); printf(" KJ4NHF is your dstar repeater callsign\n");

@ -133,10 +133,10 @@ int main(int argc, char **argv)
if (argc != 10) { if (argc != 10) {
printf("Usage: g2link_test_audio <IPaddress> <port> <dvtoolFile> <repeaterCallsign> <module> <delay_between> <delay_before> <MYCALL> <YRCALL>\n"); printf("Usage: g2link_test_audio <IPaddress> <port> <dvtoolFile> <repeaterCallsign> <module> <delay_between> <delay_before> <MYCALL> <YRCALL>\n");
printf("Example: g2link_test_audio 127.0.0.1 19000 somefile.dvtool KJ4NHF B 19 2 KI4LKF CQCQCQ\n"); printf("Example: g2link_test_audio 127.0.0.1 20010 somefile.dvtool KJ4NHF B 19 2 KI4LKF CQCQCQ\n");
printf("Where...\n"); printf("Where...\n");
printf(" 127.0.0.1 is the IP address of the local G2\n"); printf(" 127.0.0.1 is the IP address of the local G2\n");
printf(" 19000 is the port of the INTERNAL G2\n"); printf(" 20010 is the port of the INTERNAL G2\n");
printf(" somefile.dvtool is a dvtool file\n"); printf(" somefile.dvtool is a dvtool file\n");
printf(" KJ4NHF is your G2 callsign, dont use KJ4NHF\n"); printf(" KJ4NHF is your G2 callsign, dont use KJ4NHF\n");
printf(" B is one of your modules\n"); printf(" B is one of your modules\n");

@ -0,0 +1,262 @@
/*
* Copyright (C) 2018 by Thomas A. Early N7TAE
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <exception>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <csignal>
#include <ctime>
#include "versions.h"
#include "mmdvm_modem.h"
std::atomic<bool> CMMDVMModem::keep_running(true);
CMMDVMModem::CMMDVMModem()
{
}
CMMDVMModem::~CMMDVMModem()
{
}
bool CMMDVMModem::Initialize(const char *cfgfile)
{
if (ReadConfig(cfgfile))
return true;
struct sigaction act;
act.sa_handler = &CMMDVMModem::SignalCatch;
sigemptyset(&act.sa_mask);
if (sigaction(SIGTERM, &act, 0) != 0) {
printf("sigaction-TERM failed, error=%d\n", errno);
return true;
}
if (sigaction(SIGHUP, &act, 0) != 0) {
printf("sigaction-HUP failed, error=%d\n", errno);
return true;
}
if (sigaction(SIGINT, &act, 0) != 0) {
printf("sigaction-INT failed, error=%d\n", errno);
return true;
}
// dstar_dv_init();
try {
mmdvm_future = std::async(std::launch::async, &CMMDVMModem::ProcessMMDVM, this);
} catch (const std::exception &e) {
printf("Unable to start ReadDVAPThread(). Exception: %s\n", e.what());
keep_running = false;
}
printf("Started ProcessMMDVM() thread\n");
return false;
}
void CMMDVMModem::ProcessGateway()
{
}
void CMMDVMModem::ProcessMMDVM()
{
}
bool CMMDVMModem::GetValue(const Config &cfg, const char *path, int &value, const int min, const int max, const int default_value)
{
if (cfg.lookupValue(path, value)) {
if (value < min || value > max)
value = default_value;
} else
value = default_value;
printf("%s = [%d]\n", path, value);
return true;
}
bool CMMDVMModem::GetValue(const Config &cfg, const char *path, double &value, const double min, const double max, const double default_value)
{
if (cfg.lookupValue(path, value)) {
if (value < min || value > max)
value = default_value;
} else
value = default_value;
printf("%s = [%lg]\n", path, value);
return true;
}
bool CMMDVMModem::GetValue(const Config &cfg, const char *path, bool &value, const bool default_value)
{
if (! cfg.lookupValue(path, value))
value = default_value;
printf("%s = [%s]\n", path, value ? "true" : "false");
return true;
}
bool CMMDVMModem::GetValue(const Config &cfg, const char *path, std::string &value, int min, int max, const char *default_value)
{
if (cfg.lookupValue(path, value)) {
int l = value.length();
if (l<min || l>max) {
printf("%s value '%s' is wrong size\n", path, value.c_str());
return false;
}
} else
value = default_value;
printf("%s = [%s]\n", path, value.c_str());
return true;
}
// process configuration file and return true if there was a problem
bool CMMDVMModem::ReadConfig(const char *cfgFile)
{
Config cfg;
printf("Reading file %s\n", cfgFile);
// Read the file. If there is an error, report it and exit.
try {
cfg.readFile(cfgFile);
}
catch(const FileIOException &fioex) {
printf("Can't read %s\n", cfgFile);
return true;
}
catch(const ParseException &pex) {
printf("Parse error at %s:%d - %s\n", pex.getFile(), pex.getLine(), pex.getError());
return true;
}
std::string mmdvm_path, value;
int i;
for (i=0; i<3; i++) {
mmdvm_path = "module.";
mmdvm_path += ('a' + i);
if (cfg.lookupValue(mmdvm_path + ".type", value)) {
if (0 == strcasecmp(value.c_str(), "mmdvm"))
break;
}
}
if (i >= 3) {
printf("mmdvm not defined in any module!\n");
return true;
}
RPTR_MOD = 'A' + i;
if (cfg.lookupValue(std::string(mmdvm_path+".callsign").c_str(), value) || cfg.lookupValue("ircddb.login", value)) {
int l = value.length();
if (l<3 || l>CALL_SIZE-2) {
printf("Call '%s' is invalid length!\n", value.c_str());
return true;
} else {
for (i=0; i<l; i++) {
if (islower(value[i]))
value[i] = toupper(value[i]);
}
value.resize(CALL_SIZE, ' ');
}
strcpy(RPTR, value.c_str());
} else {
printf("%s.login is not defined!\n", mmdvm_path.c_str());
return true;
}
if (cfg.lookupValue("ircddb.login", value)) {
int l = value.length();
if (l<3 || l>CALL_SIZE-2) {
printf("Call '%s' is invalid length!\n", value.c_str());
return true;
} else {
for (i=0; i<l; i++) {
if (islower(value[i]))
value[i] = toupper(value[i]);
}
value.resize(CALL_SIZE, ' ');
}
strcpy(OWNER, value.c_str());
printf("ircddb.login = [%s]\n", OWNER);
} else {
printf("ircddb.login is not defined!\n");
return true;
}
if (GetValue(cfg, std::string(mmdvm_path+".internal_ip").c_str(), value, 7, IP_SIZE, "0.0.0.0"))
strcpy(RPTR_VIRTUAL_IP, value.c_str());
else
return true;
GetValue(cfg, std::string(mmdvm_path+".port").c_str(), i, 10000, 65535, 20010);
RPTR_PORT = (unsigned short)i;
if (GetValue(cfg, "gateway.ip", value, 7, IP_SIZE, "127.0.0.1"))
strcpy(G2_INTERNAL_IP, value.c_str());
else
return true;
GetValue(cfg, "gateway.internal.port", i, 10000, 65535, 20010);
G2_PORT = (unsigned short)i;
GetValue(cfg, "timing.play.delay", DELAY_BETWEEN, 9, 25, 19);
GetValue(cfg, "timing.play.wait", DELAY_BEFORE, 1, 10, 2);
GetValue(cfg, std::string(mmdvm_path+".acknowledge").c_str(), RPTR_ACK, false);
GetValue(cfg, std::string(mmdvm_path+".packet_wait").c_str(), WAIT_FOR_PACKETS, 6, 100, 25);
return false;
}
void CMMDVMModem::SignalCatch(int signum)
{
if ((signum == SIGTERM) || (signum == SIGINT) || (signum == SIGHUP))
keep_running = false;
exit(0);
}
int main(int argc, const char **argv)
{
setbuf(stdout, NULL);
if (2 != argc) {
printf("usage: %s path_to_config_file\n", argv[0]);
printf(" %s --version\n", argv[0]);
return 1;
}
if ('-' == argv[1][0]) {
printf("\nMMDVM Modem Version #%s Copyright (C) 2018 by Thomas A. Early N7TAE\n", MMDVM_VERSION);
printf("MMDVM Modem comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n");
printf("This is free software, and you are welcome to distribute it\nunder certain conditions that are discussed in the LICENSE file.\n\n");
return 0;
}
CMMDVMModem mmdvm;
if (mmdvm.Initialize(argv[1])) {
printf("ERROR: Failed to process %s\n", argv[0]);
return 1;
}
while (mmdvm.keep_running) {
mmdvm.ProcessGateway();
}
mmdvm.mmdvm_future.get();
printf("%s is closed.\n", argv[0]);
return 0;
}

@ -0,0 +1,68 @@
/*
* Copyright (C) 2018 by Thomas A. Early N7TAE
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#pragma once
#include <atomic>
#include <string>
#include <future>
#include <libconfig.h++>
using namespace libconfig;
#define CALL_SIZE 8
#define IP_SIZE 15
class CMMDVMModem
{
public:
// functions
CMMDVMModem();
~CMMDVMModem();
bool Initialize(const char *cfgfile);
void ProcessGateway();
// data
static std::atomic<bool> keep_running;
std::future<void> mmdvm_future;
private:
// functions
void ProcessMMDVM();
static void SignalCatch(int signum);
// read configuration file
bool ReadConfig(const char *);
bool GetValue(const Config &cfg, const char *path, int &value, const int min, const int max, const int default_value);
bool GetValue(const Config &cfg, const char *path, double &value, const double min, const double max, const double default_value);
bool GetValue(const Config &cfg, const char *path, bool &value, const bool default_value);
bool GetValue(const Config &cfg, const char *path, std::string &value, const int min, const int max, const char *default_value);
// config data
char RPTR_MOD;
char RPTR[CALL_SIZE + 1];
char OWNER[CALL_SIZE + 1];
char RPTR_VIRTUAL_IP[IP_SIZE + 1];
char G2_INTERNAL_IP[IP_SIZE + 1];
unsigned short RPTR_PORT, G2_PORT;
int WAIT_FOR_PACKETS, DELAY_BEFORE, DELAY_BETWEEN;
bool RPTR_ACK;
// parameters
};

@ -3,4 +3,4 @@
#define LINK_VERSION "5.1.2" #define LINK_VERSION "5.1.2"
#define DVAP_VERSION "linux-dvap_rptr-5.1.1" #define DVAP_VERSION "linux-dvap_rptr-5.1.1"
#define DVRPTR_VERSION "linux-dvrptr-5.1.0" #define DVRPTR_VERSION "linux-dvrptr-5.1.0"
#define MMDVM_VERSION "mmdvm-dvmega-0.0.0" #define MMDVM_VERSION "mmdvm-dvmega-0.1.0"

Loading…
Cancel
Save

Powered by TurnKey Linux.