RUI3 (RAK Unified Interface 3) - RAK4631
service_lora_p2p.h
Go to the documentation of this file.
1 
9 #ifndef __SERVICE_LORA_P2P_H__
10 #define __SERVICE_LORA_P2P_H__
11 
12 #ifdef SUPPORT_LORA
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 #include <stdint.h>
19 #include <stdbool.h>
20 #include "pin_define.h"
21 
22 
23 //#define P2P_DEBUG_ENABLE
24 #ifdef P2P_DEBUG_ENABLE
25 #define LORA_P2P_DEBUG(fmt, args...) udrv_serial_log_printf(fmt, ##args)
26 #else
27 #define LORA_P2P_DEBUG(fmt, args...)
28 #endif
29 
30 
31 #define LORA_SYMBOL_TIMEOUT 5 /* Symbols */
32 #define LORA_FIX_LENGTH_PAYLOAD_ON false
33 #define LORA_IQ_INVERSION_ON false
34 
35 #define LORA_BUFFER_SIZE 255 /* Define the payload size here */
36 
40 typedef enum
41 {
42  LORA_MAC_PRIVATE_SYNCWORD = 0x1424, // Syncword for Private LoRa networks
43  LORA_MAC_PUBLIC_SYNCWORD = 0x3444 // Syncword for Public LoRa networks
45 
48 #ifdef rak4200
49  #define LORA_CHIP_SX1276
50 #elif defined rak4630
51  #define LORA_CHIP_SX126X
52 #elif defined rak11720
53  #define LORA_CHIP_SX126X
54 #elif defined rak3172 \
55  || defined rak3172-sip \
56  || defined rak3172T
57  #define LORA_CHIP_STM32WLE5XX
58 #endif
59 
60 #ifdef LORA_CHIP_SX1276
61  #define SYMBTIMEOUT_MAX 1023
62 #elif defined LORA_CHIP_SX126X
63  #define SYMBTIMEOUT_MAX 248
64 #elif defined LORA_CHIP_STM32WLE5XX
65  #define SYMBTIMEOUT_MAX 248
66 #else
67  #define SYMBTIMEOUT_MAX 0
68 #endif
69 
70 // #ifdef sx1276
71 // #define SYMBTIMEOUT_MAX 1023
72 // #elif defined sx126x
73 // #define SYMBTIMEOUT_MAX 248
74 // #elif defined stm32wle5xx
75 // #define SYMBTIMEOUT_MAX 248
76 // #else
77 // #define SYMBTIMEOUT_MAX 0
78 // #endif
79 
80 typedef struct {
81  bool isRxCancel;
83  bool isContinue;
86  volatile bool isCAD;
88 
89 typedef struct rui_lora_p2p_revc
90 {
94  uint8_t *Buffer;
98  uint8_t BufferSize;
99 
103  int16_t Rssi;
107  int8_t Snr;
109 
110 typedef void(*service_lora_p2p_send_cb_type)(void);
113 
114 int32_t service_lora_p2p_init(void);
115 
116 int32_t service_lora_p2p_config(void);
117 
118 int32_t service_lora_p2p_send(uint8_t *p_data, uint8_t len, bool cad_enable);
119 
120 int32_t service_lora_p2p_recv(uint32_t timeout);
121 
122 uint32_t service_lora_p2p_get_freq (void);;
123 
124 int32_t service_lora_p2p_set_freq (uint32_t freq);
125 
126 int32_t service_lora_p2p_check_runtime_freq(uint32_t freq);
127 
128 uint8_t service_lora_p2p_get_sf (void);
129 
130 int32_t service_lora_p2p_set_sf (uint8_t spreadfact);
131 
132 int32_t service_lora_p2p_check_runtime_sf(uint8_t spreadfact);
133 
134 uint32_t service_lora_p2p_get_bandwidth (void);
135 
136 int32_t service_lora_p2p_set_bandwidth (uint32_t bandwidth);
137 
138 int32_t service_lora_p2p_check_runtime_bandwidth(uint32_t bandwidth);
139 
140 uint8_t service_lora_p2p_get_codingrate (void);
141 
142 int32_t service_lora_p2p_set_codingrate (uint8_t codingrate);
143 
144 int32_t service_lora_p2p_check_runtime_codingrate(uint8_t codingrate);
145 
146 uint16_t service_lora_p2p_get_preamlen (void);
147 
148 int32_t service_lora_p2p_set_preamlen (uint16_t preamlen);
149 
150 int32_t service_lora_p2p_check_runtime_preamlen(uint16_t preamlen);
151 
152 uint8_t service_lora_p2p_get_powerdbm (void);
153 
154 int32_t service_lora_p2p_set_powerdbm (uint8_t powerdbm);
155 
156 int32_t service_lora_p2p_check_runtime_powerdbm(uint8_t powerdbm);
157 
159 
160 int32_t service_lora_p2p_set_crypto_enable(bool enable);
161 
162 int32_t service_lora_p2p_get_crypto_key (uint8_t *buff, uint32_t len);
163 
164 int32_t service_lora_p2p_set_crypto_key (uint8_t *buff, uint32_t len);
165 
166 int32_t service_lora_p2p_get_crypto_IV (uint8_t *buff, uint32_t len);
167 
168 int32_t service_lora_p2p_set_crypto_IV (uint8_t *buff, uint32_t len);
169 
170 uint32_t service_lora_p2p_get_fdev(void);
171 
172 int32_t service_lora_p2p_set_fdev(uint32_t fdev);
173 
174 uint32_t service_lora_p2p_get_bitrate(void);
175 
176 int32_t service_lora_p2p_set_bitrate(uint32_t bitrate);
177 
178 int32_t service_lora_p2p_encrpty(uint8_t *indata, uint16_t inlen,uint8_t *outdata );
179 
180 int32_t service_lora_p2p_decrpty(uint8_t *indata,uint16_t inlen ,uint8_t *outdata );
181 
183 
185 
187 
189 
190 int32_t service_lora_p2p_set_public_network(bool enable);
191 
193 
194 int32_t service_lora_p2p_set_symbol_timeout(uint32_t symbol_timeout);
195 
197 
198 int32_t service_lora_p2p_set_iqinverted(bool iqinverted);
199 
201 
202 int32_t service_lora_p2p_set_fix_length_payload(bool enable);
203 
204 uint16_t service_lora_p2p_get_syncword(void);
205 
206 int32_t service_lora_p2p_set_syncword( uint16_t syncword );
207 
208 bool service_lora_p2p_get_CAD(void);
209 
210 int32_t service_lora_p2p_set_CAD(bool enable);
211 
213 
214 
215 #ifdef __cplusplus
216 }
217 #endif
218 
219 #endif // end SUPPORT_LORA
220 
221 #endif // __SERVICE_LORA_P2P_H__
222 
int32_t service_lora_p2p_set_bandwidth(uint32_t bandwidth)
uint32_t service_lora_p2p_get_bandwidth(void)
int32_t service_lora_p2p_recv(uint32_t timeout)
bool isRxCancel
Definition: service_lora_p2p.h:81
int32_t service_lora_p2p_check_runtime_sf(uint8_t spreadfact)
bool service_lora_p2p_get_fix_length_payload(void)
int8_t Snr
Definition: service_lora_p2p.h:107
int32_t service_lora_p2p_set_sf(uint8_t spreadfact)
int32_t service_lora_p2p_set_freq(uint32_t freq)
uint32_t service_lora_p2p_get_bitrate(void)
bool isRadioBusy
Definition: service_lora_p2p.h:82
int32_t service_lora_p2p_register_send_CAD_cb(service_lora_p2p_send_CAD_cb_type callback)
int32_t service_lora_p2p_get_crypto_IV(uint8_t *buff, uint32_t len)
int32_t service_lora_p2p_set_symbol_timeout(uint32_t symbol_timeout)
bool isContinue
Definition: service_lora_p2p.h:83
Definition: service_lora_p2p.h:43
uint8_t service_lora_p2p_get_powerdbm(void)
bool isContinue_compatible_tx
Definition: service_lora_p2p.h:85
int32_t service_lora_p2p_check_runtime_codingrate(uint8_t codingrate)
int32_t service_lora_p2p_set_bitrate(uint32_t bitrate)
Definition: service_lora_p2p.h:80
int32_t service_lora_p2p_send(uint8_t *p_data, uint8_t len, bool cad_enable)
int32_t service_lora_p2p_init(void)
uint8_t * Buffer
Definition: service_lora_p2p.h:94
bool service_lora_p2p_get_public_network(void)
bool service_lora_p2p_get_CAD(void)
uint8_t service_lora_p2p_get_sf(void)
volatile bool isCAD
Definition: service_lora_p2p.h:86
int32_t service_lora_p2p_set_crypto_IV(uint8_t *buff, uint32_t len)
uint8_t BufferSize
Definition: service_lora_p2p.h:98
int32_t service_lora_p2p_check_runtime_bandwidth(uint32_t bandwidth)
int32_t service_lora_p2p_encrpty(uint8_t *indata, uint16_t inlen, uint8_t *outdata)
void(* service_lora_p2p_send_cb_type)(void)
Definition: service_lora_p2p.h:110
int32_t service_lora_p2p_set_iqinverted(bool iqinverted)
int32_t service_lora_p2p_set_syncword(uint16_t syncword)
uint8_t service_lora_p2p_get_codingrate(void)
int32_t service_lora_p2p_set_preamlen(uint16_t preamlen)
int32_t service_lora_p2p_register_recv_cb(service_lora_p2p_recv_cb_type callback)
int32_t service_lora_p2p_config(void)
uint32_t service_lora_p2p_get_fdev(void)
int32_t service_lora_p2p_set_codingrate(uint8_t codingrate)
int32_t service_lora_p2p_set_fix_length_payload(bool enable)
int32_t service_lora_p2p_check_runtime_powerdbm(uint8_t powerdbm)
bool service_lora_p2p_get_iqinverted(void)
int32_t service_lora_p2p_register_send_cb(service_lora_p2p_send_cb_type callback)
void(* service_lora_p2p_send_CAD_cb_type)(bool)
Definition: service_lora_p2p.h:112
int32_t service_lora_p2p_set_crypto_key(uint8_t *buff, uint32_t len)
int32_t service_lora_p2p_check_runtime_preamlen(uint16_t preamlen)
int32_t service_lora_p2p_set_powerdbm(uint8_t powerdbm)
int32_t service_lora_p2p_check_runtime_freq(uint32_t freq)
int16_t Rssi
Definition: service_lora_p2p.h:103
void(* service_lora_p2p_recv_cb_type)(rui_lora_p2p_recv_t recv_data_pkg)
Definition: service_lora_p2p.h:111
int32_t service_lora_p2p_get_crypto_key(uint8_t *buff, uint32_t len)
uint16_t service_lora_p2p_get_syncword(void)
RAK_LORA_P2P_SYNCWORD
Definition: service_lora_p2p.h:40
int32_t service_lora_p2p_set_CAD(bool enable)
bool service_lora_p2p_get_crypto_enable(void)
int32_t service_lora_p2p_decrpty(uint8_t *indata, uint16_t inlen, uint8_t *outdata)
uint32_t service_lora_p2p_get_freq(void)
int32_t service_lora_p2p_set_public_network(bool enable)
int32_t service_lora_p2p_set_crypto_enable(bool enable)
bool isContinue_no_exit
Definition: service_lora_p2p.h:84
int32_t service_lora_p2p_set_fdev(uint32_t fdev)
Definition: service_lora_p2p.h:42
uint32_t service_lora_p2p_get_symbol_timeout(void)
struct rui_lora_p2p_revc rui_lora_p2p_recv_t
uint16_t service_lora_p2p_get_preamlen(void)
bool service_lora_p2p_get_radio_stat(void)
Definition: service_lora_p2p.h:89