-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiBaseClass.php
More file actions
65 lines (59 loc) · 1.55 KB
/
MiBaseClass.php
File metadata and controls
65 lines (59 loc) · 1.55 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
<?php
/*
* Homegear Xiaomi Smarthome for Homegear with PHP 7.4
* (c) Frank Motzkau 2020
*/
include_once 'MiLogger.php';
abstract class MiBaseClass
{
protected $_model = '';
protected $_sid = '';
protected function sendCommand($socket, $cmd, $ip, $port, $ack)
{
$result = FALSE;
try
{
socket_sendto($socket, $cmd, strlen($cmd), 0, $ip, $port);
$json = null;
socket_recvfrom($socket, $json, 1024, MSG_WAITALL, $clientIP, $clientPort);
if (!is_null($json))
{
$response = json_decode($json);
if ($response->cmd === $ack)
{
$result = json_decode($json);
}
}
}
catch (\Homegear\HomegearException $e)
{
MiLogger::Instance()->exception_log($e);
}
catch (Exception $e)
{
MiLogger::Instance()->exception_log($e);
}
return $result;
}
protected function setProperty(&$param, $mixed, $property)
{
$result = FALSE;
try
{
if (property_exists($mixed, $property))
{
$param = $mixed->$property;
$result = TRUE;
}
}
catch (\Homegear\HomegearException $e)
{
MiLogger::Instance()->exception_log($e);
}
catch (Exception $e)
{
MiLogger::Instance()->exception_log($e);
}
return $result;
}
}