int recv_msg(void)
{
int ret;
+ uint8_t irq_flags;
int16_t c;
+ uint16_t t1, t2, diff;
+
+ IRQ_LOCK(irq_flags);
+ t1 = global_ms;
+ IRQ_UNLOCK(irq_flags);
+ printf_P(PSTR("recv_msg()\n"));
while (1) {
- /* XXX use select for timeout */
- c = uart_recv(GPS_UART);
+ IRQ_LOCK(irq_flags);
+ t2 = global_ms;
+ IRQ_UNLOCK(irq_flags);
+ diff = t2 - t1;
+ if (diff > 1000) {
+ printf_P(PSTR("recv_msg timeout\n"));
+ return -1;
+ }
+
+ c = uart_recv_nowait(GPS_UART);
+ if (c < 0)
+ continue;
+
+ debug_printf("%2.2x\n", c);
+
ret = recv_cb(c);
if (ret == 0)
return 0;
int wait_ack(int msg_type)
{
+ uint8_t irq_flags;
int ret;
+ uint16_t t1, t2, diff;
+
+ IRQ_LOCK(irq_flags);
+ t1 = global_ms;
+ IRQ_UNLOCK(irq_flags);
+
while (1) {
ret = recv_msg();
if (ret < 0)
return -1;
+ IRQ_LOCK(irq_flags);
+ t2 = global_ms;
+ IRQ_UNLOCK(irq_flags);
+ diff = t2 - t1;
+ if (diff > 1000) {
+ printf_P(PSTR("wait_ack timeout\n"));
+ return -1;
+ }
+
/* retry if it's not the expected message */
if (rxframe.data[0] != 0x83 && rxframe.data[0] != 0x84)
continue;
}
diff = ms - last_valid;
- if (is_valid == 1 && diff > 100) {
+ if (is_valid == 1 && diff > 500) {
is_valid = 0;
/* update global structure */
memcpy(pos, &gps_pos, sizeof(*pos));
}
-int gps_log(void)
+int gps_log(uint8_t to_stdout)
{
uint32_t ms;
uint8_t flags, prio;
(double)gps_pos.sea_altitude / 100.);
- if (sd_log_enabled()) {
+ if (!to_stdout && sd_log_enabled()) {
if (sd_log_write(buf, len) != len) {
printf_P(PSTR("error writing to file\n"));
return -1;
}
}
- else {
+ else if (to_stdout) {
printf_P(PSTR("%s"), buf);
}