diff --git a/Matlab_Octave_API/___librador/librador/usbcallhandler.cpp b/Matlab_Octave_API/___librador/librador/usbcallhandler.cpp index 17acb3e5..f59aa917 100644 --- a/Matlab_Octave_API/___librador/librador/usbcallhandler.cpp +++ b/Matlab_Octave_API/___librador/librador/usbcallhandler.cpp @@ -1,10 +1,48 @@ #include "usbcallhandler.h" #include +static void LIBUSB_CALL isoCallback(struct libusb_transfer * transfer){ + + //Thread mutex?? + + if(transfer->status!=LIBUSB_TRANSFER_CANCELLED){ + printf("Copy the data...\n"); + + printf("Re-arm the endpoint...\n"); + int error = libusb_submit_transfer(transfer); + if(error){ + printf("Error re-arming the endpoint!\n"); + } + } + return; +} + +void usb_polling_function(libusb_context *ctx){ + printf("usb_polling_function thread spawned\n"); + struct timeval tv; + tv.tv_sec = 2; + tv.tv_usec = 0; + while(1){ + printf("usb_polling_function begin loop\n"); + if(libusb_event_handling_ok(ctx)){ + libusb_handle_events_timeout(ctx, &tv); + } + } +} + usbCallHandler::usbCallHandler(unsigned short VID_in, unsigned short PID_in) { VID = VID_in; PID = PID_in; + + for(int k=0; k + +#define NUM_ISO_ENDPOINTS 1 +#define NUM_FUTURE_CTX 4 +#define ISO_PACKET_SIZE 750 +#define ISO_PACKETS_PER_CTX 33 //EVERYTHING MUST BE SENT ONE BYTE AT A TIME, HIGH AND LOW BYTES SEPARATE, IN ORDER TO AVOID ISSUES WITH ENDIANNESS. typedef struct uds{ @@ -31,6 +37,7 @@ class usbCallHandler { public: usbCallHandler(unsigned short VID_in, unsigned short PID_in); + ~usbCallHandler(); int setup_usb_control(); int setup_usb_iso(); int send_control_transfer(uint8_t RequestType, uint8_t Request, uint16_t Value, uint16_t Index, uint16_t Length, unsigned char *LDATA); @@ -41,6 +48,12 @@ private: libusb_context *ctx = NULL; libusb_device_handle *handle = NULL; unsigned char inBuffer[256]; + + //USBIso Vars + unsigned char pipeID[NUM_ISO_ENDPOINTS]; + libusb_transfer *isoCtx[NUM_ISO_ENDPOINTS][NUM_FUTURE_CTX]; + unsigned char dataBuffer[NUM_ISO_ENDPOINTS][NUM_FUTURE_CTX][ISO_PACKET_SIZE*ISO_PACKETS_PER_CTX]; + std::thread *usb_polling_thread; }; #endif // USBCALLHANDLER_H