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

Added script to wirelessly transfer compiled firmware script #294

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions scripts/canflash/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
# CAN Flash

## How to run the cantransfer.sh script

### Check if there is a connection with the pi

Type ``ping [ip address]`` in terminal, where ip address is the ip address of the pi.

### Running the script

Run the script by using the command ``sh cantransfer.sh 'bin_files' 'pi_username' 'host' 'destination_path``.
saadatq marked this conversation as resolved.
Show resolved Hide resolved

Where the inputs are 'bin files' 'pi username' 'ip address' 'destination path':

- Bin files is the path to where the compiled firmware .bin files are located.
- Pi_username is the username of the raspberry pi.
- ip_address is the ip address of the pi.
- Destination path is the folder in the pi where the bin files will be transferred to.

If no directory is given, the bin file will be sent to the home directory of the pi: ``/home/pi_username/``.
39 changes: 39 additions & 0 deletions scripts/canflash/cantransfer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#Check if all arguments have been passed
if [ "$#" -lt 3 ]; then
echo "ERROR enter all arguments: sh cantransfer.sh 'bin_files' 'pi_username' 'IP_ADDRESS' 'destination_path'"
exit 1
fi

BIN_FILE=$1
PI_USERNAME=$2
IP_ADDRESS=$3

# If destination path is set as an argument; it will be set as the destination path
# Otherwise it is set as the PI's home directory
# If the destination path is a file, the path will be the PI's home directory
if [ -d "3SM4" ]; then
DESTINATION_PATH=$4
elif [ -f "3SM4" ]; then
DESTINATION_PATH="/home/$PI_USERNAME"
saadatq marked this conversation as resolved.
Show resolved Hide resolved
else
DESTINATION_PATH="/home/$PI_USERNAME"
fi
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for home/username as the script can only transfer files within this directory. There will be a permission error if you try to transfer a file to a directory that isn't under home/username. For scp, it is assumed the destination directory is relative to /home/username.

i.e. sh cantransfer.sh test.txt username IP new-directory will transfer the file to home/username/new-directory/test.txt


# Check if the bin file exists
if [ ! -f "$BIN_FILE" ]; then
echo "ERROR: File $BIN_FILE not found"
exit 1

saadatq marked this conversation as resolved.
Show resolved Hide resolved
# Check if the path to the PI exists
# Otherwise create create the path in the PI
echo "Check if '$DESTINATION_PATH' exists on the PI..."

ssh "$PI_USERNAME@$IP_ADDRESS" "test -d '$DESTINATION_PATH'"
if [ $? -eq 0 ]; then
echo "Path doesn't exist, creating path in PI..."
ssh "$PI_USERNAME@$IP_ADDRESS" "mkdir -p '$DESTINATION_PATH'"
fi

# Perform file transfer
echo "Transferring $BIN_FILE to $PI_USERNAME@$IP_ADDRESS:$DESTINATION_PATH.."
scp "$BIN_FILE" "$PI_USERNAME@$IP_ADDRESS:$DESTINATION_PATH"
Loading