zlbusapi 0.5.7
ZeroLab Bus API for Python
Requires Python: >=3.8

# ZLBus Python SDK

ZLBus Python SDK 是一个用于与ZLBus设备通信的Python库。它提供了丰富的API来控制和配置ZLBus设备，包括数据格式设置、设备校准、RF参数配置等功能。

## 许可证

本项目仅供内部使用。

## 功能特性

- **数据处理**: 提供校验和、CRC等数据处理函数
- **设备控制**: 支持设备参数配置，如数据格式、采样频率、上传频率等
- **校准功能**: 支持IMU静态校准、磁力计校准等
- **RF配置**: 支持RF功率、连接间隔等参数配置
- **枚举和结构体**: 提供丰富的枚举类型和数据结构定义

## 安装

将 `ZlBusApi.py` 文件和相关的DLL文件放置在您的Python项目目录中。

## 快速开始

```python
import ZlBusApi as zlapi

zlapi.example()
```


## 主要功能

### C语言结构体 -> Python版本的使用说明

#### Axis3_I16
```python
import ZlBusApi as zlapi
import ctypes

block = zlapi.Axis3_I16()

# 赋0，初始化
ctypes.memset(ctypes.addressof(block), 0, ctypes.sizeof(block))

# 赋值
block.axis.x = 100
block.axis.y = 200
block.axis.z = 300

# 打印
print(block.axis.x, block.axis.y, block.axis.z)
```

#### Axis3_Float
```python
import ZlBusApi as zlapi
import ctypes

block = zlapi.Axis3_Float()

# 赋0，初始化
ctypes.memset(ctypes.addressof(block), 0, ctypes.sizeof(block))

# 赋值
block.axis.x = 100.0
block.axis.y = 200.0
block.axis.z = 300.0

# 打印
print(block.axis.x, block.axis.y, block.axis.z)
```

#### AhrsQuaternion
```python
import ZlBusApi as zlapi
import ctypes

block = zlapi.AhrsQuaternion()

# 赋0，初始化
ctypes.memset(ctypes.addressof(block), 0, ctypes.sizeof(block))

# 赋值
block.element.w = 1.0
block.element.x = 0.0
block.element.y = 0.0
block.element.z = 0.0

# 打印
print(block.element.w, block.element.x, block.element.y, block.element.z)
```

#### AhrsEuler
```python
import ZlBusApi as zlapi
import ctypes

block = zlapi.AhrsEuler()

# 赋0，初始化
ctypes.memset(ctypes.addressof(block), 0, ctypes.sizeof(block))

# 赋值
block.angle.roll = 10.0
block.angle.pitch = 45.0
block.angle.yaw = 60.0

# 打印
print(block.angle.roll, block.angle.pitch, block.angle.yaw)
```

#### xxxIdBlock
```python
import ZlBusApi as zlapi
import ctypes

block = zlapi.xxxIdBlock()

# 赋0，初始化
ctypes.memset(ctypes.addressof(block), 0, ctypes.sizeof(block))

# 赋值
block.cmdId = 0x01
block.subCmdId = 0x02
block.rfId = 0x03
block.dotId = 0x04
block.flowId = 0x05
block.userId = 0x06

# 打印
print(hex(block.cmdId), hex(block.subCmdId), hex(block.rfId), hex(block.dotId), hex(block.flowId), hex(block.userId))
```

#### e_Upload_DataFormat
```python
import ZlBusApi as zlapi
import ctypes

# 打印
print(hex(zlapi.e_Upload_DataFormat.NEW_UPLOAD_DATA_QUATERNION | zlapi.e_Upload_DataFormat.NEW_UPLOAD_DATA_GYRO))
```

#### ul_ImuDataBlock

