keer_zu 发表于 2020-10-16 16:34

Edge-X 设备服务开发(转)

Edge-X 设备服务开发一,设备驱动(device driver) 核心接口protocoldriver.go
/ ProtocolDriver is a low-level device-specific interface used by
// by other components of an EdgeX Device Service to interact with
// a specific class of devices.
type ProtocolDriver interface {
    // Initialize performs protocol-specific initialization for the device
    // service. The given *AsyncValues channel can be used to push asynchronous
    // events and readings to Core Data.
    Initialize(lc logger.LoggingClient, asyncCh chan<- *AsyncValues) error

    // HandleReadCommands passes a slice of CommandRequest struct each representing
    // a ResourceOperation for a specific device resource.
    HandleReadCommands(deviceName string, protocols mapcontract.ProtocolProperties, reqs []CommandRequest) ([]*CommandValue, error)

    // HandleWriteCommands passes a slice of CommandRequest struct each representing
    // a ResourceOperation for a specific device resource.
    // Since the commands are actuation commands, params provide parameters for the individual
    // command.
    HandleWriteCommands(deviceName string, protocols mapcontract.ProtocolProperties, reqs []CommandRequest, params []*CommandValue) error

    // Stop instructs the protocol-specific DS code to shutdown gracefully, or
    // if the force parameter is 'true', immediately. The driver is responsible
    // for closing any in-use channels, including the channel used to send async
    // readings (if supported).
    Stop(force bool) error

    // AddDevice is a callback function that is invoked
    // when a new Device associated with this Device Service is added
    AddDevice(deviceName string, protocols mapcontract.ProtocolProperties, adminState contract.AdminState) error

    // UpdateDevice is a callback function that is invoked
    // when a Device associated with this Device Service is updated
    UpdateDevice(deviceName string, protocols mapcontract.ProtocolProperties, adminState contract.AdminState) error

    // RemoveDevice is a callback function that is invoked
    // when a Device associated with this Device Service is removed
    RemoveDevice(deviceName string, protocols mapcontract.ProtocolProperties) error
}

1、初始化函数:// AsyncValues : 异步通道,用来做异步事件发送
Initialize(lc logger.LoggingClient, asyncCh chan<- *AsyncValues) error
2、写函数HandleWriteCommands(deviceName string, protocols mapcontract.ProtocolProperties, reqs []CommandRequest, params []*CommandValue) error




入参:



keer_zu 发表于 2020-10-16 16:39

在另外一个工程:github.com/edgexfoundry/go-mod-core-contracts/models/device.go





3、读函数// HandleReadCommands passes a slice of CommandRequest struct each representing
    // a ResourceOperation for a specific device resource.
    HandleReadCommands(deviceName string, protocols mapcontract.ProtocolProperties, reqs []CommandRequest) ([]*CommandValue, error)

4、停止函数// Stop instructs the protocol-specific DS code to shutdown gracefully, or
    // if the force parameter is 'true', immediately. The driver is responsible
    // for closing any in-use channels, including the channel used to send async
    // readings (if supported).
    Stop(force bool) error

5、添加设备回调函数    // AddDevice is a callback function that is invoked
    // when a new Device associated with this Device Service is added
    AddDevice(deviceName string, protocols mapcontract.ProtocolProperties, adminState contract.AdminState) error

6、更新设备回调函数// UpdateDevice is a callback function that is invoked
    // when a Device associated with this Device Service is updated
    UpdateDevice(deviceName string, protocols mapcontract.ProtocolProperties, adminState contract.AdminState) error


7、移除设备回调函数// RemoveDevice is a callback function that is invoked
    // when a Device associated with this Device Service is removed
    RemoveDevice(deviceName string, protocols mapcontract.ProtocolProperties) error












页: [1]
查看完整版本: Edge-X 设备服务开发(转)