1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace DaveRandom\LibLifxLan\Header; |
4
|
|
|
|
5
|
|
|
use DaveRandom\LibLifxLan\Exceptions\InvalidValueException; |
6
|
|
|
use function DaveRandom\LibLifxLan\validate_int_range; |
7
|
|
|
use function DaveRandom\LibLifxLan\validate_uint16; |
8
|
|
|
use function DaveRandom\LibLifxLan\validate_uint32; |
9
|
|
|
|
10
|
|
|
final class Frame |
11
|
|
|
{ |
12
|
|
|
public const WIRE_SIZE = 8; |
13
|
|
|
|
14
|
|
|
private $size; |
15
|
|
|
private $origin; |
16
|
|
|
private $tagged; |
17
|
|
|
private $addressable; |
18
|
|
|
private $protocolNo; |
19
|
|
|
private $source; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param int $size |
23
|
|
|
* @param int $origin |
24
|
|
|
* @param bool $tagged |
25
|
|
|
* @param bool $addressable |
26
|
|
|
* @param int $protocolNo |
27
|
|
|
* @param int $source |
28
|
|
|
* @throws InvalidValueException |
29
|
|
|
*/ |
30
|
62 |
|
public function __construct(int $size, int $origin, bool $tagged, bool $addressable, int $protocolNo, int $source) |
31
|
|
|
{ |
32
|
62 |
|
$this->size = validate_uint16('Message size', $size); |
33
|
60 |
|
$this->origin = validate_int_range('Message origin', $origin, 0, 3); |
34
|
58 |
|
$this->tagged = $tagged; |
35
|
58 |
|
$this->addressable = $addressable; |
36
|
58 |
|
$this->protocolNo = validate_int_range('Protocol number', $protocolNo, 0, 0x0fff); |
37
|
56 |
|
$this->source = validate_uint32('Message source', $source); |
38
|
|
|
} |
39
|
|
|
|
40
|
35 |
|
public function getSize(): int |
41
|
|
|
{ |
42
|
35 |
|
return $this->size; |
43
|
|
|
} |
44
|
|
|
|
45
|
35 |
|
public function getOrigin(): int |
46
|
|
|
{ |
47
|
35 |
|
return $this->origin; |
48
|
|
|
} |
49
|
|
|
|
50
|
34 |
|
public function isTagged(): bool |
51
|
|
|
{ |
52
|
34 |
|
return $this->tagged; |
53
|
|
|
} |
54
|
|
|
|
55
|
33 |
|
public function isAddressable(): bool |
56
|
|
|
{ |
57
|
33 |
|
return $this->addressable; |
58
|
|
|
} |
59
|
|
|
|
60
|
33 |
|
public function getProtocolNo(): int |
61
|
|
|
{ |
62
|
33 |
|
return $this->protocolNo; |
63
|
|
|
} |
64
|
|
|
|
65
|
31 |
|
public function getSource(): int |
66
|
|
|
{ |
67
|
31 |
|
return $this->source; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|