Open OBC / e36obd

Dependents:   obdtest

Committer:
openobc
Date:
Fri May 20 16:54:39 2011 +0000
Revision:
0:32d3cc3791c4

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
openobc 0:32d3cc3791c4 1 #ifndef DS2_H
openobc 0:32d3cc3791c4 2 #define DS2_H
openobc 0:32d3cc3791c4 3
openobc 0:32d3cc3791c4 4 #include "mbed.h"
openobc 0:32d3cc3791c4 5
openobc 0:32d3cc3791c4 6 #include "Bus.h"
openobc 0:32d3cc3791c4 7
openobc 0:32d3cc3791c4 8 extern Serial dbg;
openobc 0:32d3cc3791c4 9
openobc 0:32d3cc3791c4 10 #define DS2_MTU (127)
openobc 0:32d3cc3791c4 11
openobc 0:32d3cc3791c4 12 static const char DS2_IDENTIFY[] = {0x00};
openobc 0:32d3cc3791c4 13
openobc 0:32d3cc3791c4 14 /*
openobc 0:32d3cc3791c4 15 a ds2 packet looks like this:
openobc 0:32d3cc3791c4 16 {0xAA, 0xAA, 0xLL, 0xDD, 0xCC}
openobc 0:32d3cc3791c4 17 or this:
openobc 0:32d3cc3791c4 18 {0xAA, 0xLL, 0xDD, 0xCC}
openobc 0:32d3cc3791c4 19 AA = module address
openobc 0:32d3cc3791c4 20 LL = packet length
openobc 0:32d3cc3791c4 21 DD = data
openobc 0:32d3cc3791c4 22 CC = checksum
openobc 0:32d3cc3791c4 23 there can be either one or two AA module address bytes
openobc 0:32d3cc3791c4 24 there can be 1 or more DD data bytes
openobc 0:32d3cc3791c4 25
openobc 0:32d3cc3791c4 26 here is an example query packet:
openobc 0:32d3cc3791c4 27 {0x12, 0x04, 0x00, 0x16} (query DME for identification)
openobc 0:32d3cc3791c4 28 the address is a one-byte address of 0x12 (DME)
openobc 0:32d3cc3791c4 29 the packet length is 0x04 bytes
openobc 0:32d3cc3791c4 30 the one byte data payload is 0x00 (identify module)
openobc 0:32d3cc3791c4 31 the xor checksum of the entire packet is 0x16
openobc 0:32d3cc3791c4 32
openobc 0:32d3cc3791c4 33 the reply would look like this:
openobc 0:32d3cc3791c4 34 {0x12, 0x10, ... 0x??} (DME responding...)
openobc 0:32d3cc3791c4 35 the one byte address is 0x12 (DME)
openobc 0:32d3cc3791c4 36 the packet length will be 0x10 bytes
openobc 0:32d3cc3791c4 37 the xor checksum 0x?? would depend on the missing data "..."
openobc 0:32d3cc3791c4 38
openobc 0:32d3cc3791c4 39 the same query packet would look like this with two address bytes:
openobc 0:32d3cc3791c4 40 {0x12, 0x00, 0x05, 0x00, 0x17}
openobc 0:32d3cc3791c4 41
openobc 0:32d3cc3791c4 42 it seems that some modules want one address byte and some want two
openobc 0:32d3cc3791c4 43 either that or it's an extra length byte we're dealing with
openobc 0:32d3cc3791c4 44 probably it's a length byte, but I'll worry about it when I find out
openobc 0:32d3cc3791c4 45 */
openobc 0:32d3cc3791c4 46 class DS2Packet
openobc 0:32d3cc3791c4 47 {
openobc 0:32d3cc3791c4 48 unsigned short* address;
openobc 0:32d3cc3791c4 49 char* length;
openobc 0:32d3cc3791c4 50 char* data;
openobc 0:32d3cc3791c4 51 char* checksum;
openobc 0:32d3cc3791c4 52
openobc 0:32d3cc3791c4 53 char* rawdata;
openobc 0:32d3cc3791c4 54 bool has8BitAddr;
openobc 0:32d3cc3791c4 55
openobc 0:32d3cc3791c4 56 void updateChecksum();
openobc 0:32d3cc3791c4 57
openobc 0:32d3cc3791c4 58 public:
openobc 0:32d3cc3791c4 59 DS2Packet(int maxlength);
openobc 0:32d3cc3791c4 60 DS2Packet(int address, const char* data, int length);
openobc 0:32d3cc3791c4 61 ~DS2Packet();
openobc 0:32d3cc3791c4 62
openobc 0:32d3cc3791c4 63 void has8BitAddress(bool b);
openobc 0:32d3cc3791c4 64
openobc 0:32d3cc3791c4 65 bool has8BitAddress()
openobc 0:32d3cc3791c4 66 {
openobc 0:32d3cc3791c4 67 return has8BitAddr;
openobc 0:32d3cc3791c4 68 }
openobc 0:32d3cc3791c4 69
openobc 0:32d3cc3791c4 70 int getAddress()
openobc 0:32d3cc3791c4 71 {
openobc 0:32d3cc3791c4 72 if(has8BitAddr)
openobc 0:32d3cc3791c4 73 return *address >> 8 & 0xff;
openobc 0:32d3cc3791c4 74 return *address;
openobc 0:32d3cc3791c4 75 }
openobc 0:32d3cc3791c4 76
openobc 0:32d3cc3791c4 77 int getLength()
openobc 0:32d3cc3791c4 78 {
openobc 0:32d3cc3791c4 79 return *length;
openobc 0:32d3cc3791c4 80 }
openobc 0:32d3cc3791c4 81
openobc 0:32d3cc3791c4 82 char* getData()
openobc 0:32d3cc3791c4 83 {
openobc 0:32d3cc3791c4 84 return data;
openobc 0:32d3cc3791c4 85 }
openobc 0:32d3cc3791c4 86
openobc 0:32d3cc3791c4 87 int getChecksum()
openobc 0:32d3cc3791c4 88 {
openobc 0:32d3cc3791c4 89 char* check = rawdata + *length - 1;
openobc 0:32d3cc3791c4 90 return *check;
openobc 0:32d3cc3791c4 91 }
openobc 0:32d3cc3791c4 92
openobc 0:32d3cc3791c4 93 char* getRawData()
openobc 0:32d3cc3791c4 94 {
openobc 0:32d3cc3791c4 95 return rawdata;
openobc 0:32d3cc3791c4 96 }
openobc 0:32d3cc3791c4 97 };
openobc 0:32d3cc3791c4 98
openobc 0:32d3cc3791c4 99 class DS2
openobc 0:32d3cc3791c4 100 {
openobc 0:32d3cc3791c4 101 Bus *k;
openobc 0:32d3cc3791c4 102 Bus *l;
openobc 0:32d3cc3791c4 103
openobc 0:32d3cc3791c4 104 public:
openobc 0:32d3cc3791c4 105 DS2(Bus* KLine, Bus* LLine);
openobc 0:32d3cc3791c4 106 ~DS2();
openobc 0:32d3cc3791c4 107 int sendPacket(DS2Packet* packet, Bus* bus);
openobc 0:32d3cc3791c4 108 DS2Packet* getPacket(Bus* bus);
openobc 0:32d3cc3791c4 109 DS2Packet* getPacket8(Bus* bus);
openobc 0:32d3cc3791c4 110 bool test();
openobc 0:32d3cc3791c4 111 void testModule(int address);
openobc 0:32d3cc3791c4 112 void snoop();
openobc 0:32d3cc3791c4 113
openobc 0:32d3cc3791c4 114 };
openobc 0:32d3cc3791c4 115
openobc 0:32d3cc3791c4 116 #endif //DS2_H