-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmodule.php
More file actions
89 lines (79 loc) · 2.97 KB
/
module.php
File metadata and controls
89 lines (79 loc) · 2.97 KB
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
<?php
declare(strict_types=1);
/**
* WebSocketInterfaceTest Klasse zeigt die Verwendung des Datenaustausches mit einem WebSocket-Server oder -Client.
* Erweitert IPSModule.
*
* @author Michael Tröger <micha@nall-chan.net>
* @copyright 2017 Michael Tröger
* @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC BY-NC-SA 4.0
*
* @version 1.0
*
* @example <b>Ohne</b>
*/
class WebSocketInterfaceTest extends IPSModule
{
/**
* Interne Funktion des SDK.
*/
public function Create()
{
parent::Create();
}
/**
* Interne Funktion des SDK.
*/
public function ApplyChanges()
{
parent::ApplyChanges();
}
public function SendTestServer(string $ClientIP, int $FrameTyp, string $Data, bool $Fin)
{
// Daten zum WebSocket-Server
$SendData['DataID'] = '{714B71FB-3D11-41D1-AFAC-E06F1E983E09}';
$SendData['ClientIP'] = $ClientIP;
$SendData['FrameTyp'] = $FrameTyp;
$SendData['Fin'] = $Fin;
$SendData['Buffer'] = utf8_encode($Data); // immer utf8_encode falls binäre Daten enthalten sind
$this->SendDebug('ClientIP', $SendData['ClientIP'], 0);
$this->SendDebug('FrameTyp', $SendData['FrameTyp'], 0);
$this->SendDebug('Fin', ($SendData['Fin'] ? 'true' : 'false'), 0);
$this->SendDebug('Buffer', $SendData['Buffer'], 0);
return $this->SendDataToParent(json_encode($SendData));
}
public function SendTestClient(int $FrameTyp, string $Data, bool $Fin)
{
// Daten zum WebSocket-Client
$SendData['DataID'] = '{BC49DE11-24CA-484D-85AE-9B6F24D89321}';
$SendData['FrameTyp'] = $FrameTyp;
$SendData['Fin'] = $Fin;
$SendData['Buffer'] = utf8_encode($Data); // immer utf8_encode falls binäre Daten enthalten sind
$this->SendDebug('FrameTyp', $SendData['FrameTyp'], 0);
$this->SendDebug('Fin', ($SendData['Fin'] ? 'true' : 'false'), 0);
$this->SendDebug('Buffer', $SendData['Buffer'], 0);
return $this->SendDataToParent(json_encode($SendData));
}
//################# DATAPOINTS PARENT
/**
* Empfängt Daten vom Parent.
*
* @param string $JSONString Das empfangene JSON-kodierte Objekt vom Parent.
*/
public function ReceiveData($JSONString)
{
$Data = json_decode($JSONString);
// Daten vom WebSocket-Server
if ($Data->DataID == '{8F1F6C32-B1AD-4B7F-8DFB-1244A96FCACF}') {
$this->SendDebug('FrameTyp', $Data->FrameTyp, 0);
$this->SendDebug('ClientIP', $Data->ClientIP, 0);
$this->SendDebug('ClientPort', $Data->ClientPort, 0);
$this->SendDebug('Receive', utf8_decode($Data->Buffer), 0);
}
// Daten vom WebSocket-Client
if ($Data->DataID == '{C51A4B94-8195-4673-B78D-04D91D52D2DD}') {
$this->SendDebug('FrameTyp', $Data->FrameTyp, 0);
$this->SendDebug('Receive', utf8_decode($Data->Buffer), 0);
}
}
}