Sophie Dexter
/
Just4Trionic
Just4Trionic - CAN and BDM FLASH programmer for Saab cars
Diff: can232.cpp
- Revision:
- 4:682d96ff6d79
- Parent:
- 1:d5452e398b76
--- a/can232.cpp Tue Jun 07 12:23:28 2011 +0000 +++ b/can232.cpp Wed Sep 11 11:55:51 2013 +0000 @@ -25,9 +25,9 @@ #define CMD_OPEN 'O' ///< Open the CAN device (do this before an S/s command) #define CMD_PRESET_SPEED 'S' ///< Sn: set preconfigured speeds -#define CMD_SPEED_0 '0' ///< 10 kbits -#define CMD_SPEED_1 '1' ///< 20 kbits -#define CMD_SPEED_2 '2' ///< 50 kbits +#define CMD_SPEED_0 '0' ///< 10 kbits (or 47,619 bits with 's') +#define CMD_SPEED_1 '1' ///< 20 kbits (or 500 kbits with 's') +#define CMD_SPEED_2 '2' ///< 50 kbits (or 615 kbits with 's') #define CMD_SPEED_3 '3' ///< 100 kbits #define CMD_SPEED_4 '4' ///< 125 kbits #define CMD_SPEED_5 '5' ///< 250 kbits @@ -50,6 +50,12 @@ #define CMD_READ_FLAGS 'F' ///< Read flags !?! +#define CMD_FILTER 'f' ///< Filter which CAN message types to allow +#define CMD_FILTER_NONE '0' ///< Allow all CAN message types +#define CMD_FILTER_T5 '5' ///< Allow only Trionic 5 CAN message types +#define CMD_FILTER_T7 '7' ///< Allow only Trionic 5 CAN message types +#define CMD_FILTER_T8 '8' ///< Allow only Trionic 5 CAN message types + #define CMD_ACCEPT_CODE 'M' ///< Mxxxxxxxx: Acceptance code e.g. 0x00000000 } accept #define CMD_ACCEPT_MASK 'm' ///< mxxxxxxxx: Acceptance mask e.g. 0xffffffff } all @@ -88,21 +94,19 @@ *cmd_buffer = '\0'; char ret; char rx_char; - can_open(); - can.attach(&show_can_message); -// bool (*reset_func)(); while (true) { // read chars from USB -// Trionic5ShowCANMessage(); if (pc.readable()) { + // turn Error LED off for next command + led4 = 0; rx_char = pc.getc(); switch (rx_char) { - // 'ESC' key to go back to mbed Just4Trionic 'home' menu + // 'ESC' key to go back to mbed Just4Trionic 'home' menu case '\e': can_close(); can.attach(NULL); return; - // end-of-command reached + // end-of-command reached case TERM_OK : // execute command and return flag via USB ret = execute_can_cmd(); @@ -113,7 +117,7 @@ // ret == TERM_OK ? led_on(LED_ACT) : led_on(LED_ERR); ret == TERM_OK ? led3 = 1 : led4 = 1; break; - // another command char + // another command char default: // store in buffer if space permits if (StrLen(cmd_buffer) < CMD_BUF_LENGTH - 1) { @@ -154,48 +158,119 @@ case CMD_SEND_29BIT: break; - + case CMD_CLOSE: can_close(); return TERM_OK; case CMD_OPEN: can_open(); return TERM_OK; - + case CMD_PRESET_SPEED: CHECK_ARGLENGTH(0); - switch (cmd) { - // get firmware version +// can.attach(NULL); + switch (cmd) { case CMD_SPEED_0: - return (can.frequency(10000)) ? TERM_OK : TERM_ERR; + can_configure(2, 10000, 0); + break; case CMD_SPEED_1: - return (can.frequency(20000)) ? TERM_OK : TERM_ERR; + can_configure(2, 20000, 0); + break; case CMD_SPEED_2: - return (can.frequency(50000)) ? TERM_OK : TERM_ERR; + can_configure(2, 50000, 0); + break; case CMD_SPEED_3: - return (can.frequency(100000)) ? TERM_OK : TERM_ERR; + can_configure(2, 100000, 0); + break; case CMD_SPEED_4: - return (can.frequency(125000)) ? TERM_OK : TERM_ERR; + can_configure(2, 125000, 0); + break; case CMD_SPEED_5: - return (can.frequency(250000)) ? TERM_OK : TERM_ERR; + can_configure(2, 250000, 0); + break; case CMD_SPEED_6: - return (can.frequency(500000)) ? TERM_OK : TERM_ERR; + can_configure(2, 500000, 0); + break; case CMD_SPEED_7: - return (can.frequency(800000)) ? TERM_OK : TERM_ERR; + can_configure(2, 800000, 0); + break; case CMD_SPEED_8: - return (can.frequency(1000000)) ? TERM_OK : TERM_ERR; + can_configure(2, 1000000, 0); + break; + default: + return TERM_ERR; } - break; - + can.attach(&show_can_message); + return TERM_OK; + case CMD_DIRECT_SPEED: CHECK_ARGLENGTH(0); switch (cmd) { case CMD_SPEED_0: - return (can.frequency(47619)) ? TERM_OK : TERM_ERR; + can_configure(2, 47619, 0); + break; case CMD_SPEED_1: - return (can.frequency(500000)) ? TERM_OK : TERM_ERR; + can_configure(2, 500000, 0); + break; case CMD_SPEED_2: - return (can.frequency(615000)) ? TERM_OK : TERM_ERR; + can_configure(2, 615000, 0); + break; + default: + return TERM_ERR; + } + can.attach(&show_can_message); + return TERM_OK; + + case CMD_FILTER: + CHECK_ARGLENGTH(0); + switch (cmd) { + case CMD_FILTER_NONE: + can_use_filters(FALSE); // Accept all messages (Acceptance Filters disabled) + return TERM_OK; + case CMD_FILTER_T5: + can_reset_filters(); + can_add_filter(2, 0x005); //005h - + can_add_filter(2, 0x006); //006h - + can_add_filter(2, 0x00C); //00Ch - + can_add_filter(2, 0x008); //008h - + return TERM_OK; + case CMD_FILTER_T7: + can_reset_filters(); + can_add_filter(2, 0x220); //220h + can_add_filter(2, 0x238); //238h + can_add_filter(2, 0x240); //240h + can_add_filter(2, 0x258); //258h + can_add_filter(2, 0x266); //266h - Ack + return TERM_OK; + can_add_filter(2, 0x1A0); //1A0h - Engine information + can_add_filter(2, 0x280); //280h - Pedals, reverse gear + can_add_filter(2, 0x290); //290h - Steering wheel and SID buttons + can_add_filter(2, 0x2F0); //2F0h - Vehicle speed + can_add_filter(2, 0x320); //320h - Doors, central locking and seat belts + can_add_filter(2, 0x370); //370h - Mileage + can_add_filter(2, 0x3A0); //3A0h - Vehicle speed + can_add_filter(2, 0x3B0); //3B0h - Head lights + can_add_filter(2, 0x3E0); //3E0h - Automatic Gearbox + can_add_filter(2, 0x410); //410h - Light dimmer and light sensor + can_add_filter(2, 0x430); //430h - SID beep request (interesting for Knock indicator?) + can_add_filter(2, 0x460); //460h - Engine rpm and speed + can_add_filter(2, 0x4A0); //4A0h - Steering wheel, Vehicle Identification Number + can_add_filter(2, 0x520); //520h - ACC, inside temperature + can_add_filter(2, 0x530); //530h - ACC + can_add_filter(2, 0x5C0); //5C0h - Coolant temperature, air pressure + can_add_filter(2, 0x630); //630h - Fuel usage + can_add_filter(2, 0x640); //640h - Mileage + can_add_filter(2, 0x7A0); //7A0h - Outside temperature + return TERM_OK; + case CMD_FILTER_T8: + can_reset_filters(); + can_add_filter(2, 0x645); //645h - CIM + can_add_filter(2, 0x7E0); //7E0h - + can_add_filter(2, 0x7E8); //7E8h - + can_add_filter(2, 0x311); //311h - + can_add_filter(2, 0x5E8); //5E8h - + //can_add_filter(2, 0x101); //101h - + return TERM_OK; } break; }