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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_uart.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define THINGSTREAM_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
70 
76 #define THINGSTREAM_OK 0
77 #define THINGSTREAM_ERROR -1
78 
84 #define THINGSTREAM_DRV_RX_BUFFER_SIZE 600
85 #define THINGSTREAM_DRV_TX_BUFFER_SIZE 100
86 
92 #define THINGSTREAM_NEMA_CGNSINF 1
93 #define THINGSTREAM_NEMA_GPGLL 3
94 #define THINGSTREAM_NEMA_CGNSINF_NUM_ELEMENT 20
95 #define THINGSTREAM_NEMA_GPGLL_NUM_ELEMENT 5
96 
102 #define THINGSTREAM_GPGGA_TIME 1
103 #define THINGSTREAM_GPGGA_LATITUDE 2
104 #define THINGSTREAM_GPGGA_LATITUDE_SIDE 3
105 #define THINGSTREAM_GPGGA_LONGITUDE 4
106 #define THINGSTREAM_GPGGA_LONGITUDE_SIDE 5
107 #define THINGSTREAM_GPGGA_QUALITY_INDICATOR 6
108 #define THINGSTREAM_GPGGA_NUMBER_OF_SATELLITES 7
109 #define THINGSTREAM_GPGGA_H_DILUTION_OF_POS 8
110 #define THINGSTREAM_GPGGA_ALTITUDE 9
111 #define THINGSTREAM_GPGGA_ALTITUDE_UNIT 10
112 #define THINGSTREAM_GPGGA_GEOIDAL_SEPARATION 11
113 #define THINGSTREAM_GPGGA_GEOIDAL_SEPARATION_UNIT 12
114 #define THINGSTREAM_GPGGA_TIME_SINCE_LAST_DGPS 13
115 #define THINGSTREAM_GPGGA_DGPS_REFERENCE_STATION_ID 14
116 
122 #define THINGSTREAM_GPGLL_LATITUDE 1
123 #define THINGSTREAM_GPGLL_LATITUDE_SIDE 2
124 #define THINGSTREAM_GPGLL_LONGITUDE 3
125 #define THINGSTREAM_GPGLL_LONGITUDE_SIDE 4
126 
132 #define THINGSTREAM_ERROR_COMMAND_OR_ELEMENT 0xFF
133 #define THINGSTREAM_ERROR_START_OR_END_COMMAND 0x8F
134 #define THINGSTREAM_ERROR_NEXT_ELEMENT 0x4F
135 #define THINGSTREAM_ERROR_CURRENT_ELEMENT 0x2F
136 #define THINGSTREAM_NO_ERROR 0x00
137 
143 #define THINGSTREAM_CGNSINF_RUN_STAT 1
144 #define THINGSTREAM_CGNSINF_FIX_STAT 2
145 #define THINGSTREAM_CGNSINF_DATE_TIME 3
146 #define THINGSTREAM_CGNSINF_LATITUDE 4
147 #define THINGSTREAM_CGNSINF_LONGITUDE 5
148 #define THINGSTREAM_CGNSINF_ALTITUDE 6
149 #define THINGSTREAM_CGNSINF_SPEED 7
150 #define THINGSTREAM_CGNSINF_COURSE 8
151 #define THINGSTREAM_CGNSINF_FIX_MODE 9
152 #define THINGSTREAM_CGNSINF_RESERVED1 10
153 #define THINGSTREAM_CGNSINF_HDOP 11
154 #define THINGSTREAM_CGNSINF_PDOP 12
155 #define THINGSTREAM_CGNSINF_VDOP 13
156 #define THINGSTREAM_CGNSINF_RESERVED2 14
157 #define THINGSTREAM_CGNSINF_SAT_VIEW 15
158 #define THINGSTREAM_CGNSINF_SAT_USED 16
159 #define THINGSTREAM_CGNSINF_GLONASS_VIEW 17
160 #define THINGSTREAM_CGNSINF_RESERVED3 18
161 #define THINGSTREAM_CGNSINF_C_N0 19
162 #define THINGSTREAM_CGNSINF_HPA 20
163 #define THINGSTREAM_CGNSINF_VPA 21
164  // End group macro
167 // --------------------------------------------------------------- PUBLIC TYPES
175 typedef struct
176 {
177  // Output pins
178  digital_out_t rst;
179 
180  // Modules
181  uart_t uart;
182 
183  char uart_rx_buffer[ THINGSTREAM_DRV_RX_BUFFER_SIZE ];
184  char uart_tx_buffer[ THINGSTREAM_DRV_TX_BUFFER_SIZE ];
185 
186 } thingstream_t;
187 
191 typedef struct
192 {
193  // Communication gpio pins
194  pin_name_t rx_pin;
195  pin_name_t tx_pin;
196 
197  // Additional gpio pins
198  pin_name_t rst;
199 
200  // static variable
201  uint32_t baud_rate; // Clock speed.
203  uart_data_bits_t data_bit; // Data bits.
204  uart_parity_t parity_bit; // Parity bit.
205  uart_stop_bits_t stop_bit; // Stop bits.
206 
208 
212 // Actuator switch type
214 
215 // Actuator counter type
217 
218 // Actuator string type
220 
221 // Parser error type
222 typedef uint8_t thingstream_error_t;
223  // End types group
225 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
226 
232 #ifdef __cplusplus
233 extern "C"{
234 #endif
235 
245 
254 
261 void thingstream_module_power ( thingstream_t *ctx, uint8_t power_state );
262 
269 void thingstream_reset_pin_state ( thingstream_t *ctx, uint8_t state );
270 
278 void thingstream_generic_write ( thingstream_t *ctx, char *data_buf, uint16_t len );
279 
289 int32_t thingstream_generic_read ( thingstream_t *ctx, char *data_buf, uint16_t max_len );
290 
297 void thingstream_send_command ( thingstream_t *ctx, char *command );
298 
309 thingstream_error_t thingstream_generic_parser ( char *rsp, uint8_t command,
310  uint8_t element, char *parser_buf );
311 
312 #ifdef __cplusplus
313 }
314 #endif
315 #endif // _THINGSTREAM_H_
316  // End public_function group
319 
320 // ------------------------------------------------------------------------- END
thingstream_send_command
void thingstream_send_command(thingstream_t *ctx, char *command)
Send command.
thingstream_cfg_t::baud_rate
uint32_t baud_rate
Definition: thingstream.h:201
thingstream_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: thingstream.h:205
thingstream_actuator_sw_t
uint8_t thingstream_actuator_sw_t
Error type.
Definition: thingstream.h:213
thingstream_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: thingstream.h:203
thingstream_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: thingstream.h:204
thingstream_cfg_setup
void thingstream_cfg_setup(thingstream_cfg_t *cfg)
Config Object Initialization function.
thingstream_cfg_t::rst
pin_name_t rst
Definition: thingstream.h:198
thingstream_init
err_t thingstream_init(thingstream_t *ctx, thingstream_cfg_t *cfg)
Initialization function.
thingstream_module_power
void thingstream_module_power(thingstream_t *ctx, uint8_t power_state)
Power module.
thingstream_generic_parser
thingstream_error_t thingstream_generic_parser(char *rsp, uint8_t command, uint8_t element, char *parser_buf)
Generic parser function.
THINGSTREAM_DRV_TX_BUFFER_SIZE
#define THINGSTREAM_DRV_TX_BUFFER_SIZE
Definition: thingstream.h:85
thingstream_error_t
uint8_t thingstream_error_t
Definition: thingstream.h:222
thingstream_cfg_t::tx_pin
pin_name_t tx_pin
Definition: thingstream.h:195
THINGSTREAM_DRV_RX_BUFFER_SIZE
#define THINGSTREAM_DRV_RX_BUFFER_SIZE
Definition: thingstream.h:84
thingstream_t::rst
digital_out_t rst
Definition: thingstream.h:178
thingstream_actuator_cnt_t
int16_t thingstream_actuator_cnt_t
Definition: thingstream.h:216
thingstream_cfg_t
Click configuration structure definition.
Definition: thingstream.h:192
thingstream_t
Click ctx object definition.
Definition: thingstream.h:176
thingstream_cfg_t::rx_pin
pin_name_t rx_pin
Definition: thingstream.h:194
thingstream_generic_read
int32_t thingstream_generic_read(thingstream_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
thingstream_actuator_str_t
char thingstream_actuator_str_t
Definition: thingstream.h:219
thingstream_generic_write
void thingstream_generic_write(thingstream_t *ctx, char *data_buf, uint16_t len)
Generic write function.
thingstream_reset_pin_state
void thingstream_reset_pin_state(thingstream_t *ctx, uint8_t state)
Set RST pin state.
thingstream_t::uart
uart_t uart
Definition: thingstream.h:181
thingstream_cfg_t::uart_blocking
bool uart_blocking
Definition: thingstream.h:202