summaryrefslogtreecommitdiff
path: root/driver_garmin.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2013-09-29 01:42:45 -0400
committerEric S. Raymond <esr@thyrsus.com>2013-09-29 01:46:53 -0400
commit4361ec2d89bdf451602d659ddfd0fb9a79c178a2 (patch)
treeaf067d1d7614a9e67f449eec933ba3347cde10b0 /driver_garmin.c
parenta77b95b57475c2856707e91b197f8aaa8e5eb407 (diff)
downloadgpsd-4361ec2d89bdf451602d659ddfd0fb9a79c178a2.tar.gz
Change gpsd_report to no longer use a global. All regression tests pass.
This is a large, ugly change. But without it we can't troubleshoot the ICP/IP-source initialization bug properly - colliding definitions of gpsd_report() were interfering with error reporting early in gpsd runs. More cleanup work remains to be done, but at least this is working.
Diffstat (limited to 'driver_garmin.c')
-rw-r--r--driver_garmin.c222
1 files changed, 134 insertions, 88 deletions
diff --git a/driver_garmin.c b/driver_garmin.c
index 7e4f82f3..a340072d 100644
--- a/driver_garmin.c
+++ b/driver_garmin.c
@@ -304,17 +304,17 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id,
cpo_pvt_data *pvt = NULL;
cpo_rcv_data *rmd = NULL;
- gpsd_report(LOG_IO, "Garmin: PrintSERPacket(, %#02x, %#02x, )\n", pkt_id,
- pkt_len);
+ gpsd_report(session->context->debug, LOG_IO,
+ "Garmin: PrintSERPacket(, %#02x, %#02x, )\n", pkt_id, pkt_len);
session->cycle_end_reliable = true;
switch (pkt_id) {
case ACK:
- gpsd_report(LOG_PROG, "Garmin: ACK\n");
+ gpsd_report(session->context->debug, LOG_PROG, "Garmin: ACK\n");
break;
case NAK:
- gpsd_report(LOG_PROG, "Garmin: NAK\n");
+ gpsd_report(session->context->debug, LOG_PROG, "Garmin: NAK\n");
break;
case GARMIN_PKTID_L001_COMMAND_DATA:
prod_id = get_uint16((uint8_t *) buf);
@@ -339,29 +339,36 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id,
break;
}
/*@ +branchstate @*/
- gpsd_report(LOG_PROG, "Garmin: Appl, Command Data: %s\n", msg);
+ gpsd_report(session->context->debug, LOG_PROG,
+ "Garmin: Appl, Command Data: %s\n", msg);
break;
case GARMIN_PKTID_PRODUCT_RQST:
- gpsd_report(LOG_PROG, "Garmin: Appl, Product Data req\n");
+ gpsd_report(session->context->debug, LOG_PROG,
+ "Garmin: Appl, Product Data req\n");
break;
case GARMIN_PKTID_PRODUCT_DATA:
prod_id = get_uint16((uint8_t *) buf);
ver = get_uint16((uint8_t *) & buf[2]);
maj_ver = (int)(ver / 100);
min_ver = (int)(ver - (maj_ver * 100));
- gpsd_report(LOG_PROG, "Garmin: Appl, Product Data, sz: %d\n",
+ gpsd_report(session->context->debug, LOG_PROG,
+ "Garmin: Appl, Product Data, sz: %d\n",
pkt_len);
(void)snprintf(session->subtype, sizeof(session->subtype),
"%d: %d.%02d", (int)prod_id, maj_ver, min_ver);
- gpsd_report(LOG_INF, "Garmin: Product ID: %d, SoftVer: %d.%02d\n",
+ gpsd_report(session->context->debug, LOG_INF,
+ "Garmin: Product ID: %d, SoftVer: %d.%02d\n",
prod_id, maj_ver, min_ver);
- gpsd_report(LOG_INF, "Garmin: Product Desc: %s\n", &buf[4]);
+ gpsd_report(session->context->debug, LOG_INF,
+ "Garmin: Product Desc: %s\n", &buf[4]);
mask |= DEVICEID_SET;
- gpsd_report(LOG_DATA, "Garmin: PRODUCT_DATA: subtype=%s\n",
+ gpsd_report(session->context->debug, LOG_DATA,
+ "Garmin: PRODUCT_DATA: subtype=%s\n",
session->subtype);
break;
case GARMIN_PKTID_PVT_DATA:
- gpsd_report(LOG_PROG, "Garmin: Appl, PVT Data Sz: %d\n", pkt_len);
+ gpsd_report(session->context->debug, LOG_PROG,
+ "Garmin: Appl, PVT Data Sz: %d\n", pkt_len);
pvt = (cpo_pvt_data *) buf;
@@ -375,26 +382,29 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id,
time_l += (time_t) round(pvt->gps_tow);
session->context->gps_tow = pvt->gps_tow;
session->newdata.time = (timestamp_t)time_l;
- gpsd_report(LOG_PROG, "Garmin: time_l: %ld\n", (long int)time_l);
+ gpsd_report(session->context->debug, LOG_PROG,
+ "Garmin: time_l: %ld\n", (long int)time_l);
session->newdata.latitude = radtodeg(pvt->lat);
/* sanity check the lat */
if (90.0 < session->newdata.latitude) {
session->newdata.latitude = 90.0;
- gpsd_report(LOG_INF, "Garmin: ERROR: Latitude overrange\n");
+ gpsd_report(session->context->debug, LOG_INF,
+ "Garmin: ERROR: Latitude overrange\n");
} else if (-90.0 > session->newdata.latitude) {
session->newdata.latitude = -90.0;
- gpsd_report(LOG_INF,
+ gpsd_report(session->context->debug, LOG_INF,
"Garmin: ERROR: Latitude negative overrange\n");
}
session->newdata.longitude = radtodeg(pvt->lon);
/* sanity check the lon */
if (180.0 < session->newdata.longitude) {
session->newdata.longitude = 180.0;
- gpsd_report(LOG_INF, "Garmin: ERROR: Longitude overrange\n");
+ gpsd_report(session->context->debug, LOG_INF,
+ "Garmin: ERROR: Longitude overrange\n");
} else if (-180.0 > session->newdata.longitude) {
session->newdata.longitude = -180.0;
- gpsd_report(LOG_INF,
+ gpsd_report(session->context->debug, LOG_INF,
"Garmin: ERROR: Longitude negative overrange\n");
}
// altitude over WGS84 converted to MSL
@@ -456,18 +466,20 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id,
break;
}
- gpsd_report(LOG_PROG, "Garmin: Appl, mode %d, status %d\n",
+ gpsd_report(session->context->debug, LOG_PROG,
+ "Garmin: Appl, mode %d, status %d\n",
session->newdata.mode, session->gpsdata.status);
- gpsd_report(LOG_INF, "Garmin: UTC Time: %lf\n",
+ gpsd_report(session->context->debug, LOG_INF,
+ "Garmin: UTC Time: %lf\n",
session->newdata.time);
- gpsd_report(LOG_INF,
+ gpsd_report(session->context->debug, LOG_INF,
"Garmin: Geoid Separation (MSL-WGS84): from garmin %lf, calculated %lf\n",
-pvt->msl_hght,
wgs84_separation(session->newdata.latitude,
session->newdata.longitude));
- gpsd_report(LOG_INF,
+ gpsd_report(session->context->debug, LOG_INF,
"Garmin: Alt: %.3f, Epe: %.3f, Eph: %.3f, Epv: %.3f, Fix: %d, Gps_tow: %f, Lat: %.3f, Lon: %.3f, LonVel: %.3f, LatVel: %.3f, AltVel: %.3f, MslHgt: %.3f, Leap: %d, GarminDays: %d\n",
pvt->alt, pvt->epe, pvt->eph, pvt->epv, GPSD_LE16TOH(pvt->fix),
pvt->gps_tow, session->newdata.latitude,
@@ -489,7 +501,7 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id,
if (session->fixcnt > 3)
mask |= PPSTIME_IS;
}
- gpsd_report(LOG_DATA,
+ gpsd_report(session->context->debug, LOG_DATA,
"Garmin: PVT_DATA: time=%.2f, lat=%.2f lon=%.2f "
"speed=%.2f track=%.2f climb=%.2f "
"epx=%.2f epy=%.2f epv=%.2f "
@@ -509,11 +521,13 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id,
case GARMIN_PKTID_RMD_DATA:
case GARMIN_PKTID_RMD41_DATA:
rmd = (cpo_rcv_data *) buf;
- gpsd_report(LOG_IO, "Garmin: PVT RMD Data Sz: %d\n", pkt_len);
- gpsd_report(LOG_PROG, "Garmin: PVT RMD rcvr_tow: %f, rcvr_wn: %d\n",
+ gpsd_report(session->context->debug, LOG_IO,
+ "Garmin: PVT RMD Data Sz: %d\n", pkt_len);
+ gpsd_report(session->context->debug, LOG_PROG,
+ "Garmin: PVT RMD rcvr_tow: %f, rcvr_wn: %d\n",
rmd->rcvr_tow, rmd->rcvr_wn);
for (i = 0; i < GARMIN_CHANNELS; i++) {
- gpsd_report(LOG_INF,
+ gpsd_report(session->context->debug, LOG_INF,
"Garmin: PVT RMD Sat: %3u, cycles: %9u, pr: %16.6f, "
"phase: %7.3f, slp_dtct: %3s, snr: %3u, Valid: %3s\n",
(int)rmd->sv[i].svid + 1,
@@ -527,7 +541,8 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id,
break;
case GARMIN_PKTID_SAT_DATA:
- gpsd_report(LOG_PROG, "Garmin: SAT Data Sz: %d\n", pkt_len);
+ gpsd_report(session->context->debug, LOG_PROG,
+ "Garmin: SAT Data Sz: %d\n", pkt_len);
sats = (cpo_sat_data *) buf;
session->gpsdata.satellites_visible = 0;
@@ -535,7 +550,7 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id,
memset(session->gpsdata.used, 0, sizeof(session->gpsdata.used));
gpsd_zero_satellites(&session->gpsdata);
for (i = 0, j = 0; i < GARMIN_CHANNELS; i++, sats++) {
- gpsd_report(LOG_INF,
+ gpsd_report(session->context->debug, LOG_INF,
"Garmin: Sat %3d, snr: %5u, elev: %2d, Azmth: %3d, Stat: %x\n",
sats->svid, GPSD_LE16TOH(sats->snr), sats->elev,
GPSD_LE16TOH(sats->azmth),
@@ -576,7 +591,7 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id,
mask |= SATELLITE_SET;
if (session->gpsdata.satellites_used > 0)
mask |= USED_IS;
- gpsd_report(LOG_DATA,
+ gpsd_report(session->context->debug, LOG_DATA,
"Garmin: SAT_DATA: visible=%d used=%d\n",
session->gpsdata.satellites_visible,
session->gpsdata.satellites_used);
@@ -584,20 +599,23 @@ gps_mask_t PrintSERPacket(struct gps_device_t *session, unsigned char pkt_id,
case GARMIN_PKTID_PROTOCOL_ARRAY:
// this packet is never requested, it just comes, in some case
// after a GARMIN_PKTID_PRODUCT_RQST
- gpsd_report(LOG_INF, "Garmin: Appl, Product Capability, sz: %d\n",
+ gpsd_report(session->context->debug, LOG_INF,
+ "Garmin: Appl, Product Capability, sz: %d\n",
pkt_len);
for (i = 0; i < pkt_len; i += 3) {
- gpsd_report(LOG_INF, "Garmin: %c%03d\n", buf[i],
- get_uint16((uint8_t *) & buf[i + 1]));
+ gpsd_report(session->context->debug, LOG_INF,
+ "Garmin: %c%03d\n",
+ buf[i], get_uint16((uint8_t *) & buf[i + 1]));
}
break;
default:
- gpsd_report(LOG_WARN,
+ gpsd_report(session->context->debug, LOG_WARN,
"Garmin: Unknown packet id: %#02x, Sz: %#02x\n",
pkt_id, pkt_len);
break;
}
- gpsd_report(LOG_IO, "Garmin: PrintSERPacket(, %#02x, %#02x, )\n",
+ gpsd_report(session->context->debug, LOG_IO,
+ "Garmin: PrintSERPacket(, %#02x, %#02x, )\n",
pkt_id, pkt_len);
return mask;
}
@@ -619,17 +637,19 @@ static gps_mask_t PrintUSBPacket(struct gps_device_t *session, Packet_t * pkt)
//
uint8_t *buffer = (uint8_t *) pkt;
- gpsd_report(LOG_PROG, "Garmin: PrintUSBPacket()\n");
+ gpsd_report(session->context->debug, LOG_PROG, "Garmin: PrintUSBPacket()\n");
// gem
if (DLE == pkt->mPacketType) {
- gpsd_report(LOG_PROG, "Garmin: really a SER packet!\n");
+ gpsd_report(session->context->debug, LOG_PROG,
+ "Garmin: really a SER packet!\n");
return PrintSERPacket(session,
(unsigned char)buffer[1],
(int)buffer[2], (unsigned char *)(buffer + 3));
}
// gem
if (4096 < mDataSize) {
- gpsd_report(LOG_WARN, "Garmin: bogus packet, size too large=%d\n",
+ gpsd_report(session->context->debug, LOG_WARN,
+ "Garmin: bogus packet, size too large=%d\n",
mDataSize);
return 0;
}
@@ -641,16 +661,17 @@ static gps_mask_t PrintUSBPacket(struct gps_device_t *session, Packet_t * pkt)
/* Garmin USB layer specific */
switch (pkt->mPacketId) {
case GARMIN_PKTID_TRANSPORT_START_SESSION_REQ:
- gpsd_report(LOG_PROG, "Garmin: Transport, Start Session req\n");
+ gpsd_report(session->context->debug, LOG_PROG,
+ "Garmin: Transport, Start Session req\n");
break;
case GARMIN_PKTID_TRANSPORT_START_SESSION_RESP:
mode = get_int32(&pkt->mData.uchars[0]);
- gpsd_report(LOG_PROG,
+ gpsd_report(session->context->debug, LOG_PROG,
"Garmin: Transport, Start Session resp, unit: 0x%x\n",
mode);
break;
default:
- gpsd_report(LOG_PROG,
+ gpsd_report(session->context->debug, LOG_PROG,
"Garmin: Transport, Packet: Type %d %d %d, ID: %d, Sz: %d\n",
pkt->mPacketType, pkt->mReserved1, pkt->mReserved2,
pkt->mPacketId, mDataSize);
@@ -670,10 +691,12 @@ static gps_mask_t PrintUSBPacket(struct gps_device_t *session, Packet_t * pkt)
switch (pkt->mPacketId) {
case PRIV_PKTID_SET_MODE:
prod_id = get_uint16(&pkt->mData.uchars[0]);
- gpsd_report(LOG_PROG, "Garmin: Private, Set Mode: %d\n", prod_id);
+ gpsd_report(session->context->debug, LOG_PROG,
+ "Garmin: Private, Set Mode: %d\n", prod_id);
break;
case PRIV_PKTID_INFO_REQ:
- gpsd_report(LOG_PROG, "Garmin: Private, ID: Info Req\n");
+ gpsd_report(session->context->debug, LOG_PROG,
+ "Garmin: Private, ID: Info Req\n");
break;
case PRIV_PKTID_INFO_RESP:
veri = get_int32(pkt->mData.uchars);
@@ -681,19 +704,21 @@ static gps_mask_t PrintUSBPacket(struct gps_device_t *session, Packet_t * pkt)
min_ver = (int)(veri & 0xffff);
mode = get_int32(&pkt->mData.uchars[4]);
serial = get_int32(&pkt->mData.uchars[8]);
- gpsd_report(LOG_PROG, "Garmin: Private, ID: Info Resp\n");
- gpsd_report(LOG_INF,
+ gpsd_report(session->context->debug, LOG_PROG,
+ "Garmin: Private, ID: Info Resp\n");
+ gpsd_report(session->context->debug, LOG_INF,
"Garmin: USB Driver found, Version %d.%d, Mode: %d, GPS Serial# %u\n",
maj_ver, min_ver, mode, serial);
break;
default:
- gpsd_report(LOG_PROG, "Garmin: Private, Packet: ID: %d, Sz: %d\n",
+ gpsd_report(session->context->debug, LOG_PROG,
+ "Garmin: Private, Packet: ID: %d, Sz: %d\n",
pkt->mPacketId, mDataSize);
break;
}
break;
default:
- gpsd_report(LOG_PROG,
+ gpsd_report(session->context->debug, LOG_PROG,
"Garmin: Packet: Type %d %d %d, ID: %d, Sz: %d\n",
pkt->mPacketType, pkt->mReserved1, pkt->mReserved2,
pkt->mPacketId, mDataSize);
@@ -729,7 +754,8 @@ static void Build_Send_USB_Packet(struct gps_device_t *session,
theBytesReturned = gpsd_write(session, (const char *)thePacket,
(size_t) theBytesToWrite);
- gpsd_report(LOG_IO, "Garmin: SendPacket(), wrote %zd bytes\n",
+ gpsd_report(session->context->debug, LOG_IO,
+ "Garmin: SendPacket(), wrote %zd bytes\n",
theBytesReturned);
// Garmin says:
@@ -801,7 +827,8 @@ static void Build_Send_SER_Packet(struct gps_device_t *session,
theBytesReturned = gpsd_write(session, (const char *)thePacket,
(size_t) theBytesToWrite);
- gpsd_report(LOG_IO, "Garmin: SendPacket(), wrote %zd bytes\n",
+ gpsd_report(session->context->debug, LOG_IO,
+ "Garmin: SendPacket(), wrote %zd bytes\n",
theBytesReturned);
}
@@ -817,7 +844,8 @@ static void Build_Send_SER_Packet(struct gps_device_t *session,
* libudev: http://www.kernel.org/pub/linux/utils/kernel/hotplug/libudev/
*/
/*@-compdef -usedef -nullpass@*/
-static bool is_usb_device(const char *path UNUSED, int vendor, int product)
+static bool is_usb_device(const char *path UNUSED, int vendor, int product,
+ const int debug)
{
// discover devices
libusb_device **list;
@@ -825,11 +853,13 @@ static bool is_usb_device(const char *path UNUSED, int vendor, int product)
ssize_t i = 0;
bool found = false;
- gpsd_report(LOG_INF, "attempting USB device enumeration.\n");
+ gpsd_report(debug, LOG_INF,
+ "attempting USB device enumeration.\n");
(void)libusb_init(NULL);
if ((cnt = libusb_get_device_list(NULL, &list)) < 0) {
- gpsd_report(LOG_ERROR, "USB device list call failed.\n");
+ gpsd_report(debug, LOG_ERROR,
+ "USB device list call failed.\n");
libusb_exit(NULL);
return false;
}
@@ -840,13 +870,14 @@ static bool is_usb_device(const char *path UNUSED, int vendor, int product)
int r = libusb_get_device_descriptor(dev, &desc);
if (r < 0) {
- gpsd_report(LOG_ERROR,
+ gpsd_report(debug, LOG_ERROR,
"USB descriptor fetch failed on device %zd.\n", i);
continue;
}
/* we can extract device descriptor data */
- gpsd_report(LOG_INF, "%04x:%04x (bus %d, device %d)\n",
+ gpsd_report(debug, LOG_INF,
+ "%04x:%04x (bus %d, device %d)\n",
desc.idVendor, desc.idProduct,
libusb_get_bus_number(dev),
libusb_get_device_address(dev));
@@ -858,7 +889,8 @@ static bool is_usb_device(const char *path UNUSED, int vendor, int product)
}
}
- gpsd_report(LOG_SHOUT, "vendor/product match with %04x:%04x %sfound\n",
+ gpsd_report(debug, LOG_SHOUT,
+ "vendor/product match with %04x:%04x %sfound\n",
vendor, product, found ? "" : "not ");
libusb_free_device_list(list, 1);
libusb_exit(NULL);
@@ -893,7 +925,7 @@ static bool is_usb_device(const char *path UNUSED, int vendor, int product)
* return 1 is device found
* return 0 if not
*/
-static bool garmin_usb_detect(struct gps_device_t *session UNUSED)
+static bool garmin_usb_detect(struct gps_device_t *session)
{
#if defined(__linux__) || defined(S_SPLINT_S)
/*
@@ -906,11 +938,12 @@ static bool garmin_usb_detect(struct gps_device_t *session UNUSED)
return false;
else {
#ifdef HAVE_LIBUSB
- if (!is_usb_device(session->gpsdata.dev.path, 0x091e, 0x0003))
+ if (!is_usb_device(session->gpsdata.dev.path, 0x091e, 0x0003,
+ session->context->debug))
return false;
if (!gpsd_set_raw(session)) {
- gpsd_report(LOG_ERROR,
+ gpsd_report(session->context->debug, LOG_ERROR,
"Garmin: garmin_usb_detect: error changing port attributes: %s\n",
strerror(errno));
return false;
@@ -918,7 +951,7 @@ static bool garmin_usb_detect(struct gps_device_t *session UNUSED)
if (sizeof(session->driver.garmin.Buffer) < sizeof(Packet_t)) {
/* dunno how this happens, but it does on some compilers */
- gpsd_report(LOG_ERROR,
+ gpsd_report(session->context->debug, LOG_ERROR,
"Garmin: garmin_usb_detect: Compile error, garmin.Buffer too small.\n");
return false;
}
@@ -926,7 +959,8 @@ static bool garmin_usb_detect(struct gps_device_t *session UNUSED)
// FIXME!!! needs to use libusb totally and move garmin_gps aside */
// set Mode 1, mode 0 is broken somewhere past 2.6.14
// but how?
- gpsd_report(LOG_PROG, "Garmin: Set garmin_gps driver mode = 0\n");
+ gpsd_report(session->context->debug, LOG_PROG,
+ "Garmin: Set garmin_gps driver mode = 0\n");
Build_Send_USB_Packet(session, GARMIN_LAYERID_PRIVATE,
PRIV_PKTID_SET_MODE, 4, MODE_GARMIN_SERIAL);
// expect no return packet !?
@@ -951,12 +985,13 @@ static void garmin_event_hook(struct gps_device_t *session, event_t event)
*/
if (event == event_identified || event == event_reactivate) {
// Tell the device to send product data
- gpsd_report(LOG_PROG, "Garmin: Get Product Data\n");
+ gpsd_report(session->context->debug, LOG_PROG, "Garmin: Get Product Data\n");
Build_Send_SER_Packet(session, GARMIN_LAYERID_APPL,
GARMIN_PKTID_PRODUCT_RQST, 0, 0);
// turn on PVT data 49
- gpsd_report(LOG_PROG, "Garmin: Set to send reports every 1 second\n");
+ gpsd_report(session->context->debug, LOG_PROG,
+ "Garmin: Set to send reports every 1 second\n");
Build_Send_SER_Packet(session, GARMIN_LAYERID_APPL,
GARMIN_PKTID_L001_COMMAND_DATA, 2,
@@ -964,7 +999,8 @@ static void garmin_event_hook(struct gps_device_t *session, event_t event)
#if USE_RMD
// turn on RMD data 110
- gpsd_report(LOG_PROG, "Garmin: Set to send Raw sat data\n");
+ gpsd_report(session->context->debug, LOG_PROG,
+ "Garmin: Set to send Raw sat data\n");
Build_Send_SER_Packet(session, GARMIN_LAYERID_APPL,
GARMIN_PKTID_L001_COMMAND_DATA, 2,
CMND_START_RM_DATA);
@@ -972,7 +1008,7 @@ static void garmin_event_hook(struct gps_device_t *session, event_t event)
}
if (event == event_deactivate)
/* FIX-ME: is any action needed, or is closing the port sufficient? */
- gpsd_report(LOG_PROG, "Garmin: garmin_close()\n");
+ gpsd_report(session->context->debug, LOG_PROG, "Garmin: garmin_close()\n");
}
#define Send_ACK() Build_Send_SER_Packet(session, 0, ACK, 0, 0)
@@ -997,22 +1033,24 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session)
if (session->packet.type == GARMIN_PACKET)
session->gpsdata.dev.driver_mode = MODE_BINARY;
- gpsd_report(LOG_RAW, "Garmin: garmin_ser_parse()\n");
+ gpsd_report(session->context->debug, LOG_RAW, "Garmin: garmin_ser_parse()\n");
if (6 > len) {
/* WTF? */
/* minimum packet; <DLE> [pkt id] [length=0] [chksum] <DLE> <STX> */
Send_NAK();
- gpsd_report(LOG_RAW + 1, "Garmin: serial too short: %zd\n", len);
+ gpsd_report(session->context->debug, LOG_RAW + 1,
+ "Garmin: serial too short: %zd\n", len);
return 0;
}
/* debug */
for (i = 0; i < (int)len; i++) {
- gpsd_report(LOG_RAW + 1, "Garmin: Char: %#02x\n", buf[i]);
+ gpsd_report(session->context->debug, LOG_RAW + 1,
+ "Garmin: Char: %#02x\n", buf[i]);
}
if ('\x10' != buf[0]) {
Send_NAK();
- gpsd_report(LOG_RAW + 1, "Garmin: buf[0] not DLE\n");
+ gpsd_report(session->context->debug, LOG_RAW + 1, "Garmin: buf[0] not DLE\n");
return 0;
}
n = 1;
@@ -1021,7 +1059,7 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session)
if ('\x10' == pkt_id) {
if ('\x10' != buf[n++]) {
Send_NAK();
- gpsd_report(LOG_RAW + 1, "Garmin: Bad pkt_id %#02x\n", pkt_id);
+ gpsd_report(session->context->debug, LOG_RAW + 1, "Garmin: Bad pkt_id %#02x\n", pkt_id);
return 0;
}
}
@@ -1030,7 +1068,8 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session)
chksum += pkt_len;
if ('\x10' == pkt_len) {
if ('\x10' != buf[n++]) {
- gpsd_report(LOG_RAW + 1, "Garmin: Bad pkt_len %#02x\n", pkt_len);
+ gpsd_report(session->context->debug, LOG_RAW + 1,
+ "Garmin: Bad pkt_len %#02x\n", pkt_len);
Send_NAK();
return 0;
}
@@ -1043,7 +1082,8 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session)
break;
}
if (len < n + i) {
- gpsd_report(LOG_RAW + 1, "Garmin: Packet too short %zd < %zd\n",
+ gpsd_report(session->context->debug, LOG_RAW + 1,
+ "Garmin: Packet too short %zd < %zd\n",
len, n + i);
Send_NAK();
return 0;
@@ -1053,7 +1093,8 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session)
got_dle = 0;
if ('\x10' != c) {
Send_NAK();
- gpsd_report(LOG_RAW + 1, "Garmin: Bad DLE %#02x\n", c);
+ gpsd_report(session->context->debug, LOG_RAW + 1,
+ "Garmin: Bad DLE %#02x\n", c);
return 0;
}
} else {
@@ -1067,7 +1108,7 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session)
/* get checksum */
if (len < n + i) {
Send_NAK();
- gpsd_report(LOG_RAW + 1,
+ gpsd_report(session->context->debug, LOG_RAW + 1,
"Garmin: No checksum, Packet too short %zd < %zd\n", len,
n + i);
return 0;
@@ -1077,7 +1118,7 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session)
/* get final DLE */
if (len < n + i) {
Send_NAK();
- gpsd_report(LOG_RAW + 1,
+ gpsd_report(session->context->debug, LOG_RAW + 1,
"Garmin: No final DLE, Packet too short %zd < %zd\n", len,
n + i);
return 0;
@@ -1085,13 +1126,13 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session)
c = buf[n + i++];
if ('\x10' != c) {
Send_NAK();
- gpsd_report(LOG_RAW + 1, "Garmin: Final DLE not DLE\n");
+ gpsd_report(session->context->debug, LOG_RAW + 1, "Garmin: Final DLE not DLE\n");
return 0;
}
/* get final ETX */
if (len < n + i) {
Send_NAK();
- gpsd_report(LOG_RAW + 1,
+ gpsd_report(session->context->debug, LOG_RAW + 1,
"Garmin: No final ETX, Packet too short %zd < %zd\n", len,
n + i);
return 0;
@@ -1100,18 +1141,20 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session)
c = buf[n + i];
if ('\x03' != c) {
Send_NAK();
- gpsd_report(LOG_RAW + 1, "Garmin: Final ETX not ETX\n");
+ gpsd_report(session->context->debug, LOG_RAW + 1,
+ "Garmin: Final ETX not ETX\n");
return 0;
}
/* debug */
/*@ -usedef -compdef @*/
for (i = 0; i < data_index; i++) {
- gpsd_report(LOG_RAW + 1, "Garmin: Char: %#02x\n", data_buf[i]);
+ gpsd_report(session->context->debug, LOG_RAW + 1,
+ "Garmin: Char: %#02x\n", data_buf[i]);
}
- gpsd_report(LOG_IO,
+ gpsd_report(session->context->debug, LOG_IO,
"Garmin: garmin_ser_parse() Type: %#02x, Len: %#02x, chksum: %#02x\n",
pkt_id, pkt_len, chksum);
mask = PrintSERPacket(session, pkt_id, pkt_len, data_buf);
@@ -1121,7 +1164,7 @@ gps_mask_t garmin_ser_parse(struct gps_device_t *session)
(void)usleep(300);
Send_ACK();
/*@ +usedef +compdef @*/
- gpsd_report(LOG_IO, "Garmin: garmin_ser_parse( )\n");
+ gpsd_report(session->context->debug, LOG_IO, "Garmin: garmin_ser_parse( )\n");
return mask;
}
@@ -1149,12 +1192,13 @@ static void garmin_switcher(struct gps_device_t *session, int mode)
ssize_t status = gpsd_write(session, switcher, sizeof(switcher));
/*@ -charint @*/
if (status == (ssize_t)sizeof(switcher)) {
- gpsd_report(LOG_IO,
+ gpsd_report(session->context->debug, LOG_IO,
"Garmin: => GPS: turn off binary %02x %02x %02x... \n",
switcher[0], switcher[1], switcher[2]);
session->gpsdata.dev.driver_mode = MODE_NMEA;
} else {
- gpsd_report(LOG_ERROR, "Garmin: => GPS: FAILED\n");
+ gpsd_report(session->context->debug, LOG_ERROR,
+ "Garmin: => GPS: FAILED\n");
}
settle(); // wait 333mS, essential!
@@ -1238,7 +1282,7 @@ static int GetPacket(struct gps_device_t *session)
session->driver.garmin.BufferLen = 0;
session->packet.outbuflen = 0;
- gpsd_report(LOG_IO, "Garmin: GetPacket()\n");
+ gpsd_report(session->context->debug, LOG_IO, "Garmin: GetPacket()\n");
for (cnt = 0; cnt < 10; cnt++) {
size_t pkt_size;
@@ -1259,17 +1303,18 @@ static int GetPacket(struct gps_device_t *session)
if (0 > theBytesReturned) {
// read error...
// or EAGAIN, but O_NONBLOCK is never set
- gpsd_report(LOG_ERROR,
+ gpsd_report(session->context->debug, LOG_ERROR,
"Garmin: GetPacket() read error=%d, errno=%d\n",
theBytesReturned, errno);
continue;
}
- gpsd_report(LOG_RAW, "Garmin: got %d bytes\n", theBytesReturned);
+ gpsd_report(session->context->debug, LOG_RAW,
+ "Garmin: got %d bytes\n", theBytesReturned);
session->driver.garmin.BufferLen += theBytesReturned;
if (256 <= session->driver.garmin.BufferLen) {
// really bad read error...
- gpsd_report(LOG_ERROR,
+ gpsd_report(session->context->debug, LOG_ERROR,
"Garmin: GetPacket() packet too long, %ld > 255 !\n",
session->driver.garmin.BufferLen);
session->driver.garmin.BufferLen = 0;
@@ -1280,7 +1325,7 @@ static int GetPacket(struct gps_device_t *session)
// have enough data to check packet size
if (session->driver.garmin.BufferLen > pkt_size) {
// wrong amount of data in buffer
- gpsd_report(LOG_ERROR,
+ gpsd_report(session->context->debug, LOG_ERROR,
"Garmin: GetPacket() packet size wrong! Packet: %ld, s/b %ld\n",
session->driver.garmin.BufferLen, pkt_size);
session->driver.garmin.BufferLen = 0;
@@ -1302,15 +1347,16 @@ static int GetPacket(struct gps_device_t *session)
}
// dump the individual bytes, debug only
// for ( x = 0; x < session->driver.garmin.BufferLen; x++ ) {
- // gpsd_report(LOG_RAW+1, "Garmin: p[%d] = %x\n", x, session->driver.garmin.Buffer[x]);
+ // gpsd_report(session->context->debug, LOG_RAW+1, "Garmin: p[%d] = %x\n", x, session->driver.garmin.Buffer[x]);
// }
if (10 <= cnt) {
- gpsd_report(LOG_ERROR,
+ gpsd_report(session->context->debug, LOG_ERROR,
"Garmin: GetPacket() packet too long or too slow!\n");
return -1;
}
- gpsd_report(LOG_RAW, "Garmin: GotPacket() sz=%d \n",
+ gpsd_report(session->context->debug, LOG_RAW,
+ "Garmin: GotPacket() sz=%d \n",
session->driver.garmin.BufferLen);
session->packet.outbuflen = session->driver.garmin.BufferLen;
return 0;
@@ -1318,7 +1364,7 @@ static int GetPacket(struct gps_device_t *session)
static gps_mask_t garmin_usb_parse(struct gps_device_t *session)
{
- gpsd_report(LOG_PROG, "Garmin: garmin_usb_parse()\n");
+ gpsd_report(session->context->debug, LOG_PROG, "Garmin: garmin_usb_parse()\n");
return PrintUSBPacket(session,
(Packet_t *) session->driver.garmin.Buffer);
}