| | |
| | | ) |
| | | |
| | | 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 |
| | |
| | | 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 { |