-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* init command panel * complete command center core * added controller server websocket path in env * Change controller server env to local, fixed command response bug * fixed bug * fixed bug
- Loading branch information
1 parent
8ff3a6d
commit 3f4298e
Showing
22 changed files
with
1,331 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import json | ||
from dataclasses import dataclass | ||
|
||
from ..client import client | ||
from ..graphqls.command import ToControllerServerPartial | ||
|
||
|
||
@dataclass | ||
class CommandAgent: | ||
async def send_to_controller_server(self, msg_partial: ToControllerServerPartial): | ||
msg_full = json.dumps( | ||
{ | ||
**(msg_partial.to_dict()), | ||
"from": "controlPanel", | ||
"statusCode": 0, | ||
} | ||
) | ||
await client.send_command(msg_full) | ||
|
||
|
||
command_agent = CommandAgent() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import asyncio | ||
from typing import Any, List, Optional | ||
|
||
import bpy | ||
|
||
from ....properties.ui.types import CommandCenterRPiStatusType, CommandCenterStatusType | ||
from ...asyncio import AsyncTask | ||
from ...states import state | ||
|
||
|
||
class Countdown_task_class: | ||
task: Optional[asyncio.Task[Any]] = None | ||
|
||
|
||
countdown_task = Countdown_task_class() | ||
|
||
|
||
def set_command_status(connected: bool): | ||
command_status: CommandCenterStatusType = getattr( | ||
bpy.context.window_manager, "ld_ui_command_center" | ||
) | ||
command_status.connected = connected | ||
|
||
|
||
def set_RPi_props_from_state(): | ||
rpi_props: List[CommandCenterRPiStatusType] = getattr( | ||
bpy.context.window_manager, "ld_ui_rpi_status" | ||
) | ||
|
||
rpi_status = state.rpi_status | ||
if not rpi_props: | ||
for dancer_name, dancer_item in rpi_status.items(): | ||
rpi_item: CommandCenterRPiStatusType = getattr( | ||
bpy.context.window_manager, "ld_ui_rpi_status" | ||
).add() | ||
rpi_item.name = dancer_name | ||
if dancer_item.ethernet.connected == dancer_item.wifi.connected: | ||
rpi_item.interface_type = "ethernet" | ||
interface_status = dancer_item.ethernet | ||
elif dancer_item.ethernet.connected: | ||
rpi_item.interface_type = "ethernet" | ||
interface_status = dancer_item.ethernet | ||
else: | ||
rpi_item.interface_type = "wifi" | ||
interface_status = dancer_item.wifi | ||
|
||
rpi_item.IP = interface_status.IP | ||
rpi_item.MAC = interface_status.MAC | ||
rpi_item.connected = interface_status.connected | ||
rpi_item.message = interface_status.message | ||
rpi_item.statusCode = interface_status.statusCode | ||
rpi_item.selected = False | ||
else: | ||
for dancer_name, dancer_item in rpi_status.items(): | ||
rpi_item: CommandCenterRPiStatusType = next( | ||
item for item in rpi_props if item.name == dancer_name | ||
) | ||
if dancer_item.ethernet.connected == dancer_item.wifi.connected: | ||
interface_status = dancer_item.ethernet | ||
elif dancer_item.ethernet.connected: | ||
interface_status = dancer_item.ethernet | ||
else: | ||
interface_status = dancer_item.wifi | ||
rpi_item.connected = interface_status.connected | ||
rpi_item.message = interface_status.message | ||
rpi_item.statusCode = interface_status.statusCode | ||
|
||
|
||
def get_selected_dancer() -> List[str]: | ||
rpi_status_list: List[CommandCenterRPiStatusType] = getattr( | ||
bpy.context.window_manager, "ld_ui_rpi_status" | ||
) | ||
return [item.name for item in rpi_status_list if item.selected] | ||
|
||
|
||
def set_countdown(delay: int): | ||
async def countdown(delay: int): | ||
command_status: CommandCenterStatusType = getattr( | ||
bpy.context.window_manager, "ld_ui_command_center" | ||
) | ||
for t in range(delay + 1): | ||
seconds = delay - t | ||
m, s = divmod(seconds, 60) | ||
countdown = f"{m:02d}:{s:02d}" | ||
command_status.countdown = countdown | ||
print(countdown) | ||
if seconds > 0: | ||
await asyncio.sleep(1) | ||
else: | ||
bpy.ops.screen.animation_play() | ||
|
||
countdown_task.task = AsyncTask(countdown, delay=delay).exec() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from ....graphqls.command import ( | ||
FromControllerServerBoardInfoPayload, | ||
FromControllerServerCommandResponse, | ||
) | ||
from ...models import InterfaceStatus, RPiStatusItem, ShellTransaction | ||
from ...states import state | ||
from ..property.command import set_RPi_props_from_state | ||
|
||
|
||
def read_board_info_payload(payload: FromControllerServerBoardInfoPayload): | ||
for item in payload.values(): | ||
rpi_status = state.rpi_status | ||
if item.dancer not in rpi_status: | ||
rpi_status[item.dancer] = RPiStatusItem( | ||
ethernet=InterfaceStatus( | ||
name=item.dancer, | ||
IP=item.IP, | ||
MAC=item.MAC, | ||
connected=False, | ||
statusCode=0, | ||
message="", | ||
), | ||
wifi=InterfaceStatus( | ||
name=item.dancer, | ||
IP=item.IP, | ||
MAC=item.MAC, | ||
connected=False, | ||
statusCode=0, | ||
message="", | ||
), | ||
) | ||
match item.interface: | ||
case "ethernet": | ||
rpi_status[item.dancer].ethernet = InterfaceStatus( | ||
name=item.dancer, | ||
IP=item.IP, | ||
MAC=item.MAC, | ||
connected=item.connected, | ||
statusCode=0, | ||
message="", | ||
) | ||
case "wifi": | ||
rpi_status[item.dancer].wifi = InterfaceStatus( | ||
name=item.dancer, | ||
IP=item.IP, | ||
MAC=item.MAC, | ||
connected=item.connected, | ||
statusCode=0, | ||
message="", | ||
) | ||
set_RPi_props_from_state() | ||
|
||
|
||
def read_command_response(data: FromControllerServerCommandResponse): | ||
payload = data.payload | ||
dancer = payload.dancer | ||
command = payload.command | ||
message = payload.message | ||
rpi_status = state.rpi_status | ||
if dancer not in state.rpi_status: | ||
rpi_status[dancer] = RPiStatusItem( | ||
ethernet=InterfaceStatus( | ||
name=dancer, IP="", MAC="", connected=False, statusCode=0, message="" | ||
), | ||
wifi=InterfaceStatus( | ||
name=dancer, IP="", MAC="", connected=False, statusCode=0, message="" | ||
), | ||
) | ||
rpi_status_item = rpi_status[dancer] | ||
if rpi_status_item.ethernet.connected: | ||
rpi_status_item.ethernet.message = f"[{command}] {message}" | ||
rpi_status_item.ethernet.statusCode = data.statusCode | ||
if rpi_status_item.wifi.connected: | ||
rpi_status_item.wifi.message = f"[{command}] {message}" | ||
rpi_status_item.wifi.statusCode = data.statusCode | ||
shell_history = state.shell_history | ||
if dancer not in shell_history: | ||
shell_history[dancer] = [] | ||
shell_history[dancer].append(ShellTransaction(command=command, output=message)) | ||
set_RPi_props_from_state() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.