zhangzengfei
2023-08-10 0718b07276198334437f52aa5c6c07cca2002225
collector/device.go
@@ -10,7 +10,7 @@
)
func getDeviceList() ([]msg.PLCDevice, error) {
   responseBody, err := util.HttpPost(config.Options.ApsDeviceWebApi, nil)
   responseBody, err := util.HttpPost(config.Options.DeviceListWebApi, nil)
   if err != nil {
      logger.Warn("get device list from aps error:%s", err.Error())
      return nil, err
@@ -32,16 +32,16 @@
func HandleDeviceUpdate(message []byte) error {
   var device msg.PLCDevice
   logger.Debug("receive device update msg: %s", string(message))
   err := json.Unmarshal(message, &device)
   if err != nil {
      logger.Error("unmarshal device update msg error:%s", err.Error())
      return err
   }
   if task, ok := mapTask.Load(device.DeviceID); ok {
      // 存在的任务, 先停止掉, 然后重新开启一个
      task.(collectorProc).cancel()
   }
   // 先停掉正在执行的任务
   stopTask(&device)
   // 判断是否是重新启动的状态, 启动一个新的任务
   if device.Status == 0 {