Switching between can and vcan - socketcan

I have read the documentation and I know that:
To enable a real can you do
$ sudo ip link set can0 type can bitrate 125000
$ sudo ip link set up can0
and to enable a vcan you do
$ modprobe vcan
$ sudo ip link add dev vcan0 type vcan
$ sudo ip link set up vcan0
In my case, I even disable vcan before enabling can as in
$ sudo ip link set dev vacn0 down
$ sudo ip link set can0 type can bitrate 125000
$ sudo ip link set up can0
My question is how about the opposite? (Going from can to vcan)?
If my can is up , should I disable it before enabling vcan? and how?
and also enabling vcan uses add not set... why?

There is no connection between real CAN network devices and virtual CAN devices, other than they share the same socket interface.
What you've shown here is how you make either kind of CAN device (real or virtual) active and set it up.
How you'd switch between one and the other in your application should be as simple as using one or the other name for the network device.
You can have real CAN and virtual CAN devices available and up at the same time with no concerns.
As for why you need to add your vcan0 device but not to add your real can0 device, the operating system usually detects your CAN hardware and creates the device automatically.
One exception to this is if you're using a CAN-to-serial adapter with slcand, where you would need to run slcand first (and it will create devices named like slcan0):
$ sudo slcand -o -s8 -t hw -S 3000000 /dev/ttyUSB0
$ sudo ip link set up slcan0

Related

Deactivate macport

