From fabd63f3f64304eb90694064cf251a4626a4f0bd Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Wed, 16 Oct 2013 11:23:34 +0200 Subject: EMI-App: Add command line interface to control App via serial console --- src/target/firmware/apps/emi/main.c | 224 ++++++++++++++++++++++++++++++------ 1 file changed, 191 insertions(+), 33 deletions(-) diff --git a/src/target/firmware/apps/emi/main.c b/src/target/firmware/apps/emi/main.c index c80fa090..d912e144 100644 --- a/src/target/firmware/apps/emi/main.c +++ b/src/target/firmware/apps/emi/main.c @@ -99,6 +99,7 @@ static int tone_on = 0; struct templates { char *name; /* name of template */ + char *cli; /* cli parameter */ uint8_t slots; /* number of slots used (multislot) */ int burst_num; /* number of bits in burstmap */ uint32_t *burst_map; @@ -149,22 +150,22 @@ static uint32_t template_pdch[] = { }; static struct templates templates[] = { - { "SDCCH", 1, 102, template_sdcch }, - { "TCH/F", 1, 26, template_tchf }, - { "TCH/F (2 TS)", 2, 26, template_tchf }, - { "TCH/F (3 TS)", 3, 26, template_tchf }, - { "TCH/F (4 TS)", 4, 26, template_tchf }, - { "TCH/F (5 TS)", 5, 26, template_tchf }, - { "TCH/H", 1, 26, template_tchh }, - { "TCH/F(H) DTX", 1, 26, template_tchf_h_dtx }, - { "PDCH (ack)", 1, 1664, template_pdch_ack }, - { "PDCH", 1, 416, template_pdch }, - { "PDCH (2 TS)", 2, 416, template_pdch }, - { "PDCH (3 TS)", 3, 416, template_pdch }, - { "PDCH (4 TS)", 4, 416, template_pdch }, - { "PDCH (5 TS)", 5, 416, template_pdch }, - { "RACH", 1, 217, NULL }, - { 0, 0, 0, NULL } + { "SDCCH", "sdcch", 1, 102, template_sdcch }, + { "TCH/F", "tchf", 1, 26, template_tchf }, + { "TCH/F (2 TS)", "tchf2", 2, 26, template_tchf }, + { "TCH/F (3 TS)", "tchf3", 3, 26, template_tchf }, + { "TCH/F (4 TS)", "tchf4", 4, 26, template_tchf }, + { "TCH/F (5 TS)", "tchf5", 5, 26, template_tchf }, + { "TCH/H", "tchh", 1, 26, template_tchh }, + { "TCH/F(H) DTX", "dtx", 1, 26, template_tchf_h_dtx }, + { "PDCH (ack)", "pdchack", 1, 1664, template_pdch_ack }, + { "PDCH", "pdch", 1, 416, template_pdch }, + { "PDCH (2 TS)", "pdch2", 2, 416, template_pdch }, + { "PDCH (3 TS)", "pdch3", 3, 416, template_pdch }, + { "PDCH (4 TS)", "pdch4", 4, 416, template_pdch }, + { "PDCH (5 TS)", "pdch5", 5, 416, template_pdch }, + { "RACH", "rach", 1, 217, NULL }, + { 0, 0, 0, 0, NULL } }; static int sel_template = 0, scroll_template = 0; @@ -326,6 +327,31 @@ static void exit_arfcn(void) refresh_display(); } +static int check_arfcn(int check) +{ + struct band *temp = NULL; + int i; + + for (i = 0; bands[i].max; i++) { + temp = &bands[i]; + if (temp->min < temp->max) { + if (check >= temp->min && check <= temp->max) + break; + } else { + if (check >= temp->min || check <= temp->max) + break; + } + } + if (!bands[i].max) + return -EINVAL; + if (check > 1023) + return -EINVAL; + arfcn = check; + band = temp; + + return 0; +} + static void enter_arfcn(enum key_codes code) { /* enter mode */ @@ -354,7 +380,6 @@ static void enter_arfcn(enum key_codes code) if (code == KEY_RIGHT_SB) { int check = 0; int i; - struct band *temp = NULL; /* nothing entered */ if (cursor == 0) { @@ -364,22 +389,8 @@ static void enter_arfcn(enum key_codes code) check = (check << 3) + (check << 1) + input[i] - '0'; /* check */ - for (i = 0; bands[i].max; i++) { - temp = &bands[i]; - if (temp->min < temp->max) { - if (check >= temp->min && check <= temp->max) - break; - } else { - if (check >= temp->min || check <= temp->max) - break; - } - } - if (!bands[i].max) + if (check_arfcn(check)) return; - if (check > 1023) - return; - arfcn = check; - band = temp; mode = MODE_MAIN; refresh_display(); refresh_template(); @@ -724,6 +735,153 @@ static void refresh_template(void) } } +/* non conform strcmp hack */ +static int _strcmp(char *s1, char *s2) +{ + int i; + + if (strlen(s1) != strlen(s2)) + return 1; + for (i = 0; i < (int)strlen(s1); i++) + if (s1[i] != s2[i]) + return 1; + return 0; +} + +/* non conform atoi hack */ +static int _atoi(const char *s) +{ + int i = 0; + + while (*s >= '0' && *s <= '9') + i = i*10 + *s++ - '0'; + return i; +} + +static void cli(char *command) +{ + char *param = ""; + int i; + + for (i = 0; i < (int)strlen(command); i++) { + if (command[i] == ' ') { + command[i] = '\0'; + param = command + i + 1; + break; + } + } + + if (command[0] == '\0') + return; + + if (!_strcmp(command, "help")) { + printf("Available commands:\n\n"); + printf("help this text\n\n"); + printf("arfcn Absolute radio frequency number\n\n"); + printf("dcs Use DCS1800 for ARFCN 512..810\n\n"); + printf("pcs Use PCS1900 for ARFCN 512..810\n\n"); + printf("uplink Use uplink bands\n\n"); + printf("downlink Use downlink bands\n\n"); + printf("template