Firmware SDK
twr_sam_m8q.h
1 #ifndef _TWR_SAM_M8Q
2 #define _TWR_SAM_M8Q
3 
4 #include <twr_i2c.h>
5 #include <twr_scheduler.h>
6 
10 
12 
13 typedef enum
14 {
17 
20 
23 
26 
28 
30 
31 typedef struct twr_sam_m8q_t twr_sam_m8q_t;
32 
34 
35 typedef struct
36 {
38  bool (*on)(twr_sam_m8q_t *self);
39 
41  bool (*off)(twr_sam_m8q_t *self);
42 
44 
46 
47 typedef struct
48 {
50  int year;
51 
53  int month;
54 
56  int day;
57 
59  int hours;
60 
62  int minutes;
63 
65  int seconds;
66 
68 
70 
71 typedef struct
72 {
74  float latitude;
75 
77  float longitude;
78 
80 
82 
83 typedef struct
84 {
86  float altitude;
87 
89  char units;
90 
92 
94 
95 typedef struct
96 {
99 
102 
104 
106 
107 typedef struct
108 {
110  float horizontal;
111 
113  float vertical;
114 
116 
118 
119 typedef enum
120 {
121  TWR_SAM_M8Q_STATE_ERROR = -1,
122  TWR_SAM_M8Q_STATE_START = 0,
123  TWR_SAM_M8Q_STATE_READ = 1,
124  TWR_SAM_M8Q_STATE_UPDATE = 2,
125  TWR_SAM_M8Q_STATE_STOP = 3
126 
127 } twr_sam_m8q_state_t;
128 
129 typedef void (twr_sam_m8q_event_handler_t)(twr_sam_m8q_t *, twr_sam_m8q_event_t, void *);
130 
131 struct twr_sam_m8q_t
132 {
133  twr_i2c_channel_t _i2c_channel;
134  uint8_t _i2c_address;
135  const twr_sam_m8q_driver_t *_driver;
136  twr_scheduler_task_id_t _task_id;
137  twr_sam_m8q_event_handler_t *_event_handler;
138  void *_event_param;
139  bool _running;
140  bool _configured;
141  twr_sam_m8q_state_t _state;
142  uint8_t _ddc_buffer[64];
143  size_t _ddc_length;
144  char _line_buffer[128];
145  size_t _line_length;
146  bool _line_clipped;
147  struct
148  {
149  bool valid;
150  struct
151  {
152  int year;
153  int month;
154  int day;
155  } date;
156  struct
157  {
158  int hours;
159  int minutes;
160  int seconds;
161  } time;
162  float latitude;
163  float longitude;
164  } _rmc;
165  struct
166  {
167  bool valid;
168  int fix_quality;
169  float altitude;
170  char altitude_units;
171  } _gga;
172  struct
173  {
174  bool valid;
175  float h_accuracy;
176  float v_accuracy;
177  float speed;
178  float course;
179  int satellites;
180  } _pubx;
181 };
182 
184 
190 
191 void twr_sam_m8q_init(twr_sam_m8q_t *self, twr_i2c_channel_t channel, uint8_t i2c_address, const twr_sam_m8q_driver_t *driver);
192 
197 
198 void twr_sam_m8q_set_event_handler(twr_sam_m8q_t *self, twr_sam_m8q_event_handler_t event_handler, void *event_param);
199 
202 
203 void twr_sam_m8q_start(twr_sam_m8q_t *self);
204 
207 
208 void twr_sam_m8q_stop(twr_sam_m8q_t *self);
209 
211 
213 
219 
221 
227 
229 
235 
237 
243 
245 
251 
253 
254 #endif // _TWR_SAM_M8Q
twr_i2c_channel_t
I2C channels.
Definition: twr_i2c.h:16
void twr_sam_m8q_stop(twr_sam_m8q_t *self)
Stop navigation module.
Definition: twr_sam_m8q.c:43
void twr_sam_m8q_invalidate(twr_sam_m8q_t *self)
Invalidate navigation data.
Definition: twr_sam_m8q.c:53
void twr_sam_m8q_start(twr_sam_m8q_t *self)
Start navigation module.
Definition: twr_sam_m8q.c:32
float longitude
Longitude.
Definition: twr_sam_m8q.h:77
void twr_sam_m8q_init(twr_sam_m8q_t *self, twr_i2c_channel_t channel, uint8_t i2c_address, const twr_sam_m8q_driver_t *driver)
Initialize SAM-M8Q module driver.
Definition: twr_sam_m8q.c:13
void twr_sam_m8q_set_event_handler(twr_sam_m8q_t *self, twr_sam_m8q_event_handler_t event_handler, void *event_param)
Set callback function.
Definition: twr_sam_m8q.c:26
int minutes
Minutes.
Definition: twr_sam_m8q.h:62
int seconds
Seconds.
Definition: twr_sam_m8q.h:65
float latitude
Latitude.
Definition: twr_sam_m8q.h:74
float horizontal
Horizontal accuracy estimate.
Definition: twr_sam_m8q.h:110
float altitude
Altitude.
Definition: twr_sam_m8q.h:86
int satellites_tracked
Number of satellites tracked.
Definition: twr_sam_m8q.h:101
bool twr_sam_m8q_get_quality(twr_sam_m8q_t *self, twr_sam_m8q_quality_t *quality)
Get quality.
Definition: twr_sam_m8q.c:109
bool twr_sam_m8q_get_accuracy(twr_sam_m8q_t *self, twr_sam_m8q_accuracy_t *accuracy)
Get accuracy.
Definition: twr_sam_m8q.c:124
struct twr_sam_m8q_t twr_sam_m8q_t
SAM-M8Q instance.
Definition: twr_sam_m8q.h:31
float vertical
Vertical accuracy estimate.
Definition: twr_sam_m8q.h:113
twr_sam_m8q_event_t
Callback events.
Definition: twr_sam_m8q.h:14
bool twr_sam_m8q_get_time(twr_sam_m8q_t *self, twr_sam_m8q_time_t *time)
Get time.
Definition: twr_sam_m8q.c:60
bool twr_sam_m8q_get_position(twr_sam_m8q_t *self, twr_sam_m8q_position_t *position)
Get position.
Definition: twr_sam_m8q.c:79
int fix_quality
Fix quality.
Definition: twr_sam_m8q.h:98
char units
Units of altitude.
Definition: twr_sam_m8q.h:89
bool twr_sam_m8q_get_altitude(twr_sam_m8q_t *self, twr_sam_m8q_altitude_t *altitude)
Get altitude.
Definition: twr_sam_m8q.c:94
@ TWR_SAM_M8Q_EVENT_ERROR
Error event.
Definition: twr_sam_m8q.h:16
@ TWR_SAM_M8Q_EVENT_STOP
Stop event.
Definition: twr_sam_m8q.h:25
@ TWR_SAM_M8Q_EVENT_START
Start event.
Definition: twr_sam_m8q.h:19
@ TWR_SAM_M8Q_EVENT_UPDATE
Update event.
Definition: twr_sam_m8q.h:22
size_t twr_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: twr_scheduler.h:22
Accuracy data structure.
Definition: twr_sam_m8q.h:108
Altitude data structure.
Definition: twr_sam_m8q.h:84
SAM-M8Q driver.
Definition: twr_sam_m8q.h:36
Position data structure.
Definition: twr_sam_m8q.h:72
Quality data structure.
Definition: twr_sam_m8q.h:96
Time data structure.
Definition: twr_sam_m8q.h:48