-
Notifications
You must be signed in to change notification settings - Fork 0
/
script
165 lines (139 loc) · 5.42 KB
/
script
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
! ------ Google Maps Traffic API 23.06.2019 Vers. 1.1 -----------------------------------------------------------
! by kafetzke
!
! ------------------ EINRICHTUNG Anfang -------------------
!
! Anzulegen fuer das Script sind die
! folgenden Systemvariablen
! --------------------------------------------------------------
! maps_start String
! maps_destination String
! maps_duration Zahl
! maps_duration_in_traffic Zahl
! maps_duration_diff Zahl
! maps_distance Zahl
! maps_timestamp String
! ------------------------------------------------------------------------------------------------------------
!
! -- Einbindung in ein CCU-Programm --
! WENN
! Zeitplan (z.B: alle 5min)
! DANN
! Script (dieses Framework)
!
!
! -- Ansprechen des Frameworks --
! WENN
! Zeitpunkt (z.B. 06:00-12:00)
! DANN
! maps_start = Startadresse
! maps_destination = Zieladresse
!
!
! -- Nutzung (Beispiel)
! WENN
! maps_duration_diff > 0 (bei Änderung)
! DANN
! tuWas
!
! ------------------------------------------------------------------------------------------------------------
! Debugging einschalten = true oder aussschalten = false
! z.B. zum Test unter "Script testen"
!
! ------------------------------------------------------------------------------------------------------------
boolean debug = true;
! --------------------------------------------------------------
! Virtuelles CUxD-Exec-Device hier angeben
! --------------------------------------------------------------
string execdevice = "CUxD.CUX2801001:1";
! --------------------------------------------------------------
! Die API verlangt nach einem Key. Hierzu ist eine Registrierung notwendig - dann gibt es kostenloses Kontinget
! https://cloud.google.com/maps-platform/?apis=routes
string apikey = "YourGoogleApiKey";
! Start und Endpunkt können wie ein Suchbegriff auf GoogleMaps angegeben werden. Wichtig: Leerzeichen sind durch "+" zu ersetzen
string startpoint = dom.GetObject("maps_start").Value();
string endpoint = dom.GetObject("maps_destination").Value();
!------------------ EINRICHTUNG ENDE -------------------
!------------------------------------------------------------------------------------------------------------
! Aufruf der Google-API
! https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=Washington,DC&destinations=New+York+City,NY&departure_time=now&key=YOUR_API_KEY
!------------------------------------------------------------------------------------------------------------
string url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=" # startpoint # "\&destinations=" # endpoint # "\&mode=driving\&language=de-DE\&departure_time=now\&key=" # apikey;
if(debug){WriteLine("url: " #url);}
string downloader = "LD_LIBRARY_PATH=/usr/local/addons/cuxd /usr/local/addons/cuxd/curl";
string stdout = "";
string cmd = downloader # " " # url;
var ret;
!------------------------------------------------------------------------------------------------------------
! Los gehts...
!------------------------------------------------------------------------------------------------------------
var duration = 0;
var duration_in_traffic = 0;
var duration_diff = 0;
WriteLine("cmd : "#cmd);
ret= dom.GetObject(execdevice # ".CMD_SETS").State(cmd);
if(debug){WriteLine("ret cmd_sets : "#ret);}
ret = dom.GetObject(execdevice # ".CMD_QUERY_RET").State(1);
if(debug){WriteLine("ret cmd_query_ret: "#ret);}
stdout = dom.GetObject(execdevice # ".CMD_RETS").State();
!----------- Entfernung --------------
string keyword = "distance";
if (stdout)
{
string temp_string = stdout.Substr(stdout.Find(keyword));
temp_string = temp_string.Substr(temp_string.Find("value")+8);
! Diese schreibweise sorgt für einen double-Wert
var value = 0.0 + temp_string.Substr(0,temp_string.Find("}"));
dom.GetObject("maps_distance").State(value/1000);
if(debug) {WriteLine("distance : "#value);}
}
!----------- Dauer --------------
string keyword = "duration";
if (stdout)
{
string temp_string = stdout.Substr(stdout.Find(keyword));
temp_string = temp_string.Substr(temp_string.Find("value")+8);
! Diese schreibweise sorgt für einen Integer-Wert
var value = 0 + temp_string.Substr(0,temp_string.Find("}"));
dom.GetObject("maps_duration").State(value/60);
if(debug) {WriteLine("duration : "#value);}
duration = value;
}
!----------- Dauer mit Verkehr --------------
string keyword = "duration_in_traffic";
if (stdout)
{
string temp_string = stdout.Substr(stdout.Find(keyword));
if (temp_string <> "")
{
temp_string = temp_string.Substr(temp_string.Find("value")+8);
! Diese schreibweise sorgt für einen Integer-Wert
var value = 0 + temp_string.Substr(0,temp_string.Find("}"));
dom.GetObject("maps_duration_in_traffic").State(value/60);
if(debug) {WriteLine("duration_in_traffic: "#value);}
duration_in_traffic = value;
}
else
{
duration_in_traffic = duration;
}
}
!---------- Ergebnis schreiben und Eingabe-Variablen zurücksetzen---
if (duration_in_traffic > duration)
{
duration_diff = duration_in_traffic - duration;
if(debug)
{
WriteLine("Verzögerung gefunden! "#duration_diff#"min");
}
}
else
{
duration_diff = 0;
}
if(debug)
{
WriteLine("duration_diff : "#duration_diff);
}
dom.GetObject("maps_duration_diff").State(duration_diff/60);
dom.GetObject("maps_timestamp").State(system.Date("%Y-%m-%d %H:%M:%S").ToTime());