Newer
Older
func (tm *SssMgr) oneM2M_subscribe_discovery_event(requestedIotPlatformId string) (err error) {
return nil
}
func (tm *SssMgr) oneM2M_deserialize(sensor SensorDiscoveryInfo, response map[string]interface{}) (sensorResp SensorDiscoveryInfo, err error) {
sensorResp = sensor // Same data structure
log.Debug(">>> oneM2M_deserialize: response: ", response)
for i, m := range response {
log.Debug("==> ", i, " value is ", m)
if _, ok := m.(map[string]interface{}); !ok {
// Skip it
log.Warn("oneM2M_deserialize: m is not map[string]interface{}")
continue
}
// m is a map[string]interface.
// loop over keys and values in the map.
log.Debug(k, " value is ", v)
log.Debug("oneM2M_deserialize: type(v): ", reflect.TypeOf(v))
if k == "ri" {
if item, ok := v.(string); ok {
log.Error("oneM2M_deserialize: Failed to process ", k)
if item, ok := v.(float64); ok {
switch item {
case 2:
sensorResp.SensorType = "AE"
case 3:
sensorResp.SensorType = "CNT"
case 4:
sensorResp.SensorType = "CNI"
default:
sensorResp.SensorType = strconv.FormatFloat(item, 'f', -1, 64)
}
log.Error("oneM2M_deserialize: Failed to process ", k)
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
if item, ok := v.(string); ok {
sensorResp.SensorCharacteristicList = append(
sensorResp.SensorCharacteristicList,
SensorCharacteristic{
CharacteristicName: k,
CharacteristicValue: string(item),
})
} else if item, ok := v.(float64); ok {
sensorResp.SensorCharacteristicList = append(
sensorResp.SensorCharacteristicList,
SensorCharacteristic{
CharacteristicName: k,
CharacteristicValue: strconv.FormatFloat(item, 'f', -1, 64),
})
} else if item, ok := v.(int64); ok {
sensorResp.SensorCharacteristicList = append(
sensorResp.SensorCharacteristicList,
SensorCharacteristic{
CharacteristicName: k,
CharacteristicValue: strconv.FormatInt(item, 10),
})
} else if item, ok := v.(bool); ok {
sensorResp.SensorCharacteristicList = append(
sensorResp.SensorCharacteristicList,
SensorCharacteristic{
CharacteristicName: k,
CharacteristicValue: strconv.FormatBool(item),
})
} else if item, ok := v.([]string); ok {
sensorResp.SensorCharacteristicList = append(
sensorResp.SensorCharacteristicList,
SensorCharacteristic{
CharacteristicName: k,
CharacteristicValue: strings.Join(item, ","),
})
} else if item, ok := v.([]int64); ok {
log.Error("oneM2M_deserialize: Failed to convert list of int64 into string: ", item)
} else if item, ok := v.([]interface{}); ok {
log.Debug("oneM2M_deserialize: Got []interface {} for ", k)
log.Debug("oneM2M_deserialize: ValueOf ", reflect.ValueOf(item))
s := SensorCharacteristic{
CharacteristicName: k,
}
var buf bytes.Buffer
fmt.Fprintf(&buf, "%T", item)
s.CharacteristicValue = buf.String()
sensorResp.SensorCharacteristicList = append(sensorResp.SensorCharacteristicList, s)
} else {
log.Error("oneM2M_deserialize: Failed to process: ", k)
}
}
} // End of 'for' loop
} // End of 'for' loop
log.Debug("oneM2M_deserialize: sensorResp: ", sensorResp)