-
Notifications
You must be signed in to change notification settings - Fork 205
/
main.sh
executable file
·91 lines (83 loc) · 2.18 KB
/
main.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
OPENWBBASEDIR=$(cd "$(dirname "$0")/../../" && pwd)
RAMDISKDIR="$OPENWBBASEDIR/ramdisk"
MODULEDIR=$(cd "$(dirname "$0")" && pwd)
DMOD="EVSOC"
MYLOGFILE="$RAMDISKDIR/soc.log"
CHARGEPOINT=$1
# check if config file is already in env
if [[ -z "$debug" ]]; then
echo "soc_eq: Seems like openwb.conf is not loaded. Reading file."
# try to load config
. "$OPENWBBASEDIR/loadconfig.sh"
# load helperFunctions
. "$OPENWBBASEDIR/helperFunctions.sh"
fi
socDebug=$debug
# for development only
#socDebug=1
case $CHARGEPOINT in
2)
# second charge point
ladeleistungfile="$RAMDISKDIR/llaktuells1"
soctimerfile="$RAMDISKDIR/soctimer1"
soc_file="$RAMDISKDIR/soc1"
soc_eq_client_id=$soc_eq_client_id_lp2
soc_eq_client_secret=$soc_eq_client_secret_lp2
soc_eq_vin=$soc_eq_vin_lp2
;;
*)
# defaults to first charge point for backward compatibility
# set CHARGEPOINT in case it is empty (needed for logging)
CHARGEPOINT=1
ladeleistungfile="$RAMDISKDIR/llaktuell"
soctimerfile="$RAMDISKDIR/soctimer"
soc_file="$RAMDISKDIR/soc"
soc_eq_client_id=$soc_eq_client_id_lp1
soc_eq_client_secret=$soc_eq_client_secret_lp1
soc_eq_vin=$soc_eq_vin_lp1
;;
esac
incrementTimer() {
case $dspeed in
1)
# Regelgeschwindigkeit 10 Sekunden
ticksize=1
;;
2)
# Regelgeschwindigkeit 20 Sekunden
ticksize=2
;;
3)
# Regelgeschwindigkeit 60 Sekunden
ticksize=1
;;
*)
# Regelgeschwindigkeit unbekannt
ticksize=1
;;
esac
soctimer=$((soctimer + ticksize))
echo $soctimer >"$soctimerfile"
}
soctimer=$(<"$soctimerfile")
ladeleistung=$(<"$ladeleistungfile")
if ((ladeleistung > 500)); then
tmpintervall=$((5 * 6))
else
tmpintervall=$((60 * 6))
fi
if ((socDebug > 0)); then
tmpintervall=12
fi
if ((soctimer < tmpintervall)); then
openwbDebugLog "$DMOD" 1 "Lp$CHARGEPOINT: Nothing to do yet. Incrementing timer. $soctimer < $tmpintervall"
incrementTimer
else
openwbDebugLog "$DMOD" 1 "Lp$CHARGEPOINT: Requesting SoC"
echo 0 >"$soctimerfile"
"$MODULEDIR/soc.py" "$soc_eq_client_id" "$soc_eq_client_secret" "$soc_eq_vin" "$soc_file" "$CHARGEPOINT" >>"$MYLOGFILE" 2>&1
ret=$?
openwbDebugLog "$DMOD" 1 "Lp$CHARGEPOINT: Py Return: $ret"
openwbModulePublishState "EVSOC" "$ret" "Code: $ret" "$CHARGEPOINT"
fi