-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharging_get_bcontroller.sh
executable file
·91 lines (73 loc) · 1.91 KB
/
charging_get_bcontroller.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
#!/bin/bash
# BogdanDIA
CPATH=$(dirname "$0")/tesla-ble.conf
. $CPATH
. ${SCRIPTS_PATH}/log-def.sh
charging_get_bcontroller()
{
app() {
# set timeouts variable
CMD_TMO="-command-timeout $BLE_CMD_TIMEOUT -connect-timeout $BLE_CONN_TIMEOUT"
# set BT Controller Number
export HCINUM=$HCI_NUM
# run command
./tesla-control $CMD_TMO -vin "$VIN" -key-file "$PRIVATE_KEY" -ble -domain vcsec body-controller-state
STATUS=$?
return $STATUS
}
# load log definition
. ${SCRIPTS_PATH}/log-def.sh
# cd to BIN_PATH
cd "$BIN_PATH"
log ""
log "`date` get-bcontroller"
log "BIN_PATH: $BIN_PATH"
log "VIN: $VIN"
log "HCI_NUM: $HCI_NUM"
log "PWD: `pwd`"
log "SCRIPTS_PATH: $SCRIPTS_PATH"
log "COMMAND_TIMEOUT: $COMMAND_TIMEOUT"
log "Burst start"
if [[ -n $VIN ]]; then
log "VIN provided"
else
log "no VIN provided in tesla-ble.conf. Exiting..."
fi
if [[ -n $PRIVATE_KEY ]];then
log "PRIVATE_KEY provided"
else
log "no PRIVATE_KEY provided in tesla-ble.conf. Exiting..."
fi
CMD_STAT=""
for (( i=0; i<5; i++ ))
do
app 2> >(tee -a charging-log.txt >&2) 1> >(tee -a charging-log.txt >&1)
CMD_STAT=$?
if [[ $CMD_STAT -eq 0 ]]; then
log "Ok: try: $i"
break
else
log "Fail: try: $i"
fi
done
log "Burst end"
return $CMD_STAT
}
export -f charging_get_bcontroller
# set the default value if the initial definition is not correct
if [[ ! $COMMAND_TIMEOUT =~ ^[0-9]+$ ]]; then
COMMAND_TIMEOUT=0
fi
# return after timeout period. Load config upon executing function
timeout --preserve-status -k 1 -s SIGKILL "$COMMAND_TIMEOUT" bash -c ". ${SCRIPTS_PATH}/tesla-ble.conf; charging_get_bcontroller"
STATUS=$?
wait
log "STATUS: $STATUS"
if [[ $STATUS -eq 0 ]]; then
log "Command get-bcontroller success"
elif [[ $STATUS -eq 137 ]]; then
log "Fail - Command Timeout"
else
log "Command get-bcontroller fail"
fi
exit "$STATUS"