-
Notifications
You must be signed in to change notification settings - Fork 2
/
BoolMessage.sedona
57 lines (53 loc) · 1.68 KB
/
BoolMessage.sedona
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
**
** Bool message defines a boolean type MQTT topic data point. There are 2 use cases:
** 1. when put it within a Publisher object, it will publish it's payload to
** the MQTT broker configured by the Publisher object (publishing mode)
** 2. when put it within a Subscriber object, it will fetch data from MQTT broker
** configured by the Subscriber object (subscription mode)
**
** Just like other type of Message object, BoolMessage's parent must be Publisher or Subscriber, otherwise it will not work
**
** By BoolMessage, you can configure the following MQTT related things:
** 1. MQTT topic
** 2. MQTT QoS
** 3. publishInterval (how often to publish data, publishing mode)
** 4. updateInterval (how often to check data update, subscription mode)
**
** The 'error' slot will show error message if something is wrong.
**
class BoolMessage extends Message
{
property bool payload = false
**
** return the payload string,
** shouldn't be called by outside
**
protected override Str getPayload()
{
Str s = null
if (payload == true)
s = "1"
else if (payload == false)
s = "0"
else
s = "2"
return s
}
**
** callback method to update local data,
** shouldn't be called by outside
**
protected override bool updateData(Obj handle)
{
bool result = super.updateData(handle)
if (!result)
return result
if (strBuf.equals("true") || strBuf.equals("True") || strBuf.equals("TRUE") || strBuf.equals("1"))
payload := true
else if (strBuf.equals("false") || strBuf.equals("False") || strBuf.equals("FALSE") || strBuf.equals("0"))
payload := false
else
payload := null
return result
}
}