Skip to content

Commit

Permalink
Refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
Ircama committed Mar 15, 2021
1 parent 45db2f0 commit e7d2b2c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,23 @@ At the command prompt, cursors and [keyboard shortcuts](https://github.com/chzye
## Advanced usage

*echo* and *linefeed* settings are both disabled by default. They can be configured via related AT commands (*ATL1* and *ATE1*). To enable them via command line:

```
emulator.counters['cmd_linefeeds'] = True; emulator.counters['cmd_echo'] = True
```

Possible values of `emulator.counters['cmd_linefeeds']`:

Value|Behaviour|Reference
:---:|---------|-----------------------------------------
0 |(Default) Each line is closed by two CRs.|`\r\r`
1 |Each line is closed by two CRs and a LF. |`\r\r\n`
2 |Each line is closed by a CR and a LF. |`\r\n`
3 |Each line is closed by a LF.|`\n`
4 |Each line is closed by a CR.|`\r`

Each time the interface is reset, the counters are restored to their default settings and the `emulator.counters['...']` commands need to be issued again.

Space characters are inserted by default in the ECU response as per specification. To remove them, use the AT command *ATS0* or `emulator.counters['cmd_spaces']=0`, Notice that an *ATZ* command resets all counters.

The emulator includes a timeout management for each entered character, which by default is not active (e.g., set to 1440 seconds). This setting can be configured through `emulator.counters['req_timeout']`. Decimals are allowed. Some adapters provide a feature that discards characters if each of them is not entered within a short time limit (apart from the first one after a CR/Carriage Return). The appropriate emulation for this timeout is to set `emulator.counters['req_timeout']=0.015` (e.g., 15 milliseconds). Typing commands by hand via terminal emulator with such adapters is not possible as the allowed timing is too short. The same happens when setting *req_timeout* to 0.015.
Expand Down Expand Up @@ -435,7 +448,7 @@ ObdMessage Dictionary Generator for "ELM327-emulator".

Sample usage: `obd_dictionary -i /dev/ttyUSB0 -c car.csv -o AurisOutput.py -v -p 10 -d 1 -n mycar`

*obd_dictionary* exploits the [command discovery feature](https://python-obd.readthedocs.io/en/latest/Connections/#supported_commands) of *python-OBD* which autopopulates the set of builtin commands supported by the vehicle through [queries](https://github.com/brendan-w/python-OBD/blob/8f4a55cd04170d006eb7d1d774fb4bacb1c6282f/obd/obd.py#L102) performed within the [connection phase](https://github.com/brendan-w/python-OBD/blob/8f4a55cd04170d006eb7d1d774fb4bacb1c6282f/obd/obd.py#L65). Optionally, this set can be further enriched with a list of custom PIDs included in an input csv file in [Torque CSV Format](https://torque-bhp.com/wiki/PIDs). The autopopulation feature can be disabled with `-x` option.
*obd_dictionary* exploits the [command discovery feature](https://python-obd.readthedocs.io/en/latest/Connections/#supported_commands) of *python-OBD*, which autopopulates the set of builtin commands supported by the vehicle through [queries](https://github.com/brendan-w/python-OBD/blob/8f4a55cd04170d006eb7d1d774fb4bacb1c6282f/obd/obd.py#L102) performed within the [connection phase](https://github.com/brendan-w/python-OBD/blob/8f4a55cd04170d006eb7d1d774fb4bacb1c6282f/obd/obd.py#L65). Optionally, this set can be further enriched with a list of custom PIDs included in an input csv file in [Torque CSV Format](https://torque-bhp.com/wiki/PIDs). The autopopulation feature can be disabled with `-x` option.

The command allows all the python-OBD interface settings (see `-B`, `-T`, `-C`, `-F`, `-P` command-line options) and a dry-run flag (`-r`), which is very useful to test the OBDII connection.

Expand All @@ -447,14 +460,22 @@ python3 -m obd_dictionary -i /dev/rfcomm0 -B 38400 -T 30 -r

See also [this post](https://github.com/brendan-w/python-OBD/issues/93#issuecomment-327472934) for Bluetooth.

For better analysis, the `-r` output can be piped to *lnav*:
For better analysis, the `-r` output can be piped to *lnav* (the following command tests the UBB connection):

```shell
python3 -m obd_dictionary -i /dev/ttyUSB0 -B 38400 -r 2>&1 | lnav
```

When the tests provide successful connection, the `-r` option can be removed and the additional *obd_dictionary* options can be added.

*obd_dictionary* can be also used to test *elm*. Run `python3 -m elm`; select `scenario car`. Read the pseudotty, say */dev/pts/2*. Run *obd_dictionary*:

```shell
python3 -m obd_dictionary -i /dev/pts/2 2>&1 | lnav
```

(The automation of this process is shown further on.)

In general, *ELM327-emulator* should already manage all needed AT Commands within its default dictionary, so in most cases it is worthwhile removing them from the new scenario via `-t` option.

The file produced by *obd_dictionary* provides the same information model of *obd_message.py*. It can be used to replace the default module or can be dynamically imported in *ELM327-emulator* through the `merge` command, which loads an *ObdMessage* dictionary and merges it to *emulator.ObdMessage*. Example of *merge* process:
Expand Down
19 changes: 15 additions & 4 deletions elm/elm.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,22 @@ def read(self):
def write(self, resp):
""" write a response to the port """

n = "\r\n" if 'cmd_linefeeds' in self.counters and self.counters[
'cmd_linefeeds'] == 1 else "\r"
n = "\r"
if 'cmd_linefeeds' in self.counters:
if self.counters['cmd_linefeeds'] == 1:
n = "\r\n"
if self.counters['cmd_linefeeds'] == 2:
n = "\n"
if self.counters['cmd_linefeeds'] == 3:
n = ""
resp = resp.replace('\r', '\n')
if self.counters['cmd_linefeeds'] == 4:
n = ""
resp += n + ">"
nospaces = 1 if 'cmd_spaces' in self.counters and self.counters[
'cmd_spaces'] == 0 else 0
nospaces = 0
if ('cmd_spaces' in self.counters
and self.counters['cmd_spaces'] == 0):
nospaces = 1

j = 0
for i in re.split(r'\0([^\0]+)\0', resp):
Expand Down
2 changes: 1 addition & 1 deletion obd_dictionary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def obd_dictionary():
# Print header information
print("\n".join([ecu[k] + ' = "' + k + '"' for k in ecu]))
print('ELM_R_OK = "OK\\r"\n'
'ELM_R_UNKNOWN = "?\r"\n'
'ELM_R_UNKNOWN = "?\\r"\n'
'ELM_MAX_RESP = "[0123456]?$"\n')
print("ObdMessage = {")
print(" '" + args.car_name + "': {")
Expand Down

0 comments on commit e7d2b2c

Please sign in to comment.