Skip to content

Commit 78a1e90

Browse files
committed
add monitor command. use new obd-parser
1 parent 762c52a commit 78a1e90

File tree

9 files changed

+1744
-17
lines changed

9 files changed

+1744
-17
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ coverage
66
typings
77
*.d.ts
88
*.js
9-
*.rdb
9+
*.rdb
10+
outputs/

README.md

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# obd-parser-cli
22

3-
A CLI tool that can interface with On Board Diagnostics (OBD) of vehicles.
3+
A CLI tool that can interface with On Board Diagnostics (OBD II) of vehicles.
44

5-
## Testing
5+
## Compatibility and Testing
66
This software has only been tested with a Volkswagen MK6 GTI. Your success in
77
using this software with your vehicle might vary.
88

@@ -57,29 +57,35 @@ the help menu:
5757
```
5858
$ obd --help
5959
60-
🚔 OBD CLI 🚘
60+
🚔 OBD CLI 🚘
6161
6262
Usage: index [options] [command]
6363
6464
6565
Commands:
6666
67-
list list supported pids that can be passed to "poll" commands
68-
poll <pid> [pids...] poll for an OBD value(s) specified by <pid> or a list of pids
67+
list list supported pids that can be passed to "poll" commands
68+
poll <pid> [pids...] poll for an OBD value(s) specified by <pid> or a list of pids
69+
monitor <pid:interval> [pid:interval...] similar to poll, but continously checks PID values every n milliseconds,
70+
e.g 0C:1000 will get RPM every 1000 milliseconds
6971
7072
Options:
7173
7274
-h, --help output usage information
7375
-V, --version output the version number
7476
-c, --connection <string> type of connection, valid options are "fake" or "serial"
7577
-b, --baudrate <number> control connection baudrate, e.g 38400
78+
-o, --outdir <string> loation to create folder containing monitor results
7679
-i, --interface <name> the interface to use for connection, e.g /dev/tty.serialusb
7780
```
7881

7982
### Listing PIDs (list)
8083

81-
Use the list command to view PIDs that can be read from vehicles. Currently only
82-
a handful are supported. Here's how you can view them:
84+
Use the list command to view PIDs that can be read from vehicles. Currently
85+
only a handful are supported by this module and certain vehicles will not
86+
support all PIDS either.
87+
88+
Here's how you can view them:
8389

