File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 3
3
mac_address=" $1 "
4
4
file=" $2 "
5
5
6
+ function progress_bar() {
7
+ progress_character=' ='
8
+ percent_bar=" $( head -c " $(( $1 / 5 )) " < /dev/zero | tr ' \0' $progress_character ) "
9
+ percent_bar=" ${percent_bar} $( printf " %$(( 20 - ($1 / 5 )) )s" ) "
10
+ printf " \rLoading... [%s] (%s%%)" " $percent_bar " " $1 "
11
+ }
12
+
6
13
function load() {
14
+ counter=0
15
+ lines=$( wc -l < $file )
16
+ progress_bar 0
7
17
while read line; do
8
18
line=$( printf ' %s\r' " $line " | xxd -p | tr -d ' \n' )
9
- gatttool -i hci0 -b " $mac_address " --char-write-req -a 0x0031 -n $line
19
+ gatttool -i hci0 \
20
+ -n $line \
21
+ -a 0x0031 \
22
+ -b " $mac_address " \
23
+ --char-write-req 1> /dev/null
24
+ (( counter++ ))
25
+ percentage=" $( bc <<< " scale=2; (${counter}/${lines})*100" ) "
26
+ progress_bar " ${percentage% .* } "
10
27
done < $file
28
+ printf " \n"
11
29
}
12
30
13
31
if [[ ! " $mac_address " =~ ^([a-fA-F0-9]{2}:){5}[a-zA-Z0-9]{2}$ ]]; then
14
32
error=" Wrong MAC address! Example: AA:BB:CC:DD:EE:FF"
15
- elif [[ ! -r $file && -f $file ]]; then
33
+ elif ! [[ -r $file && -f $file ]]; then
16
34
error=" No such file!"
17
35
else
18
36
load
You can’t perform that action at this time.
0 commit comments