-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathx_pos_maxm10s.h
262 lines (204 loc) · 9.97 KB
/
x_pos_maxm10s.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
* Copyright 2022 u-blox Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef X_POS_MAXM10S_H__
#define X_POS_MAXM10S_H__
/** @file
* @brief This file contains the API to handle MAXM10S GNSS positioning module in
* XPLR-IOT-1 device. It handles the module by using ubxlib library
*
* Some parts of MaxM10S module can be treated as a sensor (eg. Update Period,
* sampling threads etc).
* Other parts that make use of ubxlib functionality shoulbe be treated as a
* ublox module.
* That is why MaxM10S module lives between two worlds: sensors/modules and lends
* elements from both, sometimes treated as a sensor and others as a module.
*
*
* In order to get a position fix the following should be done:
*
* - xPosMaxM10Init() -> powers the module, initializes ubxlib and gnss module
* - xPosMaxM10Enable() -> starts up the necessary threads (also calls the init function
* mentioned above if necessary)
*/
#include <stdint.h>
#include <shell/shell.h> // needed for shell commands
#include "x_errno.h" // for functions that want to return a c210 error code
#include "x_module_common.h" // for xSerialCommOption_t type
#include "x_sens_common_types.h" // for sensor status structure type
/* ----------------------------------------------------------------
* TYPE DEFINITIONS
* -------------------------------------------------------------- */
/** Struct type that describes MaxM10S status.
*/
typedef struct{
bool pinsConfigured; /**< Are MaxM10 pins configured? */
bool isPowered; /**< Is MaxM10 powered on? */
bool isUbxInit; /**< Is MaxM10 ready to be used by ubxlib? Use MaxM10Init function to render it ready */
bool isEnabled; /**< Is the sampling thread running for MaxM10*/
bool isPublishEnabled; /**< When true and C210 is connected to MQTT(SN), the position
obtained by MaxM10 are published to Thingstream*/
uint32_t updatePeriod; /**< The sampling period of MaxM10*/
uint32_t timeoutPeriod; /**< Timeout period for MaxM10 to respond with a position fix, since it is requested
Timeout period should not be higher than updatePeriod*/
xSerialCommOption_t com; /**< Indicates which MaxM10 Uart Com is active: UART to USB or UART connected to NORA-B1*/
}xPosMaxM10Status_t;
/* ----------------------------------------------------------------
* FUNCTIONS - HARDWARE CONTROL OF MAXM10S
* -------------------------------------------------------------- */
/** Configures the MAXM10S pins connected to NORA-B1 as outputs.
* Should be used before any other hardware control is used (such as powerOn/Off etc.)
*/
void xPosMaxM10ConfigPins(void);
/** Just powers the MaxM10 module by setting the appropriate pins
* SafeBoot disabled, Backup Supply Disabled
* Cannot be accessed while the Main Sensor Aggregation Function is active
*/
void xPosMaxM10PowerOn(void);
/** Just powers off the MaxM10 module by clearing the appropriate pin
* Cannot be accessed while the Main Sensor Aggregation Function is active
*/
void xPosMaxM10PowerOff(void);
/** Enables NORA - MAXM10S Uart communication. Disables MaxM10S UART to USB
* communication
*/
void xPosMaxM10EnableNoraCom(void);
/** Disables NORA - MAXM10S Uart communication. Enables MaxM10S UART to USB
* communication
*/
void xPosMaxM10DisableNoraCom(void);
/** Assert Enable Pin of MaxM10 (provides powers to the module)
*/
void max10EnablePinAssert(void);
/** Deassert Enable Pin of MaxM10 (remove power from the module)
*/
void max10EnablePinDeassert(void);
/** Enable MaxM10S Safe boot pin
*/
void max10SafeBootPinAssert(void);
/** Disable MaxM10S Safe boot pin
*/
void max10SafeBootPinDeassert(void);
/** Enable MaxM10S Backup Supply pin
*/
void max10BackupSupplyPinAssert(void);
/** Disable MaxM10S Backup Supply pin
*/
void max10BackupSupplyPinDeassert(void);
/* ----------------------------------------------------------------
* FUNCTIONS - as MODULE CONTROL
* -------------------------------------------------------------- */
/** Initializes/ Prepares MaxM10S to be used with ubxlib.
* If necessary powers up MaxM10, sets the needed pins/coms and initializes
* ubxlib Port and ubxlib Gnss modules.
*
* @return zero on success else negative error code.
*/
err_code xPosMaxM10Init(void);
/** Deinitializes any ubxlib configuration that has to do with MaxM10,
* so the module cannot be used by ubxlib anymore.
* Also disables (suspends) the MaxM10 thread/sampling.
* It does NOT power down MaxM10S.
* That happens because this function could be used for a switch between cell, wifi
* that needs temporarily to deinitialize ubxlib configuration. In that case if we
* power down the GNSS modules it will take some time to obtain a position fix again. If the
* module is still powered the module won't need so much time to obtain a position fix.
*
* It's up to the user to decide whether he want to power the GNSS module down explicitly by using
* xPosMaxM10PowerOff function.
*/
void xPosMaxM10Deinit(void);
/** Returns the status of the module. The status includes info about
* whether the module is ready to be used by ubxlib, if its thread is running,
* the sampling/update period and if publish to MQTT(SN) is enabled or not. See
* xPosMaxM10Status_t
*
* @return a structure containing the module status.
*/
xPosMaxM10Status_t xPosMaxM10GetModuleStatus(void);
/* ----------------------------------------------------------------
* FUNCTIONS - as SENSOR CONTROL
* -------------------------------------------------------------- */
/** Sets the Update/Sampling Period of MaxM10S. If MaxM10 is enabled/running
* its values will be updated based on this period. If the sensor is disabled/suspended
* the Update period will take effect when the sensor is enabled again.
*
* @param milliseconds The update period of the sensor in milliseconds.
* @return zero on success (X_ERR_SUCCESS) else negative error code.
*/
err_code xPosMaxM10SetUpdatePeriod(uint32_t milliseconds);
/** Enables MaxM10 position sampling by resuming/starting the module's sampling thread.
* Cannot be accessed when the main Sensor Aggregation function is active.
* If necessary initializes the module by calling xPosMaxM10Init()
*
* @return zero on success else negative error code.
*/
err_code xPosMaxM10Enable(void);
/** Disables MaxM10 position sampling by suspending/stoping the module's sampling thread.
* Cannot be accessed when the main Sensor Aggregation function is active.
*/
void xPosMaxM10Disable(void);
/** Enables/Disables the publish of position to MQTT(SN). In order for
* the position to be actually published, an MQTT(SN) connection should be active
* via the MQTT module.
* If no connection is active, when a connection is activated the position will start
* publishing. If while connected the publish is disabled, the module won't publish the position.
*
* @param enable [true] = enables publish, [false] = disable publish
* @return zero on success else negative error code.
*/
void xPosMaxM10EnablePublish(bool enable);
/** Returns the status of the module, but in a sensor status description structure.
* Basically its like xPosMaxM10GetModuleStatus function but it returns a xSensStatus_t
* structure instead of a xPosMaxM10Status_t structure (the latter holds some more information)
*
* @return a sensor type structure containing the module status.
*/
xSensStatus_t xPosMaxM10GetSensorStatus(void);
/* ----------------------------------------------------------------
* FUNCTIONS IMPLEMENTING SHELL-COMMANDS
* -------------------------------------------------------------- */
/** This function is intented only to be used as a command executed by the shell.
* It basically enables/disables the publish of the sensor measurements using the
* string parameters "on", "off" respectively
* Command Example: modules MAXM10S publish on
*
* @param shell the shell instance from which the command is given.
* @param argc the number of parameters given along with the command.
* @param argv the array including the parameters themselves.
*/
void xPosMaxM10EnablePublishCmd(const struct shell *shell, size_t argc, char **argv);
/** This function is intented only to be used as a command executed by the shell.
* It sets the period of the position aquisition in milliseconds
* Shell Command Example: modules MAXM10S set_period 10000
*
* @param shell the shell instance from which the command is given.
* @param argc the number of parameters given along with the command.
* @param argv the array including the parameters themselves.
*/
void xPosMaxM10UpdatePeriodCmd(const struct shell *shell, size_t argc, char **argv);
/** This function is intented only to be used as a command executed by the shell.
* It sets the max time to wait for a response with the position aquisition since the
* request has been sent the module. It is set in milliseconds. The timeout cannot be higher
* than the Update Period of the module nor the timeout set for GNSS aquisition from
* ubxlib (U_GNSS_POS_TIMEOUT_SECONDS)
* Shell Command Example: modules MAXM10S set_timeout 10000
*
* @param shell the shell instance from which the command is given.
* @param argc the number of parameters given along with the command.
* @param argv the array including the parameters themselves.
*/
void xPosMaxM10TimeoutPeriodCmd(const struct shell *shell, size_t argc, char **argv);
#endif // X_POS_MAXM10S_H__