12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package modbus
- import (
- "server/model"
- "server/utils"
- "time"
- )
- // GetSunPowerInfo 获取太阳能信息
- func GetSunPowerInfo() {
- for _, conn := range model.ConnectionMap {
- //_, dev, err := utils.GetDataByDeviceId(id)
- utils.WriteDevice(SolarEnergyData(), conn)
- //if dev.IsSun && dev.State == 1 { //打开 并且在线
- // err = utils.WriteDevice(SolarEnergyData(), conn)
- // if err != nil {
- // return err
- // }
- //}
- }
- //return nil
- }
- // GetDeviceInfo 获取设备信息
- func GetDeviceInfo() {
- for id, conn := range model.ConnectionMap {
- _, dev, _ := utils.GetDataByDeviceId(id)
- utils.WriteDevice(ReadDeviceInfo(dev.LoopNumber), conn)
- }
- }
- // DealWithOffline 处理离线
- func DealWithOffline() {
- regions, _ := utils.LoadData()
- for i, region := range regions {
- for i2, device := range region.Devices {
- if time.Now().After(device.OnlineTime.Add(4*time.Minute)) && regions[i].Devices[i2].State != 0 {
- regions[i].Devices[i2].State = 0
- }
- }
- }
- utils.SaveData("static/data.json", regions)
- }
|