2#ifdef INNOMAKERUSB2CANLIB_EXPORTS
3#define INNOMAKERUSB2CANLIB_EXP __declspec(dllexport)
5#define INNOMAKERUSB2CANLIB_EXP __declspec(dllimport)
17class INNOMAKERUSB2CANLIB_EXP InnoMakerUsb2CanLib {
20 class InnoMakerDevice {
22 libusb_device_handle *devHandle;
23 libusb_device *device;
27 struct innomaker_host_frame
39 struct Innomaker_device_bittming
55 class innomaker_tx_context
62 std::atomic<bool> flag = ATOMIC_VAR_INIT(
false);
64 spin_mutex() =
default;
65 spin_mutex(
const spin_mutex&) =
delete;
66 spin_mutex& operator= (
const spin_mutex&) =
delete;
68 bool expected =
false;
69 while (!flag.compare_exchange_strong(expected,
true))
81 spin_mutex tx_ctx_lock;
82 innomaker_tx_context tx_context[10];
87 struct innomaker_identify_mode
93 struct innomaker_device_mode
101 struct UsbSetupPacket
111 static int LIBUSB_CALL hotplug_callback(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event,
void *user_data);
112 static int LIBUSB_CALL hotplug_callback_detach(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event,
void *user_data);
123 bool scanInnoMakerDevice();
126 int getInnoMakerDeviceCount();
129 InnoMakerDevice* getInnoMakerDevice(
int devIndex);
132 bool openInnoMakerDevice(InnoMakerDevice *device);
135 bool closeInnoMakerDevice(InnoMakerDevice *device);
138 bool sendInnoMakerDeviceBuf(InnoMakerDevice *device, BYTE *buf,
int size,
unsigned int timeout);
141 bool recvInnoMakerDeviceBuf(InnoMakerDevice *device, BYTE *buf,
int size,
unsigned int timeout);
144 bool urbResetDevice(InnoMakerDevice *device);
147 bool urbSetupDevice(InnoMakerDevice *device, UsbCanMode canMode, Innomaker_device_bittming bittming);
149 InnoMakerUsb2CanLib() {
150 innoMakerDevices =
new vector<InnoMakerDevice>();
153 ~InnoMakerUsb2CanLib() {
154 delete(innoMakerDevices);
158 innomaker_tx_context *innomaker_alloc_tx_context(innomaker_can *dev);
163 void innomaker_free_tx_context(innomaker_tx_context *txc);
168 innomaker_tx_context *innomaker_get_tx_context(innomaker_can *dev, UINT
id);
172 bool urbSetHostFormat(InnoMakerDevice *device);
174 bool urbSetBitrate(InnoMakerDevice *device, Innomaker_device_bittming bittming);
176 bool urbStartDevice(InnoMakerDevice *device, UsbCanMode mode);
180 vector<InnoMakerDevice> *innoMakerDevices;
184 int endPointIn = 129;
186 libusb_hotplug_callback_handle hp[2];
191 libusb_device **devs;
194 void(*addCallback)(InnoMakerDevice *device);
196 void(*removeCallback)(InnoMakerDevice *device);
198 int innomaker_MAX_TX_URBS = 10;