BatteryOperationMessage.php
3.34 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
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
<?php
/**
* Created by PhpStorm.
* User: billy
* Date: 20/03/2017
* Time: 6:23 PM
*/
namespace App\Modules\Onenet\Message\ReceiveMessage;
use App\Common\Byte;
use App\Modules\Onenet\Message\MsgType;
use App\Modules\Onenet\Message\ReceiveMessage;
use Illuminate\Support\Facades\Log;
class BatteryOperationMessage extends ReceiveMessage
{
/**
* @var int
*/
private $remark_stanza = 0;
/**
* @var int
*/
private $time_stanza = 0;
/**
* @var int
*/
private $position_stanza = 3;
/**
* @var
*/
private $battery_sn;
/**
* @var
*/
private $battery_position;
/**
* @var
*/
private $time;
/**
* @param $deviceId
* @param $dataStreamType
* TakeOutMessage constructor.
*/
public function __construct($deviceId, $dataStreamType)
{
parent::__construct($deviceId, MsgType::DATASTREAM_TYPE, $dataStreamType);
}
/**
* @return int
*/
protected function getStanzaLength()
{
return config('constants.battery.sn_length') + $this->time_stanza + $this->remark_stanza + $this->position_stanza;
}
/**
* @return int
*/
public function getRemarkStanza()
{
return $this->remark_stanza;
}
/**
* @param int $remark_stanza
*/
public function setRemarkStanza($remark_stanza)
{
$this->remark_stanza = $remark_stanza;
}
/**
* @return int
*/
public function getTimeStanza()
{
return $this->time_stanza;
}
/**
* @param int $time_stanza
*/
public function setTimeStanza($time_stanza)
{
$this->time_stanza = $time_stanza;
}
/**
* @return mixed
*/
public function getBatterySn()
{
return $this->battery_sn;
}
/**
* @param mixed $battery_sn
*/
public function setBatterySn($battery_sn)
{
$this->battery_sn = $battery_sn;
}
/**
* @return mixed
*/
public function getTime()
{
return $this->time;
}
/**
* @param mixed $time
*/
public function setTime($time)
{
$this->time = $time;
}
/**
* @return mixed
*/
public function getBatteryPosition()
{
return $this->battery_position;
}
/**
* @param mixed $battery_position
*/
public function setBatteryPosition($battery_position)
{
$this->battery_position = $battery_position;
}
protected function unpackInternal($msg)
{
$this->battery_sn = substr($msg, 0, config('constants.battery.sn_length'));
$i = config('constants.battery.sn_length');
$byte = intval(substr($msg, $i, $this->position_stanza));
$this->battery_position = $byte+1;
$i += $this->position_stanza;
$this->time = date('Y-m-d H:i:s');
// $this->time = $this->handleTimeStanza($msg, $i, $this->time_stanza);
}
/**
* @param $msg
*/
public function unpack($msg)
{
if (strlen($msg) != $this->getStanzaLength())
{
Log::error("[unpack] stanza size incorrect! received size:".strlen($msg).", actual size:".$this->getStanzaLength());
return;
}
$this->unpackInternal($msg);
// $this->time = $this->handleTimeStanza($msg, $i, $this->time_stanza);
}
}