|
12 | 12 | */ |
13 | 13 | #include "Globals.h" |
14 | 14 |
|
15 | | -#if defined(NATIVE_SDR) |
16 | | -#include "sdr/port/PseudoPTYPort.h" |
17 | | - |
18 | | -#include <sys/types.h> |
19 | | -#include <unistd.h> |
20 | | -#include <signal.h> |
21 | | -#include <fcntl.h> |
22 | | -#include <pwd.h> |
23 | | -#include <cstdio> |
24 | | -#include <cassert> |
25 | | -#include <cstdlib> |
26 | | -#include <cstring> |
27 | | - |
28 | | -#include <zmq.hpp> |
29 | | -#endif |
30 | | - |
31 | | -// --------------------------------------------------------------------------- |
32 | | -// Macros |
33 | | -// --------------------------------------------------------------------------- |
34 | | - |
35 | | -#if defined(NATIVE_SDR) |
36 | | -#define IS(s) (::strcmp(argv[i], s) == 0) |
37 | | -#endif |
38 | | - |
39 | 15 | // --------------------------------------------------------------------------- |
40 | 16 | // Globals Variables |
41 | 17 | // --------------------------------------------------------------------------- |
@@ -81,36 +57,9 @@ CalRSSI calRSSI; |
81 | 57 | CWIdTX cwIdTX; |
82 | 58 |
|
83 | 59 | /* RS232 and Air Interface I/O */ |
84 | | -#if defined(NATIVE_SDR) |
85 | | -SerialPortSDR serial; |
86 | | -#else |
87 | 60 | SerialPort serial; |
88 | | -#endif |
89 | 61 | IO io; |
90 | 62 |
|
91 | | -#if defined(NATIVE_SDR) |
92 | | -std::string g_progExe = std::string(__EXE_NAME__); |
93 | | - |
94 | | -std::string m_zmqRx = std::string("ipc:///tmp/dvm-rx.ipc"); |
95 | | -std::string m_zmqTx = std::string("ipc:///tmp/dvm-tx.ipc"); |
96 | | - |
97 | | -std::string m_ptyPort = std::string("/dev/ptmx"); |
98 | | - |
99 | | -std::string g_logFileName = std::string("dsp.log"); |
100 | | - |
101 | | -bool g_debug = false; |
102 | | - |
103 | | -int g_signal = 0; |
104 | | -bool g_killed = false; |
105 | | - |
106 | | -bool g_daemon = false; |
107 | | - |
108 | | -extern sdr::port::PseudoPTYPort* m_serialPort; |
109 | | - |
110 | | -extern zmq::socket_t m_zmqSocketTx; |
111 | | -extern zmq::socket_t m_zmqSocketRx; |
112 | | -#endif |
113 | | - |
114 | 63 | // --------------------------------------------------------------------------- |
115 | 64 | // Global Functions |
116 | 65 | // --------------------------------------------------------------------------- |
@@ -329,263 +278,3 @@ int main() |
329 | 278 | loop(); |
330 | 279 | } |
331 | 280 | #endif // defined(STM32F4XX) |
332 | | - |
333 | | -#if defined(NATIVE_SDR) |
334 | | -void fatal(const char* message) |
335 | | -{ |
336 | | - ::fprintf(stderr, "%s: %s\n", g_progExe.c_str(), message); |
337 | | - exit(EXIT_FAILURE); |
338 | | -} |
339 | | - |
340 | | -void usage(const char* message, const char* arg) |
341 | | -{ |
342 | | - ::fprintf(stdout, "" DESCRIPTION " (built %s)\r\n", __BUILD__); |
343 | | - ::fprintf(stdout, "Copyright (c) 2025 Bryan Biedenkapp, N2PLL and DVMProject (https://github.com/dvmproject) Authors.\n"); |
344 | | - ::fprintf(stdout, "Portions Copyright (c) 2015-2021 by Jonathan Naylor, G4KLX and others\n\n"); |
345 | | - if (message != nullptr) { |
346 | | - ::fprintf(stderr, "%s: ", g_progExe.c_str()); |
347 | | - ::fprintf(stderr, message, arg); |
348 | | - ::fprintf(stderr, "\n\n"); |
349 | | - } |
350 | | - |
351 | | - ::fprintf(stdout, |
352 | | - "usage: %s [-bdvh]" |
353 | | - " [--syslog]" |
354 | | - " [-r <ZeroMQ Rx IPC Endpoint>] [-t <ZeroMQ Tx IPC Endpoint>]" |
355 | | - " [-p <PTY port>]" |
356 | | - " [-l <log filename>]\n\n" |
357 | | - " -b background process\n" |
358 | | - "\n" |
359 | | - " -d enable debug\n" |
360 | | - " -v show version information\n" |
361 | | - " -h show this screen\n" |
362 | | - "\n" |
363 | | - " --syslog force logging to syslog\n" |
364 | | - "\n" |
365 | | - " -r ZeroMQ Rx IPC Endpoint\n" |
366 | | - " -t ZeroMQ Tx IPC Endpoint\n" |
367 | | - "\n" |
368 | | - " -p PTY Port\n" |
369 | | - "\n" |
370 | | - " -l Log Filename\n" |
371 | | - "\n" |
372 | | - " -- stop handling options\n", |
373 | | - g_progExe.c_str()); |
374 | | - exit(EXIT_FAILURE); |
375 | | -} |
376 | | - |
377 | | -int checkArgs(int argc, char* argv[]) |
378 | | -{ |
379 | | - int i, p = 0; |
380 | | - |
381 | | - // iterate through arguments |
382 | | - for (i = 1; i <= argc; i++) |
383 | | - { |
384 | | - if (argv[i] == nullptr) { |
385 | | - break; |
386 | | - } |
387 | | - |
388 | | - if (*argv[i] != '-') { |
389 | | - continue; |
390 | | - } |
391 | | - else if (IS("--")) { |
392 | | - ++p; |
393 | | - break; |
394 | | - } |
395 | | - else if (IS("-r")) { |
396 | | - if ((argc - 1) <= 0) |
397 | | - usage("error: %s", "must specify the ZeroMQ Rx IPC Endpoint"); |
398 | | - m_zmqRx = std::string(argv[++i]); |
399 | | - |
400 | | - if (m_zmqRx == "") |
401 | | - usage("error: %s", "IPC endpoint cannot be blank!"); |
402 | | - |
403 | | - p += 2; |
404 | | - } |
405 | | - else if (IS("-t")) { |
406 | | - if ((argc - 1) <= 0) |
407 | | - usage("error: %s", "must specify the ZeroMQ Tx IPC Endpoint"); |
408 | | - m_zmqTx = std::string(argv[++i]); |
409 | | - |
410 | | - if (m_zmqTx == "") |
411 | | - usage("error: %s", "IPC endpoint cannot be blank!"); |
412 | | - |
413 | | - p += 2; |
414 | | - } |
415 | | - else if (IS("-p")) { |
416 | | - if ((argc - 1) <= 0) |
417 | | - usage("error: %s", "must specify the PTY port"); |
418 | | - m_ptyPort = std::string(argv[++i]); |
419 | | - |
420 | | - if (m_ptyPort == "") |
421 | | - usage("error: %s", "PTY port cannot be blank!"); |
422 | | - |
423 | | - p += 2; |
424 | | - } |
425 | | - else if (IS("-l")) { |
426 | | - if ((argc - 1) <= 0) |
427 | | - usage("error: %s", "must specify the log filename"); |
428 | | - g_logFileName = std::string(argv[++i]); |
429 | | - |
430 | | - if (g_logFileName == "") |
431 | | - usage("error: %s", "log filename cannot be blank!"); |
432 | | - |
433 | | - p += 2; |
434 | | - } |
435 | | - else if (IS("-b")) { |
436 | | - ++p; |
437 | | - g_daemon = true; |
438 | | - } |
439 | | - else if (IS("-d")) { |
440 | | - ++p; |
441 | | - g_debug = true; |
442 | | - } |
443 | | - else if (IS("--syslog")) { |
444 | | - g_useSyslog = true; |
445 | | - } |
446 | | - else if (IS("-v")) { |
447 | | - ::fprintf(stdout, "" DESCRIPTION " (built %s)\r\n", __BUILD__); |
448 | | - ::fprintf(stdout, "Copyright (c) 2022 Bryan Biedenkapp, N2PLL and DVMProject (https://github.com/dvmproject) Authors.\r\n"); |
449 | | - ::fprintf(stdout, "Portions Copyright (c) 2015-2021 by Jonathan Naylor, G4KLX and others\r\n"); |
450 | | - if (argc == 2) |
451 | | - exit(EXIT_SUCCESS); |
452 | | - } |
453 | | - else if (IS("-h")) { |
454 | | - usage(nullptr, nullptr); |
455 | | - if (argc == 2) |
456 | | - exit(EXIT_SUCCESS); |
457 | | - } |
458 | | - else { |
459 | | - usage("unrecognized option `%s'", argv[i]); |
460 | | - } |
461 | | - } |
462 | | - |
463 | | - if (p < 0 || p > argc) { |
464 | | - p = 0; |
465 | | - } |
466 | | - |
467 | | - return ++p; |
468 | | -} |
469 | | - |
470 | | -static void sigHandler(int signum) |
471 | | -{ |
472 | | - g_killed = true; |
473 | | - g_signal = signum; |
474 | | -} |
475 | | - |
476 | | -// --------------------------------------------------------------------------- |
477 | | -// Program Entry Point |
478 | | -// --------------------------------------------------------------------------- |
479 | | - |
480 | | -int main(int argc, char** argv) |
481 | | -{ |
482 | | - m_zmqRx = std::string("ipc:///tmp/dvm-rx.ipc"); |
483 | | - m_zmqTx = std::string("ipc:///tmp/dvm-tx.ipc"); |
484 | | - |
485 | | - if (argv[0] != nullptr && *argv[0] != 0) |
486 | | - g_progExe = std::string(argv[0]); |
487 | | - |
488 | | - if (argc > 1) { |
489 | | - // check arguments |
490 | | - int i = checkArgs(argc, argv); |
491 | | - if (i < argc) { |
492 | | - argc -= i; |
493 | | - argv += i; |
494 | | - } |
495 | | - else { |
496 | | - argc--; |
497 | | - argv++; |
498 | | - } |
499 | | - } |
500 | | - |
501 | | - ::signal(SIGINT, sigHandler); |
502 | | - ::signal(SIGTERM, sigHandler); |
503 | | - ::signal(SIGHUP, sigHandler); |
504 | | - |
505 | | - // initialize system logging |
506 | | - bool ret = ::LogInitialise(".", g_logFileName.c_str(), 1U, 1U); |
507 | | - if (!ret) { |
508 | | - ::fprintf(stderr, "unable to open the log file\n"); |
509 | | - return 1; |
510 | | - } |
511 | | - |
512 | | - // handle POSIX process forking |
513 | | - if (g_daemon) { |
514 | | - // create new process |
515 | | - pid_t pid = ::fork(); |
516 | | - if (pid == -1) { |
517 | | - ::fprintf(stderr, "%s: Couldn't fork() , exiting\n", g_progExe.c_str()); |
518 | | - ::LogFinalise(); |
519 | | - return EXIT_FAILURE; |
520 | | - } |
521 | | - else if (pid != 0) { |
522 | | - ::LogFinalise(); |
523 | | - exit(EXIT_SUCCESS); |
524 | | - } |
525 | | - |
526 | | - // create new session and process group |
527 | | - if (::setsid() == -1) { |
528 | | - ::fprintf(stderr, "%s: Couldn't setsid(), exiting\n", g_progExe.c_str()); |
529 | | - ::LogFinalise(); |
530 | | - return EXIT_FAILURE; |
531 | | - } |
532 | | - |
533 | | - // set the working directory to the root directory |
534 | | - if (::chdir("/") == -1) { |
535 | | - ::fprintf(stderr, "%s: Couldn't cd /, exiting\n", g_progExe.c_str()); |
536 | | - ::LogFinalise(); |
537 | | - return EXIT_FAILURE; |
538 | | - } |
539 | | - |
540 | | - ::close(STDIN_FILENO); |
541 | | - ::close(STDOUT_FILENO); |
542 | | - ::close(STDERR_FILENO); |
543 | | - } |
544 | | - |
545 | | - do { |
546 | | - g_signal = 0; |
547 | | - |
548 | | - { |
549 | | - ::LogInfo("" DESCRIPTION " (built %s)", __BUILD__); |
550 | | - ::LogInfo("Copyright (c) 2017-2025 Bryan Biedenkapp, N2PLL and DVMProject (https://github.com/dvmproject) Authors."); |
551 | | - ::LogInfo("Portions Copyright (c) 2015-2021 by Jonathan Naylor, G4KLX and others"); |
552 | | - |
553 | | - ::LogInfoEx("DSP is performing initialization and warmup"); |
554 | | - setup(); |
555 | | - |
556 | | - ::LogInfoEx("DSP is up and running"); |
557 | | - while (!g_killed) { |
558 | | - loop(); |
559 | | - ::usleep(1); |
560 | | - } |
561 | | - } |
562 | | - |
563 | | - if (g_signal == 2) |
564 | | - ::LogInfoEx("Exited on receipt of SIGINT"); |
565 | | - |
566 | | - if (g_signal == 15) |
567 | | - ::LogInfoEx("Exited on receipt of SIGTERM"); |
568 | | - |
569 | | - if (g_signal == 1) |
570 | | - ::LogInfoEx("Restarting on receipt of SIGHUP"); |
571 | | - } while (g_signal == 1); |
572 | | - |
573 | | - ::LogInfoEx("DSP is shutting down"); |
574 | | - |
575 | | - if (m_serialPort != nullptr) { |
576 | | - m_serialPort->close(); |
577 | | - delete m_serialPort; |
578 | | - } |
579 | | - |
580 | | - try |
581 | | - { |
582 | | - m_zmqSocketTx.close(); |
583 | | - m_zmqSocketRx.close(); |
584 | | - } |
585 | | - catch(const zmq::error_t& zmqE) { /* stub */ } |
586 | | - catch(const std::exception& e) { /* stub */ } |
587 | | - |
588 | | - ::LogFinalise(); |
589 | | - return 0; |
590 | | -} |
591 | | -#endif // defined(NATIVE_SDR) |
0 commit comments