diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2005-07-01 06:00:44 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2005-07-01 06:00:44 +0000 |
commit | e5e3065cc0d29233754da4ed09999ce4c771b40b (patch) | |
tree | 04b59f4e8c80d663e4edeb216a3480c4063a95f7 | |
parent | 39ba7ffed21fe6f61a7a55d1e520be0c96dd52fb (diff) | |
download | gpsd-e5e3065cc0d29233754da4ed09999ce4c771b40b.tar.gz |
This is the fix I had been waiting for Gary to check in -- I hope.
-rw-r--r-- | garmin.c | 32 |
1 files changed, 20 insertions, 12 deletions
@@ -200,6 +200,7 @@ static inline double radtodeg( double rad) { static gps_mask_t PrintPacket(struct gps_device_t *session, Packet_t *pkt ); static void SendPacket (struct gps_device_t *session, Packet_t *aPacket ); +static int GetPacket (struct gps_device_t *session ); // For debugging, decodes and prints some known packets. static gps_mask_t PrintPacket(struct gps_device_t *session, Packet_t *pkt) @@ -504,7 +505,10 @@ static void SendPacket (struct gps_device_t *session, Packet_t *aPacket ) // The Garmin sample WinXX code also assumes the same behavior, so // maybe it is something in the USB protocol. // -static ssize_t garmin_get_packet (struct gps_device_t *session ) +// Return: 0 = got a good packet +// -1 = error +// 1 = got partial packet +static int GetPacket (struct gps_device_t *session ) { struct timespec delay, rem; int cnt = 0; @@ -514,7 +518,7 @@ static ssize_t garmin_get_packet (struct gps_device_t *session ) memset( &delay, 0, sizeof(delay)); session->GarminBufferLen = 0; - gpsd_report(4, "garmin_get_packet()\n"); + gpsd_report(4, "GetPacket()\n"); for( cnt = 0 ; cnt < 10 ; cnt++ ) { // Read async data until the driver returns less than the @@ -529,10 +533,9 @@ static ssize_t garmin_get_packet (struct gps_device_t *session ) , buf + session->GarminBufferLen , ASYNC_DATA_SIZE); if ( 0 > theBytesReturned ) { - if (errno == EAGAIN) - return 0; - // real read error... - gpsd_report(0, "garmin_get_packet() read error=%d, errno=%d\n" + // read error... + // or EAGAIN, but O_NONBLOCK is never set + gpsd_report(0, "GetPacket() read error=%d, errno=%d\n" , theBytesReturned, errno); continue; } @@ -547,7 +550,7 @@ static ssize_t garmin_get_packet (struct gps_device_t *session ) if ( 256 <= session->GarminBufferLen ) { // really bad read error... session->GarminBufferLen = 0; - gpsd_report(3, "garmin_get_packet() packet too long!\n"); + gpsd_report(3, "GetPacket() packet too long!\n"); break; } @@ -563,12 +566,12 @@ static ssize_t garmin_get_packet (struct gps_device_t *session ) // gpsd_report(6, "p[%d] = %x\n", x, session->GarminBuffer[x]); // } if ( 10 <= cnt ) { - gpsd_report(3, "garmin_get_packet() packet too long or too slow!\n"); + gpsd_report(3, "GetPacket() packet too long or too slow!\n"); return -1; } gpsd_report(5, "GotPacket() sz=%d \n", session->GarminBufferLen); - return (ssize_t)session->GarminBufferLen; + return 0; } /* @@ -667,7 +670,7 @@ static bool garmin_probe(struct gps_device_t *session) , &session->ttyset_old); return false; } - if (garmin_get_packet( session ) == (ssize_t)sizeof(session->GarminBuffer)) { + if ( 0 == GetPacket( session ) ) { (void)PrintPacket(session, thePacket); if( ( (unsigned char)75 == thePacket->mPacketType) @@ -714,7 +717,7 @@ static bool garmin_probe(struct gps_device_t *session) , &session->ttyset_old); return(0); } - if ( garmin_get_packet( session ) == (ssize_t)sizeof(session->GarminBuffer)) { + if ( 0 == GetPacket( session ) ) { (void)PrintPacket(session, thePacket); if( (GARMIN_LAYERID_TRANSPORT == thePacket->mPacketType) @@ -762,7 +765,7 @@ static bool garmin_probe(struct gps_device_t *session) , &session->ttyset_old); return false; } - if ( garmin_get_packet( session ) == (ssize_t)sizeof(session->GarminBuffer)) { + if ( 0 == GetPacket( session ) ) { (void)PrintPacket(session, thePacket); if( (GARMIN_LAYERID_APPL == (unsigned int)thePacket->mPacketType) @@ -822,6 +825,11 @@ static void garmin_init(struct gps_device_t *session) //SendPacket(session, thePacket); } +static int garmin_get_packet(struct gps_device_t *session) +{ + return ( 0 == GetPacket( session ) ? 1 : 0); +} + static gps_mask_t garmin_parse_input(struct gps_device_t *session) { return PrintPacket(session, (Packet_t*)session->GarminBuffer); |