123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package modbus
- import (
- "server/logger"
- "server/model"
- "server/utils"
- "time"
- )
- // GetSunPowerInfo 获取太阳能信息
- func GetSunPowerInfo() error {
- for id, conn := range model.ConnectionMap {
- _, dev, err := utils.GetDataByDeviceId(id)
- 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, err := utils.LoadData()
- if err != nil {
- logger.Get().Errorln("离线" + err.Error())
- return
- }
- for i, region := range regions {
- for i2, device := range region.Devices {
- if time.Now().After(device.OnlineTime.Add(8*time.Minute)) && regions[i].Devices[i2].State != 0 {
- regions[i].Devices[i2].State = 0
- }
- }
- }
- if len(regions) == 0 {
- return
- }
- err = utils.SaveData("static/data.json", regions)
- logger.Get().Errorln("离线保存" + err.Error())
- }
|