8490
```
8591
$ obd list
@@ -92,6 +98,15 @@ Available PIDs for "poll" commands are:
9298
0C - Engine RPM
9399
05 - Engine Coolant Temperature
94100
0D - Vehicle Speed
101+
04 - Calculated Engine Load
102+
0A - Fuel Pressure
103+
0B - Intake Manifold Absolute Pressure
104+
0F - Intake Air Temperature
105+
10 - MAF Air Flow Rate
106+
11 - Throttle Position
107+
1C - OBD Standard
108+
03 - Fuel System Status
109+
20 - Supported PIDs
95110
96111
Example command usage: "obd poll 2F"
97112
@@ -128,7 +143,7 @@ Results:
128143

129144
The above example uses the "fake" connection type and therefore returns
130145
randomised values for the PIDs you requested. If you'd like to connect via
131-
a serial conncetion you can try the following (macOS) example:
146+
a serial conncetion you can try the following (macOS tested) example:
132147

133148
```
134149
$ obd poll -c serial -b 38400 -i /dev/tty.serialusb "Engine RPM"
@@ -143,4 +158,49 @@ Results:
143158
┌────────────┬────────┐
144159
│ Engine RPM │ 835.50 │
145160
└────────────┴────────┘
161+
```
162+
163+
### Monitor
164+
165+
The monitor command is similar to poll, but instead it prints lines of JSON
166+
continuously until the process is killed. You can use the `--output` option
167+
to specify a directory to write JSON files to that will contain this data.
168+
This creates a folder in the specified `output` directory with the current
169+
date, and then writes the JSON to folders that represent each trip taken.
170+
Inside each folder a JSON file is created. The name of the file will be
171+
0.json by default. Once this file reaches ~128KB in size a new file, 1.json
172+
will be created, and so on until the process is killed.
173+
174+
Here's a sample command and output data:
175+
176+
```
177+
$ obd monitor 0d:100 0c:1000 05:5000 -c serial -i /dev/tty.usbserial -b 38400
178+
179+
🚔 OBD CLI 🚘
180+
181+
Connecting via "fake" type...
182+
OBD module intialised...
183+
184+
{"ts":"2017-03-15T16:57:18.296Z","bytes":"410D26","value":38,"counter":715,"pretty":"38km/h","name":"Vehicle Speed","pid":"0D"}
185+
{"ts":"2017-03-15T16:57:18.318Z","bytes":"410C16CA","value":1458.5,"counter":716,"pretty":"1458.5rpm","name":"Engine RPM","pid":"0C"}
186+
{"ts":"2017-03-15T16:57:18.946Z","bytes":"410F43","value":27,"counter":717,"pretty":"27°C","name":"Intake Air Temperature","pid":"0F"}
187+
{"ts":"2017-03-15T16:57:19.295Z","bytes":"410D26","value":38,"counter":718,"pretty":"38km/h","name":"Vehicle Speed","pid":"0D"}
188+
{"ts":"2017-03-15T16:57:19.316Z","bytes":"410C1684","value":1441,"counter":719,"pretty":"1441rpm","name":"Engine RPM","pid":"0C"}
189+
{"ts":"2017-03-15T16:57:20.296Z","bytes":"410D22","value":34,"counter":720,"pretty":"34km/h","name":"Vehicle Speed","pid":"0D"}
190+
{"ts":"2017-03-15T16:57:21.235Z","bytes":"410572","value":74,"counter":722,"pretty":"74°C","name":"Engine Coolant Temperature","pid":"05"}
191+
```
192+
193+
If using the `--output` option, then the created folder structure might look
194+
as follows if you had two trips in a given day:
195+
196+
```
197+
| |____
198+
| | |____2017-03-12
199+
| | | |____2ee5ff94-a02d-4791-9cd8-8b0d9770c34f
200+
| | | | |____0.json
201+
| | | |____599d7463-c568-441d-b6f7-86ea92ea3e59
202+
| | | | |____0.json
203+
| | | | |____1.json
204+
| | | | |____2.json
205+
| | | | |____3.json
146206
```

bin/index.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import * as Promise from 'bluebird';
44

5-
function onError (e) {
6-
console.log('uncaught error', e);
5+
function onError (e: Error) {
6+
console.log('uncaught error', e.stack);
77
}
88

99
Promise.onPossiblyUnhandledRejection(onError)
@@ -18,13 +18,16 @@ g.program = program;
1818

1919
import poll from '../lib/command-poll';
2020
import list from '../lib/command-list';
21+
import monitor from '../lib/command-monitor';
2122

2223
console.log('\n🚔 OBD CLI 🚘');
2324

2425
program
2526
.version(require('../package.json').version)
2627
.option('-c, --connection <string>', 'type of connection, valid options are "fake" or "serial"')
2728
.option('-b, --baudrate <number>', 'control connection baudrate, e.g 38400')
29+
.option('-o, --outdir <string>', 'loation to create folder containing monitor results')
30+
.option('-z, --zip', 'if this option is passed then output files will be zipped')
2831
.option(
2932
'-i, --interface <name>',
3033
'the interface to use for connection, e.g /dev/tty.serialusb'
@@ -47,6 +50,21 @@ program
4750
poll([pid].concat(extraPids || []));
4851
});
4952

53+
program
54+
.command('monitor <pid:interval> [pid:interval...]')
55+
.description(
56+
`similar to poll, but continously checks PID values every n milliseconds,
57+
e.g 0C:1000 will get RPM every 1000 milliseconds`
58+
)
59+
.action(function (pid:string, extraPids:string[]) {
60+
if (!pid) {
61+
console.log('please specify at least 1 pid, e.g "obd poll -c fake 2F')
62+
process.exit(1);
63+
}
64+
65+
monitor([pid].concat(extraPids || []));
66+
});
67+
5068
if (!process.argv.slice(2).length) {
5169
program.outputHelp();
5270
} else {

0 commit comments

Comments
 (0)