Skip to content

Commit

Permalink
Parse messages.
Browse files Browse the repository at this point in the history
Fix squelch for md380.
  • Loading branch information
sergev committed Aug 31, 2018
1 parent 6a69737 commit 5a842d8
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 11 deletions.
6 changes: 3 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
58 changes: 52 additions & 6 deletions md380.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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.
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
40 changes: 40 additions & 0 deletions uv380.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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.
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand Down

0 comments on commit 5a842d8

Please sign in to comment.