64
55
/*! \brief Communication class to connect to and communicate via the
65
56
CrazyRadio USB dongle.
67
58
The class is capable of finding the CrazyRadio USB dongle on the
68
59
host computer, open and maintain a connection, and send/receive
69
60
data when communicating with the Crazyflie Nano copter using the
74
65
/*! \brief The radio URI as supplied when initializing the class
76
string m_strRadioIdentifier;
67
std::string m_strRadioIdentifier;
77
68
/*! \brief The current USB context as supplied by libusb */
78
69
libusb_context *m_ctxContext;
79
70
libusb_device *m_devDevice;
80
71
libusb_device_handle *m_hndlDevice;
74
std::string m_strDataRate;
86
77
enum Power m_enumPower;
88
79
int m_bContCarrier;
89
80
float m_fDeviceVersion;
90
81
bool m_bAckReceived;
91
list<CCRTPPacket*> m_lstLoggingPackets;
82
std::list<CCRTPPacket*> m_lstLoggingPackets;
94
list<libusb_device*> listDevices(int nVendorID, int nProductID);
85
std::list<libusb_device*> listDevices(int nVendorID, int nProductID);
95
86
bool openUSBDongle();
96
87
bool claimInterface(int nInterface);
97
88
void closeDevice();
99
90
CCRTPPacket *readACK();
101
92
CCRTPPacket *writeData(void *vdData, int nLength);
102
93
bool writeControl(void *vdData, int nLength, uint8_t u8Request, uint16_t u16Value, uint16_t u16Index);
103
94
bool readData(void *vdData, int &nMaxLength);
105
96
void setARC(int nARC);
106
97
void setChannel(int nChannel);
107
void setDataRate(string strDataRate);
98
void setDataRate(std::string strDataRate);
108
99
void setARDBytes(int nARDBytes);
109
100
void setARDTime(int nARDTime);
110
101
void setAddress(char *cAddress);
114
105
/*! \brief Constructor for the radio communication class
116
107
\param strRadioIdentifier URI for the radio to be opened,
117
108
e.g. "radio://<dongle-no>/<channel-no>/<datarate>". */
118
CCrazyRadio(string strRadioIdentifier);
109
CCrazyRadio(std::string strRadioIdentifier);
119
110
/*! \brief Destructor for the radio communication class */
122
113
/*! \brief Function to start the radio communication
124
115
The first available USB dongle will be opened and claimed for
125
116
communication. The connection will be maintained and used to
126
117
communicate with a Crazyflie Nano quadcopter in range.
129
120
made and 'false' if no dongle could be found (or any other
130
121
USB-related error came up - this is not handled here). */
131
122
bool startRadio();
133
124
/*! \brief Returns the current setting for power usage by the USB
136
127
\return Value denoting the current power settings reserved for
138
129
enum Power power();
139
130
/*! \brief Set the power level to be used for communication purposes
141
132
\param enumPower The level of power that is being used for
142
133
communication. The integer value maps to one of the entries of the
144
135
void setPower(enum Power enumPower);
146
137
/*! \brief Sends the given packet's payload to the copter
148
139
\param crtpSend The packet which supplied header and payload
149
140
information to send to the copter */
150
141
CCRTPPacket *sendPacket(CCRTPPacket *crtpSend, bool bDeleteAfterwards = false);
152
143
/*! \brief Sends the given packet and waits for a reply.
154
145
Internally, this function calls the more elaborate
155
146
sendAndReceive() function supplying parameters for retrying and
156
147
waiting. Convenience function signature.
158
149
\param crtpSend Packet to send
159
150
\param bDeleteAfterwards Whether or not the packet to send is
160
151
deleted internally after sending it
162
153
\return Packet containing the reply or NULL if no reply was
163
154
received (after retrying). */
164
155
CCRTPPacket *sendAndReceive(CCRTPPacket *crtpSend, bool bDeleteAfterwards = false);
166
157
/*! \brief Sends the given packet and waits for a reply.
168
159
Sends out the CCRTPPacket instance denoted by crtpSend on the
169
160
given port and channel. Retries a number of times and waits
170
161
between each retry whether or not an answer was received (in this
171
162
case, dummy packets are sent in order to receive replies).
173
164
\param crtpSend Packet to send
175
166
\param nPort Port number on which to send this packet (and where
176
167
to wait for the reply)
177
168
\param nChannel Channel number on which to send this packet (and
181
172
\param nRetries Number of retries (re-sending) before giving up on
183
174
\param nMicrosecondsWait Microseconds to wait between two re-sends
185
176
\return Packet containing the reply or NULL if no reply was
186
177
received (after retrying). */
187
178
CCRTPPacket *sendAndReceive(CCRTPPacket *crtpSend, int nPort, int nChannel, bool bDeleteAfterwards = true, int nRetries = 10, int nMicrosecondsWait = 100);
189
180
/*! \brief Sends out an empty dummy packet
191
182
Only contains the payload `0xff`, as used for empty packet
192
183
requests. Mostly used for waiting or keepalive.
194
185
\return Boolean value denoting whether sending the dummy packet
195
186
worked or not. */
196
187
bool sendDummyPacket();
198
189
/*! \brief Waits for the next non-empty packet.
200
191
Sends out dummy packets until a reply is non-empty and then
201
192
returns this reply.
203
194
\return Packet contaning a non-empty reply. */
204
195
CCRTPPacket *waitForPacket();
206
197
/*! \brief Whether or not the copter is answering sent packets.
208
199
Returns whether the copter is actually answering sent packets with
209
200
a set ACK flag. If this is not the case, it is either switched off
212
203
\return Returns true if the copter is returning the ACK flag properly, false otherwise. */
213
204
bool ackReceived();
214
205
/*! \brief Whether or not the USB connection is still operational.
216
207
Checks if the USB read/write calls yielded any errors.
218
209
\return Returns true if the connection is working properly and
219
210
false otherwise. */
222
213
/*! \brief Extracting all logging related packets
224
215
Returns a list of all collected logging related (i.e. originating
225
216
from port 5) packets. This is called by the CCrazyflie class
226
217
automatically when performing cycle().
228
219
\return List of CCRTPPacket instances collected from port 5
230
list<CCRTPPacket*> popLoggingPackets();
221
std::list<CCRTPPacket*> popLoggingPackets();