g2c  2.0.0.0
g2c.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 G2C_H
36 #define G2C_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 G2C_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  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
58 
64 #define G2C_RETVAL uint8_t
65 
66 #define G2C_OK 0x00
67 #define G2C_INIT_ERROR 0xFF
68 
74 #define G2C_PARSER_NO_ERROR 0x00
75 #define G2C_PARSER_ERROR_REF 0x01
76 #define G2C_PARSER_ERROR_CMD 0x02
77 #define G2C_PARSER_ERROR_DATA 0x04
78 
84 #define G2C_STATUS_DEVICE_READY 1
85 #define G2C_STATUS_ACT_NETWORK_AND_BROKER 4
86 #define G2C_STATUS_ACT_NETWORK 2
87 #define G2C_STATUS_ACT_BROKER 3
88 #define G2C_STATUS_DEVICE_BUSY 0
89 
95 #define G2C_MODULE_POWER_ON 1
96 #define G2C_MODULE_POWER_OFF 0
97 
103 #define DRV_RX_BUFFER_SIZE 500
104  // End group macro
107 // --------------------------------------------------------------- PUBLIC TYPES
115 typedef struct
116 {
117  // Output pins
118 
119  digital_out_t rst;
120  digital_out_t cts;
121 
122  // Input pins
123 
124  digital_in_t rts;
125 
126  // Modules
127 
128  uart_t uart;
129 
130  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
131  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
132 
133 } g2c_t;
134 
138 typedef struct
139 {
140  // Communication gpio pins
141 
142  pin_name_t rx_pin;
143  pin_name_t tx_pin;
144 
145  // Additional gpio pins
146 
147  pin_name_t rst;
148  pin_name_t cts;
149  pin_name_t rts;
150 
151  // static variable
152 
153  uint32_t baud_rate; // Clock speed.
155  uart_data_bits_t data_bit; // Data bits.
156  uart_parity_t parity_bit; // Parity bit.
157  uart_stop_bits_t stop_bit; // Stop bits.
158 
159 } g2c_cfg_t;
160 
164 // Actuator switch type
165 typedef uint8_t g2c_actuator_sw_t;
166 
167 // Actuator counter type
168 typedef int16_t g2c_actuator_cnt_t;
169 
170 // Actuator string type
171 typedef char g2c_actuator_str_t;
172 
173 // Parser error type
174 typedef uint8_t g2c_error_t;
175  // End types group
177 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
178 
184 #ifdef __cplusplus
185 extern "C"{
186 #endif
187 
196 void g2c_cfg_setup ( g2c_cfg_t *cfg );
197 
206 G2C_RETVAL g2c_init ( g2c_t *ctx, g2c_cfg_t *cfg );
207 
215 void g2c_module_power( g2c_t *ctx, uint8_t power_state, uint8_t bootloader );
216 
222 void g2c_reset ( g2c_t *ctx );
223 
231 void g2c_generic_write ( g2c_t *ctx, char *data_buf, uint16_t len );
232 
242 uint16_t g2c_generic_read ( g2c_t *ctx, char *data_buf, uint16_t max_len );
243 
250 void g2c_send_command ( g2c_t *ctx, char *command );
251 
259 void g2c_send_operator_cfg( g2c_t *ctx, char *op_username, char *op_password );
260 
268 void g2c_send_broker_cfg( g2c_t *ctx, char *brc_key, char *brc_password );
269 
277 void g2c_send_data_ref( g2c_t *ctx, char *reference_buf, char *data_buf );
278 
288 g2c_error_t g2c_actuator_sw_parser ( char *rsp, char *act_ref, g2c_actuator_sw_t *sw_state );
289 
299 g2c_error_t g2c_actuator_cnt_parser ( char *rsp, char *act_ref, g2c_actuator_cnt_t *num_data );
300 
310 g2c_error_t g2c_actuator_str_parser ( char *rsp, char *act_ref, g2c_actuator_str_t *str_data );
311 
312 #ifdef __cplusplus
313 }
314 #endif
315 #endif // _G2C_H_
316  // End public_function group
319 
320 // ------------------------------------------------------------------------- END
void g2c_send_broker_cfg(g2c_t *ctx, char *brc_key, char *brc_password)
Broker configuration.
g2c_error_t g2c_actuator_str_parser(char *rsp, char *act_ref, g2c_actuator_str_t *str_data)
String parser function.
char g2c_actuator_str_t
Definition: g2c.h:171
uart_stop_bits_t stop_bit
Definition: g2c.h:157
G2C_RETVAL g2c_init(g2c_t *ctx, g2c_cfg_t *cfg)
Initialization function.
uint8_t g2c_error_t
Definition: g2c.h:174
uart_parity_t parity_bit
Definition: g2c.h:156
void g2c_cfg_setup(g2c_cfg_t *cfg)
Config Object Initialization function.
pin_name_t rts
Definition: g2c.h:149
uint16_t g2c_generic_read(g2c_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
digital_out_t rst
Definition: g2c.h:119
uint8_t g2c_actuator_sw_t
Error type.
Definition: g2c.h:165
pin_name_t rx_pin
Definition: g2c.h:142
g2c_error_t g2c_actuator_sw_parser(char *rsp, char *act_ref, g2c_actuator_sw_t *sw_state)
Switch parser function.
void g2c_send_command(g2c_t *ctx, char *command)
Function for send command.
Click ctx object definition.
Definition: g2c.h:115
Click configuration structure definition.
Definition: g2c.h:138
void g2c_reset(g2c_t *ctx)
Reset module.
void g2c_module_power(g2c_t *ctx, uint8_t power_state, uint8_t bootloader)
Power module.
uart_data_bits_t data_bit
Definition: g2c.h:155
void g2c_send_operator_cfg(g2c_t *ctx, char *op_username, char *op_password)
Operater ( Network ) configuration.
pin_name_t rst
Definition: g2c.h:147
#define DRV_RX_BUFFER_SIZE
Definition: g2c.h:103
uint32_t baud_rate
Definition: g2c.h:153
pin_name_t cts
Definition: g2c.h:148
pin_name_t tx_pin
Definition: g2c.h:143
void g2c_generic_write(g2c_t *ctx, char *data_buf, uint16_t len)
Generic write function.
int16_t g2c_actuator_cnt_t
Definition: g2c.h:168
#define G2C_RETVAL
Definition: g2c.h:64
digital_in_t rts
Definition: g2c.h:124
digital_out_t cts
Definition: g2c.h:120
uart_t uart
Definition: g2c.h:128
bool uart_blocking
Definition: g2c.h:154
g2c_error_t g2c_actuator_cnt_parser(char *rsp, char *act_ref, g2c_actuator_cnt_t *num_data)
Counter parser function.
void g2c_send_data_ref(g2c_t *ctx, char *reference_buf, char *data_buf)
Send data reference.