summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/venus_api.c27
-rw-r--r--src/venus_api.h8
-rw-r--r--src/venus_gps.c4
3 files changed, 20 insertions, 19 deletions
diff --git a/src/venus_api.c b/src/venus_api.c
index 26e2787..c1ae5d4 100644
--- a/src/venus_api.c
+++ b/src/venus_api.c
@@ -95,7 +95,7 @@ speed_t baud_to_venus(speed_t baud)
static uint8_t seq_start[] = { 0xA0, 0xA1 };
static uint8_t seq_end[] = { 0x0D, 0x0A };
-void free_venus_msg_data(struct venus_msg *msg)
+void venus_msg_data_free(struct venus_msg *msg)
{
if (!msg) {
return;
@@ -107,7 +107,7 @@ void free_venus_msg_data(struct venus_msg *msg)
msg->data = NULL;
}
-uint8_t checksum(void *data, uint16_t len)
+uint8_t venus_checksum(void *data, uint16_t len)
{
int i;
uint8_t cs = 0;
@@ -140,7 +140,7 @@ int venus_write_msg(int fd, struct venus_msg *msg)
if (err != msg->len) {
log_error("failed to write data: %d %m", err);
}
- cs = checksum(msg->data, msg->len);
+ cs = venus_checksum(msg->data, msg->len);
err = full_write(fd, &cs, 1);
if (err != 1) {
log_error("failed to write checksum: %d %m", err);
@@ -161,10 +161,9 @@ int venus_read_msg(int fd, struct venus_msg *msg)
uint8_t seq[2];
int attempts = 0;
- again:
+again:
while (1) {
safe_readn(fd, seq, 2);
- //log_error("start seq %c %c", seq[0], seq[1]);
if (!memcmp(seq, seq_start, 2)) {
break;
}
@@ -180,7 +179,7 @@ int venus_read_msg(int fd, struct venus_msg *msg)
data = malloc(len);
safe_readn(fd, data, len);
safe_readn(fd, &cs, 1);
- if (checksum(data, len) != cs) {
+ if (venus_checksum(data, len) != cs) {
log_error("checksum mismatch");
return -1;
}
@@ -213,7 +212,7 @@ int venus_read_msg(int fd, struct venus_msg *msg)
return 0;
}
-ssize_t read_nmea_sentence(int fd, void *buf, size_t count)
+ssize_t venus_read_nmea_sentence(int fd, void *buf, size_t count)
{
int err;
char c;
@@ -296,7 +295,7 @@ int venus_system_restart(int fd, uint8_t mode, time_t utc, int16_t latitude, int
log_error("venus_read_msg: %d", err);
return -1;
}
- free_venus_msg_data(&msg);
+ venus_msg_data_free(&msg);
return 0;
}
@@ -323,7 +322,7 @@ int venus_factory_defaults(int fd, uint8_t type)
log_error("venus_read_msg: %d", err);
return -1;
}
- free_venus_msg_data(&msg);
+ venus_msg_data_free(&msg);
return 0;
}
@@ -352,7 +351,7 @@ int venus_conf_serial(int fd, uint8_t com, uint8_t baud, uint8_t attr)
log_error("venus_read_msg: %d", err);
return -1;
}
- free_venus_msg_data(&msg);
+ venus_msg_data_free(&msg);
return 0;
}
@@ -380,7 +379,7 @@ int venus_conf_format(int fd, uint8_t type, uint8_t attr)
log_error("venus_read_msg: %d", err);
return -1;
}
- free_venus_msg_data(&msg);
+ venus_msg_data_free(&msg);
return 0;
}
@@ -407,14 +406,14 @@ int venus_query_sw_version(int fd, uint8_t type)
log_error("venus_read_msg: %d", err);
return -1;
}
- free_venus_msg_data(&msg);
+ venus_msg_data_free(&msg);
err = venus_read_msg(fd, &msg);
if (err < 0) {
log_error("venus_read_msg: %d", err);
return -1;
}
- free_venus_msg_data(&msg);
+ venus_msg_data_free(&msg);
return 0;
}
@@ -448,7 +447,7 @@ int venus_conf_nmea(int fd, uint8_t gga, uint8_t gsa, uint8_t gsv, uint8_t gll,
log_error("venus_read_msg: %d", err);
return -1;
}
- free_venus_msg_data(&msg);
+ venus_msg_data_free(&msg);
return 0;
}
diff --git a/src/venus_api.h b/src/venus_api.h
index 75f189f..85387e0 100644
--- a/src/venus_api.h
+++ b/src/venus_api.h
@@ -78,11 +78,12 @@ struct venus_msg {
speed_t value_to_baud(speed_t value);
speed_t baud_to_venus(speed_t baud);
-void free_venus_msg_data(struct venus_msg *msg);
-uint8_t checksum(void *data, uint16_t len);
+void venus_msg_data_free(struct venus_msg *msg);
+
+uint8_t venus_checksum(void *data, uint16_t len);
int venus_write_msg(int fd, struct venus_msg *msg);
int venus_read_msg(int fd, struct venus_msg *msg);
-ssize_t read_nmea_sentence(int fd, void *buf, size_t count);
+ssize_t venus_read_nmea_sentence(int fd, void *buf, size_t count);
int venus_system_restart(int fd, uint8_t mode, time_t utc, int16_t latitude,
int16_t longitude, int16_t altitude);
int venus_factory_defaults(int fd, uint8_t type);
@@ -92,6 +93,7 @@ int venus_query_sw_version(int fd, uint8_t type);
int venus_conf_nmea(int fd, uint8_t gga, uint8_t gsa, uint8_t gsv, uint8_t gll,
uint8_t rmc, uint8_t vtg, uint8_t zda, uint8_t attr);
int venus_tty_configure(int fd, speed_t baud_rate);
+
int venus_open(const char *dev, speed_t baud_rate);
#endif /* ~__VENUS_API_H */
diff --git a/src/venus_gps.c b/src/venus_gps.c
index 1f317a0..5f4e7b1 100644
--- a/src/venus_gps.c
+++ b/src/venus_gps.c
@@ -163,9 +163,9 @@ static int udp_send_msgs(int sd, int tty)
int err;
while (1) {
- count = read_nmea_sentence(tty, buf, sizeof(buf));
+ count = venus_read_nmea_sentence(tty, buf, sizeof(buf));
if (count <= 0) {
- log_error("read_nmea_sentence failed: quiting");
+ log_error("venus_read_nmea_sentence failed: quiting");
return -1;
}
err = send(sd, buf, count, 0);