package common_models import ( "encoding/json" "fmt" ) type DeviceMeta struct { Id string `json:"id"` Name string `json:"name"` Model string `json:"model"` Properties []iotaProperty `json:"properties"` Capabilities []iotaCapability `json:"capabilities"` } // "meta" : { // "windspeed" : "风速(m/s)", // "pm25" : "PM2.5(ug/m³)", // "pm10" : "PM10(ug/m³)", // "noise" : "噪声(db)", // "winddir" : "风向(°)", // "humidity" : "湿度(%)", // "temp" : "温度(℃)" // } func (m *DeviceMeta) GetOutputProps() (out map[string]string) { out = make(map[string]string) if len(m.Capabilities) == 0 { return } for _, property := range m.Capabilities[0].Properties { info := fmt.Sprintf("%s(%s)", property.ShowName, property.Unit) out[property.Name] = info } return } func (m *DeviceMeta) GetOutputUnit() (out map[string]string) { out = make(map[string]string) if len(m.Capabilities) == 0 { return } for _, property := range m.Capabilities[0].Properties { out[property.Name] = property.Unit } return } // redis序列化 func (m *DeviceMeta) MarshalBinary() (data []byte, err error) { return json.Marshal(m) } // redis序列化 func (m *DeviceMeta) UnmarshalBinary(data []byte) error { return json.Unmarshal(data, m) } type iotaCapability struct { CapabilityCategoryId int `json:"capabilityCategoryId"` Id string `json:"id"` Name string `json:"name"` Properties []iotaProperty `json:"properties"` } type iotaProperty struct { Category string `json:"category"` Name string `json:"name"` ShowName string `json:"showName"` Unit string `json:"unit"` }