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 all 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
23 changes: 23 additions & 0 deletions scripts/canflash/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
# 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 in the Pi.
They will be placed relative to the Raspberry Pi's home directory.

If the directory does not exist in the pi, the script will create the path in the pi relative to the home directory.

If no directory is given in destination path, the bin file will be sent to the home directory of the pi: ``/home/pi_username/``.

49 changes: 49 additions & 0 deletions scripts/canflash/cantransfer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#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 [ ! -z $4 ]; then
echo "4th arguement is: $4"
DESTINATION_PATH=$4
fi

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

# 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 [ ! -z $DESTINATION_PATH ]; then
# Check if the path to the Pi exists
# Otherwise create create the path in the PI
echo "Check if '$DESTINATION_PATH' path exists on the Pi..."

ssh "$PI_USERNAME@$IP_ADDRESS" "test -d /home/$PI_USERNAME/$DESTINATION_PATH"

if [ $? -eq 1 ]; then
echo "Path doesn't exist, creating path in Pi..."
ssh "$PI_USERNAME@$IP_ADDRESS" "mkdir -p '$DESTINATION_PATH'"
else
echo "Path exists in Pi"
fi
fi

# Perform file transfer
if [ ! -z $DESTINATION_PATH ]; then
echo "Transferring $BIN_FILE to $PI_USERNAME@$IP_ADDRESS:$DESTINATION_PATH."
scp "$BIN_FILE" "$PI_USERNAME@$IP_ADDRESS:$DESTINATION_PATH"
else
# If destination path is empty
# The file will be placed in the the home directory
echo "Transferring $BIN_FILE to $PI_USERNAME@$IP_ADDRESS:/home/$PI_USERNAME."
scp "$BIN_FILE" "$PI_USERNAME@$IP_ADDRESS:/home/$PI_USERNAME"
fi
Loading