Skip to content

Commit 605e73e

Browse files
committed
Updated README to rst format
1 parent b4176f8 commit 605e73e

File tree

3 files changed

+78
-63
lines changed

3 files changed

+78
-63
lines changed

README.md README.rst

+76-61
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
1-
# python-can-isotp
1+
python-can-isotp
2+
================
3+
4+
What it is
5+
----------
26

3-
## What it is ##
47
A Python wrapper helping the use of [can-isotp Loadable Kernel Module](https://github.com/hartkopp/can-isotp) extending SocketCAN under Linux.
58
It provides a friendly and pythonic interface to interact with SocketCAN using the ISO-TP (ISO-15765-2) protocol.
69

7-
## What it's not ##
10+
What it's not
11+
-------------
12+
813
- An implementation of the ISO-TP protocol. It simplifies the access to the already available features within Python and your operating system
914
- A portable module. It is designed to work under Linux only.
1015
- A way to magically do ISO-TP regardless of your environment. You need to load a module into your Linux kernel before using this. Otherwise, your OS will deny the creation of the socket.
1116
- A revolutionary module. It just makes the syntax easier :)
1217

13-
## Why is it differents from other projects ##
18+
Why is it differents from other projects
19+
----------------------------------------
20+
1421
Other Python libraries enabling the use of ISO-TP protocol makes an implementation of the standard in Python, in the user space.
1522
As mentioned by the authors of SocketCAN in their documentation, this approach has many downsides, mainly when comes to respecting the protocol timings.
1623

