Fixed GPS communication error

master
Sven Steudte 2017-12-12 03:38:01 +01:00
rodzic d642472fed
commit b51b45b839
1 zmienionych plików z 20 dodań i 19 usunięć

Wyświetl plik

@ -34,23 +34,25 @@ void gps_transmit_string(uint8_t *cmd, uint8_t length)
} }
/** /**
* Receives a single byte from the GPS. Returns 0x00 is there is no byte available * Receives a single byte from the GPS and assigns to supplied pointer.
* Returns false is there is no byte available else true
*/ */
uint8_t gps_receive_byte(void) bool gps_receive_byte(uint8_t *data)
{ {
uint8_t val = 0x00;
#if defined(UBLOX_USE_I2C) #if defined(UBLOX_USE_I2C)
uint16_t len; uint16_t len;
I2C_read16(UBLOX_MAX_ADDRESS, 0xFD, &len); I2C_read16(UBLOX_MAX_ADDRESS, 0xFD, &len);
if(len) if(len) {
I2C_read8(UBLOX_MAX_ADDRESS, 0xFF, &val); I2C_read8(UBLOX_MAX_ADDRESS, 0xFF, data);
return true;
}
#elif defined(UBLOX_USE_UART) #elif defined(UBLOX_USE_UART)
val = sdGetTimeout(&SD5, TIME_IMMEDIATE); if((msg = sdGetTimeout(&SD5, TIME_IMMEDIATE)) != MSG_TIMEOUT) {
if(val == 0xFF) val = 0x00; *data = msg;
#endif return true;
}
return val; #endif
return false;
} }
/** /**
@ -58,7 +60,7 @@ uint8_t gps_receive_byte(void)
* *
* waits for transmission of an ACK/NAK message from the GPS. * waits for transmission of an ACK/NAK message from the GPS.
* *
* returns 1 if ACK was received, 0 if NAK was received * returns 1 if ACK was received, 0 if NAK was received or timeout
* *
*/ */
uint8_t gps_receive_ack(uint8_t class_id, uint8_t msg_id, uint16_t timeout) { uint8_t gps_receive_ack(uint8_t class_id, uint8_t msg_id, uint16_t timeout) {
@ -77,8 +79,8 @@ uint8_t gps_receive_ack(uint8_t class_id, uint8_t msg_id, uint16_t timeout) {
while(sTimeout >= chVTGetSystemTimeX()) { while(sTimeout >= chVTGetSystemTimeX()) {
// Receive one byte // Receive one byte
rx_byte = gps_receive_byte(); ;
if(!rx_byte) { if(!gps_receive_byte(&rx_byte)) {
chThdSleepMilliseconds(10); chThdSleepMilliseconds(10);
continue; continue;
} }
@ -102,7 +104,7 @@ uint8_t gps_receive_ack(uint8_t class_id, uint8_t msg_id, uint16_t timeout) {
} }
return false; return 0;
} }
/** /**
@ -124,8 +126,7 @@ uint16_t gps_receive_payload(uint8_t class_id, uint8_t msg_id, unsigned char *pa
while(sTimeout >= chVTGetSystemTimeX()) { while(sTimeout >= chVTGetSystemTimeX()) {
// Receive one byte // Receive one byte
rx_byte = gps_receive_byte(); if(!gps_receive_byte(&rx_byte)) {
if(!rx_byte) {
chThdSleepMilliseconds(10); chThdSleepMilliseconds(10);
continue; continue;
} }
@ -380,7 +381,7 @@ bool GPS_Init(void) {
if(status) { if(status) {
TRACE_INFO("GPS > ... Disable NMEA output OK"); TRACE_INFO("GPS > ... Disable NMEA output OK");
} else { } else {
TRACE_ERROR("GPS > Communication Eror"); TRACE_ERROR("GPS > Communication Error [disable NMEA]");
return false; return false;
} }
@ -389,7 +390,7 @@ bool GPS_Init(void) {
if(status) { if(status) {
TRACE_INFO("GPS > ... Set airborne model OK"); TRACE_INFO("GPS > ... Set airborne model OK");
} else { } else {
TRACE_ERROR("GPS > Communication Eror"); TRACE_ERROR("GPS > Communication Error [set airborne]");
return false; return false;
} }