-
Notifications
You must be signed in to change notification settings - Fork 108
/
deviceshifumqttconfig.go
52 lines (43 loc) · 1.46 KB
/
deviceshifumqttconfig.go
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
package deviceshifumqtt
import (
"github.com/edgenesis/shifu/pkg/deviceshifu/deviceshifubase"
"github.com/edgenesis/shifu/pkg/logger"
)
const (
mqttTopic = "MQTTTopic"
)
// ReturnBody Body of mqtt's reply
type ReturnBody struct {
MQTTMessage string `json:"mqtt_message"`
MQTTTimestamp string `json:"mqtt_receive_timestamp"`
}
// RequestBody Body of mqtt's request by POST method
type RequestBody string
// MQTTInstructions MQTT Instructions
type MQTTInstructions struct {
Instructions map[string]*MQTTInstruction
}
// MQTTInstruction MQTT Instruction
type MQTTInstruction struct {
MQTTProtocolProperty *MQTTProtocolProperty
}
// MQTTProtocolProperty MQTT Instruction's Property
type MQTTProtocolProperty struct {
MQTTTopic string
}
// CreateMQTTInstructions Create MQTT Instructions
func CreateMQTTInstructions(dsInstructions *deviceshifubase.DeviceShifuInstructions) *MQTTInstructions {
instructions := make(map[string]*MQTTInstruction)
for key, dsInstruction := range dsInstructions.Instructions {
if dsInstruction.DeviceShifuProtocolProperties != nil && dsInstruction.DeviceShifuProtocolProperties[mqttTopic] == "" {
logger.Fatalf("Error when Read MQTTTopic From DeviceShifuInstructions, error: instruction %v has an empty topic", key)
}
instruction := &MQTTInstruction{
&MQTTProtocolProperty{
MQTTTopic: dsInstruction.DeviceShifuProtocolProperties[mqttTopic],
},
}
instructions[key] = instruction
}
return &MQTTInstructions{instructions}
}