```python
import ZlBusApi as zlapi
import ctypes

block = zlapi.ul_ImuDataBlock()

# 赋0，初始化
ctypes.memset(ctypes.addressof(block), 0, ctypes.sizeof(block))

# 赋值
block.pkId.cmdId = 0x01
block.pkId.subCmdId = 0x02
block.pkId.rfId = 0x03
block.pkId.dotId = 0x04
block.pkId.flowId = 0x05
block.pkId.userId = 0x06

block.temperature = 25.0

block.quat.element.w = 1.0
block.quat.element.x = 0.0
block.quat.element.y = 0.0
block.quat.element.z = 0.0

block.acc.axis.x = 100.0
block.acc.axis.y = 200.0
block.acc.axis.z = 300.0

block.gyro.axis.x = 10.0
block.gyro.axis.y = 20.0
block.gyro.axis.z = 30.0
```

#### ul_DeviceStateBlock

```python
import ZlBusApi as zlapi
import ctypes

block = zlapi.ul_DeviceStateBlock()

# 赋0，初始化
ctypes.memset(ctypes.addressof(block), 0, ctypes.sizeof(block))

# 赋值
block.pkId.cmdId = 0x01
block.pkId.subCmdId = 0x02
block.pkId.rfId = 0x03
block.pkId.dotId = 0x04
block.pkId.flowId = 0x05
block.pkId.userId = 0x06

block.deviceState = 0xFF

# 打印
print(hex(block.deviceState))
```

#### ul_BatteryBlock

```python
import ZlBusApi as zlapi
import ctypes

block = zlapi.ul_BatteryBlock()

# 赋0，初始化
ctypes.memset(ctypes.addressof(block), 0, ctypes.sizeof(block))

# 赋值
block.pkId.cmdId = 0x01

block.mvOk = True
block.mv = 3300

# 打印
print(block.mv)
```


#### ul_AntValueBlock

```python
import ZlBusApi as zlapi
import ctypes

block = zlapi.ul_AntValueBlock()

# 赋0，初始化
ctypes.memset(ctypes.addressof(block), 0, ctypes.sizeof(block))

# 赋值
block.pkId.cmdId = 0x01

block.antNums = 2
block.antValue[0] = 2652
block.antValue[1] = 1458
block.antValue[2] = 0

# 打印
print(block.antNums, block.antValue[0], block.antValue[1])
```

#### ul_CtrlDataBaseBlock

```python
import ZlBusApi as zlapi
import ctypes

block = zlapi.ul_CtrlDataBaseBlock()

# 赋0，初始化
ctypes.memset(ctypes.addressof(block), 0, ctypes.sizeof(block))

# 赋值
block.pkId.cmdId = 0x01

block.error = False
block.errCode = zlapi.ERROR_CMU.ERROR_PK_NONE

# 打印
print(block.error, block.errCode)
```

#### ul_UploadDataFormatBlock （略……）
#### e_SampleHz （类型e_Upload_DataFormat，略……）
#### ul_SamplingHzBlock （略……）
#### e_UploadHz （略……）
#### ul_UploadHzBlock （略……）
#### e_FiterParam （略……）
#### ul_FilterMapBlock （略……）
#### e_Convention （略……）
#### ul_IcDirBlock （略……）

#### ul_DevieRfNameBlock
```python
import ZlBusApi as zlapi
import ctypes

block = zlapi.ul_DevieRfNameBlock()

# 赋0，初始化
ctypes.memset(ctypes.addressof(block), 0, ctypes.sizeof(block))

# 赋值
block.pkId.cmdId = 0x01

rfName = b"RfName"
ctypes.memmove(ctypes.addressof(block.name), rfName, len(rfName))

# 打印
print(bytes(block.name).split(b'\0', 1)[0].decode('utf-8', errors='ignore'))
```

#### ul_RfPowerBlock （略……）
#### e_LedColor （略……）
#### e_LedMode （略……）
#### ul_RgbDataBlock （略……）
#### e_BaudRate （略……）
#### ul_UartBaudRateBlock （略……）
#### ul_BlockSizeBlock （略……）
#### ul_DeviceMacBlock （略……）
#### ul_DeviceSnFullStrBlock （类似ul_DevieRfNameBlock, 略……）
#### ul_DeviceBoardVersionBlock （类似ul_DevieRfNameBlock, 略……）
#### ul_DeviceFirmwareVersionBlock （类似ul_DevieRfNameBlock, 略……）

---

