diff --git a/README.md b/README.md
index e50f751..9656b58 100644
--- a/README.md
+++ b/README.md
@@ -78,9 +78,9 @@ Please use the stable version listed above, we cannot support others.
# cp ~/xlxd/scripts/xlxd /etc/init.d/xlxd
```
-###### Adapt the default startup parameters to your needs
+###### Adapt the default configuration to your needs
```
-# pico /etc/init.d/xlxd
+# pico /xlxd/xlxd.config
```
###### Download the dmrid.dat from the XLXAPI server to your xlxd folder
```
diff --git a/config/xlxd.config b/config/xlxd.config
new file mode 100644
index 0000000..42eaccf
--- /dev/null
+++ b/config/xlxd.config
@@ -0,0 +1,15 @@
+#########################################################################################
+# XLXD config file
+#
+# one line per entry
+# each entry specifies an option
+#
+#########################################################################################
+# the reflector callsign - default N0CALL
+callsign N0CALL
+
+# listening IP address - default 0.0.0.0
+listen 0.0.0.0
+
+# AMBE transcoder IP address - default 127.0.0.1
+transcoder 127.0.0.1
\ No newline at end of file
diff --git a/scripts/xlxd b/scripts/xlxd
index 6e86018..633aaa6 100755
--- a/scripts/xlxd
+++ b/scripts/xlxd
@@ -19,7 +19,6 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin
# change below settings according to your system
NAME="xlxd"
DAEMON="/xlxd/xlxd"
-ARGUMENTS="XLX999 192.168.1.240 127.0.0.1"
PIDFILE="/var/log/xlxd.pid"
USER=root
GROUP=root
@@ -31,7 +30,7 @@ start () {
# start daemon
echo -n "Starting $NAME: "
- start-stop-daemon --start --exec $DAEMON --chuid $USER:$GROUP --background -- $ARGUMENTS
+ start-stop-daemon --start --exec $DAEMON --chuid $USER:$GROUP --background
RETVAL=$?
echo
sleep 4
diff --git a/src/cconfig.cpp b/src/cconfig.cpp
new file mode 100755
index 0000000..b562b87
--- /dev/null
+++ b/src/cconfig.cpp
@@ -0,0 +1,104 @@
+//
+// cconfig.cpp
+// xlxd
+//
+// Created by Alessio Caiazza (IU5BON) on 22/07/2022.
+// Copyright © 2022 Alessio Caiazza (IU5BON). 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 "cconfig.h"
+#include "ccallsign.h"
+#include "cip.h"
+#include
+
+
+CConfig::CConfig() :
+ m_Callsign("N0CALL"),
+ m_ListenIp(CIp("0.0.0.0")),
+ m_TranscoderIp(CIp("127.0.0.1"))
+{
+ ReadOptions();
+}
+
+
+void CConfig::DumpConfig()
+{
+ std::cout << "Configuration options" << std::endl;
+ std::cout << "callsign " << GetCallsign() << std::endl;
+ std::cout << "listen " << GetListenIp() << std::endl;
+ std::cout << "transcoder " << GetTranscoderIp() << std::endl;
+ std::cout << std::endl;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////
+// option helpers
+
+char *CConfig::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 CConfig::ReadOptions(void)
+{
+ char sz[256];
+
+ std::ifstream file(CONFIG_PATH);
+ if (file.is_open())
+ {
+ 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, "callsign", 8) == 0)
+ {
+ m_Callsign = CCallsign(szval);
+ }
+ else if (strncmp(szt, "listen", 5) == 0)
+ {
+ m_ListenIp = CIp(szval);
+ }
+ else if (strncmp(szt, "transcoder", 10) == 0)
+ {
+ m_TranscoderIp = CIp(szval);
+ }
+ else
+ {
+ // unknown option - ignore
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/cconfig.h b/src/cconfig.h
new file mode 100644
index 0000000..7d25872
--- /dev/null
+++ b/src/cconfig.h
@@ -0,0 +1,65 @@
+//
+// cconfig.h
+// xlxd
+//
+// Created by Alessio Caiazza (IU5BON) on 22/07/2022.
+// Copyright © 2022 Alessio Caiazza (IU5BON). 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 cconfig_h
+#define cconfig_h
+
+#include
+#include "cip.h"
+#include "ccallsign.h"
+
+////////////////////////////////////////////////////////////////////////////////////////
+// class
+
+class CConfig
+{
+public:
+ // constructor
+ CConfig();
+
+ void DumpConfig();
+
+ // getters
+ const CCallsign &GetCallsign(void) const { return m_Callsign; }
+ const CIp &GetListenIp(void) const { return m_ListenIp; }
+ const CIp &GetTranscoderIp(void) const { return m_TranscoderIp; }
+
+ // setters for bacward compatible CLI parameters
+ void SetCallsign(const CCallsign &callsign) { m_Callsign = callsign; }
+ void SetListenIp(const CIp &ip) { m_ListenIp = ip; }
+ void SetTranscoderIp(const CIp &ip) { m_TranscoderIp = ip; }
+
+protected:
+ // config
+ void ReadOptions(void);
+ char* TrimWhiteSpaces(char *str);
+
+protected:
+ CCallsign m_Callsign;
+ CIp m_ListenIp;
+ CIp m_TranscoderIp;
+};
+
+////////////////////////////////////////////////////////////////////////////////////////
+#endif /* cconfig_h */
diff --git a/src/main.cpp b/src/main.cpp
index 723ab5b..3703cb3 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -24,6 +24,7 @@
#include "main.h"
#include "creflector.h"
+#include "cconfig.h"
#include "syslog.h"
#include
@@ -86,21 +87,34 @@ int main(int argc, const char * argv[])
#endif
+ CConfig conf = CConfig();
+
// check arguments
- if ( argc != 4 )
+ if ( argc == 4 )
+ {
+ conf.SetCallsign(CCallsign(argv[1]));
+ conf.SetListenIp(CIp(argv[2]));
+ conf.SetTranscoderIp(CIp(argv[3]));
+ }
+ else if ( argc != 1 )
{
std::cout << "Usage: xlxd callsign xlxdip ambedip" << std::endl;
std::cout << "example: xlxd XLX999 192.168.178.212 127.0.0.1" << std::endl;
+
+ std::cout << "Startup parameters can also be defined in " << CONFIG_PATH << std::endl;
+
return 1;
}
// splash
std::cout << "Starting xlxd " << VERSION_MAJOR << "." << VERSION_MINOR << "." << VERSION_REVISION << std::endl << std::endl;
+ conf.DumpConfig();
+
// initialize reflector
- g_Reflector.SetCallsign(argv[1]);
- g_Reflector.SetListenIp(CIp(argv[2]));
- g_Reflector.SetTranscoderIp(CIp(CIp(argv[3])));
+ g_Reflector.SetCallsign(conf.GetCallsign());
+ g_Reflector.SetListenIp(conf.GetListenIp());
+ g_Reflector.SetTranscoderIp(conf.GetTranscoderIp());
// and let it run
if ( !g_Reflector.Start() )
diff --git a/src/main.h b/src/main.h
index 26b5ba2..014f8c6 100644
--- a/src/main.h
+++ b/src/main.h
@@ -176,6 +176,9 @@
// system paths -------------------------------------------------
+#ifndef CONFIG_PATH
+#define CONFIG_PATH "/xlxd/xlxd.config"
+#endif
#define XML_PATH "/var/log/xlxd.xml"
#define WHITELIST_PATH "/xlxd/xlxd.whitelist"
#define BLACKLIST_PATH "/xlxd/xlxd.blacklist"