MqttControllers.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. package MqttServer
  2. import (
  3. "Cold_mqtt/logs"
  4. "Cold_mqtt/models/Device"
  5. "Cold_mqtt/models/Product"
  6. "time"
  7. )
  8. func Read_DeviceParameter(T_sn string) {
  9. r_Device, err := Device.Read_Device_ByT_sn(T_sn)
  10. if err != nil {
  11. logs.Println("Read_DeviceParameter 没有该设备:", T_sn)
  12. return
  13. }
  14. if r_Device.T_online != 1 && r_Device.T_online_s != 1 {
  15. logs.Println("Read_DeviceParameter 设备不在线:", r_Device.T_sn)
  16. return
  17. }
  18. // 协议区分
  19. switch r_Device.T_protocol {
  20. case 3:
  21. Read_DeviceParameter3(r_Device.T_sn)
  22. default:
  23. Read_DeviceParameter3(r_Device.T_sn)
  24. }
  25. return
  26. }
  27. func Read_DeviceSensorParameter(T_sn string) {
  28. time.Sleep(time.Second * 3)
  29. r_Device, err := Device.Read_Device_ByT_sn(T_sn)
  30. if err != nil {
  31. logs.Println("Read_DeviceSensorParameter 没有该设备:", T_sn)
  32. return
  33. }
  34. if r_Device.T_online != 1 && r_Device.T_online_s != 1 {
  35. logs.Println("Read_DeviceSensorParameter 设备不在线:", r_Device.T_sn)
  36. return
  37. }
  38. // 协议区分
  39. switch r_Device.T_protocol {
  40. case 3:
  41. Read_DeviceSensorParameter3(r_Device.T_sn)
  42. default:
  43. Read_DeviceSensorParameter3(r_Device.T_sn)
  44. }
  45. return
  46. }
  47. // 修改设备参数
  48. func Pu_DeviceParameter(Rt_DeviceParameter Device.DeviceParameter) {
  49. r_Device, err := Device.Read_Device_ByT_sn(Rt_DeviceParameter.T_sn)
  50. if err != nil {
  51. logs.Println("Pu_DeviceParameter 没有该设备:", Rt_DeviceParameter.T_sn)
  52. return
  53. }
  54. if r_Device.T_online != 1 && r_Device.T_online_s != 1 {
  55. logs.Println("Pu_DeviceParameter 设备不在线:", r_Device.T_sn)
  56. return
  57. }
  58. // 协议区分
  59. switch r_Device.T_protocol {
  60. case 3:
  61. Pu_DeviceParameter3(Rt_DeviceParameter)
  62. default:
  63. Pu_DeviceParameter3(Rt_DeviceParameter)
  64. }
  65. return
  66. }
  67. // 修改传感器参数
  68. func Pu_DeviceParameter_Sensor(Rt_parameter_sensor Device.DeviceSensorParameter) {
  69. r_Device, err := Device.Read_Device_ByT_sn(Rt_parameter_sensor.T_sn)
  70. if err != nil {
  71. logs.Println("Pu_DeviceParameter_Sensor 没有该设备:", Rt_parameter_sensor.T_sn)
  72. return
  73. }
  74. if r_Device.T_online != 1 && r_Device.T_online_s != 1 {
  75. logs.Println("Pu_DeviceParameter_Sensor 设备不在线:", r_Device.T_sn)
  76. return
  77. }
  78. // 协议区分
  79. switch r_Device.T_protocol {
  80. case 3:
  81. Pu_DeviceParameter_Sensor3(Rt_parameter_sensor)
  82. default:
  83. Pu_DeviceParameter_Sensor3(Rt_parameter_sensor)
  84. }
  85. return
  86. }
  87. func Set_DeviceTask(v Device.Device_task) {
  88. r_Device, err := Device.Read_Device_ByT_sn(v.T_sn)
  89. if err != nil {
  90. logs.Println("Set_DeviceTask 没有该设备:", v.T_sn)
  91. return
  92. }
  93. if r_Device.T_online != 1 && r_Device.T_online_s != 1 {
  94. logs.Println("Set_DeviceTask 设备不在线:", r_Device.T_sn)
  95. return
  96. }
  97. // 协议区分
  98. switch r_Device.T_protocol {
  99. case 3:
  100. Set_DeviceTask3(v)
  101. default:
  102. Set_DeviceTask3(v)
  103. }
  104. return
  105. }
  106. func Set_RestartShutdown(v Device.Device_task) {
  107. r_Device, err := Device.Read_Device_ByT_sn(v.T_sn)
  108. if err != nil {
  109. logs.Println("Set_DeviceTask 没有该设备:", v.T_sn)
  110. return
  111. }
  112. if r_Device.T_online != 1 && r_Device.T_online_s != 1 {
  113. logs.Println("Set_RestartShutdown 设备不在线:", r_Device.T_sn)
  114. return
  115. }
  116. // 协议区分
  117. switch r_Device.T_protocol {
  118. case 3:
  119. Set_DeviceRestart3(v)
  120. default:
  121. Set_DeviceRestart3(v)
  122. }
  123. return
  124. }
  125. func Get_Device_Realtime(T_sn string) {
  126. r_Device, err := Device.Read_Device_ByT_sn(T_sn)
  127. if err != nil {
  128. logs.Println("Get_Device_Realtime 没有该设备:", T_sn)
  129. return
  130. }
  131. if r_Device.T_online != 1 && r_Device.T_online_s != 1 {
  132. logs.Println("Get_Device_Realtime 设备不在线:", T_sn)
  133. return
  134. }
  135. if DeviceParameter, is := Device.Read_DeviceParameter(r_Device.T_sn); is {
  136. if DeviceParameter.T_dormancy == 1 {
  137. logs.Println("Get_Device_Realtime 设备进入休眠!!!", T_sn)
  138. return
  139. }
  140. }
  141. // 协议区分
  142. switch r_Device.T_protocol {
  143. case 3:
  144. Get_Device_Realtime3(r_Device.T_sn)
  145. default:
  146. Get_Device_Realtime3(r_Device.T_sn)
  147. }
  148. return
  149. }
  150. func Up_ProductUpgrade(v Product.ProductUpgrade_T) {
  151. r_Device, err := Device.Read_Device_ByT_sn(v.T_sn)
  152. if err != nil {
  153. logs.Println("Up_ProductUpgrade 没有该设备:", v.T_sn)
  154. return
  155. }
  156. if r_Device.T_online != 1 && r_Device.T_online_s != 1 {
  157. logs.Println("Up_ProductUpgrade 设备不在线:", r_Device.T_sn)
  158. return
  159. }
  160. // 协议区分
  161. switch r_Device.T_protocol {
  162. case 3:
  163. Up_DeviceProductUpgrade(v)
  164. default:
  165. Up_DeviceProductUpgrade(v)
  166. }
  167. return
  168. }