-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
app_channel.h
163 lines (150 loc) · 6.41 KB
/
app_channel.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
/*
* || ____ _ __
* +------+ / __ )(_) /_______________ _____ ___
* | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \
* +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
* || || /_____/_/\__/\___/_/ \__,_/ /___/\___/
*
* LPS node firmware.
*
* Copyright 2020, Bitcraze AB
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Foobar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
/* app_channel.h: App realtime communication channel with the ground */
#pragma once
#include <stddef.h>
#include <stdbool.h>
#include "crtp.h"
#define APPCHANNEL_WAIT_FOREVER (-1)
#define APPCHANNEL_MTU (31)
/**
* Send an app-channel packet - deprecated (removed after August 2023). Use appchannelSendDataPacketBlock() instead.
*
* The maximum buffer size that can be sent is define in APPCHANNEL_MTU.
* If the length of the buffer is longer than that, the packet will be cropped
* to send only the APPCHANNEL_MTU first bytes.
*
* This function can block if there is no more space in the Crazyflie TX queue.
* This is very unlikely to happen when CRTP is connected but can happen when the
* connection is not active.
*
* @param data Pointer to the data buffer to be sent
* @param length Length of the data buffer to send
*
* \app_api
*/
void appchannelSendPacket(void* data, size_t length);
/**
* Send an app-channel packet
*
* The maximum buffer size that can be sent is define in APPCHANNEL_MTU.
* If the length of the buffer is longer than that, the packet will be cropped
* to send only the APPCHANNEL_MTU first bytes.
*
* This function can block if there is no more space in the Crazyflie TX queue.
* This is very unlikely to happen when CRTP is connected but can happen when the
* connection is not active.
*
* @param data Pointer to the data buffer to be sent
* @param length Length of the data buffer to send
*
* \app_api
*/
void appchannelSendDataPacketBlock(void* data, size_t length);
/**
* Send an app-channel packet
*
* The maximum buffer size that can be sent is define in APPCHANNEL_MTU.
* If the length of the buffer is longer than that, the packet will be cropped
* to send only the APPCHANNEL_MTU first bytes.
*
* This function is non-blocking and may discard the packet if there is no more
* space in the Crazyflie TX queue. This is very unlikely to happen when CRTP
* is connected but can happen when the connection is not active.
*
* @param data Pointer to the data buffer to be sent
* @param length Length of the data buffer to send
*
* @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
*
* \app_api
*/
int appchannelSendDataPacket(void* data, size_t length);
/**
* Receive an app-channel packet - deprecated (removed after August 2023). Use appchannelReceiveDataPacket() instead
*
* If the data received is longer than max_length, the data will be silently cropped and only
* the fist "max_length" bytes of the packet will be copied in the buffer.
*
* The maximum length packet possible to be received is APPCHANNEL_MTU bytes long.
*
* @param buffer Data buffer where the packet content will be copied
* @param max_length Maximum length of the data to be received, ie. length of the data buffer
* @param timeout_ms Time to wait for a packet in millisecond. A value of 0 will make the
* function non blocking, only reporting a packet is one is already in the
* receive queue. A value of APPCHANNEL_WAIT_FOREVER make the function block
* infinitely until a packet is received.
* @return 0 if no packet has been received. The data length of the packet received.
*/
size_t appchannelReceivePacket(void* buffer, size_t max_length, int timeout_ms);
/**
* Receive an app-channel packet
*
* If the data received is longer than max_length, the data will be silently cropped and only
* the fist "max_length" bytes of the packet will be copied in the buffer.
*
* The maximum length packet possible to be received is APPCHANNEL_MTU bytes long.
*
* @param buffer Data buffer where the packet content will be copied
* @param max_length Maximum length of the data to be received, ie. length of the data buffer
* @param timeout_ms Time to wait for a packet in millisecond. A value of 0 will make the
* function non blocking, only reporting a packet is one is already in the
* receive queue. A value of APPCHANNEL_WAIT_FOREVER make the function block
* infinitely until a packet is received.
* @return 0 if no packet has been received. The data length of the packet received.
*/
size_t appchannelReceiveDataPacket(void* buffer, size_t max_length, int timeout_ms);
/**
* Returns if an overflow has occurred in the receive queue
*
* The app-channel received packets are put in a queue. It is expected that the app is
* regularly calling appchannelReceiveDataPacket() to get the packets from the receive queue.
* If that is not the case, the queue can overflow and this function allows the app to know
* about it. The overflow flag is being reset by this call.
*
* @return true if an overflow has occurred in the receive queue.
*/
bool appchannelHasOverflowOccurred();
/**
* Returns if an overflow has occurred in the receive queue - deprecated (removed after August 2023). Use appchannelHasOverflowOccurred() instead
*
* The app-channel received packets are put in a queue. It is expected that the app is
* regularly calling appchannelReceiveDataPacket() to get the packets from the receive queue.
* If that is not the case, the queue can overflow and this function allows the app to know
* about it. The overflow flag is being reset by this call.
*
* @return true if an overflow has occurred in the receive queue.
*/
bool appchannelHasOverflowOccured();
// Function declared bellow are private to the Crazyflie firmware and
// should not be called from an app
/**
*
*/
void appchannelInit();
/**
*
*/
void appchannelIncomingPacket(CRTPPacket *p);