1724
The best way do ISO-TP communication is within the kernel space, just like [hartkopp/can-isotp](https://github.com/hartkopp/can-isotp) module does by using a socket interface following the mentality of SocketCAN. The well known duality between complexity and flexibility makes the usage of sockets onerous and non-intuitive to the uninitiated. This is where this project becomes handy, it wraps the socket object so that a programmer can configure and use it quickly, in an intuitive way.
1825

1926
Also, it will tells you if you do something wrong, like setting a socket options after binding the socket to the addresse. The native implementation will silently ignore the options, which can causes some headaches!
2027

21-
## Troubleshooting ##
28+
Troubleshooting
29+
---------------
30+
2231
- **My socket module does not include the `CAN_ISOTP` constant**
2332

2433
That means that your Python version does not include support for ISOTP protocol. It should be included starting from Python 3.7, under Linux build only.
@@ -27,66 +36,72 @@ That means that your Python version does not include support for ISOTP protocol.
2736

2837
The Loadable Kernel Module is not loaded in your Linux kernel. Follow the steps given it the module repository. You needs to compile the module, install the `.ko` file and then run `modprobe can-isotp` as Super User. Then your OS will accept to create a ISO-TP sockets.
2938

30-
## Examples ##
31-
32-
### Without this project ###
33-
```python
34-
SOL_CAN_ISOTP = 106 # These constants exist in the module header, not in Python.
35-
CAN_ISOTP_RECV_FC = 2
36-
# Many more exists.
37-
38-
import socket
39-
import struct
40-
41-
s = socket.socket(socket.AF_CAN, socket.SOCK_DGRAM, socket.CAN_ISOTP)
42-
s2 = socket.socket(socket.AF_CAN, socket.SOCK_DGRAM, socket.CAN_ISOTP)
43-
# Configuring the sockets with ugly struct.pack() that requires knowledge of the LKM structure
44-
s.setsockopt(SOL_CAN_ISOTP, CAN_ISOTP_RECV_FC, struct.pack("=BBB", 0x10, 3,0)) #bs, stmin, wftmax
45-
#s.setsockopt(SOL_CAN_ISOTP, CAN_ISOTP_OPTS, struct.pack(...))
46-
#s.setsockopt(SOL_CAN_ISOTP, CAN_ISOTP_LL_OPTS, struct.pack(...))
47-
48-
s.bind(("vcan0", 0x123, 0x456)) #rxid, txid with confusing order.
49-
s2.bind(("vcan0", 0x456, 0x123)) #rxid, txid
50-
s2.send(b"Hello, this is a long payload sent in small chunks of 8 bytes.")
51-
print(s.recv(4095))
52-
```
53-
54-
### With this project ###
55-
```python
56-
import isotp
57-
58-
s = isotp.socket()
59-
s2 = isotp.socket()
60-
# Configuring the sockets.
61-
s.set_fc_opts(stmin=5, bs=10)
62-
#s.set_general_opts(...)
63-
#s.set_ll_opts(...)
64-
65-
s.bind("vcan0" rxid=0x123 txid=0x456) # We love named parameters!
66-
s2.bind("vcan0", rxid=0x456, txid=0x123)
67-
s2.send(b"Hello, this is a long payload sent in small chunks of 8 bytes.")
68-
print(s.recv())
69-
```
70-
71-
## Don't like playing with a simili-socket ? ##
39+
Examples
40+
--------
41+
42+
Without this project
43+
####################
44+
45+
.. code-block:: python
46+
47+
SOL_CAN_ISOTP = 106 # These constants exist in the module header, not in Python.
48+
CAN_ISOTP_RECV_FC = 2
49+
# Many more exists.
50+
51+
import socket
52+
import struct
53+
54+
s = socket.socket(socket.AF_CAN, socket.SOCK_DGRAM, socket.CAN_ISOTP)
55+
s2 = socket.socket(socket.AF_CAN, socket.SOCK_DGRAM, socket.CAN_ISOTP)
56+
# Configuring the sockets with ugly struct.pack() that requires knowledge of the LKM structure
57+
s.setsockopt(SOL_CAN_ISOTP, CAN_ISOTP_RECV_FC, struct.pack("=BBB", 0x10, 3,0)) #bs, stmin, wftmax
58+
#s.setsockopt(SOL_CAN_ISOTP, CAN_ISOTP_OPTS, struct.pack(...))
59+
#s.setsockopt(SOL_CAN_ISOTP, CAN_ISOTP_LL_OPTS, struct.pack(...))
60+
61+
s.bind(("vcan0", 0x123, 0x456)) #rxid, txid with confusing order.
62+
s2.bind(("vcan0", 0x456, 0x123)) #rxid, txid
63+
s2.send(b"Hello, this is a long payload sent in small chunks of 8 bytes.")
64+
print(s.recv(4095))
65+
66+
With this project
67+
-----------------
68+
69+
.. code-block:: python
70+
71+
import isotp
72+
73+
s = isotp.socket()
74+
s2 = isotp.socket()
75+
# Configuring the sockets.
76+
s.set_fc_opts(stmin=5, bs=10)
77+
#s.set_general_opts(...)
78+
#s.set_ll_opts(...)
79+
80+
s.bind("vcan0" rxid=0x123 txid=0x456) # We love named parameters!
81+
s2.bind("vcan0", rxid=0x456, txid=0x123)
82+
s2.send(b"Hello, this is a long payload sent in small chunks of 8 bytes.")
83+
print(s.recv())
84+
85+
Don't like playing with a simili-socket ?
86+
-----------------------------------------
7287

7388
You don't want to reinvent the wheel by using a fake socket object, but still would like to simplify your work?
7489
Say no more, you can use some helpers availables in the `isotp` module.
7590

76-
``` python
77-
import isotp
78-
import socket
79-
s = socket.socket(socket.AF_CAN, socket.SOCK_DGRAM, socket.CAN_ISOTP) # native socket.
80-
isotp.opts.flowcontrol.write(s, stmin=5)
81-
isotp.opts.general.write(optflags = isotp.opts.flags.CAN_ISOTP_TX_PADDING | isotp.opts.flags.CAN_ISOTP_RX_PADDING)
82-
s.bind(("vcan0", 0x123, 0x456))
83-
```
91+
.. code-block:: python
92+
93+
import isotp
94+
import socket
95+
s = socket.socket(socket.AF_CAN, socket.SOCK_DGRAM, socket.CAN_ISOTP) # native socket.
96+
isotp.opts.flowcontrol.write(s, stmin=5)
97+
isotp.opts.general.write(optflags = isotp.opts.flags.CAN_ISOTP_TX_PADDING | isotp.opts.flags.CAN_ISOTP_RX_PADDING)
98+
s.bind(("vcan0", 0x123, 0x456))
8499
85100
Or you can access the native socket within the wrapper
86101

87-
``` python
88-
import isotp
89-
s = isotp.socket()
90-
s.bind("vcan0", rxid=0x123, txid=0x456)
91-
print(s._socket.getsockname())
92-
```
102+
.. code-block:: python
103+
104+
import isotp
105+
s = isotp.socket()
106+
s.bind("vcan0", rxid=0x123, txid=0x456)
107+
print(s._socket.getsockname())

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[metadata]
2-
description-file = README.md
2+
description-file = README.rst

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
here = path.abspath(path.dirname(__file__))
66

7-
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
7+
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
88
long_description = f.read()
99

1010
setup(

0 commit comments

Comments
 (0)