neomesh915mhz  2.1.0.0
neomesh915mhz.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 NEOMESH915MHZ_H
29 #define NEOMESH915MHZ_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
59 #define NEOMESH915MHZ_CMD_NACK_SEND 0x02
60 #define NEOMESH915MHZ_CMD_ACK_SEND 0x03
61 #define NEOMESH915MHZ_CMD_NODE_STATUS 0x07
62 #define NEOMESH915MHZ_CMD_NODE_INFO 0x08
63 #define NEOMESH915MHZ_CMD_NEIGHBOUR_LIST 0x09
64 #define NEOMESH915MHZ_CMD_NETWORK_COMMAND 0x0A
65 #define NEOMESH915MHZ_CMD_SAPI_TO_AAPI 0x0B
66 #define NEOMESH915MHZ_CMD_ROUTE_INFO 0x0C
67 #define NEOMESH915MHZ_CMD_WES_COMMAND 0x10
68 #define NEOMESH915MHZ_CMD_WES_SETUP_RSP 0x11
69 #define NEOMESH915MHZ_CMD_GET_SW_VERSION 0x14
70 #define NEOMESH915MHZ_CMD_ALT_MODE 0x20
71 
76 #define NEOMESH915MHZ_RSP_ACK 0x50
77 #define NEOMESH915MHZ_RSP_NACK 0x51
78 #define NEOMESH915MHZ_RSP_ACK_HOST 0x52
79 #define NEOMESH915MHZ_RSP_ACK_HOST_HAPA 0x53
80 #define NEOMESH915MHZ_RSP_NACK_HOST 0x54
81 #define NEOMESH915MHZ_RSP_NACK_HOST_HAPA 0x55
82 #define NEOMESH915MHZ_RSP_NACK_SEND 0x56
83 #define NEOMESH915MHZ_RSP_NACK_DROP 0x57
84 #define NEOMESH915MHZ_RSP_NODE_INFO 0x58
85 #define NEOMESH915MHZ_RSP_NEIGHBOUR_LIST 0x59
86 #define NEOMESH915MHZ_RSP_NETWORK_COMMAND 0x5A
87 #define NEOMESH915MHZ_RSP_ROUTE_INFO 0x5C
88 #define NEOMESH915MHZ_RSP_WES_STATUS 0x60
89 #define NEOMESH915MHZ_RSP_WES_SETUP 0x61
90 #define NEOMESH915MHZ_RSP_GET_SW_VERSION 0x64
91 #define NEOMESH915MHZ_RSP_ALT_MODE 0x70
92 
97 #define NEOMESH915MHZ_SAPI_CMD_LOGIN 0x0103u
98 #define NEOMESH915MHZ_SAPI_CMD_RESET_LIST_ITERATOR 0x0104u
99 #define NEOMESH915MHZ_SAPI_CMD_GET_LIST 0x0105u
100 #define NEOMESH915MHZ_SAPI_CMD_GET_SETTING_FLASH 0x0106u
101 #define NEOMESH915MHZ_SAPI_CMD_GET_SETTING_RAM 0x0107u
102 #define NEOMESH915MHZ_SAPI_CMD_COMMIT_SETTINGS 0x0108u
103 #define NEOMESH915MHZ_SAPI_CMD_DISCARD_SETTINGS 0x0109u
104 #define NEOMESH915MHZ_SAPI_CMD_SET_SETTING 0x010Au
105 #define NEOMESH915MHZ_SAPI_CMD_START_PROTOCOL_STACK 0x0112u
106 #define NEOMESH915MHZ_SAPI_CMD_START_BOOTLOADER 0x0113u
107 #define NEOMESH915MHZ_SAPI_HEADER 0x3E
108 #define NEOMESH915MHZ_SAPI_TRAIL 0x21
109 
114 #define NEOMESH915MHZ_SAPI_RSP_OK 0x0380u
115 #define NEOMESH915MHZ_SAPI_RSP_ERROR 0x0381u
116 #define NEOMESH915MHZ_SAPI_RSP_BOOTLOADER_START 0x0382u
117 #define NEOMESH915MHZ_SAPI_RSP_PROTOCOL_STACK_START 0x0383u
118 #define NEOMESH915MHZ_SAPI_RSP_PROTOCOL_STACK_ERROR 0x0384u
119 #define NEOMESH915MHZ_SAPI_RSP_RESET 0x0385u
120 #define NEOMESH915MHZ_SAPI_RSP_SETTINGS_LIST_OUTPUT 0x0185u
121 #define NEOMESH915MHZ_SAPI_RSP_SETTINGS_VALUE 0x0186u
122 
127 #define NEOMESH915MHZ_SAPI_LOGIN_PASSWORD_0 0x4C
128 #define NEOMESH915MHZ_SAPI_LOGIN_PASSWORD_1 0x76
129 #define NEOMESH915MHZ_SAPI_LOGIN_PASSWORD_2 0x6C
130 #define NEOMESH915MHZ_SAPI_LOGIN_PASSWORD_3 0x31
131 #define NEOMESH915MHZ_SAPI_LOGIN_PASSWORD_4 0x30
132 
137 #define NEOMESH915MHZ_SAPI_SETTINGS_ID_NODE_ID 0x0A
138 
143 #define NEOMESH915MHZ_TIMEOUT_MS 20000ul
144 
149 #define NEOMESH915MHZ_MAX_PAYLOAD_LEN 255
150 
156 #define NEOMESH915MHZ_TX_DRV_BUFFER_SIZE 300u
157 #define NEOMESH915MHZ_RX_DRV_BUFFER_SIZE 300u
158  // neomesh915mhz_cmd
160 
175 #define NEOMESH915MHZ_MAP_MIKROBUS( cfg, mikrobus ) \
176  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
177  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
178  cfg.app = MIKROBUS( mikrobus, MIKROBUS_AN ); \
179  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
180  cfg.wes = MIKROBUS( mikrobus, MIKROBUS_CS ); \
181  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
182  cfg.wup = MIKROBUS( mikrobus, MIKROBUS_INT );
183  // neomesh915mhz_map // neomesh915mhz
186 
191 typedef struct
192 {
193  // Output pins
194  digital_out_t rst;
195  digital_out_t wes;
197  // Input pins
198  digital_in_t app;
199  digital_in_t cts;
200  digital_in_t wup;
202  // Modules
203  uart_t uart;
205  // Buffers
206  uint8_t uart_rx_buffer[ NEOMESH915MHZ_RX_DRV_BUFFER_SIZE ];
207  uint8_t uart_tx_buffer[ NEOMESH915MHZ_TX_DRV_BUFFER_SIZE ];
210 
215 typedef struct
216 {
217  // Communication gpio pins
218  pin_name_t rx_pin;
219  pin_name_t tx_pin;
221  // Additional gpio pins
222  pin_name_t app;
223  pin_name_t rst;
224  pin_name_t wes;
225  pin_name_t cts;
226  pin_name_t wup;
228  // Static variable
229  uint32_t baud_rate;
231  uart_data_bits_t data_bit;
232  uart_parity_t parity_bit;
233  uart_stop_bits_t stop_bit;
236 
241 typedef struct
242 {
243  uint8_t cmd;
244  uint8_t len;
245  uint8_t payload[ NEOMESH915MHZ_MAX_PAYLOAD_LEN ];
248 
253 typedef struct
254 {
255  uint16_t cmd;
256  uint8_t len;
257  uint8_t payload[ NEOMESH915MHZ_MAX_PAYLOAD_LEN ];
260 
265 typedef enum
266 {
270 
272 
289 
304 
318 
333 
347 
362 
372 void neomesh915mhz_set_rst_pin ( neomesh915mhz_t *ctx, uint8_t state );
373 
383 void neomesh915mhz_set_wes_pin ( neomesh915mhz_t *ctx, uint8_t state );
384 
394 
404 
414 
415 #ifdef __cplusplus
416 }
417 #endif
418 #endif // NEOMESH915MHZ_H
419  // neomesh915mhz
421 
422 // ------------------------------------------------------------------------ END
neomesh915mhz_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: neomesh915mhz.h:231
neomesh915mhz_send_aapi_frame
err_t neomesh915mhz_send_aapi_frame(neomesh915mhz_t *ctx, neomesh915mhz_aapi_frame_t *frame)
NeoMesh 915MHz send aapi frame function.
neomesh915mhz_cfg_t::tx_pin
pin_name_t tx_pin
Definition: neomesh915mhz.h:219
neomesh915mhz_cfg_t::wes
pin_name_t wes
Definition: neomesh915mhz.h:224
neomesh915mhz_set_wes_pin
void neomesh915mhz_set_wes_pin(neomesh915mhz_t *ctx, uint8_t state)
NeoMesh 915MHz set wes pin function.
NEOMESH915MHZ_MAX_PAYLOAD_LEN
#define NEOMESH915MHZ_MAX_PAYLOAD_LEN
NeoMesh 915MHz payload length.
Definition: neomesh915mhz.h:149
neomesh915mhz_t::rst
digital_out_t rst
Definition: neomesh915mhz.h:194
NEOMESH915MHZ_TIMEOUT
@ NEOMESH915MHZ_TIMEOUT
Definition: neomesh915mhz.h:269
neomesh915mhz_read_sapi_frame
err_t neomesh915mhz_read_sapi_frame(neomesh915mhz_t *ctx, neomesh915mhz_sapi_frame_t *frame)
NeoMesh 915MHz read sapi frame function.
neomesh915mhz_cfg_t::wup
pin_name_t wup
Definition: neomesh915mhz.h:226
neomesh915mhz_sapi_frame_t
NeoMesh 915MHz Click data frame object.
Definition: neomesh915mhz.h:254
neomesh915mhz_cfg_t::rx_pin
pin_name_t rx_pin
Definition: neomesh915mhz.h:218
neomesh915mhz_cfg_t::uart_blocking
bool uart_blocking
Definition: neomesh915mhz.h:230
neomesh915mhz_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: neomesh915mhz.h:232
neomesh915mhz_aapi_frame_t
NeoMesh 915MHz Click data frame object.
Definition: neomesh915mhz.h:242
neomesh915mhz_sapi_frame_t::cmd
uint16_t cmd
Definition: neomesh915mhz.h:255
neomesh915mhz_init
err_t neomesh915mhz_init(neomesh915mhz_t *ctx, neomesh915mhz_cfg_t *cfg)
NeoMesh 915MHz initialization function.
neomesh915mhz_cfg_t::cts
pin_name_t cts
Definition: neomesh915mhz.h:225
neomesh915mhz_get_wup_pin
uint8_t neomesh915mhz_get_wup_pin(neomesh915mhz_t *ctx)
NeoMesh 915MHz get wup pin function.
neomesh915mhz_aapi_frame_t::len
uint8_t len
Definition: neomesh915mhz.h:244
neomesh915mhz_t::cts
digital_in_t cts
Definition: neomesh915mhz.h:199
neomesh915mhz_get_app_pin
uint8_t neomesh915mhz_get_app_pin(neomesh915mhz_t *ctx)
NeoMesh 915MHz get app pin function.
neomesh915mhz_aapi_frame_t::cmd
uint8_t cmd
Definition: neomesh915mhz.h:243
neomesh915mhz_t::uart
uart_t uart
Definition: neomesh915mhz.h:203
neomesh915mhz_t
NeoMesh 915MHz Click context object.
Definition: neomesh915mhz.h:192
neomesh915mhz_cfg_t::app
pin_name_t app
Definition: neomesh915mhz.h:222
NEOMESH915MHZ_ERROR
@ NEOMESH915MHZ_ERROR
Definition: neomesh915mhz.h:268
neomesh915mhz_get_cts_pin
uint8_t neomesh915mhz_get_cts_pin(neomesh915mhz_t *ctx)
NeoMesh 915MHz get cts pin function.
neomesh915mhz_return_value_t
neomesh915mhz_return_value_t
NeoMesh 915MHz Click return value data.
Definition: neomesh915mhz.h:266
NEOMESH915MHZ_RX_DRV_BUFFER_SIZE
#define NEOMESH915MHZ_RX_DRV_BUFFER_SIZE
Definition: neomesh915mhz.h:157
neomesh915mhz_cfg_t
NeoMesh 915MHz Click configuration object.
Definition: neomesh915mhz.h:216
neomesh915mhz_cfg_t::baud_rate
uint32_t baud_rate
Definition: neomesh915mhz.h:229
neomesh915mhz_t::app
digital_in_t app
Definition: neomesh915mhz.h:198
neomesh915mhz_read_aapi_frame
err_t neomesh915mhz_read_aapi_frame(neomesh915mhz_t *ctx, neomesh915mhz_aapi_frame_t *frame)
NeoMesh 915MHz read aapi frame function.
neomesh915mhz_sapi_frame_t::len
uint8_t len
Definition: neomesh915mhz.h:256
neomesh915mhz_t::wup
digital_in_t wup
Definition: neomesh915mhz.h:200
NEOMESH915MHZ_TX_DRV_BUFFER_SIZE
#define NEOMESH915MHZ_TX_DRV_BUFFER_SIZE
NeoMesh 915MHz driver buffer size.
Definition: neomesh915mhz.h:156
NEOMESH915MHZ_OK
@ NEOMESH915MHZ_OK
Definition: neomesh915mhz.h:267
neomesh915mhz_set_rst_pin
void neomesh915mhz_set_rst_pin(neomesh915mhz_t *ctx, uint8_t state)
NeoMesh 915MHz set rst pin function.
neomesh915mhz_cfg_setup
void neomesh915mhz_cfg_setup(neomesh915mhz_cfg_t *cfg)
NeoMesh 915MHz configuration object setup function.
neomesh915mhz_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: neomesh915mhz.h:233
neomesh915mhz_t::wes
digital_out_t wes
Definition: neomesh915mhz.h:195
neomesh915mhz_send_sapi_frame
err_t neomesh915mhz_send_sapi_frame(neomesh915mhz_t *ctx, neomesh915mhz_sapi_frame_t *frame)
NeoMesh 915MHz send sapi frame function.
neomesh915mhz_cfg_t::rst
pin_name_t rst
Definition: neomesh915mhz.h:223