1 #include "Crazyradio.h" 6 #include <libusb-1.0/libusb.h> 28 , m_datarate(Datarate_250KPS)
32 setDatarate(Datarate_2MPS);
34 setContCarrier(
false);
35 setAddress(0xE7E7E7E7E7);
60 a[4] = (address >> 0) & 0xFF;
61 a[3] = (address >> 8) & 0xFF;
62 a[2] = (address >> 16) & 0xFF;
63 a[1] = (address >> 24) & 0xFF;
64 a[0] = (address >> 32) & 0xFF;
69 libusb_control_transfer(
71 LIBUSB_REQUEST_TYPE_VENDOR,
110 int t = (us / 250) - 1;
148 throw std::runtime_error(
"No valid device handle!");
156 status = libusb_bulk_transfer(
158 (0x01 | LIBUSB_ENDPOINT_OUT),
166 if (status != LIBUSB_SUCCESS) {
167 throw std::runtime_error(libusb_error_name(status));
169 if (
length != (uint32_t)transferred) {
170 std::stringstream sstr;
171 sstr <<
"Did transfer " << transferred <<
" but " <<
length <<
" was requested!";
172 throw std::runtime_error(sstr.str());
176 status = libusb_bulk_transfer(
178 (0x81 | LIBUSB_ENDPOINT_IN),
179 (
unsigned char*)&result,
183 if (status == LIBUSB_ERROR_TIMEOUT) {
186 if (status != LIBUSB_SUCCESS) {
187 throw std::runtime_error(libusb_error_name(status));
190 result.size = transferred - 1;
205 throw std::runtime_error(
"No valid device handle!");
213 status = libusb_bulk_transfer(
215 (0x01 | LIBUSB_ENDPOINT_OUT),
223 if (status != LIBUSB_SUCCESS) {
224 throw std::runtime_error(libusb_error_name(status));
226 if (length != (uint32_t)transferred) {
227 std::stringstream sstr;
228 sstr <<
"Did transfer " << transferred <<
" but " << length <<
" was requested!";
229 throw std::runtime_error(sstr.str());
235 uint32_t totalLength)
241 throw std::runtime_error(
"No valid device handle!");
249 status = libusb_bulk_transfer(
251 (0x01 | LIBUSB_ENDPOINT_OUT),
259 if (status != LIBUSB_SUCCESS) {
260 throw std::runtime_error(libusb_error_name(status));
262 if (totalLength != (uint32_t)transferred) {
263 std::stringstream sstr;
264 sstr <<
"Did transfer " << transferred <<
" but " << totalLength <<
" was requested!";
265 throw std::runtime_error(sstr.str());
void setArdTime(uint8_t us)
static uint32_t numDevices(uint16_t idVendor, uint16_t idProduct)
void sendVendorSetup(uint8_t request, uint16_t value, uint16_t index, const unsigned char *data, uint16_t length)
void setAckEnable(bool enable)
void setPower(Power power)
virtual void sendPacket(const uint8_t *data, uint32_t length, ITransport::Ack &result)
void logPacket(const uint8_t *data, uint32_t length)
Crazyradio(uint32_t devid)
void setAddress(uint64_t address)
void setContCarrier(bool active)
virtual void sendPacketNoAck(const uint8_t *data, uint32_t length)
void setArdBytes(uint8_t nbytes)
void setDatarate(Datarate datarate)
void logAck(const Ack &ack)
static uint32_t numDevices()
virtual void send2PacketsNoAck(const uint8_t *data, uint32_t totalLength)
libusb_device_handle * m_handle
void setChannel(uint8_t channel)