package iotReportProtocol import ( "IotAdmin/common/global" "IotAdmin/core/logger" "IotAdmin/core/sdk" iotInterface "IotAdmin/iot/interface" iotMap "IotAdmin/iot/map" iotProtocol "IotAdmin/iot/protocol" iotStruct "IotAdmin/iot/struct" "IotAdmin/iot/struct/electric" "encoding/json" "errors" "strconv" "time" ) func getMeterElectricCalc(cfg *iotStruct.SlaveConfig) (calc iotInterface.MeterCalcHandler, tms int, err error) { now := time.Now() today, _ := strconv.Atoi(now.Format("20060102")) tms = today if x, ok := iotMap.MapMeterCalc.Get(cfg.No); ok { calc = *x } else { calc, err = GetMeterCalcHandler(cfg.Protocol, cfg.No, today, "", cfg.OtherConfig) } return } // GetMeterCalcHandler 获取表计协议计算处理器 func GetMeterCalcHandler(protocol string, id string, time int, calc, cfg string) (handler iotInterface.MeterCalcHandler, err error) { switch protocol { case iotProtocol.MeterElAdw300: handler, err = electric.NewMeterADW300(id, time, calc, cfg) case iotProtocol.MeterElPmc350b: handler, err = electric.NewMeterPMC350B(id, time, calc, cfg) default: err = errors.New("not support protocol") } return } func updateMeterCalc(elMeter electric.MeterElectric, calc *iotInterface.MeterCalcHandler) { q := sdk.Runtime.GetMemoryQueue("") data, err := json.Marshal(elMeter) if err != nil { logger.Errorf("更新电表计算参数失败: %s", err.Error()) return } mp := make(map[string]interface{}) mp["data"] = string(data) mp["id"] = elMeter.Id mp["time"] = elMeter.Time message, err := sdk.Runtime.GetStreamMessage("", global.UpdateMeterCalc, mp) if err != nil { logger.Errorf("构建更新表计计算参数 message [%s]失败: %v", global.UpdateMeterCalc, err) return } err = q.Append(message) if err != nil { return } iotMap.MapMeterCalc.Add(elMeter.Id, calc) }