Skip to content

Commit a175dd5

Browse files
author
Helio
committed
Improve program structure
The only TODO is to clarify the upload_progress function.
1 parent 5a7a154 commit a175dd5

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

bbload

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
#!/bin/bash
22

3-
43
mac_address="$1"
54
file="$2"
65

76

7+
function error() {
8+
cat <<- EOH
9+
$1
10+
11+
Usage: $0 <MAC address> <file>
12+
13+
This tool will upload the file to the BlueBasic device that has that MAC address
14+
Need gatttool installed
15+
EOH
16+
exit 1
17+
}
18+
19+
820
function upload_progress() {
921
progress_character='='
1022
progress_length=20
@@ -35,6 +47,8 @@ function load() {
3547
chunks+=("${hexdump:chunk:180}")
3648
done
3749

50+
upload_progress 0
51+
3852
for chunk in ${!chunks[@]}; do
3953
result="$(gatttool -i hci0 \
4054
-a 0x0031 \
@@ -49,29 +63,14 @@ function load() {
4963
exit 1
5064
fi
5165
done
52-
5366
printf "\n"
54-
exit 0
5567
}
5668

5769

58-
if [[ ! "$mac_address" =~ ^([a-fA-F0-9]{2}:){5}[a-zA-Z0-9]{2}$ ]]; then
59-
error="Wrong MAC address! Example: AA:BB:CC:DD:EE:FF"
70+
if ! [[ "$mac_address" =~ ^([a-fA-F0-9]{2}:){5}[a-zA-Z0-9]{2}$ ]]; then
71+
error "Wrong MAC address! Example: AA:BB:CC:DD:EE:FF"
6072
elif ! [[ -r $file && -f $file ]]; then
61-
error="No such file!"
73+
error "No such file!"
6274
else
6375
load
6476
fi
65-
66-
67-
cat <<- EOH
68-
$error
69-
70-
Usage: $0 <MAC address> <file>
71-
72-
This tool will upload the file to the BlueBasic device that has that MAC address
73-
Need gatttool installed
74-
EOH
75-
76-
77-
exit 1

0 commit comments

Comments
 (0)