Skip to content

Commit f2cf8f9

Browse files
committed
Add LORA message
1 parent b71b748 commit f2cf8f9

File tree

5 files changed

+103
-5
lines changed

5 files changed

+103
-5
lines changed

src/devices/zcard.toit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ZCARD-MESSAGES := [
2121
BatteryStatus.MT,
2222
AlarmControl.MT,
2323
LinkControl.MT,
24-
1004, // LORA
24+
Lora.MT,
2525
PresetPage.MT,
2626
TextPage.MT,
2727
MenuPage.MT,

src/messages/m1004-lora.toit

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import ..protocol as protocol
2+
3+
class Lora extends protocol.Data:
4+
static MT := 1004
5+
static PAYLOAD := 2
6+
static SPREAD_FACTOR := 4
7+
static CODING_RATE := 5
8+
static BANDWIDTH := 6
9+
static CENTER_FREQUENCY := 7
10+
static TX_POWER := 8
11+
static PREAMBLE_LENGTH := 9
12+
static RECEIVE_MS := 10
13+
static SLEEP := 11
14+
static STATE := 12
15+
16+
static setMsg --spreadFactor/int --codingRate/int --bandwidth/int --centerFrequency/int --txPower/int --preambleLength/int --sleep/int?=null -> protocol.Message:
17+
msg := protocol.Message MT
18+
msg.data.addDataUint8 SPREAD_FACTOR spreadFactor
19+
msg.data.addDataUint8 CODING_RATE codingRate
20+
msg.data.addDataUint8 BANDWIDTH bandwidth
21+
msg.data.addDataUint32 CENTER_FREQUENCY centerFrequency
22+
msg.data.addDataUint8 TX_POWER txPower
23+
msg.data.addDataUint8 PREAMBLE_LENGTH preambleLength
24+
if sleep:
25+
msg.data.addDataUint8 SLEEP sleep
26+
msg.header.data.addDataUint8 protocol.Header.TYPE_MESSAGE_METHOD protocol.Header.METHOD_SET
27+
return msg
28+
29+
static getMsg -> protocol.Message:
30+
msg := protocol.Message MT
31+
msg.header.data.addDataUint8 protocol.Header.TYPE_MESSAGE_METHOD protocol.Header.METHOD_GET
32+
return msg
33+
34+
static doMsg --payload/ByteArray --receiveMs/int -> protocol.Message:
35+
msg := protocol.Message MT
36+
msg.data.addData PAYLOAD payload
37+
msg.data.addDataUint32 RECEIVE_MS receiveMs
38+
msg.header.data.addDataUint8 protocol.Header.TYPE_MESSAGE_METHOD protocol.Header.METHOD_DO
39+
return msg
40+
41+
static subscribeMsg -> protocol.Message:
42+
msg := protocol.Message MT
43+
msg.header.data.addDataUint8 protocol.Header.TYPE_MESSAGE_METHOD protocol.Header.METHOD_SUBSCRIBE
44+
return msg
45+
46+
static unsubscribeMsg -> protocol.Message:
47+
msg := protocol.Message MT
48+
msg.header.data.addDataUint8 protocol.Header.TYPE_MESSAGE_METHOD protocol.Header.METHOD_UNSUBSCRIBE
49+
return msg
50+
51+
constructor.fromData data/protocol.Data:
52+
super.fromData data
53+
54+
payload -> ByteArray:
55+
return getData PAYLOAD
56+
57+
spreadFactor -> int:
58+
return getDataUint8 SPREAD_FACTOR
59+
60+
codingRate -> int:
61+
return getDataUint8 CODING_RATE
62+
63+
bandwidth -> int:
64+
return getDataUint8 BANDWIDTH
65+
66+
centerFrequency -> int:
67+
return getDataUint32 CENTER_FREQUENCY
68+
69+
txPower -> int:
70+
return getDataUint8 TX_POWER
71+
72+
preambleLength -> int:
73+
return getDataUint8 PREAMBLE_LENGTH
74+
75+
receiveMs -> int:
76+
return getDataUint32 RECEIVE_MS
77+
78+
sleep -> int:
79+
return getDataUint8 SLEEP
80+
81+
state -> int:
82+
return getDataUint STATE
83+
84+
stringify -> string:
85+
return {
86+
"Payload": payload,
87+
"Spread Factor": spreadFactor,
88+
"Coding Rate": codingRate,
89+
"Bandwidth": bandwidth,
90+
"Center Frequency": centerFrequency,
91+
"TX Power": txPower,
92+
"Preamble Length": preambleLength,
93+
"Receive Ms": receiveMs,
94+
"Sleep": sleep,
95+
"State": state,
96+
}.stringify

src/messages/messages.toit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import .m43-battery-status show BatteryStatus
1616
import .m44-pressure show Pressure
1717
import .m45-alarm-control show AlarmControl
1818
import .m50-link-control show LinkControl
19+
import .m1004-lora show Lora
1920
import .m10008-preset-page show PresetPage
2021
import .m10009-text-page show TextPage
2122
import .m10010-menu-page show MenuPage

src/protocol/Header.toit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Header:
4848
static METHOD_GET /int ::= 2
4949
static METHOD_SUBSCRIBE /int ::= 3
5050
static METHOD_DO /int ::= 4
51+
static METHOD_UNSUBSCRIBE /int ::= 5
5152

5253
messageLength_ /int := 0
5354
messageType_ /int := 0

src/services/httpmsg/msgs.toit

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ sample-messages := {
4141
"Duration 0": (messages.AlarmControl.doMsg --duration=0).bytesForProtocol,
4242
"3s pattern 4 intensity 1": (messages.AlarmControl.doMsg --duration=3 --buzzerPattern=4 --buzzerIntensity=1).bytesForProtocol,
4343
},
44-
"1004 LORA": {
45-
"Transmit": #[0X03, 0X18, 0X00, 0XEC, 0X03, 0X01, 0X00, 0X05, 0X01, 0X04, 0X02, 0X00, 0X02, 0X0A, 0X04, 0X6C, 0X62, 0X6C, 0X62, 0X02, 0X10, 0X27, 0X80, 0X55],
46-
"Subscribe": #[0X03, 0X0E, 0X00, 0XEC, 0X03, 0X01, 0X00, 0X05, 0X01, 0X03, 0X00, 0X00, 0XC5, 0XD8],
47-
"Unsubscribe": #[0X03, 0X0E, 0X00, 0XEC, 0X03, 0X01, 0X00, 0X05, 0X01, 0X05, 0X00, 0X00, 0X65, 0X6A],
44+
"$(messages.Lora.MT) LORA": {
45+
"Transmit lblb, receive 5s": (messages.Lora.doMsg --payload="lblb".to-byte-array --receiveMs=5000).bytesForProtocol,
46+
"Subscribe": (messages.Lora.subscribeMsg).bytesForProtocol,
47+
"Unsubscribe": (messages.Lora.unsubscribeMsg).bytesForProtocol,
4848
},
4949
// "GSM": {
5050
// "SET Normal mode": #[0x03, 0x17, 0x00, 0x31, 0x00, 0x01, 0x00, 0x05, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x75, 0x30],

0 commit comments

Comments
 (0)