|
1 |
| -from pms.sensor.base import Cmd |
2 |
| - |
| 1 | +"""Additional commands for NovaFitness sensors |
3 | 2 |
|
4 |
| -class SDS: |
5 |
| - """Additional commands for NovaFitness sensors |
6 |
| -
|
7 |
| - Laser Dust Sensor Control Protocol V1.3 |
8 |
| - https://learn.watterott.com/sensors/sds011/sds011_protocol.pdf |
9 |
| - """ |
| 3 | +Laser Dust Sensor Control Protocol V1.3 |
| 4 | +https://learn.watterott.com/sensors/sds011/sds011_protocol.pdf |
| 5 | +""" |
10 | 6 |
|
11 |
| - @staticmethod |
12 |
| - def _msg(cmd: int, payload: str, device: int = 0xFFFF) -> bytes: |
13 |
| - assert 0 <= cmd <= 0xFF, f"command id out of range: 0 <= {cmd} <= 0xFF" |
14 |
| - assert 0 <= device <= 0xFFFF, f"device id out of range: 0 <= {device} <= 0xFFFF" |
15 |
| - checksum = sum(bytes.fromhex(payload)) + device // 0x100 + device % 0x100 |
16 |
| - return bytes.fromhex(f"AA{cmd:02X}{payload}{device:04X}{checksum%0x100:02X}AB") |
17 | 7 |
|
18 |
| - @classmethod |
19 |
| - def write_id(cls, new_id: int, device: int = 0xFFFF) -> Cmd: |
20 |
| - """Protocol V1.3, section 3) Set Device ID |
| 8 | +from pms.sensor.base import Cmd |
21 | 9 |
|
22 |
| - The setting is still effective after power off [Factory default has set a unique ID] |
23 |
| - """ |
24 |
| - return Cmd(cls._msg(0xB4, f"0500000000000000000000{new_id:02X}", device), b"\xAA\xC0", 10) |
25 | 10 |
|
26 |
| - @classmethod |
27 |
| - def work_period(cls, minutes: int = 0, device: int = 0xFFFF) -> Cmd: |
28 |
| - """Protocol V1.3, section 5) Set working period |
| 11 | +def _msg(cmd: int, payload: str, device: int = 0xFFFF) -> bytes: |
| 12 | + assert 0 <= cmd <= 0xFF, f"command id out of range: 0 <= {cmd} <= 0xFF" |
| 13 | + assert 0 <= device <= 0xFFFF, f"device id out of range: 0 <= {device} <= 0xFFFF" |
| 14 | + checksum = sum(bytes.fromhex(payload)) + device // 0x100 + device % 0x100 |
| 15 | + return bytes.fromhex(f"AA{cmd:02X}{payload}{device:04X}{checksum%0x100:02X}AB") |
29 | 16 |
|
30 |
| - The setting is still effective after power off [factory default is continuous measurement] |
31 |
| - The sensor works periodically and reports the latest data. |
32 | 17 |
|
33 |
| - 0 minute: continuous mode (default), i.e. report every 1 second |
34 |
| - 1-30 minutes: sample for 30 secors and sleep the rest of the period |
35 |
| - """ |
| 18 | +def write_id(new_id: int, device: int = 0xFFFF) -> Cmd: |
| 19 | + """Protocol V1.3, section 3) Set Device ID |
36 | 20 |
|
37 |
| - assert 0 <= minutes <= 30, f"minutes out of range: 0 <= {minutes} <= 30" |
38 |
| - return Cmd( |
39 |
| - cls._msg(0xB4, f"0801{minutes:02X}00000000000000000000", device), b"\xAA\xC0", 10 |
40 |
| - ) |
| 21 | + The setting is still effective after power off [Factory default has set a unique ID] |
| 22 | + """ |
| 23 | + return Cmd(_msg(0xB4, f"0500000000000000000000{new_id:02X}", device), b"\xAA\xC0", 10) |
41 | 24 |
|
42 |
| - @classmethod |
43 |
| - def firmware_version(cls, device: int = 0xFFFF) -> Cmd: |
44 |
| - """Protocol V1.3, 6) Check firmware version""" |
45 |
| - return Cmd(cls._msg(0xB4, "07000000000000000000000000", device), b"\xAA\xC0", 10) |
46 | 25 |
|
| 26 | +def work_period(minutes: int = 0, device: int = 0xFFFF) -> Cmd: |
| 27 | + """Protocol V1.3, section 5) Set working period |
47 | 28 |
|
48 |
| -class HPMA: |
49 |
| - """Additional commands for Honeywell sensors |
| 29 | + The setting is still effective after power off [factory default is continuous measurement] |
| 30 | + The sensor works periodically and reports the latest data. |
50 | 31 |
|
51 |
| - HPM Series, Particulate Matter Sensors, 32322550 Issue F |
52 |
| - https://sensing.honeywell.com/honeywell-sensing-particulate-hpm-series-datasheet-32322550 |
| 32 | + 0 minute: continuous mode (default), i.e. report every 1 second |
| 33 | + 1-30 minutes: sample for 30 secors and sleep the rest of the period |
53 | 34 | """
|
54 | 35 |
|
55 |
| - @staticmethod |
56 |
| - def read_cf() -> Cmd: |
57 |
| - """Read Customer Adjustment Coefficient |
58 |
| -
|
59 |
| - HPM Series, Table 4 and Table 6 |
60 |
| - """ |
61 |
| - return Cmd(b"\x68\x01\x10\x87", b"\x40\x02\x10", 5) |
62 |
| - |
63 |
| - @staticmethod |
64 |
| - def write_cf(cf: int = 0) -> Cmd: |
65 |
| - """Set Customer Adjustment Coefficient |
| 36 | + assert 0 <= minutes <= 30, f"minutes out of range: 0 <= {minutes} <= 30" |
| 37 | + return Cmd(_msg(0xB4, f"0801{minutes:02X}00000000000000000000", device), b"\xAA\xC0", 10) |
66 | 38 |
|
67 |
| - HPM Series, Table 4 and Table 6 |
68 |
| - cf: 30 ~ 200 (Default, 100) |
69 |
| - """ |
70 | 39 |
|
71 |
| - assert 30 <= cf <= 200, f"out of range: 30 <= {cf} <= 200" |
72 |
| - return Cmd(bytes.fromhex(f"680208{cf:02X}{(0xff8e-cf)%0x100:02X}"), b"\xA5\xA5", 2) |
| 40 | +def firmware_version(device: int = 0xFFFF) -> Cmd: |
| 41 | + """Protocol V1.3, 6) Check firmware version""" |
| 42 | + return Cmd(_msg(0xB4, "07000000000000000000000000", device), b"\xAA\xC0", 10) |
0 commit comments