Ircama / ELM327-emulator

ELM327 Emulator for testing software interfacing OBDII via ELM327 adapter supporting multi-ECU simulation
Other
437 stars 91 forks source link

CRITICAL - Error while processing '': string index out of range #13

Closed noloader closed 3 years ago

noloader commented 3 years ago

Hi Everyone,

Thanks for this emulator. It looks like it will be very useful.

I'm working on Ubuntu 20.04, x86_64, fully patched. Python 3.8.10 is installed, and dependencies are installed. I cloned ELM327-emulator, and ran it using python3 -m elm. The emulator was waiting/listening on /dev/pts/3.

I then connected my client to the emulator via /dev/pts/3. My client configured its terminal with 38400, 8N1 like a real ELM327. I issued an ATZ from my client to reset the controller. The command hung in my client.

At the emulator there was a lot of activity:

$ python3 -m elm
2021-07-09 21:25:42,876 - root - INFO - 

ELM327 OBD-II adapter emulator v3.0.1 started on pseudo-tty port "/dev/pts/3".

Welcome to the ELM327 OBD-II adapter emulator.
ELM327-emulator is running on /dev/pts/3
Type help or ? to list commands.

CMD> 2021-07-09 21:25:59,439 - root - CRITICAL - Error while processing '':
string index out of range
Traceback (most recent call last):
  File "/home/jwalton/ELM327-emulator/elm/elm.py", line 848, in run
    request_header, request_data, resp = self.handle_request(
  File "/home/jwalton/ELM327-emulator/elm/elm.py", line 1802, in handle_request
    if cmd[1] == 'T' and org_cmd.upper()[1] != 'T':  # AT or ST shall be unspaced
IndexError: string index out of range

2021-07-09 21:25:59,440 - root - CRITICAL - Error while processing '':
string index out of range
Traceback (most recent call last):
  File "/home/jwalton/ELM327-emulator/elm/elm.py", line 848, in run
    request_header, request_data, resp = self.handle_request(
  File "/home/jwalton/ELM327-emulator/elm/elm.py", line 1802, in handle_request
    if cmd[1] == 'T' and org_cmd.upper()[1] != 'T':  # AT or ST shall be unspaced
IndexError: string index out of range

2021-07-09 21:25:59,442 - root - INFO - Unknown ELM command: 'ELM327V1.5', header=7E0
2021-07-09 21:25:59,443 - root - INFO - Unknown ELM command: 'ELM327V1.5', header=7E0
2021-07-09 21:25:59,443 - root - WARNING - Invalid request: '>ATZ'
2021-07-09 21:25:59,443 - root - WARNING - Invalid request: '>ATZ'
2021-07-09 21:25:59,444 - root - WARNING - Invalid request: '>ATZ'
2021-07-09 21:25:59,444 - root - INFO - Unknown ELM command: 'ELM327V1.5', header=7E0
2021-07-09 21:25:59,444 - root - INFO - Unknown ELM command: 'ELM327V1.5', header=7E0
2021-07-09 21:25:59,445 - root - WARNING - Invalid request: '>'
2021-07-09 21:25:59,445 - root - WARNING - Invalid request: '>'
2021-07-09 21:25:59,445 - root - WARNING - Invalid request: '>'
2021-07-09 21:25:59,445 - root - WARNING - Invalid request: '>'
2021-07-09 21:25:59,445 - root - WARNING - Invalid request: '>'
2021-07-09 21:25:59,446 - root - INFO - Unknown ELM command: 'ELM327V1.5', header=7E0
2021-07-09 21:25:59,446 - root - CRITICAL - Error while processing '?':
string index out of range
Traceback (most recent call last):
  File "/home/jwalton/ELM327-emulator/elm/elm.py", line 848, in run
    request_header, request_data, resp = self.handle_request(
  File "/home/jwalton/ELM327-emulator/elm/elm.py", line 1802, in handle_request
    if cmd[1] == 'T' and org_cmd.upper()[1] != 'T':  # AT or ST shall be unspaced
IndexError: string index out of range

2021-07-09 21:25:59,446 - root - CRITICAL - Error while processing '?':
string index out of range
Traceback (most recent call last):
  File "/home/jwalton/ELM327-emulator/elm/elm.py", line 848, in run
    request_header, request_data, resp = self.handle_request(
  File "/home/jwalton/ELM327-emulator/elm/elm.py", line 1802, in handle_request
    if cmd[1] == 'T' and org_cmd.upper()[1] != 'T':  # AT or ST shall be unspaced
IndexError: string index out of range

2021-07-09 21:25:59,446 - root - WARNING - Invalid request: '>'
2021-07-09 21:25:59,446 - root - WARNING - Invalid request: '>'
2021-07-09 21:25:59,447 - root - CRITICAL - Error while processing '?':
string index out of range
Traceback (most recent call last):
  File "/home/jwalton/ELM327-emulator/elm/elm.py", line 848, in run
    request_header, request_data, resp = self.handle_request(
  File "/home/jwalton/ELM327-emulator/elm/elm.py", line 1802, in handle_request
    if cmd[1] == 'T' and org_cmd.upper()[1] != 'T':  # AT or ST shall be unspaced
IndexError: string index out of range

2021-07-09 21:25:59,447 - root - CRITICAL - Error while processing '?':
string index out of range
Traceback (most recent call last):
  File "/home/jwalton/ELM327-emulator/elm/elm.py", line 848, in run
    request_header, request_data, resp = self.handle_request(
  File "/home/jwalton/ELM327-emulator/elm/elm.py", line 1802, in handle_request
    if cmd[1] == 'T' and org_cmd.upper()[1] != 'T':  # AT or ST shall be unspaced
IndexError: string index out of range

2021-07-09 21:25:59,447 - root - WARNING - Invalid request: '>'
2021-07-09 21:25:59,447 - root - WARNING - Invalid request: '>ATZ'
2021-07-09 21:25:59,447 - root - WARNING - Invalid request: '>ATZ'
2021-07-09 21:25:59,447 - root - WARNING - Invalid request: '>ATZ'
2021-07-09 21:25:59,447 - root - WARNING - Invalid request: '>ATZ'
2021-07-09 21:25:59,447 - root - WARNING - Invalid request: '>ATZ'
2021-07-09 21:25:59,448 - root - WARNING - Invalid request: '>ATZ'
2021-07-09 21:25:59,448 - root - INFO - Unknown ELM command: 'ELM327V1.5', header=7E0
<skip many similar blocks of messages>

2021-07-09 21:26:01,542 - root - WARNING - Invalid request: '>'
2021-07-09 21:26:01,542 - root - WARNING - Invalid request: '>'
2021-07-09 21:26:01,542 - root - WARNING - Invalid request: '>'
2021-07-09 21:26:01,543 - root - WARNING - Invalid request: '>'
2021-07-09 21:26:01,544 - root - WARNING - Invalid request: '>'
2021-07-09 21:26:01,544 - root - WARNING - Invalid request: '>'
2021-07-09 21:26:01,587 - root - WARNING - Invalid request: '>'
2021-07-09 21:26:01,588 - root - WARNING - Invalid request: '>'
2021-07-09 21:26:01,638 - root - WARNING - Invalid request: '>'
2021-07-09 21:26:01,688 - root - WARNING - Invalid request: '>'
2021-07-09 21:26:01,688 - root - WARNING - Invalid request: '>'
2021-07-09 21:26:01,738 - root - WARNING - Invalid request: '>'
2021-07-09 21:26:01,739 - root - WARNING - Invalid request: '>'
2021-07-09 21:26:01,788 - root - WARNING - Invalid request: '>'
2021-07-09 21:26:01,839 - root - WARNING - Invalid request: '>'
2021-07-09 21:26:01,889 - root - WARNING - Invalid request: '>'
2021-07-09 21:26:01,939 - root - WARNING - Invalid request: '>'
2021-07-09 21:26:01,940 - root - WARNING - Invalid request: '>'
2021-07-09 21:26:01,990 - root - WARNING - Invalid request: '>'
<skip many similar messages>

I got the same result when running python3 -m elm -s car. I got the same result with Master (shown above) and v3.0.0. I also got a similar result with v2.1.0 (but output is different). Running as sudo does not seem to make a difference.

I can provide my C test program, if interested. There's not much to it though. It just issues AT commands and reads responses. After some AT commands it uses ODB commands, like 01 00 and 09 02. When testing with a knock-off ELM327 the command completes successfully. (I'm trying the ELM327-Emulator because it is faster and more convenient than doing stuff on the car in the garage).

I did not see a similar bug report, so I opened this one.

My apologies if I a doing something wrong here.

noloader commented 3 years ago

I can avoid the crash/backtrace with the following, but the AT command still results in problems at the emulator. The emulator does not return a response, and the emulator produces a ton of warnings. The client still hangs.

$ git diff
diff --git a/elm/elm.py b/elm/elm.py
index 77e9555..ef66b6a 100644
--- a/elm/elm.py
+++ b/elm/elm.py
@@ -1799,7 +1799,7 @@ class Elm:
         if self.delay > 0:
             time.sleep(self.delay)

-        if cmd[1] == 'T' and org_cmd.upper()[1] != 'T':  # AT or ST shall be unspaced
+        if (len(cmd) < 2 or len(org_cmd) < 2) or (cmd[1] == 'T' and org_cmd.upper()[1] != 'T'):  # AT or ST shall be unspaced
             logging.error("Improper AT or ST command %s.", repr(org_cmd))
             return header, cmd, ""

After the Python code change, the ATZ command produces the following in the emulator output:

$ python3 -m elm -s car
2021-07-10 03:08:37,026 - root - INFO - 

ELM327 OBD-II adapter emulator v3.0.1 started on pseudo-tty port "/dev/pts/3".

Emulator scenario switched to 'car'
Welcome to the ELM327 OBD-II adapter emulator.
ELM327-emulator is running on /dev/pts/3
Type help or ? to list commands.

CMD> 2021-07-10 03:08:42,626 - root - ERROR - Improper AT or ST command ''.
2021-07-10 03:08:42,627 - root - ERROR - Improper AT or ST command ''.
2021-07-10 03:08:42,636 - root - INFO - Unknown ELM command: 'ELM327V1.5', header=7E0
2021-07-10 03:08:42,637 - root - INFO - Unknown ELM command: 'ELM327V1.5', header=7E0
2021-07-10 03:08:42,638 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,638 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,638 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,639 - root - INFO - Unknown ELM command: 'ELM327V1.5', header=7E0
2021-07-10 03:08:42,640 - root - INFO - Unknown ELM command: 'ELM327V1.5', header=7E0
2021-07-10 03:08:42,640 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,640 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,640 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,640 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,641 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,641 - root - INFO - Unknown ELM command: 'ELM327V1.5', header=7E0
2021-07-10 03:08:42,641 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,642 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,642 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,642 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,642 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,643 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,643 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,643 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,643 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,643 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,644 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,644 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,644 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,644 - root - INFO - Unknown ELM command: 'ELM327V1.5', header=7E0
2021-07-10 03:08:42,644 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,645 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,645 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,645 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,645 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,646 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,646 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,646 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,646 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,646 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,646 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,646 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,647 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,647 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,647 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,647 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,647 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,647 - root - INFO - Unknown ELM command: 'ELM327V1.5', header=7E0
2021-07-10 03:08:42,648 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,648 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,648 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,648 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,648 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,649 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,649 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,649 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,649 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,649 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,649 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,649 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,650 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,650 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,650 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,650 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,650 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,650 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,650 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,650 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,651 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,651 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,651 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,651 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,651 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,651 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,651 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,651 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,651 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,652 - root - INFO - Unknown ELM command: 'ELM327V1.5', header=7E0
2021-07-10 03:08:42,652 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,652 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,652 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,652 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,653 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,653 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,653 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,653 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,653 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,653 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,654 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,654 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,654 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,654 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,654 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,654 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,654 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,655 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,655 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,655 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,655 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,655 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,655 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,655 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,655 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,655 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,655 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,655 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,655 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,656 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,656 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,656 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,656 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,656 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,656 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,656 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,656 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,657 - root - INFO - Unknown ELM command: 'ELM327V1.5', header=7E0
2021-07-10 03:08:42,657 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,657 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,657 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,657 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,658 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,658 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,658 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,658 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,659 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,659 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,659 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,659 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,659 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,660 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,660 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,660 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,660 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,660 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,660 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,661 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,661 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,661 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,661 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,661 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,661 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,661 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,661 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,662 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,662 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,662 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,662 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,662 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,663 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,663 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,663 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,663 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,663 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,663 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,664 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,664 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,664 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,664 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,664 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,664 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,664 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,664 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,664 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,664 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,664 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,664 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,665 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,665 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,665 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,665 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,665 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,665 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,665 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,665 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,665 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,665 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,665 - root - WARNING - Invalid request: '>ATZ'
2021-07-10 03:08:42,666 - root - INFO - Unknown ELM command: 'ELM327V1.5', header=7E0
2021-07-10 03:08:42,666 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,666 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,667 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,667 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,667 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,667 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,667 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,667 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,668 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,668 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,668 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,668 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,668 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,669 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,669 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,669 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,669 - root - ERROR - Improper AT or ST command '?'.
2021-07-10 03:08:42,669 - root - WARNING - Invalid request: '>'
2021-07-10 03:08:42,670 - root - WARNING - Invalid request: '>'
<skip many similar messages>

Somewhat off-topic, this looks incorrect if it supposed to be part of the ATZ response (as the identification string):

2021-07-10 03:08:42,636 - root - INFO - Unknown ELM command: 'ELM327V1.5', header=7E0

According to the ELM327 Data Sheet (p. 8) by ELM Electronics, the identification string is supposed to be like the following. Valid versions are 1.0, 1.0a, 1.1, 1.2, 1.2a, 1.3, 1.3a, 1.4, 1.4b, 2.0, 2.1, 2.2, and 2.3. Also see ELM Electronics AT Commands by Version.

ELM327 v2.3

(If you are seeing ELM327 v1.5, the ELM327 v1.5 identification string is a dead giveaway that the controller is a knockoff since ELM Electronics did not produce a v1.5 revision).

Ircama commented 3 years ago

This looks like strange behaviour, I'll analyze it early next week.

noloader commented 3 years ago

Thanks @Ircama,

If you want an account on this machine, then please let me know. I am happy to provide it with admin privileges. I'll need your SSH public key. Email to noloader, gmail account.

Otherwise the machine is Core i7-8700 running Ubuntu 20.04, x86_64, fully patched. You should be able to duplicate the OS and software environment in a VM.

noloader commented 3 years ago

@Ircama,

One other question... Sorry to have to ask. I am not a Python person...

Should master_fd in elm.py include os.O_NOCTTY?

self.master_fd = os.open(self.device_port, os.O_RDWR)

In C, I open my serial ports with const int flags = O_RDWR | O_NOCTTY | O_SYNC;. I use O_NOCTTY to avoid some problems with being a controlling terminal (which a serial port is not). Also see Serial Programming Guide for POSIX Operating Systems. I use O_SYNC because the file descriptor moves between blocking and non-blocking, depending on how I am reading data.

noloader commented 3 years ago

@Ircama,

I was able to connect to the emulator using GNU's screen program. I was also able to send an ATZ and receive the identification string with screen.

I've been down this road before... If I recall properly, screen opens the device with a lot of unexpected options ("unexpected" from the way a serial port is typically configured). In fact, my lab notes even say to look at GNU Screen's InitTTY function.

I attached my test program in case you want to kick it around for testing: elm327.c.zip.


/* The settings below are from GNU Screen program and its  */
/* InitTTY. InitTTY is screen's startup code for the TTY.  */
int term_config_gnu_screen(int fd, unsigned int speed)
{
    struct termios tty;
    if (tcgetattr(fd, &tty) != 0) {
        log_error("term_config: tcgetattr: %s\n", strerror(errno));
        return errno;
    }

    // Hack... Screen determines this at runtime, and sometimes it is 0.
    int ttyflag = 1;

#if defined(BRKINT)
    tty.c_iflag |= BRKINT;
#endif

#if defined(IGNPAR)
    tty.c_iflag |= IGNPAR;
#endif

#if defined(ISTRIP) && 0
    tty.c_iflag |= ISTRIP;
#endif

#if defined(IXON)
    tty.c_iflag |= IXON;
#endif

    if (!ttyflag) {
#if defined(ICRNL)
        tty.c_iflag |= ICRNL;
#endif

#if defined(ONLCR)
        tty.c_oflag |= ONLCR;
#endif

#if defined(TAB3)
        tty.c_oflag |= TAB3;
#endif

#if defined(OXTABS)
        tty.c_oflag |= OXTABS;
#endif

#if defined(PARENB) && 0
        tty.c_cflag |= PARENB;
#endif

#if defined(OPOST)
        tty.c_oflag |= OPOST;
#endif
    }

#if defined(CS8)
    tty.c_cflag |= CS8;
#endif

#if defined(CREAD)
    tty.c_cflag |= CREAD;
#endif

#if defined(CLOCAL)
    tty.c_cflag |= CLOCAL;
#endif

#if defined(ECHOCTL)
    tty.c_lflag |= ECHOCTL;
#endif

#if defined(ECHOKE)
    tty.c_lflag |= ECHOKE;
#endif

    if (!ttyflag) {
#if defined(ISIG)
        tty.c_lflag |= ISIG;
#endif

#if defined(ICANON)
        tty.c_lflag |= ICANON;
#endif

#if defined(ECHO)
        tty.c_lflag |= ECHO;
#endif

    }
#if defined(ECHOE)
    tty.c_lflag |= ECHOE;
#endif

#if defined(ECHOK)
    tty.c_lflag |= ECHOK;
#endif

#if defined(IEXTEN)
    tty.c_lflag |= IEXTEN;
#endif

#if defined(VINTR)
# if (VINTR < MAXCC)
    tty.c_cc[VINTR] = Ctrl('C');
# endif
#endif

#if defined(VQUIT)
# if (VQUIT < MAXCC)
    tty.c_cc[VQUIT] = Ctrl('\\');
# endif
#endif

#if defined(VERASE)
# if (VERASE < MAXCC)
    tty.c_cc[VERASE] = 0x7f;    /* DEL */
# endif
#endif

#if defined(VKILL)
# if (VKILL < MAXCC)
    tty.c_cc[VKILL] = Ctrl('U');
# endif
#endif

#if defined(VEOF)
# if (VEOF < MAXCC)
    tty.c_cc[VEOF] = Ctrl('D');
# endif
#endif

#if defined(VEOL)
# if (VEOL < MAXCC)
    tty.c_cc[VEOL] = VDISABLE;
# endif
#endif

#if defined(VEOL2)
# if (VEOL2 < MAXCC)
    tty.c_cc[VEOL2] = VDISABLE;
# endif
#endif

#if defined(VSWTCH)
# if (VSWTCH < MAXCC)
    tty.c_cc[VSWTCH] = VDISABLE;
# endif
#endif

#if defined(VSTART)
# if (VSTART < MAXCC)
    tty.c_cc[VSTART] = Ctrl('Q');
# endif
#endif

#if defined(VSTOP)
# if (VSTOP < MAXCC)
    tty.c_cc[VSTOP] = Ctrl('S');
# endif
#endif

#if defined(VSUSP)
# if (VSUSP < MAXCC)
    tty.c_cc[VSUSP] = Ctrl('Z');
# endif
#endif

#if defined(VDSUSP)
# if (VDSUSP < MAXCC)
    tty.c_cc[VDSUSP] = Ctrl('Y');
# endif
#endif

#if defined(VREPRINT)
# if (VREPRINT < MAXCC)
    tty.c_cc[VREPRINT] = Ctrl('R');
# endif
#endif

#if defined(VDISCARD)
# if (VDISCARD < MAXCC)
    tty.c_cc[VDISCARD] = Ctrl('O');
# endif
#endif

#if defined(VWERASE)
# if (VWERASE < MAXCC)
    tty.c_cc[VWERASE] = Ctrl('W');
# endif
#endif

#if defined(VLNEXT)
# if (VLNEXT < MAXCC)
    tty.c_cc[VLNEXT] = Ctrl('V');
# endif
#endif

#if defined(VSTATUS)
# if (VSTATUS < MAXCC)
    tty.c_cc[VSTATUS] = Ctrl('T');
# endif
#endif

    if (ttyflag) {
        tty.c_cc[VMIN] = 1;
        tty.c_cc[VTIME] = 0;
    }

#if defined(TIOCKSET)
    tty.m_jtchars.t_ascii = 'J';
    tty.m_jtchars.t_kanji = 'B';
    tty.m_knjmode = KM_ASCII | KM_SYSSJIS;
#endif

    cfsetospeed(&tty, term_get_baud(speed));
    cfsetispeed(&tty, term_get_baud(speed));

    if (tcsetattr(fd, TCSANOW, &tty) != 0) {
        log_error("term_config: tcsetattr: %s\n", strerror(errno));
        return errno;
    }

    if (tcflush(fd, TCIOFLUSH) != 0)
    {
        log_warn("term_config: tcflush: %s\n", strerror(errno));
    }

    return 0;
}
noloader commented 3 years ago

@Ircama,

I kind of got to the bottom of things... In my test program I needed to use a raw terminal, and not the terminal attributes taken from /dev/pts/3.

So I changed this:

struct termios tty;
if (tcgetattr(fd, &tty) != 0) {
    printf("Failed to get terminal attributes: %s\n", strerror(errno));
    goto cleanup_and_exit;
}

to this:

struct termios tty;
cfmakeraw(&tty);

and things worked as expected.

Sorry about the extra noise.

Ircama commented 3 years ago

Please recheck this issue after python3 -m pip install --upgrade git+https://github.com/ircama/ELM327-emulator

noloader commented 3 years ago

Thanks @Ircama ,

Please recheck this issue after python3 -m pip install --upgrade git+https://github.com/ircama/ELM327-emulator

I'm using master, which looks like it has the changes.

Using cfmakeraw to configure a terminal works as expected. It worked before and after the commits.

Using tcgetattr to configure a terminal no longer crashes/throws exception after the commits. However, the stream of messages is still present in the emulator, and the client still hangs on ATZ.

Ircama commented 3 years ago

Thanks @noloader for these notes and sorry for this this long wait before my feedback.

I have created a new branch named slave_raw with a possible fix that I need to test with all the applications that I have already used for the previous verifications.

Please recheck your issue after python3 -m pip install --upgrade git+https://github.com/ircama/ELM327-emulator.git@slave_raw.

Regards

github-actions[bot] commented 3 years ago

This issue becomed stale because of no feedback for 30 days. Remove the stale label or add a comment; otherwise, this will be automatically closed in 60 days.