This repository has been archived by the owner on Sep 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
longfi.h
167 lines (146 loc) · 4.57 KB
/
longfi.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#ifndef __LONGFI_H__
#define __LONGFI_H__
#ifdef __cplusplus
extern "C"
{
#endif
#include "board.h"
#include "lfc/lfc.h"
#include "radio/radio.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
/*!
* Authentication modes
*/
typedef enum
{
PresharedKey128,
_LongFiAuthModeMax = 0xFFFFFFFF // fore 32-bit value
// TODO: ECDH
} LongFiAuthMode_t;
/*!
* Configure device with necessary network routing information
*/
typedef struct
{
uint32_t oui; // organizations unique identifier
uint16_t device_id; // device identifier within organization
LongFiAuthMode_t auth_mode;
} LongFiConfig_t;
/*!
* Configure
*/
union LongFiAuthCallbacks {
const uint8_t * preshared_key;
// other auth types will have other callbacks
};
/*!
* LongFi handler for library
*/
typedef struct
{
Radio_t * radio; // pointer to struct of SX12XX radio functions
BoardBindings_t *
bindings; // pointer to struct of system bindings, defined in board.h
LongFiConfig_t config;
union LongFiAuthCallbacks auth_cb;
struct lfc lfc;
} LongFi_t;
/*!
* \brief Constructor for LongFi handle
*
* \param [IN] bindings System bindings for radio driver
* \param [IN] radio Handle to radio struct
* \param [IN] config RF Network Configuration
*/
LongFi_t longfi_new_handle(BoardBindings_t * bindings,
Radio_t * radio,
LongFiConfig_t config,
union LongFiAuthCallbacks auth_cb);
/*!
* \brief Run time initialization of library
*
* \param [IN] handle
*/
void longfi_init(LongFi_t * handle);
/*!
* Events to be handle by client
*/
typedef enum ClientEvent_t
{
ClientEvent_None, // this is a non-event, no handling required
ClientEvent_TxDone, // the full transmit is complete (1 or more fragments)
ClientEvent_Rx, // a full packet was received
} ClientEvent_t;
/*!
* \brief Provide ownership of a buffer to the library. Sets maximum transmit and receive
*
* \param [IN] handle
* \param [IN] buffer A pointer to the memory
* \param [IN] buffer_len Size of memory in bytes
*/
void longfi_set_buf(LongFi_t * handle, uint8_t * buffer, size_t buffer_len);
/*!
* \brief Dispatches a packet to the protocol. It is not safe to use this
* function again without waiting for a ClientEvent_TxDone
*
* \param [IN] handle
* \param [IN] buffer A pointer to the memory
* \param [IN] buffer_len Size of memory in bytes
*/
void longfi_send(LongFi_t * handle, const uint8_t * data, size_t len);
/*!
* The structure of a received packet
*/
typedef struct RxPacket_t
{
uint8_t * buf;
size_t len;
int16_t rssi;
int8_t snr;
} RxPacket_t;
/*!
* \brief Gets a downlink packet. This is to be called after a ClientEvent_Rx
*
* \retval RxPacket_t returns a received packet, including ownership
* Give a buffer back to LongFi using longfi_set_buf to send or receive again
*/
RxPacket_t longfi_get_rx();
/*!
* These are system generated events that the client must collect and push
* into longfi_handle_event. All the DIO events are pin interrupts
*/
typedef enum RfEvent_t
{
RFE_DIO0, // TxDone or Rx
RFE_DIO1, // unimplemented
RFE_DIO2, // unimplemented
RFE_DIO3, // unimplemented
RFE_DIO4, // unimplemented
RFE_DIO5, // unimplemented
RFE_Timer1, // unimplemented
RFE_Timer2, // unimplemented
RFE_Timer3 // unimplemented
} RfEvent_t;
/*!
* \brief To be used by client in a low-priorty loop, feeding events into the library
*
* \param [IN] LongFi_t
* \param [IN] RfEvent_t A system generated event
*
* \retval ClientEvent_t should be handled by a client
*/
ClientEvent_t longfi_handle_event(LongFi_t * handle, RfEvent_t rf_event);
/*!
* \brief Continuously sends a byte byte (0xAB) at 910MHz.
* Useful for setting of RF hardware test
*
* \param [IN] LongFi_t
*/
void longfi_rf_test(LongFi_t * handle);
extern const struct Radio_s Radio;
#ifdef __cplusplus
}
#endif
#endif // __LONGFI_H__