Skip to content

Commit

Permalink
remove native SDR code (the approach/mechanism way this is done needs…
Browse files Browse the repository at this point in the history
… to be rethought, ZMQ is a poor way of doing this as it only provides the same FSK-level modulation we currently have); compress debug messages;
  • Loading branch information
gatekeep committed Dec 18, 2023
1 parent a2c7878 commit 826255c
Show file tree
Hide file tree
Showing 29 changed files with 104 additions and 2,743 deletions.
2 changes: 1 addition & 1 deletion CWIdTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ uint8_t CWIdTX::write(const uint8_t* data, uint8_t length)

m_poLen += 5U;

DEBUG2("CWIdTx: write(): message created with length", m_poLen);
DEBUG2("CWIdTx::write() message length", m_poLen);

return RSN_OK;
}
Expand Down
5 changes: 0 additions & 5 deletions Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@
#include <cstring>
#endif

#if !defined(NATIVE_SDR)
#include <arm_math.h>
#else
#include "sdr/arm_math.h"
#endif

// ---------------------------------------------------------------------------
// Types
Expand Down Expand Up @@ -168,7 +164,6 @@ const uint8_t BIT_MASK_TABLE[] = { 0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x0
#define CPU_TYPE_ARDUINO_DUE 0x00U
#define CPU_TYPE_NXP 0x01U
#define CPU_TYPE_STM32 0x02U
#define CPU_TYPE_NATIVE_SDR 0xF0U

// ---------------------------------------------------------------------------
// Macros
Expand Down
294 changes: 0 additions & 294 deletions FirmwareMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,6 @@
*/
#include "Globals.h"

#if defined(NATIVE_SDR)
#include "sdr/port/PseudoPTYPort.h"

#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <pwd.h>
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>

#include <zmq.hpp>
#endif

// ---------------------------------------------------------------------------
// Macros
// ---------------------------------------------------------------------------

#if defined(NATIVE_SDR)
#define IS(s) (::strcmp(argv[i], s) == 0)
#endif

// ---------------------------------------------------------------------------
// Globals Variables
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -109,29 +85,6 @@ IO io;
Digipot digipot;
#endif

#if defined(NATIVE_SDR)
std::string g_progExe = std::string(__EXE_NAME__);

std::string m_zmqRx = std::string("ipc:///tmp/dvm-rx.ipc");
std::string m_zmqTx = std::string("ipc:///tmp/dvm-tx.ipc");

std::string m_ptyPort = std::string("/dev/ptmx");

std::string g_logFileName = std::string("dsp.log");

bool g_debug = false;

int g_signal = 0;
bool g_killed = false;

bool g_daemon = false;

extern sdr::port::PseudoPTYPort* m_serialPort;

extern zmq::socket_t m_zmqSocketTx;
extern zmq::socket_t m_zmqSocketRx;
#endif

// ---------------------------------------------------------------------------
// Global Functions
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -281,250 +234,3 @@ int main()
loop();
}
#endif // defined(STM32F4XX)

#if defined(NATIVE_SDR)
void fatal(const char* message)
{
::fprintf(stderr, "%s: %s\n", g_progExe.c_str(), message);
exit(EXIT_FAILURE);
}

void usage(const char* message, const char* arg)
{
::fprintf(stdout, "" DESCRIPTION " (built %s)\r\n", __BUILD__);
::fprintf(stdout, "Copyright (c) 2022 Bryan Biedenkapp, N2PLL and DVMProject (https://github.com/dvmproject) Authors.\n");
::fprintf(stdout, "Portions Copyright (c) 2015-2021 by Jonathan Naylor, G4KLX and others\n\n");
if (message != nullptr) {
::fprintf(stderr, "%s: ", g_progExe.c_str());
::fprintf(stderr, message, arg);
::fprintf(stderr, "\n\n");
}

::fprintf(stdout, "usage: %s [-bdvh] [-r <ZeroMQ Rx IPC Endpoint>] [-t <ZeroMQ Tx IPC Endpoint>] [-p <PTY port>] [-l <log filename>]\n\n"
" -r ZeroMQ Rx IPC Endpoint\n"
" -t ZeroMQ Tx IPC Endpoint\n"
" -p PTY Port\n"
" -l Log Filename\n"
"\n"
" -b background process\n"
"\n"
" -d enable debug\n"
" -v show version information\n"
" -h show this screen\n"
" -- stop handling options\n",
g_progExe.c_str());
exit(EXIT_FAILURE);
}

