Skip to content

Commit

Permalink
Compatibility with socketcan
Browse files Browse the repository at this point in the history
  • Loading branch information
freol35241 committed Dec 16, 2021
1 parent f36682f commit 6f0cb08
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ services:
network_mode: "host"
environment:
- CLUON_CID=121
- CANBUS_CHANNEL=0
- CANBUS_TYPE=kvaser
- CANBUS_CHANNEL=can0
- CANBUS_TYPE=socketcan
devices:
- "/dev/ttyUSB0:/dev/ttyUSB0"
```
Note: On `socketcan`, the can interface must be "enabled" by issuing the following command: `ip link set can0 up`

## Development setup
To setup the development environment:

Expand All @@ -55,4 +57,4 @@ To run the linters:

To run the tests:

python -m pytest --verbose tests
python -m pytest --verbose tests
7 changes: 4 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
CLUON_CID = env.int("CLUON_CID", 111)
CLUON_SENDER_ID = env.int("CLUON_SENDER_ID", 1)
LOG_LEVEL = env.log_level("LOG_LEVEL", logging.WARNING)
CANBUS_CHANNEL = env.int("CANBUS_CHANNEL", 0)
CANBUSTYPE = env("CANBUSTYPE", "kvaser")
CANBUS_CHANNEL = env("CANBUS_CHANNEL")
CANBUS_TYPE = env("CANBUS_TYPE")

# Setup logger
logging.basicConfig(level=LOG_LEVEL)
Expand Down Expand Up @@ -150,8 +150,9 @@ def cluon_send(message_requests):
source.map(frame_handler).sink(cluon_send)

# Open can bus. Make sure it is the right channel!
channel = int(CANBUS_CHANNEL) if CANBUS_TYPE in ("kvaser",) else CANBUS_CHANNEL
can_bus = can.interface.Bus(
bustype=CANBUSTYPE, channel=CANBUS_CHANNEL, bitrate=500000
bustype=CANBUS_TYPE, channel=channel, bitrate=500000
)

# Start processing messages
Expand Down

0 comments on commit 6f0cb08

Please sign in to comment.