fix: execute command dead lock
This commit is contained in:
parent
b0bfd95ed9
commit
e1f60366c8
@ -3,7 +3,7 @@ package device
|
|||||||
// FingerPoseCommand 手指姿态指令
|
// FingerPoseCommand 手指姿态指令
|
||||||
type FingerPoseCommand struct{ poseData []byte }
|
type FingerPoseCommand struct{ poseData []byte }
|
||||||
|
|
||||||
func NewFingerPoseCommand(fingerID string, poseData []byte) *FingerPoseCommand {
|
func NewFingerPoseCommand(poseData []byte) *FingerPoseCommand {
|
||||||
return &FingerPoseCommand{poseData: poseData}
|
return &FingerPoseCommand{poseData: poseData}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ func (h *L10Hand) SetFingerPose(pose []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 创建指令
|
// 创建指令
|
||||||
cmd := device.NewFingerPoseCommand("all", perturbedPose)
|
cmd := device.NewFingerPoseCommand(perturbedPose)
|
||||||
|
|
||||||
// 执行指令
|
// 执行指令
|
||||||
err := h.ExecuteCommand(cmd)
|
err := h.ExecuteCommand(cmd)
|
||||||
@ -197,11 +197,9 @@ func (h *L10Hand) ResetPose() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// commandToRawMessage 将通用指令转换为 L10 特定的 CAN 消息
|
// commandToRawMessageUnsafe 将通用指令转换为 L10 特定的 CAN 消息(不加锁版本)
|
||||||
func (h *L10Hand) commandToRawMessage(cmd device.Command) (communication.RawMessage, error) {
|
// 注意:此方法不是线程安全的,只应在已获取适当锁的情况下调用
|
||||||
h.mutex.RLock()
|
func (h *L10Hand) commandToRawMessageUnsafe(cmd device.Command) (communication.RawMessage, error) {
|
||||||
defer h.mutex.RUnlock()
|
|
||||||
|
|
||||||
var data []byte
|
var data []byte
|
||||||
canID := uint32(h.handType)
|
canID := uint32(h.handType)
|
||||||
|
|
||||||
@ -238,8 +236,8 @@ func (h *L10Hand) ExecuteCommand(cmd device.Command) error {
|
|||||||
return fmt.Errorf("设备 %s 未连接或未激活", h.id)
|
return fmt.Errorf("设备 %s 未连接或未激活", h.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转换指令为 CAN 消息
|
// 转换指令为 CAN 消息(使用不加锁版本,因为已经在写锁保护下)
|
||||||
rawMsg, err := h.commandToRawMessage(cmd)
|
rawMsg, err := h.commandToRawMessageUnsafe(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.status.ErrorCount++
|
h.status.ErrorCount++
|
||||||
h.status.LastError = err.Error()
|
h.status.LastError = err.Error()
|
||||||
@ -259,13 +257,10 @@ func (h *L10Hand) ExecuteCommand(cmd device.Command) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.status.LastUpdate = time.Now()
|
h.status.LastUpdate = time.Now()
|
||||||
// 成功的日志记录移到 SetFingerPose 和 SetPalmPose 中,因为那里有更详细的信息
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- 其他 L10Hand 方法 (initializeComponents, GetID, GetModel, ReadSensorData, etc.) 保持不变 ---
|
|
||||||
// --- 确保它们存在且与您上传的版本一致 ---
|
|
||||||
|
|
||||||
func (h *L10Hand) initializeComponents(_ map[string]any) error {
|
func (h *L10Hand) initializeComponents(_ map[string]any) error {
|
||||||
// 初始化传感器组件
|
// 初始化传感器组件
|
||||||
sensors := []device.Component{
|
sensors := []device.Component{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user