File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
mac_address=" $1 "
4
4
file=" $2 "
5
-
5
+ handle= " 0x0021 "
6
6
7
7
function error() {
8
8
cat << - EOH
@@ -37,21 +37,29 @@ function upload_progress() {
37
37
function load() {
38
38
hexdump=" "
39
39
chunks=()
40
+ eol=13
40
41
41
42
while read line; do
42
43
line=$( printf ' %s\r' " $line " | xxd -p | tr -d ' \n' )
43
44
hexdump+=" $line "
44
45
done < $file
45
46
46
- for (( chunk= 0 ; chunk< ${# hexdump} ; chunk+= 180 )) ; do
47
- chunks+=(" ${hexdump: chunk: 180} " )
47
+ length=(${# hexdump} )
48
+ for (( chunk= 0 ; chunk< length; )) ; do
49
+ byte=0
50
+ buffer=" "
51
+ for (( count= 0 ; ((chunk< length && byte != eol && count < 20 )) ; count++, chunk+=2)); do
52
+ byte=(" 0x${hexdump: chunk: 2} " )
53
+ buffer+=" ${hexdump: chunk: 2} "
54
+ done
55
+ chunks+=(" $buffer " )
48
56
done
49
57
50
58
upload_progress 0
51
59
52
60
for chunk in ${! chunks[@]} ; do
53
61
result=" $( gatttool -i hci0 \
54
- -a 0x0031 \
62
+ -a " $handle " \
55
63
-b " $mac_address " \
56
64
-n " ${chunks[chunk]} " \
57
65
--char-write-req 2>&1 ) "
@@ -72,5 +80,6 @@ if ! [[ "$mac_address" =~ ^([a-fA-F0-9]{2}:){5}[a-zA-Z0-9]{2}$ ]]; then
72
80
elif ! [[ -r $file && -f $file ]]; then
73
81
error " No such file!"
74
82
else
83
+ printf " using handle %s\n" " $handle "
75
84
load
76
85
fi
You can’t perform that action at this time.
0 commit comments