123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- package Handle
- import (
- "ColdP_server/controllers/MqttServer"
- "ColdP_server/controllers/lib"
- "ColdP_server/models/Device"
- "ColdP_server/models/System"
- "encoding/json"
- "fmt"
- "time"
- )
- func Go_Read_DeviceParameter() {
- for true {
- for k, _ := range lib.CountryRead_DeviceParameterSnMap {
- fmt.Println("CountryRead_DeviceParameterSnMap => KEY", k)
- Read_DeviceParameter(k)
- delete(lib.CountryRead_DeviceParameterSnMap, k)
- }
- time.Sleep(1)
- }
- }
- func init() {
- //go Go_Read_DeviceParameter()
- }
- func Read_DeviceParameter(T_sn string) {
- // base 读取基本参数
- Msid := lib.Random(1, 9999)
- Rt_parameter := MqttServer.Rt_Parameter{
- Sn: T_sn,
- Type: 3,
- Param: "base",
- Msid: (Msid * 10) + 1,
- }
- // offset 温湿度补偿
- Msid = lib.Random(1, 9999)
- Rt_parameter.Param = "offset"
- Rt_parameter.Msid = (Msid * 10) + 3
- // 回复
- jsonStu, err := json.Marshal(Rt_parameter)
- if err != nil {
- System.Add_Logs("MqttServer", "参数请求 [Rt_Parameter]", "offset")
- fmt.Println("回复失败 [Rt_Parameter],err=", err)
- }
- fmt.Println(string(jsonStu))
- MqttServer.Mqtt_publish(T_sn, string(jsonStu))
- //lib.CountryMsidMap[(Msid*10)+3] = T_uuid // Mqtt 消息透传
- return
- }
- func Pu_DeviceParameter(T_uuid string, T_sn string, Rt_parameter_base_ MqttServer.Rt_Parameter_Base_) {
- // base 读取基本参数
- Msid := lib.Random(1, 9999)
- Rt_parameter := MqttServer.Rt_Parameter_Base{
- Sn: T_sn,
- Type: 4,
- Msid: (Msid * 10) + 1,
- Base: Rt_parameter_base_,
- }
- // 回复
- jsonStu, err := json.Marshal(Rt_parameter)
- if err != nil {
- System.Add_Logs("设备配置", "MQTT回复失败 [Pu_DeviceParameter]", string(jsonStu))
- fmt.Println("设备配置 MQTT回复失败 [Pu_DeviceParameter],err=", err)
- return
- }
- fmt.Println(string(jsonStu))
- MqttServer.Mqtt_publish(T_sn, string(jsonStu))
- //lib.CountryMsidMap[(Msid*10)+1] = T_uuid // Mqtt 消息透传
- Deviceparameter := Device.DeviceParameter{
- T_sn: T_sn,
- T_devName: Rt_parameter_base_.T_devName,
- T_uploadTime: Rt_parameter_base_.T_uploadTime,
- T_saveTime: Rt_parameter_base_.T_saveTime,
- T_overrunSave: Rt_parameter_base_.T_overrunSave,
- T_overrunAlarm: Rt_parameter_base_.T_overrunAlarm,
- T_outageAlarm: Rt_parameter_base_.T_outageAlarm,
- T_lostAlarm: Rt_parameter_base_.T_lostAlarm,
- T_warningTime: Rt_parameter_base_.T_warningTime,
- T_warningDelay: Rt_parameter_base_.T_warningDelay,
- T_batteryLimit: Rt_parameter_base_.T_batteryLimit,
- T_tempPre: Rt_parameter_base_.T_tempPre,
- T_humPre: Rt_parameter_base_.T_humPre,
- T_enwarning: Rt_parameter_base_.T_enwarning,
- T_uuid: T_uuid,
- T_Msid: (Msid * 10) + 1,
- T_SendState: 0,
- T_State: 2,
- }
- if !Device.Add_DeviceParameter(Deviceparameter) {
- System.Add_Logs("设备配置", "插入失败 [Pu_DeviceParameter]", string(jsonStu))
- fmt.Println("设备配置 [Pu_DeviceParameter],err=", err)
- }
- return
- }
- func Pu_DeviceParameter_Sensor(T_uuid string, T_sn string, Rt_parameter_sensor_ []MqttServer.Rt_Parameter_Sensor_) {
- // base 读取基本参数
- Msid := lib.Random(1, 9999)
- Rt_parameter := MqttServer.Rt_Parameter_Sensor{
- Sn: T_sn,
- Type: 4,
- Msid: (Msid * 10) + 2,
- Sensor: Rt_parameter_sensor_,
- }
- // 回复
- jsonStu, err := json.Marshal(Rt_parameter)
- if err != nil {
- System.Add_Logs("设备配置", "MQTT回复失败 [Pu_DeviceParameter_Sensor]", string(jsonStu))
- fmt.Println("设备配置 MQTT回复失败 [Pu_DeviceParameter_Sensor],err=", err)
- }
- fmt.Println(string(jsonStu))
- MqttServer.Mqtt_publish(T_sn, string(jsonStu))
- //lib.CountryMsidMap[(Msid*10)+2] = T_uuid // Mqtt 消息透传
- //
- ///
- for _, v := range Rt_parameter_sensor_ {
- // 记录传感器
- Devicesensorparameter := Device.DeviceSensorParameter{
- T_sn: T_sn,
- T_id: v.T_id,
- T_name: v.T_name,
- T_Tlower: v.T_Tlower,
- T_Tupper: v.T_Tupper,
- T_RHlower: v.T_RHlower,
- T_RHupper: v.T_RHupper,
- T_en: v.T_en,
- T_free: v.T_free,
- T_uuid: T_uuid,
- T_Msid: (Msid * 10) + 2,
- T_SendState: 0,
- T_State: 2,
- }
- if !Device.Add_DeviceSensorParameter(Devicesensorparameter) {
- System.Add_Logs("设备配置", "插入失败 [Pu_DeviceParameter_Sensor]", string(jsonStu))
- fmt.Println("设备配置 [Pu_DeviceParameter_Sensor],err=", err)
- }
- }
- return
- }
- func Pu_DeviceParameter_Compensate(T_uuid string, T_sn string, Rt_parameter_compensate_ []MqttServer.Rt_Parameter_Compensate_) {
- // base 读取基本参数
- Msid := lib.Random(1, 9999)
- Rt_parameter_offset := MqttServer.Rt_Parameter_Offset{
- Sn: T_sn,
- Type: 4,
- Msid: (Msid * 10) + 3,
- Offset: Rt_parameter_compensate_,
- }
- // 回复
- jsonStu, err := json.Marshal(Rt_parameter_offset)
- if err != nil {
- System.Add_Logs("MqttServer", "参数请求 [Pu_DeviceParameter_Compensate]", "Offset")
- fmt.Println("回复失败 [Pu_DeviceParameter_Compensate],err=", err)
- }
- fmt.Println(string(jsonStu))
- MqttServer.Mqtt_publish(T_sn, string(jsonStu))
- // lib.CountryMsidMap[(Msid*10)+3] = T_uuid // Mqtt 消息透传
- ///
- return
- }
|