diff options
-rw-r--r-- | driver_evermore.c | 9 | ||||
-rw-r--r-- | driver_garmin.c | 11 | ||||
-rw-r--r-- | driver_italk.c | 14 | ||||
-rw-r--r-- | driver_navcom.c | 7 | ||||
-rw-r--r-- | driver_oncore.c | 73 | ||||
-rw-r--r-- | driver_proto.c | 19 | ||||
-rw-r--r-- | driver_sirf.c | 7 | ||||
-rw-r--r-- | driver_superstar2.c | 13 | ||||
-rw-r--r-- | driver_tsip.c | 12 | ||||
-rw-r--r-- | driver_ubx.c | 11 | ||||
-rw-r--r-- | driver_zodiac.c | 2 | ||||
-rw-r--r-- | drivers.c | 87 | ||||
-rw-r--r-- | gpsd.h-tail | 3 | ||||
-rw-r--r-- | libgpsd_core.c | 35 | ||||
-rw-r--r-- | www/writing-a-driver.xml | 16 |
15 files changed, 140 insertions, 179 deletions
diff --git a/driver_evermore.c b/driver_evermore.c index 454781f9..60950558 100644 --- a/driver_evermore.c +++ b/driver_evermore.c @@ -483,11 +483,10 @@ static void evermore_mode(struct gps_device_t *session, int mode) } } -static void evermore_configurator(struct gps_device_t *session, - event_t event, unsigned int seq) +static void evermore_event_hook(struct gps_device_t *session, event_t event) { - gpsd_report(LOG_PROG, "evermore_configurator(%d)\n", seq); - if (event == event_configure && seq == 0) { + if (event == event_configure && session->packet.counter == 0) { + gpsd_report(LOG_PROG, "evermore_event_hook\n"); if (session->packet.type == NMEA_PACKET) { (void) evermore_nmea_config(session, 1); /* configure NMEA messages for gpsd (GPGSV every 5s) */ gpsd_report(LOG_WARN, "NMEA_PACKET packet\n"); @@ -543,7 +542,7 @@ const struct gps_type_t evermore_binary = .control_send = evermore_control_send, /* how to send a control string */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = evermore_configurator, /* switch to binary */ + .event_hook = evermore_event_hook, /* handle config events */ .speed_switcher = evermore_speed, /* we can change baud rates */ .mode_switcher = evermore_mode, /* there is a mode switcher */ .rate_switcher = evermore_rate_switcher, /* change sample rate */ diff --git a/driver_garmin.c b/driver_garmin.c index a196def4..2f9139f6 100644 --- a/driver_garmin.c +++ b/driver_garmin.c @@ -854,10 +854,9 @@ static bool garmin_detect(struct gps_device_t *session) return true; } -static void garmin_configurator(struct gps_device_t *session, - event_t event, unsigned int seq) +static void garmin_event_hook(struct gps_device_t *session, event_t event) { - if (event == event_probe_subtype && seq == 0) { + if (event == event_probe_subtype && session->packet.counter == 0) { // Tell the device to send product data gpsd_report(LOG_PROG, "Get Garmin Product Data\n"); Build_Send_SER_Packet(session, GARMIN_LAYERID_APPL @@ -1220,7 +1219,7 @@ const struct gps_type_t garmin_usb_binary_old = .control_send = garmin_control_send, /* send raw bytes */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = garmin_configurator, /* enable what we need */ + .event_hook = garmin_event_hook,/* enable what we need */ .speed_switcher = NULL, /* no speed switcher */ .mode_switcher = NULL, /* no mode switcher */ .rate_switcher = NULL, /* no sample-rate switcher */ @@ -1246,7 +1245,7 @@ const struct gps_type_t garmin_usb_binary = .control_send = garmin_control_send, /* send raw bytes */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = garmin_configurator, /* enable what we need */ + .event_hook = garmin_event_hook,/* enable what we need */ .speed_switcher = NULL, /* no speed switcher */ .mode_switcher = garmin_switcher, /* how to change modes */ .rate_switcher = NULL, /* no sample-rate switcher */ @@ -1271,7 +1270,7 @@ const struct gps_type_t garmin_ser_binary = .control_send = garmin_control_send, /* send raw bytes */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = NULL, /* enable what we need */ + .event_hook = NULL, /* enable what we need */ .speed_switcher = NULL, /* no speed switcher */ .mode_switcher = garmin_switcher, /* how to change modes */ .rate_switcher = NULL, /* no sample-rate switcher */ diff --git a/driver_italk.c b/driver_italk.c index f220e820..113e1250 100644 --- a/driver_italk.c +++ b/driver_italk.c @@ -393,10 +393,9 @@ static void italk_mode(struct gps_device_t *session, int mode) } } -static void italk_configurator(struct gps_device_t *session, - event_t event, unsigned int seq) +static void italk_event_hook(struct gps_device_t *session, event_t event) { - if (event == event_configure && seq == 0 && session->packet.type == NMEA_PACKET) + if (event == event_configure && session->packet.counter == 0 && session->packet.type == NMEA_PACKET) (void)italk_set_mode(session, session->gpsdata.dev.baudrate, (char)session->gpsdata.dev.parity, @@ -430,7 +429,7 @@ const struct gps_type_t italk_binary = .control_send = italk_control_send, /* how to send a control string */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = italk_configurator,/* configure the device */ + .event_hook = italk_event_hook, /* handle configure events */ .speed_switcher = italk_speed, /* we can change baud rates */ .mode_switcher = italk_mode, /* there is a mode switcher */ .rate_switcher = NULL, /* no sample-rate switcher */ @@ -506,11 +505,10 @@ static void itrax_probe_subtype(struct gps_device_t *session, unsigned int seq) } #ifdef ALLOW_RECONFIGURE -static void itrax_configurator(struct gps_device_t - event_t event, *session, int seq) +static void itrax_configurator(struct gps_device_t event_t event, *session) /* set synchronous mode */ { - if (event == event_configure && seq == 0) { + if (event == event_configure && session.packet_counter == 0) { (void)literal_send(session->gpsdata.gps_fd, "$PFST,SYNCMODE,1\r\n"); (void)literal_send(session->gpsdata.gps_fd, ITRAX_MODESTRING, session->gpsdata.baudrate); @@ -556,7 +554,7 @@ const static struct gps_type_t itrax = { .control_send = garmin_control_send, /* send raw bytes */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = itrax_configurator,/* set synchronous mode */ + .event_hook = event_hook, /* set synchronous mode */ .speed_switcher = itrax_speed, /* how to change speeds */ .mode_switcher = NULL, /* no mode switcher */ .rate_switcher = itrax_rate, /* there's a sample-rate switcher */ diff --git a/driver_navcom.c b/driver_navcom.c index 51f0aa61..8b3d18f6 100644 --- a/driver_navcom.c +++ b/driver_navcom.c @@ -186,11 +186,10 @@ static void navcom_cmd_0x11(struct gps_device_t *session, u_int8_t port_selectio } #endif /* ALLOW_RECONFIGURE */ -static void navcom_configurator(struct gps_device_t *session, - event_t event, unsigned int seq) +static void navcom_event_hook(struct gps_device_t *session, event_t event) { /* Request the following messages: */ - if (event == event_probe_subtype && seq==0) { + if (event == event_probe_subtype && session->packet.counter == 0) { /*@ +charint @*/ navcom_cmd_0x1c(session, 0x01, 5); /* Blink LEDs on receiver */ navcom_cmd_0x20(session, 0xae, 0x1770); /* Identification Block - send every 10 min*/ @@ -1277,7 +1276,7 @@ const struct gps_type_t navcom_binary = .control_send = navcom_control_send, /* how to send a control string */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = navcom_configurator, /* configuration logic */ + .event_hook = navcom_event_hook, /* configuration logic */ .speed_switcher = navcom_speed, /* we do change baud rates */ .mode_switcher = NULL, /* there is not a mode switcher */ .rate_switcher = NULL, /* no sample-rate switcher */ diff --git a/driver_oncore.c b/driver_oncore.c index b71f3214..77d45aa1 100644 --- a/driver_oncore.c +++ b/driver_oncore.c @@ -44,13 +44,11 @@ static gps_mask_t oncore_msg_firmware(struct gps_device_t *, unsigned char *, si /* * These methods may be called elsewhere in gpsd */ -static ssize_t oncore_control_send(struct gps_device_t *, char *, size_t ); +static ssize_t oncore_control_send(struct gps_device_t *, char *, size_t); static void oncore_probe_wakeup(struct gps_device_t *); -static void oncore_configurator(struct gps_device_t *, event_t, unsigned int ); -static bool oncore_set_speed(struct gps_device_t *, speed_t, char, int ); -static void oncore_set_mode(struct gps_device_t *, int ); -static void oncore_revert(struct gps_device_t *); -static void oncore_wrapup(struct gps_device_t *); +static void oncore_event_hook(struct gps_device_t *, event_t); +static bool oncore_set_speed(struct gps_device_t *, speed_t, char, int); +static void oncore_set_mode(struct gps_device_t *, int); /* * Decode the navigation solution message @@ -393,10 +391,9 @@ static ssize_t oncore_control_send(struct gps_device_t *session, #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE -static void oncore_configurator(struct gps_device_t *session, - event_t event, unsigned int seq UNUSED) +static void oncore_event_hook(struct gps_device_t *session, event_t event) { - if (event == event_configure) { + if (event == event_configure && session->packet.counter == 0) { (void)oncore_control_send(session,enableEa,sizeof(enableEa)); (void)oncore_control_send(session,enableBb,sizeof(enableBb)); (void)oncore_control_send(session,enableEn,sizeof(enableEn)); @@ -406,29 +403,6 @@ static void oncore_configurator(struct gps_device_t *session, } } -/* - * This is the entry point to the driver. When the packet sniffer recognizes - * a packet for this driver, it calls this method which passes the packet to - * the binary processor or the nmea processor, depending on the session type. - */ -static gps_mask_t oncore_parse_input(struct gps_device_t *session) -{ - gps_mask_t st; - - if (session->packet.type == ONCORE_PACKET){ - st = oncore_dispatch(session, session->packet.outbuffer, session->packet.outbuflen); - session->gpsdata.dev.driver_mode = MODE_BINARY; - return st; -#ifdef NMEA_ENABLE - } else if (session->packet.type == NMEA_PACKET) { - st = nmea_parse((char *)session->packet.outbuffer, session); - session->gpsdata.dev.driver_mode = MODE_NMEA; - return st; -#endif /* NMEA_ENABLE */ - } else - return 0; -} - static bool oncore_set_speed(struct gps_device_t *session UNUSED, speed_t speed UNUSED, char parity UNUSED, @@ -462,21 +436,24 @@ static void oncore_set_mode(struct gps_device_t *session, int mode) session->gpsdata.dev.driver_mode = MODE_BINARY; } } - -static void oncore_revert(struct gps_device_t *session UNUSED) -{ - /* - * Reverse what the .configurator method changed. - */ -} #endif /* ALLOW_RECONFIGURE */ -static void oncore_wrapup(struct gps_device_t *session UNUSED) +static gps_mask_t oncore_parse_input(struct gps_device_t *session) { - /* - * Do release actions that are independent of whether the .configurator - * method ran or not. - */ + gps_mask_t st; + + if (session->packet.type == ONCORE_PACKET){ + st = oncore_dispatch(session, session->packet.outbuffer, session->packet.outbuflen); + session->gpsdata.dev.driver_mode = MODE_BINARY; + return st; +#ifdef NMEA_ENABLE + } else if (session->packet.type == NMEA_PACKET) { + st = nmea_parse((char *)session->packet.outbuffer, session); + session->gpsdata.dev.driver_mode = MODE_NMEA; + return st; +#endif /* NMEA_ENABLE */ + } else + return 0; } /* This is everything we export */ @@ -505,7 +482,7 @@ const struct gps_type_t oncore_binary = { #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE /* Enable what reports we need */ - .configurator = oncore_configurator, + .event_hook = oncore_event_hook, /* Speed (baudrate) switch */ .speed_switcher = oncore_set_speed, /* Switch to NMEA mode */ @@ -514,11 +491,11 @@ const struct gps_type_t oncore_binary = { .rate_switcher = NULL, /* Minimum cycle time of the device */ .min_cycle = 1, - /* Undo the actions of .configurator */ - .revert = oncore_revert, + /* Undo actions at configure_event time */ + .revert = NULL, #endif /* ALLOW_RECONFIGURE */ /* Puts device back to original settings */ - .wrapup = oncore_wrapup, + .wrapup = NULL, }; #endif /* defined(ONCORE_ENABLE) && defined(BINARY_ENABLE) */ diff --git a/driver_proto.c b/driver_proto.c index 2e34f0a7..e03ab721 100644 --- a/driver_proto.c +++ b/driver_proto.c @@ -69,7 +69,7 @@ static gps_mask_t _proto__msg_svinfo(struct gps_device_t *, unsigned char *, siz static ssize_t _proto__control_send(struct gps_device_t *, char *, size_t); static bool _proto__probe_detect(struct gps_device_t *); static void _proto__probe_wakeup(struct gps_device_t *); -static void _proto__configurator(struct gps_device_t *, event_t, unsigned int); +static void _proto__event_hook(struct gps_device_t *, event_t); static bool _proto__set_speed(struct gps_device_t *, speed_t, char, int); static void _proto__set_mode(struct gps_device_t *, int); static void _proto__revert(struct gps_device_t *); @@ -313,9 +313,12 @@ static ssize_t _proto__control_send(struct gps_device_t *session, #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE -static void _proto__configurator(struct gps_device_t *session, - event_t event, unsigned int seq) +static void _proto__event_hook(struct gps_device_t *session, event_t event) { + /* + * Remember that session->packet.counter is available when yoo write + these hooks; session->packet.counter == 0 is often a useful condition. + */ if (event == event_configure) { /* * Change sentence mix and set reporting modes as needed. @@ -388,7 +391,7 @@ static void _proto__set_mode(struct gps_device_t *session, int mode) static void _proto__revert(struct gps_device_t *session) { /* - * Reverse what the .configurator method changed. + * Reverse whatever was done art configure_event time. */ } #endif /* ALLOW_RECONFIGURE */ @@ -396,8 +399,8 @@ static void _proto__revert(struct gps_device_t *session) static void _proto__wrapup(struct gps_device_t *session) { /* - * Do release actions that are independent of whether the .configurator - * method ran or not. + * Do release actions that are independent of whether the event_configure + * hook ran or not. */ } @@ -441,7 +444,7 @@ const struct gps_type_t _proto__binary = { #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE /* configuration hook for various events */ - .configurator = _proto__configurator, + .event_hook = _proto__event_hook, /* Speed (baudrate) switch */ .speed_switcher = _proto__set_speed, /* Switch to NMEA mode */ @@ -450,7 +453,7 @@ const struct gps_type_t _proto__binary = { .rate_switcher = NULL, /* Minimum cycle time of the device */ .min_cycle = 1, - /* Undo the actions of .configurator */ + /* Undo the actions at configure_event time */ .revert = _proto__revert, #endif /* ALLOW_RECONFIGURE */ /* Puts device back to original settings */ diff --git a/driver_sirf.c b/driver_sirf.c index 9cd78e8a..d9013001 100644 --- a/driver_sirf.c +++ b/driver_sirf.c @@ -937,10 +937,9 @@ static gps_mask_t sirfbin_parse_input(struct gps_device_t *session) } #ifdef ALLOW_RECONFIGURE -static void sirfbin_configure(struct gps_device_t *session, - event_t event, unsigned int seq) +static void sirfbin_event_hook(struct gps_device_t *session, event_t event) { - if (event != event_configure || seq != 0) + if (event != event_configure || session->packet.counter != 0) return; if (session->packet.type == NMEA_PACKET) { gpsd_report(LOG_PROG, "Switching chip mode to SiRF binary.\n"); @@ -1040,7 +1039,7 @@ const struct gps_type_t sirf_binary = .control_send = sirf_control_send,/* how to send a control string */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = sirfbin_configure,/* initialize the device */ + .event_hook = sirfbin_event_hook,/* initialize the device */ .speed_switcher = sirfbin_speed, /* we can change baud rate */ .mode_switcher = sirfbin_mode, /* there's a mode switcher */ .rate_switcher = NULL, /* no sample-rate switcher */ diff --git a/driver_superstar2.c b/driver_superstar2.c index 3ecd961c..a0a9c7de 100644 --- a/driver_superstar2.c +++ b/driver_superstar2.c @@ -47,8 +47,7 @@ static gps_mask_t superstar2_msg_ephemeris(struct gps_device_t *, */ static ssize_t superstar2_control_send(struct gps_device_t *, char *, size_t); static void superstar2_probe_wakeup(struct gps_device_t *); -static void superstar2_configurator(struct gps_device_t *, - event_t, unsigned int); +static void superstar2_event_hook(struct gps_device_t *, event_t); static bool superstar2_set_speed(struct gps_device_t *, speed_t, char, int); static void superstar2_set_mode(struct gps_device_t *, int); static void superstar2_probe_wakeup(struct gps_device_t *); @@ -517,11 +516,9 @@ superstar2_probe_wakeup(struct gps_device_t *session) return; } -static void superstar2_configurator(struct gps_device_t *session, - event_t event, - unsigned int seq) +static void superstar2_event_hook(struct gps_device_t *session, event_t event) { - if (seq != 0) + if (session->packet.counter != 0) return; if (event == event_configure) { @@ -646,7 +643,7 @@ const struct gps_type_t superstar2_binary = { #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE /* Enable what reports we need */ - .configurator = superstar2_configurator, + .event_hook = superstar2_event_hook, /* Speed (baudrate) switch */ .speed_switcher = superstar2_set_speed, /* Switch to NMEA mode */ @@ -655,7 +652,7 @@ const struct gps_type_t superstar2_binary = { .rate_switcher = NULL, /* Minimum cycle time (not used) */ .min_cycle = 1, - /* Undo the actions of .configurator */ + /* Undo the actions of event_configure */ .revert = NULL, #endif /* ALLOW_RECONFIGURE */ /* Puts device back to original settings */ diff --git a/driver_tsip.c b/driver_tsip.c index a6275338..dba8c617 100644 --- a/driver_tsip.c +++ b/driver_tsip.c @@ -763,11 +763,9 @@ static ssize_t tsip_control_send(struct gps_device_t *session, #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE -static void tsip_configurator(struct gps_device_t *session, - event_t event, - unsigned int seq) +static void tsip_event_hook(struct gps_device_t *session, event_t event) { - if (event == event_configure && seq == 0) { + if (event == event_configure && session->packet.counter == 0) { unsigned char buf[100]; /* I/O Options */ @@ -777,10 +775,10 @@ static void tsip_configurator(struct gps_device_t *session, putbyte(buf,3,0x08); /* Aux: dBHz */ (void)tsip_write(session, 0x35, buf, 4); } - if (event == event_probe_subtype && seq == 0) { + if (event == event_probe_subtype) { unsigned char buf[100]; - switch (seq) { + switch (session->packet.counter) { case 0: /* * TSIP is ODD parity 1 stopbit, save original values and @@ -911,7 +909,7 @@ const struct gps_type_t tsip_binary = .control_send = tsip_control_send,/* how to send commands */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = tsip_configurator,/* initial mode sets */ + .event_hook = tsip_event_hook, /* initial mode sets */ .speed_switcher = tsip_speed_switch,/* change baud rate */ .mode_switcher = tsip_mode, /* there is a mode switcher */ .rate_switcher = NULL, /* no rate switcher */ diff --git a/driver_ubx.c b/driver_ubx.c index 347629de..3899fec6 100644 --- a/driver_ubx.c +++ b/driver_ubx.c @@ -568,13 +568,12 @@ static ssize_t ubx_control_send(struct gps_device_t *session, char *msg, size_t #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE -static void ubx_configure(struct gps_device_t *session, - event_t event, unsigned int seq) +static void ubx_event_hook(struct gps_device_t *session, event_t event) { - if (event == event_configure) { + if (event == event_configure && session->packet.counter == 0) { unsigned char msg[32]; - gpsd_report(LOG_IO, "UBX configure: %d\n",seq); + gpsd_report(LOG_IO, "UBX configure: %d\n", session->packet.counter); (void)ubx_write(session, 0x06u, 0x00, NULL, 0); /* get this port's settings */ @@ -735,12 +734,12 @@ const struct gps_type_t ubx_binary = { .control_send = ubx_control_send, /* no control sender yet */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = ubx_configure, /* Enable what reports we need */ + .event_hook = ubx_event_hook, /* Enable what reports we need */ .speed_switcher = ubx_speed, /* Speed (baudrate) switch */ .mode_switcher = ubx_nmea_mode, /* Switch to NMEA mode */ .rate_switcher = ubx_rate, /* Message delivery rate switcher */ .min_cycle = 0.25, /* Maximum 4Hz sample rate */ - .revert = ubx_revert, /* Undo the actions of .configurator */ + .revert = ubx_revert, /* Undo the actions of event_configure */ #endif /* ALLOW_RECONFIGURE */ .wrapup = NULL, /* Puts device back to original settings */ }; diff --git a/driver_zodiac.c b/driver_zodiac.c index 10d2e6c7..9f1193ed 100644 --- a/driver_zodiac.c +++ b/driver_zodiac.c @@ -505,7 +505,7 @@ const struct gps_type_t zodiac_binary = .control_send = zodiac_control_send, /* for gpsctl and friends */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = NULL, /* no configuration */ + .event_hook = NULL, /* no configuration */ .speed_switcher = zodiac_speed_switch,/* we can change baud rate */ .mode_switcher = NULL, /* no mode switcher */ .rate_switcher = NULL, /* no sample-rate switcher */ @@ -111,13 +111,12 @@ gps_mask_t nmea_parse_input(struct gps_device_t *session) } } -static void nmea_configurator(struct gps_device_t *session, - event_t event, unsigned int seq) +static void nmea_event_hook(struct gps_device_t *session, event_t event) { if (event == event_probe_subtype) { /* change this guard if the probe count goes up */ - if (seq <= 8) - gpsd_report(LOG_WARN, "=> Probing device subtype %d\n", seq); + if (session->packet.counter <= 8) + gpsd_report(LOG_WARN, "=> Probing device subtype %d\n", session->packet.counter); /* * The reason for splitting these probes up by packet sequence * number, interleaving them with the first few packet receives, @@ -135,7 +134,7 @@ static void nmea_configurator(struct gps_device_t *session, * a comma to the trigger, because that won't be in the response * unless there is actual following data. */ - switch (seq) { + switch (session->packet.counter) { #ifdef SIRF_ENABLE case 0: /* probe for Garmin serial GPS -- expect $PGRMC followed by data*/ @@ -230,7 +229,7 @@ const struct gps_type_t nmea = { .control_send = nmea_write, /* how to send control strings */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = nmea_configurator, /* enable what we need */ + .event_hook = nmea_event_hook, /* enable what we need */ .speed_switcher = NULL, /* no speed switcher */ .mode_switcher = NULL, /* no mode switcher */ .rate_switcher = NULL, /* no sample-rate switcher */ @@ -259,15 +258,14 @@ static void garmin_mode_switch(struct gps_device_t *session, int mode) } } -static void garmin_nmea_configurator(struct gps_device_t *session, - event_t event, unsigned int seq) +static void garmin_nmea_event_hook(struct gps_device_t *session, event_t event) { if (event == event_configure) { /* * Receivers like the Garmin GPS-10 don't handle having having a lot of * probes shoved at them very well. */ - switch (seq) { + switch (session->packet.counter) { case 0: /* reset some config, AutoFix, WGS84, PPS * Set the PPS pulse length to 40ms which leaves the Garmin 18-5hz @@ -321,8 +319,8 @@ const struct gps_type_t garmin = { .control_send = nmea_write, /* how to send control strings */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = garmin_nmea_configurator,/* enable what we need */ - .speed_switcher = NULL, /* no speed switcher */ + .event_hook = garmin_nmea_event_hook, /* enable what we need */ + .speed_switcher = NULL, /* no speed switcher */ .mode_switcher = garmin_mode_switch, /* mode switcher */ .rate_switcher = NULL, /* no sample-rate switcher */ .min_cycle = 1, /* not relevant, no rate switch */ @@ -340,10 +338,9 @@ const struct gps_type_t garmin = { **************************************************************************/ #ifdef ALLOW_RECONFIGURE -static void ashtech_configure(struct gps_device_t *session, - event_t event, unsigned int seq) +static void ashtech_event_hook(struct gps_device_t *session, event_t event) { - if (event == event_configure && seq == 0){ + if (event == event_configure && session->packet.counter == 0) { /* turn WAAS on. can't hurt... */ (void)nmea_send(session, "$PASHS,WAS,ON"); /* reset to known output state */ @@ -383,7 +380,7 @@ const struct gps_type_t ashtech = { .control_send = nmea_write, /* how to send control strings */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = ashtech_configure, /* change its sentence set */ + .event_hook = ashtech_event_hook, /* change its sentence set */ .speed_switcher = NULL, /* no speed switcher */ .mode_switcher = NULL, /* no mode switcher */ .rate_switcher = NULL, /* no sample-rate switcher */ @@ -402,14 +399,13 @@ const struct gps_type_t ashtech = { **************************************************************************/ #ifdef ALLOW_RECONFIGURE -static void fv18_configure(struct gps_device_t *session, - event_t event, unsigned int seq) +static void fv18_event_hook(struct gps_device_t *session, event_t event) { /* * Tell an FV18 to send GSAs so we'll know if 3D is accurate. * Suppress GLL and VTG. Enable ZDA so dates will be accurate for replay. */ - if (event == event_configure && seq == 0) + if (event == event_configure && session->packet.counter == 0) (void)nmea_send(session, "$PFEC,GPint,GSA01,DTM00,ZDA01,RMC01,GLL00,VTG00,GSV05"); } @@ -429,7 +425,7 @@ const struct gps_type_t fv18 = { .control_send = nmea_write, /* how to send control strings */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = fv18_configure, /* change its sentence set */ + .event_hook = fv18_event_hook, /* change its sentence set */ .speed_switcher = NULL, /* no speed switcher */ .mode_switcher = NULL, /* no mode switcher */ .rate_switcher = NULL, /* no sample-rate switcher */ @@ -451,14 +447,13 @@ const struct gps_type_t fv18 = { * Based on http://www.tecsys.de/fileadmin/user_upload/pdf/gh79_1an_intant.pdf */ -static void gpsclock_configurator(struct gps_device_t *session, - event_t event, unsigned int seq) +static void gpsclock_event_hook(struct gps_device_t *session, event_t event) { /* * Michael St. Laurent <mikes@hartwellcorp.com> reports that you have to * ignore the trailing PPS edge when extracting time from this chip. */ - if (event == event_probe_subtype && seq == 0) { + if (event == event_probe_subtype && session->packet.counter == 0) { gpsd_report(LOG_INF, "PPS trailing edge will be ignored"); session->driver.nmea.ignore_trailing_edge = true; } @@ -478,7 +473,7 @@ const struct gps_type_t gpsclock = { .control_send = nmea_write, /* how to send control strings */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = gpsclock_configurator, /* change its sentence set */ + .event_hook = gpsclock_event_hook, /* change its sentence set */ .speed_switcher = NULL, /* no speed switcher */ .mode_switcher = NULL, /* no mode switcher */ .rate_switcher = NULL, /* sample rate is fixed */ @@ -505,14 +500,13 @@ const struct gps_type_t gpsclock = { */ #ifdef ALLOW_RECONFIGURE -static void tripmate_configurator(struct gps_device_t *session, - event_t event, unsigned int seq) +static void tripmate_event_hook(struct gps_device_t *session, event_t event) { /* stop it sending PRWIZCH */ - if (event == event_configure && seq == 0) + if (event == event_configure && session->packet.counter == 0) (void)nmea_send(session, "$PRWIILOG,ZCH,V,,"); /* TripMate requires this response to the ASTRAL it sends at boot time */ - if (event == event_probe_subtype && seq == 0) + if (event == event_probe_subtype && session->packet.counter == 0) (void)nmea_send(session, "$IIGPQ,ASTRAL"); } #endif /* ALLOW_RECONFIGURE */ @@ -528,10 +522,10 @@ static const struct gps_type_t tripmate = { .parse_packet = nmea_parse_input, /* how to interpret a packet */ .rtcm_writer = pass_rtcm, /* send RTCM data straight */ #ifdef ALLOW_CONTROLSEND - .control_send = nmea_write, /* how to send control strings */ + .control_send = nmea_write, /* how to send control strings */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = tripmate_configurator, /* send unconditionally */ + .event_hook = tripmate_event_hook, /* send unconditionally */ .speed_switcher= NULL, /* no speed switcher */ .mode_switcher = NULL, /* no mode switcher */ .rate_switcher = NULL, /* no sample-rate switcher */ @@ -553,10 +547,9 @@ static const struct gps_type_t tripmate = { * **************************************************************************/ -static void earthmate_configurator(struct gps_device_t *session, - event_t event, unsigned int seq) +static void earthmate_event_hook(struct gps_device_t *session, event_t event) { - if (event == event_probe_subtype && seq == 0) { + if (event == event_probe_subtype && session->packet.counter == 0) { (void)gpsd_write(session, "EARTHA\r\n", 8); (void)usleep(10000); (void)gpsd_switch_driver(session, "Zodiac Binary"); @@ -578,7 +571,7 @@ static const struct gps_type_t earthmate = { .control_send = nmea_write, /* how to send control strings */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = earthmate_configurator, /* no configuration here */ + .event_hook = earthmate_event_hook, /* no configuration here */ .speed_switcher= NULL, /* no speed switcher */ .mode_switcher = NULL, /* no mode switcher */ .rate_switcher = NULL, /* no sample-rate switcher */ @@ -686,10 +679,9 @@ static int tnt_packet_sniff(struct gps_device_t *session) return BAD_PACKET; } -static void tnt_configurator(struct gps_device_t *session, - event_t event, unsigned int seq) +static void tnt_event_hook(struct gps_device_t *session, event_t event) { - if (event == event_probe_subtype && seq == 0) { + if (event == event_probe_subtype && session->packet_counter == 0) { // Send codes to start the flow of data //tnt_send(session->gpsdata.gps_fd, "@BA?"); // Query current rate //tnt_send(session->gpsdata.gps_fd, "@BA=8"); // Start HTM packet at 1Hz @@ -755,7 +747,7 @@ static const struct gps_type_t trueNorth = { .control_send = nmea_write, /* how to send control strings */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = tnt_configurator, /* no setting changes */ + .event_hook = tnt_event_hook, /* no setting changes */ .speed_switcher = NULL, /* no speed switcher */ .mode_switcher = NULL, /* no mode switcher */ .rate_switcher = NULL, /* no wrapup */ @@ -827,7 +819,7 @@ static const struct gps_type_t oceanServer = { .control_send = nmea_write, /* how to send control strings */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = oceanserver_configure, + .event_hook = oceanserver_configure, .speed_switcher = NULL, /* no speed switcher */ .mode_switcher = NULL, /* no mode switcher */ .rate_switcher = NULL, /* no wrapup */ @@ -869,7 +861,7 @@ static const struct gps_type_t rtcm104v2 = { .control_send = nmea_write, /* how to send control strings */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = NULL, /* no configurator */ + .event_hook = NULL, /* no event_hook */ .speed_switcher= NULL, /* no speed switcher */ .mode_switcher = NULL, /* no mode switcher */ .rate_switcher = NULL, /* no sample-rate switcher */ @@ -911,7 +903,7 @@ static const struct gps_type_t rtcm104v3 = { .control_send = nmea_write, /* how to send control strings */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = NULL, /* no configurator */ + .event_hook = NULL, /* no event_hook */ .speed_switcher= NULL, /* no speed switcher */ .mode_switcher = NULL, /* no mode switcher */ .rate_switcher = NULL, /* no sample-rate switcher */ @@ -950,7 +942,7 @@ static const struct gps_type_t garmintxt = { .control_send = nmea_write, /* how to send control strings */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = NULL, /* no configurator */ + .event_hook = NULL, /* no event_hook */ .speed_switcher= NULL, /* no speed switcher */ .mode_switcher = NULL, /* no mode switcher */ .rate_switcher = NULL, /* no sample-rate switcher */ @@ -998,8 +990,7 @@ gps_mask_t processMKT3301(int c UNUSED, char *field[], struct gps_device_t *sess } #ifdef ALLOW_RECONFIGURE -static void mkt3301_configure(struct gps_device_t *session, - event_t event, unsigned int seq) +static void mkt3301_event_hook(struct gps_device_t *session, event_t event) { /* 0 NMEA_SEN_GLL, GPGLL interval - Geographic Position - Latitude longitude @@ -1020,7 +1011,7 @@ static void mkt3301_configure(struct gps_device_t *session, "$PMTK314,1,1,1,1,1,5,1,1,0,0,0,0,0,0,0,0,0,1,0" */ - if(event == event_configure && seq == 0) { + if(event == event_configure && session->packet.counter == 0) { (void)nmea_send(session,"$PMTK320,0"); /* power save off */ (void)nmea_send(session,"$PMTK300,1000,0,0,0.0,0.0"); /* Fix interval */ (void)nmea_send(session,"$PMTK314,0,1,0,1,1,5,1,1,0,0,0,0,0,0,0,0,0,1,0"); @@ -1044,7 +1035,7 @@ const struct gps_type_t mkt3301 = { .control_send = nmea_write, /* how to send control strings */ #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - .configurator = mkt3301_configure, /* change its sentence set */ + .event_hook = mkt3301_event_hook, /* change its sentence set */ .speed_switcher = NULL, /* no speed switcher */ .mode_switcher = NULL, /* no mode switcher */ .rate_switcher = NULL, /* no sample-rate switcher */ @@ -1095,11 +1086,11 @@ static const struct gps_type_t aivdm = { .rtcm_writer = NULL, #ifdef ALLOW_CONTROLSEND /* Control string sender - should provide checksum and headers/trailer */ - .control_send = NULL, + .control_send = NULL, #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE /* Enable what reports we need */ - .configurator = NULL, + .event_hook = NULL, /* Speed (baudrate) switch */ .speed_switcher = NULL, /* Switch to NMEA mode */ @@ -1108,7 +1099,7 @@ static const struct gps_type_t aivdm = { .rate_switcher = NULL, /* Minimum cycle time of the device */ .min_cycle = 1, - /* Undo the actions of .configurator */ + /* Undo the actions of configure_event */ .revert = NULL, #endif /* ALLOW_RECONFIGURE */ /* Puts device back to original settings */ diff --git a/gpsd.h-tail b/gpsd.h-tail index 4d57cb9e..d3fa5646 100644 --- a/gpsd.h-tail +++ b/gpsd.h-tail @@ -210,8 +210,7 @@ struct gps_type_t { /*@null@*/ssize_t (*control_send)(struct gps_device_t *session, char *buf, size_t buflen); #endif /* ALLOW_CONTROLSEND */ #ifdef ALLOW_RECONFIGURE - /*@null@*/void (*configurator)(struct gps_device_t *session, - event_t event, unsigned int seq); + /*@null@*/void (*event_hook)(struct gps_device_t *session, event_t event); /*@null@*/bool (*speed_switcher)(struct gps_device_t *session, speed_t speed, char parity, int stopbits); /*@null@*/void (*mode_switcher)(struct gps_device_t *session, int mode); diff --git a/libgpsd_core.c b/libgpsd_core.c index a0e7638d..d557963d 100644 --- a/libgpsd_core.c +++ b/libgpsd_core.c @@ -36,9 +36,11 @@ int gpsd_switch_driver(struct gps_device_t *session, char* type_name) strcmp(session->device_type->type_name, type_name) == 0) { #ifdef ALLOW_RECONFIGURE gpsd_report(LOG_PROG, "Reconfiguring for %s...\n", session->device_type->type_name); + /* FIXME: Probably wrong to zero the packet counter here */ + session->packet.counter = 0; if (session->enable_reconfigure - && session->device_type->configurator != NULL) - session->device_type->configurator(session, event_configure, 0); + && session->device_type->event_hook != NULL) + session->device_type->event_hook(session, event_configure); #endif /* ALLOW_RECONFIGURE */ return 0; } @@ -50,15 +52,14 @@ int gpsd_switch_driver(struct gps_device_t *session, char* type_name) gpsd_assert_sync(session); /*@i@*/session->device_type = *dp; session->gpsdata.dev.mincycle = session->device_type->min_cycle; - if (!session->context->readonly && session->device_type->configurator != NULL) - session->device_type->configurator(session, - event_probe_subtype, - session->packet.counter = 0); + session->packet.counter = 0; + if (!session->context->readonly && session->device_type->event_hook != NULL) + session->device_type->event_hook(session, event_probe_subtype); #ifdef ALLOW_RECONFIGURE if (session->enable_reconfigure - && session->device_type->configurator != NULL) { + && session->device_type->event_hook != NULL) { gpsd_report(LOG_PROG, "configuring for %s...\n", session->device_type->type_name); - session->device_type->configurator(session, event_configure, 0); + session->device_type->event_hook(session, event_configure); } #endif /* ALLOW_RECONFIGURE */ return 1; @@ -300,16 +301,15 @@ int gpsd_activate(struct gps_device_t *session, bool reconfigurable) /* clear driver subtype field and private data union */ session->subtype[0] = '\0'; memset(&session->driver, '\0', sizeof(session->driver)); + session->packet.counter = 0; /* if we know the device type, probe for subtype and configure it */ if (session->device_type != NULL) { - if (!session->context->readonly && session->device_type->configurator !=NULL) - session->device_type->configurator(session, - event_probe_subtype, - session->packet.counter = 0); + if (!session->context->readonly && session->device_type->event_hook !=NULL) + session->device_type->event_hook(session, event_probe_subtype); #ifdef ALLOW_RECONFIGURE if (reconfigurable) { - if (session->device_type->configurator != NULL) - session->device_type->configurator(session, event_configure, session->packet.counter); + if (session->device_type->event_hook != NULL) + session->device_type->event_hook(session, event_configure); } #endif /* ALLOW_RECONFIGURE */ } @@ -711,10 +711,9 @@ gps_mask_t gpsd_poll(struct gps_device_t *session) if (session->device_type) { newlen = session->device_type->get_packet(session); session->gpsdata.d_xmit_time = timestamp(); - if (session->packet.outbuflen>0 && !session->context->readonly && session->device_type->configurator!=NULL) - session->device_type->configurator(session, - event_probe_subtype, - ++session->packet.counter); + ++session->packet.counter; + if (session->packet.outbuflen>0 && !session->context->readonly && session->device_type->event_hook!=NULL) + session->device_type->event_hook(session, event_probe_subtype); } else { const struct gps_type_t **dp; diff --git a/www/writing-a-driver.xml b/www/writing-a-driver.xml index bbeef663..69ea7454 100644 --- a/www/writing-a-driver.xml +++ b/www/writing-a-driver.xml @@ -605,10 +605,10 @@ document I discuss my work to implement this function.</para> that wakes up the device when the main auto-baud hunt loop in the daemon offers a new speed to probe at.</para> -<para><structfield>.configurator</structfield> points to a block of +<para><structfield>.event_hook</structfield> points to a block of code that will be executed on and after various events, distinguished by a second argument that specifies the event type. It also gets a scond -argument which may be a packet sequence number. The configurator hook +argument which may be a packet sequence number. The event_hook hook is called in the following circumstances:</para> <itemizedlist> @@ -620,7 +620,7 @@ device's driver to a different type, with event type <listitem><para> Whenever gpsd_switch_driver() is called, with event -type 'configurator' and sequence number zero, <emphasis>even if no driver +type 'event_configur', <emphasis>even if no driver change occurs</emphasis>. (Thus, when rhe driver type changes, the configurator hook is called twice with two different event types. _ </para></listitem> @@ -636,9 +636,7 @@ number is set to zero and passed to both these calls. </para></listitem> <listitem><para> -Whenever a full packet is received, with event type 'event_probe_subtype' -and the second argument being the sequence number of the packet since -the last driver switch (1 or greater). +Whenever a full packet is received, with event type 'event_probe_subtype'. </para></listitem> </itemizedlist> @@ -654,6 +652,12 @@ of the driver data structure <userinput>struct gps_device_t the correct set of sentences to supply the parser with the data needed by <filename>gpsd</filename>.</para> +<para>When writing hook code, it is iuseful to brer in mind that the +<structfield>.packet.counter</structfield> member of the session +structure is available; it is often useful to take action only +when this counter is zero. It is zeroed when the device is activated +or someting triggers a device change.</para> + <para><structfield>.get_packet</structfield> points to a block of code that actually gets the packets from the serial stream. You will almost certainly use the generic routine |