Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
添加GPIO接口
Browse files Browse the repository at this point in the history
  • Loading branch information
zgwit committed Aug 15, 2024
1 parent 21f21a3 commit 8ef36e5
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
80 changes: 80 additions & 0 deletions docs/protocol_gpio.md
Original file line number Diff line number Diff line change
@@ -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
},
]
}
```
29 changes: 29 additions & 0 deletions rpc/gpio.go
Original file line number Diff line number Diff line change
@@ -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{}

0 comments on commit 8ef36e5

Please sign in to comment.