EdgexAgent/device-ble-go/pkg/dataparse/dataPublisher.go
2025-07-10 20:40:32 +08:00

28 lines
735 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package dataparse
import (
"device-ble/internal/interfaces"
"device-ble/pkg/ble"
"fmt"
)
// PublishToMessageBus 发布数据到MessageBus。
// SendToBlE 异步传输到蓝牙发送器。
func SendToBlE(controller interfaces.BLEController, data interface{}) error {
if controller != nil {
queueIface := controller.GetQueue()
if queue, ok := queueIface.(interfaces.SerialQueueInterface); ok {
if err := ble.SendJSONOverBLE(queue, data); err == nil {
return nil
} else {
return fmt.Errorf("向BLE控制器发送数据失败")
}
} else {
return fmt.Errorf("BLE控制器队列类型断言失败无法发送数据")
}
} else {
return fmt.Errorf("BLE控制器未初始化无法发送数据")
}
}