From 8ef36e51bdc8edcbae7f903bfdb94ec0b0958d38 Mon Sep 17 00:00:00 2001 From: jason Date: Fri, 16 Aug 2024 06:52:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0GPIO=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/protocol_gpio.md | 80 +++++++++++++++++++++++++++++++++++++++++++ rpc/gpio.go | 29 ++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/docs/protocol_gpio.md b/docs/protocol_gpio.md index e69de29..e5b57ed 100644 --- a/docs/protocol_gpio.md +++ b/docs/protocol_gpio.md @@ -0,0 +1,80 @@ +# IoT通讯协议 之 GPIO + +本节规定了GPIO的交互内容 + +## 1、查询 + +```json5 +{ + "module": "gpio", + "command": "list", +} +``` + + +查询反馈 + +```json5 +{ + "result": "ok/fail", //结果 + "reason": "密码错误", //错误原因 + "data": [ + { + "path": "/dev/gpio0", + "name": "开关1", + "type": "io", //io, adc + "value": 1, + "writable": true, + }, + ] +} +``` + + +## 2、设置GPIO + +```json5 +{ + "module": "gpio", + "command": "write", + "data": { + "path": "/dev/gpio0", + "value": 1 + } +} +``` + + +## 3、读GPIO +```json5 +{ + "module": "gpio", + "command": "read", + "data": { + "path": "/dev/gpio0", + } +} +``` + +响应 +```json5 +{ + "path": "/dev/gpio0", + "value": 1, +} +``` + +## 4、GPIO数据上报 + +```json5 +{ + "module": "gpio", + "command": "status", + "data": [ + { + "path": "/dev/gpio0", + "value": 1 + }, + ] +} +``` diff --git a/rpc/gpio.go b/rpc/gpio.go index 9ab1e3e..94fbaa3 100644 --- a/rpc/gpio.go +++ b/rpc/gpio.go @@ -1 +1,30 @@ package rpc + +type GpioPath struct { + Path string `json:"path"` +} + +type GpioItem struct { + Name string `json:"name"` + Path string `json:"path"` + Type string `json:"type"` + Value int64 `json:"value"` + Writable bool `json:"writable"` +} + +type GpioValue struct { + Path string `json:"path"` + Value int64 `json:"value"` +} + +type GpioSearchRequest GpioPath + +type GpioSearchResponse []GpioItem + +type GpioReadRequest GpioPath + +type GpioReadResponse GpioValue + +type GpioWriteRequest GpioValue + +type GpioWriteResponse struct{}