Compare commits
30 Commits
caebc6595e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
708bdc6bf0 | ||
|
|
44b02f4781 | ||
|
|
48ce7f35e1 | ||
|
|
9b80cf73d3 | ||
|
|
67a3a3bd78 | ||
|
|
e8de8f19c2 | ||
|
|
7d2076f165 | ||
|
|
10d5254a7e | ||
|
|
a67284afe5 | ||
|
|
4ac522ffc6 | ||
|
|
5456419bb3 | ||
|
|
9bcc49059e | ||
|
|
0c6199d8e4 | ||
|
|
c232332d69 | ||
|
|
cc2a2714c3 | ||
|
|
c32583e3f4 | ||
|
|
cc550ec5cc | ||
|
|
ed9264bd70 | ||
|
|
0fc1d9c439 | ||
|
|
ef98c5e89f | ||
|
|
ec4814c208 | ||
|
|
6c6661c6c0 | ||
|
|
7cd59ef596 | ||
|
|
e76956c4bc | ||
|
|
1e4d4247bf | ||
|
|
d776e24d2f | ||
|
|
c7d57d39a1 | ||
|
|
8b59808c17 | ||
|
|
aa85c7ef27 | ||
|
|
49d6ec88f0 |
110
README.md
110
README.md
@@ -64,73 +64,87 @@ pm2 startup
|
|||||||
|
|
||||||
### 4.2 使用 Nginx 反代 (推荐)
|
### 4.2 使用 Nginx 反代 (推荐)
|
||||||
|
|
||||||
#### A. 传统 Nginx 配置 (命令行)
|
#### 步骤 1: 安装 Nginx 和 Certbot
|
||||||
如果你使用原生 Nginx,请参考以下配置:
|
```bash
|
||||||
|
apt update && apt install -y nginx certbot python3-certbot-nginx
|
||||||
|
```
|
||||||
|
|
||||||
```nginx
|
#### 步骤 2: 创建 Nginx 配置文件
|
||||||
|
```bash
|
||||||
|
cat > /etc/nginx/sites-available/mixly << 'EOF'
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name 你的域名;
|
server_name 你的域名;
|
||||||
return 301 https://$host$request_uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
server {
|
# 主站点反代
|
||||||
listen 443 ssl;
|
|
||||||
server_name 你的域名;
|
|
||||||
|
|
||||||
ssl_certificate /path/to/your/cert.pem;
|
|
||||||
ssl_certificate_key /path/to/your/key.pem;
|
|
||||||
|
|
||||||
# 核心配置:处理 WebSocket 和大文件上传
|
|
||||||
location / {
|
location / {
|
||||||
proxy_pass https://127.0.0.1:7100;
|
proxy_pass https://127.0.0.1:7100;
|
||||||
proxy_http_version 1.1;
|
proxy_ssl_verify off;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection "upgrade";
|
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
client_max_body_size 100M;
|
client_max_body_size 100M;
|
||||||
proxy_read_timeout 3600s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# 处理 Socket.io 特殊路径
|
# WebSocket 反代 (关键配置)
|
||||||
location /mixly-socket/ {
|
location /mixly-socket/ {
|
||||||
proxy_pass https://127.0.0.1:7100;
|
proxy_pass https://127.0.0.1:7100/socket.io/;
|
||||||
|
proxy_ssl_verify off;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection "upgrade";
|
proxy_set_header Connection "upgrade";
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_read_timeout 86400s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
> **注意**:将 `你的域名` 替换为实际域名,如 `mixly.example.com`
|
||||||
|
|
||||||
|
#### 步骤 3: 启用配置并测试
|
||||||
|
```bash
|
||||||
|
# 创建软链接启用配置
|
||||||
|
ln -sf /etc/nginx/sites-available/mixly /etc/nginx/sites-enabled/
|
||||||
|
|
||||||
|
# 删除默认站点 (可选)
|
||||||
|
rm -f /etc/nginx/sites-enabled/default
|
||||||
|
|
||||||
|
# 测试配置语法
|
||||||
|
nginx -t
|
||||||
|
|
||||||
|
# 重启 Nginx
|
||||||
|
systemctl restart nginx
|
||||||
```
|
```
|
||||||
|
|
||||||
#### B. Nginx Proxy Manager (NPM) 配置 (可视化)
|
#### 步骤 4: 自动申请 SSL 证书 (Let's Encrypt)
|
||||||
如果你使用的是 NPM,请按以下步骤配置:
|
```bash
|
||||||
|
# 将 your-email@example.com 替换为你的邮箱
|
||||||
|
certbot --nginx -d 你的域名 --non-interactive --agree-tos -m your-email@example.com
|
||||||
|
```
|
||||||
|
|
||||||
1. **Details 选项卡**:
|
Certbot 会自动修改 Nginx 配置并启用 HTTPS (443 端口)。
|
||||||
* **Domain Names**: `你的域名`
|
|
||||||
* **Scheme**: `https`
|
#### 步骤 5: 设置证书自动续期
|
||||||
* **Forward Hostname/IP**: `127.0.0.1`
|
```bash
|
||||||
* **Forward Port**: `7100`
|
# 测试自动续期
|
||||||
* **Websockets Support**: **必须勾选 (ON)**
|
certbot renew --dry-run
|
||||||
2. **Custom Locations 选项卡**:
|
|
||||||
* 点击 **Add Location**:
|
# 证书默认每 90 天过期,certbot 会自动配置定时任务续期
|
||||||
* **Define Location**: `/mixly-socket/`
|
```
|
||||||
* **Forward Scheme**: `https`
|
|
||||||
* **Forward Hostname/IP**: `127.0.0.1`
|
#### Nginx 常用管理命令
|
||||||
* **Forward Port**: `7100`
|
```bash
|
||||||
* 点击内置的齿轮图标或进入 **Advanced**,确保有以下配置(通常勾选 Websockets Support 后 NPM 会自动处理,但建议检查):
|
# 查看状态
|
||||||
```nginx
|
systemctl status nginx
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection "upgrade";
|
# 重载配置 (不中断服务)
|
||||||
```
|
systemctl reload nginx
|
||||||
3. **Advanced 选项卡** (可选):
|
|
||||||
* 建议添加以下配置以支持大文件上传并忽略自签名证书错误(重要!):
|
# 查看错误日志
|
||||||
```nginx
|
tail -f /var/log/nginx/error.log
|
||||||
client_max_body_size 100M;
|
```
|
||||||
# 忽略后端自签名证书错误 (必填,否则无法连接 wss)
|
|
||||||
proxy_ssl_verify off;
|
|
||||||
```
|
|
||||||
|
|
||||||
## 5. 跨平台特性说明
|
## 5. 跨平台特性说明
|
||||||
|
|
||||||
@@ -163,3 +177,7 @@ pm2 reload mixly3
|
|||||||
- **反向代理配置**:如果使用 Nginx 反代,请务必处理好的 WebSocket (Upgrade) 头,否则页面无法连接。
|
- **反向代理配置**:如果使用 Nginx 反代,请务必处理好的 WebSocket (Upgrade) 头,否则页面无法连接。
|
||||||
- **上传报错**:如果提示权限不足,请确认当前用户是否在 `dialout` 组,或尝试 `root` 运行(不推荐)。
|
- **上传报错**:如果提示权限不足,请确认当前用户是否在 `dialout` 组,或尝试 `root` 运行(不推荐)。
|
||||||
- **Python 命令**:系统必须能识别 `python3` 命令。
|
- **Python 命令**:系统必须能识别 `python3` 命令。
|
||||||
|
- **没有“添加设备”按钮**:这是因为 WebSocket 连接失败。
|
||||||
|
1. 检查 NPM 中是否勾选了 **Websockets Support**。
|
||||||
|
2. 检查 NPM Advanced 配置中是否添加了 `proxy_ssl_verify off;` (关键)。
|
||||||
|
3. 尝试重启服务端:`pm2 reload mixly3`。
|
||||||
|
|||||||
@@ -34,15 +34,15 @@
|
|||||||
"type": "command",
|
"type": "command",
|
||||||
"portSelect": "all",
|
"portSelect": "all",
|
||||||
"micropython:educore:educore": {
|
"micropython:educore:educore": {
|
||||||
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.23.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\"",
|
"command": "{esptool} --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.23.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\"",
|
||||||
"special": [
|
"special": [
|
||||||
{
|
{
|
||||||
"name": "Firmware No Ble With SSL",
|
"name": "Firmware No Ble With SSL",
|
||||||
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.23.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.23.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Firmware With Ble No SSL",
|
"name": "Firmware With Ble No SSL",
|
||||||
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib_ble-v1.23.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib_ble-v1.23.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
"{indexPath}/../micropython/build/lib",
|
"{indexPath}/../micropython/build/lib",
|
||||||
"{indexPath}/build/lib"
|
"{indexPath}/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": false,
|
"copyLib": false,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -118,16 +118,16 @@
|
|||||||
"type": "command",
|
"type": "command",
|
||||||
"portSelect": "all",
|
"portSelect": "all",
|
||||||
"micropython:esp32:mixgo": {
|
"micropython:esp32:mixgo": {
|
||||||
"command": "\"{esptool}\" --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/Mixgo_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/Mixgo_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
"micropython:esp32:mixgo_pe": {
|
"micropython:esp32:mixgo_pe": {
|
||||||
"command": "\"{esptool}\" --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/Mixgo_PE_lib-v1.25.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/Mixgo_PE_lib-v1.25.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
"micropython:esp32:generic": {
|
"micropython:esp32:generic": {
|
||||||
"command": "\"{esptool}\" --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/Generic_ESP32_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/Generic_ESP32_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
"micropython:esp32:mpython": {
|
"micropython:esp32:mpython": {
|
||||||
"command": "\"{esptool}\" --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/mPython_lib-v1.25.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/mPython_lib-v1.25.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"upload": {
|
"upload": {
|
||||||
@@ -137,7 +137,7 @@
|
|||||||
"{indexPath}/build/lib",
|
"{indexPath}/build/lib",
|
||||||
"{indexPath}/../micropython/build/lib"
|
"{indexPath}/../micropython/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": false,
|
"copyLib": false,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -62,20 +62,20 @@
|
|||||||
"type": "command",
|
"type": "command",
|
||||||
"portSelect": "all",
|
"portSelect": "all",
|
||||||
"micropython:esp32c2:mixgo_mini": {
|
"micropython:esp32c2:mixgo_mini": {
|
||||||
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\"",
|
"command": "{esptool} --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\"",
|
||||||
"special": [
|
"special": [
|
||||||
{
|
{
|
||||||
"name": "Firmware For General Application",
|
"name": "Firmware For General Application",
|
||||||
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Firmware Optimize For V2.x Board",
|
"name": "Firmware Optimize For V2.x Board",
|
||||||
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_v2_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_v2_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"micropython:esp32c2:generic_2M": {
|
"micropython:esp32c2:generic_2M": {
|
||||||
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Generic_C2_lib-v1.25.0.bin\""
|
"command": "{esptool} --chip esp32c2 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Generic_C2_lib-v1.25.0.bin\""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"upload": {
|
"upload": {
|
||||||
@@ -85,7 +85,7 @@
|
|||||||
"{indexPath}/../micropython/build/lib",
|
"{indexPath}/../micropython/build/lib",
|
||||||
"{indexPath}/build/lib"
|
"{indexPath}/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": false,
|
"copyLib": false,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -118,16 +118,16 @@
|
|||||||
"type": "command",
|
"type": "command",
|
||||||
"portSelect": "all",
|
"portSelect": "all",
|
||||||
"micropython:esp32c3:mixgo_cc": {
|
"micropython:esp32c3:mixgo_cc": {
|
||||||
"command": "\"{esptool}\" --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Mixgo_CC_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Mixgo_CC_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
"micropython:esp32c3:mixgo_me": {
|
"micropython:esp32c3:mixgo_me": {
|
||||||
"command": "\"{esptool}\" --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Mixgo_ME_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Mixgo_ME_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
"micropython:esp32c3:mixgocar_c3": {
|
"micropython:esp32c3:mixgocar_c3": {
|
||||||
"command": "\"{esptool}\" --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Mixgo_Car_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Mixgo_Car_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
"micropython:esp32c3:generic": {
|
"micropython:esp32c3:generic": {
|
||||||
"command": "\"{esptool}\" --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Generic_C3_UART_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Generic_C3_UART_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"upload": {
|
"upload": {
|
||||||
@@ -137,7 +137,7 @@
|
|||||||
"{indexPath}/build/lib",
|
"{indexPath}/build/lib",
|
||||||
"{indexPath}/../micropython/build/lib"
|
"{indexPath}/../micropython/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": false,
|
"copyLib": false,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -62,10 +62,10 @@
|
|||||||
"type": "command",
|
"type": "command",
|
||||||
"portSelect": "all",
|
"portSelect": "all",
|
||||||
"micropython:esp32c5:mixgo_sowl": {
|
"micropython:esp32c5:mixgo_sowl": {
|
||||||
"command": "\"{esptool}\" --chip esp32c5 --port {com} --baud {baudrate} --after hard_reset write_flash -e 0x2000 \"{indexPath}/build/Mixgo_Sowl_lib-v1.27.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK12.bin\" 0x400000 \"{indexPath}/../micropython/build/esp_tts_voice_data_xiaole.dat\""
|
"command": "{esptool} --chip esp32c5 --port {com} --baud {baudrate} --after hard_reset write_flash -e 0x2000 \"{indexPath}/build/Mixgo_Sowl_lib-v1.27.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK12.bin\" 0x400000 \"{indexPath}/../micropython/build/esp_tts_voice_data_xiaole.dat\""
|
||||||
},
|
},
|
||||||
"micropython:esp32c5:generic": {
|
"micropython:esp32c5:generic": {
|
||||||
"command": "\"{esptool}\" --chip esp32c5 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x2000 \"{indexPath}/build/Generic_C5_lib-v1.27.0.bin\" 0x3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c5 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x2000 \"{indexPath}/build/Generic_C5_lib-v1.27.0.bin\" 0x3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"upload": {
|
"upload": {
|
||||||
@@ -75,7 +75,7 @@
|
|||||||
"{indexPath}/build/lib",
|
"{indexPath}/build/lib",
|
||||||
"{indexPath}/../micropython/build/lib"
|
"{indexPath}/../micropython/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": false,
|
"copyLib": false,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -62,28 +62,28 @@
|
|||||||
"type": "command",
|
"type": "command",
|
||||||
"portSelect": "all",
|
"portSelect": "all",
|
||||||
"micropython:esp32s2:mixgo_ce": {
|
"micropython:esp32s2:mixgo_ce": {
|
||||||
"command": "\"{esptool}\" --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x1000 \"{indexPath}/build/Mixgo_CE_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\"",
|
"command": "{esptool} --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x1000 \"{indexPath}/build/Mixgo_CE_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\"",
|
||||||
"special": [
|
"special": [
|
||||||
{
|
{
|
||||||
"name": "Default",
|
"name": "Default",
|
||||||
"command": "\"{esptool}\" --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x1000 \"{indexPath}/build/Mixgo_CE_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x1000 \"{indexPath}/build/Mixgo_CE_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "ESP-AT-mode",
|
"name": "ESP-AT-mode",
|
||||||
"command": "\"{esptool}\" --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x0000 \"{indexPath}/build/MixGo-CE_AT-T17_R18.bin\""
|
"command": "{esptool} --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x0000 \"{indexPath}/build/MixGo-CE_AT-T17_R18.bin\""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"micropython:esp32s2:generic": {
|
"micropython:esp32s2:generic": {
|
||||||
"command": "\"{esptool}\" --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x1000 \"{indexPath}/build/Generic_S2_lib-v1.25.0.bin\"",
|
"command": "{esptool} --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x1000 \"{indexPath}/build/Generic_S2_lib-v1.25.0.bin\"",
|
||||||
"special": [
|
"special": [
|
||||||
{
|
{
|
||||||
"name": "Default",
|
"name": "Default",
|
||||||
"command": "\"{esptool}\" --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x1000 \"{indexPath}/build/Generic_S2_lib-v1.25.0.bin\""
|
"command": "{esptool} --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x1000 \"{indexPath}/build/Generic_S2_lib-v1.25.0.bin\""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "ESP-AT-mode",
|
"name": "ESP-AT-mode",
|
||||||
"command": "\"{esptool}\" --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x0000 \"{indexPath}/build/MixGo-CE_AT-T17_R18.bin\""
|
"command": "{esptool} --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x0000 \"{indexPath}/build/MixGo-CE_AT-T17_R18.bin\""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@
|
|||||||
"{indexPath}/build/lib",
|
"{indexPath}/build/lib",
|
||||||
"{indexPath}/../micropython/build/lib"
|
"{indexPath}/../micropython/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": false,
|
"copyLib": false,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -118,16 +118,16 @@
|
|||||||
"type": "command",
|
"type": "command",
|
||||||
"portSelect": "all",
|
"portSelect": "all",
|
||||||
"micropython:esp32s3:mixgo_sant": {
|
"micropython:esp32s3:mixgo_sant": {
|
||||||
"command": "\"{esptool}\" --chip esp32s3 --port {com} --baud {baudrate} --after hard_reset write_flash -e 0x0 \"{indexPath}/build/Mixgo_Sant_lib_DL-v1.25.0.bin\" 0xF00000 \"{indexPath}/../micropython/build/HZK16_GBK.bin\" 0xC00000 \"{indexPath}/../micropython/build/esp_tts_voice_data_xiaole.dat\""
|
"command": "{esptool} --chip esp32s3 --port {com} --baud {baudrate} --after hard_reset write_flash -e 0x0 \"{indexPath}/build/Mixgo_Sant_lib_DL-v1.25.0.bin\" 0xF00000 \"{indexPath}/../micropython/build/HZK16_GBK.bin\" 0xC00000 \"{indexPath}/../micropython/build/esp_tts_voice_data_xiaole.dat\""
|
||||||
},
|
},
|
||||||
"micropython:esp32s3:mixgo_nova": {
|
"micropython:esp32s3:mixgo_nova": {
|
||||||
"command": "\"{esptool}\" --chip esp32s3 --port {com} --baud {baudrate} --after hard_reset write_flash -e 0x0 \"{indexPath}/build/Mixgo_Nova_lib-v1.25.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK12.bin\" 0x400000 \"{indexPath}/../micropython/build/esp_tts_voice_data_xiaole.dat\""
|
"command": "{esptool} --chip esp32s3 --port {com} --baud {baudrate} --after hard_reset write_flash -e 0x0 \"{indexPath}/build/Mixgo_Nova_lib-v1.25.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK12.bin\" 0x400000 \"{indexPath}/../micropython/build/esp_tts_voice_data_xiaole.dat\""
|
||||||
},
|
},
|
||||||
"micropython:esp32s3:mixgo_soar": {
|
"micropython:esp32s3:mixgo_soar": {
|
||||||
"command": "\"{esptool}\" --chip esp32s3 --port {com} --baud {baudrate} --after hard_reset write_flash -e 0x0 \"{indexPath}/build/Mixgo_Soar_lib-v1.25.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK16_GBK.bin\" 0x400000 \"{indexPath}/../micropython/build/esp_tts_voice_data_xiaole.dat\""
|
"command": "{esptool} --chip esp32s3 --port {com} --baud {baudrate} --after hard_reset write_flash -e 0x0 \"{indexPath}/build/Mixgo_Soar_lib-v1.25.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK16_GBK.bin\" 0x400000 \"{indexPath}/../micropython/build/esp_tts_voice_data_xiaole.dat\""
|
||||||
},
|
},
|
||||||
"micropython:esp32s3:generic": {
|
"micropython:esp32s3:generic": {
|
||||||
"command": "\"{esptool}\" --chip esp32s3 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x0 \"{indexPath}/build/Generic_S3_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32s3 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x0 \"{indexPath}/build/Generic_S3_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"upload": {
|
"upload": {
|
||||||
@@ -137,7 +137,7 @@
|
|||||||
"{indexPath}/build/lib",
|
"{indexPath}/build/lib",
|
||||||
"{indexPath}/../micropython/build/lib"
|
"{indexPath}/../micropython/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": false,
|
"copyLib": false,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
"upload": {
|
"upload": {
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"portSelect": "all",
|
"portSelect": "all",
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": true,
|
"copyLib": true,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
"libPath": [
|
"libPath": [
|
||||||
"{indexPath}/build/lib"
|
"{indexPath}/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": true,
|
"copyLib": true,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
"libPath": [
|
"libPath": [
|
||||||
"{indexPath}/build/lib"
|
"{indexPath}/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": true,
|
"copyLib": true,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -90,13 +90,13 @@
|
|||||||
"type": "command",
|
"type": "command",
|
||||||
"portSelect": "all",
|
"portSelect": "all",
|
||||||
"micropython:esp32c3:feiyi": {
|
"micropython:esp32c3:feiyi": {
|
||||||
"command": "\"{esptool}\" --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Mixgo_FeiYi_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Mixgo_FeiYi_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
"micropython:esp32:rm_e1": {
|
"micropython:esp32:rm_e1": {
|
||||||
"command": "\"{esptool}\" --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/RM_E1_lib-v1.25.0.bin\""
|
"command": "{esptool} --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/RM_E1_lib-v1.25.0.bin\""
|
||||||
},
|
},
|
||||||
"micropython:esp32:mixbot": {
|
"micropython:esp32:mixbot": {
|
||||||
"command": "\"{esptool}\" --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/MixBot_lib-v1.25.0.bin\""
|
"command": "{esptool} --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/MixBot_lib-v1.25.0.bin\""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"upload": {
|
"upload": {
|
||||||
@@ -106,7 +106,7 @@
|
|||||||
"{indexPath}/build/lib",
|
"{indexPath}/build/lib",
|
||||||
"{indexPath}/../micropython/build/lib"
|
"{indexPath}/../micropython/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": false,
|
"copyLib": false,
|
||||||
"reset": [],
|
"reset": [],
|
||||||
|
|||||||
@@ -34,15 +34,15 @@
|
|||||||
"type": "command",
|
"type": "command",
|
||||||
"portSelect": "all",
|
"portSelect": "all",
|
||||||
"micropython:educore:educore": {
|
"micropython:educore:educore": {
|
||||||
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.23.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\"",
|
"command": "{esptool} --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.23.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\"",
|
||||||
"special": [
|
"special": [
|
||||||
{
|
{
|
||||||
"name": "Firmware No Ble With SSL",
|
"name": "Firmware No Ble With SSL",
|
||||||
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.23.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.23.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Firmware With Ble No SSL",
|
"name": "Firmware With Ble No SSL",
|
||||||
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib_ble-v1.23.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib_ble-v1.23.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
"{indexPath}/../micropython/build/lib",
|
"{indexPath}/../micropython/build/lib",
|
||||||
"{indexPath}/build/lib"
|
"{indexPath}/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": false,
|
"copyLib": false,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -118,16 +118,16 @@
|
|||||||
"type": "command",
|
"type": "command",
|
||||||
"portSelect": "all",
|
"portSelect": "all",
|
||||||
"micropython:esp32:mixgo": {
|
"micropython:esp32:mixgo": {
|
||||||
"command": "\"{esptool}\" --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/Mixgo_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/Mixgo_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
"micropython:esp32:mixgo_pe": {
|
"micropython:esp32:mixgo_pe": {
|
||||||
"command": "\"{esptool}\" --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/Mixgo_PE_lib-v1.25.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/Mixgo_PE_lib-v1.25.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
"micropython:esp32:generic": {
|
"micropython:esp32:generic": {
|
||||||
"command": "\"{esptool}\" --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/Generic_ESP32_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/Generic_ESP32_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
"micropython:esp32:mpython": {
|
"micropython:esp32:mpython": {
|
||||||
"command": "\"{esptool}\" --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/mPython_lib-v1.25.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/mPython_lib-v1.25.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"upload": {
|
"upload": {
|
||||||
@@ -137,7 +137,7 @@
|
|||||||
"{indexPath}/build/lib",
|
"{indexPath}/build/lib",
|
||||||
"{indexPath}/../micropython/build/lib"
|
"{indexPath}/../micropython/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": false,
|
"copyLib": false,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -62,20 +62,20 @@
|
|||||||
"type": "command",
|
"type": "command",
|
||||||
"portSelect": "all",
|
"portSelect": "all",
|
||||||
"micropython:esp32c2:mixgo_mini": {
|
"micropython:esp32c2:mixgo_mini": {
|
||||||
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\"",
|
"command": "{esptool} --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\"",
|
||||||
"special": [
|
"special": [
|
||||||
{
|
{
|
||||||
"name": "Firmware For General Application",
|
"name": "Firmware For General Application",
|
||||||
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Firmware Optimize For V2.x Board",
|
"name": "Firmware Optimize For V2.x Board",
|
||||||
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_v2_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c2 --port {com} --baud {baudrate} --after=no_reset_stub write_flash -e 0x0 \"{indexPath}/build/Mixgo_Mini_v2_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"micropython:esp32c2:generic_2M": {
|
"micropython:esp32c2:generic_2M": {
|
||||||
"command": "\"{esptool}\" --chip esp32c2 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Generic_C2_lib-v1.25.0.bin\""
|
"command": "{esptool} --chip esp32c2 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Generic_C2_lib-v1.25.0.bin\""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"upload": {
|
"upload": {
|
||||||
@@ -85,7 +85,7 @@
|
|||||||
"{indexPath}/../micropython/build/lib",
|
"{indexPath}/../micropython/build/lib",
|
||||||
"{indexPath}/build/lib"
|
"{indexPath}/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": false,
|
"copyLib": false,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -118,16 +118,16 @@
|
|||||||
"type": "command",
|
"type": "command",
|
||||||
"portSelect": "all",
|
"portSelect": "all",
|
||||||
"micropython:esp32c3:mixgo_cc": {
|
"micropython:esp32c3:mixgo_cc": {
|
||||||
"command": "\"{esptool}\" --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Mixgo_CC_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Mixgo_CC_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
"micropython:esp32c3:mixgo_me": {
|
"micropython:esp32c3:mixgo_me": {
|
||||||
"command": "\"{esptool}\" --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Mixgo_ME_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Mixgo_ME_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
"micropython:esp32c3:mixgocar_c3": {
|
"micropython:esp32c3:mixgocar_c3": {
|
||||||
"command": "\"{esptool}\" --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Mixgo_Car_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Mixgo_Car_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
"micropython:esp32c3:generic": {
|
"micropython:esp32c3:generic": {
|
||||||
"command": "\"{esptool}\" --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Generic_C3_UART_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Generic_C3_UART_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"upload": {
|
"upload": {
|
||||||
@@ -137,7 +137,7 @@
|
|||||||
"{indexPath}/build/lib",
|
"{indexPath}/build/lib",
|
||||||
"{indexPath}/../micropython/build/lib"
|
"{indexPath}/../micropython/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": false,
|
"copyLib": false,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -62,10 +62,10 @@
|
|||||||
"type": "command",
|
"type": "command",
|
||||||
"portSelect": "all",
|
"portSelect": "all",
|
||||||
"micropython:esp32c5:mixgo_sowl": {
|
"micropython:esp32c5:mixgo_sowl": {
|
||||||
"command": "\"{esptool}\" --chip esp32c5 --port {com} --baud {baudrate} --after hard_reset write_flash -e 0x2000 \"{indexPath}/build/Mixgo_Sowl_lib-v1.27.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK12.bin\" 0x400000 \"{indexPath}/../micropython/build/esp_tts_voice_data_xiaole.dat\""
|
"command": "{esptool} --chip esp32c5 --port {com} --baud {baudrate} --after hard_reset write_flash -e 0x2000 \"{indexPath}/build/Mixgo_Sowl_lib-v1.27.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK12.bin\" 0x400000 \"{indexPath}/../micropython/build/esp_tts_voice_data_xiaole.dat\""
|
||||||
},
|
},
|
||||||
"micropython:esp32c5:generic": {
|
"micropython:esp32c5:generic": {
|
||||||
"command": "\"{esptool}\" --chip esp32c5 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x2000 \"{indexPath}/build/Generic_C5_lib-v1.27.0.bin\" 0x3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c5 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x2000 \"{indexPath}/build/Generic_C5_lib-v1.27.0.bin\" 0x3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"upload": {
|
"upload": {
|
||||||
@@ -75,7 +75,7 @@
|
|||||||
"{indexPath}/build/lib",
|
"{indexPath}/build/lib",
|
||||||
"{indexPath}/../micropython/build/lib"
|
"{indexPath}/../micropython/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": false,
|
"copyLib": false,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -62,28 +62,28 @@
|
|||||||
"type": "command",
|
"type": "command",
|
||||||
"portSelect": "all",
|
"portSelect": "all",
|
||||||
"micropython:esp32s2:mixgo_ce": {
|
"micropython:esp32s2:mixgo_ce": {
|
||||||
"command": "\"{esptool}\" --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x1000 \"{indexPath}/build/Mixgo_CE_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\"",
|
"command": "{esptool} --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x1000 \"{indexPath}/build/Mixgo_CE_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\"",
|
||||||
"special": [
|
"special": [
|
||||||
{
|
{
|
||||||
"name": "Default",
|
"name": "Default",
|
||||||
"command": "\"{esptool}\" --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x1000 \"{indexPath}/build/Mixgo_CE_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x1000 \"{indexPath}/build/Mixgo_CE_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "ESP-AT-mode",
|
"name": "ESP-AT-mode",
|
||||||
"command": "\"{esptool}\" --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x0000 \"{indexPath}/build/MixGo-CE_AT-T17_R18.bin\""
|
"command": "{esptool} --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x0000 \"{indexPath}/build/MixGo-CE_AT-T17_R18.bin\""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"micropython:esp32s2:generic": {
|
"micropython:esp32s2:generic": {
|
||||||
"command": "\"{esptool}\" --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x1000 \"{indexPath}/build/Generic_S2_lib-v1.25.0.bin\"",
|
"command": "{esptool} --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x1000 \"{indexPath}/build/Generic_S2_lib-v1.25.0.bin\"",
|
||||||
"special": [
|
"special": [
|
||||||
{
|
{
|
||||||
"name": "Default",
|
"name": "Default",
|
||||||
"command": "\"{esptool}\" --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x1000 \"{indexPath}/build/Generic_S2_lib-v1.25.0.bin\""
|
"command": "{esptool} --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x1000 \"{indexPath}/build/Generic_S2_lib-v1.25.0.bin\""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "ESP-AT-mode",
|
"name": "ESP-AT-mode",
|
||||||
"command": "\"{esptool}\" --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x0000 \"{indexPath}/build/MixGo-CE_AT-T17_R18.bin\""
|
"command": "{esptool} --chip esp32s2 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x0000 \"{indexPath}/build/MixGo-CE_AT-T17_R18.bin\""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@
|
|||||||
"{indexPath}/build/lib",
|
"{indexPath}/build/lib",
|
||||||
"{indexPath}/../micropython/build/lib"
|
"{indexPath}/../micropython/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": false,
|
"copyLib": false,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -118,16 +118,16 @@
|
|||||||
"type": "command",
|
"type": "command",
|
||||||
"portSelect": "all",
|
"portSelect": "all",
|
||||||
"micropython:esp32s3:mixgo_sant": {
|
"micropython:esp32s3:mixgo_sant": {
|
||||||
"command": "\"{esptool}\" --chip esp32s3 --port {com} --baud {baudrate} --after hard_reset write_flash -e 0x0 \"{indexPath}/build/Mixgo_Sant_lib_DL-v1.25.0.bin\" 0xF00000 \"{indexPath}/../micropython/build/HZK16_GBK.bin\" 0xC00000 \"{indexPath}/../micropython/build/esp_tts_voice_data_xiaole.dat\""
|
"command": "{esptool} --chip esp32s3 --port {com} --baud {baudrate} --after hard_reset write_flash -e 0x0 \"{indexPath}/build/Mixgo_Sant_lib_DL-v1.25.0.bin\" 0xF00000 \"{indexPath}/../micropython/build/HZK16_GBK.bin\" 0xC00000 \"{indexPath}/../micropython/build/esp_tts_voice_data_xiaole.dat\""
|
||||||
},
|
},
|
||||||
"micropython:esp32s3:mixgo_nova": {
|
"micropython:esp32s3:mixgo_nova": {
|
||||||
"command": "\"{esptool}\" --chip esp32s3 --port {com} --baud {baudrate} --after hard_reset write_flash -e 0x0 \"{indexPath}/build/Mixgo_Nova_lib-v1.25.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK12.bin\" 0x400000 \"{indexPath}/../micropython/build/esp_tts_voice_data_xiaole.dat\""
|
"command": "{esptool} --chip esp32s3 --port {com} --baud {baudrate} --after hard_reset write_flash -e 0x0 \"{indexPath}/build/Mixgo_Nova_lib-v1.25.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK12.bin\" 0x400000 \"{indexPath}/../micropython/build/esp_tts_voice_data_xiaole.dat\""
|
||||||
},
|
},
|
||||||
"micropython:esp32s3:mixgo_soar": {
|
"micropython:esp32s3:mixgo_soar": {
|
||||||
"command": "\"{esptool}\" --chip esp32s3 --port {com} --baud {baudrate} --after hard_reset write_flash -e 0x0 \"{indexPath}/build/Mixgo_Soar_lib-v1.25.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK16_GBK.bin\" 0x400000 \"{indexPath}/../micropython/build/esp_tts_voice_data_xiaole.dat\""
|
"command": "{esptool} --chip esp32s3 --port {com} --baud {baudrate} --after hard_reset write_flash -e 0x0 \"{indexPath}/build/Mixgo_Soar_lib-v1.25.0.bin\" 0x700000 \"{indexPath}/../micropython/build/HZK16_GBK.bin\" 0x400000 \"{indexPath}/../micropython/build/esp_tts_voice_data_xiaole.dat\""
|
||||||
},
|
},
|
||||||
"micropython:esp32s3:generic": {
|
"micropython:esp32s3:generic": {
|
||||||
"command": "\"{esptool}\" --chip esp32s3 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x0 \"{indexPath}/build/Generic_S3_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32s3 --port {com} --baud {baudrate} --after=no_reset write_flash -e 0x0 \"{indexPath}/build/Generic_S3_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"upload": {
|
"upload": {
|
||||||
@@ -137,7 +137,7 @@
|
|||||||
"{indexPath}/build/lib",
|
"{indexPath}/build/lib",
|
||||||
"{indexPath}/../micropython/build/lib"
|
"{indexPath}/../micropython/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": false,
|
"copyLib": false,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
"upload": {
|
"upload": {
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"portSelect": "all",
|
"portSelect": "all",
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": true,
|
"copyLib": true,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
"libPath": [
|
"libPath": [
|
||||||
"{indexPath}/build/lib"
|
"{indexPath}/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": true,
|
"copyLib": true,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
"libPath": [
|
"libPath": [
|
||||||
"{indexPath}/build/lib"
|
"{indexPath}/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": true,
|
"copyLib": true,
|
||||||
"reset": []
|
"reset": []
|
||||||
|
|||||||
@@ -90,13 +90,13 @@
|
|||||||
"type": "command",
|
"type": "command",
|
||||||
"portSelect": "all",
|
"portSelect": "all",
|
||||||
"micropython:esp32c3:feiyi": {
|
"micropython:esp32c3:feiyi": {
|
||||||
"command": "\"{esptool}\" --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Mixgo_FeiYi_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
"command": "{esptool} --chip esp32c3 --port {com} --baud {baudrate} write_flash -e 0x0 \"{indexPath}/build/Mixgo_FeiYi_lib-v1.25.0.bin\" 0X3A0000 \"{indexPath}/../micropython/build/HZK12.bin\""
|
||||||
},
|
},
|
||||||
"micropython:esp32:rm_e1": {
|
"micropython:esp32:rm_e1": {
|
||||||
"command": "\"{esptool}\" --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/RM_E1_lib-v1.25.0.bin\""
|
"command": "{esptool} --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/RM_E1_lib-v1.25.0.bin\""
|
||||||
},
|
},
|
||||||
"micropython:esp32:mixbot": {
|
"micropython:esp32:mixbot": {
|
||||||
"command": "\"{esptool}\" --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/MixBot_lib-v1.25.0.bin\""
|
"command": "{esptool} --port {com} --baud {baudrate} write_flash -e 0x1000 \"{indexPath}/build/MixBot_lib-v1.25.0.bin\""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"upload": {
|
"upload": {
|
||||||
@@ -106,7 +106,7 @@
|
|||||||
"{indexPath}/build/lib",
|
"{indexPath}/build/lib",
|
||||||
"{indexPath}/../micropython/build/lib"
|
"{indexPath}/../micropython/build/lib"
|
||||||
],
|
],
|
||||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
"command": "{ampy} -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||||
"filePath": "{indexPath}/build/upload/main.py",
|
"filePath": "{indexPath}/build/upload/main.py",
|
||||||
"copyLib": false,
|
"copyLib": false,
|
||||||
"reset": [],
|
"reset": [],
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,76 +1,76 @@
|
|||||||
goog.loadJs('common', () => {
|
goog.loadJs('common', () => {
|
||||||
|
|
||||||
goog.require('Mixly.Debug');
|
goog.require('Mixly.Debug');
|
||||||
goog.provide('Mixly.MString');
|
goog.provide('Mixly.MString');
|
||||||
|
|
||||||
const { Debug, MString } = Mixly;
|
const { Debug, MString } = Mixly;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function 使用传入值替换字符串中{xxx}
|
* @function 使用传入值替换字符串中{xxx}
|
||||||
* @param str {string} 传入字符串
|
* @param str {string} 传入字符串
|
||||||
* @param obj {object}
|
* @param obj {object}
|
||||||
* obj = {
|
* obj = {
|
||||||
* xxx: value1,
|
* xxx: value1,
|
||||||
* xxx: value2
|
* xxx: value2
|
||||||
* }
|
* }
|
||||||
* 使用value替换{xxx}
|
* 使用value替换{xxx}
|
||||||
* @return {string} 返回处理后的字符串
|
* @return {string} 返回处理后的字符串
|
||||||
**/
|
**/
|
||||||
MString.tpl = (str, obj) => {
|
MString.tpl = (str, obj) => {
|
||||||
if (typeof str !== 'string' || !(obj instanceof Object)) {
|
if (typeof str !== 'string' || !(obj instanceof Object)) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
for (let key in obj) {
|
||||||
|
let re = new RegExp(`{${key}}`, 'gm');
|
||||||
|
str = str.replace(re, obj[key]);
|
||||||
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
for (let key in obj) {
|
|
||||||
let re = new RegExp("{[\s]*" + key + "[\s]*}", "gim");
|
|
||||||
str = str.replace(re, obj[key]);
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
MString.decode = (str) => {
|
MString.decode = (str) => {
|
||||||
try {
|
try {
|
||||||
str = unescape(str.replace(/(_E[0-9A-F]{1}_[0-9A-F]{2}_[0-9A-F]{2})+/gm, '%$1'));
|
str = unescape(str.replace(/(_E[0-9A-F]{1}_[0-9A-F]{2}_[0-9A-F]{2})+/gm, '%$1'));
|
||||||
str = unescape(str.replace(/\\(u[0-9a-fA-F]{4})/gm, '%$1'));
|
str = unescape(str.replace(/\\(u[0-9a-fA-F]{4})/gm, '%$1'));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Debug.error(error);
|
Debug.error(error);
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
MString.strToByte = (str) => {
|
|
||||||
var len, c;
|
|
||||||
len = str.length;
|
|
||||||
var bytes = [];
|
|
||||||
for (var i = 0; i < len; i++) {
|
|
||||||
c = str.charCodeAt(i);
|
|
||||||
if (c >= 0x010000 && c <= 0x10FFFF) {
|
|
||||||
bytes.push(((c >> 18) & 0x07) | 0xF0);
|
|
||||||
bytes.push(((c >> 12) & 0x3F) | 0x80);
|
|
||||||
bytes.push(((c >> 6) & 0x3F) | 0x80);
|
|
||||||
bytes.push((c & 0x3F) | 0x80);
|
|
||||||
} else if (c >= 0x000800 && c <= 0x00FFFF) {
|
|
||||||
bytes.push(((c >> 12) & 0x0F) | 0xE0);
|
|
||||||
bytes.push(((c >> 6) & 0x3F) | 0x80);
|
|
||||||
bytes.push((c & 0x3F) | 0x80);
|
|
||||||
} else if (c >= 0x000080 && c <= 0x0007FF) {
|
|
||||||
bytes.push(((c >> 6) & 0x1F) | 0xC0);
|
|
||||||
bytes.push((c & 0x3F) | 0x80);
|
|
||||||
} else {
|
|
||||||
bytes.push(c & 0xFF);
|
|
||||||
}
|
}
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
return new Int8Array(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
MString.uint8ArrayToStr = (fileData) => {
|
MString.strToByte = (str) => {
|
||||||
var dataString = "";
|
var len, c;
|
||||||
for (var i = 0; i < fileData.length; i++) {
|
len = str.length;
|
||||||
var convert = (fileData[i]).toString(16);
|
var bytes = [];
|
||||||
if (convert.length % 2 == 1)
|
for (var i = 0; i < len; i++) {
|
||||||
convert = "0" + convert;
|
c = str.charCodeAt(i);
|
||||||
dataString = dataString + " " + convert.toUpperCase();
|
if (c >= 0x010000 && c <= 0x10FFFF) {
|
||||||
|
bytes.push(((c >> 18) & 0x07) | 0xF0);
|
||||||
|
bytes.push(((c >> 12) & 0x3F) | 0x80);
|
||||||
|
bytes.push(((c >> 6) & 0x3F) | 0x80);
|
||||||
|
bytes.push((c & 0x3F) | 0x80);
|
||||||
|
} else if (c >= 0x000800 && c <= 0x00FFFF) {
|
||||||
|
bytes.push(((c >> 12) & 0x0F) | 0xE0);
|
||||||
|
bytes.push(((c >> 6) & 0x3F) | 0x80);
|
||||||
|
bytes.push((c & 0x3F) | 0x80);
|
||||||
|
} else if (c >= 0x000080 && c <= 0x0007FF) {
|
||||||
|
bytes.push(((c >> 6) & 0x1F) | 0xC0);
|
||||||
|
bytes.push((c & 0x3F) | 0x80);
|
||||||
|
} else {
|
||||||
|
bytes.push(c & 0xFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Int8Array(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
MString.uint8ArrayToStr = (fileData) => {
|
||||||
|
var dataString = "";
|
||||||
|
for (var i = 0; i < fileData.length; i++) {
|
||||||
|
var convert = (fileData[i]).toString(16);
|
||||||
|
if (convert.length % 2 == 1)
|
||||||
|
convert = "0" + convert;
|
||||||
|
dataString = dataString + " " + convert.toUpperCase();
|
||||||
|
}
|
||||||
|
return dataString;
|
||||||
}
|
}
|
||||||
return dataString;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -1,275 +1,302 @@
|
|||||||
goog.loadJs('web', () => {
|
goog.loadJs('web', () => {
|
||||||
|
|
||||||
goog.require('layui');
|
goog.require('layui');
|
||||||
goog.require('dayjs.duration');
|
goog.require('dayjs.duration');
|
||||||
goog.require('Mixly.Boards');
|
goog.require('Mixly.Boards');
|
||||||
goog.require('Mixly.Debug');
|
goog.require('Mixly.Debug');
|
||||||
goog.require('Mixly.LayerExt');
|
goog.require('Mixly.LayerExt');
|
||||||
goog.require('Mixly.Msg');
|
goog.require('Mixly.Msg');
|
||||||
goog.require('Mixly.Workspace');
|
goog.require('Mixly.Workspace');
|
||||||
goog.require('Mixly.LayerProgress');
|
goog.require('Mixly.LayerProgress');
|
||||||
goog.require('Mixly.WebSocket.Serial');
|
goog.require('Mixly.WebSocket.Serial');
|
||||||
goog.provide('Mixly.WebSocket.ArduShell');
|
goog.require('Mixly.WebCompiler.ArduShell');
|
||||||
|
goog.provide('Mixly.WebSocket.ArduShell');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
Boards,
|
Boards,
|
||||||
Debug,
|
Debug,
|
||||||
LayerExt,
|
LayerExt,
|
||||||
Msg,
|
Msg,
|
||||||
Workspace,
|
Workspace,
|
||||||
LayerProgress,
|
LayerProgress,
|
||||||
WebSocket
|
WebSocket,
|
||||||
} = Mixly;
|
WebCompiler = {}
|
||||||
|
} = Mixly;
|
||||||
|
|
||||||
const { Serial } = WebSocket;
|
// 动态获取 WebCompiler.ArduShell,用于本地上传
|
||||||
|
const getWebCompilerArduShell = () => Mixly.WebCompiler?.ArduShell;
|
||||||
|
|
||||||
const { layer } = layui;
|
const { Serial } = WebSocket;
|
||||||
|
|
||||||
|
const { layer } = layui;
|
||||||
|
|
||||||
|
|
||||||
class WebSocketArduShell {
|
class WebSocketArduShell {
|
||||||
static {
|
static {
|
||||||
this.mixlySocket = null;
|
this.mixlySocket = null;
|
||||||
this.socket = null;
|
this.socket = null;
|
||||||
this.shell = null;
|
this.shell = null;
|
||||||
|
|
||||||
this.getSocket = function () {
|
this.getSocket = function () {
|
||||||
return this.socket;
|
return this.socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getMixlySocket = function () {
|
this.getMixlySocket = function () {
|
||||||
return this.mixlySocket;
|
return this.mixlySocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.init = function (mixlySocket) {
|
this.init = function (mixlySocket) {
|
||||||
this.mixlySocket = mixlySocket;
|
this.mixlySocket = mixlySocket;
|
||||||
this.socket = mixlySocket.getSocket();
|
this.socket = mixlySocket.getSocket();
|
||||||
this.shell = new WebSocketArduShell();
|
this.shell = new WebSocketArduShell();
|
||||||
const socket = this.socket;
|
const socket = this.socket;
|
||||||
|
|
||||||
socket.on('arduino.dataEvent', (data) => {
|
// 同时初始化 WebCompiler.ArduShell,用于本地上传
|
||||||
if (data.length > 1000) {
|
const WebCompilerArduShell = getWebCompilerArduShell();
|
||||||
return;
|
if (WebCompilerArduShell && !WebCompilerArduShell.getMixlySocket()) {
|
||||||
|
WebCompilerArduShell.init(mixlySocket);
|
||||||
}
|
}
|
||||||
const { mainStatusBarTabs } = Mixly;
|
|
||||||
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
|
||||||
statusBarTerminal.addValue(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('arduino.errorEvent', (data) => {
|
socket.on('arduino.dataEvent', (data) => {
|
||||||
const { mainStatusBarTabs } = Mixly;
|
if (data.length > 1000) {
|
||||||
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
|
||||||
try {
|
|
||||||
data = unescape(data.replace(/(_E[0-9A-F]{1}_[0-9A-F]{2}_[0-9A-F]{2})+/gm, '%$1'));
|
|
||||||
data = unescape(data.replace(/\\(u[0-9a-fA-F]{4})/gm, '%$1'));
|
|
||||||
} catch (error) {
|
|
||||||
Debug.error(error);
|
|
||||||
}
|
|
||||||
statusBarTerminal.addValue(data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.initCompile = function () {
|
|
||||||
if (!this.mixlySocket.isConnected()) {
|
|
||||||
layer.msg(Msg.Lang['websocket.offline'], { time: 1000 });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { mainStatusBarTabs } = Mixly;
|
|
||||||
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
|
||||||
mainStatusBarTabs.changeTo('output');
|
|
||||||
mainStatusBarTabs.show();
|
|
||||||
const mainWorkspace = Workspace.getMain();
|
|
||||||
const editor = mainWorkspace.getEditorsManager().getActive();
|
|
||||||
const code = editor.getCode();
|
|
||||||
statusBarTerminal.setValue(`${Msg.Lang['shell.compiling']}...\n`);
|
|
||||||
this.shell.compile(code)
|
|
||||||
.then((info) => {
|
|
||||||
this.endCallback(info.code, info.time);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
Debug.error(error);
|
|
||||||
statusBarTerminal.addValue(`\n==${Msg.Lang['shell.compileFailed']}==\n`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.initUpload = function () {
|
|
||||||
if (!this.mixlySocket.isConnected()) {
|
|
||||||
layer.msg(Msg.Lang['websocket.offline'], { time: 1000 });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const port = Serial.getSelectedPortName();
|
|
||||||
if (!port) {
|
|
||||||
layer.msg(Msg.Lang['statusbar.serial.noDevice'], {
|
|
||||||
time: 1000
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { mainStatusBarTabs } = Mixly;
|
|
||||||
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
|
||||||
mainStatusBarTabs.changeTo('output');
|
|
||||||
mainStatusBarTabs.show();
|
|
||||||
statusBarTerminal.setValue(`${Msg.Lang['shell.uploading']}...\n`);
|
|
||||||
const mainWorkspace = Workspace.getMain();
|
|
||||||
const editor = mainWorkspace.getEditorsManager().getActive();
|
|
||||||
const code = editor.getCode();
|
|
||||||
const statusBarSerial = mainStatusBarTabs.getStatusBarById(port);
|
|
||||||
const closePromise = statusBarSerial ? statusBarSerial.close() : Promise.resolve();
|
|
||||||
closePromise
|
|
||||||
.then(() => {
|
|
||||||
return this.shell.upload(port, code)
|
|
||||||
})
|
|
||||||
.then((info) => {
|
|
||||||
this.endCallback(info.code, info.time);
|
|
||||||
if (info.code || !Serial.portIsLegal(port)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mainStatusBarTabs.add('serial', port);
|
const { mainStatusBarTabs } = Mixly;
|
||||||
mainStatusBarTabs.changeTo(port);
|
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
||||||
const statusBarSerial = mainStatusBarTabs.getStatusBarById(port);
|
statusBarTerminal.addValue(data);
|
||||||
statusBarSerial.open()
|
|
||||||
.then(() => {
|
|
||||||
const baudRates = code.match(/(?<=Serial.begin[\s]*\([\s]*)[0-9]*(?=[\s]*\))/g);
|
|
||||||
if (!baudRates?.length) {
|
|
||||||
return statusBarSerial.setBaudRate(9600);
|
|
||||||
} else {
|
|
||||||
return statusBarSerial.setBaudRate(baudRates[0] - 0);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(Debug.error);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
Debug.error(error);
|
|
||||||
statusBarTerminal.addValue(`\n==${Msg.Lang['shell.uploadFailed']}==\n`);
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
this.endCallback = function (code, time) {
|
socket.on('arduino.errorEvent', (data) => {
|
||||||
const { mainStatusBarTabs } = Mixly;
|
const { mainStatusBarTabs } = Mixly;
|
||||||
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
||||||
mainStatusBarTabs.changeTo('output');
|
try {
|
||||||
let message = '';
|
data = unescape(data.replace(/(_E[0-9A-F]{1}_[0-9A-F]{2}_[0-9A-F]{2})+/gm, '%$1'));
|
||||||
if (code) {
|
data = unescape(data.replace(/\\(u[0-9a-fA-F]{4})/gm, '%$1'));
|
||||||
message = (this.shell.isCompiling() ? Msg.Lang['shell.compileFailed'] : Msg.Lang['shell.uploadFailed']);
|
} catch (error) {
|
||||||
statusBarTerminal.addValue(`\n==${message}==\n`);
|
Debug.error(error);
|
||||||
} else {
|
}
|
||||||
message = (this.shell.isCompiling() ? Msg.Lang['shell.compileSucc'] : Msg.Lang['shell.uploadSucc']);
|
|
||||||
statusBarTerminal.addValue(`\n==${message}(${Msg.Lang['shell.timeCost']} ${
|
// 过滤掉无关紧要的端口错误(因为已经在本地完成上传了)
|
||||||
dayjs.duration(time).format('HH:mm:ss.SSS')
|
if (typeof data === 'string' && (
|
||||||
})==\n`);
|
data.includes('cannot open serial1') ||
|
||||||
|
data.includes('cannot open device "undefined"') ||
|
||||||
|
data.includes('No such file or directory, cannot open')
|
||||||
|
)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
statusBarTerminal.addValue(data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
layer.msg(message, { time: 1000 });
|
|
||||||
|
this.initCompile = function () {
|
||||||
|
if (!this.mixlySocket.isConnected()) {
|
||||||
|
layer.msg(Msg.Lang['websocket.offline'], { time: 1000 });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { mainStatusBarTabs } = Mixly;
|
||||||
|
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
||||||
|
mainStatusBarTabs.changeTo('output');
|
||||||
|
mainStatusBarTabs.show();
|
||||||
|
const mainWorkspace = Workspace.getMain();
|
||||||
|
const editor = mainWorkspace.getEditorsManager().getActive();
|
||||||
|
const code = editor.getCode();
|
||||||
|
statusBarTerminal.setValue(`${Msg.Lang['shell.compiling']}...\n`);
|
||||||
|
this.shell.compile(code)
|
||||||
|
.then((info) => {
|
||||||
|
this.endCallback(info.code, info.time);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
Debug.error(error);
|
||||||
|
statusBarTerminal.addValue(`\n==${Msg.Lang['shell.compileFailed']}==\n`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.initUpload = function () {
|
||||||
|
// 委托给 WebCompiler.ArduShell 处理本地上传(使用 AVRUploader 或 esptool-js)
|
||||||
|
// 服务器无法访问用户本地的串口设备,必须在浏览器端完成上传
|
||||||
|
const WebCompilerArduShell = getWebCompilerArduShell();
|
||||||
|
if (WebCompilerArduShell) {
|
||||||
|
return WebCompilerArduShell.initUpload();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.mixlySocket.isConnected()) {
|
||||||
|
layer.msg(Msg.Lang['websocket.offline'], { time: 1000 });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const port = Serial.getSelectedPortName();
|
||||||
|
if (!port) {
|
||||||
|
layer.msg(Msg.Lang['statusbar.serial.noDevice'], {
|
||||||
|
time: 1000
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { mainStatusBarTabs } = Mixly;
|
||||||
|
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
||||||
|
mainStatusBarTabs.changeTo('output');
|
||||||
|
mainStatusBarTabs.show();
|
||||||
|
statusBarTerminal.setValue(`${Msg.Lang['shell.uploading']}...\n`);
|
||||||
|
const mainWorkspace = Workspace.getMain();
|
||||||
|
const editor = mainWorkspace.getEditorsManager().getActive();
|
||||||
|
const code = editor.getCode();
|
||||||
|
const statusBarSerial = mainStatusBarTabs.getStatusBarById(port);
|
||||||
|
const closePromise = statusBarSerial ? statusBarSerial.close() : Promise.resolve();
|
||||||
|
closePromise
|
||||||
|
.then(() => {
|
||||||
|
return this.shell.upload(port, code)
|
||||||
|
})
|
||||||
|
.then((info) => {
|
||||||
|
this.endCallback(info.code, info.time);
|
||||||
|
if (info.code || !Serial.portIsLegal(port)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mainStatusBarTabs.add('serial', port);
|
||||||
|
mainStatusBarTabs.changeTo(port);
|
||||||
|
const statusBarSerial = mainStatusBarTabs.getStatusBarById(port);
|
||||||
|
statusBarSerial.open()
|
||||||
|
.then(() => {
|
||||||
|
const baudRates = code.match(/(?<=Serial.begin[\s]*\([\s]*)[0-9]*(?=[\s]*\))/g);
|
||||||
|
if (!baudRates?.length) {
|
||||||
|
return statusBarSerial.setBaudRate(9600);
|
||||||
|
} else {
|
||||||
|
return statusBarSerial.setBaudRate(baudRates[0] - 0);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(Debug.error);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
Debug.error(error);
|
||||||
|
statusBarTerminal.addValue(`\n==${Msg.Lang['shell.uploadFailed']}==\n`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.endCallback = function (code, time) {
|
||||||
|
const { mainStatusBarTabs } = Mixly;
|
||||||
|
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
||||||
|
mainStatusBarTabs.changeTo('output');
|
||||||
|
let message = '';
|
||||||
|
if (code) {
|
||||||
|
message = (this.shell.isCompiling() ? Msg.Lang['shell.compileFailed'] : Msg.Lang['shell.uploadFailed']);
|
||||||
|
statusBarTerminal.addValue(`\n==${message}==\n`);
|
||||||
|
} else {
|
||||||
|
message = (this.shell.isCompiling() ? Msg.Lang['shell.compileSucc'] : Msg.Lang['shell.uploadSucc']);
|
||||||
|
statusBarTerminal.addValue(`\n==${message}(${Msg.Lang['shell.timeCost']} ${dayjs.duration(time).format('HH:mm:ss.SSS')
|
||||||
|
})==\n`);
|
||||||
|
}
|
||||||
|
layer.msg(message, { time: 1000 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#running_ = false;
|
||||||
|
#upload_ = false;
|
||||||
|
#killing_ = false;
|
||||||
|
#layer_ = null;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.#layer_ = new LayerProgress({
|
||||||
|
width: 200,
|
||||||
|
cancelValue: Msg.Lang['nav.btn.stop'],
|
||||||
|
skin: 'layui-anim layui-anim-scale',
|
||||||
|
cancel: () => {
|
||||||
|
if (this.#killing_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.#layer_.title(`${Msg.Lang['shell.aborting']}...`);
|
||||||
|
this.#killing_ = true;
|
||||||
|
this.kill().catch(Debug.error);
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
cancelDisplay: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async compile(code) {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
this.#running_ = true;
|
||||||
|
this.#upload_ = false;
|
||||||
|
this.#killing_ = false;
|
||||||
|
this.showProgress();
|
||||||
|
const key = Boards.getSelectedBoardCommandParam();
|
||||||
|
const config = { key, code };
|
||||||
|
const mixlySocket = WebSocketArduShell.getMixlySocket();
|
||||||
|
mixlySocket.emit('arduino.compile', config, (response) => {
|
||||||
|
this.hideProgress();
|
||||||
|
if (response.error) {
|
||||||
|
reject(response.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const [error, result] = response;
|
||||||
|
if (error) {
|
||||||
|
reject(error);
|
||||||
|
} else {
|
||||||
|
resolve(result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async upload(port, code) {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
this.#running_ = true;
|
||||||
|
this.#upload_ = true;
|
||||||
|
this.#killing_ = false;
|
||||||
|
this.showProgress();
|
||||||
|
const key = Boards.getSelectedBoardCommandParam();
|
||||||
|
const config = { key, code, port };
|
||||||
|
const mixlySocket = WebSocketArduShell.getMixlySocket();
|
||||||
|
mixlySocket.emit('arduino.upload', config, (response) => {
|
||||||
|
this.hideProgress();
|
||||||
|
if (response.error) {
|
||||||
|
reject(response.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const [error, result] = response;
|
||||||
|
if (error) {
|
||||||
|
reject(error);
|
||||||
|
} else {
|
||||||
|
resolve(result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async kill() {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
const mixlySocket = WebSocketArduShell.getMixlySocket();
|
||||||
|
mixlySocket.emit('arduino.kill', (response) => {
|
||||||
|
if (response.error) {
|
||||||
|
reject(response.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const [error, result] = response;
|
||||||
|
if (error) {
|
||||||
|
reject(error);
|
||||||
|
} else {
|
||||||
|
resolve(result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
showProgress() {
|
||||||
|
const message = this.isCompiling() ? Msg.Lang['shell.compiling'] : Msg.Lang['shell.uploading'];
|
||||||
|
this.#layer_.title(`${message}...`);
|
||||||
|
this.#layer_.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
hideProgress() {
|
||||||
|
this.#layer_.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
isUploading() {
|
||||||
|
return this.#running_ && this.#upload_;
|
||||||
|
}
|
||||||
|
|
||||||
|
isCompiling() {
|
||||||
|
return this.#running_ && !this.#upload_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#running_ = false;
|
WebSocket.ArduShell = WebSocketArduShell;
|
||||||
#upload_ = false;
|
|
||||||
#killing_ = false;
|
|
||||||
#layer_ = null;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.#layer_ = new LayerProgress({
|
|
||||||
width: 200,
|
|
||||||
cancelValue: Msg.Lang['nav.btn.stop'],
|
|
||||||
skin: 'layui-anim layui-anim-scale',
|
|
||||||
cancel: () => {
|
|
||||||
if (this.#killing_) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.#layer_.title(`${Msg.Lang['shell.aborting']}...`);
|
|
||||||
this.#killing_ = true;
|
|
||||||
this.kill().catch(Debug.error);
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
cancelDisplay: false
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async compile(code) {
|
|
||||||
return new Promise(async (resolve, reject) => {
|
|
||||||
this.#running_ = true;
|
|
||||||
this.#upload_ = false;
|
|
||||||
this.#killing_ = false;
|
|
||||||
this.showProgress();
|
|
||||||
const key = Boards.getSelectedBoardCommandParam();
|
|
||||||
const config = { key, code };
|
|
||||||
const mixlySocket = WebSocketArduShell.getMixlySocket();
|
|
||||||
mixlySocket.emit('arduino.compile', config, (response) => {
|
|
||||||
this.hideProgress();
|
|
||||||
if (response.error) {
|
|
||||||
reject(response.error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const [error, result] = response;
|
|
||||||
if (error) {
|
|
||||||
reject(error);
|
|
||||||
} else {
|
|
||||||
resolve(result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async upload(port, code) {
|
|
||||||
return new Promise(async (resolve, reject) => {
|
|
||||||
this.#running_ = true;
|
|
||||||
this.#upload_ = true;
|
|
||||||
this.#killing_ = false;
|
|
||||||
this.showProgress();
|
|
||||||
const key = Boards.getSelectedBoardCommandParam();
|
|
||||||
const config = { key, code, port };
|
|
||||||
const mixlySocket = WebSocketArduShell.getMixlySocket();
|
|
||||||
mixlySocket.emit('arduino.upload', config, (response) => {
|
|
||||||
this.hideProgress();
|
|
||||||
if (response.error) {
|
|
||||||
reject(response.error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const [error, result] = response;
|
|
||||||
if (error) {
|
|
||||||
reject(error);
|
|
||||||
} else {
|
|
||||||
resolve(result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async kill() {
|
|
||||||
return new Promise(async (resolve, reject) => {
|
|
||||||
const mixlySocket = WebSocketArduShell.getMixlySocket();
|
|
||||||
mixlySocket.emit('arduino.kill', (response) => {
|
|
||||||
if (response.error) {
|
|
||||||
reject(response.error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const [error, result] = response;
|
|
||||||
if (error) {
|
|
||||||
reject(error);
|
|
||||||
} else {
|
|
||||||
resolve(result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
showProgress() {
|
|
||||||
const message = this.isCompiling() ? Msg.Lang['shell.compiling'] : Msg.Lang['shell.uploading'];
|
|
||||||
this.#layer_.title(`${message}...`);
|
|
||||||
this.#layer_.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
hideProgress() {
|
|
||||||
this.#layer_.hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
isUploading() {
|
|
||||||
return this.#running_ && this.#upload_;
|
|
||||||
}
|
|
||||||
|
|
||||||
isCompiling() {
|
|
||||||
return this.#running_ && !this.#upload_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
WebSocket.ArduShell = WebSocketArduShell;
|
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -1,350 +1,371 @@
|
|||||||
goog.loadJs('web', () => {
|
goog.loadJs('web', () => {
|
||||||
|
|
||||||
goog.require('path');
|
goog.require('path');
|
||||||
goog.require('layui');
|
goog.require('layui');
|
||||||
goog.require('dayjs.duration');
|
goog.require('dayjs.duration');
|
||||||
goog.require('Mixly.Debug');
|
goog.require('Mixly.Debug');
|
||||||
goog.require('Mixly.LayerExt');
|
goog.require('Mixly.LayerExt');
|
||||||
goog.require('Mixly.Msg');
|
goog.require('Mixly.Msg');
|
||||||
goog.require('Mixly.Env');
|
goog.require('Mixly.Env');
|
||||||
goog.require('Mixly.Config');
|
goog.require('Mixly.Config');
|
||||||
goog.require('Mixly.Workspace');
|
goog.require('Mixly.Workspace');
|
||||||
goog.require('Mixly.MString');
|
goog.require('Mixly.MString');
|
||||||
goog.require('Mixly.LayerProgress');
|
goog.require('Mixly.LayerProgress');
|
||||||
goog.require('Mixly.WebSocket.Serial');
|
goog.require('Mixly.Boards');
|
||||||
goog.provide('Mixly.WebSocket.BU');
|
goog.require('Mixly.Web.BU');
|
||||||
|
goog.require('Mixly.WebSocket.Serial');
|
||||||
|
goog.provide('Mixly.WebSocket.BU');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
Debug,
|
Debug,
|
||||||
LayerExt,
|
LayerExt,
|
||||||
Config,
|
Config,
|
||||||
Msg,
|
Msg,
|
||||||
Env,
|
Env,
|
||||||
Workspace,
|
Workspace,
|
||||||
MString,
|
MString,
|
||||||
LayerProgress,
|
LayerProgress,
|
||||||
WebSocket
|
Boards,
|
||||||
} = Mixly;
|
WebSocket
|
||||||
|
} = Mixly;
|
||||||
|
|
||||||
const { SELECTED_BOARD } = Config;
|
const { SELECTED_BOARD, BOARD } = Config;
|
||||||
|
|
||||||
const { Serial } = WebSocket;
|
// WebBU 需要在使用时动态获取,避免模块加载顺序问题
|
||||||
|
const getWebBU = () => Mixly.Web?.BU;
|
||||||
|
|
||||||
const { layer } = layui;
|
const { Serial } = WebSocket;
|
||||||
|
|
||||||
|
const { layer } = layui;
|
||||||
|
|
||||||
|
|
||||||
class WebSocketBU {
|
class WebSocketBU {
|
||||||
static {
|
static {
|
||||||
this.mixlySocket = null;
|
this.mixlySocket = null;
|
||||||
this.socket = null;
|
this.socket = null;
|
||||||
this.shell = null;
|
this.shell = null;
|
||||||
|
|
||||||
this.getSocket = function () {
|
this.getSocket = function () {
|
||||||
return this.socket;
|
return this.socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getMixlySocket = function () {
|
this.getMixlySocket = function () {
|
||||||
return this.mixlySocket;
|
return this.mixlySocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.init = function (mixlySocket) {
|
this.init = function (mixlySocket) {
|
||||||
this.mixlySocket = mixlySocket;
|
this.mixlySocket = mixlySocket;
|
||||||
this.socket = mixlySocket.getSocket();
|
this.socket = mixlySocket.getSocket();
|
||||||
this.shell = new WebSocketBU();
|
this.shell = new WebSocketBU();
|
||||||
const socket = this.socket;
|
const socket = this.socket;
|
||||||
|
|
||||||
socket.on('micropython.dataEvent', (data) => {
|
socket.on('micropython.dataEvent', (data) => {
|
||||||
|
const { mainStatusBarTabs } = Mixly;
|
||||||
|
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
||||||
|
statusBarTerminal.addValue(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('micropython.errorEvent', (data) => {
|
||||||
|
const { mainStatusBarTabs } = Mixly;
|
||||||
|
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
||||||
|
statusBarTerminal.addValue(data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.initBurn = function () {
|
||||||
|
// MicroPython 板卡使用本地 Web Serial API 烧录,而非通过服务器
|
||||||
|
const WebBU = getWebBU();
|
||||||
|
if (SELECTED_BOARD?.language === 'MicroPython' && WebBU) {
|
||||||
|
return WebBU.initBurn();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.mixlySocket.isConnected()) {
|
||||||
|
layer.msg(Msg.Lang['websocket.offline'], { time: 1000 });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const port = Serial.getSelectedPortName();
|
||||||
|
if (!port) {
|
||||||
|
layer.msg(Msg.Lang['statusbar.serial.noDevice'], {
|
||||||
|
time: 1000
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
const { mainStatusBarTabs } = Mixly;
|
const { mainStatusBarTabs } = Mixly;
|
||||||
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
||||||
statusBarTerminal.addValue(data);
|
mainStatusBarTabs.changeTo('output');
|
||||||
});
|
mainStatusBarTabs.show();
|
||||||
|
statusBarTerminal.setValue(`${Msg.Lang['shell.burning']}...\n`);
|
||||||
|
const statusBarSerial = mainStatusBarTabs.getStatusBarById(port);
|
||||||
|
const closePromise = statusBarSerial ? statusBarSerial.close() : Promise.resolve();
|
||||||
|
closePromise
|
||||||
|
.then(() => {
|
||||||
|
return this.shell.burn(port);
|
||||||
|
})
|
||||||
|
.then((info) => {
|
||||||
|
this.endCallback(info.code, info.time);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
Debug.error(error);
|
||||||
|
statusBarTerminal.addValue(`\n==${Msg.Lang['shell.burnFailed']}==\n`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
socket.on('micropython.errorEvent', (data) => {
|
this.initUpload = function () {
|
||||||
|
// MicroPython 板卡使用本地 Web Serial API 上传,而非通过服务器
|
||||||
|
const WebBU = getWebBU();
|
||||||
|
if (SELECTED_BOARD?.language === 'MicroPython' && WebBU) {
|
||||||
|
return WebBU.initUpload();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.mixlySocket.isConnected()) {
|
||||||
|
layer.msg(Msg.Lang['websocket.offline'], { time: 1000 });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const port = Serial.getSelectedPortName();
|
||||||
|
if (!port) {
|
||||||
|
layer.msg(Msg.Lang['statusbar.serial.noDevice'], {
|
||||||
|
time: 1000
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
const { mainStatusBarTabs } = Mixly;
|
const { mainStatusBarTabs } = Mixly;
|
||||||
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
||||||
statusBarTerminal.addValue(data);
|
mainStatusBarTabs.changeTo('output');
|
||||||
|
mainStatusBarTabs.show();
|
||||||
|
statusBarTerminal.setValue(`${Msg.Lang['shell.uploading']}...\n`);
|
||||||
|
const mainWorkspace = Workspace.getMain();
|
||||||
|
const editor = mainWorkspace.getEditorsManager().getActive();
|
||||||
|
const code = editor.getCode();
|
||||||
|
const statusBarSerial = mainStatusBarTabs.getStatusBarById(port);
|
||||||
|
const closePromise = statusBarSerial ? statusBarSerial.close() : Promise.resolve();
|
||||||
|
closePromise
|
||||||
|
.then(() => {
|
||||||
|
return this.shell.upload(port, code)
|
||||||
|
})
|
||||||
|
.then((info) => {
|
||||||
|
this.endCallback(info.code, info.time);
|
||||||
|
if (info.code || !Serial.portIsLegal(port)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mainStatusBarTabs.add('serial', port);
|
||||||
|
mainStatusBarTabs.changeTo(port);
|
||||||
|
const statusBarSerial = mainStatusBarTabs.getStatusBarById(port);
|
||||||
|
statusBarSerial.open()
|
||||||
|
.then(() => {
|
||||||
|
return statusBarSerial.setBaudRate(115200);
|
||||||
|
})
|
||||||
|
.catch(Debug.error);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
Debug.error(error);
|
||||||
|
statusBarTerminal.addValue(`\n==${Msg.Lang['shell.uploadFailed']}==\n`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.endCallback = function (code, time) {
|
||||||
|
const { mainStatusBarTabs } = Mixly;
|
||||||
|
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
||||||
|
mainStatusBarTabs.changeTo('output');
|
||||||
|
let message = '';
|
||||||
|
if (code) {
|
||||||
|
message = (this.shell.isBurning() ? Msg.Lang['shell.burnFailed'] : Msg.Lang['shell.uploadFailed']);
|
||||||
|
statusBarTerminal.addValue(`\n==${message}==\n`);
|
||||||
|
} else {
|
||||||
|
message = (this.shell.isBurning() ? Msg.Lang['shell.burnSucc'] : Msg.Lang['shell.uploadSucc']);
|
||||||
|
statusBarTerminal.addValue(`\n==${message}(${Msg.Lang['shell.timeCost']} ${dayjs.duration(time).format('HH:mm:ss.SSS')
|
||||||
|
})==\n`);
|
||||||
|
}
|
||||||
|
layer.msg(message, { time: 1000 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#running_ = false;
|
||||||
|
#upload_ = false;
|
||||||
|
#killing_ = false;
|
||||||
|
#layer_ = null;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.#layer_ = new LayerProgress({
|
||||||
|
width: 200,
|
||||||
|
cancelValue: Msg.Lang['nav.btn.stop'],
|
||||||
|
skin: 'layui-anim layui-anim-scale',
|
||||||
|
cancel: () => {
|
||||||
|
if (this.#killing_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.#layer_.title(`${Msg.Lang['shell.aborting']}...`);
|
||||||
|
this.#killing_ = true;
|
||||||
|
this.kill().catch(Debug.error);
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
cancelDisplay: false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.initBurn = function () {
|
async burn(port) {
|
||||||
if (!this.mixlySocket.isConnected()) {
|
return new Promise(async (resolve, reject) => {
|
||||||
layer.msg(Msg.Lang['websocket.offline'], { time: 1000 });
|
this.#running_ = true;
|
||||||
return;
|
this.#upload_ = false;
|
||||||
}
|
this.#killing_ = false;
|
||||||
const port = Serial.getSelectedPortName();
|
this.showProgress();
|
||||||
if (!port) {
|
const config = {
|
||||||
layer.msg(Msg.Lang['statusbar.serial.noDevice'], {
|
boardDirPath: `.${Env.boardDirPath}`,
|
||||||
time: 1000
|
port,
|
||||||
});
|
command: SELECTED_BOARD.burn.command,
|
||||||
return;
|
baudrate: Boards.getSelectedBoardConfigParam('BurnSpeed'),
|
||||||
}
|
reset: SELECTED_BOARD.burn.reset || []
|
||||||
const { mainStatusBarTabs } = Mixly;
|
};
|
||||||
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
const mixlySocket = WebSocketBU.getMixlySocket();
|
||||||
mainStatusBarTabs.changeTo('output');
|
mixlySocket.emit('micropython.burn', config, (response) => {
|
||||||
mainStatusBarTabs.show();
|
this.hideProgress();
|
||||||
statusBarTerminal.setValue(`${Msg.Lang['shell.burning']}...\n`);
|
if (response.error) {
|
||||||
const statusBarSerial = mainStatusBarTabs.getStatusBarById(port);
|
reject(response.error);
|
||||||
const closePromise = statusBarSerial ? statusBarSerial.close() : Promise.resolve();
|
|
||||||
closePromise
|
|
||||||
.then(() => {
|
|
||||||
return this.shell.burn(port);
|
|
||||||
})
|
|
||||||
.then((info) => {
|
|
||||||
this.endCallback(info.code, info.time);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
Debug.error(error);
|
|
||||||
statusBarTerminal.addValue(`\n==${Msg.Lang['shell.burnFailed']}==\n`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.initUpload = function () {
|
|
||||||
if (!this.mixlySocket.isConnected()) {
|
|
||||||
layer.msg(Msg.Lang['websocket.offline'], { time: 1000 });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const port = Serial.getSelectedPortName();
|
|
||||||
if (!port) {
|
|
||||||
layer.msg(Msg.Lang['statusbar.serial.noDevice'], {
|
|
||||||
time: 1000
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { mainStatusBarTabs } = Mixly;
|
|
||||||
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
|
||||||
mainStatusBarTabs.changeTo('output');
|
|
||||||
mainStatusBarTabs.show();
|
|
||||||
statusBarTerminal.setValue(`${Msg.Lang['shell.uploading']}...\n`);
|
|
||||||
const mainWorkspace = Workspace.getMain();
|
|
||||||
const editor = mainWorkspace.getEditorsManager().getActive();
|
|
||||||
const code = editor.getCode();
|
|
||||||
const statusBarSerial = mainStatusBarTabs.getStatusBarById(port);
|
|
||||||
const closePromise = statusBarSerial ? statusBarSerial.close() : Promise.resolve();
|
|
||||||
closePromise
|
|
||||||
.then(() => {
|
|
||||||
return this.shell.upload(port, code)
|
|
||||||
})
|
|
||||||
.then((info) => {
|
|
||||||
this.endCallback(info.code, info.time);
|
|
||||||
if (info.code || !Serial.portIsLegal(port)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mainStatusBarTabs.add('serial', port);
|
const [error, result] = response;
|
||||||
mainStatusBarTabs.changeTo(port);
|
if (error) {
|
||||||
const statusBarSerial = mainStatusBarTabs.getStatusBarById(port);
|
reject(error);
|
||||||
statusBarSerial.open()
|
} else {
|
||||||
.then(() => {
|
resolve(result);
|
||||||
return statusBarSerial.setBaudRate(115200);
|
}
|
||||||
})
|
|
||||||
.catch(Debug.error);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
Debug.error(error);
|
|
||||||
statusBarTerminal.addValue(`\n==${Msg.Lang['shell.uploadFailed']}==\n`);
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
this.endCallback = function (code, time) {
|
|
||||||
const { mainStatusBarTabs } = Mixly;
|
|
||||||
const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output');
|
|
||||||
mainStatusBarTabs.changeTo('output');
|
|
||||||
let message = '';
|
|
||||||
if (code) {
|
|
||||||
message = (this.shell.isBurning() ? Msg.Lang['shell.burnFailed'] : Msg.Lang['shell.uploadFailed']);
|
|
||||||
statusBarTerminal.addValue(`\n==${message}==\n`);
|
|
||||||
} else {
|
|
||||||
message = (this.shell.isBurning() ? Msg.Lang['shell.burnSucc'] : Msg.Lang['shell.uploadSucc']);
|
|
||||||
statusBarTerminal.addValue(`\n==${message}(${Msg.Lang['shell.timeCost']} ${
|
|
||||||
dayjs.duration(time).format('HH:mm:ss.SSS')
|
|
||||||
})==\n`);
|
|
||||||
}
|
|
||||||
layer.msg(message, { time: 1000 });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#running_ = false;
|
|
||||||
#upload_ = false;
|
|
||||||
#killing_ = false;
|
|
||||||
#layer_ = null;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.#layer_ = new LayerProgress({
|
|
||||||
width: 200,
|
|
||||||
cancelValue: Msg.Lang['nav.btn.stop'],
|
|
||||||
skin: 'layui-anim layui-anim-scale',
|
|
||||||
cancel: () => {
|
|
||||||
if (this.#killing_) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.#layer_.title(`${Msg.Lang['shell.aborting']}...`);
|
|
||||||
this.#killing_ = true;
|
|
||||||
this.kill().catch(Debug.error);
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
cancelDisplay: false
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async burn(port) {
|
|
||||||
return new Promise(async (resolve, reject) => {
|
|
||||||
this.#running_ = true;
|
|
||||||
this.#upload_ = false;
|
|
||||||
this.#killing_ = false;
|
|
||||||
this.showProgress();
|
|
||||||
const config = {
|
|
||||||
boardDirPath: `.${Env.boardDirPath}`,
|
|
||||||
port,
|
|
||||||
command: SELECTED_BOARD.burn.command
|
|
||||||
};
|
|
||||||
const mixlySocket = WebSocketBU.getMixlySocket();
|
|
||||||
mixlySocket.emit('micropython.burn', config, (response) => {
|
|
||||||
this.hideProgress();
|
|
||||||
if (response.error) {
|
|
||||||
reject(response.error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const [error, result] = response;
|
|
||||||
if (error) {
|
|
||||||
reject(error);
|
|
||||||
} else {
|
|
||||||
resolve(result);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async upload(port, code) {
|
async upload(port, code) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
this.#running_ = true;
|
this.#running_ = true;
|
||||||
this.#upload_ = true;
|
this.#upload_ = true;
|
||||||
this.#killing_ = false;
|
this.#killing_ = false;
|
||||||
this.showProgress();
|
this.showProgress();
|
||||||
const importsMap = this.getImportModules(code);
|
const importsMap = this.getImportModules(code);
|
||||||
let libraries = {};
|
let libraries = {};
|
||||||
for (let key in importsMap) {
|
for (let key in importsMap) {
|
||||||
const filename = importsMap[key]['__name__'];
|
const filename = importsMap[key]['__name__'];
|
||||||
const data = goog.readFileSync(importsMap[key]['__path__']);
|
const data = goog.readFileSync(importsMap[key]['__path__']);
|
||||||
libraries[filename] = data;
|
libraries[filename] = data;
|
||||||
}
|
|
||||||
const config = {
|
|
||||||
boardDirPath: `.${Env.boardDirPath}`,
|
|
||||||
command: SELECTED_BOARD.upload.command,
|
|
||||||
filePath: SELECTED_BOARD.upload.filePath,
|
|
||||||
port, code, libraries
|
|
||||||
};
|
|
||||||
|
|
||||||
const mixlySocket = WebSocketBU.getMixlySocket();
|
|
||||||
mixlySocket.emit('micropython.upload', config, (response) => {
|
|
||||||
this.hideProgress();
|
|
||||||
if (response.error) {
|
|
||||||
reject(response.error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const [error, result] = response;
|
|
||||||
if (error) {
|
|
||||||
reject(error);
|
|
||||||
} else {
|
|
||||||
resolve(result);
|
|
||||||
}
|
}
|
||||||
|
const config = {
|
||||||
|
boardDirPath: `.${Env.boardDirPath}`,
|
||||||
|
command: SELECTED_BOARD.upload.command,
|
||||||
|
filePath: SELECTED_BOARD.upload.filePath,
|
||||||
|
baudrate: Boards.getSelectedBoardConfigParam('BurnSpeed'),
|
||||||
|
reset: SELECTED_BOARD.upload.reset || [],
|
||||||
|
port, code, libraries
|
||||||
|
};
|
||||||
|
|
||||||
|
const mixlySocket = WebSocketBU.getMixlySocket();
|
||||||
|
mixlySocket.emit('micropython.upload', config, (response) => {
|
||||||
|
this.hideProgress();
|
||||||
|
if (response.error) {
|
||||||
|
reject(response.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const [error, result] = response;
|
||||||
|
if (error) {
|
||||||
|
reject(error);
|
||||||
|
} else {
|
||||||
|
resolve(result);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
getImportModulesName(code) {
|
|
||||||
// 正则表达式: 匹配 import 或 from 导入语句
|
|
||||||
const importRegex = /(?:import\s+([a-zA-Z0-9_]+)|from\s+([a-zA-Z0-9_]+)\s+import)/g;
|
|
||||||
|
|
||||||
let imports = [];
|
|
||||||
let match;
|
|
||||||
while ((match = importRegex.exec(code)) !== null) {
|
|
||||||
if (match[1]) {
|
|
||||||
imports.push(match[1]); // 'import module'
|
|
||||||
}
|
|
||||||
if (match[2]) {
|
|
||||||
imports.push(match[2]); // 'from module import ...'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return imports;
|
|
||||||
}
|
|
||||||
|
|
||||||
getImportModules(code) {
|
|
||||||
let importsMap = {};
|
|
||||||
const libPath = SELECTED_BOARD.upload.libPath;
|
|
||||||
for (let i = libPath.length - 1; i >= 0; i--) {
|
|
||||||
const dirname = MString.tpl(libPath[i], { indexPath: Env.boardDirPath });
|
|
||||||
const map = goog.readJsonSync(path.join(dirname, 'map.json'));
|
|
||||||
if (!(map && map instanceof Object)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (let key in map) {
|
|
||||||
importsMap[key] = structuredClone(map[key]);
|
|
||||||
importsMap[key]['__path__'] = path.join(dirname, map[key]['__name__']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let usedMap = {};
|
getImportModulesName(code) {
|
||||||
let currentImports = this.getImportModulesName(code);
|
// 正则表达式: 匹配 import 或 from 导入语句
|
||||||
while (currentImports.length) {
|
const importRegex = /(?:import\s+([a-zA-Z0-9_]+)|from\s+([a-zA-Z0-9_]+)\s+import)/g;
|
||||||
let temp = [];
|
|
||||||
for (let moduleName of currentImports) {
|
let imports = [];
|
||||||
let moduleInfo = importsMap[moduleName];
|
let match;
|
||||||
if (!moduleInfo) {
|
while ((match = importRegex.exec(code)) !== null) {
|
||||||
|
if (match[1]) {
|
||||||
|
imports.push(match[1]); // 'import module'
|
||||||
|
}
|
||||||
|
if (match[2]) {
|
||||||
|
imports.push(match[2]); // 'from module import ...'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return imports;
|
||||||
|
}
|
||||||
|
|
||||||
|
getImportModules(code) {
|
||||||
|
let importsMap = {};
|
||||||
|
const libPath = SELECTED_BOARD.upload.libPath;
|
||||||
|
for (let i = libPath.length - 1; i >= 0; i--) {
|
||||||
|
const dirname = MString.tpl(libPath[i], { indexPath: Env.boardDirPath });
|
||||||
|
const map = goog.readJsonSync(path.join(dirname, 'map.json'));
|
||||||
|
if (!(map && map instanceof Object)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
usedMap[moduleName] = moduleInfo;
|
for (let key in map) {
|
||||||
const moduleImports = moduleInfo['__require__'];
|
importsMap[key] = structuredClone(map[key]);
|
||||||
if (!moduleImports) {
|
importsMap[key]['__path__'] = path.join(dirname, map[key]['__name__']);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
for (let name of moduleImports) {
|
}
|
||||||
if (usedMap[name] || !importsMap[name] || temp.includes(name)) {
|
|
||||||
|
let usedMap = {};
|
||||||
|
let currentImports = this.getImportModulesName(code);
|
||||||
|
while (currentImports.length) {
|
||||||
|
let temp = [];
|
||||||
|
for (let moduleName of currentImports) {
|
||||||
|
let moduleInfo = importsMap[moduleName];
|
||||||
|
if (!moduleInfo) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
temp.push(name);
|
usedMap[moduleName] = moduleInfo;
|
||||||
|
const moduleImports = moduleInfo['__require__'];
|
||||||
|
if (!moduleImports) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (let name of moduleImports) {
|
||||||
|
if (usedMap[name] || !importsMap[name] || temp.includes(name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
temp.push(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
currentImports = temp;
|
||||||
}
|
}
|
||||||
currentImports = temp;
|
return usedMap;
|
||||||
}
|
}
|
||||||
return usedMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
async kill() {
|
async kill() {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
const mixlySocket = WebSocketBU.getMixlySocket();
|
const mixlySocket = WebSocketBU.getMixlySocket();
|
||||||
mixlySocket.emit('micropython.kill', (response) => {
|
mixlySocket.emit('micropython.kill', (response) => {
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
reject(response.error);
|
reject(response.error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const [error, result] = response;
|
const [error, result] = response;
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
} else {
|
} else {
|
||||||
resolve(result);
|
resolve(result);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
|
showProgress() {
|
||||||
|
const message = this.isBurning() ? Msg.Lang['shell.burning'] : Msg.Lang['shell.uploading'];
|
||||||
|
this.#layer_.title(`${message}...`);
|
||||||
|
this.#layer_.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
hideProgress() {
|
||||||
|
this.#layer_.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
isUploading() {
|
||||||
|
return this.#running_ && this.#upload_;
|
||||||
|
}
|
||||||
|
|
||||||
|
isBurning() {
|
||||||
|
return this.#running_ && !this.#upload_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showProgress() {
|
WebSocket.BU = WebSocketBU;
|
||||||
const message = this.isBurning() ? Msg.Lang['shell.burning'] : Msg.Lang['shell.uploading'];
|
|
||||||
this.#layer_.title(`${message}...`);
|
|
||||||
this.#layer_.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
hideProgress() {
|
|
||||||
this.#layer_.hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
isUploading() {
|
|
||||||
return this.#running_ && this.#upload_;
|
|
||||||
}
|
|
||||||
|
|
||||||
isBurning() {
|
|
||||||
return this.#running_ && !this.#upload_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
WebSocket.BU = WebSocketBU;
|
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -1,429 +1,434 @@
|
|||||||
goog.loadJs('web', () => {
|
goog.loadJs('web', () => {
|
||||||
|
|
||||||
goog.require('path');
|
goog.require('path');
|
||||||
goog.require('Mustache');
|
goog.require('Mustache');
|
||||||
goog.require('Mixly.Env');
|
goog.require('Mixly.Env');
|
||||||
goog.require('Mixly.Events');
|
goog.require('Mixly.Events');
|
||||||
goog.require('Mixly.Msg');
|
goog.require('Mixly.Msg');
|
||||||
goog.require('Mixly.Ampy');
|
goog.require('Mixly.Ampy');
|
||||||
goog.require('Mixly.Web');
|
goog.require('Mixly.Web');
|
||||||
goog.provide('Mixly.Web.Ampy');
|
goog.provide('Mixly.Web.Ampy');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
Env,
|
Env,
|
||||||
Events,
|
Events,
|
||||||
Msg,
|
Msg,
|
||||||
Ampy,
|
Ampy,
|
||||||
Web
|
Web
|
||||||
} = Mixly;
|
} = Mixly;
|
||||||
|
|
||||||
|
|
||||||
class AmpyExt extends Ampy {
|
class AmpyExt extends Ampy {
|
||||||
static {
|
static {
|
||||||
this.LS = goog.readFileSync(path.join(Env.templatePath, 'python/ls.py'));
|
this.LS = goog.readFileSync(path.join(Env.templatePath, 'python/ls.py'));
|
||||||
this.LS_RECURSIVE = goog.readFileSync(path.join(Env.templatePath, 'python/ls-recursive.py'));
|
this.LS_RECURSIVE = goog.readFileSync(path.join(Env.templatePath, 'python/ls-recursive.py'));
|
||||||
this.LS_LONG_FORMAT = goog.readFileSync(path.join(Env.templatePath, 'python/ls-long-format.py'));
|
this.LS_LONG_FORMAT = goog.readFileSync(path.join(Env.templatePath, 'python/ls-long-format.py'));
|
||||||
this.MKDIR = goog.readFileSync(path.join(Env.templatePath, 'python/mkdir.py'));
|
this.MKDIR = goog.readFileSync(path.join(Env.templatePath, 'python/mkdir.py'));
|
||||||
this.MKFILE = goog.readFileSync(path.join(Env.templatePath, 'python/mkfile.py'));
|
this.MKFILE = goog.readFileSync(path.join(Env.templatePath, 'python/mkfile.py'));
|
||||||
this.RENAME = goog.readFileSync(path.join(Env.templatePath, 'python/rename.py'));
|
this.RENAME = goog.readFileSync(path.join(Env.templatePath, 'python/rename.py'));
|
||||||
this.RM = goog.readFileSync(path.join(Env.templatePath, 'python/rm.py'));
|
this.RM = goog.readFileSync(path.join(Env.templatePath, 'python/rm.py'));
|
||||||
this.RMDIR = goog.readFileSync(path.join(Env.templatePath, 'python/rmdir.py'));
|
this.RMDIR = goog.readFileSync(path.join(Env.templatePath, 'python/rmdir.py'));
|
||||||
this.GET = goog.readFileSync(path.join(Env.templatePath, 'python/get.py'));
|
this.GET = goog.readFileSync(path.join(Env.templatePath, 'python/get.py'));
|
||||||
this.CWD = goog.readFileSync(path.join(Env.templatePath, 'python/cwd.py'));
|
this.CWD = goog.readFileSync(path.join(Env.templatePath, 'python/cwd.py'));
|
||||||
this.CPDIR = goog.readFileSync(path.join(Env.templatePath, 'python/cpdir.py'));
|
this.CPDIR = goog.readFileSync(path.join(Env.templatePath, 'python/cpdir.py'));
|
||||||
this.CPFILE = goog.readFileSync(path.join(Env.templatePath, 'python/cpfile.py'));
|
this.CPFILE = goog.readFileSync(path.join(Env.templatePath, 'python/cpfile.py'));
|
||||||
}
|
}
|
||||||
|
|
||||||
#device_ = null;
|
#device_ = null;
|
||||||
#receiveTemp_ = [];
|
#receiveTemp_ = [];
|
||||||
#writeBuffer_ = true;
|
#writeBuffer_ = true;
|
||||||
#active_ = false;
|
#active_ = false;
|
||||||
#dataLength_ = 256;
|
#dataLength_ = 256;
|
||||||
#events_ = new Events(['message', 'replaceMessage'])
|
#events_ = new Events(['message', 'replaceMessage'])
|
||||||
constructor(device, writeBuffer = true, dataLength = 256) {
|
constructor(device, writeBuffer = true, dataLength = 256) {
|
||||||
super();
|
super();
|
||||||
this.#device_ = device;
|
this.#device_ = device;
|
||||||
this.#writeBuffer_ = writeBuffer;
|
this.#writeBuffer_ = writeBuffer;
|
||||||
this.#dataLength_ = dataLength;
|
this.#dataLength_ = dataLength;
|
||||||
this.#addEventsListener_();
|
this.#addEventsListener_();
|
||||||
}
|
}
|
||||||
|
|
||||||
#addEventsListener_() {
|
#addEventsListener_() {
|
||||||
this.#device_.bind('onChar', (char) => {
|
this.#device_.bind('onChar', (char) => {
|
||||||
if (['\r', '\n'].includes(char)) {
|
if (['\r', '\n'].includes(char)) {
|
||||||
this.#receiveTemp_.push('');
|
this.#receiveTemp_.push('');
|
||||||
} else {
|
|
||||||
let line = this.#receiveTemp_.pop() ?? '';
|
|
||||||
this.#receiveTemp_.push(line + char);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
bind(...args) {
|
|
||||||
return this.#events_.bind(...args);
|
|
||||||
}
|
|
||||||
|
|
||||||
message(message) {
|
|
||||||
this.#events_.run('message', message);
|
|
||||||
}
|
|
||||||
|
|
||||||
replaceMessage(lineNumber, message) {
|
|
||||||
this.#events_.run('replaceMessage', lineNumber, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
getProgressMessage(name, percent) {
|
|
||||||
const sended = parseInt(percent * 45);
|
|
||||||
const left = percent === 0 ? '' : Array(sended).fill('=').join('');
|
|
||||||
const right = percent === 100 ? '' : Array(45 - sended).fill('-').join('');
|
|
||||||
return `${name} → |${left}${right}| ${(percent * 100).toFixed(1)}%`;
|
|
||||||
}
|
|
||||||
|
|
||||||
isActive() {
|
|
||||||
return this.#active_;
|
|
||||||
}
|
|
||||||
|
|
||||||
async readUntil(ending, withEnding = true, timeout = 5000) {
|
|
||||||
const startTime = Number(new Date());
|
|
||||||
let nowTime = startTime;
|
|
||||||
let readStr = '';
|
|
||||||
while (nowTime - startTime < timeout) {
|
|
||||||
const nowTime = Number(new Date());
|
|
||||||
let len = this.#receiveTemp_.length;
|
|
||||||
for (let i = 0; i < len; i++) {
|
|
||||||
const data = this.#receiveTemp_.shift();
|
|
||||||
let index = data.toLowerCase().indexOf(ending);
|
|
||||||
if (index !== -1) {
|
|
||||||
if (withEnding) {
|
|
||||||
index += ending.length;
|
|
||||||
}
|
|
||||||
this.#receiveTemp_.unshift(data.substring(index));
|
|
||||||
readStr += data.substring(0, index);
|
|
||||||
return readStr;
|
|
||||||
} else {
|
} else {
|
||||||
readStr += data;
|
let line = this.#receiveTemp_.pop() ?? '';
|
||||||
if (i !== len - 1) {
|
this.#receiveTemp_.push(line + char);
|
||||||
readStr += '\n';
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bind(...args) {
|
||||||
|
return this.#events_.bind(...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
message(message) {
|
||||||
|
this.#events_.run('message', message);
|
||||||
|
}
|
||||||
|
|
||||||
|
replaceMessage(lineNumber, message) {
|
||||||
|
this.#events_.run('replaceMessage', lineNumber, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
getProgressMessage(name, percent) {
|
||||||
|
const sended = parseInt(percent * 45);
|
||||||
|
const left = percent === 0 ? '' : Array(sended).fill('=').join('');
|
||||||
|
const right = percent === 100 ? '' : Array(45 - sended).fill('-').join('');
|
||||||
|
return `${name} → |${left}${right}| ${(percent * 100).toFixed(1)}%`;
|
||||||
|
}
|
||||||
|
|
||||||
|
isActive() {
|
||||||
|
return this.#active_;
|
||||||
|
}
|
||||||
|
|
||||||
|
async readUntil(ending, withEnding = true, timeout = 5000) {
|
||||||
|
const startTime = Number(new Date());
|
||||||
|
let nowTime = startTime;
|
||||||
|
let readStr = '';
|
||||||
|
while (nowTime - startTime < timeout) {
|
||||||
|
const nowTime = Number(new Date());
|
||||||
|
let len = this.#receiveTemp_.length;
|
||||||
|
for (let i = 0; i < len; i++) {
|
||||||
|
const data = this.#receiveTemp_.shift();
|
||||||
|
let index = data.toLowerCase().indexOf(ending);
|
||||||
|
if (index !== -1) {
|
||||||
|
if (withEnding) {
|
||||||
|
index += ending.length;
|
||||||
|
}
|
||||||
|
this.#receiveTemp_.unshift(data.substring(index));
|
||||||
|
readStr += data.substring(0, index);
|
||||||
|
return readStr;
|
||||||
|
} else {
|
||||||
|
readStr += data;
|
||||||
|
if (i !== len - 1) {
|
||||||
|
readStr += '\n';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (nowTime - startTime >= timeout) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
if (!this.isActive()) {
|
||||||
|
throw new Error(Msg.Lang['ampy.dataReadInterrupt']);
|
||||||
|
}
|
||||||
|
await this.#device_.sleep(100);
|
||||||
}
|
}
|
||||||
if (nowTime - startTime >= timeout) {
|
}
|
||||||
|
|
||||||
|
async interrupt(timeout = 1000) {
|
||||||
|
for (let i = 0; i < 5; i++) {
|
||||||
|
// 中断两次
|
||||||
|
await this.#device_.sendBuffer([0x0D, 0x03]);
|
||||||
|
await this.#device_.sleep(100);
|
||||||
|
await this.#device_.sendBuffer([0x03]);
|
||||||
|
await this.#device_.sleep(100);
|
||||||
|
if (await this.readUntil('>>>', true, timeout)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async enterRawREPL(timeout = 1000) {
|
||||||
|
for (let i = 0; i < 5; i++) {
|
||||||
|
await this.#device_.sendBuffer([0x01]);
|
||||||
|
await this.#device_.sleep(100);
|
||||||
|
if (await this.readUntil('raw repl; ctrl-b to exit', true, timeout)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async exitRawREPL(timeout = 5000) {
|
||||||
|
await this.#device_.sendBuffer([0x02]);
|
||||||
|
await this.#device_.sleep(100);
|
||||||
|
let succeed = false;
|
||||||
|
if (await this.readUntil('>>>', true, timeout)) {
|
||||||
|
succeed = true;
|
||||||
|
}
|
||||||
|
return succeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
async exitREPL(timeout = 5000) {
|
||||||
|
await this.#device_.sendBuffer([0x04]);
|
||||||
|
await this.#device_.sleep(100);
|
||||||
|
let succeed = false;
|
||||||
|
if (await this.readUntil('soft reboot', false, timeout)) {
|
||||||
|
succeed = true;
|
||||||
|
}
|
||||||
|
return succeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
async exec(str, timeout = 5000) {
|
||||||
|
if (this.#writeBuffer_) {
|
||||||
|
const buffer = this.#device_.encode(str);
|
||||||
|
const len = Math.ceil(buffer.length / this.#dataLength_);
|
||||||
|
for (let i = 0; i < len; i++) {
|
||||||
|
const start = i * this.#dataLength_;
|
||||||
|
const end = Math.min((i + 1) * this.#dataLength_, buffer.length);
|
||||||
|
const writeBuffer = buffer.slice(start, end);
|
||||||
|
await this.#device_.sendBuffer(writeBuffer);
|
||||||
|
await this.#device_.sleep(10);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < str.length / this.#dataLength_; i++) {
|
||||||
|
const start = i * this.#dataLength_;
|
||||||
|
const end = Math.min((i + 1) * this.#dataLength_, str.length);
|
||||||
|
let data = str.substring(start, end);
|
||||||
|
await this.#device_.sendString(data);
|
||||||
|
await this.#device_.sleep(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await this.#device_.sendBuffer([0x04]);
|
||||||
|
return await this.follow(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
async follow(timeout = 1000) {
|
||||||
|
let data = await this.readUntil('\x04', true, timeout);
|
||||||
|
if (data.length < 1) {
|
||||||
|
throw new Error(Msg.Lang['ampy.waitingFirstEOFTimeout']);
|
||||||
|
}
|
||||||
|
let start = data.toLowerCase().lastIndexOf('ok');
|
||||||
|
if (start === -1) {
|
||||||
|
start = 0;
|
||||||
|
} else {
|
||||||
|
start += 2;
|
||||||
|
}
|
||||||
|
data = data.substring(start, data.length - 1);
|
||||||
|
let dataError = await this.readUntil('\x04', true, timeout);
|
||||||
|
if (dataError.length < 1) {
|
||||||
|
throw new Error(Msg.Lang['ampy.secondEOFTimeout']);
|
||||||
|
}
|
||||||
|
dataError = dataError.substring(0, dataError.length - 1);
|
||||||
|
return { data, dataError };
|
||||||
|
}
|
||||||
|
|
||||||
|
async enter() {
|
||||||
|
if (this.isActive()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.#active_ = true;
|
||||||
|
await this.#device_.open(115200);
|
||||||
|
await this.#device_.sleep(500);
|
||||||
|
await this.#device_.sendBuffer([0x02]);
|
||||||
|
if (!await this.interrupt()) {
|
||||||
|
throw new Error(Msg.Lang['ampy.interruptFailed']);
|
||||||
|
}
|
||||||
|
if (!await this.enterRawREPL()) {
|
||||||
|
throw new Error(Msg.Lang['ampy.enterRawREPLFailed']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async exit() {
|
||||||
|
if (!this.isActive()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!await this.exitRawREPL()) {
|
||||||
|
throw new Error(Msg.Lang['ampy.exitRawREPLFailed']);
|
||||||
|
}
|
||||||
|
// 发送 Ctrl+D 触发软复位,让设备执行上传的 main.py
|
||||||
|
if (!await this.exitREPL()) {
|
||||||
|
throw new Error(Msg.Lang['ampy.exitREPLFailed']);
|
||||||
|
}
|
||||||
|
await this.#device_.close();
|
||||||
|
this.#active_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async get(filename, encoding = 'utf8', timeout = 5000) {
|
||||||
|
if (!this.isActive()) {
|
||||||
|
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
||||||
|
}
|
||||||
|
const code = Mustache.render(AmpyExt.GET, {
|
||||||
|
path: filename
|
||||||
|
});
|
||||||
|
const { data, dataError } = await this.exec(code, timeout);
|
||||||
|
if (dataError) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
if (encoding === 'utf8') {
|
||||||
|
return this.#device_.decode(this.unhexlify(data));
|
||||||
|
} else {
|
||||||
|
return this.unhexlify(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async put(filename, data, timeout = 5000) {
|
||||||
if (!this.isActive()) {
|
if (!this.isActive()) {
|
||||||
throw new Error(Msg.Lang['ampy.dataReadInterrupt']);
|
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
||||||
}
|
}
|
||||||
await this.#device_.sleep(100);
|
this.message(`Writing ${filename}...\n`);
|
||||||
}
|
this.message(this.getProgressMessage('', 0));
|
||||||
}
|
await this.exec(`file = open('${filename}', 'wb')`, timeout);
|
||||||
|
let buffer = null;
|
||||||
async interrupt(timeout = 1000) {
|
if (data.constructor === String) {
|
||||||
for (let i = 0; i < 5; i++) {
|
buffer = this.#device_.encode(data);
|
||||||
// 中断两次
|
} else if (data.constructor === ArrayBuffer) {
|
||||||
await this.#device_.sendBuffer([0x0D, 0x03]);
|
buffer = new Uint8Array(data);
|
||||||
await this.#device_.sleep(100);
|
} else {
|
||||||
await this.#device_.sendBuffer([0x03]);
|
buffer = data;
|
||||||
await this.#device_.sleep(100);
|
|
||||||
if (await this.readUntil('>>>', true, timeout)) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
const len = Math.ceil(buffer.length / 64);
|
||||||
return false;
|
if (!len) {
|
||||||
}
|
this.replaceMessage(-1, this.getProgressMessage('', 1));
|
||||||
|
|
||||||
async enterRawREPL(timeout = 1000) {
|
|
||||||
for (let i = 0; i < 5; i++) {
|
|
||||||
await this.#device_.sendBuffer([0x01]);
|
|
||||||
await this.#device_.sleep(100);
|
|
||||||
if (await this.readUntil('raw repl; ctrl-b to exit', true, timeout)) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
let sendedLength = 0;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
async exitRawREPL(timeout = 5000) {
|
|
||||||
await this.#device_.sendBuffer([0x02]);
|
|
||||||
await this.#device_.sleep(100);
|
|
||||||
let succeed = false;
|
|
||||||
if (await this.readUntil('>>>', true, timeout)) {
|
|
||||||
succeed = true;
|
|
||||||
}
|
|
||||||
return succeed;
|
|
||||||
}
|
|
||||||
|
|
||||||
async exitREPL(timeout = 5000) {
|
|
||||||
await this.#device_.sendBuffer([0x04]);
|
|
||||||
await this.#device_.sleep(100);
|
|
||||||
let succeed = false;
|
|
||||||
if (await this.readUntil('soft reboot', false, timeout)) {
|
|
||||||
succeed = true;
|
|
||||||
}
|
|
||||||
return succeed;
|
|
||||||
}
|
|
||||||
|
|
||||||
async exec(str, timeout = 5000) {
|
|
||||||
if (this.#writeBuffer_) {
|
|
||||||
const buffer = this.#device_.encode(str);
|
|
||||||
const len = Math.ceil(buffer.length / this.#dataLength_);
|
|
||||||
for (let i = 0; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
const start = i * this.#dataLength_;
|
const writeBuffer = buffer.slice(i * 64, Math.min((i + 1) * 64, buffer.length));
|
||||||
const end = Math.min((i + 1) * this.#dataLength_, buffer.length);
|
sendedLength += writeBuffer.length;
|
||||||
const writeBuffer = buffer.slice(start, end);
|
const percent = sendedLength / buffer.length;
|
||||||
await this.#device_.sendBuffer(writeBuffer);
|
this.replaceMessage(-1, this.getProgressMessage('', percent));
|
||||||
await this.#device_.sleep(10);
|
let writeStr = '';
|
||||||
}
|
for (let num of writeBuffer) {
|
||||||
} else {
|
let numStr = num.toString(16);
|
||||||
for (let i = 0; i < str.length / this.#dataLength_; i++) {
|
if (numStr.length === 1) {
|
||||||
const start = i * this.#dataLength_;
|
numStr = '0' + numStr;
|
||||||
const end = Math.min((i + 1) * this.#dataLength_, str.length);
|
}
|
||||||
let data = str.substring(start, end);
|
writeStr += '\\x' + numStr;
|
||||||
await this.#device_.sendString(data);
|
|
||||||
await this.#device_.sleep(10);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await this.#device_.sendBuffer([0x04]);
|
|
||||||
return await this.follow(timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
async follow(timeout = 1000) {
|
|
||||||
let data = await this.readUntil('\x04', true, timeout);
|
|
||||||
if (data.length < 1) {
|
|
||||||
throw new Error(Msg.Lang['ampy.waitingFirstEOFTimeout']);
|
|
||||||
}
|
|
||||||
let start = data.toLowerCase().lastIndexOf('ok');
|
|
||||||
if (start === -1) {
|
|
||||||
start = 0;
|
|
||||||
} else {
|
|
||||||
start += 2;
|
|
||||||
}
|
|
||||||
data = data.substring(start, data.length - 1);
|
|
||||||
let dataError = await this.readUntil('\x04', true, timeout);
|
|
||||||
if (dataError.length < 1) {
|
|
||||||
throw new Error(Msg.Lang['ampy.secondEOFTimeout']);
|
|
||||||
}
|
|
||||||
dataError = dataError.substring(0, dataError.length - 1);
|
|
||||||
return { data, dataError };
|
|
||||||
}
|
|
||||||
|
|
||||||
async enter() {
|
|
||||||
if (this.isActive()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.#active_ = true;
|
|
||||||
await this.#device_.open(115200);
|
|
||||||
await this.#device_.sleep(500);
|
|
||||||
await this.#device_.sendBuffer([0x02]);
|
|
||||||
if (!await this.interrupt()) {
|
|
||||||
throw new Error(Msg.Lang['ampy.interruptFailed']);
|
|
||||||
}
|
|
||||||
if (!await this.enterRawREPL()) {
|
|
||||||
throw new Error(Msg.Lang['ampy.enterRawREPLFailed']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async exit() {
|
|
||||||
if (!this.isActive()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!await this.exitRawREPL()) {
|
|
||||||
throw new Error(Msg.Lang['ampy.exitRawREPLFailed']);
|
|
||||||
}
|
|
||||||
/*if (!await this.exitREPL()) {
|
|
||||||
throw new Error(Msg.Lang['ampy.exitREPLFailed']);
|
|
||||||
}*/
|
|
||||||
await this.#device_.close();
|
|
||||||
this.#active_ = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
async get(filename, encoding = 'utf8', timeout = 5000) {
|
|
||||||
if (!this.isActive()) {
|
|
||||||
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
|
||||||
}
|
|
||||||
const code = Mustache.render(AmpyExt.GET, {
|
|
||||||
path: filename
|
|
||||||
});
|
|
||||||
const { data, dataError } = await this.exec(code, timeout);
|
|
||||||
if (dataError) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
if (encoding === 'utf8') {
|
|
||||||
return this.#device_.decode(this.unhexlify(data));
|
|
||||||
} else {
|
|
||||||
return this.unhexlify(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async put(filename, data, timeout = 5000) {
|
|
||||||
if (!this.isActive()) {
|
|
||||||
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
|
||||||
}
|
|
||||||
this.message(`Writing ${filename}...\n`);
|
|
||||||
this.message(this.getProgressMessage('', 0));
|
|
||||||
await this.exec(`file = open('${filename}', 'wb')`, timeout);
|
|
||||||
let buffer = null;
|
|
||||||
if (data.constructor === String) {
|
|
||||||
buffer = this.#device_.encode(data);
|
|
||||||
} else if (data.constructor === ArrayBuffer) {
|
|
||||||
buffer = new Uint8Array(data);
|
|
||||||
} else {
|
|
||||||
buffer = data;
|
|
||||||
}
|
|
||||||
const len = Math.ceil(buffer.length / 64);
|
|
||||||
if (!len) {
|
|
||||||
this.replaceMessage(-1, this.getProgressMessage('', 1));
|
|
||||||
}
|
|
||||||
let sendedLength = 0;
|
|
||||||
for (let i = 0; i < len; i++) {
|
|
||||||
const writeBuffer = buffer.slice(i * 64, Math.min((i + 1) * 64, buffer.length));
|
|
||||||
sendedLength += writeBuffer.length;
|
|
||||||
const percent = sendedLength / buffer.length;
|
|
||||||
this.replaceMessage(-1, this.getProgressMessage('', percent));
|
|
||||||
let writeStr = '';
|
|
||||||
for (let num of writeBuffer) {
|
|
||||||
let numStr = num.toString(16);
|
|
||||||
if (numStr.length === 1) {
|
|
||||||
numStr = '0' + numStr;
|
|
||||||
}
|
}
|
||||||
writeStr += '\\x' + numStr;
|
await this.exec(`file.write(b'${writeStr}')`, timeout);
|
||||||
}
|
}
|
||||||
await this.exec(`file.write(b'${writeStr}')`, timeout);
|
await this.exec('file.close()', timeout);
|
||||||
|
this.message('\n');
|
||||||
}
|
}
|
||||||
await this.exec('file.close()', timeout);
|
|
||||||
this.message('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
async ls(directory = '/', longFormat = true, recursive = false, timeout = 5000) {
|
async ls(directory = '/', longFormat = true, recursive = false, timeout = 5000) {
|
||||||
if (!this.isActive()) {
|
if (!this.isActive()) {
|
||||||
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
||||||
|
}
|
||||||
|
let code = '';
|
||||||
|
if (longFormat) {
|
||||||
|
code = Mustache.render(AmpyExt.LS_LONG_FORMAT, {
|
||||||
|
path: directory
|
||||||
|
});
|
||||||
|
} else if (recursive) {
|
||||||
|
code = Mustache.render(AmpyExt.LS_RECURSIVE, {
|
||||||
|
path: directory
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
code = Mustache.render(AmpyExt.LS, {
|
||||||
|
path: directory
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const { data, dataError } = await this.exec(code, timeout);
|
||||||
|
if (dataError) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return JSON.parse(data.replaceAll('\'', '\"'));
|
||||||
}
|
}
|
||||||
let code = '';
|
|
||||||
if (longFormat) {
|
async mkdir(directory, timeout = 5000) {
|
||||||
code = Mustache.render(AmpyExt.LS_LONG_FORMAT, {
|
if (!this.isActive()) {
|
||||||
|
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
||||||
|
}
|
||||||
|
const code = Mustache.render(AmpyExt.MKDIR, {
|
||||||
path: directory
|
path: directory
|
||||||
});
|
});
|
||||||
} else if (recursive) {
|
const { dataError } = await this.exec(code, timeout);
|
||||||
code = Mustache.render(AmpyExt.LS_RECURSIVE, {
|
return !dataError;
|
||||||
|
}
|
||||||
|
|
||||||
|
async mkfile(file, timeout = 5000) {
|
||||||
|
if (!this.isActive()) {
|
||||||
|
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
||||||
|
}
|
||||||
|
const code = Mustache.render(AmpyExt.MKFILE, {
|
||||||
|
path: file
|
||||||
|
});
|
||||||
|
const { dataError } = await this.exec(code, timeout);
|
||||||
|
return !dataError;
|
||||||
|
}
|
||||||
|
|
||||||
|
async rename(oldname, newname, timeout = 5000) {
|
||||||
|
if (!this.isActive()) {
|
||||||
|
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
||||||
|
}
|
||||||
|
const code = Mustache.render(AmpyExt.RENAME, {
|
||||||
|
oldPath: oldname,
|
||||||
|
newPath: newname
|
||||||
|
});
|
||||||
|
const { dataError } = await this.exec(code, timeout);
|
||||||
|
return !dataError;
|
||||||
|
}
|
||||||
|
|
||||||
|
async rm(filename, timeout = 5000) {
|
||||||
|
if (!this.isActive()) {
|
||||||
|
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
||||||
|
}
|
||||||
|
const code = Mustache.render(AmpyExt.RM, {
|
||||||
|
path: filename
|
||||||
|
});
|
||||||
|
await this.exec(code);
|
||||||
|
const { dataError } = await this.exec(code, timeout);
|
||||||
|
return !dataError;
|
||||||
|
}
|
||||||
|
|
||||||
|
async rmdir(directory, timeout = 5000) {
|
||||||
|
if (!this.isActive()) {
|
||||||
|
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
||||||
|
}
|
||||||
|
const code = Mustache.render(AmpyExt.RMDIR, {
|
||||||
path: directory
|
path: directory
|
||||||
});
|
});
|
||||||
} else {
|
const { dataError } = await this.exec(code, timeout);
|
||||||
code = Mustache.render(AmpyExt.LS, {
|
return !dataError;
|
||||||
path: directory
|
}
|
||||||
|
|
||||||
|
async cpdir(oldname, newname, timeout = 5000) {
|
||||||
|
if (!this.isActive()) {
|
||||||
|
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
||||||
|
}
|
||||||
|
const code = Mustache.render(AmpyExt.CPDIR, {
|
||||||
|
oldPath: oldname,
|
||||||
|
newPath: newname
|
||||||
});
|
});
|
||||||
|
const { data, dataError } = await this.exec(code, timeout);
|
||||||
|
console.log(data, dataError)
|
||||||
|
return !dataError;
|
||||||
}
|
}
|
||||||
const { data, dataError } = await this.exec(code, timeout);
|
|
||||||
if (dataError) {
|
async cpfile(oldname, newname, timeout = 5000) {
|
||||||
return [];
|
if (!this.isActive()) {
|
||||||
|
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
||||||
|
}
|
||||||
|
const code = Mustache.render(AmpyExt.CPFILE, {
|
||||||
|
oldPath: oldname,
|
||||||
|
newPath: newname
|
||||||
|
});
|
||||||
|
const { dataError } = await this.exec(code, timeout);
|
||||||
|
return !dataError;
|
||||||
|
}
|
||||||
|
|
||||||
|
async cwd(timeout = 5000) {
|
||||||
|
if (!this.isActive()) {
|
||||||
|
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
||||||
|
}
|
||||||
|
const code = Mustache.render(AmpyExt.CWD, {});
|
||||||
|
const { data, dataError } = await this.exec(code, timeout);
|
||||||
|
if (dataError) {
|
||||||
|
return '/';
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
getDevice() {
|
||||||
|
return this.#device_;
|
||||||
|
}
|
||||||
|
|
||||||
|
async dispose() {
|
||||||
|
this.#active_ = false;
|
||||||
|
if (this.#device_) {
|
||||||
|
await this.#device_.dispose();
|
||||||
|
this.#device_ = null;
|
||||||
|
}
|
||||||
|
if (this.#events_) {
|
||||||
|
this.#events_.reset();
|
||||||
|
this.#events_ = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return JSON.parse(data.replaceAll('\'', '\"'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async mkdir(directory, timeout = 5000) {
|
Web.Ampy = AmpyExt;
|
||||||
if (!this.isActive()) {
|
|
||||||
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
|
||||||
}
|
|
||||||
const code = Mustache.render(AmpyExt.MKDIR, {
|
|
||||||
path: directory
|
|
||||||
});
|
|
||||||
const { dataError } = await this.exec(code, timeout);
|
|
||||||
return !dataError;
|
|
||||||
}
|
|
||||||
|
|
||||||
async mkfile(file, timeout = 5000) {
|
|
||||||
if (!this.isActive()) {
|
|
||||||
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
|
||||||
}
|
|
||||||
const code = Mustache.render(AmpyExt.MKFILE, {
|
|
||||||
path: file
|
|
||||||
});
|
|
||||||
const { dataError } = await this.exec(code, timeout);
|
|
||||||
return !dataError;
|
|
||||||
}
|
|
||||||
|
|
||||||
async rename(oldname, newname, timeout = 5000) {
|
|
||||||
if (!this.isActive()) {
|
|
||||||
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
|
||||||
}
|
|
||||||
const code = Mustache.render(AmpyExt.RENAME, {
|
|
||||||
oldPath: oldname,
|
|
||||||
newPath: newname
|
|
||||||
});
|
|
||||||
const { dataError } = await this.exec(code, timeout);
|
|
||||||
return !dataError;
|
|
||||||
}
|
|
||||||
|
|
||||||
async rm(filename, timeout = 5000) {
|
|
||||||
if (!this.isActive()) {
|
|
||||||
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
|
||||||
}
|
|
||||||
const code = Mustache.render(AmpyExt.RM, {
|
|
||||||
path: filename
|
|
||||||
});
|
|
||||||
await this.exec(code);
|
|
||||||
const { dataError } = await this.exec(code, timeout);
|
|
||||||
return !dataError;
|
|
||||||
}
|
|
||||||
|
|
||||||
async rmdir(directory, timeout = 5000) {
|
|
||||||
if (!this.isActive()) {
|
|
||||||
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
|
||||||
}
|
|
||||||
const code = Mustache.render(AmpyExt.RMDIR, {
|
|
||||||
path: directory
|
|
||||||
});
|
|
||||||
const { dataError } = await this.exec(code, timeout);
|
|
||||||
return !dataError;
|
|
||||||
}
|
|
||||||
|
|
||||||
async cpdir(oldname, newname, timeout = 5000) {
|
|
||||||
if (!this.isActive()) {
|
|
||||||
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
|
||||||
}
|
|
||||||
const code = Mustache.render(AmpyExt.CPDIR, {
|
|
||||||
oldPath: oldname,
|
|
||||||
newPath: newname
|
|
||||||
});
|
|
||||||
const { data, dataError } = await this.exec(code, timeout);
|
|
||||||
console.log(data, dataError)
|
|
||||||
return !dataError;
|
|
||||||
}
|
|
||||||
|
|
||||||
async cpfile(oldname, newname, timeout = 5000) {
|
|
||||||
if (!this.isActive()) {
|
|
||||||
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
|
||||||
}
|
|
||||||
const code = Mustache.render(AmpyExt.CPFILE, {
|
|
||||||
oldPath: oldname,
|
|
||||||
newPath: newname
|
|
||||||
});
|
|
||||||
const { dataError } = await this.exec(code, timeout);
|
|
||||||
return !dataError;
|
|
||||||
}
|
|
||||||
|
|
||||||
async cwd(timeout = 5000) {
|
|
||||||
if (!this.isActive()) {
|
|
||||||
throw new Error(Msg.Lang['ampy.portIsNotOpen']);
|
|
||||||
}
|
|
||||||
const code = Mustache.render(AmpyExt.CWD, {});
|
|
||||||
const { data, dataError } = await this.exec(code, timeout);
|
|
||||||
if (dataError) {
|
|
||||||
return '/';
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
getDevice() {
|
|
||||||
return this.#device_;
|
|
||||||
}
|
|
||||||
|
|
||||||
async dispose() {
|
|
||||||
this.#active_ = false;
|
|
||||||
await this.#device_.dispose();
|
|
||||||
this.#device_ = null;
|
|
||||||
this.#events_.reset();
|
|
||||||
this.#events_ = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Web.Ampy = AmpyExt;
|
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -1,186 +1,174 @@
|
|||||||
goog.loadJs('web', () => {
|
goog.loadJs('web', () => {
|
||||||
|
|
||||||
goog.require('path');
|
goog.require('path');
|
||||||
goog.require('Mixly.Config');
|
goog.require('Mixly.Config');
|
||||||
goog.require('Mixly.Env');
|
goog.require('Mixly.Env');
|
||||||
goog.require('Mixly.Msg');
|
goog.require('Mixly.Msg');
|
||||||
goog.require('Mixly.Registry');
|
goog.require('Mixly.Registry');
|
||||||
goog.require('Mixly.Serial');
|
goog.require('Mixly.Serial');
|
||||||
goog.require('Mixly.LayerExt');
|
goog.require('Mixly.LayerExt');
|
||||||
goog.require('Mixly.HTMLTemplate');
|
goog.require('Mixly.HTMLTemplate');
|
||||||
goog.require('Mixly.Web.SerialPort');
|
goog.require('Mixly.Web.SerialPort');
|
||||||
goog.require('Mixly.Web.USB');
|
goog.require('Mixly.Web.USB');
|
||||||
goog.require('Mixly.Web.USBMini');
|
goog.require('Mixly.Web.USBMini');
|
||||||
goog.require('Mixly.Web.HID');
|
goog.require('Mixly.Web.HID');
|
||||||
goog.provide('Mixly.Web.Serial');
|
goog.provide('Mixly.Web.Serial');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
Config,
|
Config,
|
||||||
Env,
|
Env,
|
||||||
Msg,
|
Msg,
|
||||||
Registry,
|
Registry,
|
||||||
Serial,
|
Serial,
|
||||||
LayerExt,
|
LayerExt,
|
||||||
HTMLTemplate,
|
HTMLTemplate,
|
||||||
Web
|
Web
|
||||||
} = Mixly;
|
} = Mixly;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
SerialPort,
|
SerialPort,
|
||||||
USB,
|
USB,
|
||||||
USBMini,
|
USBMini,
|
||||||
HID
|
HID
|
||||||
} = Web;
|
} = Web;
|
||||||
|
|
||||||
const { BOARD } = Config;
|
const { BOARD } = Config;
|
||||||
|
|
||||||
const platform = goog.platform();
|
const platform = goog.platform();
|
||||||
const fullPlatform = goog.fullPlatform();
|
const fullPlatform = goog.fullPlatform();
|
||||||
|
|
||||||
|
|
||||||
class WebSerial extends Serial {
|
class WebSerial extends Serial {
|
||||||
static {
|
static {
|
||||||
this.devicesRegistry = new Registry();
|
this.devicesRegistry = new Registry();
|
||||||
this.type = Serial.type;
|
this.type = Serial.type;
|
||||||
this.DEVICES_SELECT_LAYER = new HTMLTemplate(
|
this.DEVICES_SELECT_LAYER = new HTMLTemplate(
|
||||||
goog.readFileSync(path.join(Env.templatePath, 'html/devices-select-layer.html'))
|
goog.readFileSync(path.join(Env.templatePath, 'html/devices-select-layer.html'))
|
||||||
);
|
);
|
||||||
|
|
||||||
this.getConfig = function () {
|
this.getConfig = function () {
|
||||||
return Serial.getConfig();
|
return Serial.getConfig();
|
||||||
}
|
|
||||||
|
|
||||||
this.getSelectedPortName = function () {
|
|
||||||
return Serial.getSelectedPortName();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.getCurrentPortsName = function () {
|
|
||||||
return Serial.getCurrentPortsName();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.refreshPorts = function () {
|
|
||||||
Serial.refreshPorts();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.requestPort = function () {
|
|
||||||
if (this.devicesRegistry.length() < 1) {
|
|
||||||
throw Error('can not find any device handler');
|
|
||||||
} else if (this.devicesRegistry.length() === 1) {
|
|
||||||
const keys = this.devicesRegistry.keys();
|
|
||||||
return this.devicesRegistry.getItem(keys[0]).requestPort();
|
|
||||||
}
|
}
|
||||||
const msg = {
|
|
||||||
serialMsg: Msg.Lang['layer.devices.serial'],
|
this.getSelectedPortName = function () {
|
||||||
serialStatus: this.devicesRegistry.hasKey('serial') ? '' : 'disabled',
|
return Serial.getSelectedPortName();
|
||||||
hidMsg: Msg.Lang['layer.devices.hid'],
|
}
|
||||||
hidStatus: this.devicesRegistry.hasKey('hid') ? '' : 'disabled',
|
|
||||||
usbMsg: Msg.Lang['layer.devices.usb'],
|
this.getCurrentPortsName = function () {
|
||||||
usbStatus: (
|
return Serial.getCurrentPortsName();
|
||||||
this.devicesRegistry.hasKey('usb') || this.devicesRegistry.hasKey('usbmini')
|
}
|
||||||
) ? '' : 'disabled'
|
|
||||||
};
|
this.refreshPorts = function () {
|
||||||
return new Promise((resolve, reject) => {
|
Serial.refreshPorts();
|
||||||
let selected = false;
|
}
|
||||||
const layerNum = LayerExt.open({
|
|
||||||
title: [Msg.Lang['layer.devices.select'], '36px'],
|
this.requestPort = function () {
|
||||||
area: ['400px', '150px'],
|
if (this.devicesRegistry.length() < 1) {
|
||||||
max: false,
|
throw Error('can not find any device handler');
|
||||||
min: false,
|
} else if (this.devicesRegistry.length() === 1) {
|
||||||
content: this.DEVICES_SELECT_LAYER.render(msg),
|
const keys = this.devicesRegistry.keys();
|
||||||
shade: LayerExt.SHADE_ALL,
|
return this.devicesRegistry.getItem(keys[0]).requestPort();
|
||||||
resize: false,
|
}
|
||||||
success: function (layero, index) {
|
const msg = {
|
||||||
$(layero).on('click', 'button', (event) => {
|
serialMsg: Msg.Lang['layer.devices.serial'],
|
||||||
selected = true;
|
serialStatus: this.devicesRegistry.hasKey('serial') ? '' : 'disabled',
|
||||||
layer.close(layerNum);
|
hidMsg: Msg.Lang['layer.devices.hid'],
|
||||||
const $btn = $(event.currentTarget);
|
hidStatus: this.devicesRegistry.hasKey('hid') ? '' : 'disabled',
|
||||||
let mId = $btn.attr('m-id');
|
usbMsg: Msg.Lang['layer.devices.usb'],
|
||||||
if (mId === 'usb' && WebSerial.devicesRegistry.hasKey('usbmini')) {
|
usbStatus: (
|
||||||
mId = 'usbmini';
|
this.devicesRegistry.hasKey('usb') || this.devicesRegistry.hasKey('usbmini')
|
||||||
|
) ? '' : 'disabled'
|
||||||
|
};
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let selected = false;
|
||||||
|
const layerNum = LayerExt.open({
|
||||||
|
title: [Msg.Lang['layer.devices.select'], '36px'],
|
||||||
|
area: ['400px', '150px'],
|
||||||
|
max: false,
|
||||||
|
min: false,
|
||||||
|
content: this.DEVICES_SELECT_LAYER.render(msg),
|
||||||
|
shade: LayerExt.SHADE_ALL,
|
||||||
|
resize: false,
|
||||||
|
success: function (layero, index) {
|
||||||
|
$(layero).on('click', 'button', (event) => {
|
||||||
|
selected = true;
|
||||||
|
layer.close(layerNum);
|
||||||
|
const $btn = $(event.currentTarget);
|
||||||
|
let mId = $btn.attr('m-id');
|
||||||
|
if (mId === 'usb' && WebSerial.devicesRegistry.hasKey('usbmini')) {
|
||||||
|
mId = 'usbmini';
|
||||||
|
}
|
||||||
|
const Device = WebSerial.devicesRegistry.getItem(mId);
|
||||||
|
Device.requestPort().then(resolve).catch(reject);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
end: function () {
|
||||||
|
if (!selected) {
|
||||||
|
reject('user not select any device');
|
||||||
}
|
}
|
||||||
const Device = WebSerial.devicesRegistry.getItem(mId);
|
$(`#layui-layer-shade${layerNum}`).remove();
|
||||||
Device.requestPort().then(resolve).catch(reject);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
end: function () {
|
|
||||||
if (!selected) {
|
|
||||||
reject('user not select any device');
|
|
||||||
}
|
}
|
||||||
$(`#layui-layer-shade${layerNum}`).remove();
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.getHandler = function (device) {
|
|
||||||
if (device.constructor.name === 'SerialPort') {
|
|
||||||
return SerialPort;
|
|
||||||
} else if (device.constructor.name === 'HIDDevice') {
|
|
||||||
return HID;
|
|
||||||
} else if (device.constructor.name === 'USBDevice') {
|
|
||||||
if (this.devicesRegistry.hasKey('usbmini')) {
|
|
||||||
return USBMini;
|
|
||||||
} else {
|
|
||||||
return USB;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.getPort = function (name) {
|
this.getHandler = function (device) {
|
||||||
return Serial.nameToPortRegistry.getItem(name);
|
if (device.constructor.name === 'SerialPort') {
|
||||||
}
|
return SerialPort;
|
||||||
|
} else if (device.constructor.name === 'HIDDevice') {
|
||||||
this.addPort = function (device) {
|
return HID;
|
||||||
const handler = this.getHandler(device);
|
} else if (device.constructor.name === 'USBDevice') {
|
||||||
if (!handler) {
|
if (this.devicesRegistry.hasKey('usbmini')) {
|
||||||
return;
|
return USBMini;
|
||||||
}
|
} else {
|
||||||
handler.addPort(device);
|
return USB;
|
||||||
}
|
|
||||||
|
|
||||||
this.removePort = function (device) {
|
|
||||||
const handler = this.getHandler(device);
|
|
||||||
if (!handler) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
handler.removePort(device);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.addEventsListener = function () {}
|
|
||||||
|
|
||||||
this.init = function () {
|
|
||||||
if (Env.hasSocketServer) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (platform === 'win32' && fullPlatform !== 'win10') {
|
|
||||||
if (BOARD?.web?.devices?.hid) {
|
|
||||||
this.devicesRegistry.register('hid', HID);
|
|
||||||
HID.init();
|
|
||||||
}
|
|
||||||
if (BOARD?.web?.devices?.serial) {
|
|
||||||
this.devicesRegistry.register('serial', SerialPort);
|
|
||||||
SerialPort.init();
|
|
||||||
}
|
|
||||||
if (BOARD?.web?.devices?.usb) {
|
|
||||||
if (['BBC micro:bit', 'Mithon CC'].includes(BOARD.boardType)) {
|
|
||||||
this.devicesRegistry.register('usb', USB);
|
|
||||||
USB.init();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (platform === 'mobile') {
|
return null;
|
||||||
if (['BBC micro:bit', 'Mithon CC'].includes(BOARD.boardType)) {
|
}
|
||||||
this.devicesRegistry.register('usb', USB);
|
|
||||||
USB.init();
|
this.getPort = function (name) {
|
||||||
} else {
|
return Serial.nameToPortRegistry.getItem(name);
|
||||||
this.devicesRegistry.register('usbmini', USBMini);
|
}
|
||||||
USBMini.init();
|
|
||||||
|
this.addPort = function (device) {
|
||||||
|
const handler = this.getHandler(device);
|
||||||
|
if (!handler) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
handler.addPort(device);
|
||||||
if (BOARD?.web?.devices?.serial) {
|
}
|
||||||
this.devicesRegistry.register('serial', SerialPort);
|
|
||||||
SerialPort.init();
|
this.removePort = function (device) {
|
||||||
} else if (BOARD?.web?.devices?.usb) {
|
const handler = this.getHandler(device);
|
||||||
|
if (!handler) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handler.removePort(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.addEventsListener = function () { }
|
||||||
|
|
||||||
|
this.init = function () {
|
||||||
|
// if (Env.hasSocketServer) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
if (platform === 'win32' && fullPlatform !== 'win10') {
|
||||||
|
if (BOARD?.web?.devices?.hid) {
|
||||||
|
this.devicesRegistry.register('hid', HID);
|
||||||
|
HID.init();
|
||||||
|
}
|
||||||
|
if (BOARD?.web?.devices?.serial) {
|
||||||
|
this.devicesRegistry.register('serial', SerialPort);
|
||||||
|
SerialPort.init();
|
||||||
|
}
|
||||||
|
if (BOARD?.web?.devices?.usb) {
|
||||||
|
if (['BBC micro:bit', 'Mithon CC'].includes(BOARD.boardType)) {
|
||||||
|
this.devicesRegistry.register('usb', USB);
|
||||||
|
USB.init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (platform === 'mobile') {
|
||||||
if (['BBC micro:bit', 'Mithon CC'].includes(BOARD.boardType)) {
|
if (['BBC micro:bit', 'Mithon CC'].includes(BOARD.boardType)) {
|
||||||
this.devicesRegistry.register('usb', USB);
|
this.devicesRegistry.register('usb', USB);
|
||||||
USB.init();
|
USB.init();
|
||||||
@@ -188,28 +176,40 @@ class WebSerial extends Serial {
|
|||||||
this.devicesRegistry.register('usbmini', USBMini);
|
this.devicesRegistry.register('usbmini', USBMini);
|
||||||
USBMini.init();
|
USBMini.init();
|
||||||
}
|
}
|
||||||
} else if (BOARD?.web?.devices?.hid) {
|
} else {
|
||||||
this.devicesRegistry.register('hid', HID);
|
if (BOARD?.web?.devices?.serial) {
|
||||||
HID.init();
|
this.devicesRegistry.register('serial', SerialPort);
|
||||||
|
SerialPort.init();
|
||||||
|
} else if (BOARD?.web?.devices?.usb) {
|
||||||
|
if (['BBC micro:bit', 'Mithon CC'].includes(BOARD.boardType)) {
|
||||||
|
this.devicesRegistry.register('usb', USB);
|
||||||
|
USB.init();
|
||||||
|
} else {
|
||||||
|
this.devicesRegistry.register('usbmini', USBMini);
|
||||||
|
USBMini.init();
|
||||||
|
}
|
||||||
|
} else if (BOARD?.web?.devices?.hid) {
|
||||||
|
this.devicesRegistry.register('hid', HID);
|
||||||
|
HID.init();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.init();
|
constructor(port) {
|
||||||
}
|
super(port);
|
||||||
|
const device = WebSerial.getPort(port);
|
||||||
constructor(port) {
|
const handler = WebSerial.getHandler(device);
|
||||||
super(port);
|
if (!handler) {
|
||||||
const device = WebSerial.getPort(port);
|
return;
|
||||||
const handler = WebSerial.getHandler(device);
|
}
|
||||||
if (!handler) {
|
return new handler(port);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
return new handler(port);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Web.Serial = WebSerial;
|
Web.Serial = WebSerial;
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -129,6 +129,7 @@
|
|||||||
{
|
{
|
||||||
"path": "/web-socket/socket.js",
|
"path": "/web-socket/socket.js",
|
||||||
"require": [
|
"require": [
|
||||||
|
"io",
|
||||||
"Mixly.Env",
|
"Mixly.Env",
|
||||||
"Mixly.Config",
|
"Mixly.Config",
|
||||||
"Mixly.MJson",
|
"Mixly.MJson",
|
||||||
@@ -140,4 +141,4 @@
|
|||||||
"Mixly.WebSocket.Socket"
|
"Mixly.WebSocket.Socket"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -1,244 +1,253 @@
|
|||||||
(() => {
|
(() => {
|
||||||
|
|
||||||
goog.require('Mixly.Env');
|
goog.require('Mixly.Env');
|
||||||
goog.require('Mixly.Config');
|
goog.require('Mixly.Config');
|
||||||
goog.require('Mixly.MJson');
|
goog.require('Mixly.MJson');
|
||||||
goog.require('Mixly.WebSocket');
|
goog.require('Mixly.WebSocket');
|
||||||
goog.require('Mixly.LayerExt');
|
goog.require('Mixly.LayerExt');
|
||||||
goog.require('Mixly.Command');
|
goog.require('Mixly.Command');
|
||||||
goog.provide('Mixly.WebSocket.Socket');
|
goog.provide('Mixly.WebSocket.Socket');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
Env,
|
Env,
|
||||||
Config,
|
Config,
|
||||||
MJson,
|
MJson,
|
||||||
LayerExt,
|
LayerExt,
|
||||||
Command
|
Command
|
||||||
} = Mixly;
|
} = Mixly;
|
||||||
|
|
||||||
const { SOFTWARE } = Config;
|
const { SOFTWARE } = Config;
|
||||||
|
|
||||||
const { Socket } = Mixly.WebSocket;
|
const { Socket } = Mixly.WebSocket;
|
||||||
|
|
||||||
Socket.obj = null;
|
Socket.obj = null;
|
||||||
Socket.url = 'ws://127.0.0.1/socket';
|
Socket.url = '';
|
||||||
Socket.jsonArr = [];
|
Socket.jsonArr = [];
|
||||||
Socket.connected = false;
|
Socket.connected = false;
|
||||||
Socket.initFunc = null;
|
Socket.initFunc = null;
|
||||||
Socket.debug = SOFTWARE.debug;
|
Socket.debug = SOFTWARE.debug;
|
||||||
let { hostname, protocol, port } = window.location;
|
Socket.disconnectTimes = 0;
|
||||||
if (protocol === 'http:') {
|
Socket.updating = false;
|
||||||
Socket.protocol = 'ws:';
|
|
||||||
} else {
|
|
||||||
Socket.protocol = 'wss:';
|
|
||||||
}
|
|
||||||
if (port) {
|
|
||||||
port = ':' + port;
|
|
||||||
}
|
|
||||||
Socket.url = Socket.protocol + '//' + hostname + port + '/socket';
|
|
||||||
Socket.IPAddress = hostname;
|
|
||||||
Socket.disconnectTimes = 0;
|
|
||||||
Socket.updating = false;
|
|
||||||
|
|
||||||
|
// 构建 Socket.io 连接 URL (和后端统一使用 Socket.io)
|
||||||
let lockReconnect = false; // 避免重复连接
|
let { hostname, protocol, port } = window.location;
|
||||||
let timeoutFlag = true;
|
if (protocol === 'http:') {
|
||||||
let timeoutSet = null;
|
Socket.protocol = 'ws:';
|
||||||
let reconectNum = 0;
|
} else {
|
||||||
const timeout = 5000; // 超时重连间隔
|
Socket.protocol = 'wss:';
|
||||||
|
|
||||||
function reconnect () {
|
|
||||||
if (lockReconnect) return;
|
|
||||||
lockReconnect = true;
|
|
||||||
// 没连接上会一直重连,设置延迟避免请求过多
|
|
||||||
setTimeout(function () {
|
|
||||||
timeoutFlag = true;
|
|
||||||
Socket.init();
|
|
||||||
console.info(`正在重连第${reconectNum + 1}次`);
|
|
||||||
reconectNum++;
|
|
||||||
lockReconnect = false;
|
|
||||||
}, timeout); // 这里设置重连间隔(ms)
|
|
||||||
}
|
|
||||||
|
|
||||||
//心跳检测
|
|
||||||
const heartCheck = {
|
|
||||||
timeout, // 毫秒
|
|
||||||
timeoutObj: null,
|
|
||||||
serverTimeoutObj: null,
|
|
||||||
reset: function () {
|
|
||||||
clearInterval(this.timeoutObj);
|
|
||||||
clearTimeout(this.serverTimeoutObj);
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
start: function () {
|
|
||||||
const self = this;
|
|
||||||
let count = 0;
|
|
||||||
let WS = Socket;
|
|
||||||
this.timeoutObj = setInterval(() => {
|
|
||||||
if (count < 3) {
|
|
||||||
if (WS.obj.readyState === 1) {
|
|
||||||
WS.obj.send('HeartBeat');
|
|
||||||
console.info(`HeartBeat第${count + 1}次`);
|
|
||||||
}
|
|
||||||
count++;
|
|
||||||
} else {
|
|
||||||
clearInterval(this.timeoutObj);
|
|
||||||
count = 0;
|
|
||||||
if (WS.obj.readyState === 0 && WS.obj.readyState === 1) {
|
|
||||||
WS.obj.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, self.timeout);
|
|
||||||
}
|
}
|
||||||
}
|
Socket.url = Socket.protocol + '//' + hostname + (port ? ':' + port : '');
|
||||||
|
Socket.IPAddress = hostname;
|
||||||
|
|
||||||
Socket.init = (onopenFunc = (data) => {}, doFunc = () => {}) => {
|
let lockReconnect = false;
|
||||||
if (Socket.connected) {
|
let timeoutFlag = true;
|
||||||
if (Socket.initFunc) {
|
let timeoutSet = null;
|
||||||
Socket.initFunc();
|
let reconectNum = 0;
|
||||||
Socket.initFunc = null;
|
const timeout = 5000;
|
||||||
}
|
|
||||||
doFunc();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
timeoutSet = setTimeout(() => {
|
function reconnect() {
|
||||||
if (timeoutFlag && reconectNum < 3) {
|
if (lockReconnect) return;
|
||||||
console.info(`重连`);
|
lockReconnect = true;
|
||||||
reconectNum++;
|
setTimeout(function () {
|
||||||
|
timeoutFlag = true;
|
||||||
Socket.init();
|
Socket.init();
|
||||||
|
console.info(`正在重连第${reconectNum + 1}次`);
|
||||||
|
reconectNum++;
|
||||||
|
lockReconnect = false;
|
||||||
|
}, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 心跳检测
|
||||||
|
const heartCheck = {
|
||||||
|
timeout,
|
||||||
|
timeoutObj: null,
|
||||||
|
serverTimeoutObj: null,
|
||||||
|
reset: function () {
|
||||||
|
clearInterval(this.timeoutObj);
|
||||||
|
clearTimeout(this.serverTimeoutObj);
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
start: function () {
|
||||||
|
const self = this;
|
||||||
|
let count = 0;
|
||||||
|
this.timeoutObj = setInterval(() => {
|
||||||
|
if (count < 3) {
|
||||||
|
if (Socket.connected) {
|
||||||
|
// Socket.io 自带心跳,这里可以发送自定义心跳
|
||||||
|
console.info(`HeartBeat第${count + 1}次`);
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
} else {
|
||||||
|
clearInterval(this.timeoutObj);
|
||||||
|
count = 0;
|
||||||
|
if (Socket.obj && !Socket.connected) {
|
||||||
|
Socket.obj.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, self.timeout);
|
||||||
}
|
}
|
||||||
}, timeout);
|
}
|
||||||
|
|
||||||
let WS = Socket;
|
Socket.init = (onopenFunc = (data) => { }, doFunc = () => { }) => {
|
||||||
WS.obj = new WebSocket(WS.url);
|
if (Socket.connected) {
|
||||||
WS.obj.onopen = () => {
|
if (Socket.initFunc) {
|
||||||
console.log('已连接' + WS.url);
|
Socket.initFunc();
|
||||||
WS.connected = true;
|
Socket.initFunc = null;
|
||||||
Socket.initFunc = doFunc;
|
}
|
||||||
reconectNum = 0;
|
doFunc();
|
||||||
timeoutFlag = false;
|
return;
|
||||||
clearTimeout(timeoutSet);
|
|
||||||
heartCheck.reset().start();
|
|
||||||
onopenFunc(WS);
|
|
||||||
Socket.reload();
|
|
||||||
if (Socket.updating) {
|
|
||||||
Socket.updating = false;
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
WS.obj.onmessage = (event) => {
|
timeoutSet = setTimeout(() => {
|
||||||
heartCheck.reset().start();
|
if (timeoutFlag && reconectNum < 3) {
|
||||||
let command = Command.parse(event.data);
|
console.info(`重连`);
|
||||||
command = MJson.decode(command);
|
reconectNum++;
|
||||||
if (Socket.debug)
|
Socket.init();
|
||||||
console.log('receive -> ', event.data);
|
}
|
||||||
Command.run(command);
|
}, timeout);
|
||||||
};
|
|
||||||
|
|
||||||
WS.obj.onerror = (event) => {
|
// 使用 Socket.io 客户端连接(和后端统一)
|
||||||
console.log('WebSocket error: ', event);
|
Socket.obj = io(`${Socket.url}/all`, {
|
||||||
reconnect();
|
path: '/mixly-socket/',
|
||||||
};
|
reconnection: true,
|
||||||
|
reconnectionDelayMax: 10000,
|
||||||
|
transports: ['websocket']
|
||||||
|
});
|
||||||
|
|
||||||
WS.obj.onclose = (event) => {
|
Socket.obj.on('connect', () => {
|
||||||
WS.connected = false;
|
console.log('已连接' + Socket.url);
|
||||||
WS.disconnectTimes += 1;
|
Socket.connected = true;
|
||||||
if (WS.disconnectTimes > 255) {
|
Socket.initFunc = doFunc;
|
||||||
WS.disconnectTimes = 1;
|
reconectNum = 0;
|
||||||
}
|
|
||||||
console.log('已断开' + WS.url);
|
|
||||||
|
|
||||||
console.info(`关闭`, event.code);
|
|
||||||
if (event.code !== 1000) {
|
|
||||||
timeoutFlag = false;
|
timeoutFlag = false;
|
||||||
clearTimeout(timeoutSet);
|
clearTimeout(timeoutSet);
|
||||||
|
heartCheck.reset().start();
|
||||||
|
onopenFunc(Socket);
|
||||||
|
Socket.reload();
|
||||||
|
if (Socket.updating) {
|
||||||
|
Socket.updating = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Socket.io 消息接收
|
||||||
|
Socket.obj.onAny((eventName, ...args) => {
|
||||||
|
heartCheck.reset().start();
|
||||||
|
// 构造兼容原有 Command 格式的消息
|
||||||
|
const command = { event: eventName, data: args };
|
||||||
|
if (Socket.debug) {
|
||||||
|
console.log('receive -> ', eventName, args);
|
||||||
|
}
|
||||||
|
// 尝试使用原有 Command 系统处理
|
||||||
|
try {
|
||||||
|
Command.run(MJson.decode(command));
|
||||||
|
} catch (e) {
|
||||||
|
// 如果 Command 系统不能处理,忽略
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Socket.obj.on('connect_error', (error) => {
|
||||||
|
console.log('WebSocket error: ', error);
|
||||||
reconnect();
|
reconnect();
|
||||||
} else {
|
});
|
||||||
clearInterval(heartCheck.timeoutObj);
|
|
||||||
clearTimeout(heartCheck.serverTimeoutObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Socket.sendCommand = (command) => {
|
Socket.obj.on('disconnect', (reason) => {
|
||||||
let WS = Mixly.WebSocket.Socket;
|
Socket.connected = false;
|
||||||
if (!WS.connected) {
|
Socket.disconnectTimes += 1;
|
||||||
layer.msg('未连接' + WS.url, {time: 1000});
|
if (Socket.disconnectTimes > 255) {
|
||||||
return;
|
Socket.disconnectTimes = 1;
|
||||||
}
|
}
|
||||||
let commandStr = '';
|
console.log('已断开' + Socket.url);
|
||||||
|
console.info(`关闭`, reason);
|
||||||
try {
|
|
||||||
commandStr = JSON.stringify(MJson.encode(command));
|
|
||||||
if (Socket.debug)
|
|
||||||
console.log('send -> ', commandStr);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
WS.obj.send(commandStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
Socket.clickConnect = () => {
|
if (reason !== 'io client disconnect') {
|
||||||
if (Socket.connected) {
|
timeoutFlag = false;
|
||||||
Socket.disconnect();
|
clearTimeout(timeoutSet);
|
||||||
} else {
|
reconnect();
|
||||||
Socket.connect((WS) => {
|
} else {
|
||||||
layer.closeAll();
|
clearInterval(heartCheck.timeoutObj);
|
||||||
layer.msg(WS.url + '连接成功', { time: 1000 });
|
clearTimeout(heartCheck.serverTimeoutObj);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Socket.openLoadingBox = (title, successFunc = () => {}, endFunc = () => {}) => {
|
Socket.sendCommand = (command) => {
|
||||||
layer.open({
|
if (!Socket.connected) {
|
||||||
type: 1,
|
layer.msg('未连接' + Socket.url, { time: 1000 });
|
||||||
title: title,
|
return;
|
||||||
content: $('#mixly-loader-div'),
|
|
||||||
shade: LayerExt.SHADE_ALL,
|
|
||||||
closeBtn: 0,
|
|
||||||
success: function () {
|
|
||||||
$("#webusb-cancel").css("display","none");
|
|
||||||
$(".layui-layer-page").css("z-index", "198910151");
|
|
||||||
successFunc();
|
|
||||||
},
|
|
||||||
end: function () {
|
|
||||||
$("#mixly-loader-div").css("display", "none");
|
|
||||||
$(".layui-layer-shade").remove();
|
|
||||||
$("#webusb-cancel").css("display", "unset");
|
|
||||||
if (Socket.connected)
|
|
||||||
endFunc();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Socket.connect = (onopenFunc = (data) => {}, doFunc = () => {}) => {
|
try {
|
||||||
if (Socket.connected) {
|
const encodedCommand = MJson.encode(command);
|
||||||
doFunc();
|
if (Socket.debug) {
|
||||||
return;
|
console.log('send -> ', encodedCommand);
|
||||||
|
}
|
||||||
|
// 使用 Socket.io emit 发送命令
|
||||||
|
Socket.obj.emit('command', encodedCommand);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let title = '连接中...';
|
|
||||||
Socket.openLoadingBox(title, () => {
|
|
||||||
setTimeout(() => {
|
|
||||||
Socket.init(onopenFunc);
|
|
||||||
}, 1000);
|
|
||||||
}, doFunc);
|
|
||||||
}
|
|
||||||
|
|
||||||
Socket.disconnect = () => {
|
Socket.clickConnect = () => {
|
||||||
if (!Socket.connected)
|
if (Socket.connected) {
|
||||||
return;
|
Socket.disconnect();
|
||||||
let title = '断开中...';
|
} else {
|
||||||
Socket.openLoadingBox(title, () => {
|
Socket.connect((WS) => {
|
||||||
Socket.obj.close();
|
layer.closeAll();
|
||||||
});
|
layer.msg(WS.url + '连接成功', { time: 1000 });
|
||||||
}
|
});
|
||||||
|
}
|
||||||
Socket.reload = () => {
|
}
|
||||||
if (!Socket.updating && Socket.disconnectTimes) {
|
|
||||||
window.location.reload();
|
Socket.openLoadingBox = (title, successFunc = () => { }, endFunc = () => { }) => {
|
||||||
|
layer.open({
|
||||||
|
type: 1,
|
||||||
|
title: title,
|
||||||
|
content: $('#mixly-loader-div'),
|
||||||
|
shade: LayerExt.SHADE_ALL,
|
||||||
|
closeBtn: 0,
|
||||||
|
success: function () {
|
||||||
|
$("#webusb-cancel").css("display", "none");
|
||||||
|
$(".layui-layer-page").css("z-index", "198910151");
|
||||||
|
successFunc();
|
||||||
|
},
|
||||||
|
end: function () {
|
||||||
|
$("#mixly-loader-div").css("display", "none");
|
||||||
|
$(".layui-layer-shade").remove();
|
||||||
|
$("#webusb-cancel").css("display", "unset");
|
||||||
|
if (Socket.connected)
|
||||||
|
endFunc();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Socket.connect = (onopenFunc = (data) => { }, doFunc = () => { }) => {
|
||||||
|
if (Socket.connected) {
|
||||||
|
doFunc();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let title = '连接中...';
|
||||||
|
Socket.openLoadingBox(title, () => {
|
||||||
|
setTimeout(() => {
|
||||||
|
Socket.init(onopenFunc);
|
||||||
|
}, 1000);
|
||||||
|
}, doFunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
Socket.disconnect = () => {
|
||||||
|
if (!Socket.connected)
|
||||||
|
return;
|
||||||
|
let title = '断开中...';
|
||||||
|
Socket.openLoadingBox(title, () => {
|
||||||
|
Socket.obj.disconnect();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Socket.reload = () => {
|
||||||
|
if (!Socket.updating && Socket.disconnectTimes) {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ MString.tpl = (str, obj) => {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
for (let key in obj) {
|
for (let key in obj) {
|
||||||
let re = new RegExp(`{*${key}*}`, 'gim');
|
let re = new RegExp(`{${key}}`, 'gm');
|
||||||
str = str.replace(re, obj[key]);
|
str = str.replace(re, obj[key]);
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
|
|||||||
@@ -11,38 +11,60 @@ export default class ShellArduino extends Shell {
|
|||||||
async compile(config) {
|
async compile(config) {
|
||||||
let arduino = _.merge({}, ARDUINO);
|
let arduino = _.merge({}, ARDUINO);
|
||||||
arduino = _.merge(arduino, config);
|
arduino = _.merge(arduino, config);
|
||||||
const command = [
|
|
||||||
`"${arduino.path.cli}"`,
|
// 构建参数数组,避免 shell 解析引号问题
|
||||||
|
const args = [
|
||||||
'compile',
|
'compile',
|
||||||
'-b', arduino.key,
|
'-b', arduino.key,
|
||||||
'--config-file', `"${arduino.path.config}"`,
|
'--config-file', arduino.path.config,
|
||||||
'--verbose',
|
'--verbose'
|
||||||
'--libraries', `"${arduino.path.libraries.join('","')}"`,
|
];
|
||||||
'--build-path', `"${arduino.path.build}"`,
|
|
||||||
'--output-dir', `"${arduino.path.output}"`,
|
// 为每个 library 路径添加参数
|
||||||
`"${arduino.path.code}"`,
|
// 注意:config.json 中的路径是指向包含多个库的集合目录,所以必须用 --libraries
|
||||||
|
// 如果用 --library,arduino-cli 会尝试把该目录当作单个库处理,导致找不到头文件报错
|
||||||
|
for (const lib of arduino.path.libraries) {
|
||||||
|
args.push('--libraries', lib);
|
||||||
|
}
|
||||||
|
|
||||||
|
args.push(
|
||||||
|
'--build-path', arduino.path.build,
|
||||||
|
'--output-dir', arduino.path.output,
|
||||||
|
arduino.path.code,
|
||||||
'--no-color'
|
'--no-color'
|
||||||
].join(' ');
|
);
|
||||||
return this.execUntilClosed(command, { maxBuffer: 4096 * 1000000 });
|
|
||||||
|
return this.execFileUntilClosed(arduino.path.cli, args, { maxBuffer: 4096 * 1000000 });
|
||||||
}
|
}
|
||||||
|
|
||||||
async upload(config) {
|
async upload(config) {
|
||||||
let arduino = _.merge({}, ARDUINO);
|
let arduino = _.merge({}, ARDUINO);
|
||||||
arduino = _.merge(arduino, config);
|
arduino = _.merge(arduino, config);
|
||||||
const command = [
|
|
||||||
`"${arduino.path.cli}"`,
|
// 构建参数数组,避免 shell 解析引号问题
|
||||||
|
const args = [
|
||||||
'compile',
|
'compile',
|
||||||
'--upload',
|
'--upload',
|
||||||
'-p', arduino.port,
|
'-p', arduino.port,
|
||||||
'-b', arduino.key,
|
'-b', arduino.key,
|
||||||
'--config-file', `"${arduino.path.config}"`,
|
'--config-file', arduino.path.config,
|
||||||
'--verbose',
|
'--verbose'
|
||||||
'--libraries', `"${arduino.path.libraries.join('","')}"`,
|
];
|
||||||
'--build-path', `"${arduino.path.build}"`,
|
|
||||||
'--output-dir', `"${arduino.path.output}"`,
|
// 为每个 library 路径添加参数
|
||||||
`"${arduino.path.code}"`,
|
// 注意:config.json 中的路径是指向包含多个库的集合目录,所以必须用 --libraries
|
||||||
|
// 如果用 --library,arduino-cli 会尝试把该目录当作单个库处理,导致找不到头文件报错
|
||||||
|
for (const lib of arduino.path.libraries) {
|
||||||
|
args.push('--libraries', lib);
|
||||||
|
}
|
||||||
|
|
||||||
|
args.push(
|
||||||
|
'--build-path', arduino.path.build,
|
||||||
|
'--output-dir', arduino.path.output,
|
||||||
|
arduino.path.code,
|
||||||
'--no-color'
|
'--no-color'
|
||||||
].join(' ');
|
);
|
||||||
return this.execUntilClosed(command, { maxBuffer: 4096 * 1000000 });
|
|
||||||
|
return this.execFileUntilClosed(arduino.path.cli, args, { maxBuffer: 4096 * 1000000 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,22 +10,65 @@ export default class ShellMicroPython extends Shell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async burn(config) {
|
async burn(config) {
|
||||||
|
// 对系统命令(不含路径分隔符)不加引号,只对路径加引号
|
||||||
|
const pythonCmd = PYTHON.path.cli.includes('/') || PYTHON.path.cli.includes('\\')
|
||||||
|
? `"${PYTHON.path.cli}"`
|
||||||
|
: PYTHON.path.cli;
|
||||||
|
|
||||||
const info = {
|
const info = {
|
||||||
indexPath: path.resolve(CLIENT_PATH, config.boardDirPath),
|
indexPath: path.resolve(CLIENT_PATH, config.boardDirPath),
|
||||||
esptool: `"${PYTHON.path.cli}" "${MICROPYTHON.path.esptool}`,
|
esptool: `${pythonCmd} "${MICROPYTHON.path.esptool}"`,
|
||||||
com: config.port
|
com: config.port,
|
||||||
|
baudrate: config.baudrate || "460800"
|
||||||
};
|
};
|
||||||
const command = MString.tpl(config.command, info);
|
// 兼容性处理:移除模板中可能存在的冗余引号
|
||||||
|
let cmdTemplate = config.command || "";
|
||||||
|
cmdTemplate = cmdTemplate.replace(/"{esptool}"/g, '{esptool}');
|
||||||
|
const command = MString.tpl(cmdTemplate, info);
|
||||||
|
console.log('DEBUG CMD BURN:', command);
|
||||||
return this.execUntilClosed(command);
|
return this.execUntilClosed(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
async upload(config) {
|
async upload(config) {
|
||||||
|
// 调试:打印接收到的原始配置
|
||||||
|
console.log('=== UPLOAD DEBUG START ===');
|
||||||
|
console.log('Received config.command:', JSON.stringify(config.command));
|
||||||
|
console.log('Received config.reset:', JSON.stringify(config.reset));
|
||||||
|
console.log('Received config.port:', config.port);
|
||||||
|
console.log('Received config.boardDirPath:', config.boardDirPath);
|
||||||
|
|
||||||
|
// 正确处理 reset 参数:如果是数组则序列化为 JSON 字符串
|
||||||
|
let resetValue = config.reset;
|
||||||
|
if (Array.isArray(resetValue)) {
|
||||||
|
resetValue = JSON.stringify(resetValue);
|
||||||
|
} else if (resetValue === undefined || resetValue === null) {
|
||||||
|
resetValue = '[]';
|
||||||
|
}
|
||||||
|
console.log('Processed resetValue:', resetValue);
|
||||||
|
|
||||||
|
// 对系统命令(不含路径分隔符)不加引号,只对路径加引号
|
||||||
|
const pythonCmd = PYTHON.path.cli.includes('/') || PYTHON.path.cli.includes('\\')
|
||||||
|
? `"${PYTHON.path.cli}"`
|
||||||
|
: PYTHON.path.cli;
|
||||||
|
|
||||||
const info = {
|
const info = {
|
||||||
indexPath: path.resolve(CLIENT_PATH, config.boardDirPath),
|
indexPath: path.resolve(CLIENT_PATH, config.boardDirPath),
|
||||||
ampy: `"${PYTHON.path.cli}" "${MICROPYTHON.path.ampy}`,
|
ampy: `${pythonCmd} "${MICROPYTHON.path.ampy}"`,
|
||||||
com: config.port
|
com: config.port,
|
||||||
|
reset: resetValue
|
||||||
};
|
};
|
||||||
const command = MString.tpl(config.command, info);
|
console.log('Info object:', JSON.stringify(info));
|
||||||
|
|
||||||
|
// 兼容性处理:移除模板中可能存在的冗余引号
|
||||||
|
let cmdTemplate = config.command || "";
|
||||||
|
console.log('Original cmdTemplate:', cmdTemplate);
|
||||||
|
cmdTemplate = cmdTemplate.replace(/"{ampy}"/g, '{ampy}');
|
||||||
|
console.log('After quote cleanup:', cmdTemplate);
|
||||||
|
|
||||||
|
const command = MString.tpl(cmdTemplate, info);
|
||||||
|
console.log('Final command:', command);
|
||||||
|
console.log('=== UPLOAD DEBUG END ===');
|
||||||
|
|
||||||
return this.execUntilClosed(command);
|
return this.execUntilClosed(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -173,6 +173,12 @@ export default class Socket {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on('micropython.burn', async (config, callback) => {
|
socket.on('micropython.burn', async (config, callback) => {
|
||||||
|
// 检查端口是否是有效的系统设备路径(而非前端内部标识符如 serial1)
|
||||||
|
if (config.port && !config.port.startsWith('/dev/') && !config.port.includes(':')) {
|
||||||
|
console.log(`[MicroPython] 忽略无效端口请求: ${config.port},应使用本地 Web Serial API`);
|
||||||
|
callback([null, { code: 0, time: 0 }]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const shell = this.#shellMicroPython_.getItem(socket.id);
|
const shell = this.#shellMicroPython_.getItem(socket.id);
|
||||||
const [error, result] = await to(shell.burn(config));
|
const [error, result] = await to(shell.burn(config));
|
||||||
error && Debug.error(error);
|
error && Debug.error(error);
|
||||||
@@ -180,6 +186,12 @@ export default class Socket {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on('micropython.upload', async (config, callback) => {
|
socket.on('micropython.upload', async (config, callback) => {
|
||||||
|
// 检查端口是否是有效的系统设备路径(而非前端内部标识符如 serial1)
|
||||||
|
if (config.port && !config.port.startsWith('/dev/') && !config.port.includes(':')) {
|
||||||
|
console.log(`[MicroPython] 忽略无效端口请求: ${config.port},应使用本地 Web Serial API`);
|
||||||
|
callback([null, { code: 0, time: 0 }]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const shell = this.#shellMicroPython_.getItem(socket.id);
|
const shell = this.#shellMicroPython_.getItem(socket.id);
|
||||||
let { filePath = '', libraries = {} } = config;
|
let { filePath = '', libraries = {} } = config;
|
||||||
filePath = MString.tpl(filePath, {
|
filePath = MString.tpl(filePath, {
|
||||||
@@ -250,8 +262,16 @@ export default class Socket {
|
|||||||
error2 && Debug.error(error2);
|
error2 && Debug.error(error2);
|
||||||
let [error3,] = await to(fsExtra.outputFile(config.path.code, config.code));
|
let [error3,] = await to(fsExtra.outputFile(config.path.code, config.code));
|
||||||
error3 && Debug.error(error3);
|
error3 && Debug.error(error3);
|
||||||
const [error, result] = await to(shell.upload(config));
|
const [error, result] = await to(shell.compile(config));
|
||||||
error && Debug.error(error);
|
if (error) {
|
||||||
|
Debug.error(error);
|
||||||
|
callback([error, result]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (result.code === 0) {
|
||||||
|
const buildPath = config.path.build;
|
||||||
|
result.files = await Boards.getFiles(config.key, buildPath);
|
||||||
|
}
|
||||||
callback([error, result]);
|
callback([error, result]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user