获取当前帧bytes
This commit is contained in:
parent
c6bc92c4de
commit
2a120d85f4
|
|
@ -97,6 +97,8 @@ func GetDeviceCurrentFrameV4(deviceId int, curCount int) (buf []byte, cnt int) {
|
|||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
log.Printf("设备:%d 错误: %v\n", deviceId, err)
|
||||
// 异常时释放 buf
|
||||
buf = nil
|
||||
}
|
||||
}()
|
||||
//获取读写锁
|
||||
|
|
@ -120,21 +122,32 @@ func GetDeviceCurrentFrameV4(deviceId int, curCount int) (buf []byte, cnt int) {
|
|||
return nil, frameCount
|
||||
}
|
||||
//获取当前帧
|
||||
var tempBuf []byte
|
||||
switch deviceId {
|
||||
case 1:
|
||||
if Device1CurrentFrame.Empty() {
|
||||
return nil, -1
|
||||
}
|
||||
buf = Device1CurrentFrame.ToBytes()
|
||||
tempBuf = Device1CurrentFrame.ToBytes()
|
||||
case 50:
|
||||
if Device50CurrentFrame.Empty() {
|
||||
return nil, -1
|
||||
}
|
||||
buf = Device50CurrentFrame.ToBytes()
|
||||
tempBuf = Device50CurrentFrame.ToBytes()
|
||||
case 73:
|
||||
if Device73CurrentFrame.Empty() {
|
||||
return nil, -1
|
||||
}
|
||||
tempBuf = Device73CurrentFrame.ToBytes()
|
||||
default:
|
||||
return nil, -1
|
||||
}
|
||||
// 避免直接返回大数组,可考虑复制必要的数据
|
||||
if len(tempBuf) > 0 {
|
||||
buf = make([]byte, len(tempBuf))
|
||||
copy(buf, tempBuf)
|
||||
// 释放临时变量
|
||||
tempBuf = nil
|
||||
}
|
||||
return buf, frameCount
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue