-
Notifications
You must be signed in to change notification settings - Fork 19
/
programming_loop_docker.sh
executable file
·83 lines (71 loc) · 1.84 KB
/
programming_loop_docker.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
#!/bin/bash
COMPILE_CMD=""
LOAD_CMD=""
MAKE_CMD="docker-compose run nrf make"
load() {
${MAKE_CMD} ${LOAD_CMD}
}
compile() {
${MAKE_CMD} ${COMPILE_CMD}
}
get_mac() {
echo "### Extracting MAC, please wait"
docker-compose run nrf getMAC | tail -1 | tee -a macs.log
}
if [[ $# -ne 1 ]]
then
echo "use: programming_loop.sh [test|prod]"
echo "Where test loads the tester code, and prod loads the final code"
exit 1
fi
mode="$1"
case $mode in
test)
COMPILE_CMD="badge_03v6_tester"
LOAD_CMD="flashNew"
shift # past argument
;;
prod)
COMPILE_CMD="badge_03v6_noDebug"
LOAD_CMD="flashCode"
shift # past argument
;;
*)
# unknown option
echo "Unknown option"
exit 1
;;
esac
shift
echo "Using parameters: ${COMPILE_CMD} ${LOAD_CMD}"
# make code
echo "============================================================"
echo "Compiling code- ${COMPILE_CMD}"
echo "============================================================"
compile
COUNTER=1
# program devices
idVendor="1366"
idProduct="1015"
idString="${idVendor}:${idProduct}"
echo
echo "============================================================"
echo "Place new badge. if a badge is already placed, remove it and place it in the programmer again"
inotifywait -q -r -m /dev/bus/usb -e CREATE | while read e
do
#check if the relevant device is now connected, based on
#idVendor and idProduct codes
devIsConnected=$(lsusb | grep "ID ${idString}" | wc -l)
if [[ ( "$devIsConnected" == 1) ]]
then
echo "============================================================"
echo "########## Programming new badge (${COUNTER}) #######"
sleep 5
load
sleep 1
get_mac
echo "########## Finished (${COUNTER}) #######"
let COUNTER=COUNTER+1
echo "### Done. Place next badge!!!"
fi
done