-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLoRaMESH.h
153 lines (123 loc) · 4.45 KB
/
LoRaMESH.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* ---------------------------------------------------
Radioenge Equipamentos de Telecomunicações
---------------------------------------------------
This library contains a set of functions to configure
and operate the EndDevice LoRaMESH Radioenge
Date: 13/12/18
Ported to ADuCM3029 by Rafael Marinho (github.com/rma6)
& Matheus Souza (github.com/mfbsouza)
*/
#ifndef _LORA_MESH_
#define _LORA_MESH_
#include <stdint.h>
#ifndef UART_H_
#include "uart.h"
#endif
/* ----- Defines ------ */
#define MAX_PAYLOAD_SIZE 232
#define MAX_BUFFER_SIZE 237
/* ----- Default Commands List ----- */
typedef enum
{
CMD_LORAPARAMETER = 0xD6, /* Gets or Sets the LoRa modulation parameters */
CMD_LOCALREAD = 0xE2, /* Gets the ID, NET and UNIQUE ID info from the local device */
CMD_REMOTEREAD = 0xD4, /* Gets the ID, NET and UNIQUE ID info from a remote device */
CMD_WRITECONFIG = 0xCA, /* Writes configuration info to the device, i.e. NET and ID */
CMD_GPIOCONFIG = 0xC2, /* Configures a given GPIO pin to a desired mode, gets or sets its value */
CMD_DIAGNOSIS = 0xE7, /* Gets diagnosis information from the device */
CMD_READNOISE = 0xD8, /* Reads the noise floor on the current channel */
CMD_READRSSI = 0xD5, /* Reads the RSSI between the device and a neighbour */
CMD_TRACEROUTE = 0xD2, /* Traces the hops from the device to the master */
CMD_SENDTRANSP = 0x28 /* Sends a packet to the device's transparent serial port */
} Cmd_Typedef;
/* GPIO Enum */
typedef enum
{
GPIO0,
GPIO1,
GPIO2,
GPIO3,
GPIO4,
GPIO5,
GPIO6,
GPIO7
} GPIO_Typedef;
/* GPIO mode enum */
typedef enum
{
DIGITAL_IN,
DIGITAL_OUT,
ANALOG_IN = 3
} Mode_Typedef;
/* Pull resistor enum */
typedef enum
{
PULL_OFF,
PULLUP,
PULLDOWN
} Pull_Typedef;
typedef enum
{
MESH_OK,
MESH_ERROR
} MeshStatus_Typedef;
/* ----- Public global variables ----- */
/* ----- Public Functions Prototype ----- */
/**
* @brief Prepares a frame to transmission via commands interface
* @param id: Target device's ID
* @param command: Byte that indicates the command
* @param payload: pointer to the array holding the payload
* @param payloadSize: payload size
* @retval MESH_OK or MESH_ERROR
*/
MeshStatus_Typedef PrepareFrameCommand(uint16_t id, uint8_t command, uint8_t* payload, uint8_t payloadSize);
/**
* @brief Prepares a frame to transmission via transparent interface
* @param id: Target device's ID
* @param payload: pointer to the array holding the payload
* @param payloadSize: payload size
* @retval MESH_OK or MESH_ERROR
*/
MeshStatus_Typedef PrepareFrameTransp(uint16_t id, uint8_t* payload, uint8_t payloadSize);
/**
* @brief Sends a frame previously prepared by PrepareFrame
* @param None
* @retval MESH_OK or MESH_ERROR
*/
MeshStatus_Typedef SendPacket();
/**
* @brief Receives a packet from the commands interface
* @param id[out]: ID from the received message
* @param command[out]: received command
* @param payload[out]: buffer where the received payload will be copied to
* @param payloadSize[out]: received payload size
* @param timeout: reception timeout, in ms
* @retval MESH_OK or MESH_ERROR
*/
MeshStatus_Typedef ReceivePacketCommand(uint16_t* id, uint8_t* command, uint8_t* payload, uint8_t* payloadSize, uint32_t timeout);
/**
* @brief Receives a packet from the transparent interface
* @param id[out]: ID from the received message
* @param payload[out]: buffer where the received payload will be copied to
* @param payloadSize[out]: received payload size
* @param timeout: reception timeout, in ms
* @retval MESH_OK or MESH_ERROR
*/
MeshStatus_Typedef ReceivePacketTransp(uint16_t* id, uint8_t* payload, uint8_t* payloadSize, uint32_t timeout);
/**
* @brief Gets the ID, NET and UNIQUE ID info from the local device
* @param id[out]: Local device's id
* @param net[out]: Configured NET on local device
* @param uniqueId[out]: Device Unique ID
* @retval MESH_OK or MESH_ERROR
*/
MeshStatus_Typedef LocalRead(uint16_t* id, uint16_t* net, uint32_t* uniqueId);
/**
* @brief Computes CRC16.
* @param data_in: Pointer to the input buffer.
* @param length: Buffer size
* @retval CRC16
*/
uint16_t ComputeCRC(uint8_t* data_in, uint16_t length);
#endif