int checkArgs(int argc, char* argv[])
{
int i, p = 0;

// iterate through arguments
for (i = 1; i <= argc; i++)
{
if (argv[i] == nullptr) {
break;
}

if (*argv[i] != '-') {
continue;
}
else if (IS("--")) {
++p;
break;
}
else if (IS("-r")) {
if ((argc - 1) <= 0)
usage("error: %s", "must specify the ZeroMQ Rx IPC Endpoint");
m_zmqRx = std::string(argv[++i]);

if (m_zmqRx == "")
usage("error: %s", "IPC endpoint cannot be blank!");

p += 2;
}
else if (IS("-t")) {
if ((argc - 1) <= 0)
usage("error: %s", "must specify the ZeroMQ Tx IPC Endpoint");
m_zmqTx = std::string(argv[++i]);

if (m_zmqTx == "")
usage("error: %s", "IPC endpoint cannot be blank!");

p += 2;
}
else if (IS("-p")) {
if ((argc - 1) <= 0)
usage("error: %s", "must specify the PTY port");
m_ptyPort = std::string(argv[++i]);

if (m_ptyPort == "")
usage("error: %s", "PTY port cannot be blank!");

p += 2;
}
else if (IS("-l")) {
if ((argc - 1) <= 0)
usage("error: %s", "must specify the log filename");
g_logFileName = std::string(argv[++i]);

if (g_logFileName == "")
usage("error: %s", "log filename cannot be blank!");

p += 2;
}
else if (IS("-b")) {
++p;
g_daemon = true;
}
else if (IS("-d")) {
++p;
g_debug = true;
}
else if (IS("-v")) {
::fprintf(stdout, "" DESCRIPTION " (built %s)\r\n", __BUILD__);
::fprintf(stdout, "Copyright (c) 2022 Bryan Biedenkapp, N2PLL and DVMProject (https://github.com/dvmproject) Authors.\r\n");
::fprintf(stdout, "Portions Copyright (c) 2015-2021 by Jonathan Naylor, G4KLX and others\r\n");
if (argc == 2)
exit(EXIT_SUCCESS);
}
else if (IS("-h")) {
usage(nullptr, nullptr);
if (argc == 2)
exit(EXIT_SUCCESS);
}
else {
usage("unrecognized option `%s'", argv[i]);
}
}

if (p < 0 || p > argc) {
p = 0;
}

return ++p;
}

static void sigHandler(int signum)
{
g_killed = true;
g_signal = signum;
}

// ---------------------------------------------------------------------------
// Program Entry Point
// ---------------------------------------------------------------------------

