-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlinkIntegration.brs
243 lines (193 loc) · 7.81 KB
/
BlinkIntegration.brs
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
'BlinkIntegration Brightsign plug-in
' Initialisation
Function BlinkIntegration_Initialize(msgPort As Object, userVariables As Object, bsp as Object) as Object
BlinkIntegration = newBlinkIntegration(msgPort, userVariables, bsp)
return BlinkIntegration
End Function
' Création de l'objet plugin
Function newBlinkIntegration(msgPort As Object, userVariables As Object, bsp as Object)
s = {}
' Variables
s.ipServer = "192.168.120.1"
' Recopie
s.msgPort = msgPort
s.userVariables = userVariables
s.bsp = bsp
s.dlog = dlog
' Fonctions génériques
s.ProcessEvent = BlinkIntegration_ProcessEvent
s.FindWidget = BlinkIntegration_FindWidget
s.widgetFounded = invalid
s.sendCEC = sendCEC
' Fonctions HTML
s.handleHtmlEventPlugin = handleHtmlEventPlugin
' Fonctions de veille
s.videoMode = CreateObject("roVideoMode")
s.low_energy = "false"
' Device Infos
s.deviceInfos = CreateObject("roDeviceInfo")
' Fonctions de récéption UDP
s.handleUdpEventPlugin = handleUdpEventPlugin
s.udpReceiverPort = 5555
s.udpReceiver = CreateObject("roDatagramReceiver", s.udpReceiverPort)
s.udpReceiver.SetPort(msgPort)
' Fonctions d’envoi UDP
s.udpSender = CreateObject("roDatagramSender")
s.sendMonitoring = sendMonitoring
return s
End Function
' Réception d’infos depuis le JavaScript
Function handleHtmlEventPlugin(event as Object, obj as Object) as boolean
retval = false
payload = event.GetData()
if payload.reason = "message" then
if payload.message.action <> invalid then
msg$ = LCase(payload.message.action)
obj.dlog("Réception du message JavaScript " + msg$)
if msg$ = "reboot" then
RebootSystem()
else if msg$ = "restart" then
print "Restart is made in web"
else if msg$ = "poweroff" then
ShutdownSystem()
else if msg$ = "sleep" then
obj.sendCEC("4036", obj)
obj.videoMode.SetPowerSaveMode(true)
obj.low_energy = "true"
else if msg$ = "shutdown" then
obj.videoMode.SetPowerSaveMode(true)
else if msg$ = "wake" then
obj.sendCEC("400D", obj)
obj.videoMode.SetPowerSaveMode(false)
obj.low_energy = "false"
else if msg$ = "monitoring" then
obj.sendMonitoring(obj.ipServer, obj)
else if msg$ = "noudp" then
obj.ipServer = ""
end if
end if
end if
return retval
End Function
' Réception d’infos en UDP
Function handleUdpEventPlugin(event As Object, obj as Object) as boolean
retval = false
msg$ = LCase(event)
obj.dlog("Réception du datagramme " + msg$)
if left(msg$, 6) = "reboot" then
RebootSystem()
else if left(msg$, 7) = "restart" then
RestartApplication()
else if left(msg$, 8) = "poweroff" then
ShutdownSystem()
else if left(msg$, 8) = "shutdown" then
obj.videoMode.SetPowerSaveMode(true)
else if left(msg$, 5) = "sleep" then
obj.sendCEC("4036", obj)
obj.videoMode.SetPowerSaveMode(true)
obj.low_energy = "true"
else if left(msg$, 4) = "wake" then
obj.videoMode.SetPowerSaveMode(false)
obj.sendCEC("400D", obj)
obj.low_energy = "false"
else if left(msg$, 10) = "monitoring" then
obj.sendMonitoring(obj.ipServer, obj)
else if left(msg$, 5) = "noudp" then
obj.ipServer = ""
end if
return retval
End Function
' Envoie le monitoring
Sub sendMonitoring(ip$ as String, obj as Object)
unitName$ = "BrightSign" + " " + obj.deviceInfos.GetModel()
unitDescription$ = ""
obj.dlog("Extraction des informations de sync")
localCurrentSync = CreateObject("roSyncSpec")
if localCurrentSync.ReadFromFile("local-sync.xml") or localCurrentSync.ReadFromFile("localSetupToStandalone-sync.xml") then
unitName$ = localCurrentSync.LookupMetadata("client", "unitName")
unitDescription$ = localCurrentSync.LookupMetadata("client", "unitDescription")
endif
obj.dlog("Création du monitoring")
message = "{"
message = message + Chr(34) + "os" + Chr(34) + ": {"
message = message + Chr(34) + "lifetime" + Chr(34) + ": " + StrI(obj.deviceInfos.GetDeviceLifetime()) + ","
message = message + Chr(34) + "uptime" + Chr(34) + ": " + StrI(obj.deviceInfos.GetDeviceUptime()) + ","
message = message + Chr(34) + "bootCount" + Chr(34) + ": " + StrI(obj.deviceInfos.GetDeviceBootCount()) + ","
message = message + Chr(34) + "platform" + Chr(34) + ": " + Chr(34) + obj.deviceInfos.GetFamily() + Chr(34) + ","
message = message + Chr(34) + "version" + Chr(34) + ": " + Chr(34) + obj.deviceInfos.GetBootVersion() + " / " + obj.deviceInfos.GetVersion() + Chr(34) + "}, "
message = message + Chr(34) + "device" + Chr(34) + ": {"
message = message + Chr(34) + "model" + Chr(34) + ": " + Chr(34) + obj.deviceInfos.GetModel() + Chr(34) + ","
message = message + Chr(34) + "manufacturer" + Chr(34) + ": " + Chr(34) + "BrightSign" + Chr(34) + ","
message = message + Chr(34) + "uuid" + Chr(34) + ": " + Chr(34) + obj.deviceInfos.GetDeviceUniqueId() + Chr(34) + ","
message = message + Chr(34) + "name" + Chr(34) + ": " + Chr(34) + unitName$ + Chr(34) + ","
message = message + Chr(34) + "description" + Chr(34) + ": " + Chr(34) + unitDescription$ + Chr(34) + "}, "
message = message + Chr(34) + "energy" + Chr(34) + ": {"
message = message + Chr(34) + "low" + Chr(34) + ": " + obj.low_energy + ","
message = message + Chr(34) + "force" + Chr(34) + ": " + "false" + "}, "
message = message + Chr(34) + "screen" + Chr(34) + ": {" + Chr(34) + "size" + Chr(34) + ": {"
message = message + Chr(34) + "width" + Chr(34) + ": " + StrI(obj.videoMode.GetOutputResX()) + ","
message = message + Chr(34) + "height" + Chr(34) + ": " + StrI(obj.videoMode.GetOutputResY()) + "}}"
message = message + "}"
if ip$ <> "" then
obj.dlog("Envoi en UDP à " + ip$)
obj.udpSender.SetDestination(ip$, 5555)
obj.udpSender.Send(message)
end if
obj.dlog("Envoi au JavaScript")
if obj.widgetFounded = invalid
obj.FindWidget("roHtmlWidget", obj)
if obj.widgetFounded = invalid
obj.dlog("Widget trouvé")
else
obj.dlog("Widget introuvable")
end if
end if
if obj.widgetFounded <> invalid
obj.dlog("Envoi au widget roHtmlWidget")
obj.widgetFounded.PostJSMessage({infos: message})
end if
End Sub
' Événements levés par le gestionnaires d’événements interne
Function BlinkIntegration_ProcessEvent(event As Object) as boolean
retval = false
m.dlog("Réception d'un événement " + type(event))
if type(event) = "roHtmlWidgetEvent" then
retval = handleHtmlEventPlugin(event, m)
else if type(event) = "roDatagramEvent" then
retval = handleUdpEventPlugin(event, m)
end if
return retval
End Function
' Recherche un widget par son type
Sub BlinkIntegration_FindWidget(widgetType$ as String, obj as Object)
obj.dlog("Recherche d'un widget de type " + widgetType$)
for each zone in m.bsp.sign.zonesHSM
if zone.displayedHtmlWidget <> invalid then
' Widget direct
' obj.dlog("-> displayedHtmlWidget " + type(zone.displayedHtmlWidget))
obj.widgetFounded = zone.displayedHtmlWidget
else if zone.widget <> invalid then
' Recherche dans les widgets
' obj.dlog("-> widget " + type(zone.widget))
if type(zone.widget) = widgetType$ then
obj.widgetFounded = zone.widget
end if
end if
next
End Sub
' Envoie une commande CEC
Sub sendCEC(cecCommand$ As String, obj as Object)
obj.dlog("Envoi de la commande CEC " + cecCommand$)
cec = CreateObject("roCecInterface")
if type(cec) = "roCecInterface" then
b = CreateObject("roByteArray")
b.fromhexstring(cecCommand$)
cec.SendRawMessage(b)
cec = invalid
endif
End Sub
' Log dans la console Web
Sub dlog(message$ as string)
slog = createobject("roSystemLog")
slog.sendline(message$)
End Sub