Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAN test interface support #70

Merged
merged 10 commits into from
Mar 11, 2023
Merged

Conversation

hhenry01
Copy link
Member

@hhenry01 hhenry01 commented Dec 12, 2022

Description

Creates a vcan interface inside the docker container so we can test programs that utilize CAN without physical hardware.

Verification

  • Commands work in dev container
  • Commands work in deployment container
  • Commands work on RPi

@hhenry01 hhenry01 added infrastructure sim Boat Simulator team labels Dec 12, 2022
@hhenry01 hhenry01 self-assigned this Dec 12, 2022
@hhenry01 hhenry01 linked an issue Dec 12, 2022 that may be closed by this pull request
@hhenry01 hhenry01 force-pushed the user/hhenry01/52-can-interface-support branch 2 times, most recently from 3755be8 to 2a65ced Compare December 12, 2022 06:58
@hhenry01 hhenry01 marked this pull request as ready for review December 12, 2022 07:16
@hhenry01
Copy link
Member Author

hhenry01 commented Dec 12, 2022

@patrick-5546 when you review this, can you do the following?

  1. Pull and rebuild the container.
  2. In one terminal, enter candump vcan0
  3. Open a new terminal, enter cansend 012#12.34
  4. Make sure that the first terminal where you ran candump updates after executing the command in the second terminal.
    The online sources I read mentioned needing to enable the vcan driver locally with sudo modprobe vcan before it will work. I unloaded the driver and it still worked which is not consistent with what the online resources said, so I might not have done it properly. If it works then it should work fine with WSL setups. No clue whether it will work on Mac or Arch though.

@hhenry01 hhenry01 force-pushed the user/hhenry01/52-can-interface-support branch from 2a65ced to 461c6e2 Compare December 12, 2022 07:22
@patrick-5546
Copy link
Member

patrick-5546 commented Jan 13, 2023

@patrick-5546 patrick-5546 marked this pull request as draft January 13, 2023 21:27
@patrick-5546
Copy link
Member

@patrick-5546 patrick-5546 marked this pull request as ready for review January 19, 2023 21:59
Copy link
Member

@patrick-5546 patrick-5546 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@patrick-5546 when you review this, can you do the following?

This is what I get running the commands on WSL:

ros@docker-desktop:/workspaces/sailbot_workspace$ candump vcan0
socket: Address family not supported by protocol
ros@docker-desktop:/workspaces/sailbot_workspace$ sudo modprobe vcan
sudo: modprobe: command not found
ros@docker-desktop:/workspaces/sailbot_workspace$ cansend 012#12.34
cansend - send CAN-frames via CAN_RAW sockets.

Usage: cansend <device> <can_frame>.

<can_frame>:
 <can_id>#{data}          for 'classic' CAN 2.0 data frames
 <can_id>#R{len}          for 'classic' CAN 2.0 data frames
 <can_id>##<flags>{data}  for CAN FD frames

<can_id>:
 3 (SFF) or 8 (EFF) hex chars
{data}:
 0..8 (0..64 CAN FD) ASCII hex-values (optionally separated by '.')
{len}:
 an optional 0..8 value as RTR frames can contain a valid dlc field
<flags>:
 a single ASCII Hex value (0 .. F) which defines canfd_frame.flags

Examples:
  5A1#11.2233.44556677.88 / 123#DEADBEEF / 5AA# / 123##1 / 213##311223344 /
  1F334455#1122334455667788 / 123#R / 00000123#R3

Are the commands supposed to be run inside or outside the dev container?

@patrick-5546
Copy link
Member

To get vcan running on WSL: linux-can/can-utils#46 (comment)

@patrick-5546
Copy link
Member

To get vcan running on WSL: linux-can/can-utils#46 (comment)

Wasn't able to get this working, plus it seems like a pain to compile a custom kernel. Can you take a look at this? https://github.com/wsovalle/docker-vxcan

@patrick-5546
Copy link
Member

Is this still valid?

@hhenry01 hhenry01 force-pushed the user/hhenry01/52-can-interface-support branch 2 times, most recently from e03577b to d671674 Compare March 3, 2023 05:09
@hhenry01
Copy link
Member Author

hhenry01 commented Mar 3, 2023

Reworked the PR based on recent container changes. If a vcan0 or can0 device is setup on the host then the start_container.sh script will set it up within the docker container. I could only test with vcan0 because we don't have a physical hardware setup atm.

@hhenry01 hhenry01 force-pushed the user/hhenry01/52-can-interface-support branch from d671674 to d093b54 Compare March 3, 2023 05:17
Copy link
Member

@patrick-5546 patrick-5546 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the output of the script the first time I run it, is this what is intended?

