Parse messages.

Fix squelch for md380.
This commit is contained in:
Serge Vakulenko 2018-08-31 13:15:35 -07:00
parent 6a69737d65
commit 5a842d8770
4 changed files with 97 additions and 11 deletions

6
main.c
View File

@ -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);
}

58
md380.c
View File

@ -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;
}

View File

@ -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);

40
uv380.c
View File

@ -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;
}