triangle algo refind
This commit is contained in:
157
network.py
157
network.py
@@ -1489,56 +1489,48 @@ class NetworkManager:
|
||||
qiniu_key = key.rstrip("/") + "/" + archive_filename
|
||||
self.logger.info(f"[LOG_UPLOAD] 日志归档已生成: {archive_path}, qiniu_key: {qiniu_key}")
|
||||
|
||||
# 2) 自动检测网络类型
|
||||
if self._network_type == "wifi" and self.is_wifi_connected():
|
||||
mode = "wifi"
|
||||
else:
|
||||
mode = "4g"
|
||||
|
||||
self.logger.info(f"[LOG_UPLOAD] Using {mode} path, archive: {archive_path}")
|
||||
|
||||
try:
|
||||
# 2) WiFi 优先:只要 WiFi 已连接就先尝试 WiFi,失败再回落到 4G
|
||||
wifi_tried = False
|
||||
wifi_ok = False
|
||||
if mode == "wifi":
|
||||
# ---- WiFi path: 使用 requests 库上传 ----
|
||||
import requests
|
||||
import urllib3
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
|
||||
if self.is_wifi_connected():
|
||||
wifi_tried = True
|
||||
self.logger.info(f"[LOG_UPLOAD] Using wifi path (preferred), archive: {archive_path}")
|
||||
try:
|
||||
# ---- WiFi path: 使用 requests 库上传 ----
|
||||
import requests
|
||||
import urllib3
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
with open(archive_path, 'rb') as f:
|
||||
files = {'file': (archive_filename, f, 'application/octet-stream')}
|
||||
data = {'token': upload_token, 'key': qiniu_key}
|
||||
wifi_upload_url = upload_url.replace('https://', 'http://', 1)
|
||||
self.logger.info(f"[LOG_UPLOAD] WiFi upload URL: {wifi_upload_url}")
|
||||
response = requests.post(wifi_upload_url, files=files, data=data, timeout=120, verify=False)
|
||||
response.raise_for_status()
|
||||
result_json = response.json()
|
||||
uploaded_key = result_json.get('key', qiniu_key)
|
||||
|
||||
with open(archive_path, 'rb') as f:
|
||||
files = {'file': (archive_filename, f, 'application/octet-stream')}
|
||||
data = {'token': upload_token, 'key': qiniu_key}
|
||||
wifi_upload_url = upload_url.replace('https://', 'http://', 1)
|
||||
self.logger.info(f"[LOG_UPLOAD] WiFi upload URL: {wifi_upload_url}")
|
||||
response = requests.post(wifi_upload_url, files=files, data=data, timeout=120, verify=False)
|
||||
response.raise_for_status()
|
||||
result_json = response.json()
|
||||
uploaded_key = result_json.get('key', qiniu_key)
|
||||
self.logger.info(f"[LOG_UPLOAD] WiFi upload ok: key={uploaded_key}")
|
||||
|
||||
self.logger.info(f"[LOG_UPLOAD] WiFi upload ok: key={uploaded_key}")
|
||||
access_url = None
|
||||
if outlink:
|
||||
access_url = f"https://{outlink}/{uploaded_key}"
|
||||
|
||||
access_url = None
|
||||
if outlink:
|
||||
access_url = f"https://{outlink}/{uploaded_key}"
|
||||
response_data = {
|
||||
"result": "log_upload_ok",
|
||||
"key": uploaded_key,
|
||||
"via": "wifi",
|
||||
}
|
||||
if access_url:
|
||||
response_data["url"] = access_url
|
||||
|
||||
response_data = {
|
||||
"result": "log_upload_ok",
|
||||
"key": uploaded_key,
|
||||
"via": "wifi",
|
||||
}
|
||||
if access_url:
|
||||
response_data["url"] = access_url
|
||||
|
||||
self.safe_enqueue(response_data, 2)
|
||||
wifi_ok = True
|
||||
except Exception as e:
|
||||
# WiFi 上传失败不影响主链路:记录原因并回落 4G
|
||||
self.logger.warning(f"[LOG_UPLOAD] WiFi upload failed, fallback to 4g: {e}")
|
||||
|
||||
if not wifi_ok:
|
||||
if not wifi_tried:
|
||||
self.logger.info(f"[LOG_UPLOAD] WiFi not connected, using 4g path, archive: {archive_path}")
|
||||
else:
|
||||
self.logger.info(f"[LOG_UPLOAD] Using 4g fallback path, archive: {archive_path}")
|
||||
self.safe_enqueue(response_data, 2)
|
||||
|
||||
else:
|
||||
# ---- 4G path: 使用 FourGUploadManager AT命令上传 ----
|
||||
import importlib.util
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
@@ -1578,8 +1570,11 @@ class NetworkManager:
|
||||
}, 2)
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"[LOG_UPLOAD] upload exception: {e}")
|
||||
self.safe_enqueue({"result": "log_upload_failed", "reason": str(e)[:100]}, 2)
|
||||
self.logger.error(f"[LOG_UPLOAD] upload exception ({mode}): {e}")
|
||||
self.safe_enqueue({
|
||||
"result": "log_upload_failed",
|
||||
"reason": str(e)[:100]
|
||||
}, 2)
|
||||
finally:
|
||||
# 清理临时归档文件
|
||||
try:
|
||||
@@ -1600,57 +1595,51 @@ class NetworkManager:
|
||||
shoot_id: 射击ID
|
||||
outlink: 外链域名(可选,用于构建访问URL)
|
||||
"""
|
||||
# WiFi 优先(独立于 TCP 主链路):只要 WiFi 已连接就先走 WiFi,失败再回落 4G
|
||||
mode = "wifi" if self.is_wifi_connected() else "4g"
|
||||
# 自动检测网络类型,选择上传路径
|
||||
if self._network_type == "wifi" and self.is_wifi_connected():
|
||||
mode = "wifi"
|
||||
else:
|
||||
mode = "4g"
|
||||
|
||||
self.logger.info(f"[IMAGE_UPLOAD] Using {mode} path, image: {image_path}")
|
||||
|
||||
try:
|
||||
wifi_ok = False
|
||||
|
||||
if mode == "wifi":
|
||||
try:
|
||||
# ---- WiFi path: 使用 requests 库上传 ----
|
||||
import requests
|
||||
import urllib3
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
# ---- WiFi path: 使用 requests 库上传 ----
|
||||
import requests
|
||||
import urllib3
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
|
||||
with open(image_path, 'rb') as f:
|
||||
files = {'file': (os.path.basename(image_path), f, 'application/octet-stream')}
|
||||
data = {'token': upload_token, 'key': key}
|
||||
# 将 HTTPS 转为 HTTP(设备端 SSL 兼容性)
|
||||
wifi_upload_url = upload_url.replace('https://', 'http://', 1)
|
||||
self.logger.info(f"[IMAGE_UPLOAD] WiFi upload URL: {wifi_upload_url}")
|
||||
response = requests.post(wifi_upload_url, files=files, data=data, timeout=120, verify=False)
|
||||
response.raise_for_status()
|
||||
result_json = response.json()
|
||||
uploaded_key = result_json.get('key', key)
|
||||
with open(image_path, 'rb') as f:
|
||||
files = {'file': (os.path.basename(image_path), f, 'application/octet-stream')}
|
||||
data = {'token': upload_token, 'key': key}
|
||||
# 测试:将HTTPS转为HTTP
|
||||
wifi_upload_url = upload_url.replace('https://', 'http://', 1)
|
||||
self.logger.info(f"[IMAGE_UPLOAD] WiFi upload URL: {wifi_upload_url}")
|
||||
response = requests.post(wifi_upload_url, files=files, data=data, timeout=120, verify=False)
|
||||
response.raise_for_status()
|
||||
result_json = response.json()
|
||||
uploaded_key = result_json.get('key', key)
|
||||
|
||||
self.logger.info(f"[IMAGE_UPLOAD] WiFi upload ok: key={uploaded_key}")
|
||||
self.logger.info(f"[IMAGE_UPLOAD] WiFi upload ok: key={uploaded_key}")
|
||||
|
||||
access_url = None
|
||||
if outlink:
|
||||
access_url = f"https://{outlink}/{uploaded_key}"
|
||||
access_url = None
|
||||
if outlink:
|
||||
access_url = f"https://{outlink}/{uploaded_key}"
|
||||
|
||||
response_data = {
|
||||
"result": "image_upload_ok",
|
||||
"shootId": shoot_id,
|
||||
"key": uploaded_key,
|
||||
"via": "wifi",
|
||||
}
|
||||
if access_url:
|
||||
response_data["url"] = access_url
|
||||
response_data = {
|
||||
"result": "image_upload_ok",
|
||||
"shootId": shoot_id,
|
||||
"key": uploaded_key,
|
||||
"via": "wifi",
|
||||
}
|
||||
if access_url:
|
||||
response_data["url"] = access_url
|
||||
|
||||
self.safe_enqueue(response_data, 2)
|
||||
wifi_ok = True
|
||||
except Exception as e:
|
||||
self.logger.warning(f"[IMAGE_UPLOAD] WiFi upload failed, fallback to 4g: {e}")
|
||||
self.safe_enqueue(response_data, 2)
|
||||
|
||||
if not wifi_ok:
|
||||
else:
|
||||
# ---- 4G path: 使用 FourGUploadManager AT命令上传 ----
|
||||
if mode != "4g":
|
||||
self.logger.info(f"[IMAGE_UPLOAD] Using 4g fallback path, image: {image_path}")
|
||||
|
||||
import importlib.util
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"four_g_upload_manager",
|
||||
|
||||
Reference in New Issue
Block a user