Merge branch 'master' of https://git.scientificdatasystems.co.uk/robin/useful_linux_scripts
This commit is contained in:
commit
3141c9817f
17
README_CANABLE_V_2_0.txt
Normal file
17
README_CANABLE_V_2_0.txt
Normal file
@ -0,0 +1,17 @@
|
||||
# the CANable V2.0 does not seem to obej the sjw argument.
|
||||
# hence it will miss can bus messages esp 0x0F1FD000 etc.
|
||||
# 10DEC2024
|
||||
|
||||
sudo ip link set dev can0 down
|
||||
sudo ip link set dev can0 up type can bitrate 100000 sjw 4
|
||||
sudo ip link set dev can0 up
|
||||
|
||||
|
||||
#
|
||||
# SJW cannot be changed currently using slcan (which is a serial terminal such as /dev/ttyACM0 linked to the linux kernel)
|
||||
# see
|
||||
# https://github.com/linux-can/can-utils/issues/30
|
||||
# https://github.com/torvalds/linux/commit/80bcf5ec9927
|
||||
#
|
||||
sudo ip --details link show can0
|
||||
|
12
README_USB2CANFD_V1.txt
Normal file
12
README_USB2CANFD_V1.txt
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
|
||||
Commands to get the USB2CANFD V1 working.
|
||||
==========================================
|
||||
|
||||
$ sudo slcand -o -s3 -t hw -S 3000000 /dev/ttyACM0
|
||||
$ sudo ip link set up slcan0
|
||||
|
||||
|
||||
RPC 28NOV2025
|
||||
============================================================
|
@ -140,8 +140,8 @@ export EDITOR vi
|
||||
RED="\[\033[0;31m\]"
|
||||
YELLOW="\[\033[0;33m\]"
|
||||
GREEN="\[\033[0;32m\]"
|
||||
|
||||
PS1="$GREEN\$(date +%Y-%m-%d_%H:%M) \w$RED \$(formattedGitBranch)$GREEN \n\$ "
|
||||
hn=`hostname`
|
||||
PS1="$GREEN\$(date +%Y-%m-%d_%H:%M) $YELLOW $hn $GREEN \w $RED \$(formattedGitBranch)$GREEN \n\$ "
|
||||
|
||||
export PATH="$PATH:"/opt/microchip/xc8/v1.34/bin""
|
||||
|
||||
|
25
can_logging/crontab.list
Normal file
25
can_logging/crontab.list
Normal file
@ -0,0 +1,25 @@
|
||||
# Edit this file to introduce tasks to be run by cron.
|
||||
#
|
||||
# Each task to run has to be defined through a single line
|
||||
# indicating with different fields when the task will be run
|
||||
# and what command to run for the task
|
||||
#
|
||||
# To define the time you can provide concrete values for
|
||||
# minute (m), hour (h), day of month (dom), month (mon),
|
||||
# and day of week (dow) or use '*' in these fields (for 'any').
|
||||
#
|
||||
# Notice that tasks will be started based on the cron's system
|
||||
# daemon's notion of time and timezones.
|
||||
#
|
||||
# Output of the crontab jobs (including errors) is sent through
|
||||
# email to the user the crontab file belongs to (unless redirected).
|
||||
#
|
||||
# For example, you can run a backup of all your user accounts
|
||||
# at 5 a.m every week with:
|
||||
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
|
||||
#
|
||||
# For more information see the manual pages of crontab(5) and cron(8)
|
||||
#
|
||||
# m h dom mon dow command
|
||||
25 8 * * * /home/robin/reset_can.sh >> /home/robin/can_logs/cronlog.log 2>&1
|
||||
#34 10 * * * /home/robin/reset_can.sh >> /home/robin/can_logs/cronlog.log 2>&1
|
39
can_logging/reset_can.sh
Executable file
39
can_logging/reset_can.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
|
||||
# crontab starts bash minimally, so
|
||||
export PATH=/usr/local/bin:/usr/bin:/bin
|
||||
|
||||
# debugging
|
||||
set -eux
|
||||
|
||||
sudo ip link set can0 down || { echo "Failed to bring down CAN interface"; exit 1; }
|
||||
|
||||
# NON FD or classical only set up
|
||||
# sudo ip link set can0 type can bitrate 100000 sjw 128
|
||||
sudo ip link set can0 type can bitrate 100000 sjw 128 dbitrate 400000 fd on
|
||||
sudo ip link set can0 up
|
||||
|
||||
mkdir -p ~/can_logs
|
||||
cd ~/can_logs/
|
||||
|
||||
d=`date`
|
||||
|
||||
echo "-----------------------------------------------------------" >> can_reset_log.txt
|
||||
/usr/sbin/ifconfig can0 >> can_reset_log.txt
|
||||
echo "CAN NOW RESET" $d >> can_reset_log.txt
|
||||
sudo ip link show can0 >> can_reset_log.txt
|
||||
echo "-----------------------------------------------------------" >> can_reset_log.txt
|
||||
|
||||
# Compress any old log files
|
||||
#
|
||||
find . -type f -name "*.log" -exec zip {}.zip {} \;
|
||||
# delete uncompressed log files
|
||||
find . -type f -name "*.log" -exec rm -f {} \;
|
||||
|
||||
/usr/bin/candump -l -t A can0 &
|
||||
|
||||
|
||||
# Find and delete .log.zip files older than one month
|
||||
#
|
||||
find . -type f -name "*.log.zip" -mtime +30 -exec rm -f {} \;
|
||||
|
16
git_hub_reset_codes.txt
Normal file
16
git_hub_reset_codes.txt
Normal file
@ -0,0 +1,16 @@
|
||||
b2ef2-46e05
|
||||
1bd6d-f3a35
|
||||
57c22-85e82
|
||||
31fde-6551c
|
||||
78bb1-c8f88
|
||||
633a1-0c05b
|
||||
1e3c0-e3e77
|
||||
e7aad-62ae5
|
||||
60d1a-9ee24
|
||||
b8e33-f7b1d
|
||||
2580a-5fb93
|
||||
47db7-000df
|
||||
05667-25d14
|
||||
08460-3cc2a
|
||||
e6aba-cc300
|
||||
7dde9-81492
|
29
ppt2png.sh
Executable file
29
ppt2png.sh
Executable file
@ -0,0 +1,29 @@
|
||||
#!/usr/bin/bash
|
||||
################################################################################
|
||||
# Generate temporary file safely
|
||||
temp_file=$(mktemp)
|
||||
ppt "$1" > "$temp_file"
|
||||
|
||||
# Count lines directly
|
||||
line_count=$(wc -l < "$temp_file")
|
||||
|
||||
# Calculate image height (e.g., 20 pixels per line, with a minimum height)
|
||||
line_height=20
|
||||
image_height=$((line_count * line_height))
|
||||
[ "$image_height" -lt 70 ] && image_height=70 # Ensure a minimum height of 70 pixels
|
||||
|
||||
# Generate image with dynamic height and fixed-width font
|
||||
convert \
|
||||
-size 165x${image_height} \
|
||||
xc:lightblue \
|
||||
-font Courier \
|
||||
-pointsize 12 \
|
||||
-fill blue \
|
||||
-gravity center \
|
||||
-draw "text 0,0 '$(cat "$temp_file")'" \
|
||||
image.png
|
||||
|
||||
# Clean up temporary file
|
||||
gwenview image.png
|
||||
rm $temp_file
|
||||
################################################################################
|
32
reset_can.sh
Executable file
32
reset_can.sh
Executable file
@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
sudo ip link set can0 down
|
||||
# NON FD or classical only set up
|
||||
# sudo ip link set can0 type can bitrate 100000 sjw 128
|
||||
sudo ip link set can0 type can bitrate 100000 sjw 128 dbitrate 400000 fd on
|
||||
sudo ip link set can0 up
|
||||
|
||||
mkdir -p ~/can_logs
|
||||
cd ~/can_logs/
|
||||
|
||||
d=`date`
|
||||
|
||||
echo "-----------------------------------------------------------" >> can_reset_log.txt
|
||||
ifconfig can0 >> can_reset_log.txt
|
||||
echo "CAN NOW RESET" $d >> can_reset_log.txt
|
||||
sudo ip link show can0 >> can_reset_log.txt
|
||||
echo "-----------------------------------------------------------" >> can_reset_log.txt
|
||||
|
||||
# Compress any old log files
|
||||
#
|
||||
find . -type f -name "*.log" -exec zip {}.zip {} \;
|
||||
# delete uncompressed log files
|
||||
find . -type f -name "*.log" -exec rm -f {} \;
|
||||
|
||||
/usr/bin/candump -l -t A can0 &
|
||||
|
||||
|
||||
# Find and delete .log.zip files older than one month
|
||||
#
|
||||
find . -type f -name "*.log.zip" -mtime +30 -exec rm -f {} \;
|
||||
|
101
set_up_can_usb.md
Normal file
101
set_up_can_usb.md
Normal file
@ -0,0 +1,101 @@
|
||||
|
||||
|
||||
# Example binding slcan to a USB tty serial port
|
||||
sudo slcand -o -s3 -t hw -S 3000000 /dev/ttyACM3
|
||||
sudo ip link set dev can0 up type can bitrate 100000
|
||||
|
||||
# Example seting up can0 for an SDS CAN HAT for Raspberry pi
|
||||
|
||||
sudo ip link set can0 down
|
||||
sudo ip link set can0 type can bitrate 100000 sjw 128
|
||||
sudo ip link set can0 up
|
||||
|
||||
|
||||
|
||||
# to upgrade usb devices in chromium
|
||||
|
||||
Creating a udev rule to grant write permissions to a USB device and automate updating a dongle involves the following steps:
|
||||
1. Identify the USB Device
|
||||
|
||||
Plug in the USB device or dongle and identify its attributes using lsusb or udevadm.
|
||||
Using lsusb:
|
||||
|
||||
Run:
|
||||
|
||||
lsusb
|
||||
|
||||
Find your device in the list. It will look something like this:
|
||||
|
||||
Bus 001 Device 004: ID 1234:5678 Vendor_Name Product_Name
|
||||
|
||||
Vendor ID: 1234
|
||||
Product ID: 5678
|
||||
|
||||
Using udevadm:
|
||||
|
||||
Run:
|
||||
|
||||
udevadm info --query=all --name=/dev/bus/usb/001/004
|
||||
|
||||
(Replace 001 and 004 with the values from lsusb.)
|
||||
|
||||
This command provides detailed information about the device, such as the idVendor and idProduct.
|
||||
2. Create a udev Rule
|
||||
|
||||
Create a new file for your custom udev rules in /etc/udev/rules.d/.
|
||||
|
||||
For example:
|
||||
|
||||
sudo nano /etc/udev/rules.d/99-usb-dongle.rules
|
||||
|
||||
Add the following rule:
|
||||
|
||||
SUBSYSTEM=="usb", ATTR{idVendor}=="1234", ATTR{idProduct}=="5678", MODE="0666"
|
||||
|
||||
Replace 1234 and 5678 with your device's Vendor and Product IDs.
|
||||
MODE="0666" grants read and write permissions to all users. For more restricted access, specify a group and set group ownership (e.g., GROUP="usbusers" and MODE="0660").
|
||||
|
||||
3. Reload udev Rules
|
||||
|
||||
After saving the rule, reload udev rules and trigger them:
|
||||
|
||||
sudo udevadm control --reload-rules
|
||||
sudo udevadm trigger
|
||||
|
||||
4. Test Permissions
|
||||
|
||||
Unplug and replug your device, then check the permissions:
|
||||
|
||||
ls -l /dev/bus/usb/001/004
|
||||
|
||||
(Replace 001 and 004 with the actual bus and device numbers.)
|
||||
|
||||
It should now show the updated permissions.
|
||||
5. Automate Dongle Updates
|
||||
|
||||
If you have a script or tool to update the dongle, ensure it runs as the user with proper permissions. For example, create an update script:
|
||||
|
||||
#!/bin/bash
|
||||
echo "Updating dongle..."
|
||||
# Replace with the actual command to update your dongle
|
||||
your-update-command --device=/dev/bus/usb/001/004
|
||||
|
||||
Make it executable:
|
||||
|
||||
chmod +x update_dongle.sh
|
||||
|
||||
Run the script after ensuring permissions are correct.
|
||||
6. Optional: Match by Serial Number or Other Attributes
|
||||
|
||||
If multiple devices share the same Vendor/Product IDs, you can refine the rule by matching additional attributes like serial, idProduct, or idVendor.
|
||||
|
||||
Example:
|
||||
|
||||
SUBSYSTEM=="usb", ATTR{idVendor}=="1234", ATTR{idProduct}=="5678", ATTR{serial}=="ABCDEFG12345", MODE="0666"
|
||||
|
||||
You can find these attributes using:
|
||||
|
||||
udevadm info --attribute-walk --name=/dev/bus/usb/001/004
|
||||
|
||||
|
||||
|
20
time_stamp.py
Normal file
20
time_stamp.py
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
|
||||
# Time stamp CAN messages from the serial stream.
|
||||
|
||||
import sys
|
||||
from datetime import datetime
|
||||
import io
|
||||
|
||||
def add_timestamp_to_lines():
|
||||
# Ensure stdin is read with a fallback encoding
|
||||
with io.TextIOWrapper(sys.stdin.buffer, encoding='ISO8859-1', errors='replace') as stdin:
|
||||
for line in stdin:
|
||||
if 'CANMSG' in line or 'CMQ' in line:
|
||||
timestamp = datetime.now().strftime("[%Y-%m-%d %H:%M:%S.%f] ")
|
||||
sys.stdout.write(timestamp + line)
|
||||
#else:
|
||||
#sys.stdout.write(line)
|
||||
|
||||
if __name__ == "__main__":
|
||||
add_timestamp_to_lines()
|
Loading…
Reference in New Issue
Block a user