package MqttServer import ( "Cold_mqtt/logs" "Cold_mqtt/models/Device" "Cold_mqtt/models/Product" "time" ) func Read_DeviceParameter(T_sn string) { r_Device, err := Device.Read_Device_ByT_sn(T_sn) if err != nil { logs.Println("Read_DeviceParameter 没有该设备:", T_sn) return } if r_Device.T_online != 1 && r_Device.T_online_s != 1 { logs.Println("Read_DeviceParameter 设备不在线:", r_Device.T_sn) return } // 协议区分 switch r_Device.T_protocol { case 3: Read_DeviceParameter3(r_Device.T_sn) default: Read_DeviceParameter3(r_Device.T_sn) } return } func Read_DeviceSensorParameter(T_sn string) { time.Sleep(time.Second * 3) r_Device, err := Device.Read_Device_ByT_sn(T_sn) if err != nil { logs.Println("Read_DeviceSensorParameter 没有该设备:", T_sn) return } if r_Device.T_online != 1 && r_Device.T_online_s != 1 { logs.Println("Read_DeviceSensorParameter 设备不在线:", r_Device.T_sn) return } // 协议区分 switch r_Device.T_protocol { case 3: Read_DeviceSensorParameter3(r_Device.T_sn) default: Read_DeviceSensorParameter3(r_Device.T_sn) } return } // 修改设备参数 func Pu_DeviceParameter(Rt_DeviceParameter Device.DeviceParameter) { r_Device, err := Device.Read_Device_ByT_sn(Rt_DeviceParameter.T_sn) if err != nil { logs.Println("Pu_DeviceParameter 没有该设备:", Rt_DeviceParameter.T_sn) return } if r_Device.T_online != 1 && r_Device.T_online_s != 1 { logs.Println("Pu_DeviceParameter 设备不在线:", r_Device.T_sn) return } // 协议区分 switch r_Device.T_protocol { case 3: Pu_DeviceParameter3(Rt_DeviceParameter) default: Pu_DeviceParameter3(Rt_DeviceParameter) } return } // 修改传感器参数 func Pu_DeviceParameter_Sensor(Rt_parameter_sensor Device.DeviceSensorParameter) { r_Device, err := Device.Read_Device_ByT_sn(Rt_parameter_sensor.T_sn) if err != nil { logs.Println("Pu_DeviceParameter_Sensor 没有该设备:", Rt_parameter_sensor.T_sn) return } if r_Device.T_online != 1 && r_Device.T_online_s != 1 { logs.Println("Pu_DeviceParameter_Sensor 设备不在线:", r_Device.T_sn) return } // 协议区分 switch r_Device.T_protocol { case 3: Pu_DeviceParameter_Sensor3(Rt_parameter_sensor) default: Pu_DeviceParameter_Sensor3(Rt_parameter_sensor) } return } func Set_DeviceTask(v Device.Device_task) { r_Device, err := Device.Read_Device_ByT_sn(v.T_sn) if err != nil { logs.Println("Set_DeviceTask 没有该设备:", v.T_sn) return } if r_Device.T_online != 1 && r_Device.T_online_s != 1 { logs.Println("Set_DeviceTask 设备不在线:", r_Device.T_sn) return } // 协议区分 switch r_Device.T_protocol { case 3: Set_DeviceTask3(v) default: Set_DeviceTask3(v) } return } func Set_RestartShutdown(v Device.Device_task) { r_Device, err := Device.Read_Device_ByT_sn(v.T_sn) if err != nil { logs.Println("Set_DeviceTask 没有该设备:", v.T_sn) return } if r_Device.T_online != 1 && r_Device.T_online_s != 1 { logs.Println("Set_RestartShutdown 设备不在线:", r_Device.T_sn) return } // 协议区分 switch r_Device.T_protocol { case 3: Set_DeviceRestart3(v) default: Set_DeviceRestart3(v) } return } func Get_Device_Realtime(T_sn string) { r_Device, err := Device.Read_Device_ByT_sn(T_sn) if err != nil { logs.Println("Get_Device_Realtime 没有该设备:", T_sn) return } if r_Device.T_online != 1 && r_Device.T_online_s != 1 { logs.Println("Get_Device_Realtime 设备不在线:", T_sn) return } if DeviceParameter, is := Device.Read_DeviceParameter(r_Device.T_sn); is { if DeviceParameter.T_dormancy == 1 { logs.Println("Get_Device_Realtime 设备进入休眠!!!", T_sn) return } } // 协议区分 switch r_Device.T_protocol { case 3: Get_Device_Realtime3(r_Device.T_sn) default: Get_Device_Realtime3(r_Device.T_sn) } return } func Up_ProductUpgrade(v Product.ProductUpgrade_T) { r_Device, err := Device.Read_Device_ByT_sn(v.T_sn) if err != nil { logs.Println("Up_ProductUpgrade 没有该设备:", v.T_sn) return } if r_Device.T_online != 1 && r_Device.T_online_s != 1 { logs.Println("Up_ProductUpgrade 设备不在线:", r_Device.T_sn) return } // 协议区分 switch r_Device.T_protocol { case 3: Up_DeviceProductUpgrade(v) default: Up_DeviceProductUpgrade(v) } return }