int main(int argc, char** argv)
{
m_zmqRx = std::string("ipc:///tmp/dvm-rx.ipc");
m_zmqTx = std::string("ipc:///tmp/dvm-tx.ipc");

if (argv[0] != nullptr && *argv[0] != 0)
g_progExe = std::string(argv[0]);

if (argc > 1) {
// check arguments
int i = checkArgs(argc, argv);
if (i < argc) {
argc -= i;
argv += i;
}
else {
argc--;
argv++;
}
}

::signal(SIGINT, sigHandler);
::signal(SIGTERM, sigHandler);
::signal(SIGHUP, sigHandler);

// initialize system logging
bool ret = ::LogInitialise(".", g_logFileName.c_str(), 1U, 1U);
if (!ret) {
::fprintf(stderr, "unable to open the log file\n");
return 1;
}

// handle POSIX process forking
if (g_daemon) {
// create new process
pid_t pid = ::fork();
if (pid == -1) {
::fprintf(stderr, "%s: Couldn't fork() , exiting\n", g_progExe.c_str());
::LogFinalise();
return EXIT_FAILURE;
}
else if (pid != 0) {
::LogFinalise();
exit(EXIT_SUCCESS);
}

// create new session and process group
if (::setsid() == -1) {
::fprintf(stderr, "%s: Couldn't setsid(), exiting\n", g_progExe.c_str());
::LogFinalise();
return EXIT_FAILURE;
}

// set the working directory to the root directory
if (::chdir("/") == -1) {
::fprintf(stderr, "%s: Couldn't cd /, exiting\n", g_progExe.c_str());
::LogFinalise();
return EXIT_FAILURE;
}

::close(STDIN_FILENO);
::close(STDOUT_FILENO);
::close(STDERR_FILENO);
}

do {
g_signal = 0;

{
::LogInfo("" DESCRIPTION " (built %s)", __BUILD__);
::LogInfo("Copyright (c) 2017-2022 Bryan Biedenkapp, N2PLL and DVMProject (https://github.com/dvmproject) Authors.");
::LogInfo("Portions Copyright (c) 2015-2021 by Jonathan Naylor, G4KLX and others");

::LogInfoEx(LOG_DSP, "DSP is performing initialization and warmup");
setup();

::LogInfoEx(LOG_DSP, "DSP is up and running");
while (!g_killed) {
loop();
::usleep(1);
}
}

if (g_signal == 2)
::LogInfoEx(LOG_DSP, "Exited on receipt of SIGINT");

if (g_signal == 15)
::LogInfoEx(LOG_DSP, "Exited on receipt of SIGTERM");

if (g_signal == 1)
::LogInfoEx(LOG_DSP, "Restarting on receipt of SIGHUP");
} while (g_signal == 1);

::LogInfoEx(LOG_DSP, "DSP is shutting down");

if (m_serialPort != nullptr) {
m_serialPort->close();
delete m_serialPort;
}

try
{
m_zmqSocketTx.close();
m_zmqSocketRx.close();
}
catch(const zmq::error_t& zmqE) { /* stub */ }
catch(const std::exception& e) { /* stub */ }

::LogFinalise();
return 0;
}
#endif // defined(NATIVE_SDR)
16 changes: 0 additions & 16 deletions Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@
#if !defined(__GLOBALS_H__)
#define __GLOBALS_H__

#if !defined(NATIVE_SDR)
#if defined(STM32F4XX)
#include "stm32f4xx.h"
#include <cstddef>
#else
#include <Arduino.h>
#endif
#endif

#include "Defines.h"
#include "SerialPort.h"
Expand All @@ -54,18 +52,11 @@
#include "nxdn/NXDNRX.h"
#include "nxdn/NXDNTX.h"
#include "nxdn/CalNXDN.h"
#if defined(NATIVE_SDR)
#include "sdr/Log.h"
#endif
#include "CalRSSI.h"
#include "CWIdTX.h"
#include "Digipot.h"
#include "IO.h"

#if defined(NATIVE_SDR)
#include <cstring>
#endif

// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -142,11 +133,4 @@ extern CWIdTX cwIdTX;
extern Digipot digipot;
#endif

#if defined(NATIVE_SDR)
extern std::string m_zmqRx;
extern std::string m_zmqTx;
extern std::string m_ptyPort;
extern bool g_debug;
#endif

#endif // __GLOBALS_H__
4 changes: 2 additions & 2 deletions IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,9 @@ void IO::setMode()
relativeState = serial.calRelativeState(m_modemState);
}

DEBUG3("IO::setMode(): setting modem state", m_modemState, relativeState);
DEBUG3("IO::setMode() setting modem state", m_modemState, relativeState);

DEBUG4("IO::setMode(): setting lights", relativeState == STATE_DMR, relativeState == STATE_P25, relativeState == STATE_NXDN);
DEBUG4("IO::setMode() setting lights", relativeState == STATE_DMR, relativeState == STATE_P25, relativeState == STATE_NXDN);
setDMRInt(relativeState == STATE_DMR);
setP25Int(relativeState == STATE_P25);
setNXDNInt(relativeState == STATE_NXDN);
Expand Down
Loading

0 comments on commit 826255c

Please sign in to comment.