LISHUZUOXUN_yangjiang/PureBackend/network_driver.py

59 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# coding: gb2312
import traceback
from DeviceDefine.consensus import UNKNOWN
from LogRecord.log_recorder import GLOBAL_LOG
from PureBackend.base_driver import MODEL_MEDIAPIPE
from PureBackend.standard_manager import StandardManager
class NetworkDriver(StandardManager):
def __init__(self, master_mode=True, positioning=True, camera=True, model=MODEL_MEDIAPIPE, speaker=True,
multi_positioning_mode=True, device_type=UNKNOWN, pure_mode=False):
super().__init__(master_mode, positioning, camera, model, speaker, multi_positioning_mode, device_type, pure_mode)
# 查看当前链接的WiFi
def get_connected_wifi_name(self):
try:
response_data = self.connection.get_connected_wifi()
return response_data
except Exception as e:
GLOBAL_LOG.write(f"发生错误,{str(e)},错误来源:{traceback.format_exc()}")
# 查看当前链接的WiFi
def get_wifi_list(self):
try:
response_data = self.connection.get_available_wifi()
return response_data
except Exception as e:
GLOBAL_LOG.write(f"发生错误,{str(e)},错误来源:{traceback.format_exc()}")
# 断开wifi链接
def wifi_disconnect(self):
try:
self.connection.disconnect()
self.speak_driver.add_speak("已成功断开WiFi链接")
return True
except Exception as e:
GLOBAL_LOG.write(f"发生错误,{str(e)},错误来源:{traceback.format_exc()}")
return False
# 链接指定WiFi
def wifi_connect(self, wifi_name):
try:
if wifi_name:
self.connection.disconnect()
if self.connection.connect2wifi(ssid=wifi_name):
self.speak_driver.add_speak("WiFi链接成功")
return True
else:
self.speak_driver.add_speak("WiFi链接失败")
return False
else:
self.speak_driver.add_speak("WiFi链接失败WiFi名称为空")
return False
except Exception as e:
GLOBAL_LOG.write(f"发生错误,{str(e)},错误来源:{traceback.format_exc()}")
return False