From 7e3b6d7c60d3d85cebdc9a37c95ad9c8c92a2e6e Mon Sep 17 00:00:00 2001 From: Emran Billah Date: Fri, 2 Aug 2024 10:47:47 -0300 Subject: [PATCH] Adding script to flash multiple devices at a time, to ensure consistent configuration across all connected devices --- .env | 7 +++++-- docker-compose-flash-device.yml | 16 ++++++++++++++++ docker-compose-test-stadalone.yml | 1 - flash-devices-batch.sh | 31 +++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 flash-devices-batch.sh diff --git a/.env b/.env index e60bc79..e6be02f 100644 --- a/.env +++ b/.env @@ -1,2 +1,5 @@ -DEVICE_PATH=/dev/ttyUSB1 -BAUD_RATE=230400 \ No newline at end of file +DEVICES=" + /dev/ttyUSB0,230400 + /dev/ttyUSB1,230400 + /dev/ttyUSB2,230400 +" \ No newline at end of file diff --git a/docker-compose-flash-device.yml b/docker-compose-flash-device.yml index b6ca7d0..304b84f 100644 --- a/docker-compose-flash-device.yml +++ b/docker-compose-flash-device.yml @@ -1,3 +1,19 @@ +# Flash Xbee devices +# --------------------------------------------------------------------------------- +# 1. To flash a single device, modify the .env file like shown below: +# DEVICE_PATH=/dev/ttyUSB0 +# BAUD_RATE=230400 +# Then use the cmd: docker compose -f docker-compose-flash-device.yml up --build +# +# 2. To flash multiple devices, modify the .env file like shown below: +# DEVICES=" +# /dev/ttyUSB0,230400 +# /dev/ttyUSB1,230400 +# /dev/ttyUSB2,230400 +# " +# Then run the bash script using: sh ./flash-devices-batch.sh +# ----------------------------------------------------------------------------------- + version: "3.8" services: diff --git a/docker-compose-test-stadalone.yml b/docker-compose-test-stadalone.yml index d2d3001..7118b1f 100644 --- a/docker-compose-test-stadalone.yml +++ b/docker-compose-test-stadalone.yml @@ -26,7 +26,6 @@ services: - sim_network xbee-mav: - # command: rosrun xbee_ros_node xbee_config /dev/ttyUSB0 230400 command: tail -f /dev/null depends_on: - ros-master diff --git a/flash-devices-batch.sh b/flash-devices-batch.sh new file mode 100644 index 0000000..3307b67 --- /dev/null +++ b/flash-devices-batch.sh @@ -0,0 +1,31 @@ +# flash-devices-batch.sh +# Expects .env file to have the following structure: +# +# DEVICES=" +# /dev/ttyUSB0,230400 +# /dev/ttyUSB1,230400 +# /dev/ttyUSB2,230400 +# " +# + +#!/bin/sh + +# Load environment variables from .env file +. ./.env + +# Iterate over each device in the DEVICES string +for device in $DEVICES; do + # Split the device string into path and baud rate + DEVICE_PATH=$(echo $device | cut -d',' -f1) + BAUD_RATE=$(echo $device | cut -d',' -f2) + + # Export the variables for docker-compose to use + export DEVICE_PATH + export BAUD_RATE + + # Run docker-compose with the current device + docker compose -f docker-compose-flash-device.yml up --build + + # Optionally, bring down the containers after each run + docker compose -f docker-compose-flash-device.yml down +done