1 /* 2 * Copyright (c) 2023 Trackunit Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /* 8 * The GNSS NMEA0183 match is a set of modem_chat match handlers and a context to be 9 * passed to said handlers, to parse the NMEA0183 messages received from a NMEA0183 10 * based GNSS device. 11 * 12 * The context struct gnss_nmea0183_match_data *data is placed as the first member 13 * of the data structure which is passed to the modem_chat instance through the 14 * user_data member. 15 * 16 * struct my_gnss_nmea0183_driver { 17 * gnss_nmea0183_match_data match_data; 18 * ... 19 * }; 20 * 21 * The struct gnss_nmea0183_match_data context must be initialized using 22 * gnss_nmea0183_match_init(). 23 * 24 * When initializing the modem_chat instance, the three match callbacks must be added 25 * as part of the unsolicited matches. 26 * 27 * MODEM_CHAT_MATCHES_DEFINE(unsol_matches, 28 * MODEM_CHAT_MATCH_WILDCARD("$??GGA,", ",*", gnss_nmea0183_match_gga_callback), 29 * MODEM_CHAT_MATCH_WILDCARD("$??RMC,", ",*", gnss_nmea0183_match_rmc_callback), 30 * #if CONFIG_GNSS_SATELLITES 31 * MODEM_CHAT_MATCH_WILDCARD("$??GSV,", ",*", gnss_nmea0183_match_gsv_callback), 32 * #endif 33 * 34 */ 35 36 #ifndef ZEPHYR_DRIVERS_GNSS_GNSS_NMEA0183_MATCH_H_ 37 #define ZEPHYR_DRIVERS_GNSS_GNSS_NMEA0183_MATCH_H_ 38 39 #include <zephyr/types.h> 40 #include <zephyr/device.h> 41 #include <zephyr/drivers/gnss.h> 42 #include <zephyr/modem/chat.h> 43 44 struct gnss_nmea0183_match_data { 45 const struct device *gnss; 46 struct gnss_data data; 47 #if CONFIG_GNSS_SATELLITES 48 struct gnss_satellite *satellites; 49 uint16_t satellites_size; 50 uint16_t satellites_length; 51 #endif 52 uint32_t gga_utc; 53 uint32_t rmc_utc; 54 uint8_t gsv_message_number; 55 }; 56 57 /** GNSS NMEA0183 match configuration structure */ 58 struct gnss_nmea0183_match_config { 59 /** The GNSS device from which the data is published */ 60 const struct device *gnss; 61 #if CONFIG_GNSS_SATELLITES 62 /** Buffer for parsed satellites */ 63 struct gnss_satellite *satellites; 64 /** Number of elements in buffer for parsed satellites */ 65 uint16_t satellites_size; 66 #endif 67 }; 68 69 /** 70 * @brief Match callback for the NMEA GGA NMEA0183 message 71 * 72 * @details Should be used as the callback of a modem_chat match which matches "$??GGA," 73 */ 74 void gnss_nmea0183_match_gga_callback(struct modem_chat *chat, char **argv, uint16_t argc, 75 void *user_data); 76 77 /** 78 * @brief Match callback for the NMEA RMC NMEA0183 message 79 * 80 * @details Should be used as the callback of a modem_chat match which matches "$??RMC," 81 */ 82 void gnss_nmea0183_match_rmc_callback(struct modem_chat *chat, char **argv, uint16_t argc, 83 void *user_data); 84 85 /** 86 * @brief Match callback for the NMEA GSV NMEA0183 message 87 * 88 * @details Should be used as the callback of a modem_chat match which matches "$??GSV," 89 */ 90 void gnss_nmea0183_match_gsv_callback(struct modem_chat *chat, char **argv, uint16_t argc, 91 void *user_data); 92 93 /** 94 * @brief Initialize a GNSS NMEA0183 match instance 95 * 96 * @param data GNSS NMEA0183 match instance to initialize 97 * @param config Configuration to apply to GNSS NMEA0183 match instance 98 */ 99 int gnss_nmea0183_match_init(struct gnss_nmea0183_match_data *data, 100 const struct gnss_nmea0183_match_config *config); 101 102 #endif /* ZEPHYR_DRIVERS_GNSS_GNSS_NMEA0183_MATCH_H_ */ 103