|
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
|
60 |
|
public function __construct(int $size, int $origin, bool $tagged, bool $addressable, int $protocolNo, int $source) |
|
31
|
|
|
{ |
|
32
|
60 |
|
$this->size = validate_uint16('Message size', $size); |
|
33
|
58 |
|
$this->origin = validate_int_range('Message origin', $origin, 0, 3); |
|
34
|
56 |
|
$this->tagged = $tagged; |
|
35
|
56 |
|
$this->addressable = $addressable; |
|
36
|
56 |
|
$this->protocolNo = validate_int_range('Protocol number', $protocolNo, 0, 0x0fff); |
|
37
|
54 |
|
$this->source = validate_uint32('Message source', $source); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
33 |
|
public function getSize(): int |
|
41
|
|
|
{ |
|
42
|
33 |
|
return $this->size; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
33 |
|
public function getOrigin(): int |
|
46
|
|
|
{ |
|
47
|
33 |
|
return $this->origin; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
32 |
|
public function isTagged(): bool |
|
51
|
|
|
{ |
|
52
|
32 |
|
return $this->tagged; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
31 |
|
public function isAddressable(): bool |
|
56
|
|
|
{ |
|
57
|
31 |
|
return $this->addressable; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
31 |
|
public function getProtocolNo(): int |
|
61
|
|
|
{ |
|
62
|
31 |
|
return $this->protocolNo; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
29 |
|
public function getSource(): int |
|
66
|
|
|
{ |
|
67
|
29 |
|
return $this->source; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|