Permalink
Browse files

Start work on full CAN-bus mode support

  • Loading branch information...
djs committed Aug 19, 2012
1 parent 3b078aa commit 5dfe7034dbc7db4ae48b8e88a0d32d646782c033
Showing with 309 additions and 4 deletions.
  1. +26 −0 elm.py
  2. +2 −0 fixtures/elm.json
  3. +249 −0 fixtures/elm_h1.json
  4. +32 −4 test_elm.py
View
26 elm.py
@@ -91,4 +91,30 @@ def read_voltage(self):
response = self.send_control_command('RV')
return response
+class ElmFull(Elm):
+ def _connect(self):
+ self.reset()
+
+ response = self.send_control_command('SP0')
+ response = self.send_control_command('DP')
+ self.send('0100')
+
+ self.send_control_command('H1')
+
+ def send_obdii_command(self, command):
+ cmd = ['%.2X' % x for x in command]
+ text = self.send(''.join(cmd))
+
+
+ response = {}
+
+ for line in text.split('\r'):
+ segments = line.strip().split(' ')
+ ecu = int(segments[0], 16)
+ data = [int(x, 16) for x in segments[1:]]
+
+ response[ecu] = response[ecu].append(data)
+
+
+ return data
View
@@ -7,6 +7,8 @@
"AT@2": "100010006357",
"ATCRA7E8": "OK",
"ATDP": "AUTO",
+ "ATH0": "OK",
+ "ATH1": "OK",
"ATRV": "12.3V",
"ATSP0": "OK",
"ATWS": "\r\rELM327 v1.3a",
View
@@ -0,0 +1,249 @@
+
+{
+ "0100": "7E9 06 41 00 98 18 00 13 00 \r7E8 06 41 00 BE 1F A8 13 00 ",
+ "0101": "7E8 06 41 01 00 07 E5 00 00 \r7E9 06 41 01 00 04 00 00 00 ",
+ "0102": "NO DATA",
+ "0103": "7E8 04 41 03 02 00 00 00 00 ",
+ "0104": "7E9 03 41 04 86 00 00 00 00 \r7E8 03 41 04 86 00 00 00 00 ",
+ "0105": "7E9 03 41 05 73 00 00 00 00 \r7E8 03 41 05 73 00 00 00 00 ",
+ "0106": "7E8 03 41 06 80 00 00 00 00 ",
+ "0107": "7E8 03 41 07 7A 00 00 00 00 ",
+ "0108": "NO DATA",
+ "0109": "NO DATA",
+ "010a": "NO DATA",
+ "010B": "NO DATA",
+ "010C": "7E9 04 41 0C 0B A0 00 00 00 \r7E8 04 41 0C 0B A4 00 00 00 ",
+ "010D": "7E9 03 41 0D 00 00 00 00 00 \r7E8 03 41 0D 00 00 00 00 00 ",
+ "010E": "7E8 03 41 0E 90 00 00 00 00 ",
+ "010F": "7E8 03 41 0F 50 00 00 00 00 ",
+ "0110": "7E8 04 41 10 01 69 00 00 00 ",
+ "0111": "7E8 03 41 11 1C 00 00 00 00 ",
+ "0112": "NO DATA",
+ "0113": "7E8 03 41 13 03 00 00 00 00 ",
+ "0114": "NO DATA",
+ "0115": "7E8 04 41 15 7D FF 00 00 00 ",
+ "0116": "NO DATA",
+ "0117": "NO DATA",
+ "0118": "NO DATA",
+ "0119": "NO DATA",
+ "011A": "NO DATA",
+ "011B": "NO DATA",
+ "011C": "7E9 03 41 1C 09 00 00 00 00 \r7E8 03 41 1C 03 00 00 00 00 ",
+ "011D": "NO DATA",
+ "011E": "NO DATA",
+ "011F": "7E8 04 41 1F 01 01 00 00 00 \r7E9 04 41 1F 01 01 00 00 00 ",
+ "0120": "7E9 06 41 20 80 01 A0 01 00 \r7E8 06 41 20 A0 07 F0 11 00 ",
+ "0121": "7E9 04 41 21 00 00 00 00 00 \r7E8 04 41 21 00 00 00 00 00 ",
+ "0122": "NO DATA",
+ "0123": "7E8 04 41 23 01 65 00 00 00 ",
+ "0124": "NO DATA",
+ "0125": "NO DATA",
+ "0126": "NO DATA",
+ "0127": "NO DATA",
+ "0128": "NO DATA",
+ "0129": "NO DATA",
+ "012A": "NO DATA",
+ "012B": "NO DATA",
+ "012C": "NO DATA",
+ "012D": "NO DATA",
+ "012E": "7E8 03 41 2E 6B 00 00 00 00 ",
+ "012F": "7E8 03 41 2F FF 00 00 00 00 ",
+ "0130": "7E9 03 41 30 21 00 00 00 00 \r7E8 03 41 30 21 00 00 00 00 ",
+ "0131": "7E9 04 41 31 02 D0 00 00 00 \r7E8 04 41 31 02 D4 00 00 00 ",
+ "0132": "7E8 04 41 32 F0 4D 00 00 00 ",
+ "0133": "7E9 03 41 33 64 00 00 00 00 \r7E8 03 41 33 64 00 00 00 00 ",
+ "0134": "7E8 06 41 34 7F AE 7F F8 00 ",
+ "0135": "NO DATA",
+ "0136": "NO DATA",
+ "0137": "NO DATA",
+ "0138": "NO DATA",
+ "0139": "NO DATA",
+ "013A": "NO DATA",
+ "013B": "NO DATA",
+ "013C": "7E8 04 41 3C 13 71 00 00 00 ",
+ "013D": "NO DATA",
+ "013E": "NO DATA",
+ "013F": "NO DATA",
+ "0140": "7E9 06 41 40 40 80 00 00 00 \r7E8 06 41 40 FE D0 00 00 00 ",
+ "0141": "7E8 06 41 41 00 67 E1 E5 00 ",
+ "0142": "7E9 04 41 42 35 17 00 00 00 \r7E8 04 41 42 36 BC 00 00 00 ",
+ "0143": "7E8 04 41 43 00 48 00 00 00 ",
+ "0144": "7E8 04 41 44 81 4A 00 00 00 ",
+ "0145": "7E8 03 41 45 05 00 00 00 00 ",
+ "0146": "7E8 03 41 46 4F 00 00 00 00 ",
+ "0147": "7E8 03 41 47 1C 00 00 00 00 ",
+ "0148": "NO DATA",
+ "0149": "7E9 03 41 49 26 00 00 00 00 \r7E8 03 41 49 26 00 00 00 00 ",
+ "014A": "7E8 03 41 4A 13 00 00 00 00 ",
+ "014B": "NO DATA",
+ "014C": "7E8 03 41 4C 07 00 00 00 00 ",
+ "014D": "NO DATA",
+ "014E": "NO DATA",
+ "014F": "NO DATA",
+ "0150": "NO DATA",
+ "0151": "NO DATA",
+ "0152": "NO DATA",
+ "0153": "NO DATA",
+ "0154": "NO DATA",
+ "0155": "NO DATA",
+ "0156": "NO DATA",
+ "0157": "NO DATA",
+ "0158": "NO DATA",
+ "0159": "NO DATA",
+ "015A": "NO DATA",
+ "015B": "NO DATA",
+ "015C": "NO DATA",
+ "015D": "NO DATA",
+ "015E": "NO DATA",
+ "015F": "NO DATA",
+ "0160": "NO DATA",
+ "0161": "NO DATA",
+ "0162": "NO DATA",
+ "0163": "NO DATA",
+ "0164": "NO DATA",
+ "0165": "NO DATA",
+ "0166": "NO DATA",
+ "0167": "NO DATA",
+ "0168": "NO DATA",
+ "0169": "NO DATA",
+ "016A": "NO DATA",
+ "016B": "NO DATA",
+ "016C": "NO DATA",
+ "016D": "NO DATA",
+ "016E": "NO DATA",
+ "016F": "NO DATA",
+ "0170": "NO DATA",
+ "0171": "NO DATA",
+ "0172": "NO DATA",
+ "0173": "NO DATA",
+ "0174": "NO DATA",
+ "0175": "NO DATA",
+ "0176": "NO DATA",
+ "0177": "NO DATA",
+ "0178": "NO DATA",
+ "0179": "NO DATA",
+ "017A": "NO DATA",
+ "017B": "NO DATA",
+ "017C": "NO DATA",
+ "017D": "NO DATA",
+ "017E": "NO DATA",
+ "017F": "NO DATA",
+ "0180": "NO DATA",
+ "0181": "NO DATA",
+ "0182": "NO DATA",
+ "0183": "NO DATA",
+ "0184": "NO DATA",
+ "0185": "NO DATA",
+ "0186": "NO DATA",
+ "0187": "NO DATA",
+ "0188": "NO DATA",
+ "0189": "NO DATA",
+ "018A": "NO DATA",
+ "018B": "NO DATA",
+ "018C": "NO DATA",
+ "018D": "NO DATA",
+ "018E": "NO DATA",
+ "018F": "NO DATA",
+ "0190": "NO DATA",
+ "0191": "NO DATA",
+ "0192": "NO DATA",
+ "0193": "NO DATA",
+ "0194": "NO DATA",
+ "0195": "NO DATA",
+ "0196": "NO DATA",
+ "0197": "NO DATA",
+ "0198": "NO DATA",
+ "0199": "NO DATA",
+ "019A": "NO DATA",
+ "019B": "NO DATA",
+ "019C": "NO DATA",
+ "019D": "NO DATA",
+ "019E": "NO DATA",
+ "019F": "NO DATA",
+ "01A0": "NO DATA",
+ "01A1": "NO DATA",
+ "01A2": "NO DATA",
+ "01A3": "NO DATA",
+ "01A4": "NO DATA",
+ "01A5": "NO DATA",
+ "01A6": "NO DATA",
+ "01A7": "NO DATA",
+ "01A8": "NO DATA",
+ "01A9": "NO DATA",
+ "01AA": "NO DATA",
+ "01AB": "NO DATA",
+ "01AC": "NO DATA",
+ "01AD": "NO DATA",
+ "01AE": "NO DATA",
+ "01AF": "NO DATA",
+ "01B0": "NO DATA",
+ "01B1": "NO DATA",
+ "01B2": "NO DATA",
+ "01B3": "NO DATA",
+ "01B4": "NO DATA",
+ "01B5": "NO DATA",
+ "01B6": "NO DATA",
+ "01B7": "NO DATA",
+ "01B8": "NO DATA",
+ "01B9": "NO DATA",
+ "01BA": "NO DATA",
+ "01BB": "NO DATA",
+ "01BC": "NO DATA",
+ "01BD": "NO DATA",
+ "01BE": "NO DATA",
+ "01BF": "NO DATA",
+ "01C0": "NO DATA",
+ "01C1": "NO DATA",
+ "01C2": "NO DATA",
+ "01C3": "NO DATA",
+ "01C4": "NO DATA",
+ "01C5": "NO DATA",
+ "01C6": "NO DATA",
+ "01C7": "NO DATA",
+ "01C8": "NO DATA",
+ "01C9": "NO DATA",
+ "01CA": "NO DATA",
+ "01CB": "NO DATA",
+ "01CC": "NO DATA",
+ "01CD": "NO DATA",
+ "01CE": "NO DATA",
+ "01CF": "NO DATA",
+ "01D0": "NO DATA",
+ "01D1": "NO DATA",
+ "01D2": "NO DATA",
+ "01D3": "NO DATA",
+ "01D4": "NO DATA",
+ "01D5": "NO DATA",
+ "01D6": "NO DATA",
+ "01D7": "NO DATA",
+ "01D8": "NO DATA",
+ "01D9": "NO DATA",
+ "01DA": "NO DATA",
+ "01DB": "NO DATA",
+ "01DC": "NO DATA",
+ "01DD": "NO DATA",
+ "01DE": "NO DATA",
+ "01DF": "NO DATA",
+ "0902": "014 \r0: 49 02 01 31 46 41 \r1: 48 50 33 4A 32 31 43 \r2: 4C 32 31 32 39 37 38 ",
+ "AT@1": "SCANTOOL.NET LLC",
+ "AT@2": "100010006357",
+ "ATCRA7E8": "OK",
+ "ATDP": "AUTO",
+ "ATRV": "12.3V",
+ "ATSP0": "OK",
+ "ATWS": "\r\rELM327 v1.3a",
+ "ATZ": "\r\rELM327 v1.3a",
+ "ATH0": "OK",
+ "ATH1": "OK",
+ "0900": "7E9 06 49 00 14 40 00 00 00 \r7E8 06 49 00 55 40 00 00 00 ",
+ "0901": "NO DATA",
+ "0902": "7E8 10 14 49 02 01 31 46 41 \r7E8 21 48 50 33 4A 32 31 43 \r7E8 22 4C 32 31 32 39 37 38 \r",
+ "0903": "NO DATA",
+ "0904": "7E9 10 13 49 04 01 54 51 5A \r7E9 21 4D 34 54 37 2E 48 33 \r7E8 10 13 49 04 01 48 46 43 \r7E9 22 32 00 00 00 00 00 00 \r7E8 21 4B 31 50 35 2E 48 33 \r7E8 22 32 00 00 00 00 00 00 \r",
+ "0905": "NO DATA",
+ "0906": "7E8 07 49 06 01 32 17 17 C6 \r7E9 07 49 06 01 13 43 C0 C3 \r",
+ "0907": "NO DATA",
+ "0908": "7E8 10 2B 49 08 14 00 13 00 \r7E8 21 45 00 1B 00 13 00 00 \r7E8 22 00 00 00 26 00 13 00 \r7E8 23 00 00 00 00 2B 00 13 \r7E8 24 00 00 00 00 00 0A 00 \r7E8 25 0A 00 1A 00 13 00 00 \r7E8 26 00 00 00 00 00 00 00 \r",
+ "0909": "NO DATA",
+ "090a": "7E8 10 17 49 0A 01 45 43 4D \r7E9 10 17 49 0A 01 54 43 4D \r7E9 21 00 2D 54 72 61 6E 73 \r7E9 22 6D 69 73 43 74 72 6C \r7E8 21 00 2D 45 6E 67 69 6E \r7E9 23 00 00 00 00 00 00 00 \r7E8 22 65 43 6F 6E 74 72 6F \r7E8 23 6C 00 00 00 00 00 00 \r"
+}
View
@@ -20,25 +20,53 @@ def __init__(self):
self.state = self.State.RESET
fh = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures', 'elm.json'), 'r')
- self.command_table = json.load(fh)
+ self.command_table_h0 = json.load(fh)
fh.close()
+ fh = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures', 'elm_h1.json'), 'r')
+ self.command_table_h1 = json.load(fh)
+ fh.close()
+
+ self._set_h0()
+
+ def _set_h1(self):
+ self.headers = True
+ self.command_table = self.command_table_h1
+
+ def _set_h0(self):
+ self.headers = False
+ self.command_table = self.command_table_h0
+
+ def open(self):
+ pass
+
+ def inWaiting(self):
+ return 0
+
def write(self, data):
self.in_data = self.in_data + data
while True:
m = self.COMMAND_RECEIVED.search(self.in_data)
if m:
command = m.group(1).replace(' ', '').upper()
+ print "old in_data = " + repr(self.in_data)
self.in_data = self.COMMAND_RECEIVED.sub('', self.in_data)
+ print "new in_data = " + repr(self.in_data)
+
+ if command == 'ATH0':
+ self._set_h0()
+ elif command == 'ATH1':
+ self._set_h1()
- try:
+ if command in self.command_table:
if self.echo:
self.out_data = self.out_data + command + '\r'
self.out_data = self.out_data + self.command_table[command] + '\r\r>'
- except KeyError:
- pass
+ else:
+ print "wtf @ " + command
+ self.out_data = self.out_data + '?' + '\r\r>'
else:
break

0 comments on commit 5dfe703

Please sign in to comment.