fix config
This commit is contained in:
parent
abd2e9cfd5
commit
20539edf5c
@ -11,16 +11,6 @@ ISDEV = False
|
|||||||
if '--dev' in sys.argv:
|
if '--dev' in sys.argv:
|
||||||
ISDEV = True
|
ISDEV = True
|
||||||
|
|
||||||
PLAYBACK_SOCKET_PORT = 5003
|
|
||||||
PLAYBACK_SOCKET = f'127.0.0.1:{PLAYBACK_SOCKET_PORT}'
|
|
||||||
MI_REP_SOCKET_PORT = 5557
|
|
||||||
DEVICE_PY_REP_SOCKET_PORT = 5558
|
|
||||||
|
|
||||||
SWITCH1_IP = 'c1'
|
|
||||||
SWITCH1_TOKEN = '7ad51e0016e7a9d22f753d5110f76c7d'
|
|
||||||
SWITCH2_IP = 'c2'
|
|
||||||
SWITCH2_TOKEN = 'bf5a7b77a1ba3761ea63fafd8427b7d6'
|
|
||||||
|
|
||||||
CONFIG_FOLDER = platformdirs.user_config_path('Flandre', 'Scarlet')
|
CONFIG_FOLDER = platformdirs.user_config_path('Flandre', 'Scarlet')
|
||||||
|
|
||||||
if ISDEV:
|
if ISDEV:
|
||||||
@ -34,6 +24,9 @@ SOFTWARE_CONFIG_PATH = CONFIG_FOLDER / 'software.json'
|
|||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
class SoftwareConfig:
|
class SoftwareConfig:
|
||||||
|
def s(self, host, port, proto='tcp'):
|
||||||
|
return f'{proto}://{host}:{port}'
|
||||||
|
|
||||||
data_folder: Path = DS
|
data_folder: Path = DS
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -54,6 +47,7 @@ class SoftwareConfig:
|
|||||||
live_ip: str = '11.6.1.71'
|
live_ip: str = '11.6.1.71'
|
||||||
live_push_port: int = 5555
|
live_push_port: int = 5555
|
||||||
live_rep_port: int = 5556
|
live_rep_port: int = 5556
|
||||||
|
device_py_rep_port: int = 5558
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def live_push_socket(self):
|
def live_push_socket(self):
|
||||||
@ -67,6 +61,28 @@ class SoftwareConfig:
|
|||||||
def live_rep_socket_http(self):
|
def live_rep_socket_http(self):
|
||||||
return f'http://{self.live_ip}:{self.live_rep_port}'
|
return f'http://{self.live_ip}:{self.live_rep_port}'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_py_rep_socket(self):
|
||||||
|
return f'tcp://{self.live_ip}:{self.device_py_rep_port}'
|
||||||
|
|
||||||
|
playback_port: int = 5003
|
||||||
|
|
||||||
|
@property
|
||||||
|
def playback_socket(self):
|
||||||
|
return f'tcp://127.0.0.1:{self.playback_port}'
|
||||||
|
|
||||||
|
mi_rep_port: int = 5557
|
||||||
|
local_ip: str = '127.0.0.1'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def mi_rep_socket(self):
|
||||||
|
return self.s(self.local_ip, self.device_py_rep_port)
|
||||||
|
|
||||||
|
switch1_ip: str = 'c1'
|
||||||
|
switch1_token: str = '7ad51e0016e7a9d22f753d5110f76c7d'
|
||||||
|
switch2_ip: str = 'c2'
|
||||||
|
switch2_token: str = 'bf5a7b77a1ba3761ea63fafd8427b7d6'
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def read_config(path: Path):
|
def read_config(path: Path):
|
||||||
j = json.loads(path.read_text(encoding='utf-8'))
|
j = json.loads(path.read_text(encoding='utf-8'))
|
||||||
|
|||||||
@ -5,7 +5,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
import zmq
|
import zmq
|
||||||
|
|
||||||
from flandre.config import PLAYBACK_SOCKET_PORT, C
|
from flandre.config import C
|
||||||
from flandre.nodes.Node import Node
|
from flandre.nodes.Node import Node
|
||||||
from flandre.utils.Msg import MoveAxisMsg, KillMsg, SetSeqMetaMsg, SeqIdMinMax, SetBaseMsg, SeqListMsg, SeqIdList, \
|
from flandre.utils.Msg import MoveAxisMsg, KillMsg, SetSeqMetaMsg, SeqIdMinMax, SetBaseMsg, SeqListMsg, SeqIdList, \
|
||||||
SetSidMsg, RfFrameWithMetaMsg
|
SetSidMsg, RfFrameWithMetaMsg
|
||||||
@ -19,7 +19,7 @@ class Loader(Node):
|
|||||||
|
|
||||||
def loop(self):
|
def loop(self):
|
||||||
playback_socket = self.context.socket(zmq.PUSH)
|
playback_socket = self.context.socket(zmq.PUSH)
|
||||||
playback_socket.bind(f"tcp://*:{PLAYBACK_SOCKET_PORT}")
|
playback_socket.bind(f"tcp://*:{C.playback_port}")
|
||||||
|
|
||||||
# base = Path('/mnt/16T/private_dataset/us/')
|
# base = Path('/mnt/16T/private_dataset/us/')
|
||||||
base: Path | None = None
|
base: Path | None = None
|
||||||
|
|||||||
@ -14,7 +14,7 @@ from PyQt6.QtWidgets import QMainWindow, QApplication, QFrame, QMessageBox, QFil
|
|||||||
from flandre import ASSETS
|
from flandre import ASSETS
|
||||||
from flandre.pyqt.Main import Ui_MainWindow
|
from flandre.pyqt.Main import Ui_MainWindow
|
||||||
from flandre.pyqt.ZMQReceiver import ZMQReceiver
|
from flandre.pyqt.ZMQReceiver import ZMQReceiver
|
||||||
from flandre.config import DS, C, MI_REP_SOCKET_PORT
|
from flandre.config import DS, C
|
||||||
from flandre.nodes.Node import Node
|
from flandre.nodes.Node import Node
|
||||||
from flandre.utils.Msg import KillMsg, Msg, ImageArgMsg, SeqIdMinMax, MoveAxisMsg, SeqListMsg, SetBaseMsg, \
|
from flandre.utils.Msg import KillMsg, Msg, ImageArgMsg, SeqIdMinMax, MoveAxisMsg, SeqListMsg, SetBaseMsg, \
|
||||||
SetSeqMetaMsg, SetPlayMode, DeviceConnectedMsg, DeviceEnabledMsg, DeviceOnlineMsg, SetDeviceEnabledMsg, \
|
SetSeqMetaMsg, SetPlayMode, DeviceConnectedMsg, DeviceEnabledMsg, DeviceOnlineMsg, SetDeviceEnabledMsg, \
|
||||||
@ -134,7 +134,7 @@ class Adv(QMainWindow, Ui_MainWindow):
|
|||||||
self.b_us_refresh.clicked.connect(self.on_deivce_refresh)
|
self.b_us_refresh.clicked.connect(self.on_deivce_refresh)
|
||||||
|
|
||||||
self.mi_req_socket = zmq.Context().socket(zmq.REQ)
|
self.mi_req_socket = zmq.Context().socket(zmq.REQ)
|
||||||
self.mi_req_socket.connect(f"tcp://127.0.0.1:{MI_REP_SOCKET_PORT}")
|
self.mi_req_socket.connect(C.mi_rep_socket)
|
||||||
|
|
||||||
def on_deivce_switch(self):
|
def on_deivce_switch(self):
|
||||||
match self.device_switch_state:
|
match self.device_switch_state:
|
||||||
@ -542,4 +542,4 @@ class MainUI(Node):
|
|||||||
MainWindow.show()
|
MainWindow.show()
|
||||||
app.exec()
|
app.exec()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
traceback.print_exception(e)
|
||||||
|
|||||||
@ -1,25 +1,20 @@
|
|||||||
import logging
|
import logging
|
||||||
import struct
|
|
||||||
import subprocess
|
|
||||||
import time
|
import time
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
import zmq
|
import zmq
|
||||||
|
|
||||||
from config import LIVE_REP_SOCKET, CONFIG, DEVICE_CONFIG, MI_REP_SOCKET_PORT, DEVICE_PY_REP_SOCKET_PORT, LIVE_SOCKET_IP
|
from flandre.config import C
|
||||||
from nodes.Node import Node
|
from flandre.nodes.Node import Node
|
||||||
from utils.Msg import ImageArgMsg, KillMsg, SetDeviceConnectedMsg, SetDeviceEnabledMsg, DeviceEnabledMsg, \
|
from flandre.utils.Msg import KillMsg, SetDeviceSwitchMsg, DeviceSwitchMsg, RefreshDeviceMsg
|
||||||
DeviceConnectedMsg, SetDeviceConfigMsg, DeviceOnlineMsg, DeviceConfigListMsg, RequestRfFrameMsg, RfFrameMsg, \
|
from flandre.utils.mi import c1_connect, c1_connected, c1_disconnect
|
||||||
RfFrameWithMetaMsg, DeviceZero, SetDeviceSwitchMsg, DeviceSwitchMsg, RefreshDeviceMsg
|
from flandre.utils.network import check_port, check_socket
|
||||||
from utils.RfMeta import RfFrameMeta
|
|
||||||
from utils.mi import c1_connect, c1_connected, c1_disconnect
|
|
||||||
from utils.network import check_port
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Mi(Node):
|
class Mi(Node):
|
||||||
topics = [SetDeviceSwitchMsg,RefreshDeviceMsg]
|
topics = [SetDeviceSwitchMsg, RefreshDeviceMsg]
|
||||||
|
|
||||||
def __init__(self, level=logging.INFO):
|
def __init__(self, level=logging.INFO):
|
||||||
super(Mi, self).__init__(level=level)
|
super(Mi, self).__init__(level=level)
|
||||||
@ -28,16 +23,16 @@ class Mi(Node):
|
|||||||
|
|
||||||
def custom_setup(self):
|
def custom_setup(self):
|
||||||
self.mi_rep_socket = self.context.socket(zmq.REP)
|
self.mi_rep_socket = self.context.socket(zmq.REP)
|
||||||
self.mi_rep_socket.bind(f"tcp://*:{MI_REP_SOCKET_PORT}")
|
self.mi_rep_socket.bind(f"tcp://*:{C.mi_rep_port}")
|
||||||
|
|
||||||
self.device_py_req_socket = self.context.socket(zmq.REQ)
|
self.device_py_req_socket = self.context.socket(zmq.REQ)
|
||||||
self.device_py_req_socket.connect(f"tcp://{LIVE_SOCKET_IP}:{DEVICE_PY_REP_SOCKET_PORT}")
|
self.device_py_req_socket.connect(C.device_py_rep_socket)
|
||||||
|
|
||||||
self.device_py_req_socket1s = self.context.socket(zmq.REQ)
|
self.device_py_req_socket1s = self.context.socket(zmq.REQ)
|
||||||
self.device_py_req_socket1s.connect(f"tcp://{LIVE_SOCKET_IP}:{DEVICE_PY_REP_SOCKET_PORT}")
|
self.device_py_req_socket1s.connect(C.device_py_rep_socket)
|
||||||
|
|
||||||
self.device_py_req_socket60s = self.context.socket(zmq.REQ)
|
self.device_py_req_socket60s = self.context.socket(zmq.REQ)
|
||||||
self.device_py_req_socket60s.connect(f"tcp://{LIVE_SOCKET_IP}:{DEVICE_PY_REP_SOCKET_PORT}")
|
self.device_py_req_socket60s.connect(C.device_py_rep_socket)
|
||||||
|
|
||||||
self.ping1s_thread = Thread(target=self.ping1s)
|
self.ping1s_thread = Thread(target=self.ping1s)
|
||||||
self.ping1s_thread.start()
|
self.ping1s_thread.start()
|
||||||
@ -80,7 +75,7 @@ class Mi(Node):
|
|||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
def loop(self):
|
def loop(self):
|
||||||
if c1_connected() and check_port(LIVE_SOCKET_IP, DEVICE_PY_REP_SOCKET_PORT):
|
if c1_connected() and check_socket(C.device_py_rep_socket):
|
||||||
self.device_py_req_socket.send(b'get_device_status')
|
self.device_py_req_socket.send(b'get_device_status')
|
||||||
r = self.device_py_req_socket.recv()
|
r = self.device_py_req_socket.recv()
|
||||||
if r == b'on':
|
if r == b'on':
|
||||||
@ -121,11 +116,10 @@ class Mi(Node):
|
|||||||
self.device_py_req_socket.send(b'kill')
|
self.device_py_req_socket.send(b'kill')
|
||||||
self.device_py_req_socket.recv()
|
self.device_py_req_socket.recv()
|
||||||
self.send(DeviceSwitchMsg('RED'))
|
self.send(DeviceSwitchMsg('RED'))
|
||||||
elif isinstance(msg,RefreshDeviceMsg):
|
elif isinstance(msg, RefreshDeviceMsg):
|
||||||
self.device_py_req_socket.send(b'kill')
|
self.device_py_req_socket.send(b'kill')
|
||||||
self.device_py_req_socket.recv()
|
self.device_py_req_socket.recv()
|
||||||
self.device_py_req_socket.send(b'start')
|
self.device_py_req_socket.send(b'start')
|
||||||
self.device_py_req_socket.recv()
|
self.device_py_req_socket.recv()
|
||||||
self.send(DeviceSwitchMsg('GREEN'))
|
self.send(DeviceSwitchMsg('GREEN'))
|
||||||
self.ping60enable = True
|
self.ping60enable = True
|
||||||
|
|
||||||
|
|||||||
@ -1,19 +1,15 @@
|
|||||||
import click
|
import click
|
||||||
from miio.miioprotocol import MiIOProtocol
|
from miio.miioprotocol import MiIOProtocol
|
||||||
|
|
||||||
from flandre.config import SWITCH1_IP, SWITCH1_TOKEN, SWITCH2_IP, SWITCH2_TOKEN
|
from flandre.config import C
|
||||||
|
|
||||||
|
|
||||||
def c1():
|
def c1():
|
||||||
return MiIOProtocol(
|
return MiIOProtocol(C.switch1_ip, C.switch1_token)
|
||||||
SWITCH1_IP, SWITCH1_TOKEN,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def c2():
|
def c2():
|
||||||
return MiIOProtocol(
|
return MiIOProtocol(C.switch2_ip, C.switch2_token)
|
||||||
SWITCH2_IP, SWITCH2_TOKEN,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def c1_set_connect(status: bool):
|
def c1_set_connect(status: bool):
|
||||||
|
|||||||
@ -16,6 +16,10 @@ def check_port(host, port):
|
|||||||
print(f"连接过程中发生错误: {e}")
|
print(f"连接过程中发生错误: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def check_socket(socket: str):
|
||||||
|
host, port = socket.split('//')[-1].split(':')
|
||||||
|
return check_port(host, int(port))
|
||||||
# def c2():
|
# def c2():
|
||||||
# code = subprocess.run(['curl', '-m', '1', f'http://{LIVE_REP_SOCKET}'], stderr=subprocess.DEVNULL,
|
# code = subprocess.run(['curl', '-m', '1', f'http://{LIVE_REP_SOCKET}'], stderr=subprocess.DEVNULL,
|
||||||
# stdout=subprocess.DEVNULL).returncode
|
# stdout=subprocess.DEVNULL).returncode
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user