wirelesssun  2.1.0.0
wirelesssun.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef WIRELESSSUN_H
29 #define WIRELESSSUN_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_uart.h"
52 
73 #define WIRELESSSUN_CMD_HELP "help" // help - disp help
74 #define WIRELESSSUN_CMD_VERS "vers" // vers - disp firmware version string
75 #define WIRELESSSUN_CMD_VERNUM "vernum" // vernum - disp firmware version number
76 #define WIRELESSSUN_CMD_RESET "reset" // reset [sec] execute to reset board
77 #define WIRELESSSUN_CMD_SLEEP "sleep" // sleep - execute to turn system sleep
78 #define WIRELESSSUN_CMD_ECHO "echo" // echo [0|1] - set/disp terminal echo
79 #define WIRELESSSUN_CMD_JSON "json" // json [0|1] - set/disp json command mode
80 #define WIRELESSSUN_CMD_MODE "mode" // mode [profile] - set/disp profile mode (0:NONE 1:FAN)
81 #define WIRELESSSUN_CMD_CHRATE "chrate" // chrate [rate] - disp parameter radio frequency rate (Kbps)
82 #define WIRELESSSUN_CMD_CHAN "chan" // chan [low] [high] - set/disp radio channel range
83 #define WIRELESSSUN_CMD_RCCAL "rccal" // rccal [rssi] - set/disp RSSI threshold of CCA
84 #define WIRELESSSUN_CMD_MAC "mac" // mac - disp MAC address
85 #define WIRELESSSUN_CMD_MACF "macf" // macf [allow|deny|del|clr] [mac] - set/disp MAC filtering table
86 #define WIRELESSSUN_CMD_MTXCTL "mtxctl" // mtxctl [0|1] - disp to control MAC TX//time
87 #define WIRELESSSUN_CMD_PAN "pan" // pan [id] - set/disp PAN ID
88 #define WIRELESSSUN_CMD_NETNAME "netname" // netname [name] - set/disp network name
89 #define WIRELESSSUN_CMD_IP "ip" // ip [ADDR] - set/disp self IPv6 address
90 #define WIRELESSSUN_CMD_INIT "init" // init [role] - disp/execute to start/stop node's role <role> 0:stop 1:BORDER 2:ROUTER 3:LEAF
91 #define WIRELESSSUN_CMD_ATSTART "atstart" // atstart [role] - set/disp auto//starting role
92 #define WIRELESSSUN_CMD_TCPCON "tcpcon" // tcpcon <ADDR> [port] - set/execute to connect TCP port
93 #define WIRELESSSUN_CMD_TCPDIS "tcpdis" // tcpdis <ADDR> [port] - set/execute to disconnect TCP port
94 #define WIRELESSSUN_CMD_LEASEIP "leaseip" // leaseip [MAC|del|clr] [ADDR] - set/disp fixed leasing address
95 #define WIRELESSSUN_CMD_LEASERNG "leaserng" // leaserng [num] - set/disp range of leasing address by DHCPv6 server
96 #define WIRELESSSUN_CMD_STAT "stat" // stat - disp system status
97 #define WIRELESSSUN_CMD_RSTAT "rstat" // rstat - disp radio status
98 #define WIRELESSSUN_CMD_MSTAT "mstat" // mstat - disp MAC statistics
99 #define WIRELESSSUN_CMD_FSTAT "fstat" // fstat - disp FAN state
100 #define WIRELESSSUN_CMD_CHCONFIG "chconfig" // chconfig - disp radio channel configuration
101 #define WIRELESSSUN_CMD_CHCUR "chcur" // chcur - disp currrent radio channel number
102 #define WIRELESSSUN_CMD_MTXAVL "mtxavl" // mtxavl - disp available bytes in MAC-TX limitation
103 #define WIRELESSSUN_CMD_FMSECKEY "fmseckey" // fmseckey - disp MAC Security KEY for FAN
104 #define WIRELESSSUN_CMD_NEBR "nebr" // nebr [del|clr] [ADDR] - set/disp neighbors
105 #define WIRELESSSUN_CMD_PARENT "parent" // parent - disp current parent address
106 #define WIRELESSSUN_CMD_RPLINF "rplinf" // rplinf - disp RPL information
107 #define WIRELESSSUN_CMD_TCPSTAT "tcpstat" // tcpstat - disp TCP stat
108 #define WIRELESSSUN_CMD_RPLSR "rplsr" // rplsr [del|clr] [ADDR] - disp RPL Source Route
109 #define WIRELESSSUN_CMD_LEASED "leased" // leased [del|clr] [ADDR] - set/disp leased address from DHCPv6 server
110 #define WIRELESSSUN_CMD_TCPS "tcps" // tcps <ADDR> [port] <data> - send TCP data
111 #define WIRELESSSUN_CMD_UDPS "udps" // udps <ADDR> [port] <data> - send UDP data
112 #define WIRELESSSUN_CMD_UDPST "udpst" // udpst <ADDR> [port] <text> - send UDP text data
113 #define WIRELESSSUN_CMD_PING "ping" // ping <start/stop/state/-> <ADDR>< [sz] [sec] [cnt] - send ping packet
114 #define WIRELESSSUN_CMD_TCPOPTS "tcpopts" // tcpopts [opt] [port|enable] - set/disp TCP options
115 #define WIRELESSSUN_CMD_UDPOPTS "udpopts" // udpopts [opt] [port|enable] - set/disp UDP options
116 #define WIRELESSSUN_CMD_RMTCMD "rmtcmd" // rmtcmd <ADDR> <cmd> [arg1] [arg2] ... - send remote command
117 #define WIRELESSSUN_CMD_RMTOPTS "rmtopts" // rmtopts [opt] [enable] - set/disp RMTCTL options
118 #define WIRELESSSUN_CMD_RFEC "rfec" // rfec [0|1] - set/disp radio FEC mode
119 #define WIRELESSSUN_CMD_RANTSW "rantsw" // rantsw [num] - set/disp anntena switch selection <num> 0:diversity 1<= : antenna number
120 #define WIRELESSSUN_CMD_FNODE "fnode" // fnode [del|clr] [ADDR] - set/disp FAN connect node
121 #define WIRELESSSUN_CMD_AUTH "auth" // auth [0|1] - set/disp authentication mode
122 #define WIRELESSSUN_CMD_NODEF "nodef" // nodef [allow|deny|del|clr] [mac] - set/disp node filtering table
123 #define WIRELESSSUN_CMD_PARAM "param" // param - disp parameters
124 #define WIRELESSSUN_CMD_SAVE "save" // save - save parameters
125 #define WIRELESSSUN_CMD_CLEAR "clear" // clear - clear parameters
126 #define WIRELESSSUN_CMD_SVRST "svrst" // svrst [reset_delay_sec] - save parameters and reset
127 #define WIRELESSSUN_CMD_CLRST "clrst" // clrst [reset_delay_sec] - clear parameters and reset
128 #define WIRELESSSUN_CMD_PROMPT_SIGN "\r\n>" // Command prompt sign
129 #define WIRELESSSUN_CMD_DELIMITER " " // Command parameters delimiter
130 #define WIRELESSSUN_RSP_UDPR "udpr" // Command parameters delimiter
131 
136 #define WIRELESSSUN_RSP_UDPR "udpr"
137 #define WIRELESSSUN_RSP_TCPR "tcpr"
138 
143 #define WIRELESSSUN_DEVICE_ROLE_STOP "0"
144 #define WIRELESSSUN_DEVICE_ROLE_BORDER "1"
145 #define WIRELESSSUN_DEVICE_ROLE_ROUTER "2"
146 #define WIRELESSSUN_DEVICE_ROLE_LEAF "3"
147 
152 #define WIRELESSSUN_DEFAULT_PORT "3610"
153 
159 #define TX_DRV_BUFFER_SIZE 100
160 #define RX_DRV_BUFFER_SIZE 600
161  // wirelesssun_cmd
163 
178 #define WIRELESSSUN_MAP_MIKROBUS( cfg, mikrobus ) \
179  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
180  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
181  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
182  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
183  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
184  // wirelesssun_map // wirelesssun
187 
192 typedef struct
193 {
194  // Output pins
195  digital_out_t rst;
196  digital_out_t cts;
198  // Input pins
199  digital_in_t rts;
201  // Modules
202  uart_t uart;
204  // Buffers
205  char uart_rx_buffer[ RX_DRV_BUFFER_SIZE ];
206  char uart_tx_buffer[ TX_DRV_BUFFER_SIZE ];
208 } wirelesssun_t;
209 
214 typedef struct
215 {
216  // Communication gpio pins
217  pin_name_t rx_pin;
218  pin_name_t tx_pin;
220  // Additional gpio pins
221  pin_name_t rst;
222  pin_name_t cts;
223  pin_name_t rts;
225  // Static variable
226  uint32_t baud_rate;
228  uart_data_bits_t data_bit;
229  uart_parity_t parity_bit;
230  uart_stop_bits_t stop_bit;
233 
238 typedef enum
239 {
243 
245 
262 
277 
290 err_t wirelesssun_generic_write ( wirelesssun_t *ctx, char *data_in, uint16_t len );
291 
304 err_t wirelesssun_generic_read ( wirelesssun_t *ctx, char *data_out, uint16_t len );
305 
315 void wirelesssun_send_cmd ( wirelesssun_t *ctx, char *cmd );
316 
327 void wirelesssun_send_cmd_with_parameter ( wirelesssun_t *ctx, char *cmd, char *param_buf );
328 
338 
348 void wirelesssun_set_rst_pin ( wirelesssun_t *ctx, uint8_t state );
349 
359 void wirelesssun_set_cts_pin ( wirelesssun_t *ctx, uint8_t state );
360 
370 
371 #ifdef __cplusplus
372 }
373 #endif
374 #endif // WIRELESSSUN_H
375  // wirelesssun
377 
378 // ------------------------------------------------------------------------ END
wirelesssun_return_value_t
wirelesssun_return_value_t
Wireless SUN Click return value data.
Definition: wirelesssun.h:239
wirelesssun_send_cmd_with_parameter
void wirelesssun_send_cmd_with_parameter(wirelesssun_t *ctx, char *cmd, char *param_buf)
Wireless SUN send cmd function.
wirelesssun_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: wirelesssun.h:230
wirelesssun_get_rts_pin
uint8_t wirelesssun_get_rts_pin(wirelesssun_t *ctx)
Wireless SUN get rts pin function.
wirelesssun_send_cmd
void wirelesssun_send_cmd(wirelesssun_t *ctx, char *cmd)
Wireless SUN send cmd function.
wirelesssun_reset_device
void wirelesssun_reset_device(wirelesssun_t *ctx)
Wireless SUN reset device function.
wirelesssun_cfg_t::tx_pin
pin_name_t tx_pin
Definition: wirelesssun.h:218
WIRELESSSUN_ERROR_TIMEOUT
@ WIRELESSSUN_ERROR_TIMEOUT
Definition: wirelesssun.h:242
wirelesssun_t::uart
uart_t uart
Definition: wirelesssun.h:202
WIRELESSSUN_ERROR
@ WIRELESSSUN_ERROR
Definition: wirelesssun.h:241
TX_DRV_BUFFER_SIZE
#define TX_DRV_BUFFER_SIZE
Wireless SUN driver buffer size.
Definition: wirelesssun.h:159
wirelesssun_cfg_t::cts
pin_name_t cts
Definition: wirelesssun.h:222
wirelesssun_cfg_t::rx_pin
pin_name_t rx_pin
Definition: wirelesssun.h:217
wirelesssun_cfg_t::uart_blocking
bool uart_blocking
Definition: wirelesssun.h:227
wirelesssun_t::rst
digital_out_t rst
Definition: wirelesssun.h:195
wirelesssun_set_rst_pin
void wirelesssun_set_rst_pin(wirelesssun_t *ctx, uint8_t state)
Wireless SUN set rst pin function.
wirelesssun_cfg_setup
void wirelesssun_cfg_setup(wirelesssun_cfg_t *cfg)
Wireless SUN configuration object setup function.
wirelesssun_cfg_t::rts
pin_name_t rts
Definition: wirelesssun.h:223
wirelesssun_cfg_t::rst
pin_name_t rst
Definition: wirelesssun.h:221
wirelesssun_init
err_t wirelesssun_init(wirelesssun_t *ctx, wirelesssun_cfg_t *cfg)
Wireless SUN initialization function.
RX_DRV_BUFFER_SIZE
#define RX_DRV_BUFFER_SIZE
Definition: wirelesssun.h:160
wirelesssun_t
Wireless SUN Click context object.
Definition: wirelesssun.h:193
wirelesssun_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: wirelesssun.h:229
wirelesssun_cfg_t
Wireless SUN Click configuration object.
Definition: wirelesssun.h:215
wirelesssun_t::cts
digital_out_t cts
Definition: wirelesssun.h:196
wirelesssun_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: wirelesssun.h:228
wirelesssun_t::rts
digital_in_t rts
Definition: wirelesssun.h:199
WIRELESSSUN_OK
@ WIRELESSSUN_OK
Definition: wirelesssun.h:240
wirelesssun_cfg_t::baud_rate
uint32_t baud_rate
Definition: wirelesssun.h:226
wirelesssun_generic_write
err_t wirelesssun_generic_write(wirelesssun_t *ctx, char *data_in, uint16_t len)
Wireless SUN data writing function.
wirelesssun_set_cts_pin
void wirelesssun_set_cts_pin(wirelesssun_t *ctx, uint8_t state)
Wireless SUN set cts pin function.
wirelesssun_generic_read
err_t wirelesssun_generic_read(wirelesssun_t *ctx, char *data_out, uint16_t len)
Wireless SUN data reading function.