Small project to display some OBD values from the Toyota GT86/ Subaru BRZ/ Scion FRS on an OLED display.
Dependencies: Adafruit_GFX MODSERIAL mbed-rtos mbed
Diff: main.cpp
- Revision:
- 5:0b229ba8ede5
- Parent:
- 4:0e2d6cc31afb
- Child:
- 6:506b703a8acf
--- a/main.cpp Sun Apr 27 17:42:32 2014 +0000 +++ b/main.cpp Sun Apr 27 19:13:35 2014 +0000 @@ -20,6 +20,7 @@ IsoTpHandler tpHandler(&can2); +//#define ACTIVATE_DEBUG_OUTPUT #ifdef ACTIVATE_DEBUG_OUTPUT #define DEBUG_PRINT(format, ...) pc.printf(format, ##__VA_ARGS__) #else @@ -81,6 +82,71 @@ //pc.printf("can_rx_int_handler ok\r\n"); } +Mail<CANMessage, 16> can2_tx_queue; +void can2_send_packets(void const *args) { + DEBUG_PRINT("TX2 start\r\n"); + while (true) { + osEvent evt = can2_tx_queue.get(osWaitForever); + if (evt.status == osEventMail) { + CANMessage *msg = (CANMessage*) evt.value.p; + DEBUG_PRINT("TX2 check\r\n"); + if (can2.write(*msg)) + { + DEBUG_PRINT("TX2 send\r\n"); + can2_tx_queue.free(msg); + Thread::wait(150); + } + else + { + DEBUG_PRINT("TX2 wait \r\n"); + Thread::wait(150); + } + } + } +} + + +struct behaviour_t { + unsigned char rxData[8]; + char txData[8]; +}; + + + +behaviour_t behaviour[] = +{ + {{0x02, 0x21, 0x01, 0, 0, 0, 0, 0}, {0x10, 0x1F, 0x61, 0x01, 0x51, 0, 0x37, 0x01}}, //first oil temp packet + {{0x30, 0, 0, 0, 0, 0, 0, 0}, {0x21, 0x1F, 0x61, 0x01, 0x51, 0, 0x37, 0x01}}, //second oil temp packet, TODO more pakets must be sent + {{0x02, 0x01, 0x21, 0, 0, 0, 0, 0}, {0x04, 0x41, 0x21, 0, 0, 0, 0, 0}}, + {{0x02, 0x01, 0x0C, 0, 0, 0, 0, 0}, {0x04, 0x41, 0x0C, 0x0F, 0xA2, 0, 0, 0}}, + {{0x02, 0x01, 0x11, 0, 0, 0, 0, 0}, {0x03, 0x41, 0x11, 0x26, 0, 0, 0, 0}}, + {{0x02, 0x01, 0x05, 0, 0, 0, 0, 0}, {0x03, 0x41, 0x05, 0x4D, 0, 0, 0, 0}}, //engine coolant temp +}; + +void can2_send_requests(void const *args) { + while (true) { + Thread::wait(2000); + CANMessage sendMsg(0x7E0, (char*) behaviour[3].rxData, 8); + CANMessage* msg = can2_tx_queue.alloc(); + *msg = sendMsg; + can2_tx_queue.put(msg); + Thread::wait(200); + msg = can2_tx_queue.alloc(); + sendMsg.data[2] = behaviour[4].rxData[2]; + *msg = sendMsg; + can2_tx_queue.put(msg); + Thread::wait(200); + sendMsg.data[2] = behaviour[5].rxData[2]; + *msg = sendMsg; + can2_tx_queue.put(msg); + Thread::wait(200); + CANMessage sendMsg2(0x7E0, (char*) behaviour[0].rxData, 8); + msg = can2_tx_queue.alloc(); + *msg = sendMsg2; + can2_tx_queue.put(msg); + } +} + #ifdef CAN1_TEST Mail<CANMessage, 16> can1_rx_queue; CANMessage msg1; @@ -104,21 +170,6 @@ #ifdef CAN1_OBD_CAR_SIMULATOR -struct behaviour_t { - unsigned char rxData[8]; - char txData[8]; -}; - -behaviour_t behaviour[] = -{ - {{0x02, 0x21, 0x01, 0, 0, 0, 0, 0}, {0x10, 0x1F, 0x61, 0x01, 0x51, 0, 0x37, 0x01}}, //first oil temp packet - {{0x30, 0, 0, 0, 0, 0, 0, 0}, {0x21, 0x1F, 0x61, 0x01, 0x51, 0, 0x37, 0x01}}, //second oil temp packet, TODO more pakets must be sent - {{0x02, 0x01, 0x21, 0, 0, 0, 0, 0}, {0x04, 0x41, 0x21, 0, 0, 0, 0, 0}}, - {{0x02, 0x01, 0x0C, 0, 0, 0, 0, 0}, {0x04, 0x41, 0x0C, 0x0F, 0xA2, 0, 0, 0}}, - {{0x02, 0x01, 0x11, 0, 0, 0, 0, 0}, {0x03, 0x41, 0x11, 0x26, 0, 0, 0, 0}}, - {{0x02, 0x01, 0x05, 0, 0, 0, 0, 0}, {0x03, 0x41, 0x05, 0x4D, 0, 0, 0, 0}}, //engine coolant temp -}; - Mail<CANMessage, 16> can1_tx_queue; void can1_obd_car_simulator_process_packet(CANMessage &msg) @@ -264,6 +315,8 @@ Thread can1_tx_thread(can1_send_packets); #endif //CAN1_OBD_CAR_SIMULATOR #endif //CAN1_TEST + Thread can2_send_request_thread(can2_send_requests); + Thread can2_tx_thread(can2_send_packets); pc.printf("Start\r\n"); while (true) { led1 = !led1;