|
@@ -8,11 +8,13 @@ import (
|
|
"sparrow/pkg/tlv"
|
|
"sparrow/pkg/tlv"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+// CommandOrEventParam command or a event param struct
|
|
type CommandOrEventParam struct {
|
|
type CommandOrEventParam struct {
|
|
ValueType int32 `json:"value_type"`
|
|
ValueType int32 `json:"value_type"`
|
|
Name string
|
|
Name string
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// ProductCommandOrEvent ``
|
|
type ProductCommandOrEvent struct {
|
|
type ProductCommandOrEvent struct {
|
|
No int
|
|
No int
|
|
Part int
|
|
Part int
|
|
@@ -21,11 +23,14 @@ type ProductCommandOrEvent struct {
|
|
Params []CommandOrEventParam
|
|
Params []CommandOrEventParam
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// StatusParam 上报类型的参数
|
|
type StatusParam struct {
|
|
type StatusParam struct {
|
|
ValueType int32 `json:"value_type"`
|
|
ValueType int32 `json:"value_type"`
|
|
Name string
|
|
Name string
|
|
|
|
+ ID uint `json:"pid"` //protocal id 与后台对应
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// ProductObject 产品对象
|
|
type ProductObject struct {
|
|
type ProductObject struct {
|
|
Id int
|
|
Id int
|
|
No int
|
|
No int
|
|
@@ -34,13 +39,14 @@ type ProductObject struct {
|
|
Status []StatusParam
|
|
Status []StatusParam
|
|
}
|
|
}
|
|
|
|
|
|
-// product config parses the JSON product config string.
|
|
|
|
|
|
+// ProductConfig product config parses the JSON product config string.
|
|
type ProductConfig struct {
|
|
type ProductConfig struct {
|
|
Objects []ProductObject
|
|
Objects []ProductObject
|
|
Commands []ProductCommandOrEvent
|
|
Commands []ProductCommandOrEvent
|
|
Events []ProductCommandOrEvent
|
|
Events []ProductCommandOrEvent
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// New create a new productConfig
|
|
func New(config string) (*ProductConfig, error) {
|
|
func New(config string) (*ProductConfig, error) {
|
|
v := &ProductConfig{}
|
|
v := &ProductConfig{}
|
|
err := json.Unmarshal([]byte(config), v)
|
|
err := json.Unmarshal([]byte(config), v)
|
|
@@ -50,6 +56,7 @@ func New(config string) (*ProductConfig, error) {
|
|
return v, nil
|
|
return v, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// ValidateStatus validate the status
|
|
func (config *ProductConfig) ValidateStatus(label string, params []interface{}) (*ProductObject, []interface{}, error) {
|
|
func (config *ProductConfig) ValidateStatus(label string, params []interface{}) (*ProductObject, []interface{}, error) {
|
|
// search for status name
|
|
// search for status name
|
|
var paramInfo []StatusParam
|
|
var paramInfo []StatusParam
|
|
@@ -76,6 +83,7 @@ func (config *ProductConfig) ValidateStatus(label string, params []interface{})
|
|
return status, realParams, nil
|
|
return status, realParams, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// ValidateCommandOrEvent validate command or event
|
|
func (config *ProductConfig) ValidateCommandOrEvent(name string, params []interface{}, typ string) (*ProductCommandOrEvent, []interface{}, error) {
|
|
func (config *ProductConfig) ValidateCommandOrEvent(name string, params []interface{}, typ string) (*ProductCommandOrEvent, []interface{}, error) {
|
|
var target []ProductCommandOrEvent
|
|
var target []ProductCommandOrEvent
|
|
if typ == "command" {
|
|
if typ == "command" {
|
|
@@ -111,6 +119,7 @@ func (config *ProductConfig) ValidateCommandOrEvent(name string, params []interf
|
|
return coe, realParams, nil
|
|
return coe, realParams, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// StatusToMap struct to map
|
|
func (config *ProductConfig) StatusToMap(status []protocol.SubData) (map[string][]interface{}, error) {
|
|
func (config *ProductConfig) StatusToMap(status []protocol.SubData) (map[string][]interface{}, error) {
|
|
result := make(map[string][]interface{})
|
|
result := make(map[string][]interface{})
|
|
|
|
|
|
@@ -131,9 +140,9 @@ func (config *ProductConfig) StatusToMap(status []protocol.SubData) (map[string]
|
|
return result, nil
|
|
return result, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// EventToMap event ot map
|
|
func (config *ProductConfig) EventToMap(event *protocol.Event) (map[string][]interface{}, error) {
|
|
func (config *ProductConfig) EventToMap(event *protocol.Event) (map[string][]interface{}, error) {
|
|
result := make(map[string][]interface{})
|
|
result := make(map[string][]interface{})
|
|
-
|
|
|
|
name := ""
|
|
name := ""
|
|
for _, ev := range config.Events {
|
|
for _, ev := range config.Events {
|
|
if ev.No == int(event.Head.No) {
|
|
if ev.No == int(event.Head.No) {
|
|
@@ -150,6 +159,7 @@ func (config *ProductConfig) EventToMap(event *protocol.Event) (map[string][]int
|
|
return result, nil
|
|
return result, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// MapToStatus map to status
|
|
func (config *ProductConfig) MapToStatus(data map[string]interface{}) ([]protocol.SubData, error) {
|
|
func (config *ProductConfig) MapToStatus(data map[string]interface{}) ([]protocol.SubData, error) {
|
|
result := []protocol.SubData{}
|
|
result := []protocol.SubData{}
|
|
|
|
|