From 5a842d87707048cc7a605cda1a1e238cd05e70f3 Mon Sep 17 00:00:00 2001 From: Serge Vakulenko Date: Fri, 31 Aug 2018 13:15:35 -0700 Subject: [PATCH] Parse messages. Fix squelch for md380. --- main.c | 6 +++--- md380.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++------ radio.c | 4 ++-- uv380.c | 40 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 11 deletions(-) diff --git a/main.c b/main.c index d16819c..83c67b9 100644 --- a/main.c +++ b/main.c @@ -54,9 +54,9 @@ void usage() fprintf(stderr, _(" dmrconfig file.img\n")); fprintf(stderr, _(" Display configuration from the codeplug image.\n")); fprintf(stderr, _("Options:\n")); - fprintf(stderr, _(" -r Read image to the radio.\n")); - fprintf(stderr, _(" -w Write image to the radio.\n")); - fprintf(stderr, _(" -c Configure the radio from a text file.\n")); + fprintf(stderr, _(" -r Read codeplug from the radio.\n")); + fprintf(stderr, _(" -w Write codeplug to the radio.\n")); + fprintf(stderr, _(" -c Configure the radio from a text script.\n")); fprintf(stderr, _(" -t Trace USB protocol.\n")); exit(-1); } diff --git a/md380.c b/md380.c index 03ca4b1..d937e6d 100644 --- a/md380.c +++ b/md380.c @@ -527,6 +527,19 @@ static int grouplist_append(int index, int cnum) return 0; } +// +// Set text for a given message. +// +static void setup_message(int index, const char *text) +{ + uint16_t *msg = (uint16_t*) &radio_mem[OFFSET_MSG + index*288]; + + // Skip spaces and tabs. + while (*text == ' ' || *text == '\t') + text++; + utf8_decode(msg, text, 144); +} + // // Check that the radio does support this frequency. // @@ -1415,9 +1428,12 @@ badtx: fprintf(stderr, "Bad transmit frequency.\n"); return 0; } - squelch = atoi(squelch_str); - if (squelch > 9) { - fprintf(stderr, "Bad squelch level.\n"); + if (strcasecmp ("Normal", squelch_str) == 0) { + squelch = SQ_NORMAL; + } else if (strcasecmp ("Tight", squelch_str) == 0) { + squelch = SQ_TIGHT; + } else { + fprintf (stderr, "Bad squelch level.\n"); return 0; } @@ -1574,9 +1590,12 @@ badtx: fprintf(stderr, "Bad transmit frequency.\n"); return 0; } - squelch = atoi(squelch_str); - if (squelch > 9) { - fprintf(stderr, "Bad squelch level.\n"); + if (strcasecmp ("Normal", squelch_str) == 0) { + squelch = SQ_NORMAL; + } else if (strcasecmp ("Tight", squelch_str) == 0) { + squelch = SQ_TIGHT; + } else { + fprintf (stderr, "Bad squelch level.\n"); return 0; } @@ -1968,6 +1987,30 @@ static int parse_grouplist(int first_row, char *line) return 1; } +// +// Parse one line of Messages table. +// Return 0 on failure. +// +static int parse_messages(int first_row, char *line) +{ + char *text; + int mnum; + + mnum = strtoul(line, &text, 10); + if (text == line || mnum < 1 || mnum > NMESSAGES) { + fprintf(stderr, "Bad message number.\n"); + return 0; + } + + if (first_row) { + // On first entry, erase the Messages table. + memset(&radio_mem[OFFSET_MSG], 0, NMESSAGES*288); + } + + setup_message(mnum-1, text); + return 1; +} + // // Parse table header. // Return table id, or 0 in case of error. @@ -1986,6 +2029,8 @@ static int md380_parse_header(radio_device_t *radio, char *line) return 'C'; if (strncasecmp(line, "Grouplist", 9) == 0) return 'G'; + if (strncasecmp(line, "Message", 7) == 0) + return 'M'; return 0; } @@ -2002,6 +2047,7 @@ static int md380_parse_row(radio_device_t *radio, int table_id, int first_row, c case 'S': return parse_scanlist(first_row, line); case 'C': return parse_contact(first_row, line); case 'G': return parse_grouplist(first_row, line); + case 'M': return parse_messages(first_row, line); } return 0; } diff --git a/radio.c b/radio.c index a86e15f..a72a228 100644 --- a/radio.c +++ b/radio.c @@ -130,7 +130,7 @@ void radio_read_image(char *filename) FILE *img; struct stat st; - fprintf(stderr, "Read image from file '%s'.\n", filename); + fprintf(stderr, "Read codeplug from file '%s'.\n", filename); // Guess device type by file size. if (stat(filename, &st) < 0) { @@ -168,7 +168,7 @@ void radio_save_image(char *filename) { FILE *img; - fprintf(stderr, "Write image to file '%s'.\n", filename); + fprintf(stderr, "Write codeplug to file '%s'.\n", filename); img = fopen(filename, "w"); if (! img) { perror(filename); diff --git a/uv380.c b/uv380.c index f58ed6d..d080098 100644 --- a/uv380.c +++ b/uv380.c @@ -565,6 +565,19 @@ static int grouplist_append(int index, int cnum) return 0; } +// +// Set text for a given message. +// +static void setup_message(int index, const char *text) +{ + uint16_t *msg = (uint16_t*) &radio_mem[OFFSET_MSG + index*288]; + + // Skip spaces and tabs. + while (*text == ' ' || *text == '\t') + text++; + utf8_decode(msg, text, 144); +} + // // Check that the radio does support this frequency. // @@ -2045,6 +2058,30 @@ static int parse_grouplist(int first_row, char *line) return 1; } +// +// Parse one line of Messages table. +// Return 0 on failure. +// +static int parse_messages(int first_row, char *line) +{ + char *text; + int mnum; + + mnum = strtoul(line, &text, 10); + if (text == line || mnum < 1 || mnum > NMESSAGES) { + fprintf(stderr, "Bad message number.\n"); + return 0; + } + + if (first_row) { + // On first entry, erase the Messages table. + memset(&radio_mem[OFFSET_MSG], 0, NMESSAGES*288); + } + + setup_message(mnum-1, text); + return 1; +} + // // Parse table header. // Return table id, or 0 in case of error. @@ -2063,6 +2100,8 @@ static int uv380_parse_header(radio_device_t *radio, char *line) return 'C'; if (strncasecmp(line, "Grouplist", 9) == 0) return 'G'; + if (strncasecmp(line, "Message", 7) == 0) + return 'M'; return 0; } @@ -2079,6 +2118,7 @@ static int uv380_parse_row(radio_device_t *radio, int table_id, int first_row, c case 'S': return parse_scanlist(first_row, line); case 'C': return parse_contact(first_row, line); case 'G': return parse_grouplist(first_row, line); + case 'M': return parse_messages(first_row, line); } return 0; }