summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary E. Miller <gem@rellim.com>2005-06-28 04:10:40 +0000
committerGary E. Miller <gem@rellim.com>2005-06-28 04:10:40 +0000
commitf5a180ff4be1599ffc8dae38d97a42242979f809 (patch)
tree0b4a8650a8eb50c7de6f16db45269beabf2e88fd
parent364d6ce3ddda7aeabb4446b6f5b6fb7fb2b62df0 (diff)
downloadgpsd-f5a180ff4be1599ffc8dae38d97a42242979f809.tar.gz
Modify garmin code to remove calloc(). GarminBuffer is now in gps_device_t.
-rw-r--r--garmin.c26
-rw-r--r--gpsd.h4
2 files changed, 15 insertions, 15 deletions
diff --git a/garmin.c b/garmin.c
index 537f079c..644895b9 100644
--- a/garmin.c
+++ b/garmin.c
@@ -527,7 +527,7 @@ static int GetPacket (struct gps_device_t *session )
// not optimal, but given the speed and packet nature of
// the USB not too bad for a start
ssize_t theBytesReturned = 0;
- char *buf = (char *)session->GarminBuffer;
+ unsigned char *buf = session->GarminBuffer;
theBytesReturned = read(session->gpsdata.gps_fd
, buf + session->GarminBufferLen
@@ -613,16 +613,18 @@ static bool garmin_probe(struct gps_device_t *session)
return false;
}
- if ( !session->GarminBuffer ) {
- // get a packet buffer
- session->GarminBuffer = calloc( sizeof(Packet_t), 1);
- if ( NULL == session->GarminBuffer ) {
- gpsd_report(0, "garmin_probe: out of memory!\n");
- return false;
- }
+ /* reset the buffer and buffer length */
+ memset( session->GarminBuffer, 0, sizeof(session->GarminBuffer) );
+ session->GarminBufferLen = 0;
+
+ if (sizeof(session->GarminBuffer) < sizeof(Packet_t)) {
+ gpsd_report(0, "garmin_probe: Compile error, GarminBuffer too small.\n",
+ strerror(errno));
+ return false;
}
- thePacket = (Packet_t*)session->GarminBuffer;
- buffer = (unsigned char *)thePacket;
+
+ buffer = session->GarminBuffer;
+ thePacket = (Packet_t*)buffer;
// set Mode 0
set_int(buffer, GARMIN_LAYERID_PRIVATE);
@@ -796,8 +798,8 @@ static bool garmin_probe(struct gps_device_t *session)
*/
static void garmin_init(struct gps_device_t *session)
{
- Packet_t *thePacket = (Packet_t*)session->GarminBuffer;
- unsigned char *buffer = (unsigned char *)thePacket;
+ unsigned char *buffer = session->GarminBuffer;
+ Packet_t *thePacket = (Packet_t*)buffer;
bool ret;
gpsd_report(5, "to garmin_probe()\n");
diff --git a/gpsd.h b/gpsd.h
index a57aa0e5..10187c0d 100644
--- a/gpsd.h
+++ b/gpsd.h
@@ -121,9 +121,7 @@ struct gps_device_t {
time_t last_6d;
#endif /* TSIP_ENABLE */
#ifdef GARMIN_ENABLE /* private housekeeping stuff for the Garmin driver */
- /*@relnull@*/void *GarminBuffer; /* Pointer Garmin packet buffer
- void *, to keep the packet details out of the
- global context and save spave */
+ unsigned char GarminBuffer[4096+12]; /* Garmin packet buffer */
size_t GarminBufferLen; /* current GarminBuffer Length */
#endif /* GARMIN_ENABLE */
#ifdef ZODIAC_ENABLE /* private housekeeping stuff for the Zodiac driver */