Error response from daemon: No such container: sailbot
Error: No such container: sailbot
Running: docker run -it --name sailbot -v /home/pcrei/git/tmp/sailbot_workspace/.devcontainer/deployment/../..:/workspaces/sailbot_workspace -w /workspaces/sailbot_workspace --cap-add=SYS_PTRACE --cap-add=NET_ADMIN --network=host --security-opt=seccomp:unconfined --security-opt=apparmor:unconfined --pull always ghcr.io/ubcsailbot/sailbot_workspace/base:can_support /bin/bash
./start_container.sh: line 44: ifconfig: command not found
./start_container.sh: line 48: ifconfig: command not found
can_support: Pulling from ubcsailbot/sailbot_workspace/base
Digest: sha256:2e2d4f79735a2f8293a2b582d04ff3970238732972eb0384db3c34201477bf10
Status: Image is up to date for ghcr.io/ubcsailbot/sailbot_workspace/base:can_support
root@docker-desktop:/workspaces/sailbot_workspace#

Also can you update the deployment README with the CAN stuff?

@hhenry01
Copy link
Member Author

hhenry01 commented Mar 3, 2023

This is the output of the script the first time I run it, is this what is intended?

Error response from daemon: No such container: sailbot
Error: No such container: sailbot
Running: docker run -it --name sailbot -v /home/pcrei/git/tmp/sailbot_workspace/.devcontainer/deployment/../..:/workspaces/sailbot_workspace -w /workspaces/sailbot_workspace --cap-add=SYS_PTRACE --cap-add=NET_ADMIN --network=host --security-opt=seccomp:unconfined --security-opt=apparmor:unconfined --pull always ghcr.io/ubcsailbot/sailbot_workspace/base:can_support /bin/bash
./start_container.sh: line 44: ifconfig: command not found
./start_container.sh: line 48: ifconfig: command not found
can_support: Pulling from ubcsailbot/sailbot_workspace/base
Digest: sha256:2e2d4f79735a2f8293a2b582d04ff3970238732972eb0384db3c34201477bf10
Status: Image is up to date for ghcr.io/ubcsailbot/sailbot_workspace/base:can_support
root@docker-desktop:/workspaces/sailbot_workspace#

Also can you update the deployment README with the CAN stuff?

Not expected. I forgot that pulling the docker container can take a while, so the hacky 1 second delay to setup CAN won't work. Will need to rethink how to do it.

Also, what OS are you running that doesn't have ifconfig?

@patrick-5546
Copy link
Member

Also, what OS are you running that doesn't have ifconfig?

ifconfig is deprecated, so it is not included in Ubuntu 22.04. Can use ip instead or sudo apt install net-tools -y to get it.

@hhenry01
Copy link
Member Author

hhenry01 commented Mar 4, 2023

Updated the script and README. Uses ip a instead of ifconfig now. Instead of a set delay it now waits for the container to be in the "running" state before setting up CAN. And if for whatever reason the parent run container process dies unexpectedly then it can detect it, stop polling, and exit.

@hhenry01
Copy link
Member Author

hhenry01 commented Mar 4, 2023

So I messed up and wasted a bunch of my time with that forking stuff. So long as --network=host is set and --cap-add=NET_ADMIN is set then any CAN device setup on the host will automatically be accessible.

@patrick-5546
Copy link
Member

patrick-5546 commented Mar 4, 2023

@patrick-5546 when you review this, can you do the following?

  1. Pull and rebuild the container.
  2. In one terminal, enter candump vcan0
  3. Open a new terminal, enter cansend 012#12.34
  4. Make sure that the first terminal where you ran candump updates after executing the command in the second terminal.
    The online sources I read mentioned needing to enable the vcan driver locally with sudo modprobe vcan before it will work. I unloaded the driver and it still worked which is not consistent with what the online resources said, so I might not have done it properly. If it works then it should work fine with WSL setups. No clue whether it will work on Mac or Arch though.

I forgot, are these commands supposed to be run inside our outside the container?

@hhenry01
Copy link
Member Author

hhenry01 commented Mar 4, 2023

@patrick-5546 when you review this, can you do the following?

  1. Pull and rebuild the container.
  2. In one terminal, enter candump vcan0
  3. Open a new terminal, enter cansend 012#12.34
  4. Make sure that the first terminal where you ran candump updates after executing the command in the second terminal.
    The online sources I read mentioned needing to enable the vcan driver locally with sudo modprobe vcan before it will work. I unloaded the driver and it still worked which is not consistent with what the online resources said, so I might not have done it properly. If it works then it should work fine with WSL setups. No clue whether it will work on Mac or Arch though.

I forgot, are these commands supposed to be run inside our outside the container?

Inside the container. Since opening multiple terminals inside the container is a bit annoying, run candump vcan0 & instead so you don't have to open a new terminal. You must have vcan0 setup on your host computer for this to work.

@hhenry01
Copy link
Member Author

hhenry01 commented Mar 4, 2023

Tested on the Rpi and it works. I also added setup_boot.sh which I intend to use to configure any scripts/programs that need to run on boot. Doing it this way is way easier to manage than how I did services with Raye.

@hhenry01 hhenry01 merged commit 762cef0 into main Mar 11, 2023
@patrick-5546 patrick-5546 deleted the user/hhenry01/52-can-interface-support branch March 12, 2023 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infrastructure sim Boat Simulator team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CAN Interface Support
2 participants