72 CanUsb::CanUsb(
lusb::UsbDevice *dev) : ready_(false), heap_dev_(false), dev_(dev), recv_callback_(NULL), version_major_(0), version_minor_(0), version_build_(0), version_comms_(0), serial_number_(0), num_channels_(0)
123 std::vector<lusb::UsbDevice::Location> list;
125 for (
size_t i = 0; i < list.size(); i++) {
165 int len =
readConfig(&packet,
sizeof(packet));
184 int len =
readConfig(&packet,
sizeof(packet));
197 while (size >= (
int)
sizeof(*ptr)) {
198 size -=
sizeof(*ptr);
199 recv_callback_(ptr->channel, ptr->id, ptr->extended, ptr->dlc, ptr->data);
233 packet.
bus_cfg.channel = channel;
234 packet.
bus_cfg.bitrate = bitrate;
249 packet.
filter.channel = channel;
250 packet.
filter.mask = mask;
251 packet.
filter.match = match;
255 if (packet.
filter.success) {
264 std::vector<uint8_t> &rx_errors, std::vector<uint8_t> &tx_errors,
bool)
273 rx_drops.resize(size);
274 tx_drops.resize(size);
275 rx_errors.resize(size);
276 tx_errors.resize(size);
277 for (
unsigned int i = 0; i < size; i++) {
278 rx_drops[i] = packet.
stats.rx_drops[i];
279 tx_drops[i] = packet.
stats.tx_drops[i];
280 rx_errors[i] = packet.
stats.rx_errors[i];
281 tx_errors[i] = packet.
stats.tx_errors[i];
294 int len =
readConfig(&packet,
sizeof(packet));
296 timestamp = packet.
time.stamp;
303 void CanUsb::sendMessage(
unsigned int channel, uint32_t
id,
bool extended, uint8_t dlc,
const uint8_t data[8],
bool flush)
306 msg.headerWord[0] = 0;
307 msg.headerWord[1] = 0;
309 msg.extended = extended ? 1 : 0;
310 msg.channel = channel;
312 memcpy(msg.data, data, 8);
bool match(const MacAddr &other) const
struct PACK_ATTRIB::PACK_ATTRIB bus_cfg
#define CONFIGURATION_ENDPOINT
const MessageBuffer & back() const
std::string version() const
void stopBulkReadThread(unsigned char endpoint)
void sendMessage(unsigned int channel, uint32_t id, bool extended, uint8_t dlc, const uint8_t data[8], bool flush=true)
int readConfig(void *data, int size)
struct PACK_ATTRIB::PACK_ATTRIB stats
int bulkRead(void *data, int size, unsigned char endpoint, int timeout)
struct PACK_ATTRIB::PACK_ATTRIB num_channels
bool getTimeStamp(uint32_t ×tamp)
unsigned int num_channels_
bool writeConfig(const void *data, int size)
struct PACK_ATTRIB::PACK_ATTRIB time
static const int USB_DEFAULT_TIMEOUT
bool open(const Location &location=Location())
bool getStats(std::vector< uint32_t > &rx_drops, std::vector< uint32_t > &tx_drops, std::vector< uint8_t > &rx_errors, std::vector< uint8_t > &tx_errors, bool clear=false)
void recvStream(const void *data, int size)
const MessageBuffer & front() const
bool open(const std::string &mac=std::string())
struct PACK_ATTRIB::PACK_ATTRIB version
bool writeStream(const void *data, int size)
static const unsigned int MAX_CHANNELS
int readStream(void *data, int size)
struct PACK_ATTRIB StreamPacket
void startBulkReadThread(Callback callback, unsigned char endpoint)
bool addFilter(unsigned int channel, uint32_t mask, uint32_t match)
std::queue< MessageBuffer > queue_
bool bulkWrite(const void *data, int size, unsigned char endpoint, int timeout)
union PACK_ATTRIB MessageBuffer
bool configure(const std::string &mac=std::string())
struct PACK_ATTRIB::PACK_ATTRIB filter
void listDevices(std::vector< Location > &list) const
bool setBitrate(unsigned int channel, uint32_t bitrate, uint8_t mode=0)
bool push(const MessageBuffer &__x)