neomesh868mhz 2.1.0.0
neomesh868mhz.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 NEOMESH868MHZ_H
29#define NEOMESH868MHZ_H
30
31#ifdef __cplusplus
32extern "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 NEOMESH868MHZ_CMD_NACK_SEND 0x02
74#define NEOMESH868MHZ_CMD_ACK_SEND 0x03
75#define NEOMESH868MHZ_CMD_NODE_STATUS 0x07
76#define NEOMESH868MHZ_CMD_NODE_INFO 0x08
77#define NEOMESH868MHZ_CMD_NEIGHBOUR_LIST 0x09
78#define NEOMESH868MHZ_CMD_NETWORK_COMMAND 0x0A
79#define NEOMESH868MHZ_CMD_SAPI_TO_AAPI 0x0B
80#define NEOMESH868MHZ_CMD_ROUTE_INFO 0x0C
81#define NEOMESH868MHZ_CMD_WES_COMMAND 0x10
82#define NEOMESH868MHZ_CMD_WES_SETUP_RSP 0x11
83#define NEOMESH868MHZ_CMD_GET_SW_VERSION 0x14
84#define NEOMESH868MHZ_CMD_ALT_MODE 0x20
85
90#define NEOMESH868MHZ_RSP_ACK 0x50
91#define NEOMESH868MHZ_RSP_NACK 0x51
92#define NEOMESH868MHZ_RSP_ACK_HOST 0x52
93#define NEOMESH868MHZ_RSP_ACK_HOST_HAPA 0x53
94#define NEOMESH868MHZ_RSP_NACK_HOST 0x54
95#define NEOMESH868MHZ_RSP_NACK_HOST_HAPA 0x55
96#define NEOMESH868MHZ_RSP_NACK_SEND 0x56
97#define NEOMESH868MHZ_RSP_NACK_DROP 0x57
98#define NEOMESH868MHZ_RSP_NODE_INFO 0x58
99#define NEOMESH868MHZ_RSP_NEIGHBOUR_LIST 0x59
100#define NEOMESH868MHZ_RSP_NETWORK_COMMAND 0x5A
101#define NEOMESH868MHZ_RSP_ROUTE_INFO 0x5C
102#define NEOMESH868MHZ_RSP_WES_STATUS 0x60
103#define NEOMESH868MHZ_RSP_WES_SETUP 0x61
104#define NEOMESH868MHZ_RSP_GET_SW_VERSION 0x64
105#define NEOMESH868MHZ_RSP_ALT_MODE 0x70
106
111#define NEOMESH868MHZ_SAPI_CMD_LOGIN 0x0103u
112#define NEOMESH868MHZ_SAPI_CMD_RESET_LIST_ITERATOR 0x0104u
113#define NEOMESH868MHZ_SAPI_CMD_GET_LIST 0x0105u
114#define NEOMESH868MHZ_SAPI_CMD_GET_SETTING_FLASH 0x0106u
115#define NEOMESH868MHZ_SAPI_CMD_GET_SETTING_RAM 0x0107u
116#define NEOMESH868MHZ_SAPI_CMD_COMMIT_SETTINGS 0x0108u
117#define NEOMESH868MHZ_SAPI_CMD_DISCARD_SETTINGS 0x0109u
118#define NEOMESH868MHZ_SAPI_CMD_SET_SETTING 0x010Au
119#define NEOMESH868MHZ_SAPI_CMD_START_PROTOCOL_STACK 0x0112u
120#define NEOMESH868MHZ_SAPI_CMD_START_BOOTLOADER 0x0113u
121#define NEOMESH868MHZ_SAPI_HEADER 0x3E
122#define NEOMESH868MHZ_SAPI_TRAIL 0x21
123
128#define NEOMESH868MHZ_SAPI_RSP_OK 0x0380u
129#define NEOMESH868MHZ_SAPI_RSP_ERROR 0x0381u
130#define NEOMESH868MHZ_SAPI_RSP_BOOTLOADER_START 0x0382u
131#define NEOMESH868MHZ_SAPI_RSP_PROTOCOL_STACK_START 0x0383u
132#define NEOMESH868MHZ_SAPI_RSP_PROTOCOL_STACK_ERROR 0x0384u
133#define NEOMESH868MHZ_SAPI_RSP_RESET 0x0385u
134#define NEOMESH868MHZ_SAPI_RSP_SETTINGS_LIST_OUTPUT 0x0185u
135#define NEOMESH868MHZ_SAPI_RSP_SETTINGS_VALUE 0x0186u
136
141#define NEOMESH868MHZ_SAPI_LOGIN_PASSWORD_0 0x4C
142#define NEOMESH868MHZ_SAPI_LOGIN_PASSWORD_1 0x76
143#define NEOMESH868MHZ_SAPI_LOGIN_PASSWORD_2 0x6C
144#define NEOMESH868MHZ_SAPI_LOGIN_PASSWORD_3 0x31
145#define NEOMESH868MHZ_SAPI_LOGIN_PASSWORD_4 0x30
146
151#define NEOMESH868MHZ_SAPI_SETTINGS_ID_NODE_ID 0x0A
152
157#define NEOMESH868MHZ_TIMEOUT_MS 20000ul
158
163#define NEOMESH868MHZ_MAX_PAYLOAD_LEN 255
164
170#define NEOMESH868MHZ_TX_DRV_BUFFER_SIZE 300u
171#define NEOMESH868MHZ_RX_DRV_BUFFER_SIZE 300u
172
173 // neomesh868mhz_cmd
174
189#define NEOMESH868MHZ_MAP_MIKROBUS( cfg, mikrobus ) \
190 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
191 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
192 cfg.app = MIKROBUS( mikrobus, MIKROBUS_AN ); \
193 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
194 cfg.wes = MIKROBUS( mikrobus, MIKROBUS_CS ); \
195 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
196 cfg.wup = MIKROBUS( mikrobus, MIKROBUS_INT );
197
198 // neomesh868mhz_map
199 // neomesh868mhz
200
205typedef struct
206{
207 // Output pins
208 digital_out_t rst;
209 digital_out_t wes;
211 // Input pins
212 digital_in_t app;
213 digital_in_t cts;
214 digital_in_t wup;
216 // Modules
217 uart_t uart;
219 // Buffers
220 uint8_t uart_rx_buffer[ NEOMESH868MHZ_RX_DRV_BUFFER_SIZE ];
221 uint8_t uart_tx_buffer[ NEOMESH868MHZ_TX_DRV_BUFFER_SIZE ];
224
229typedef struct
230{
231 // Communication gpio pins
232 pin_name_t rx_pin;
233 pin_name_t tx_pin;
235 // Additional gpio pins
236 pin_name_t app;
237 pin_name_t rst;
238 pin_name_t wes;
239 pin_name_t cts;
240 pin_name_t wup;
242 // Static variable
243 uint32_t baud_rate;
245 uart_data_bits_t data_bit;
246 uart_parity_t parity_bit;
247 uart_stop_bits_t stop_bit;
250
255typedef struct
256{
257 uint8_t cmd;
258 uint8_t len;
259 uint8_t payload[ NEOMESH868MHZ_MAX_PAYLOAD_LEN ];
262
267typedef struct
268{
269 uint16_t cmd;
270 uint8_t len;
271 uint8_t payload[ NEOMESH868MHZ_MAX_PAYLOAD_LEN ];
274
286
303
318
332
347
361
376
386void neomesh868mhz_set_rst_pin ( neomesh868mhz_t *ctx, uint8_t state );
387
397void neomesh868mhz_set_wes_pin ( neomesh868mhz_t *ctx, uint8_t state );
398
408
418
428
429#ifdef __cplusplus
430}
431#endif
432#endif // NEOMESH868MHZ_H
433
434 // neomesh868mhz
435
436// ------------------------------------------------------------------------ END
#define NEOMESH868MHZ_RX_DRV_BUFFER_SIZE
Definition neomesh868mhz.h:171
#define NEOMESH868MHZ_MAX_PAYLOAD_LEN
NeoMesh 868MHz payload length.
Definition neomesh868mhz.h:163
#define NEOMESH868MHZ_TX_DRV_BUFFER_SIZE
NeoMesh 868MHz driver buffer size.
Definition neomesh868mhz.h:170
uint8_t neomesh868mhz_get_cts_pin(neomesh868mhz_t *ctx)
NeoMesh 868MHz get cts pin function.
err_t neomesh868mhz_read_aapi_frame(neomesh868mhz_t *ctx, neomesh868mhz_aapi_frame_t *frame)
NeoMesh 868MHz read aapi frame function.
void neomesh868mhz_cfg_setup(neomesh868mhz_cfg_t *cfg)
NeoMesh 868MHz configuration object setup function.
void neomesh868mhz_set_rst_pin(neomesh868mhz_t *ctx, uint8_t state)
NeoMesh 868MHz set rst pin function.
uint8_t neomesh868mhz_get_app_pin(neomesh868mhz_t *ctx)
NeoMesh 868MHz get app pin function.
err_t neomesh868mhz_init(neomesh868mhz_t *ctx, neomesh868mhz_cfg_t *cfg)
NeoMesh 868MHz initialization function.
err_t neomesh868mhz_read_sapi_frame(neomesh868mhz_t *ctx, neomesh868mhz_sapi_frame_t *frame)
NeoMesh 868MHz read sapi frame function.
void neomesh868mhz_set_wes_pin(neomesh868mhz_t *ctx, uint8_t state)
NeoMesh 868MHz set wes pin function.
err_t neomesh868mhz_send_aapi_frame(neomesh868mhz_t *ctx, neomesh868mhz_aapi_frame_t *frame)
NeoMesh 868MHz send aapi frame function.
err_t neomesh868mhz_send_sapi_frame(neomesh868mhz_t *ctx, neomesh868mhz_sapi_frame_t *frame)
NeoMesh 868MHz send sapi frame function.
uint8_t neomesh868mhz_get_wup_pin(neomesh868mhz_t *ctx)
NeoMesh 868MHz get wup pin function.
neomesh868mhz_return_value_t
NeoMesh 868MHz Click return value data.
Definition neomesh868mhz.h:280
@ NEOMESH868MHZ_ERROR
Definition neomesh868mhz.h:282
@ NEOMESH868MHZ_OK
Definition neomesh868mhz.h:281
@ NEOMESH868MHZ_TIMEOUT
Definition neomesh868mhz.h:283
NeoMesh 868MHz Click data frame object.
Definition neomesh868mhz.h:256
uint8_t cmd
Definition neomesh868mhz.h:257
uint8_t len
Definition neomesh868mhz.h:258
NeoMesh 868MHz Click configuration object.
Definition neomesh868mhz.h:230
uint32_t baud_rate
Definition neomesh868mhz.h:243
pin_name_t wup
Definition neomesh868mhz.h:240
pin_name_t cts
Definition neomesh868mhz.h:239
pin_name_t app
Definition neomesh868mhz.h:236
pin_name_t wes
Definition neomesh868mhz.h:238
bool uart_blocking
Definition neomesh868mhz.h:244
uart_data_bits_t data_bit
Definition neomesh868mhz.h:245
pin_name_t tx_pin
Definition neomesh868mhz.h:233
pin_name_t rx_pin
Definition neomesh868mhz.h:232
uart_stop_bits_t stop_bit
Definition neomesh868mhz.h:247
uart_parity_t parity_bit
Definition neomesh868mhz.h:246
pin_name_t rst
Definition neomesh868mhz.h:237
NeoMesh 868MHz Click data frame object.
Definition neomesh868mhz.h:268
uint8_t len
Definition neomesh868mhz.h:270
uint16_t cmd
Definition neomesh868mhz.h:269
NeoMesh 868MHz Click context object.
Definition neomesh868mhz.h:206
digital_out_t wes
Definition neomesh868mhz.h:209
digital_in_t app
Definition neomesh868mhz.h:212
uart_t uart
Definition neomesh868mhz.h:217
digital_in_t wup
Definition neomesh868mhz.h:214
digital_in_t cts
Definition neomesh868mhz.h:213
digital_out_t rst
Definition neomesh868mhz.h:208