#### hl_UploadDataFormatBlock （略……）
#### hl_DotIdBlock （略……）
#### hl_DotIdMapBlock （略……）
#### hl_BleConnIntervalBlock （略……）
#### e_AccRange （略……）
#### hl_AccRangeBlock （略……）
#### e_GyroRange （略……）
#### hl_GyroRangeBlock （略……）

#### MagEllipsoidCalParamBlock_t （略……）
#### hl_MagEllipsoidCalParamBlock （略……）
#### e_TK_FlowIdFormat （略……）
#### hl_FlowIdFormatBlock （略……）
#### hl_AhrsOffsetBlock （略……）

#### e_DataOutPort （略……）
#### hl_DataPortBlock （略……）
#### hl_DataPortMapBlock （略……）
#### hl_DeviceStateBlock （略……）
#### AntFilterParam_t （略……）
#### hl_AntFilterParamBlock （略……）
#### hl_FingerMapBlock （略……）

---

#### e_AntEn （略……）
#### e_BlockSizeType （略……）

---

#### DeviceBlock_t
```python
import ZlBusApi as zlapi
import ctypes

block = zlapi.DeviceBlock_t()

# 赋0，初始化
ctypes.memset(ctypes.addressof(block), 0, ctypes.sizeof(block))

# 赋值
block.devId = 0x01
block.connState = 0x01
block.mac[:] = (ctypes.c_uint8 * 6)(0x11, 0x22, 0x33, 0x44, 0x55, 0x66)
device_name = b"TestDevice"
ctypes.memmove(ctypes.addressof(block.name), device_name, len(device_name))

# 打印
print(bytes(block.mac).hex(' '))
print(bytes(block.name).split(b'\0', 1)[0].decode('utf-8', errors='ignore'))
```

#### DL_DongleSnFullStrBlock （略……）
#### DL_DeviceBoardVersionBlock （略……）
#### DL_DeviceFirmwareVersionBlock （略……）
#### DL_DeviceListBlock
```python
import ZlBusApi as zlapi
import ctypes

block = zlapi.DL_DeviceListBlock()

# 赋0，初始化
ctypes.memset(ctypes.addressof(block), 0, ctypes.sizeof(block))

# 赋值
block.pkId.rfId = 0x21
block.nums = 2
block.list[0].mac[:] = (ctypes.c_uint8 * 6)(0x11, 0x22, 0x33, 0x44, 0x55, 0x66)
block.list[1].mac[:] = (ctypes.c_uint8 * 6)(0x22, 0x33, 0x44, 0x55, 0x66, 0x77)
device_name1 = b"TestDevice1"
device_name2 = b"TestDevice2"
ctypes.memmove(ctypes.addressof(block.list[0].name), device_name1, len(device_name1))
ctypes.memmove(ctypes.addressof(block.list[1].name), device_name2, len(device_name2))

# 打印
print(bytes(block.list[0].mac).hex(' '))
print(bytes(block.list[0].name).split(b'\0', 1)[0].decode('utf-8', errors='ignore'))
print(bytes(block.list[1].mac).hex(' '))
print(bytes(block.list[1].name).split(b'\0', 1)[0].decode('utf-8', errors='ignore'))
```

#### DL_DeviceConnNumsBlock （略……）
#### DL_IdentifyWayBlock （略……）

#### Dongle: DL_ScanBlock
```python
import ZlBusApi as zlapi
import ctypes
#----------------------------------------------------------------------------------
# zlex.api.DL_ScanBlock
#----------------------------------------------------------------------------------
def use_api_DL_ScanBlock():
    block = zlapi.DL_ScanBlock()

    # 设置 Mac
    block.mac[:] = (ctypes.c_uint8 * 6)(0x11, 0x22, 0x33, 0x44, 0x55, 0x66)

    # 设置 name
    device_name = b"TestDevice"
    ctypes.memmove(ctypes.addressof(block.name), device_name, len(device_name))

    print(bytes(block.mac).hex(' '))
    print(bytes(block.name).split(b'\0', 1)[0].decode('utf-8', errors='ignore'))
```

#### DL_TimeStampSyncBlock （略……）

### 接口说明（略……）