|
| 1 | +/* |
| 2 | +ISO.h |
| 3 | +Parameter IDs |
| 4 | +
|
| 5 | +Copyright (c) Aster94 |
| 6 | +
|
| 7 | +Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
| 8 | +and associated documentation files (the "Software"), to deal in the Software without restriction, |
| 9 | +including without limitation the rights to use, copy, modify, merge, publish, distribute, |
| 10 | +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| 11 | +furnished to do so, subject to the following conditions: |
| 12 | +
|
| 13 | +The above copyright notice and this permission notice shall be included in all copies or |
| 14 | +substantial portions of the Software. |
| 15 | +
|
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
| 17 | +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 18 | +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 19 | +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | +*/ |
| 22 | + |
| 23 | +#ifndef ISO_h |
| 24 | +#define ISO_h |
| 25 | + |
| 26 | +#include "KWP2000.h" |
| 27 | + |
| 28 | +// These values are defined by the ISO protocol |
| 29 | +#define ISO_BAUDRATE 10400 |
| 30 | +#define ISO_MAX_DATA 260 ///< maximum length of a response from the ecu: 255 data + 4 header + 1 checksum |
| 31 | +#define ISO_T_P1 10 ///< inter byte time for ECU response - min: 0 max: 20 |
| 32 | +#define ISO_T_P2_MIN_LIMIT 50 |
| 33 | +#define ISO_T_P2_MAX_LIMIT 89600 ///< P2 time between tester request and ECU response or two ECU responses |
| 34 | +#define ISO_T_P3_MAX_LIMIT 89600 ///< P3 time between end of ECU responses and start of new tester request |
| 35 | +#define ISO_T_P4_MAX_LIMIT 20 ///< inter byte time for tester request |
| 36 | +// P2 (min & max), P3 (min & max) and P4 (min) are defined by the ECU with accessTimingParameter() |
| 37 | +#define ISO_T_IDLE 1000 ///< min 300, max undefined |
| 38 | +#define ISO_T_INIL (unsigned int)25 ///< Initialization low time |
| 39 | +#define ISO_T_WUP (unsigned int)50 ///< Wake up Pattern |
| 40 | + |
| 41 | +// Common values between all brands/bikes |
| 42 | + |
| 43 | +const uint8_t format_physical = 0x80; |
| 44 | +const uint8_t format_functional = 0xC0; // not supported |
| 45 | +const uint8_t format_CARB = 0x40; // not supported |
| 46 | + |
| 47 | +const uint8_t OUR_addr = 0xF1; // between hex F0 and FD |
| 48 | + |
| 49 | +const uint8_t start_com[] = {0x81}; |
| 50 | +const uint8_t stop_com[] = {0x82}; |
| 51 | +uint8_t start_diagnostic[2] = {0x10}; |
| 52 | +const uint8_t read_data_local_identifier = 0x21; |
| 53 | + |
| 54 | +// access timing parameter and timing paramenter indicator |
| 55 | +const uint8_t atp_read_limits[] = {0x83, 0x00}; |
| 56 | +const uint8_t atp_set_default[] = {0x83, 0x01}; |
| 57 | +const uint8_t atp_read_current[] = {0x83, 0x02}; |
| 58 | +const uint8_t atp_set_given[] = {0x83, 0x03}; |
| 59 | + |
| 60 | +const uint8_t tester_present_with_answer[] = {0x3E, 0x01}; // the ECU will answer |
| 61 | +const uint8_t tester_present_without_answer[] = {0x3E, 0x02}; // the ECU won't answer |
| 62 | + |
| 63 | +const uint8_t trouble_codes_all[] = {0x13}; |
| 64 | +const uint8_t trouble_codes_only_active[] = {0x17}; |
| 65 | +const uint8_t trouble_codes_with_status[] = {0x18}; |
| 66 | +const uint8_t clear_trouble_codes[] = {0x14}; |
| 67 | + |
| 68 | +#define request_ok(x) x | 0x40 |
| 69 | +const uint8_t request_rejected = 0x7F; |
| 70 | + |
| 71 | +// Specific brands/bikes values here are only declared and will be assigned inside the function |
| 72 | +// this is very likely to change, do not refert too much to the code below |
| 73 | + |
| 74 | +uint8_t ECU_addr; |
| 75 | + |
| 76 | +uint8_t suzuki_request_sens[] = {0x21, 0x08}; |
| 77 | +uint8_t kawasaki_request_gps[2] = {0x21, 0x0B}; |
| 78 | +uint8_t kawasaki_request_rpm[2] = {0x21, 0x09}; |
| 79 | +uint8_t kawasaki_request_speed[2] = {0x21, 0x0c}; |
| 80 | +uint8_t kawasaki_request_tps[2] = {0x21, 0x04}; |
| 81 | +uint8_t kawasaki_request_iap[2] = {0x21, 0x07}; |
| 82 | +uint8_t kawasaki_request_iat[2] = {0x21, 0x05}; |
| 83 | +uint8_t kawasaki_request_ect[2] = {0x21, 0x06}; |
| 84 | +uint8_t yamaha_request_sens[2] = {'?'}; |
| 85 | +uint8_t honda_request_sens[2] = {'?'}; |
| 86 | + |
| 87 | +uint8_t IDX_GPS; |
| 88 | +uint8_t IDX_CLUTCH; |
| 89 | +uint8_t IDX_RPM_H; |
| 90 | +uint8_t IDX_RPM_L; |
| 91 | +uint8_t IDX_SPEED; |
| 92 | +uint8_t IDX_TPS; |
| 93 | +uint8_t IDX_STPS; |
| 94 | +uint8_t IDX_IAP; |
| 95 | +uint8_t IDX_IAT; |
| 96 | +uint8_t IDX_ECT; |
| 97 | +uint8_t IDX_VOLT; |
| 98 | + |
| 99 | +void KWP2000::set_bike_specific_values(const brand brand, const model model) |
| 100 | +{ |
| 101 | + if (brand == SUZUKI) |
| 102 | + { |
| 103 | + ECU_addr = 0x12; |
| 104 | + |
| 105 | + IDX_GPS = 26; |
| 106 | + IDX_CLUTCH = 52; |
| 107 | + IDX_RPM_H = 17; |
| 108 | + IDX_RPM_L = 18; |
| 109 | + IDX_SPEED = 16; |
| 110 | + IDX_TPS = 19; |
| 111 | + IDX_STPS = 46; |
| 112 | + IDX_IAP = 20; |
| 113 | + IDX_IAT = 22; |
| 114 | + IDX_ECT = 21; |
| 115 | + IDX_VOLT = 24; |
| 116 | + /* |
| 117 | + CLT?? 20 |
| 118 | + HO2?? 25 |
| 119 | + IAP2?? 27 |
| 120 | + idle speed?? 28 |
| 121 | + ISC valve controls the volume of air that bypasses the throttle valve -29 |
| 122 | + Fuel 31-38 |
| 123 | + mode (map)?? 50 |
| 124 | + pair 51 |
| 125 | + */ |
| 126 | + } |
| 127 | + else if (brand == KAWASAKI) |
| 128 | + { |
| 129 | + ECU_addr = 0x11; |
| 130 | + start_diagnostic[1] = {0x80}; |
| 131 | + IDX_GPS = 6; |
| 132 | + IDX_RPM_H = 6; |
| 133 | + IDX_RPM_L = 7; |
| 134 | + IDX_SPEED = 6; |
| 135 | + IDX_TPS = 6; |
| 136 | + IDX_IAP = 6; |
| 137 | + IDX_IAT = 6; |
| 138 | + IDX_ECT = 6; |
| 139 | + } |
| 140 | + else if (brand == YAMAHA) |
| 141 | + { |
| 142 | + /* |
| 143 | + As far as I could understand the YDS (Yamaha Diagnostic Protocol) protocol, it is close to the Honda protocol. |
| 144 | + There are no sender-/receiver-addresses or header information. Just the checksum at the end. |
| 145 | + You initialize the diagnostic mode by sending 0x80 and from then on you can just submit 0x02 and it gives you: |
| 146 | + Rpm, Speed, Error, Gear & Checksum. |
| 147 | + */ |
| 148 | + ECU_addr = '?'; |
| 149 | + } |
| 150 | + else if (brand == HONDA) |
| 151 | + { |
| 152 | + // https://gonzos.net/projects/ctx-obd/ |
| 153 | + ECU_addr = '?'; |
| 154 | + } |
| 155 | +} |
| 156 | + |
| 157 | +#endif // ISO_h |
0 commit comments