unitree_webrtc_connect 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- unitree_webrtc_connect-2.0.0/MANIFEST.in +12 -0
- unitree_webrtc_connect-2.0.0/PKG-INFO +111 -0
- unitree_webrtc_connect-2.0.0/README.md +84 -0
- unitree_webrtc_connect-2.0.0/images/plot_lidar_1.png +0 -0
- unitree_webrtc_connect-2.0.0/images/plot_lidar_2.png +0 -0
- unitree_webrtc_connect-2.0.0/images/screenshot_1.png +0 -0
- unitree_webrtc_connect-2.0.0/pyproject.toml +51 -0
- unitree_webrtc_connect-2.0.0/setup.cfg +4 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/__init__.py +41 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/constants.py +203 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/encryption.py +131 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/lidar/libvoxel.wasm +0 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/lidar/lidar_decoder_libvoxel.py +161 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/lidar/lidar_decoder_native.py +61 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/lidar/lidar_decoder_unified.py +38 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/msgs/error_handler.py +92 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/msgs/future_resolver.py +120 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/msgs/heartbeat.py +47 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/msgs/pub_sub.py +142 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/msgs/rtc_inner_req.py +217 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/msgs/validation.py +64 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/multicast_scanner.py +70 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/unitree_auth.py +286 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/util.py +104 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/webrtc_audio.py +41 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/webrtc_audiohub.py +267 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/webrtc_datachannel.py +198 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/webrtc_driver.py +227 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect/webrtc_video.py +34 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect.egg-info/PKG-INFO +111 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect.egg-info/SOURCES.txt +32 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect.egg-info/dependency_links.txt +1 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect.egg-info/requires.txt +22 -0
- unitree_webrtc_connect-2.0.0/unitree_webrtc_connect.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Include top-level docs
|
|
2
|
+
include README.md
|
|
3
|
+
recursive-include images *.png
|
|
4
|
+
|
|
5
|
+
# Include package data explicitly (belt-and-suspenders)
|
|
6
|
+
recursive-include unitree_webrtc_connect/lidar *.wasm
|
|
7
|
+
|
|
8
|
+
# Exclude non-package stuff from sdist
|
|
9
|
+
prune tests
|
|
10
|
+
prune examples
|
|
11
|
+
prune docs
|
|
12
|
+
global-exclude __pycache__ *.py[cod] *.so *.dylib *.egg-info
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: unitree_webrtc_connect
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Connect to the Unitree Go2 and G1 with WebRTC
|
|
5
|
+
Author-email: legion1581 <legion1581@gmail.com>
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: aiortc>=1.9.0
|
|
9
|
+
Requires-Dist: pycryptodome
|
|
10
|
+
Requires-Dist: requests
|
|
11
|
+
Requires-Dist: wasmtime
|
|
12
|
+
Requires-Dist: flask-socketio
|
|
13
|
+
Requires-Dist: lz4
|
|
14
|
+
Requires-Dist: numpy
|
|
15
|
+
Requires-Dist: packaging
|
|
16
|
+
Requires-Dist: sounddevice
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: ruff>=0.8.1; extra == "dev"
|
|
19
|
+
Requires-Dist: mypy>=1.13.0; extra == "dev"
|
|
20
|
+
Requires-Dist: types-requests>=2.32; extra == "dev"
|
|
21
|
+
Provides-Extra: audio
|
|
22
|
+
Requires-Dist: sounddevice; extra == "audio"
|
|
23
|
+
Requires-Dist: pyaudio; extra == "audio"
|
|
24
|
+
Requires-Dist: pydub; extra == "audio"
|
|
25
|
+
Provides-Extra: video
|
|
26
|
+
Requires-Dist: opencv-python-headless; extra == "video"
|
|
27
|
+
|
|
28
|
+
# Unitree Go2 and G1 WebRTC Driver
|
|
29
|
+
|
|
30
|
+
This repository contains a Python implementation of the WebRTC driver to connect to the Unitree Go2 and G1 Robots. WebRTC is used by the Unitree Go/Unitree Explore APP and provides high-level control through it. Therefore, no jailbreak or firmware manipulation is required. It works out of the box for Go2 AIR/PRO/EDU models and G1 AIR/EDU.
|
|
31
|
+
|
|
32
|
+

|
|
33
|
+
|
|
34
|
+
## Currently Supported Firmware Versions
|
|
35
|
+
|
|
36
|
+
**Go2:**
|
|
37
|
+
- **1.1.x series**: 1.1.1 – 1.1.8 *(latest available)*
|
|
38
|
+
- **1.0.x series**: 1.0.19 – 1.0.25
|
|
39
|
+
|
|
40
|
+
**G1:**
|
|
41
|
+
- **1.4.0** *(latest available)*
|
|
42
|
+
|
|
43
|
+
## Audio and Video Support (Go2 only)
|
|
44
|
+
|
|
45
|
+
There are video (recvonly) and audio (sendrecv) channels in WebRTC that you can connect to. Check out the examples in the `/example` folder.
|
|
46
|
+
|
|
47
|
+
## Lidar support (Go2 only)
|
|
48
|
+
|
|
49
|
+
There is a lidar decoder built in, so you can handle decoded PoinClouds directly. Check out the examples in the `/example` folder.
|
|
50
|
+
|
|
51
|
+
## Connection Methods
|
|
52
|
+
|
|
53
|
+
The driver supports three types of connection methods:
|
|
54
|
+
|
|
55
|
+
1. **AP Mode**: Go2/G1 is in AP mode, and the WebRTC client is connected directly to it:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
UnitreeWebRTCConnection(WebRTCConnectionMethod.LocalAP)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
2. **STA-L Mode**: Go2/G1 and the WebRTC client are on the same local network. An IP or Serial number is required:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
UnitreeWebRTCConnection(WebRTCConnectionMethod.LocalSTA, ip="192.168.8.181")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
If the IP is unknown, you can specify only the serial number, and the driver will try to find the IP using the special Multicast discovery feature available on Go2:
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
UnitreeWebRTCConnection(WebRTCConnectionMethod.LocalSTA, serialNumber="B42D2000XXXXXXXX")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
3. **STA-T mode**: Remote connection through remote Unitrees TURN server. Could control your Go2/G1 even being on the diffrent network. Requires username and pass from Unitree account
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
UnitreeWebRTCConnection(WebRTCConnectionMethod.Remote, serialNumber="B42D2000XXXXXXXX", username="email@gmail.com", password="pass")
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Multicast scanner (Go2 only)
|
|
81
|
+
The driver has a built-in Multicast scanner to find the Unitree Go2 on the local network and connect using only the serial number.
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
## Installation
|
|
85
|
+
|
|
86
|
+
```sh
|
|
87
|
+
cd ~
|
|
88
|
+
sudo apt update
|
|
89
|
+
sudo apt install python3-pip
|
|
90
|
+
sudo apt install portaudio19-dev
|
|
91
|
+
pip install --upgrade setuptools pip
|
|
92
|
+
git clone https://github.com/legion1581/go2_webrtc_connect.git
|
|
93
|
+
cd go2_webrtc_connect
|
|
94
|
+
pip install -e .
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Usage
|
|
98
|
+
Example programs are located in the /example directory.
|
|
99
|
+
|
|
100
|
+
### Thanks
|
|
101
|
+
|
|
102
|
+
A big thank you to TheRoboVerse community! Visit us at [TheRoboVerse](https://theroboverse.com) for more information and support.
|
|
103
|
+
|
|
104
|
+
Special thanks to the [tfoldi WebRTC project](https://github.com/tfoldi/go2-webrtc) and [abizovnuralem](https://github.com/abizovnuralem) for adding LiDAR support, [MrRobotow](https://github.com/MrRobotoW) for providing a plot LiDAR example. Special thanks to [Nico](https://github.com/oulianov) for the aiortc monkey patch.
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
### Support
|
|
108
|
+
|
|
109
|
+
If you like this project, please consider buying me a coffee:
|
|
110
|
+
|
|
111
|
+
<a href="https://www.buymeacoffee.com/legion1581" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Unitree Go2 and G1 WebRTC Driver
|
|
2
|
+
|
|
3
|
+
This repository contains a Python implementation of the WebRTC driver to connect to the Unitree Go2 and G1 Robots. WebRTC is used by the Unitree Go/Unitree Explore APP and provides high-level control through it. Therefore, no jailbreak or firmware manipulation is required. It works out of the box for Go2 AIR/PRO/EDU models and G1 AIR/EDU.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## Currently Supported Firmware Versions
|
|
8
|
+
|
|
9
|
+
**Go2:**
|
|
10
|
+
- **1.1.x series**: 1.1.1 – 1.1.8 *(latest available)*
|
|
11
|
+
- **1.0.x series**: 1.0.19 – 1.0.25
|
|
12
|
+
|
|
13
|
+
**G1:**
|
|
14
|
+
- **1.4.0** *(latest available)*
|
|
15
|
+
|
|
16
|
+
## Audio and Video Support (Go2 only)
|
|
17
|
+
|
|
18
|
+
There are video (recvonly) and audio (sendrecv) channels in WebRTC that you can connect to. Check out the examples in the `/example` folder.
|
|
19
|
+
|
|
20
|
+
## Lidar support (Go2 only)
|
|
21
|
+
|
|
22
|
+
There is a lidar decoder built in, so you can handle decoded PoinClouds directly. Check out the examples in the `/example` folder.
|
|
23
|
+
|
|
24
|
+
## Connection Methods
|
|
25
|
+
|
|
26
|
+
The driver supports three types of connection methods:
|
|
27
|
+
|
|
28
|
+
1. **AP Mode**: Go2/G1 is in AP mode, and the WebRTC client is connected directly to it:
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
UnitreeWebRTCConnection(WebRTCConnectionMethod.LocalAP)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
2. **STA-L Mode**: Go2/G1 and the WebRTC client are on the same local network. An IP or Serial number is required:
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
UnitreeWebRTCConnection(WebRTCConnectionMethod.LocalSTA, ip="192.168.8.181")
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
If the IP is unknown, you can specify only the serial number, and the driver will try to find the IP using the special Multicast discovery feature available on Go2:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
UnitreeWebRTCConnection(WebRTCConnectionMethod.LocalSTA, serialNumber="B42D2000XXXXXXXX")
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
3. **STA-T mode**: Remote connection through remote Unitrees TURN server. Could control your Go2/G1 even being on the diffrent network. Requires username and pass from Unitree account
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
UnitreeWebRTCConnection(WebRTCConnectionMethod.Remote, serialNumber="B42D2000XXXXXXXX", username="email@gmail.com", password="pass")
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Multicast scanner (Go2 only)
|
|
54
|
+
The driver has a built-in Multicast scanner to find the Unitree Go2 on the local network and connect using only the serial number.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## Installation
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
cd ~
|
|
61
|
+
sudo apt update
|
|
62
|
+
sudo apt install python3-pip
|
|
63
|
+
sudo apt install portaudio19-dev
|
|
64
|
+
pip install --upgrade setuptools pip
|
|
65
|
+
git clone https://github.com/legion1581/go2_webrtc_connect.git
|
|
66
|
+
cd go2_webrtc_connect
|
|
67
|
+
pip install -e .
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
Example programs are located in the /example directory.
|
|
72
|
+
|
|
73
|
+
### Thanks
|
|
74
|
+
|
|
75
|
+
A big thank you to TheRoboVerse community! Visit us at [TheRoboVerse](https://theroboverse.com) for more information and support.
|
|
76
|
+
|
|
77
|
+
Special thanks to the [tfoldi WebRTC project](https://github.com/tfoldi/go2-webrtc) and [abizovnuralem](https://github.com/abizovnuralem) for adding LiDAR support, [MrRobotow](https://github.com/MrRobotoW) for providing a plot LiDAR example. Special thanks to [Nico](https://github.com/oulianov) for the aiortc monkey patch.
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
### Support
|
|
81
|
+
|
|
82
|
+
If you like this project, please consider buying me a coffee:
|
|
83
|
+
|
|
84
|
+
<a href="https://www.buymeacoffee.com/legion1581" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "unitree_webrtc_connect"
|
|
3
|
+
version = "2.0.0"
|
|
4
|
+
description = "Connect to the Unitree Go2 and G1 with WebRTC"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.8"
|
|
7
|
+
authors = [
|
|
8
|
+
{ name = "legion1581", email = "legion1581@gmail.com" }
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
dependencies = [
|
|
12
|
+
"aiortc>=1.9.0",
|
|
13
|
+
"pycryptodome",
|
|
14
|
+
"requests",
|
|
15
|
+
"wasmtime",
|
|
16
|
+
"flask-socketio",
|
|
17
|
+
"lz4",
|
|
18
|
+
"numpy",
|
|
19
|
+
"packaging",
|
|
20
|
+
"sounddevice"
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.optional-dependencies]
|
|
24
|
+
dev = ["ruff>=0.8.1", "mypy>=1.13.0", "types-requests>=2.32"]
|
|
25
|
+
audio = ["sounddevice", "pyaudio", "pydub"]
|
|
26
|
+
video = ["opencv-python-headless"]
|
|
27
|
+
|
|
28
|
+
[build-system]
|
|
29
|
+
requires = ["setuptools>=64", "wheel"]
|
|
30
|
+
build-backend = "setuptools.build_meta"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
[tool.setuptools.packages.find]
|
|
34
|
+
where = ["."]
|
|
35
|
+
include = ["unitree_webrtc_connect*"]
|
|
36
|
+
exclude = [
|
|
37
|
+
"tests",
|
|
38
|
+
"tests.*",
|
|
39
|
+
"docs",
|
|
40
|
+
"docs.*",
|
|
41
|
+
"examples",
|
|
42
|
+
"examples.*",
|
|
43
|
+
"__pycache__",
|
|
44
|
+
"__pycache__.*",
|
|
45
|
+
"*.egg-info",
|
|
46
|
+
"*.egg-info.*",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
[tool.setuptools]
|
|
50
|
+
# include data files as listed in MANIFEST.in
|
|
51
|
+
include-package-data = true
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Monkey-patch aioice.Connection to use a fixed username and password accross all instances.
|
|
2
|
+
|
|
3
|
+
import aioice
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Connection(aioice.Connection):
|
|
7
|
+
local_username = aioice.utils.random_string(4)
|
|
8
|
+
local_password = aioice.utils.random_string(22)
|
|
9
|
+
|
|
10
|
+
def __init__(self, *args, **kwargs):
|
|
11
|
+
super().__init__(*args, **kwargs)
|
|
12
|
+
self.local_username = Connection.local_username
|
|
13
|
+
self.local_password = Connection.local_password
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
aioice.Connection = Connection # type: ignore
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# Monkey-patch aiortc.rtcdtlstransport.X509_DIGEST_ALGORITHMS to remove extra SHA algorithms
|
|
20
|
+
# Extra SHA algorithms introduced in aiortc 1.10.0 causes Unity Go2 to use the new SCTP format, despite aiortc using the old SCTP syntax.
|
|
21
|
+
# This new format is not supported by aiortc version as of today (2025-06-02)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
import aiortc
|
|
25
|
+
from packaging.version import Version
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
if Version(aiortc.__version__) == Version("1.10.0"):
|
|
29
|
+
X509_DIGEST_ALGORITHMS = {
|
|
30
|
+
"sha-256": "SHA256",
|
|
31
|
+
}
|
|
32
|
+
aiortc.rtcdtlstransport.X509_DIGEST_ALGORITHMS = X509_DIGEST_ALGORITHMS
|
|
33
|
+
|
|
34
|
+
elif Version(aiortc.__version__) >= Version("1.11.0"):
|
|
35
|
+
# Syntax changed in aiortc 1.11.0, so we need to use the hashes module
|
|
36
|
+
from cryptography.hazmat.primitives import hashes
|
|
37
|
+
|
|
38
|
+
X509_DIGEST_ALGORITHMS = {
|
|
39
|
+
"sha-256": hashes.SHA256(), # type: ignore
|
|
40
|
+
}
|
|
41
|
+
aiortc.rtcdtlstransport.X509_DIGEST_ALGORITHMS = X509_DIGEST_ALGORITHMS
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
DATA_CHANNEL_TYPE = {
|
|
4
|
+
"VALIDATION": "validation",
|
|
5
|
+
"SUBSCRIBE": "subscribe",
|
|
6
|
+
"UNSUBSCRIBE": "unsubscribe",
|
|
7
|
+
"MSG": "msg",
|
|
8
|
+
"REQUEST": "req",
|
|
9
|
+
"RESPONSE": "res",
|
|
10
|
+
"VID": "vid",
|
|
11
|
+
"AUD": "aud",
|
|
12
|
+
"ERR": "err",
|
|
13
|
+
"HEARTBEAT": "heartbeat",
|
|
14
|
+
"RTC_INNER_REQ": "rtc_inner_req",
|
|
15
|
+
"RTC_REPORT": "rtc_report",
|
|
16
|
+
"ADD_ERROR": "add_error",
|
|
17
|
+
"RM_ERROR": "rm_error",
|
|
18
|
+
"ERRORS": "errors",
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
class WebRTCConnectionMethod(Enum):
|
|
22
|
+
LocalAP = 1
|
|
23
|
+
LocalSTA = 2
|
|
24
|
+
Remote = 3
|
|
25
|
+
|
|
26
|
+
app_error_messages = {
|
|
27
|
+
"app_error_code_100_1": "DDS message timeout",
|
|
28
|
+
"app_error_code_100_10": "Battery communication error",
|
|
29
|
+
"app_error_code_100_2": "Distribution switch abnormal",
|
|
30
|
+
"app_error_code_100_20": "Abnormal mote control communication",
|
|
31
|
+
"app_error_code_100_40": "MCU communication error",
|
|
32
|
+
"app_error_code_100_80": "Motor communication error",
|
|
33
|
+
"app_error_code_200_1": "Rear left fan jammed",
|
|
34
|
+
"app_error_code_200_2": "Rear right fan jammed",
|
|
35
|
+
"app_error_code_200_4": "Front fan jammed",
|
|
36
|
+
"app_error_code_300_1": "Overcurrent",
|
|
37
|
+
"app_error_code_300_10": "Winding overheating",
|
|
38
|
+
"app_error_code_300_100": "Motor communication interruption",
|
|
39
|
+
"app_error_code_300_2": "Overvoltage",
|
|
40
|
+
"app_error_code_300_20": "Encoder abnormal",
|
|
41
|
+
"app_error_code_300_4": "Driver overheating",
|
|
42
|
+
"app_error_code_300_8": "Generatrix undervoltage",
|
|
43
|
+
"app_error_code_400_1": "Motor rotate speed abnormal",
|
|
44
|
+
"app_error_code_400_10": "Abnormal dirt index",
|
|
45
|
+
"app_error_code_400_2": "PointCloud data abnormal",
|
|
46
|
+
"app_error_code_400_4": "Serial port data abnormal",
|
|
47
|
+
"app_error_code_500_1": "UWB serial port open abnormal",
|
|
48
|
+
"app_error_code_500_2": "Robot dog information retrieval abnormal",
|
|
49
|
+
"app_error_code_600_4": "Overheating software protection",
|
|
50
|
+
"app_error_code_600_8": "Low battery software protection",
|
|
51
|
+
"app_error_source_100": "Communication firmware malfunction",
|
|
52
|
+
"app_error_source_200": "Communication firmware malfunction",
|
|
53
|
+
"app_error_source_300": "Motor malfunction",
|
|
54
|
+
"app_error_source_400": "Radar malfunction",
|
|
55
|
+
"app_error_source_500": "UWB malfunction",
|
|
56
|
+
"app_error_source_600": "Motion Control",
|
|
57
|
+
"app_error_wheel_300_100": "Motor Communication Interruption",
|
|
58
|
+
"app_error_wheel_300_40": "Calibration Data Abnormality",
|
|
59
|
+
"app_error_wheel_300_80": "Abnormal Reset"
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
RTC_TOPIC = {
|
|
63
|
+
"LOW_STATE": "rt/lf/lowstate",
|
|
64
|
+
"MULTIPLE_STATE": "rt/multiplestate",
|
|
65
|
+
"FRONT_PHOTO_REQ": "rt/api/videohub/request",
|
|
66
|
+
"ULIDAR_SWITCH": "rt/utlidar/switch",
|
|
67
|
+
"ULIDAR": "rt/utlidar/voxel_map",
|
|
68
|
+
"ULIDAR_ARRAY": "rt/utlidar/voxel_map_compressed",
|
|
69
|
+
"ULIDAR_STATE": "rt/utlidar/lidar_state",
|
|
70
|
+
"ROBOTODOM": "rt/utlidar/robot_pose",
|
|
71
|
+
"UWB_REQ": "rt/api/uwbswitch/request",
|
|
72
|
+
"UWB_STATE": "rt/uwbstate",
|
|
73
|
+
"LOW_CMD": "rt/lowcmd",
|
|
74
|
+
"WIRELESS_CONTROLLER": "rt/wirelesscontroller",
|
|
75
|
+
"SPORT_MOD": "rt/api/sport/request",
|
|
76
|
+
"SPORT_MOD_STATE": "rt/sportmodestate",
|
|
77
|
+
"LF_SPORT_MOD_STATE": "rt/lf/sportmodestate",
|
|
78
|
+
"BASH_REQ": "rt/api/bashrunner/request",
|
|
79
|
+
"SELF_TEST": "rt/selftest",
|
|
80
|
+
"GRID_MAP": "rt/mapping/grid_map",
|
|
81
|
+
"SERVICE_STATE": "rt/servicestate",
|
|
82
|
+
"GPT_FEEDBACK": "rt/gptflowfeedback",
|
|
83
|
+
"VUI": "rt/api/vui/request",
|
|
84
|
+
"OBSTACLES_AVOID": "rt/api/obstacles_avoid/request",
|
|
85
|
+
"SLAM_QT_COMMAND": "rt/qt_command",
|
|
86
|
+
"SLAM_ADD_NODE": "rt/qt_add_node",
|
|
87
|
+
"SLAM_ADD_EDGE": "rt/qt_add_edge",
|
|
88
|
+
"SLAM_QT_NOTICE": "rt/qt_notice",
|
|
89
|
+
"SLAM_PC_TO_IMAGE_LOCAL": "rt/pctoimage_local",
|
|
90
|
+
"SLAM_ODOMETRY": "rt/lio_sam_ros2/mapping/odometry",
|
|
91
|
+
"ARM_COMMAND": "rt/arm_Command",
|
|
92
|
+
"ARM_FEEDBACK": "rt/arm_Feedback",
|
|
93
|
+
"AUDIO_HUB_REQ": "rt/api/audiohub/request",
|
|
94
|
+
"AUDIO_HUB_PLAY_STATE": "rt/audiohub/player/state",
|
|
95
|
+
"GAS_SENSOR": "rt/gas_sensor",
|
|
96
|
+
"GAS_SENSOR_REQ": "rt/api/gas_sensor/request",
|
|
97
|
+
"LIDAR_MAPPING_CMD": "rt/uslam/client_command",
|
|
98
|
+
"LIDAR_MAPPING_CLOUD_POINT": "rt/uslam/frontend/cloud_world_ds",
|
|
99
|
+
"LIDAR_MAPPING_ODOM": "rt/uslam/frontend/odom",
|
|
100
|
+
"LIDAR_MAPPING_PCD_FILE": "rt/uslam/cloud_map",
|
|
101
|
+
"LIDAR_MAPPING_SERVER_LOG": "rt/uslam/server_log",
|
|
102
|
+
"LIDAR_LOCALIZATION_ODOM": "rt/uslam/localization/odom",
|
|
103
|
+
"LIDAR_NAVIGATION_GLOBAL_PATH": "rt/uslam/navigation/global_path",
|
|
104
|
+
"LIDAR_LOCALIZATION_CLOUD_POINT": "rt/uslam/localization/cloud_world",
|
|
105
|
+
"PROGRAMMING_ACTUATOR_CMD": "rt/programming_actuator/command",
|
|
106
|
+
"ASSISTANT_RECORDER": "rt/api/assistant_recorder/request",
|
|
107
|
+
"MOTION_SWITCHER": "rt/api/motion_switcher/request"
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
SPORT_CMD = {
|
|
111
|
+
"Damp": 1001,
|
|
112
|
+
"BalanceStand": 1002,
|
|
113
|
+
"StopMove": 1003,
|
|
114
|
+
"StandUp": 1004,
|
|
115
|
+
"StandDown": 1005,
|
|
116
|
+
"RecoveryStand": 1006,
|
|
117
|
+
"Euler": 1007,
|
|
118
|
+
"Move": 1008,
|
|
119
|
+
"Sit": 1009,
|
|
120
|
+
"RiseSit": 1010,
|
|
121
|
+
"SwitchGait": 1011,
|
|
122
|
+
"Trigger": 1012,
|
|
123
|
+
"BodyHeight": 1013,
|
|
124
|
+
"FootRaiseHeight": 1014,
|
|
125
|
+
"SpeedLevel": 1015,
|
|
126
|
+
"Hello": 1016,
|
|
127
|
+
"Stretch": 1017,
|
|
128
|
+
"TrajectoryFollow": 1018,
|
|
129
|
+
"ContinuousGait": 1019,
|
|
130
|
+
"Content": 1020,
|
|
131
|
+
"Wallow": 1021,
|
|
132
|
+
"Dance1": 1022,
|
|
133
|
+
"Dance2": 1023,
|
|
134
|
+
"GetBodyHeight": 1024,
|
|
135
|
+
"GetFootRaiseHeight": 1025,
|
|
136
|
+
"GetSpeedLevel": 1026,
|
|
137
|
+
"SwitchJoystick": 1027,
|
|
138
|
+
"Pose": 1028,
|
|
139
|
+
"Scrape": 1029,
|
|
140
|
+
"FrontFlip": 1030,
|
|
141
|
+
"LeftFlip": 1042,
|
|
142
|
+
"RightFlip": 1043,
|
|
143
|
+
"BackFlip": 1044,
|
|
144
|
+
"FrontJump": 1031,
|
|
145
|
+
"FrontPounce": 1032,
|
|
146
|
+
"WiggleHips": 1033,
|
|
147
|
+
"GetState": 1034,
|
|
148
|
+
"EconomicGait": 1035,
|
|
149
|
+
"LeadFollow": 1045,
|
|
150
|
+
"FingerHeart": 1036,
|
|
151
|
+
"Bound": 1304,
|
|
152
|
+
"MoonWalk": 1305,
|
|
153
|
+
"OnesidedStep": 1303,
|
|
154
|
+
"CrossStep": 1302,
|
|
155
|
+
"Handstand": 1301,
|
|
156
|
+
"StandOut": 1039,
|
|
157
|
+
"FreeWalk": 1045,
|
|
158
|
+
"Standup": 1050,
|
|
159
|
+
"CrossWalk": 1051
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
class VUI_COLOR:
|
|
163
|
+
WHITE: str = 'white'
|
|
164
|
+
RED: str = 'red'
|
|
165
|
+
YELLOW: str = 'yellow'
|
|
166
|
+
BLUE: str = 'blue'
|
|
167
|
+
GREEN: str = 'green'
|
|
168
|
+
CYAN: str = 'cyan'
|
|
169
|
+
PURPLE: str = 'purple'
|
|
170
|
+
|
|
171
|
+
# Audio API IDs
|
|
172
|
+
AUDIO_API = {
|
|
173
|
+
# Audio Player Commands
|
|
174
|
+
"GET_AUDIO_LIST": 1001,
|
|
175
|
+
"SELECT_START_PLAY": 1002,
|
|
176
|
+
"PAUSE": 1003,
|
|
177
|
+
"UNSUSPEND": 1004,
|
|
178
|
+
"SELECT_PREV_START_PLAY": 1005,
|
|
179
|
+
"SELECT_NEXT_START_PLAY": 1006,
|
|
180
|
+
"SET_PLAY_MODE": 1007,
|
|
181
|
+
"SELECT_RENAME": 1008,
|
|
182
|
+
"SELECT_DELETE": 1009,
|
|
183
|
+
"GET_PLAY_MODE": 1010,
|
|
184
|
+
|
|
185
|
+
# Audio Upload
|
|
186
|
+
"UPLOAD_AUDIO_FILE": 2001,
|
|
187
|
+
|
|
188
|
+
# Internal Corpus
|
|
189
|
+
"PLAY_START_OBSTACLE_AVOIDANCE": 3001,
|
|
190
|
+
"PLAY_EXIT_OBSTACLE_AVOIDANCE": 3002,
|
|
191
|
+
"PLAY_START_COMPANION_MODE": 3003,
|
|
192
|
+
"PLAY_EXIT_COMPANION_MODE": 3004,
|
|
193
|
+
|
|
194
|
+
# Megaphone
|
|
195
|
+
"ENTER_MEGAPHONE": 4001,
|
|
196
|
+
"EXIT_MEGAPHONE": 4002,
|
|
197
|
+
"UPLOAD_MEGAPHONE": 4003,
|
|
198
|
+
|
|
199
|
+
# Internal Long Corpus
|
|
200
|
+
"INTERNAL_LONG_CORPUS_SELECT_TO_PLAY": 5001,
|
|
201
|
+
"INTERNAL_LONG_CORPUS_PLAYBACK_COMPLETED": 5002,
|
|
202
|
+
"INTERNAL_LONG_CORPUS_STOP_PLAYING": 5003
|
|
203
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
from Crypto.Cipher import AES
|
|
2
|
+
from Crypto.PublicKey import RSA
|
|
3
|
+
from Crypto.Cipher import PKCS1_v1_5
|
|
4
|
+
import base64
|
|
5
|
+
import uuid
|
|
6
|
+
import binascii
|
|
7
|
+
|
|
8
|
+
###############
|
|
9
|
+
### AES handling
|
|
10
|
+
###############
|
|
11
|
+
|
|
12
|
+
# Function to generate a UUID and return it as a 32-character hexadecimal string
|
|
13
|
+
def _generate_uuid() -> str:
|
|
14
|
+
uuid_32 = uuid.uuid4().bytes
|
|
15
|
+
uuid_32_hex_string = binascii.hexlify(uuid_32).decode('utf-8')
|
|
16
|
+
return uuid_32_hex_string
|
|
17
|
+
|
|
18
|
+
def pad(data: str) -> bytes:
|
|
19
|
+
"""Pad data to be a multiple of 16 bytes (AES block size)."""
|
|
20
|
+
block_size = AES.block_size
|
|
21
|
+
padding = block_size - len(data) % block_size
|
|
22
|
+
padded_data = data + chr(padding) * padding
|
|
23
|
+
return padded_data.encode('utf-8')
|
|
24
|
+
|
|
25
|
+
def unpad(data: bytes) -> str:
|
|
26
|
+
"""Remove padding from data."""
|
|
27
|
+
padding = data[-1]
|
|
28
|
+
return data[:-padding].decode('utf-8')
|
|
29
|
+
|
|
30
|
+
def aes_encrypt(data: str, key: str) -> str:
|
|
31
|
+
"""Encrypt the given data using AES (ECB mode with PKCS5 padding)."""
|
|
32
|
+
# Ensure key is 32 bytes for AES-256
|
|
33
|
+
key_bytes = key.encode('utf-8')
|
|
34
|
+
|
|
35
|
+
# Pad the data to ensure it is a multiple of block size
|
|
36
|
+
padded_data = pad(data)
|
|
37
|
+
|
|
38
|
+
# Create AES cipher in ECB mode
|
|
39
|
+
cipher = AES.new(key_bytes, AES.MODE_ECB)
|
|
40
|
+
|
|
41
|
+
# Encrypt data
|
|
42
|
+
encrypted_data = cipher.encrypt(padded_data)
|
|
43
|
+
|
|
44
|
+
# Encode encrypted data to Base64
|
|
45
|
+
encoded_encrypted_data = base64.b64encode(encrypted_data).decode('utf-8')
|
|
46
|
+
|
|
47
|
+
return encoded_encrypted_data
|
|
48
|
+
|
|
49
|
+
def aes_decrypt(encrypted_data: str, key: str) -> str:
|
|
50
|
+
"""Decrypt the given data using AES (ECB mode with PKCS5 padding)."""
|
|
51
|
+
# Ensure key is 32 bytes for AES-256
|
|
52
|
+
key_bytes = key.encode('utf-8')
|
|
53
|
+
|
|
54
|
+
# Decode Base64 encrypted data
|
|
55
|
+
encrypted_data_bytes = base64.b64decode(encrypted_data)
|
|
56
|
+
|
|
57
|
+
# Create AES cipher in ECB mode
|
|
58
|
+
cipher = AES.new(key_bytes, AES.MODE_ECB)
|
|
59
|
+
|
|
60
|
+
# Decrypt data
|
|
61
|
+
decrypted_padded_data = cipher.decrypt(encrypted_data_bytes)
|
|
62
|
+
|
|
63
|
+
# Unpad the decrypted data
|
|
64
|
+
decrypted_data = unpad(decrypted_padded_data)
|
|
65
|
+
|
|
66
|
+
return decrypted_data
|
|
67
|
+
|
|
68
|
+
# Function to generate an AES key
|
|
69
|
+
def generate_aes_key() -> str:
|
|
70
|
+
return _generate_uuid()
|
|
71
|
+
|
|
72
|
+
###############
|
|
73
|
+
### RSA handling
|
|
74
|
+
###############
|
|
75
|
+
|
|
76
|
+
def rsa_load_public_key(pem_data: str) -> RSA.RsaKey:
|
|
77
|
+
"""Load an RSA public key from a PEM-formatted string."""
|
|
78
|
+
key_bytes = base64.b64decode(pem_data)
|
|
79
|
+
return RSA.import_key(key_bytes)
|
|
80
|
+
|
|
81
|
+
def rsa_encrypt(data: str, public_key: RSA.RsaKey) -> str:
|
|
82
|
+
"""Encrypt data using RSA and a given public key."""
|
|
83
|
+
cipher = PKCS1_v1_5.new(public_key)
|
|
84
|
+
|
|
85
|
+
# Maximum chunk size for encryption with RSA/ECB/PKCS1Padding is key size - 11 bytes
|
|
86
|
+
max_chunk_size = public_key.size_in_bytes() - 11
|
|
87
|
+
data_bytes = data.encode('utf-8')
|
|
88
|
+
|
|
89
|
+
encrypted_bytes = bytearray()
|
|
90
|
+
for i in range(0, len(data_bytes), max_chunk_size):
|
|
91
|
+
chunk = data_bytes[i:i + max_chunk_size]
|
|
92
|
+
encrypted_chunk = cipher.encrypt(chunk)
|
|
93
|
+
encrypted_bytes.extend(encrypted_chunk)
|
|
94
|
+
|
|
95
|
+
# Base64 encode the final encrypted data
|
|
96
|
+
encoded_encrypted_data = base64.b64encode(encrypted_bytes).decode('utf-8')
|
|
97
|
+
return encoded_encrypted_data
|
|
98
|
+
|
|
99
|
+
# Example usage
|
|
100
|
+
if __name__ == "__main__":
|
|
101
|
+
# Public key
|
|
102
|
+
public_key_pem = """
|
|
103
|
+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnOc1sgpzL4GTVp9/oQ0H
|
|
104
|
+
D7eeAO2GJUABfjX3TitgXiXN1Ktn2WLsLrtAiIuj3OrrRogx8fCT16oxnXx/Xrap
|
|
105
|
+
BRHD/ufHZ08A2IRVw6U6vKDv8TpQH22sAEtUji4/P2AaZmeOxFsYW5FshQr37KBG
|
|
106
|
+
+cBb7rJWLWEJpIXmCpnt37GGCtsACqRegkl7qQ8Q0OiJmtrYLPi00xSstZb+Wv1v
|
|
107
|
+
8B0eTY3POAUXjgl357L5dc6vS99rYFkYeUCTWHaH4d51Z/KgCRYUadboDc2cgNg/
|
|
108
|
+
z2dbO9S3HADegbIsN3fTbjDCruKfvc5ejxlFZ0Xbu6SScQbmkP8t3TPvy/DXGJAh
|
|
109
|
+
NwIDAQAB
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
# Example value of UUID or data you wish to encrypt
|
|
113
|
+
value_of = "26a663562a6f4dfbbbbf2b50c1a278cb"
|
|
114
|
+
|
|
115
|
+
# Load public key
|
|
116
|
+
public_key = rsa_load_public_key(public_key_pem)
|
|
117
|
+
|
|
118
|
+
# Encrypt the message
|
|
119
|
+
encrypted_value = rsa_encrypt(value_of, public_key)
|
|
120
|
+
print(f"Encrypted Value: {encrypted_value}")
|
|
121
|
+
|
|
122
|
+
# AES testing
|
|
123
|
+
aes_key = "26a663562a6f4dfbbbbf2b50c1a278cb" # Example 32-character UUID
|
|
124
|
+
|
|
125
|
+
# Encrypt a message with AES
|
|
126
|
+
encrypted_message = aes_encrypt("Hello, world!", aes_key)
|
|
127
|
+
print(f"Encrypted AES Message: {encrypted_message}")
|
|
128
|
+
|
|
129
|
+
# Decrypt the AES message
|
|
130
|
+
decrypted_message = aes_decrypt(encrypted_message, aes_key)
|
|
131
|
+
print(f"Decrypted AES Message: {decrypted_message}")
|
|
Binary file
|