Skip to content

Commit

Permalink
优化日志
Browse files Browse the repository at this point in the history
  • Loading branch information
smthing committed Jun 3, 2024
1 parent 8a1f697 commit 558e05f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 37 deletions.
6 changes: 3 additions & 3 deletions internal/core/batch_send.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ func tryReadNewValues(deviceId string, points []plugin.PointData) {
for i < 10 {
i++
time.Sleep(time.Duration(i*100) * time.Millisecond)
helper.Logger.Info("point write success,try to read new value", zap.Any("points", readPoints))
helper.Logger.Info("point write success,try to read new value", zap.String("deviceId", deviceId), zap.Any("points", readPoints))
err := SendBatchRead(deviceId, readPoints)
if err != nil {
helper.Logger.Error("point write success, read new value error", zap.Any("points", readPoints), zap.Error(err))
helper.Logger.Error("point write success, read new value error", zap.String("deviceId", deviceId), zap.Any("points", readPoints), zap.Error(err))
break
}

ok := true
for _, p := range readPoints {
value, _ := helper.DeviceShadow.GetDevicePoint(deviceId, p.PointName)
helper.Logger.Info("point write success, read new value", zap.String("point", p.PointName), zap.Any("expect", p.Value), zap.Any("value", value))
helper.Logger.Info("point write success, read new value", zap.String("deviceId", deviceId), zap.String("point", p.PointName), zap.Any("expect", p.Value), zap.Any("value", value))
if fmt.Sprint(p.Value) != fmt.Sprint(value) {
ok = false
break
Expand Down
34 changes: 0 additions & 34 deletions internal/core/single_send.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/ibuilding-x/driver-box/driverbox/plugin"
"github.com/ibuilding-x/driver-box/internal/logger"
"go.uber.org/zap"
"time"
)

// 单点操作
Expand Down Expand Up @@ -125,36 +124,3 @@ func singleWrite(deviceId string, pointData plugin.PointData) error {
}
return err
}

// 尝试读取期望点位值
func tryReadNewValue(deviceId, pointName string, expectValue interface{}) {
point, ok := helper.CoreCache.GetPointByDevice(deviceId, pointName)
if !ok {
return
}
if point.ReadWrite != config.ReadWrite_R && point.ReadWrite != config.ReadWrite_RW {
return
}
//延迟100毫秒触发读操作
go func(deviceId, pointName string, expectValue interface{}) {
i := 0
for i < 10 {
i++
time.Sleep(time.Duration(i*100) * time.Millisecond)
helper.Logger.Info("point write success,try to read new value", zap.String("point", pointName))
err := SendSinglePoint(deviceId, plugin.ReadMode, plugin.PointData{
PointName: pointName,
})
if err != nil {
helper.Logger.Error("point write success, read new value error", zap.String("point", pointName), zap.Error(err))
break
}

value, _ := helper.DeviceShadow.GetDevicePoint(deviceId, pointName)
helper.Logger.Info("point write success, read new value", zap.String("point", pointName), zap.Any("expect", expectValue), zap.Any("value", value))
if fmt.Sprint(expectValue) == fmt.Sprint(value) {
break
}
}
}(deviceId, pointName, expectValue)
}

0 comments on commit 558e05f

Please sign in to comment.