123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- 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
- }
|