thingstream  2.0.0.0
thingstream.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef THINGSTREAM_H
36 #define THINGSTREAM_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define THINGSTREAM_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
56 
62 #define THINGSTREAM_RETVAL uint8_t
63 
64 #define THINGSTREAM_OK 0x00
65 #define THINGSTREAM_INIT_ERROR 0xFF
66 
72 #define DRV_RX_BUFFER_SIZE 500
73 
75 #define THINGSTREAM_PIN_STATE_HIGH 1
76 #define THINGSTREAM_PIN_STATE_LOW 0
77 
78 #define THINGSTREAM_SUCCESS 0xAA
79 #define THINGSTREAM_ERROR 0xBB
80 
85 #define THINGSTREAM_NEMA_CGNSINF 1
86 #define THINGSTREAM_NEMA_GPGLL 3
87 #define THINGSTREAM_NEMA_CGNSINF_NUM_ELEMENT 15
88 #define THINGSTREAM_NEMA_GPGLL_NUM_ELEMENT 5
89 
95 #define THINGSTREAM_GPGGA_TIME 1
96 #define THINGSTREAM_GPGGA_LATITUDE 2
97 #define THINGSTREAM_GPGGA_LATITUDE_SIDE 3
98 #define THINGSTREAM_GPGGA_LONGITUDE 4
99 #define THINGSTREAM_GPGGA_LONGITUDE_SIDE 5
100 #define THINGSTREAM_GPGGA_QUALITY_INDICATOR 6
101 #define THINGSTREAM_GPGGA_NUMBER_OF_SATELLITES 7
102 #define THINGSTREAM_GPGGA_H_DILUTION_OF_POS 8
103 #define THINGSTREAM_GPGGA_ALTITUDE 9
104 #define THINGSTREAM_GPGGA_ALTITUDE_UNIT 10
105 #define THINGSTREAM_GPGGA_GEOIDAL_SEPARATION 11
106 #define THINGSTREAM_GPGGA_GEOIDAL_SEPARATION_UNIT 12
107 #define THINGSTREAM_GPGGA_TIME_SINCE_LAST_DGPS 13
108 #define THINGSTREAM_GPGGA_DGPS_REFERENCE_STATION_ID 14
109 
115 #define THINGSTREAM_GPGLL_LATITUDE 1
116 #define THINGSTREAM_GPGLL_LATITUDE_SIDE 2
117 #define THINGSTREAM_GPGLL_LONGITUDE 3
118 #define THINGSTREAM_GPGLL_LONGITUDE_SIDE 4
119 
125 #define THINGSTREAM_ERROR_COMMAND_OR_ELEMENT 0xFF
126 #define THINGSTREAM_ERROR_START_OR_END_COMMAND 0x8F
127 #define THINGSTREAM_ERROR_NEXT_ELEMENT 0x4F
128 #define THINGSTREAM_ERROR_CURRENT_ELEMENT 0x2F
129 #define THINGSTREAM_NO_ERROR 0x00
130 
136 #define THINGSTREAM_CGNSINF_RUN_STAT 1
137 #define THINGSTREAM_CGNSINF_FIX_STAT 2
138 #define THINGSTREAM_CGNSINF_DATE_TIME 3
139 #define THINGSTREAM_CGNSINF_LATITUDE 4
140 #define THINGSTREAM_CGNSINF_LONGITUDE 5
141 #define THINGSTREAM_CGNSINF_ALTITUDE 6
142 #define THINGSTREAM_CGNSINF_SPEED 7
143 #define THINGSTREAM_CGNSINF_COURSE 8
144 #define THINGSTREAM_CGNSINF_FIX_MODE 9
145 #define THINGSTREAM_CGNSINF_RESERVED1 10
146 #define THINGSTREAM_CGNSINF_HDOP 11
147 #define THINGSTREAM_CGNSINF_PDOP 12
148 #define THINGSTREAM_CGNSINF_VDOP 13
149 #define THINGSTREAM_CGNSINF_RESERVED2 14
150 #define THINGSTREAM_CGNSINF_SAT_VIEW 15
151 #define THINGSTREAM_CGNSINF_SAT_USED 16
152 #define THINGSTREAM_CGNSINF_GLONASS_VIEW 17
153 #define THINGSTREAM_CGNSINF_RESERVED3 18
154 #define THINGSTREAM_CGNSINF_C_N0 19
155 #define THINGSTREAM_CGNSINF_HPA 20
156 #define THINGSTREAM_CGNSINF_VPA 21
157  // End group macro
160 // --------------------------------------------------------------- PUBLIC TYPES
168 typedef struct
169 {
170  // Output pins
171 
172  digital_out_t rst;
173 
174  // Modules
175 
176  uart_t uart;
177 
178  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
179  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
180 
181 } thingstream_t;
182 
186 typedef struct
187 {
188  // Communication gpio pins
189 
190  pin_name_t rx_pin;
191  pin_name_t tx_pin;
192 
193  // Additional gpio pins
194 
195  pin_name_t rst;
196 
197  // static variable
198 
199  uint32_t baud_rate; // Clock speed.
201  uart_data_bits_t data_bit; // Data bits.
202  uart_parity_t parity_bit; // Parity bit.
203  uart_stop_bits_t stop_bit; // Stop bits.
204 
206 
210 // Actuator switch type
212 
213 // Actuator counter type
215 
216 // Actuator string type
218 
219 // Parser error type
220 typedef uint8_t thingstream_error_t;
221  // End types group
223 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
224 
230 #ifdef __cplusplus
231 extern "C"{
232 #endif
233 
243 
252 
259 void thingstream_module_power ( thingstream_t *ctx, uint8_t power_state );
260 
267 uint8_t thingstream_reset_pin_state ( thingstream_t *ctx, uint8_t state );
268 
276 void thingstream_generic_write ( thingstream_t *ctx, char *data_buf, uint16_t len );
277 
287 int32_t thingstream_generic_read ( thingstream_t *ctx, char *data_buf, uint16_t max_len );
288 
295 void thingstream_send_command ( thingstream_t *ctx, char *command );
296 
308 (
309  char *rsp, uint8_t command,
310  uint8_t element, char *parser_buf
311 );
312 
313 #ifdef __cplusplus
314 }
315 #endif
316 #endif // _THINGSTREAM_H_
317  // End public_function group
320 
321 // ------------------------------------------------------------------------- END
int16_t thingstream_actuator_cnt_t
Definition: thingstream.h:214
pin_name_t rx_pin
Definition: thingstream.h:190
Click configuration structure definition.
Definition: thingstream.h:186
bool uart_blocking
Definition: thingstream.h:200
uint8_t thingstream_error_t
Definition: thingstream.h:220
#define THINGSTREAM_RETVAL
Definition: thingstream.h:62
char thingstream_actuator_str_t
Definition: thingstream.h:217
void thingstream_generic_write(thingstream_t *ctx, char *data_buf, uint16_t len)
Generic write function.
uint8_t thingstream_reset_pin_state(thingstream_t *ctx, uint8_t state)
Set RST pin state.
uart_data_bits_t data_bit
Definition: thingstream.h:201
thingstream_error_t thingstream_generic_parser(char *rsp, uint8_t command, uint8_t element, char *parser_buf)
Generic parser function.
uint32_t baud_rate
Definition: thingstream.h:199
int32_t thingstream_generic_read(thingstream_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
pin_name_t tx_pin
Definition: thingstream.h:191
pin_name_t rst
Definition: thingstream.h:195
digital_out_t rst
Definition: thingstream.h:172
#define DRV_RX_BUFFER_SIZE
Definition: thingstream.h:72
void thingstream_module_power(thingstream_t *ctx, uint8_t power_state)
Power module.
void thingstream_cfg_setup(thingstream_cfg_t *cfg)
Config Object Initialization function.
uart_stop_bits_t stop_bit
Definition: thingstream.h:203
void thingstream_send_command(thingstream_t *ctx, char *command)
Send command.
Click ctx object definition.
Definition: thingstream.h:168
THINGSTREAM_RETVAL thingstream_init(thingstream_t *ctx, thingstream_cfg_t *cfg)
Initialization function.
uart_parity_t parity_bit
Definition: thingstream.h:202
uart_t uart
Definition: thingstream.h:176
uint8_t thingstream_actuator_sw_t
Error type.
Definition: thingstream.h:211