一、device sdk go-設(shè)備驅(qū)動(dòng)(device driver) 核心接口

Edge-X 設(shè)備服務(wù)開(kāi)發(fā)

一,設(shè)備驅(qū)動(dòng)(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 map[string]contract.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 map[string]contract.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 map[string]contract.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 map[string]contract.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 map[string]contract.ProtocolProperties) error
}

1、初始化函數(shù):

// AsyncValues : 異步通道偎巢,用來(lái)做異步事件發(fā)送

Initialize(lc logger.LoggingClient, asyncCh chan<- *AsyncValues) error

2、寫(xiě)函數(shù)

HandleWriteCommands(deviceName string, protocols map[string]contract.ProtocolProperties, reqs []CommandRequest, params []*CommandValue) error

入?yún)ⅲ?/p>

deviceName string: 設(shè)備名

protocols map[string]contract.ProtocolProperties:設(shè)備的連接信息

reqs []CommandRequest:指令請(qǐng)求兼耀,可以是多條

params []*CommandValue:指令值压昼,可以是多個(gè)返回值,與reqs的數(shù)量通常是對(duì)應(yīng)的

在這里有一個(gè)設(shè)計(jì):在HandleWriteCommands時(shí)瘤运,reqs 與params 是分開(kāi)的窍霞,本意是分別代別請(qǐng)求的資源和參數(shù),其中的結(jié)構(gòu)體成員有重復(fù)拯坟;

在另外一個(gè)工程:github.com/edgexfoundry/go-mod-core-contracts/models/device.go

// ProtocolProperties contains the device connection information in key/value pair
type ProtocolProperties map[string]string
// CommandRequest is the struct for requesting a command to ProtocolDrivers
type CommandRequest struct {
    // DeviceResourceName is the name of Device Resource for this command
    // 例如一個(gè)設(shè)備的功能項(xiàng)(資源項(xiàng)名稱)但金,例如可以是屬性的名字
    DeviceResourceName string
    // Attributes is a key/value map to represent the attributes of the Device Resource
    // 這個(gè)看起來(lái)是非必須的,資源名可以唯一約束時(shí)郁季,Attributes的補(bǔ)充看起來(lái)非必須
    Attributes map[string]string
    // Type is the data type of the Device Resource
    Type ValueType
}
// CommandValue is the struct to represent the reading value of a Get command coming
// from ProtocolDrivers or the parameter of a Put command sending to ProtocolDrivers.
type CommandValue struct {
    // DeviceResourceName is the name of Device Resource for this command
    DeviceResourceName string
    // Origin is an int64 value which indicates the time the reading
    // contained in the CommandValue was read by the ProtocolDriver
    // instance.
    // 當(dāng)前值生成的時(shí)間
    Origin int64
    // Type is a ValueType value which indicates what type of
    // value was returned from the ProtocolDriver instance in
    // response to HandleCommand being called to handle a single
    // ResourceOperation.
    // 當(dāng)前返回值的類型冷溃,指示從后續(xù)的那個(gè)結(jié)構(gòu)體中去取值(NumericValue,stringValue梦裂,BinValue)
    Type ValueType
    // NumericValue is a byte slice with a maximum capacity of
    // 64 bytes, used to hold a numeric value returned by a
    // ProtocolDriver instance. The value can be converted to
    // its native type by referring to the the value of ResType.
    NumericValue []byte
    // stringValue is a string value returned as a value by a ProtocolDriver instance.
    stringValue string
    // BinValue is a CBOR encoded binary value with a maximum
    // capacity of 1MB, used to hold binary values returned
    // by a ProtocolDriver instance. Its decoded value is externally accessed
    // using BinaryValue() method
    BinValue []byte
}

3似枕、讀函數(shù)

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

4、停止函數(shù)

// 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年柠、添加設(shè)備回調(diào)函數(shù)

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

6凿歼、更新設(shè)備回調(diào)函數(shù)

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

7、移除設(shè)備回調(diào)函數(shù)

// RemoveDevice is a callback function that is invoked
    // when a Device associated with this Device Service is removed
    RemoveDevice(deviceName string, protocols map[string]contract.ProtocolProperties) error
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市毅往,隨后出現(xiàn)的幾起案子牵咙,更是在濱河造成了極大的恐慌派近,老刑警劉巖攀唯,帶你破解...
    沈念sama閱讀 211,290評(píng)論 6 491
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異渴丸,居然都是意外死亡侯嘀,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,107評(píng)論 2 385
  • 文/潘曉璐 我一進(jìn)店門谱轨,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)戒幔,“玉大人,你說(shuō)我怎么就攤上這事土童∈ィ” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 156,872評(píng)論 0 347
  • 文/不壞的土叔 我叫張陵献汗,是天一觀的道長(zhǎng)敢订。 經(jīng)常有香客問(wèn)我,道長(zhǎng)罢吃,這世上最難降的妖魔是什么楚午? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,415評(píng)論 1 283
  • 正文 為了忘掉前任,我火速辦了婚禮尿招,結(jié)果婚禮上矾柜,老公的妹妹穿的比我還像新娘。我一直安慰自己就谜,他們只是感情好怪蔑,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,453評(píng)論 6 385
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著丧荐,像睡著了一般缆瓣。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上篮奄,一...
    開(kāi)封第一講書(shū)人閱讀 49,784評(píng)論 1 290
  • 那天捆愁,我揣著相機(jī)與錄音,去河邊找鬼窟却。 笑死昼丑,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的夸赫。 我是一名探鬼主播菩帝,決...
    沈念sama閱讀 38,927評(píng)論 3 406
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了呼奢?” 一聲冷哼從身側(cè)響起宜雀,我...
    開(kāi)封第一講書(shū)人閱讀 37,691評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎握础,沒(méi)想到半個(gè)月后辐董,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,137評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡禀综,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,472評(píng)論 2 326
  • 正文 我和宋清朗相戀三年简烘,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片定枷。...
    茶點(diǎn)故事閱讀 38,622評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡孤澎,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出欠窒,到底是詐尸還是另有隱情覆旭,我是刑警寧澤,帶...
    沈念sama閱讀 34,289評(píng)論 4 329
  • 正文 年R本政府宣布岖妄,位于F島的核電站型将,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏衣吠。R本人自食惡果不足惜茶敏,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,887評(píng)論 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望缚俏。 院中可真熱鬧惊搏,春花似錦、人聲如沸忧换。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,741評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)亚茬。三九已至酪耳,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間刹缝,已是汗流浹背碗暗。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,977評(píng)論 1 265
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留梢夯,地道東北人言疗。 一個(gè)月前我還...
    沈念sama閱讀 46,316評(píng)論 2 360
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像颂砸,于是被迫代替她去往敵國(guó)和親噪奄。 傳聞我的和親對(duì)象是個(gè)殘疾皇子死姚,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,490評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容