Commit 8e594f24 authored by Lukas Senger's avatar Lukas Senger

Add PREMSG and POSTMSG config

parent 307545ee
......@@ -21,6 +21,8 @@
#define STRING_LEN 64 // used for paths
#define CFG_MSG_LEN 1000
#define MAX_POSTMSG_COUNT 20
#define BAUDRATE 9600
#define UBX_MAX_MSG_LEN 300 // Some messages might theoretically be longer but
......@@ -56,6 +58,8 @@ struct instance {
int32_t user_config_delay;
char *data_file;
int tm_edge;
char postmsg[MAX_POSTMSG_COUNT][CFG_MSG_LEN];
int postmsg_count;
// for message receiving
l_fp recv_time;
......@@ -286,6 +290,7 @@ static void ubx_receive(struct recvbuf *);
static int ubx_write(struct instance *, unsigned int, unsigned int, size_t,
void *);
static void ubx_checksum(u_char *, size_t, u_char *, u_char *);
static void ubx_str_msg(struct instance *, char *);
static void ubx_msg(struct instance *, char, char, u_char *, size_t);
static void ubx_msg_nav_timeutc(struct instance *, u_char *, size_t);
static void ubx_msg_nav_timels(struct instance *, u_char *, size_t);
......@@ -399,6 +404,8 @@ static int ubx_start(int unit, struct peer *peer) {
sleep(2);
ubx_configure_receiver(instance);
for (int i = 0; i < instance->postmsg_count; i++)
ubx_str_msg(instance, instance->postmsg[i]);
return 1;
}
......@@ -1133,6 +1140,36 @@ int ubx_write(struct instance *instance, unsigned int msg_class,
return ok;
}
static void ubx_str_msg(struct instance *instance, char *msgstr) {
char *pos;
char *end;
uint32_t part;
char msg[UBX_MAX_MSG_LEN];
int i;
pos = msgstr;
i = 0;
while (1) {
part = strtoul(pos, &end, 16);
if (part > UCHAR_MAX) {
if (errno == EINVAL)
ubx_log_f(instance, LOG_ERR,
"Invalid value in MSG %s", msgstr);
ubx_log_f(instance, LOG_ERR,
"Out of range value in MSG %s", msgstr);
return;
}
if (pos == end)
break;
msg[i] = (char)part;
pos = end;
i++;
}
if (ubx_write(instance, msg[0], msg[1], i - 4, &msg[4]) == 0)
ubx_log_f(instance, LOG_ERR, "Failed sending PREMSG %s", msgstr);
}
// adapted from oncore driver
static void ubx_read_config(struct instance *instance) {
char path[STRING_LEN];
......@@ -1300,6 +1337,18 @@ static int ubx_read_config_file(struct instance *instance, char *path) {
"Unknown value \"%s\" for TMEDGE, ignored",
cc);
}
} else if (!strncmp(cc, "PREMSG", 6)) {
ubx_str_msg(instance, ca);
} else if (!strncmp(cc, "POSTMSG", 7)) {
if (instance->postmsg_count == MAX_POSTMSG_COUNT) {
ubx_log_f(instance, LOG_WARNING,
"Maximum number of POSTMSGs (%d) exceeded.", MAX_POSTMSG_COUNT);
continue;
}
strncpy(instance->postmsg[instance->postmsg_count],
ca, CFG_MSG_LEN);
instance->postmsg[instance->postmsg_count][CFG_MSG_LEN - 1] = '\0';
instance->postmsg_count++;
}
}
fclose(fd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment