19
19
*/
20
20
GPSModel::GPSModel () {
21
21
memset (&_msg_gps_config, 0 , sizeof (_msg_gps_config));
22
- memset (&_msg_gpgga_response, 0 , sizeof (_msg_gpgga_response));
23
- memset (&_msg_gpsrmc_response, 0 , sizeof (_msg_gpsrmc_response));
22
+ memset (&_msg_gps_event, 0 , sizeof (_msg_gps_event));
24
23
}
25
24
26
25
/* !
27
26
* @brief Destructor for a GPSModel object.
28
27
*/
29
28
GPSModel::~GPSModel () {
30
29
memset (&_msg_gps_config, 0 , sizeof (_msg_gps_config));
31
- memset (&_msg_gpgga_response, 0 , sizeof (_msg_gpgga_response));
32
- memset (&_msg_gpsrmc_response, 0 , sizeof (_msg_gpsrmc_response));
30
+ memset (&_msg_gps_event, 0 , sizeof (_msg_gps_event));
33
31
}
34
32
35
33
/* !
36
34
* @brief Decodes a GPSConfig message from an input stream.
37
35
* @param stream A pointer to the pb_istream_t stream.
38
- * @returns True if the GPSConfig message was decoded successfully, False otherwise.
36
+ * @returns True if the GPSConfig message was decoded successfully, False
37
+ * otherwise.
39
38
*/
40
39
bool GPSModel::DecodeGPSConfig (pb_istream_t *stream) {
41
- return pb_decode (stream, wippersnapper_gps_GPSConfig_fields, &_msg_gps_config);
40
+ return pb_decode (stream, wippersnapper_gps_GPSConfig_fields,
41
+ &_msg_gps_config);
42
42
}
43
43
44
44
/* !
@@ -50,25 +50,94 @@ wippersnapper_gps_GPSConfig *GPSModel::GetGPSConfigMsg() {
50
50
}
51
51
52
52
/* !
53
- * @brief Encodes a GPGGA response message.
54
- * @returns True if the GPGGA response message was encoded successfully, False otherwise.
53
+ * @brief Creates a new GPSEvent message and initializes it.
54
+ * @NOTE: This function will clear an existing GPSEvent message. Only call when
55
+ * you are creating a NEW gps event, not modifying an existing one.
55
56
*/
56
- bool GPSModel::EncodeGPGGAResponse () {
57
- // TODO: Implement the encoding logic for GPGGAResponse
58
- return false ;
57
+ void GPSModel::CreateGPSEvent () {
58
+ // Zero-out whatever was previously in the GPSEvent message
59
+ memset (&_msg_gps_event, 0 , sizeof (_msg_gps_event));
60
+ // Create new GPSEvent message with initializer
61
+ _msg_gps_event = wippersnapper_gps_GPSEvent_init_zero;
62
+ _msg_gps_event.gga_responses_count = 0 ;
63
+ _msg_gps_event.rmc_responses_count = 0 ;
59
64
}
60
65
61
66
/* !
62
- * @brief Returns a pointer to the GPGGA response message.
63
- * @returns Pointer to the GPGGA response message.
67
+ * @brief Creates a GPSDateTime message with the provided parameters.
68
+ * @param hour GMT hour of the day (0-23).
69
+ * @param minute GMT minute of the hour (0-59).
70
+ * @param seconds GMT seconds of the minute (0-59).
71
+ * @param milliseconds GMT milliseconds (0-999).
72
+ * @param day GMT day of the month (1-31).
73
+ * @param month GMT month of the year (1-12).
74
+ * @param year GMT year (e.g., 25).
75
+ * @returns A wippersnapper_gps_GPSDateTime message.
64
76
*/
65
- wippersnapper_gps_GPGGAResponse *GPSModel::GetGPGGAResponseMsg () {
66
- return &_msg_gpgga_response;
77
+ wippersnapper_gps_GPSDateTime
78
+ GPSModel::CreateGpsDatetime (uint8_t hour, uint8_t minute, uint8_t seconds,
79
+ uint8_t milliseconds, uint8_t day, uint8_t month,
80
+ uint8_t year) {
81
+ wippersnapper_gps_GPSDateTime datetime;
82
+ // Fill in the datetime structure with the provided values
83
+ datetime.hour = (uint32_t )(hour);
84
+ datetime.minute = (uint32_t )(minute);
85
+ datetime.seconds = (uint32_t )(seconds);
86
+ datetime.milliseconds = (uint32_t )(milliseconds);
87
+ datetime.day = (uint32_t )(day);
88
+ datetime.month = (uint32_t )(month);
89
+ datetime.year = (uint32_t )(year);
90
+ return datetime;
67
91
}
68
92
69
- /* !
70
- * @brief Gets the GPGGA response message.
71
- */
72
- wippersnapper_gps_GPSRMCResponse *GPSModel::GetGPSRMCResponseMsg () {
73
- return &_msg_gpsrmc_response;
74
- }
93
+ bool GPSModel::AddGpsEventRMC (wippersnapper_gps_GPSDateTime *datetime,
94
+ uint8_t fix_status, nmea_float_t latitude,
95
+ char *lat_dir, nmea_float_t longitude,
96
+ char *lon_dir, nmea_float_t speed,
97
+ nmea_float_t angle) {
98
+ // Check if we've reached the maximum number of RMC responses
99
+ if (_msg_gps_event.rmc_responses_count >= MAX_COUNT_RMC_GGA) {
100
+ return false ; // Cannot add more RMC responses
101
+ }
102
+
103
+ // Validate pointers have been provided correctly
104
+ if (!lat_dir || !lon_dir) {
105
+ return false ;
106
+ }
107
+
108
+ wippersnapper_gps_GPSRMCResponse rmc_response;
109
+ rmc_response = wippersnapper_gps_GPSRMCResponse_init_zero;
110
+ // Assign the datetime, if provided
111
+ if (datetime) {
112
+ rmc_response.has_datetime = true ;
113
+ rmc_response.datetime = *datetime;
114
+ } else {
115
+ rmc_response.has_datetime = false ;
116
+ }
117
+
118
+ // Determine the fix status
119
+ if (fix_status == 1 || fix_status == 2 ) {
120
+ rmc_response.fix_status [0 ] = ' A' ; // Active fix
121
+ } else {
122
+ rmc_response.fix_status [0 ] = ' V' ; // Void fix
123
+ }
124
+ rmc_response.fix_status [1 ] = ' \0 ' ;
125
+
126
+ // Fill lat/lon and direction
127
+ snprintf (rmc_response.lat , sizeof (rmc_response.lat ), " %.6f" , latitude);
128
+ snprintf (rmc_response.lon , sizeof (rmc_response.lon ), " %.6f" , longitude);
129
+ strncpy (rmc_response.lat_dir , lat_dir, sizeof (rmc_response.lat_dir ) - 1 );
130
+ rmc_response.lat_dir [sizeof (rmc_response.lat_dir ) - 1 ] = ' \0 ' ;
131
+ strncpy (rmc_response.lon_dir , lon_dir, sizeof (rmc_response.lon_dir ) - 1 );
132
+ rmc_response.lon_dir [sizeof (rmc_response.lon_dir ) - 1 ] = ' \0 ' ;
133
+
134
+ // Fill current speed over ground, in knots
135
+ snprintf (rmc_response.speed , sizeof (rmc_response.speed ), " %.1f" , speed);
136
+ // Fill course in degrees from true north
137
+ snprintf (rmc_response.angle , sizeof (rmc_response.angle ) " %.1f" , angle);
138
+
139
+ _msg_gps_event.rmc_responses [_msg_gps_event.rmc_responses_count ] =
140
+ rmc_response;
141
+ _msg_gps_event.rmc_responses_count ++;
142
+ return true ;
143
+ }
0 commit comments