bmw ds2 for e36
Embed:
(wiki syntax)
Show/hide line numbers
DS2.h
00001 #ifndef DS2_H 00002 #define DS2_H 00003 00004 #include "mbed.h" 00005 00006 #include "Bus.h" 00007 00008 extern Serial dbg; 00009 00010 #define DS2_MTU (127) 00011 00012 static const char DS2_IDENTIFY[] = {0x00}; 00013 00014 /* 00015 a ds2 packet looks like this: 00016 {0xAA, 0xAA, 0xLL, 0xDD, 0xCC} 00017 or this: 00018 {0xAA, 0xLL, 0xDD, 0xCC} 00019 AA = module address 00020 LL = packet length 00021 DD = data 00022 CC = checksum 00023 there can be either one or two AA module address bytes 00024 there can be 1 or more DD data bytes 00025 00026 here is an example query packet: 00027 {0x12, 0x04, 0x00, 0x16} (query DME for identification) 00028 the address is a one-byte address of 0x12 (DME) 00029 the packet length is 0x04 bytes 00030 the one byte data payload is 0x00 (identify module) 00031 the xor checksum of the entire packet is 0x16 00032 00033 the reply would look like this: 00034 {0x12, 0x10, ... 0x??} (DME responding...) 00035 the one byte address is 0x12 (DME) 00036 the packet length will be 0x10 bytes 00037 the xor checksum 0x?? would depend on the missing data "..." 00038 00039 the same query packet would look like this with two address bytes: 00040 {0x12, 0x00, 0x05, 0x00, 0x17} 00041 00042 it seems that some modules want one address byte and some want two 00043 either that or it's an extra length byte we're dealing with 00044 probably it's a length byte, but I'll worry about it when I find out 00045 */ 00046 class DS2Packet 00047 { 00048 unsigned short* address; 00049 char* length; 00050 char* data; 00051 char* checksum; 00052 00053 char* rawdata; 00054 bool has8BitAddr; 00055 00056 void updateChecksum(); 00057 00058 public: 00059 DS2Packet(int maxlength); 00060 DS2Packet(int address, const char* data, int length); 00061 ~DS2Packet(); 00062 00063 void has8BitAddress(bool b); 00064 00065 bool has8BitAddress() 00066 { 00067 return has8BitAddr; 00068 } 00069 00070 int getAddress() 00071 { 00072 if(has8BitAddr) 00073 return *address >> 8 & 0xff; 00074 return *address; 00075 } 00076 00077 int getLength() 00078 { 00079 return *length; 00080 } 00081 00082 char* getData() 00083 { 00084 return data; 00085 } 00086 00087 int getChecksum() 00088 { 00089 char* check = rawdata + *length - 1; 00090 return *check; 00091 } 00092 00093 char* getRawData() 00094 { 00095 return rawdata; 00096 } 00097 }; 00098 00099 class DS2 00100 { 00101 Bus *k; 00102 Bus *l; 00103 00104 public: 00105 DS2(Bus* KLine, Bus* LLine); 00106 ~DS2(); 00107 int sendPacket(DS2Packet* packet, Bus* bus); 00108 DS2Packet* getPacket(Bus* bus); 00109 DS2Packet* getPacket8(Bus* bus); 00110 bool test(); 00111 void testModule(int address); 00112 void snoop(); 00113 00114 }; 00115 00116 #endif //DS2_H
Generated on Fri Jul 22 2022 12:21:05 by
1.7.2