From 2a26648063284b29ad201048a82f6f56159eee5f Mon Sep 17 00:00:00 2001 From: "kunming.wang" Date: Fri, 28 Apr 2023 11:46:33 +0800 Subject: [PATCH] =?UTF-8?q?=20(ujson,ethernet):=20ujson=E5=8F=8Aethe?= =?UTF-8?q?rnet=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. ujson新增示例、参数说明及返回值描述。 2. yt8512h新增speed及node查询接口。 固件版本: N/A 是否需要文案翻译: 是 --- .../ujson.md" | 63 ++++++++++++++++++- .../ethernet.CH395.md" | 6 +- .../ethernet.DM9051.md" | 6 +- .../ethernet.W5500.md" | 6 +- .../ethernet.YT8512H.md" | 47 +++++++++++++- 5 files changed, 113 insertions(+), 15 deletions(-) diff --git "a/docs/API_reference/zh/QuecPython\346\240\207\345\207\206\345\272\223/ujson.md" "b/docs/API_reference/zh/QuecPython\346\240\207\345\207\206\345\272\223/ujson.md" index 48605377..ed6eeea0 100644 --- "a/docs/API_reference/zh/QuecPython\346\240\207\345\207\206\345\272\223/ujson.md" +++ "b/docs/API_reference/zh/QuecPython\346\240\207\345\207\206\345\272\223/ujson.md" @@ -1,6 +1,33 @@ # ujson - JSON编码和解码 -`ujson`模块实现在Python数据对象和JSON数据格式之间进行转换的功能。该模块实现相应CPython模块的子集。更多信息请参阅CPython文档:[json](https://docs.python.org/3.5/library/json.html#module-json) +`ujson`模块实现在Python对象和JSON数据格式之间进行转换的功能。该模块实现相应CPython模块的子集。更多信息请参阅CPython文档:[json](https://docs.python.org/3.5/library/json.html#module-json) +**示例:** + +```python +# ujson使用。 + +import ujson +from uio import StringIO + +# 初始化空数据流io。 +io = StringIO() +# 解析字典类型数据并转换成json字符串到io。 +ujson.dump({"say": "hello"}, io) +# 获取io信息。 +io.getvalue() + +# 解析字典类型数据并返回json字符串。 +ujson.dumps({"say": "hello"}) + +# 初始化数据流io,并写入json字符串。 +io = StringIO('{"say": "hello"}') +# 加载io中json字符串,返回字典类型数据。 +ujson.load(io) + +# 加载json字符串,返回字典类型数据。 +ujson.loads('{"say": "hello"}') + +``` ## 编码json数据 @@ -12,7 +39,12 @@ ujson.dump(obj, stream) ``` -序列化`obj`数据对象转化成`JSON`字符串,并将其写入到给定的`stream`中。 +序列化`obj`对象转化成`JSON`字符串,并将其写入到给定的`stream`中。 + +**参数描述:** + +- `obj` - `Python`对象,需要转换成`JSON`字符串的数据对象。 +- `stream` - 数据流对象,转换成`JSON`字符串后写入的位置。 ### `ujson.dumps` @@ -20,7 +52,16 @@ ujson.dump(obj, stream) ujson.dumps(obj) ``` -将`obj`字典类型的数据转换成`JSON`字符串。 +将`Python`对象转换成`JSON`字符串。 + +**参数描述:** + +- `obj` - `Python`对象,需要转换成`JSON`字符串的数据对象。 + +**返回值描述:** + +返回`JSON`字符串。 + ## 解码json数据 @@ -34,6 +75,14 @@ ujson.load(stream) 解析给定的数据`stream`,将其解析为`JSON`字符串并反序列化成`Python`对象,最终将对象返回。 +**参数描述:** + +- `stream` -数据流对象,能够读取`JSON`字符串的数据流对象。 + +**返回值描述:** + +返回`Python`对象。 + ### `ujson.loads` ```python @@ -41,3 +90,11 @@ ujson.loads(str) ``` 解析`JSON`字符串`str`并返回一个`Python`对象。 + +**参数描述:** + +- `str` -`JSON`字符串。 + +**返回值描述:** + +返回`Python`对象。 \ No newline at end of file diff --git "a/docs/API_reference/zh/QuecPython\347\261\273\345\272\223/ethernet.CH395.md" "b/docs/API_reference/zh/QuecPython\347\261\273\345\272\223/ethernet.CH395.md" index a6b23548..c7993ca4 100644 --- "a/docs/API_reference/zh/QuecPython\347\261\273\345\272\223/ethernet.CH395.md" +++ "b/docs/API_reference/zh/QuecPython\347\261\273\345\272\223/ethernet.CH395.md" @@ -18,7 +18,7 @@ class ethernet.CH395(mac, ip='', subnet='', gateway='', spi_port=-1, spi_cs_pin= - `mac` - 字节流,6字节长度的 `mac` 地址。 - `ip` - 以太网卡的 `ip` 地址,若值为空字符串'',表示使用默认值`192.168.1.100`。 -- `subnet` - 以太网卡的子网掩码地址,若值为空字符串'',表示使用默认值`255.255.255.0`。 +- `subnet` - 以太网卡的子网掩码地址,若值为空字符串'',表示使用默认值`255.255.255.0`。 - `gateway` - 以太网卡的网关地址,若值为空字符串'',表示将 `ip` 地址的最后一位替换成`1`作为网关。 - `spi_port` - 连接`CH395`的[SPI端口](./machine.SPI.md),默认值为`-1`,表示使用上次配置的值,程序中默认配置为了 `SPI1` 端口。 - `spi_cs_pin` - 连接`CH395`的 `SPI` 片选[GPIO管脚](./machine.Pin.md),默认值为`-1`,表示使用上次配置的值,程序中默认配置为了 `Pin.GPIO4`。 @@ -38,14 +38,14 @@ nic.set_addr(ip, subnet, gateway) **参数描述:** - `ip` - 以太网卡的 `ip` 地址,若值为空字符串'',表示使用默认值`192.168.1.100`。 -- `subnet` - 以太网卡的子网掩码地址,若值为空字符串'',表示使用默认值`255.255.255.0`。 +- `subnet` - 以太网卡的子网掩码地址,若值为空字符串'',表示使用默认值`255.255.255.0`。 - `gateway` - 以太网卡的网关地址,若值为空字符串'',表示将 `ip` 地址的最后一位替换成`1`作为网关。 **返回值描述:** 成功返回整型值0,失败返回整型值-1。 -* 示例 +**示例:** ```python nic.set_addr('192.168.1.100', '', '') diff --git "a/docs/API_reference/zh/QuecPython\347\261\273\345\272\223/ethernet.DM9051.md" "b/docs/API_reference/zh/QuecPython\347\261\273\345\272\223/ethernet.DM9051.md" index 441708be..16a2091f 100644 --- "a/docs/API_reference/zh/QuecPython\347\261\273\345\272\223/ethernet.DM9051.md" +++ "b/docs/API_reference/zh/QuecPython\347\261\273\345\272\223/ethernet.DM9051.md" @@ -18,7 +18,7 @@ class ethernet.DM9051(mac, ip='', subnet='', gateway='', spi_port=-1,spi_cs_pin= - `mac` - 字节流,6字节长度的 `mac` 地址。 - `ip` - 以太网卡的 `ip` 地址,若值为空字符串'',表示使用默认值`192.168.1.100`。 -- `subnet` - 以太网卡的子网掩码地址,若值为空字符串'',表示使用默认值`255.255.255.0`。 +- `subnet` - 以太网卡的子网掩码地址,若值为空字符串'',表示使用默认值`255.255.255.0`。 - `gateway` - 以太网卡的网关地址,若值为空字符串'',表示将 `ip` 地址的最后一位替换成`1`作为网关。 - `spi_port` - 连接`DM9051`的[SPI端口](./machine.SPI.md),默认值为`-1`,表示使用上次配置的值,程序中默认配置为了 `SPI1` 端口。 - `spi_cs_pin` - 连接`DM9051`的 `SPI` 片选[GPIO管脚](./machine.Pin.md),默认值为`-1`,表示使用上次配置的值,程序中默认配置为了 `Pin.GPIO13`。 @@ -35,14 +35,14 @@ nic.set_addr(ip, subnet, gateway) **参数描述:** - `ip` - 以太网卡的 `ip` 地址,若值为空字符串'',表示使用默认值`192.168.1.100`。 -- `subnet` - 以太网卡的子网掩码地址,若值为空字符串'',表示使用默认值`255.255.255.0`。 +- `subnet` - 以太网卡的子网掩码地址,若值为空字符串'',表示使用默认值`255.255.255.0`。 - `gateway` - 以太网卡的网关地址,若值为空字符串'',表示将 `ip` 地址的最后一位替换成`1`作为网关。 **返回值描述:** 成功返回整型值0,失败返回整型值-1。 -* 示例 +**示例:** ```python nic.set_addr('192.168.1.100', '', '') diff --git "a/docs/API_reference/zh/QuecPython\347\261\273\345\272\223/ethernet.W5500.md" "b/docs/API_reference/zh/QuecPython\347\261\273\345\272\223/ethernet.W5500.md" index 6ccdc9ff..ae0ac125 100644 --- "a/docs/API_reference/zh/QuecPython\347\261\273\345\272\223/ethernet.W5500.md" +++ "b/docs/API_reference/zh/QuecPython\347\261\273\345\272\223/ethernet.W5500.md" @@ -19,7 +19,7 @@ class ethernet.W5500(mac, ip='', subnet='', gateway='', spi_port=-1, spi_cs_pin= - `mac` - 字节流,6字节长度的 `mac` 地址。 - `ip` - 以太网卡的 `ip` 地址,若值为空字符串'',表示使用默认值`192.168.1.100`。 -- `subnet` - 以太网卡的子网掩码地址,若值为空字符串'',表示使用默认值`255.255.255.0`。 +- `subnet` - 以太网卡的子网掩码地址,若值为空字符串'',表示使用默认值`255.255.255.0`。 - `gateway` - 以太网卡的网关地址,若值为空字符串'',表示将 `ip` 地址的最后一位替换成`1`作为网关。 - `spi_port` - 连接`W5500`的[SPI端口](./machine.SPI.md),默认值为`-1`,表示使用上次配置的值,程序中默认配置为 `SPI1` 端口。 - `spi_cs_pin` - 连接`W5500`的 `SPI` 片选[GPIO管脚](./machine.Pin.md),默认值为`-1`,表示使用上次配置的值,程序中默认配置为 `Pin.GPIO34`。 @@ -39,14 +39,14 @@ nic.set_addr(ip, subnet, gateway) **参数描述:** - `ip` - 以太网卡的 `ip` 地址,若值为空字符串'',表示使用默认值`192.168.1.100`。 -- `subnet` - 以太网卡的子网掩码地址,若值为空字符串'',表示使用默认值`255.255.255.0`。 +- `subnet` - 以太网卡的子网掩码地址,若值为空字符串'',表示使用默认值`255.255.255.0`。 - `gateway` - 以太网卡的网关地址,若值为空字符串'',表示将 `ip` 地址的最后一位替换成`1`作为网关。 **返回值描述:** 成功返回整型值0,失败返回整型值-1。 -* 示例 +**示例:** ```python nic.set_addr('192.168.1.100', '', '') diff --git "a/docs/API_reference/zh/QuecPython\347\261\273\345\272\223/ethernet.YT8512H.md" "b/docs/API_reference/zh/QuecPython\347\261\273\345\272\223/ethernet.YT8512H.md" index dcb4a53a..9a251617 100644 --- "a/docs/API_reference/zh/QuecPython\347\261\273\345\272\223/ethernet.YT8512H.md" +++ "b/docs/API_reference/zh/QuecPython\347\261\273\345\272\223/ethernet.YT8512H.md" @@ -18,7 +18,7 @@ class ethernet.YT8512H(mac, ip='', subnet='', gateway='') - `mac` - 字节流,6字节长度的 `mac` 地址。 - `ip` - 以太网卡的 `ip` 地址,若值为空字符串'',表示使用默认值`192.168.1.100`。 -- `subnet` - 以太网卡的子网掩码地址,若值为空字符串'',表示使用默认值`255.255.255.0`。 +- `subnet` - 以太网卡的子网掩码地址,若值为空字符串'',表示使用默认值`255.255.255.0`。 - `gateway` - 以太网卡的网关地址,若值为空字符串'',表示将 `ip` 地址的最后一位替换成`1`作为网关。 ## 方法 @@ -33,14 +33,14 @@ nic.set_addr(ip, subnet, gateway) **参数描述:** - `ip` - 以太网卡的 `ip` 地址,若值为空字符串'',表示使用默认值`192.168.1.100`。 -- `subnet` - 以太网卡的子网掩码地址,若值为空字符串'',表示使用默认值`255.255.255.0`。 +- `subnet` - 以太网卡的子网掩码地址,若值为空字符串'',表示使用默认值`255.255.255.0`。 - `gateway` - 以太网卡的网关地址,若值为空字符串'',表示将 `ip` 地址的最后一位替换成`1`作为网关。 **返回值描述:** 成功返回整型值0,失败返回整型值-1。 -* 示例 +**示例:** ```python nic.set_addr('192.168.1.100', '', '') @@ -173,3 +173,44 @@ nic.status() | `dev` | `bool` | 表示网卡设备是否连接正常,`True`/`False`表示有连接/未连接 | | `active`| `bool` | 表示网卡是否激活使用,`True`/`False`表示启用/禁用,与`set_up`/`set_down`对应 | | `link` | `bool` | 表示网卡网线是否连接,`True`/`False`表示已连接/未连接 | + +### `YT8512H.speed` + +```python +nic.speed() +``` + +获取网卡当前上下行速率。 + +**返回值描述:** + +返回tuble类型。 + +格式内容如下: +(tx, rx) + +| 参数 | 类型 | 说明 | +| ---- | ---- |---------- | +| `tx` | `int` | 表示网卡当前发送数据速率,单位bps | +| `rx` | `int` | 表示网卡当前接收数据速率,单位bps | + +### `YT8512H.node` + +```python +nic.node() +``` + +获取网卡当前已连接终端列表。 + +**返回值描述:** + +返回list类型。 + +格式内容如下: +[(mac, ip, time),] + +| 参数 | 类型 | 说明 | +| ---- | ---- |---------- | +| `mac` | `byte` | 终端`mac`地址 | +| `ip`| `str` | 终端`ip`地址 | +| `time`| `int` | 终端已连接时长,单位秒 | \ No newline at end of file -- Gitee