g2c3g  2.0.0.0
g2c3g.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 G2C3G_H
36 #define G2C3G_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 G2C3G_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55  cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
56  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
57  cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_PWM )
58 
64 #define G2C3G_RETVAL uint8_t
65 
66 #define G2C3G_OK 0x00
67 #define G2C3G_INIT_ERROR 0xFF
68 
74 #define G2C3G_PARSER_NO_ERROR 0x00
75 #define G2C3G_PARSER_ERROR_REF 0x01
76 #define G2C3G_PARSER_ERROR_CMD 0x02
77 #define G2C3G_PARSER_ERROR_DATA 0x04
78 
84 #define G2C3G_STATUS_DEVICE_READY 1
85 #define G2C3G_STATUS_ACT_NETWORK_AND_BROKER 4
86 #define G2C3G_STATUS_ACT_NETWORK 2
87 #define G2C3G_STATUS_ACT_BROKER 3
88 #define G2C3G_STATUS_DEVICE_BUSY 0
89 
95 #define G2C3G_MODULE_POWER_ON 1
96 #define G2C3G_MODULE_POWER_OFF 0
97  // End group macro
100 // --------------------------------------------------------------- PUBLIC TYPES
109 typedef struct
110 {
111  // Output pins
112 
113  digital_out_t rst;
114  digital_out_t cts;
115 
116  // Input pins
117 
118  digital_in_t gp0;
119  digital_in_t gp1;
120  digital_in_t rts;
121 
122  // Modules
123 
124  uart_t uart;
125 
126  char uart_rx_buffer[ 256 ];
127  char uart_tx_buffer[ 256 ];
128 
129 } g2c3g_t;
130 
134 typedef struct
135 {
136  // Communication gpio pins
137 
138  pin_name_t rx_pin;
139  pin_name_t tx_pin;
140 
141  // Additional gpio pins
142 
143  pin_name_t gp0;
144  pin_name_t rst;
145  pin_name_t cts;
146  pin_name_t gp1;
147  pin_name_t rts;
148 
149  // static variable
150 
151  uint32_t baud_rate; // Clock speed.
153  uart_data_bits_t data_bit; // Data bits.
154  uart_parity_t parity_bit; // Parity bit.
155  uart_stop_bits_t stop_bit; // Stop bits.
156 
157 } g2c3g_cfg_t;
158 
159 // Actuator switch type
160 typedef uint8_t g2c3g_actuator_sw_t;
161 
162 // Actuator counter type
163 typedef int16_t g2c3g_actuator_cnt_t;
164 
165 // Actuator string type
166 typedef char g2c3g_actuator_str_t;
167 
168 // Parser error type
169 typedef uint8_t g2c3g_error_t;
170  // End types group
172 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
173 
179 #ifdef __cplusplus
180 extern "C"{
181 #endif
182 
191 void g2c3g_cfg_setup( g2c3g_cfg_t *cfg );
192 
202 
208 void g2c3g_module_reset( g2c3g_t *ctx );
209 
215 uint8_t g2c3g_led_net( g2c3g_t *ctx );
216 
222 uint8_t g2c3g_led_conn( g2c3g_t *ctx );
223 
231 void g2c3g_generic_write( g2c3g_t *ctx, char *data_buf, uint16_t len );
232 
242 int32_t g2c3g_generic_read( g2c3g_t *ctx, char *data_buf, uint16_t max_len );
243 
250 void g2c3g_send_command( g2c3g_t *ctx, char *command );
251 
260 void g2c3g_send_operator_cfg( g2c3g_t *ctx, char *op_apn, char *op_username, char *op_password );
261 
269 void g2c3g_send_broker_cfg( g2c3g_t *ctx, char *brc_key, char *brc_password );
270 
278 void g2c3g_send_data_ref( g2c3g_t *ctx, char *reference_buf, char *data_buf );
279 
289 g2c3g_error_t g2c3g_actuator_sw_parser( char *rsp, char *act_ref, g2c3g_actuator_sw_t *sw_state );
290 
300 g2c3g_error_t g2c3g_actuator_cnt_parser( char *rsp, char *act_ref, g2c3g_actuator_cnt_t *num_data );
301 
311 g2c3g_error_t g2c3g_actuator_str_parser( char *rsp, char *act_ref, g2c3g_actuator_str_t *str_data );
312 
313 #ifdef __cplusplus
314 }
315 #endif
316 #endif // _G2C3G_H_
317  // End public_function group
320 
321 // ------------------------------------------------------------------------- END
g2c3g_t
Click ctx object definition.
Definition: g2c3g.h:109
g2c3g_cfg_t
Click configuration structure definition.
Definition: g2c3g.h:134
g2c3g_init
G2C3G_RETVAL g2c3g_init(g2c3g_t *ctx, g2c3g_cfg_t *cfg)
Initialization function.
g2c3g_led_net
uint8_t g2c3g_led_net(g2c3g_t *ctx)
Led network.
g2c3g_cfg_t::rx_pin
pin_name_t rx_pin
Definition: g2c3g.h:138
g2c3g_actuator_sw_t
uint8_t g2c3g_actuator_sw_t
Definition: g2c3g.h:160
g2c3g_cfg_t::uart_blocking
bool uart_blocking
Definition: g2c3g.h:152
g2c3g_cfg_setup
void g2c3g_cfg_setup(g2c3g_cfg_t *cfg)
Config Object Initialization function.
g2c3g_t::gp0
digital_in_t gp0
Definition: g2c3g.h:118
g2c3g_cfg_t::baud_rate
uint32_t baud_rate
Definition: g2c3g.h:151
g2c3g_cfg_t::rts
pin_name_t rts
Definition: g2c3g.h:147
g2c3g_cfg_t::tx_pin
pin_name_t tx_pin
Definition: g2c3g.h:139
g2c3g_send_data_ref
void g2c3g_send_data_ref(g2c3g_t *ctx, char *reference_buf, char *data_buf)
Send data reference.
g2c3g_send_broker_cfg
void g2c3g_send_broker_cfg(g2c3g_t *ctx, char *brc_key, char *brc_password)
Broker configuration.
g2c3g_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: g2c3g.h:154
g2c3g_error_t
uint8_t g2c3g_error_t
Definition: g2c3g.h:169
g2c3g_t::cts
digital_out_t cts
Definition: g2c3g.h:114
g2c3g_t::gp1
digital_in_t gp1
Definition: g2c3g.h:119
g2c3g_t::uart
uart_t uart
Definition: g2c3g.h:124
g2c3g_send_command
void g2c3g_send_command(g2c3g_t *ctx, char *command)
Function for send command.
g2c3g_t::rts
digital_in_t rts
Definition: g2c3g.h:120
g2c3g_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: g2c3g.h:153
g2c3g_module_reset
void g2c3g_module_reset(g2c3g_t *ctx)
Reset module.
g2c3g_cfg_t::cts
pin_name_t cts
Definition: g2c3g.h:145
g2c3g_actuator_str_parser
g2c3g_error_t g2c3g_actuator_str_parser(char *rsp, char *act_ref, g2c3g_actuator_str_t *str_data)
String parser function.
g2c3g_t::rst
digital_out_t rst
Definition: g2c3g.h:113
g2c3g_cfg_t::gp0
pin_name_t gp0
Definition: g2c3g.h:143
g2c3g_led_conn
uint8_t g2c3g_led_conn(g2c3g_t *ctx)
Led connection.
G2C3G_RETVAL
#define G2C3G_RETVAL
Definition: g2c3g.h:64
g2c3g_generic_read
int32_t g2c3g_generic_read(g2c3g_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
g2c3g_cfg_t::gp1
pin_name_t gp1
Definition: g2c3g.h:146
g2c3g_actuator_sw_parser
g2c3g_error_t g2c3g_actuator_sw_parser(char *rsp, char *act_ref, g2c3g_actuator_sw_t *sw_state)
Switch parser function.
g2c3g_actuator_cnt_parser
g2c3g_error_t g2c3g_actuator_cnt_parser(char *rsp, char *act_ref, g2c3g_actuator_cnt_t *num_data)
Counter parser function.
g2c3g_actuator_cnt_t
int16_t g2c3g_actuator_cnt_t
Definition: g2c3g.h:163
g2c3g_cfg_t::rst
pin_name_t rst
Definition: g2c3g.h:144
g2c3g_actuator_str_t
char g2c3g_actuator_str_t
Definition: g2c3g.h:166
g2c3g_generic_write
void g2c3g_generic_write(g2c3g_t *ctx, char *data_buf, uint16_t len)
Generic write function.
g2c3g_send_operator_cfg
void g2c3g_send_operator_cfg(g2c3g_t *ctx, char *op_apn, char *op_username, char *op_password)
Operater configuration.
g2c3g_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: g2c3g.h:155