summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2013-02-24 17:29:34 +0100
committerAndreas Eversberg <jolly@eversberg.eu>2013-02-24 17:29:34 +0100
commit2cfeba7ddbd1dc89c56fe8f3896fbf492354d1a0 (patch)
tree7023f719e35ba0e6cad07679dad1ed70126d3dfc
parenteeafd9fa5bf2f700ec18cfbbc71aa61ed99f51ee (diff)
Add command line options parsing to transceiver application
-rw-r--r--src/host/layer23/src/transceiver/main.c99
1 files changed, 89 insertions, 10 deletions
diff --git a/src/host/layer23/src/transceiver/main.c b/src/host/layer23/src/transceiver/main.c
index 3b7281dd..1efa49c3 100644
--- a/src/host/layer23/src/transceiver/main.c
+++ b/src/host/layer23/src/transceiver/main.c
@@ -23,9 +23,12 @@
#include <stdlib.h>
#include <string.h>
+#include <getopt.h>
#include <osmocom/core/select.h>
#include <osmocom/core/talloc.h>
+#include <osmocom/core/application.h>
+#include <osmocom/gsm/gsm_utils.h>
#include <osmocom/bb/common/logging.h>
@@ -38,6 +41,69 @@
void *l23_ctx = NULL;
+static int arfcn_sync = 0;
+static int daemonize = 0;
+
+static void print_help(char *argv[])
+{
+ fprintf(stderr, "Usage: %s -a arfcn_sync\n", argv[0]);
+
+ printf( "Some useful options:\n"
+ " -h --help this text\n"
+ " -d --debug MASK Enable debugging (e.g. -d DL1C:DTRX)\n"
+ " -D --daemonize For the process into a background daemon\n"
+ " -s --disable-color Don't use colors in stderr log output\n"
+ " -a --arfcn-sync ARFCN Set ARFCN to sync to\n"
+ " -p --arfcn-sync-pcs The ARFCN above is PCS\n"
+ );
+}
+
+static void handle_options(int argc, char **argv, struct app_state *as)
+{
+ while (1) {
+ int option_idx = 0, c;
+ static const struct option long_options[] = {
+ { "help", 0, 0, 'h' },
+ { "debug", 1, 0, 'd' },
+ { "daemonize", 0, 0, 'D' },
+ { "disable-color", 0, 0, 's' },
+ { "arfcn-sync", 1, 0, 'a' },
+ { "arfcn-sync-pcs", 0, 0, 'p' },
+ };
+
+ c = getopt_long(argc, argv, "hd:Dsa:p",
+ long_options, &option_idx);
+
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'h':
+ print_help(argv);
+ exit(0);
+ break;
+ case 'd':
+ log_parse_category_mask(as->stderr_target, optarg);
+ break;
+ case 'D':
+ daemonize = 1;
+ break;
+ case 's':
+ log_set_use_color(as->stderr_target, 0);
+ break;
+ case 'a':
+ as->arfcn_sync |= atoi(optarg);
+ arfcn_sync = 1;
+ break;
+ case 'p':
+ as->arfcn_sync |= ARFCN_PCS;
+ break;
+ default:
+ fprintf(stderr, "Unknow option %s\n", optarg);
+ exit(0);
+ }
+ }
+}
int main(int argc, char *argv[])
@@ -45,18 +111,8 @@ int main(int argc, char *argv[])
struct app_state _as, *as = &_as;
int rv;
- /* Options */
- if (argc != 2) {
- fprintf(stderr, "Usage: %s arfcn_sync\n", argv[0]);
- return -1;
- }
-
- /* App state init */
memset(as, 0x00, sizeof(struct app_state));
- as->arfcn_sync = atoi(argv[1]);
- printf("%d\n", as->arfcn_sync);
-
/* Init talloc */
l23_ctx = talloc_named_const(NULL, 1, "l23 app context");
@@ -68,6 +124,20 @@ int main(int argc, char *argv[])
log_add_target(as->stderr_target);
log_set_all_filter(as->stderr_target, 1);
+ /* Options */
+ if (argc < 2) {
+ print_help(argv);
+ return -1;
+ }
+ handle_options(argc, argv, as);
+ if (!arfcn_sync) {
+ fprintf(stderr, "Use --arfcn-sync <ARFCN>\n");
+ exit(0);
+ }
+
+ /* App state init */
+ printf("%d\n", as->arfcn_sync);
+
/* Init signal processing */
/* Init GMSK tables */
as->gs = osmo_gmsk_init(1);
@@ -92,6 +162,15 @@ int main(int argc, char *argv[])
/* Reset phone */
l1ctl_tx_reset_req(&as->l1l, L1CTL_RES_T_FULL);
+ if (daemonize) {
+ rv = osmo_daemonize();
+ if (rv < 0) {
+ perror("Error during daemonize");
+ exit(1);
+ }
+ }
+
+
/* Main loop */
while (1) {
osmo_select_main(0);