Skip to content

Commit 3cead96

Browse files
committed
Add messages 47 and 48 (power and sleep)
1 parent 41acadb commit 3cead96

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

src/messages/m47-cpu2-sleep.toit

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import ..protocol as protocol
2+
3+
class CPU2Sleep extends protocol.Data:
4+
static MT := 47
5+
static INTERVAL := 1
6+
static WAKE-ON-EVENT := 2
7+
8+
static do-msg --interval/int --wake-on-event/bool=false -> protocol.Message:
9+
msg := protocol.Message MT
10+
msg.data.add-data-uint32 INTERVAL interval
11+
msg.data.add-data-uint8 WAKE-ON-EVENT (wake-on-event ? 1 : 0)
12+
msg.header.data.add-data-uint8 protocol.Header.TYPE-MESSAGE-METHOD protocol.Header.METHOD-DO
13+
return msg
14+
15+
constructor.from-data data/protocol.Data:
16+
super.from-data data
17+
18+
constructor --interval/int --wake-on-event/int:
19+
this.add-data-uint32 INTERVAL interval
20+
this.add-data-uint8 WAKE-ON-EVENT wake-on-event
21+
22+
interval -> int:
23+
return get-data-uint32 INTERVAL
24+
25+
wake-on-event -> int:
26+
return get-data-uint8 WAKE-ON-EVENT
27+
28+
stringify -> string:
29+
return {
30+
"Interval": interval,
31+
"Wake on Event": wake-on-event,
32+
}.stringify
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import ..protocol as protocol
2+
3+
class PowerProfile extends protocol.Data:
4+
static MT := 48
5+
static TOTAL-POWER := 3
6+
static CURRENT-NOW := 4
7+
8+
static subscribe-msg --interval/int=300 -> protocol.Message:
9+
msg := protocol.Message MT
10+
msg.header.data.add-data-uint8 protocol.Header.TYPE-MESSAGE-METHOD protocol.Header.METHOD-SUBSCRIBE
11+
msg.header.data.add-data-uint32 protocol.Header.TYPE_SUBSCRIPTION_INTERVAL interval
12+
return msg
13+
14+
static unsubscribe-msg -> protocol.Message:
15+
msg := protocol.Message MT
16+
msg.header.data.add-data-uint8 protocol.Header.TYPE-MESSAGE-METHOD protocol.Header.METHOD-UNSUBSCRIBE
17+
return msg
18+
19+
constructor.from-data data/protocol.Data:
20+
super.from-data data
21+
22+
total-power -> float:
23+
return get-data-float32 TOTAL-POWER
24+
25+
current-now -> float:
26+
return get-data-float32 CURRENT-NOW
27+
28+
stringify -> string:
29+
return {
30+
"Total Power": total-power,
31+
"Current Now": current-now,
32+
}.stringify

src/messages/messages.toit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import .m43-battery-status show BatteryStatus
1616
import .m44-pressure show Pressure
1717
import .m45-alarm-control show AlarmControl
1818
import .m46-buzzer-sequence show BuzzerSequence
19+
import .m47-cpu2-sleep show CPU2Sleep
20+
import .m48-power-profile show PowerProfile
1921
import .m50-link-control show LinkControl
2022
import .m1004-lora show Lora
2123
import .m10008-preset-page show PresetPage

0 commit comments

Comments
 (0)