-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.sh
executable file
·126 lines (99 loc) · 2.49 KB
/
upload.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash -e
pushd $(dirname $0) &>/dev/null
DIR=$(pwd)
popd &>/dev/null
HOST="192.168.0.66"
BASEURL="http://${HOST}"
SL=0.1
SEP="\t\t\t\t"
mcuSyncBootloader() {
echo -ne "Syncing bootloader $SEP "
curl -s $BASEURL/sync | grep "STM32F103" >/dev/null
ret=$?
[ $ret -eq 0 ] && echo "Done" || echo "FAIL"
return $ret
}
mcuReboot() {
echo -ne "Rebooting $SEP "
curl -s $BASEURL/run | grep "Run" >/dev/null
ret=$?
[ $ret -eq 0 ] && echo "Done" || echo "FAIL"
return $ret
}
mcuUploadBin() {
echo -ne "Uploading binary $SEP "
fw=$1
curl -s -F "data=@${fw}" $BASEURL/upload | grep "Uploaded OK" >/dev/null
ret=$?
[ $ret -eq 0 ] && echo "Done" || echo "FAIL"
return $ret
}
mcuErase() {
echo -ne "Erasing flash $SEP "
curl -s $BASEURL/erase | grep "Erase OK" >/dev/null
ret=$?
[ $ret -eq 0 ] && echo "Done" || echo "FAIL"
return $ret
}
mcuFlash() {
echo -ne "Flash binary $SEP "
curl -s $BASEURL/programm | grep "Programming" >/dev/null
ret=$?
[ $ret -eq 0 ] && echo "Done" || echo "FAIL"
return $ret
}
mcuDeleteBin() {
echo -ne "Deleting binary $SEP "
curl -s $BASEURL/delete >/dev/null
echo "Done"
return 0
}
mcuBinStatus() {
TMP=$(tempfile)
curl -s ${BASEURL}/list 2>/dev/null >$TMP
export MCU=$(cat $TMP | sed 's|.*MCU: \([a-zA-Z0-9]*\).*|\1|g')
export FILE=$(cat $TMP | sed 's|.*File: \{1,2\}\([a-zA-Z0-9\.]*\).*|\1|g')
export SIZE=$(cat $TMP | sed 's|.*Size:\(0-9\)+.*|\1|g')
rm $TMP
}
printCSum() {
file=$1
}
espOTAupdate() {
fw=$1
[ ! -f $fw ] && echo >&2 "Firmware '$fw' not found" && return 1
fn=$(basename $fw)
lu=${fw}.lastUpdate
cs=$(sha1sum -b ${fw} | cut -f1 -d' ')
[[ -f "$lu" ]] && [[ "$cs" == "$(cat $lu)" ]] && echo "FW already up to date" && return 0
echo -ne "Updating ESP $SEP "
curl -s -F "firmware=@${fw};fwname=\"${fn}\"" ${BASEURL}/update | grep "Update Success" >/dev/null
ret=$?
if [ $ret -eq 0 ]; then
echo "Done"
sha1sum -b $fw | cut -f1 -d' ' > $lu
else
echo "FAIL"
fi
}
stm32OTAupdate() {
fw=$1
[ ! -f $fw ] && echo >&2 "Firmware '$fw' not found" && return 1
fn=$(basename $fw)
lu=${fw}.lastUpdate
cs=$(sha1sum -b ${fw} | cut -f1 -d' ')
[[ -f "$lu" ]] && [[ "$cs" == "$(cat $lu)" ]] && echo "FW already up to date" && return 0
mcuSyncBootloader
mcuDeleteBin
mcuUploadBin $fw
mcuErase
mcuFlash
mcuReboot
sha1sum -b $fw | cut -f1 -d' ' > $lu
}
if [ $1 == "--stm32" ]; then
stm32OTAupdate $DIR/cmake-build-debug/fancontrol.bin
fi
if [ $1 == "--esp" ]; then
espOTAupdate /tmp/arduino_build_67208/STM32-OTA-ESP8266.ino.bin
fi