zephyr/drivers/gnss/gnss_nmea0183_match.h
Bjarki Arge Andreasen 2b14e5d84a drivers: gnss: Add nmea0183 match utilities
This commit adds generic matches and handlers for the RMC,
GGA and GSV messages to be implemented as part of all
NMEA0183 based GNSS modems.

NMEA0183 based GNSS modems must place the
struct gnss_nmea0183_match_data struct as the first struct
in their data struct. Their data struct shall then be set
as the user_data for the modem_chat instance.

Lastly, the gnss_nmea0183_match callbacks must be included
in the unsolicited matches for the modem_chat instance.

The GNSS modems will initialize the NMEA0183 match instance
using gnss_nmea0183_match_init.

Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
2023-10-30 11:43:19 -04:00

107 lines
3.4 KiB
C

/*
* Copyright (c) 2023 Trackunit Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* The GNSS NMEA0183 match is a set of modem_chat match handlers and a context to be
* passed to said handlers, to parse the NMEA0183 messages received from a NMEA0183
* based GNSS device.
*
* The context struct gnss_nmea0183_match_data *data is placed as the first member
* of the data structure which is passed to the modem_chat instance through the
* user_data member.
*
* struct my_gnss_nmea0183_driver {
* gnss_nmea0183_match_data match_data;
* ...
* };
*
* The struct gnss_nmea0183_match_data context must be initialized using
* gnss_nmea0183_match_init().
*
* When initializing the modem_chat instance, the three match callbacks must be added
* as part of the unsolicited matches.
*
* MODEM_CHAT_MATCHES_DEFINE(unsol_matches,
* MODEM_CHAT_MATCH_WILDCARD("$??GGA,", ",*", gnss_nmea0183_match_gga_callback),
* MODEM_CHAT_MATCH_WILDCARD("$??RMC,", ",*", gnss_nmea0183_match_rmc_callback),
* #if CONFIG_GNSS_SATELLITES
* MODEM_CHAT_MATCH_WILDCARD("$??GSV,", ",*", gnss_nmea0183_match_gsv_callback),
* #endif
*
*/
#ifndef ZEPHYR_DRIVERS_GNSS_GNSS_NMEA0183_MATCH_H_
#define ZEPHYR_DRIVERS_GNSS_GNSS_NMEA0183_MATCH_H_
#include <zephyr/types.h>
#include <zephyr/device.h>
#include <zephyr/drivers/gnss.h>
#include <zephyr/modem/chat.h>
struct gnss_nmea0183_match_data {
const struct device *gnss;
struct gnss_data data;
#if CONFIG_GNSS_SATELLITES
struct gnss_satellite *satellites;
uint16_t satellites_size;
uint16_t satellites_length;
#endif
int64_t timestamp;
uint16_t timeout_ms;
uint8_t gga_received : 1;
uint8_t rmc_received : 1;
uint8_t gsv_message_number : 6;
};
/** GNSS NMEA0183 match configuration structure */
struct gnss_nmea0183_match_config {
/** The GNSS device from which the data is published */
const struct device *gnss;
#if CONFIG_GNSS_SATELLITES
/** Buffer for parsed satellites */
struct gnss_satellite *satellites;
/** Number of elements in buffer for parsed satellites */
uint16_t satellites_size;
#endif
/** The maximum time from the first to the last NMEA0183 message of a fix */
uint16_t timeout_ms;
};
/**
* @brief Match callback for the NMEA GGA NMEA0183 message
*
* @details Should be used as the callback of a modem_chat match which matches "$??GGA,"
*/
void gnss_nmea0183_match_gga_callback(struct modem_chat *chat, char **argv, uint16_t argc,
void *user_data);
/**
* @brief Match callback for the NMEA RMC NMEA0183 message
*
* @details Should be used as the callback of a modem_chat match which matches "$??RMC,"
*/
void gnss_nmea0183_match_rmc_callback(struct modem_chat *chat, char **argv, uint16_t argc,
void *user_data);
/**
* @brief Match callback for the NMEA GSV NMEA0183 message
*
* @details Should be used as the callback of a modem_chat match which matches "$??GSV,"
*/
void gnss_nmea0183_match_gsv_callback(struct modem_chat *chat, char **argv, uint16_t argc,
void *user_data);
/**
* @brief Initialize a GNSS NMEA0183 match instance
*
* @param data GNSS NMEA0183 match instance to initialize
* @param config Configuration to apply to GNSS NMEA0183 match instance
*/
int gnss_nmea0183_match_init(struct gnss_nmea0183_match_data *data,
const struct gnss_nmea0183_match_config *config);
#endif /* ZEPHYR_DRIVERS_GNSS_GNSS_NMEA0183_MATCH_H_ */