I am trying to install the macport demeter using the following line in mac terminal:
sudo port install demeter
I get the error message
Error: Failed to activate demeter: Image error: /opt/local/lib/perl5/vendor_perl/5.34/darwin-thread-multi-2level/Ifeffit.pm is being used by the active p5.34-ifeffit port. Please deactivate this port first, or use 'port -f activate demeter' to force the activation.
I have two questions:
(1) Why am I getting this error message? Have I accidentally got two copies of demeter?
(2) How can I deactivate this port? (I'd rather deactivate it then use the force activate option)
When I run
sudo lsof -i -n -P | grep TCP
I can't actually see 'p5.34-ifeffit port' in the list of ports.
This is a bug in the demeter port. It should not install the files of the ifeffit perl module, but instead declare a dependency on p5.34-ifeffit.
Please file a ticket at https://trac.macports.org/newticket.
You can force the activation, but that will overwrite the file(s) in question with the copies from the demeter port. Uninstalling that port later will delete those files, which may then in turn break other software that relies on p5.34-ifeffit.
I'm not experienced with Demeter but you might try asking for help on the MacPorts users mailing list:
https://lists.macports.org/mailman/listinfo/macports-users
Or raise a ticket on the MacPorts Trac system:
https://trac.macports.org/newticket?port=demeter
Craig

qemu doesn't recognize block device file

I have a working QEMU image emulating an ARM vexpress-a9 and I run it like so:
sudo qemu-system-arm -m 512M -M vexpress-a9 -D qemu.log -d unimp -kernel buildroot-2019.02.5/output/images/zImage -dtb buildroot-2019.02.5/output/images/vexpress-v2p-ca9.dtb -append "console=ttyAMA0,115200 kgdboc=kbd,ttyAMA0,115200 ip=dhcp nokaslr" -initrd buildroot-2019.02.5/output/images/rootfs.cpio -nographic -net nic -net bridge,br=mybridge -s
I would now like to add a hard disk for persistent storage and then transfer control from busybox initrd based rootfs over to the full fledged version offered with Linux. So I add it to the command line
sudo qemu-system-arm -m 1024M -M vexpress-a9 -D qemu.log -drive if=none,format=raw,file=disk.img -kernel buildroot-2019.02.5/output/images/zImage -dtb buildroot-2019.02.5/output/images/vexpress-v2p-ca9.dtb -append "console=ttyAMA0,115200 kgdboc=kbd,ttyAMA0,115200 ip=dhcp nokaslr" -initrd buildroot-2019.02.5/output/images/rootfs.cpio -nographic -net nic -net bridge,br=mybridge -s
of course I first create a disk image and format it as ext2:
qemu-img create disk.img 10G && mkfs.ext2 -F disk.img
From the log messages I see that it has not been able to detect this at all. I think I need to understand how block devices work with Qemu. I know the older -hda has been changed to a newer -drive option can combines the cumbersome specification of the front and back ends separately. But I don't know the basics and why I am getting this problem.
I am basically looking to switch_root from initrd to the full fledged Linux rootfs but this is only the first step.
From the log messages I see that it has not been able to detect this at all.
That's because you haven't created QEMU device connected to that drive.
I think I need to understand how block devices work with Qemu.
You have front-ends that represent some kind of hardware to the guest and you have back-ends that interact with backing storage on the host. You create a front-end with -device option and block back-end with -drive option. You give the drive an id and refer to that id from the device. E.g. this is how I attach virtio-blk-pci device to a disk image on my virt machine: -device virtio-blk-pci,drive=vd0 -drive file=rootfs.ext2,format=raw,id=vd0.
qemu-system-arm -device help will give you the list of supported device types and qemu-system-arm -device <specific-device-type>,help will show detailed help for specific-device-type properties.

How do I run wireguard (or wg-quick) for a single program?

I need to run wireguard only for a single program, and have the rest of my system not use it. Is this possible or doable? I'm currently using wg-quick
Yes you can, using network namespaces.
First let's create the wireguard namespace:
ip netns add wireguard
Then, we create a wireguard interface in your standard namespace
ip link add wg0 type wireguard
(You can configure the interface here)
We move it to the wireguard namespace
ip link set wg0 netns wireguard
And now, you can run a process in the wireguard namespace using
sudo -E ip netns exec wireguard sudo -E -u \#$(id -u) -g \#$(id -g) YOUR_PROCESS_CMD
You should read this for more information: https://www.wireguard.com/netns

Read serial port from micaz

I would like to know if there is a mean to read in a terminal outputs generated by a MicaZ (printf), I tried the command: make login but it doesn't work.
I think that the is no rule login in micaz makefile.
Try command:
sudo cat /dev/ttyUSB1
Before doing this, check that your Micaz is connected through ttyUSB1.
You can check it using command:
ls /dev
If ttyUSB1 is in the list above, it will work.
As far as I remember the MIB510 board, used to program the MicaZ, has two serial ports. One for ISP and the other as a serial console. You might also want to use minicom to be able to fully interact with the serial console. On ubuntu you can install it with sudo apt-get install minicom and is run with minicom -8 -b9600 -D/dev/ttyUSB1 set the baudrate according to your setup.
Here you can find an introduction to minicom.
Good luck!

There is a new relic clone for arm (Raspberry PI)?

I need to monitor the performance of a raspberry PI (with raspbian), I tried to use new relic, but it doesn't support ARM architecture, so it's impossible to use.
I even tried graphdat but seems to have the same problem.
Any alternative to suggest me?
Linode Longview does support arm architecture:
https://www.linode.com/longview
The free tier have 12-hour retention but that may be enough for most cases.
I know this is old, but New Relic has ARM and ARM64 infrastructure agents now:
https://download.newrelic.com/infrastructure_agent/binaries/linux/arm/
I've tested this on a Raspberry Pi 4 (8GB) on Debian (32-bit) and it's been working fine so far.
In case anyone else tries, here's what I did:
Download the Infrastructure Agent:
sudo curl https://download.newrelic.com/infrastructure_agent/binaries/linux/arm/newrelic-infra_linux_1.20.5_arm.tar.gz --output newrelic-infra_linux_1.20.5_arm.tar.gz
Extract the files
sudo tar -xf newrelic-infra_linux_1.20.5_arm.tar.gz
Add license key to the config script:
echo "license_key=\"<YOUR_LICENSE_KEY>\"" | sudo tee -a ~/newrelic-infra/config_defaults.sh
Install the Infrastructure Agent
sudo ~/newrelic-infra/installer.sh
Check service status to make sure it's running:
sudo systemctl status newrelic-infra
By default, process information is not sent to New Relic, so I had to enable it manually:
echo "enable_process_metrics: true" | sudo tee -a /etc/newrelic-infra.yml
Finally, restart the service:
sudo systemctl restart newrelic-infra

Resources