forked from unhuman-io/motorlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusb_communication.h
34 lines (31 loc) · 1.2 KB
/
usb_communication.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
#ifndef UNHUMAN_MOTORLIB_USB_COMMUNICATION_H_
#define UNHUMAN_MOTORLIB_USB_COMMUNICATION_H_
#include "communication.h"
class USBCommunication : public CommunicationBase {
public:
USBCommunication(USB1 &usb) : usb_(usb) {}
int receive_data(ReceiveData * const data) {
return usb_.receive_data(2, (uint8_t *const) data, sizeof(*data));
}
void send_data(const SendData &data) {
usb_.send_data(2, reinterpret_cast<const uint8_t *>(&data), sizeof(SendData), false);
}
int receive_string(char * const string) {
int count = usb_.receive_data(1, (uint8_t * const) string, 64);
string[count] = 0;
return count;
}
bool send_string(const char * const string, uint16_t length) {
usb_.send_data(1, (const uint8_t * const) string,
std::min((uint16_t) MAX_API_DATA_SIZE, length), true);
return true;
}
bool send_string_active() const { return usb_.tx_active(1); }
void cancel_send_string() { usb_.cancel_transfer(1); }
bool new_rx_data() { return usb_.new_rx_data(2); }
bool tx_data_ack() { return usb_.tx_data_ack(2); }
private:
USB1 &usb_;
friend class System;
};
#endif // UNHUMAN_MOTORLIB_USB_COMMUNICATION_H_