31 #include <libusb-1.0/libusb.h> 36 #include "mogi/thread.h" 37 #include "pandadefinitions.h" 39 #define TIMEOUT (0) // For libusb, in ms 40 #define NUM_CAN_PACKETS_PER_TRANSFER (4) // I've had luck with a value of 4, but failure at 3 or less 41 #define BYTES_PER_CAN_PACKET (16) 42 #define BYTES_PER_UART_TRANSFER (64) 53 const char* safetyModelToString(
int safetyModel );
54 const char* carHarnessStatusToString(
int car_harness_status);
55 const char* faultStatusToString(
int fault_status);
56 std::string faultsToString(
int faults );
57 const char* usbPowerModeToString(
int usb_power_mode );
58 void printPandaHealth(
const PandaHealth& health );
69 virtual void notificationUartRead(
char* buffer,
size_t bufferLength) {};
70 virtual void notificationUartWrite() {};
72 virtual void notificationCanRead(
char* buffer,
size_t bufferLength) {};
73 virtual void notificationCanWrite() {};
82 Usb(UsbMode mode = MODE_ASYNCHRONOUS);
97 int sendCanData(
unsigned char* buffer,
int length);
99 void requestCanData();
100 void requestUartData();
103 bool hasGpsSupport();
104 void uartWrite(
const char* buffer,
int length);
108 void setUartBaud(
int uart,
int baud);
109 void setUartParity(
int uart,
int parity);
112 void setEspPower(
bool enable);
113 void espReset(
int uart,
int bootmode=0);
114 void getPandaSerial(
unsigned char* serial16);
115 void setCanLoopback(
int enable );
116 void getFirmware(
unsigned char* firmware128 );
117 unsigned char getHardware();
119 void setSafetyMode(uint16_t mode);
120 void sendHeartBeat();
121 void setPowerSaveEnable(
bool enable );
124 void setOperatingMode(UsbMode mode);
125 const char* getModeAsString()
const;
126 std::string getUsbSerialNumber() {
return serialNumber; };
127 void getHealth( PandaHealth* health );
130 void startRecording();
131 void stopRecording();
137 std::vector<UsbListener*> listeners;
138 char serialNumber[200];
139 char pandaSerial[16];
143 struct libusb_device_handle *handler;
148 unsigned char bufferSynchronousCan[BYTES_PER_CAN_PACKET*NUM_CAN_PACKETS_PER_TRANSFER];
149 unsigned char bufferSynchronousUart[BYTES_PER_UART_TRANSFER];
150 unsigned int bufferLengthSynchronousUart;
153 void sendModedUart();
156 int openDeviceByManufacturer(libusb_device **devs,
const char* manufacturerName);
159 void processNewCanRead(
char* buffer,
size_t length);
160 void processNewCanSend(
size_t length);
161 void processNewUartRead(
char* buffer,
size_t length);
162 void processNewUartSend(
size_t length);
166 static void transferCallbackReadCan(
struct libusb_transfer *transfer);
167 static void transferCallbackSendCan(
struct libusb_transfer *transfer);
168 static void transferCallbackReadUart(
struct libusb_transfer *transfer);
169 static void transferCallbackSendUart(
struct libusb_transfer *transfer);
172 static void printError(
int status);
173 static void printErrorTransfer(libusb_transfer_status status);
181 void sendPandaHardwareSimple(uint8_t requestType, uint8_t request, uint16_t value, uint16_t index);
182 void readPandaHardwareSimple(uint8_t requestType, uint8_t request,
unsigned char* buffer, uint16_t length);
Handles USB communication and parsing with a comma.ai Panda.
Definition: can.h:38
Abstract class, handles a single thread. Features mutual exclusion and pause/resume.
Definition: thread.h:27