Skip to content

Commit db1fc25

Browse files
authored
Merge pull request #428 from hardbyte/feature-extract-cli-help
Extract cli help automatically
2 parents 832eee6 + e19045f commit db1fc25

6 files changed

Lines changed: 21 additions & 150 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ matrix:
5050

5151
install:
5252
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo bash test/open_vcan.sh ; fi
53-
- travis_retry pip install sphinx
53+
- if [[ "$TRAVIS_PYTHON_VERSION" == "3.6" ]]; then travis_retry pip install -r doc/doc-requirements.txt; fi
5454
- travis_retry pip install .[test]
5555

5656
script:

doc/bus.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Conflicting calls are executed by blocking until the bus is accessible.
6868

6969
It can be used exactly like the normal :class:`~can.BusABC`:
7070

71-
# 'socketcan' is only an exemple interface, it works with all the others too
71+
# 'socketcan' is only an example interface, it works with all the others too
7272
my_bus = can.ThreadSafeBus(interface='socketcan', channel='vcan0')
7373
my_bus.send(...)
7474
my_bus.recv(...)

doc/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
'sphinx.ext.intersphinx',
4040
'sphinx.ext.coverage',
4141
'sphinx.ext.viewcode',
42-
'sphinx.ext.graphviz']
42+
'sphinx.ext.graphviz',
43+
'sphinxcontrib.programoutput'
44+
]
4345

