|
|
@ -142,6 +142,15 @@ void *safety_setter_thread(void *s) { |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void usb_close(libusb_device_handle* &dev_handle) { |
|
|
|
|
|
|
|
if (!dev_handle) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
libusb_release_interface(dev_handle, 0); |
|
|
|
|
|
|
|
libusb_close(dev_handle); |
|
|
|
|
|
|
|
dev_handle = NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// must be called before threads or with mutex
|
|
|
|
// must be called before threads or with mutex
|
|
|
|
bool usb_connect() { |
|
|
|
bool usb_connect() { |
|
|
|
int err, err2; |
|
|
|
int err, err2; |
|
|
@ -154,10 +163,7 @@ bool usb_connect() { |
|
|
|
|
|
|
|
|
|
|
|
ignition_last = false; |
|
|
|
ignition_last = false; |
|
|
|
|
|
|
|
|
|
|
|
if (dev_handle != NULL){ |
|
|
|
usb_close(dev_handle); |
|
|
|
libusb_close(dev_handle); |
|
|
|
|
|
|
|
dev_handle = NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dev_handle = libusb_open_device_with_vid_pid(ctx, 0xbbaa, 0xddcc); |
|
|
|
dev_handle = libusb_open_device_with_vid_pid(ctx, 0xbbaa, 0xddcc); |
|
|
|
if (dev_handle == NULL) { goto fail; } |
|
|
|
if (dev_handle == NULL) { goto fail; } |
|
|
@ -931,7 +937,6 @@ int main() { |
|
|
|
assert(err == 0); |
|
|
|
assert(err == 0); |
|
|
|
|
|
|
|
|
|
|
|
// join threads
|
|
|
|
// join threads
|
|
|
|
|
|
|
|
|
|
|
|
err = pthread_join(can_recv_thread_handle, NULL); |
|
|
|
err = pthread_join(can_recv_thread_handle, NULL); |
|
|
|
assert(err == 0); |
|
|
|
assert(err == 0); |
|
|
|
|
|
|
|
|
|
|
@ -941,10 +946,7 @@ int main() { |
|
|
|
err = pthread_join(can_health_thread_handle, NULL); |
|
|
|
err = pthread_join(can_health_thread_handle, NULL); |
|
|
|
assert(err == 0); |
|
|
|
assert(err == 0); |
|
|
|
|
|
|
|
|
|
|
|
//while (!do_exit) usleep(1000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// destruct libusb
|
|
|
|
// destruct libusb
|
|
|
|
|
|
|
|
usb_close(dev_handle); |
|
|
|
libusb_close(dev_handle); |
|
|
|
|
|
|
|
libusb_exit(ctx); |
|
|
|
libusb_exit(ctx); |
|
|
|
} |
|
|
|
} |
|
|
|