Newer
Older
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
<?php
namespace SmartData;
require_once( __DIR__ . '/Exception.php');
require_once( __DIR__ . '/Packable.php');
abstract class SmartData extends Packable
{
const STATIC_VERSION = "1.1";
const MOBILE_VERSION = "1.2";
public $version;
private $unit;
public $value;
public $error;
public $confidence;
public $x;
public $y;
public $z;
public $time;
public static function fields() : array {
return array(
'unit' => Unpack::UNIT,
'value' => Unpack::VALUE,
'error' => Unpack::BYTE,
'confidence' => Unpack::BYTE,
'x' => Unpack::DIMENSION,
'y' => Unpack::DIMENSION,
'z' => Unpack::DIMENSION,
'time' => Unpack::TIME,
'd' => Unpack::DIMENSION
);
}
public $gw;
public function __construct($u, $v, $e, $c, $x,$y,$z, $t, $d){
$this->unit = ($u instanceof Unit) ? $u : Unit::interpret($u);
$this->value = $v;
$this->error = $e;
$this->confidence = $c;
$this->x = $x;
$this->y = $y;
$this->z = $z;
$this->time = $t;
$this->d = $d;
if((Config::DEBUGGED[__CLASS__] ?? false) || Config::HYSTERICALLY_DEBUGGED)
Logger::debug(__CLASS__.": $this");
}
public function toArray(){
$json = array();
$json['timestamp'] = $this->time;
$json['value'] = $this->value;
$json['error'] = $this->error;
$json['confidence'] = $this->confidence;
$json['x'] = $this->x;
$json['y'] = $this->y;
$json['z'] = $this->z;
$json['d'] = $this->d;
return $json;
}
public function toJson(){
$json = json_encode($this->toArray());
$json = preg_replace('/\"timestamp\":\"/', "\"timestamp\":", $json);
$json = preg_replace('/\",\"value\":/', ",\"value\":", $json);
return $json;
}
public function unit(){
return $this->unit;
}
public function __get($property){
if (property_exists($this, $property)) {
switch ($property) {
case 'unit':
if($this->unit instanceof Unit)
return $this->unit->cod;
else
return $this->unit;
default:
return $this->$property;
}
}
}
public function __toString() {
$string = "u={$this->unit}, ";
$string .= "v={$this->value}, ";
$string .= "e={$this->error}, ";
$string .= "c={$this->confidence}, ";
$string .= "x={$this->x}, ";
$string .= "y={$this->y}, ";
$string .= "z={$this->z}, ";
$string .= "t={$this->time}, ";
$string .= "d={$this->d}";
$string .= '}';
return $string;
}
}
class StaticSmartData extends SmartData {
public function __construct($u, $v, $e, $c, $x,$y,$z, $t, $d) {
parent::__construct($u, $v, $e, $c, $x,$y,$z, $t, $d);
$this->version = SmartData::STATIC_VERSION;
}
public function __toString() {
return '{S, '.(string)parent::__toString();
}
}
class MobileSmartData extends SmartData
{
public $signature;
public function __construct($u, $v, $e, $c, $x,$y,$z, $t, $d, $signature=0) {
parent::__construct($u, $v, $e, $c, $x,$y,$z, $t, $d);
$this->signature = $signature;
$this->version = SmartData::MOBILE_VERSION;
}
public function __toString() {
return '{M, '.(string)parent::__toString();
}
}