4446
# Now, you can use the alias name as a new role, e.g. :issue:`123`.
4547
extlinks = {

doc/development.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ This is the entire ABC bus class with all internal methods:
8686
.. autoclass:: can.BusABC
8787
:private-members:
8888
:special-members:
89+
:noindex:
90+
8991

9092
Concrete instances are created by :class:`can.Bus`.
9193

doc/doc-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sphinx>=1.8.1
2+
sphinxcontrib-programoutput

doc/scripts.rst

Lines changed: 12 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -8,81 +8,17 @@ They can be called for example by ``python -m can.logger`` or ``can_logger.py``
88
can.logger
99
----------
1010

11-
Command line help, called with ``--help``::
12-
13-
usage: python -m can.logger [-h] [-f LOG_FILE] [-v] [-c CHANNEL]
14-
[-i {pcan,ixxat,socketcan_ctypes,kvaser,virtual,usb2can,vector,slcan,nican,socketcan,iscan,neovi,serial,socketcan_native}]
15-
[--filter ...] [-b BITRATE]
16-
[--active | --passive]
17-
18-
Log CAN traffic, printing messages to stdout or to a given file.
19-
20-
optional arguments:
21-
-h, --help show this help message and exit
22-
-f LOG_FILE, --file_name LOG_FILE
23-
Path and base log filename, for supported types see
24-
can.Logger.
25-
-v How much information do you want to see at the command
26-
line? You can add several of these e.g., -vv is DEBUG
27-
-c CHANNEL, --channel CHANNEL
28-
Most backend interfaces require some sort of channel.
29-
For example with the serial interface the channel
30-
might be a rfcomm device: "/dev/rfcomm0" With the
31-
socketcan interfaces valid channel examples include:
32-
"can0", "vcan0"
33-
-i {pcan,ixxat,socketcan_ctypes,kvaser,virtual,usb2can,vector,slcan,nican,socketcan,iscan,neovi,serial,socketcan_native}, --interface {pcan,ixxat,socketcan_ctypes,kvaser,virtual,usb2can,vector,slcan,nican,socketcan,iscan,neovi,serial,socketcan_native}
34-
Specify the backend CAN interface to use. If left
35-
blank, fall back to reading from configuration files.
36-
--filter ... Comma separated filters can be specified for the given
37-
CAN interface: <can_id>:<can_mask> (matches when
38-
<received_can_id> & mask == can_id & mask)
39-
<can_id>~<can_mask> (matches when <received_can_id> &
40-
mask != can_id & mask)
41-
-b BITRATE, --bitrate BITRATE
42-
Bitrate to use for the CAN bus.
43-
--active Start the bus as active, this is applied the default.
44-
--passive Start the bus as passive.
11+
Command line help, called with ``--help``:
12+
13+
14+
.. command-output:: python -m can.logger -h
4515

4616

4717
can.player
4818
----------
4919

50-
Command line help, called with ``--help``::
51-
52-
usage: python -m can.player [-h] [-f LOG_FILE] [-v] [-c CHANNEL]
53-
[-i {pcan,ixxat,socketcan_ctypes,kvaser,virtual,usb2can,vector,slcan,nican,socketcan,iscan,neovi,serial,socketcan_native}]
54-
[-b BITRATE] [--ignore-timestamps]
55-
[-g GAP] [-s SKIP]
56-
input-file
57-
58-
Replay CAN traffic.
59-
60-
positional arguments:
61-
input-file The file to replay. For supported types see
62-
can.LogReader.
63-
64-
optional arguments:
65-
-h, --help show this help message and exit
66-
-f LOG_FILE, --file_name LOG_FILE
67-
Path and base log filename, for supported types see
68-
can.LogReader.
69-
-v Also print can frames to stdout. You can add several
70-
of these to enable debugging
71-
-c CHANNEL, --channel CHANNEL
72-
Most backend interfaces require some sort of channel.
73-
For example with the serial interface the channel
74-
might be a rfcomm device: "/dev/rfcomm0" With the
75-
socketcan interfaces valid channel examples include:
76-
"can0", "vcan0"
77-
-i {pcan,ixxat,socketcan_ctypes,kvaser,virtual,usb2can,vector,slcan,nican,socketcan,iscan,neovi,serial,socketcan_native}, --interface {pcan,ixxat,socketcan_ctypes,kvaser,virtual,usb2can,vector,slcan,nican,socketcan,iscan,neovi,serial,socketcan_native}
78-
Specify the backend CAN interface to use. If left
79-
blank, fall back to reading from configuration files.
80-
-b BITRATE, --bitrate BITRATE
81-
Bitrate to use for the CAN bus.
82-
--ignore-timestamps Ignore timestamps (send all frames immediately with
83-
minimum gap between frames)
84-
-g GAP, --gap GAP <s> minimum time between replayed frames
85-
-s SKIP, --skip SKIP <s> skip gaps greater than 's' seconds
20+
.. command-output:: python -m can.player -h
21+
8622

8723
can.viewer
8824
----------
@@ -97,80 +33,9 @@ The first column is the number of times a frame with the particular ID that has
9733
Command line arguments
9834
^^^^^^^^^^^^^^^^^^^^^^
9935

100-
By default it will be using the :doc:`/interfaces/socketcan` interface. All interfaces supported are supported and can be specified using the ``-i`` argument.
101-
102-
The full usage page can be seen below::
103-
104-
Usage: python -m can.viewer [-h] [--version] [-b BITRATE] [-c CHANNEL]
105-
[-d {<id>:<format>,<id>:<format>:<scaling1>:...:<scalingN>,file.txt}]
106-
[-f {<can_id>:<can_mask>,<can_id>~<can_mask>}]
107-
[-i {iscan,ixxat,kvaser,neovi,nican,pcan,serial,slcan,socketcan,socketcan_ctypes,socketcan_native,usb2can,vector,virtual}]
108-
109-
A simple CAN viewer terminal application written in Python
110-
111-
Optional arguments:
112-
-h, --help Show this help message and exit
113-
--version Show program's version number and exit
114-
-b, --bitrate BITRATE
115-
Bitrate to use for the given CAN interface
116-
-c, --channel CHANNEL
117-
Most backend interfaces require some sort of channel.
118-
For example with the serial interface the channel
119-
might be a rfcomm device: "/dev/rfcomm0" with the
120-
socketcan interfaces valid channel examples include:
121-
"can0", "vcan0". (default: use default for the
122-
specified interface)
123-
-d, --decode {<id>:<format>,<id>:<format>:<scaling1>:...:<scalingN>,file.txt}
124-
Specify how to convert the raw bytes into real values.
125-
The ID of the frame is given as the first argument and the format as the second.
126-
The Python struct package is used to unpack the received data
127-
where the format characters have the following meaning:
128-
< = little-endian, > = big-endian
129-
x = pad byte
130-
c = char
131-
? = bool
132-
b = int8_t, B = uint8_t
133-
h = int16, H = uint16
134-
l = int32_t, L = uint32_t
135-
q = int64_t, Q = uint64_t
136-
f = float (32-bits), d = double (64-bits)
137-
Fx to convert six bytes with ID 0x100 into uint8_t, uint16 and uint32_t:
138-
$ python -m can.viewer -d "100:<BHL"
139-
Note that the IDs are always interpreted as hex values.
140-
An optional conversion from integers to real units can be given
141-
as additional arguments. In order to convert from raw integer
142-
values the values are multiplied with the corresponding scaling value,
143-
similarly the values are divided by the scaling value in order
144-
to convert from real units to raw integer values.
145-
Fx lets say the uint8_t needs no conversion, but the uint16 and the uint32_t
146-
needs to be divided by 10 and 100 respectively:
147-
$ python -m can.viewer -d "101:<BHL:1:10.0:100.0"
148-
Be aware that integer division is performed if the scaling value is an integer.
149-
Multiple arguments are separated by spaces:
150-
$ python -m can.viewer -d "100:<BHL" "101:<BHL:1:10.0:100.0"
151-
Alternatively a file containing the conversion strings separated by new lines
152-
can be given as input:
153-
$ cat file.txt
154-
100:<BHL
155-
101:<BHL:1:10.0:100.0
156-
$ python -m can.viewer -d file.txt
157-
-f, --filter {<can_id>:<can_mask>,<can_id>~<can_mask>}
158-
Comma separated CAN filters for the given CAN interface:
159-
<can_id>:<can_mask> (matches when <received_can_id> & mask == can_id & mask)
160-
<can_id>~<can_mask> (matches when <received_can_id> & mask != can_id & mask)
161-
Fx to show only frames with ID 0x100 to 0x103:
162-
python -m can.viewer -f 100:7FC
163-
Note that the ID and mask are alway interpreted as hex values
164-
-i, --interface {iscan,ixxat,kvaser,neovi,nican,pcan,serial,slcan,socketcan,socketcan_ctypes,socketcan_native,usb2can,vector,virtual}
165-
Specify the backend CAN interface to use.
166-
167-
Shortcuts:
168-
+---------+-------------------------+
169-
| Key | Description |
170-
+---------+-------------------------+
171-
| ESQ/q | Exit the viewer |
172-
| c | Clear the stored frames |
173-
| s | Sort the stored frames |
174-
| SPACE | Pause the viewer |
175-
| UP/DOWN | Scroll the viewer |
176-
+---------+-------------------------+
36+
By default the ``can.viewer`` uses the :doc:`/interfaces/socketcan` interface. All interfaces are supported and can be specified using the ``-i`` argument or configured following :doc:`/configuration`.
37+
38+
The full usage page can be seen below:
39+
40+
.. command-output:: python -m can.viewer -h
41+

0 commit comments

Comments
 (0)