Merge remote-tracking branch 'upstream/main' into reinlooptest

This commit is contained in:
rangang
2026-08-03 11:40:09 +08:00
18 changed files with 381 additions and 242 deletions
+2 -3
View File
@@ -11,7 +11,7 @@ import datetime
import threading
import requests
from api import base_url, data_record_url, the_folder
from api import device_post, the_folder
class DataCollector:
@@ -47,12 +47,11 @@ class DataCollector:
def _upload_to_server(self, data_bytes: bytes, filename: str, folder: str) -> bool:
"""向 ReinLoop 云服务器申请上传地址并上传控制数据。"""
try:
resp = requests.post(data_record_url, json={
result = device_post({
"type": "uploadDataFile",
"fileName": filename,
"folder": folder,
}, timeout=30)
result = resp.json()
except Exception as e:
self.log(f"向云服务器申请上传地址异常: {e}")
return False
+2 -6
View File
@@ -3,16 +3,12 @@
def heartbeat_device(timeout=5):
"""Refresh the current device's Server heartbeat and return its timestamp."""
import requests
from api import data_record_url, the_folder
from api import device_post
try:
response = requests.post(data_record_url, json={
result = device_post({
"type": "deviceHeartbeat",
"deviceId": the_folder,
}, timeout=timeout)
response.raise_for_status()
result = response.json()
except Exception as exc:
raise ValueError(f"设备心跳请求失败: {exc}") from exc
if not result.get("success"):
+2 -3
View File
@@ -16,7 +16,7 @@ from collections import deque
from get_V import measure_volume
from ind_collector import collect_data_with_prbs
from api import base_url, data_record_url, the_folder
from api import device_post, the_folder
class IdentificationManager:
@@ -66,12 +66,11 @@ class IdentificationManager:
"""
# Step 1: 向业务服务器申请一次性上传地址(不传文件内容)
try:
resp = requests.post(data_record_url, json={
result = device_post({
"type": "uploadDataFile",
"fileName": filename,
"folder": folder,
}, timeout=30)
result = resp.json()
except Exception as e:
self.log(f"向云服务器申请上传地址异常: {e}")
return False
+2 -5
View File
@@ -130,15 +130,12 @@ def parse_identification_config_csv(csv_text: str) -> dict:
def download_identification_config(timeout=20) -> dict:
"""Download the current customer's CSV config through the cloud server."""
import requests
from api import data_record_url, the_folder
from api import device_post
try:
response = requests.post(data_record_url, json={
result = device_post({
"type": "getIdentificationConfig",
"deviceId": the_folder,
}, timeout=timeout)
response.raise_for_status()
result = response.json()
except Exception as exc:
raise ValueError(f"连接云服务器辨识配置服务失败: {exc}") from exc
+2 -14
View File
@@ -2,13 +2,10 @@
def _post(payload, timeout=10):
import requests
from api import data_record_url
from api import device_post
try:
response = requests.post(data_record_url, json=payload, timeout=timeout)
response.raise_for_status()
result = response.json()
result = device_post(payload, timeout=timeout)
except Exception as exc:
raise ValueError(f"辨识反馈服务请求失败: {exc}") from exc
if not result.get("success"):
@@ -18,13 +15,10 @@ def _post(payload, timeout=10):
def register_identification_result(run_id: str, timeout=10) -> None:
"""Register one uploaded CSV as the customer's current review target."""
from api import the_folder
if not run_id:
raise ValueError("辨识结果缺少 run_id")
_post({
"type": "registerIdentificationResult",
"deviceId": the_folder,
"runId": run_id,
"fileName": run_id,
}, timeout=timeout)
@@ -32,11 +26,8 @@ def register_identification_result(run_id: str, timeout=10) -> None:
def get_identification_feedback(run_id: str, timeout=10):
"""Return None while pending, otherwise return the integer 0 or 1."""
from api import the_folder
result = _post({
"type": "getIdentificationFeedback",
"deviceId": the_folder,
"runId": run_id,
}, timeout=timeout)
if not result.get("ready"):
@@ -49,10 +40,7 @@ def get_identification_feedback(run_id: str, timeout=10):
def acknowledge_identification_feedback(run_id: str, timeout=10) -> None:
"""Delete the consumed review record so stale feedback cannot be reused."""
from api import the_folder
_post({
"type": "ackIdentificationFeedback",
"deviceId": the_folder,
"runId": run_id,
}, timeout=timeout)
+3 -6
View File
@@ -6,14 +6,13 @@
import threading
import io
import requests
import torch
from stable_baselines3 import SAC
# 关键:禁用 PyTorch 内部多线程,防止在 PyInstaller daemon 线程中 segfault
torch.set_num_threads(1)
from api import base_url, data_record_url, the_folder
from api import device_post, the_folder
class ModelManager:
@@ -50,8 +49,7 @@ class ModelManager:
def fetch_models():
try:
payload = {"type": "listModels", "folder": f"{the_folder}/model_config"}
resp = requests.post(data_record_url, json=payload, timeout=10)
result = resp.json()
result = device_post(payload, timeout=10)
if result.get("success"):
files = result.get("files", [])
@@ -98,8 +96,7 @@ class ModelManager:
# 获取临时下载 URL
payload = {"type": "downloadModel", "fileID": file_id}
resp = requests.post(data_record_url, json=payload, timeout=15)
result = resp.json()
result = device_post(payload, timeout=15)
if not result.get("success"):
err = result.get('errMsg', '未知错误')
+2 -13
View File
@@ -84,13 +84,10 @@ def validate_volume_config(config) -> dict:
def _post_volume_request(payload, timeout=10):
import requests
from api import data_record_url
from api import device_post
try:
response = requests.post(data_record_url, json=payload, timeout=timeout)
response.raise_for_status()
result = response.json()
result = device_post(payload, timeout=timeout)
except Exception as exc:
raise ValueError(f"连接云端容积参数服务失败: {exc}") from exc
@@ -101,11 +98,8 @@ def _post_volume_request(payload, timeout=10):
def create_volume_config_request(timeout=10) -> dict:
"""Create exactly one cloud request after the customer clicks Test."""
from api import the_folder
result = _post_volume_request({
"type": "createVolumeConfigRequest",
"deviceId": the_folder,
}, timeout=timeout)
if not result.get("requestId") or not result.get("expiresAtMs"):
raise ValueError("云端未返回有效的容积参数请求编号")
@@ -118,11 +112,9 @@ def create_volume_config_request(timeout=10) -> dict:
def poll_volume_config_request(request_id: str, timeout=10) -> dict:
"""Poll one request; download and validate JSON only when it is ready."""
import requests
from api import the_folder
result = _post_volume_request({
"type": "getVolumeConfigRequest",
"deviceId": the_folder,
"requestId": request_id,
}, timeout=timeout)
if result.get("expired"):
@@ -145,10 +137,7 @@ def poll_volume_config_request(request_id: str, timeout=10) -> dict:
def acknowledge_volume_config_request(request_id: str, timeout=10) -> None:
"""Delete the consumed/abandoned request and its temporary JSON file."""
from api import the_folder
_post_volume_request({
"type": "ackVolumeConfigRequest",
"deviceId": the_folder,
"requestId": request_id,
}, timeout=timeout)