Skip to content

Commit 017d751

Browse files
authored
Merge pull request #15 from kscheff/fix/upload_packet_size
fix upload packet size to be smaller than 20 chars
2 parents 4c25b7a + 3f1b05c commit 017d751

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

bbload

100644100755
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
mac_address="$1"
44
file="$2"
5-
5+
handle="0x0021"
66

77
function error() {
88
cat <<- EOH
@@ -37,21 +37,29 @@ function upload_progress() {
3737
function load() {
3838
hexdump=""
3939
chunks=()
40+
eol=13
4041

4142
while read line; do
4243
line=$(printf '%s\r' "$line" | xxd -p | tr -d '\n')
4344
hexdump+="$line"
4445
done < $file
4546

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")
4856
done
4957

5058
upload_progress 0
5159

5260
for chunk in ${!chunks[@]}; do
5361
result="$(gatttool -i hci0 \
54-
-a 0x0031 \
62+
-a "$handle" \
5563
-b "$mac_address" \
5664
-n "${chunks[chunk]}" \
5765
--char-write-req 2>&1)"
@@ -72,5 +80,6 @@ if ! [[ "$mac_address" =~ ^([a-fA-F0-9]{2}:){5}[a-zA-Z0-9]{2}$ ]]; then
7280
elif ! [[ -r $file && -f $file ]]; then
7381
error "No such file!"
7482
else
83+
printf "using handle %s\n" "$handle"
7584
load
7685
fi

0 commit comments

Comments
 (0)