operate.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package modbus
  2. import (
  3. "server/model"
  4. "server/utils"
  5. "time"
  6. )
  7. // GetSunPowerInfo 获取太阳能信息
  8. func GetSunPowerInfo() {
  9. for _, conn := range model.ConnectionMap {
  10. //_, dev, err := utils.GetDataByDeviceId(id)
  11. utils.WriteDevice(SolarEnergyData(), conn)
  12. //if dev.IsSun && dev.State == 1 { //打开 并且在线
  13. // err = utils.WriteDevice(SolarEnergyData(), conn)
  14. // if err != nil {
  15. // return err
  16. // }
  17. //}
  18. }
  19. //return nil
  20. }
  21. // GetDeviceInfo 获取设备信息
  22. func GetDeviceInfo() {
  23. for id, conn := range model.ConnectionMap {
  24. _, dev, _ := utils.GetDataByDeviceId(id)
  25. utils.WriteDevice(ReadDeviceInfo(dev.LoopNumber), conn)
  26. }
  27. }
  28. // DealWithOffline 处理离线
  29. func DealWithOffline() {
  30. regions, _ := utils.LoadData()
  31. for i, region := range regions {
  32. for i2, device := range region.Devices {
  33. if time.Now().After(device.OnlineTime.Add(4*time.Minute)) && regions[i].Devices[i2].State != 0 {
  34. regions[i].Devices[i2].State = 0
  35. }
  36. }
  37. }
  38. utils.SaveData("static/data.json", regions)
  39. }