Skip to content

Commit

Permalink
Merge pull request #3 from ut-issl/feature/update_for_2nd_obc
Browse files Browse the repository at this point in the history
MOBC以外にも対応
  • Loading branch information
meltingrabbit authored Dec 13, 2021
2 parents fed2faf + f988aa7 commit c057a61
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
40 changes: 30 additions & 10 deletions isslwings/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
else:
default_url = "https://localhost:5001"

default_obc_info = {
"name": "MOBC",
"hk_tlm_info": {
"tlm_name": "HK",
"cmd_counter": "OBC_GS_CMD_COUNTER",
"cmd_last_exec_id": "OBC_GS_CMD_LAST_EXEC_ID",
"cmd_last_exec_sts": "OBC_GS_CMD_LAST_EXEC_STS"
}
}

default_authentication_info = {
"client_id": "hoge_id",
"client_secret": "hoge_secret",
Expand All @@ -21,11 +31,17 @@
"password": "piyopiyo"
}


class Operation:
def __init__(self, url: str = default_url, auto_connect: bool = True, authentication_info: dict = default_authentication_info) -> None:
def __init__(
self,
url: str = default_url,
auto_connect: bool = True,
obc_info: dict = default_obc_info,
authentication_info: dict = default_authentication_info
) -> None:
self.url = url
self.operation_id = ""
self.obc_info = obc_info
self.authorized_headers = {} # 認証が必要

# 認証を入れていく
Expand Down Expand Up @@ -192,19 +208,25 @@ def get_latest_tlm(self, tlm_code_id: int) -> Tuple[dict, str]:

return telemetry_data, received_time

def send_rt_cmd(self, cmd_code: int, cmd_params_value: tuple) -> None:
command_to_send = self._generate_cmd_dict(cmd_code, cmd_params_value)
def send_rt_cmd(self, cmd_code: int, cmd_params_value: tuple, component: str = "") -> None:
command_to_send = self._generate_cmd_dict(cmd_code, cmd_params_value, component)
self._send_rt_cmd(command_to_send)

time.sleep(0.1)

def send_bl_cmd(self, ti: int, cmd_code: int, cmd_params_value: tuple) -> None:
command_to_send = self._generate_cmd_dict(cmd_code, cmd_params_value)
def send_bl_cmd(self, ti: int, cmd_code: int, cmd_params_value: tuple, component: str = "") -> None:
command_to_send = self._generate_cmd_dict(cmd_code, cmd_params_value, component)
self._send_bl_cmd(ti, command_to_send)

time.sleep(0.1)

def _generate_cmd_dict(self, cmd_code: int, cmd_params_value: tuple) -> dict:
def get_obc_info(self) -> dict:
return self.obc_info

def _generate_cmd_dict(self, cmd_code: int, cmd_params_value: tuple, component: str = "") -> dict:
if component == "":
component = self.obc_info["name"]

response = self.client.get(
"{}/api/operations/{}/cmd".format(self.url, self.operation_id),
headers=self.authorized_headers
Expand All @@ -216,7 +238,7 @@ def _generate_cmd_dict(self, cmd_code: int, cmd_params_value: tuple) -> dict:
# 該当するcmd_codeのコマンド情報を探す
command_is_found = False
for command in response["data"]:
if int(command["code"], base=16) == cmd_code:
if command["component"] == component and int(command["code"], base=16) == cmd_code:
command_is_found = True
break

Expand All @@ -236,7 +258,6 @@ def _generate_cmd_dict(self, cmd_code: int, cmd_params_value: tuple) -> dict:
return command_to_send

def _send_rt_cmd(self, command: dict) -> None:

command["execType"] = "RT"
response = self.client.post(
"{}/api/operations/{}/cmd".format(self.url, self.operation_id),
Expand All @@ -248,7 +269,6 @@ def _send_rt_cmd(self, command: dict) -> None:
raise Exception('send_cmd failed.\n" + "command "{}"'.format(command))

def _send_bl_cmd(self, ti: int, command: dict) -> None:

command["execType"] = "BL"
command["execTime"] = ti
response = self.client.post(
Expand Down
12 changes: 8 additions & 4 deletions isslwings/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def generate_and_receive_tlm(
raise Exception("No response to GENERATE_TLM.")


# FIXME: MOBC経由からの2nd OBCへのコマンドは,GS counterで confirm できないので,一旦対応しない.別関数つくる?
def send_rt_cmd_and_confirm(
ope: Operation, cmd_code: int, cmd_args: tuple, tlm_code_hk: int
) -> str:
Expand All @@ -34,6 +35,7 @@ def send_rt_cmd_and_confirm(
return _send_cmd_and_confirm(ope, func_send_cmd, cmd_code, cmd_args, tlm_code_hk)


# FIXME: MOBC経由からの2nd OBCへのコマンドは,GS counterで confirm できないので,一旦対応しない.別関数つくる?
def send_bl_cmd_and_confirm(
ope: Operation, ti: int, cmd_code: int, cmd_args: tuple, tlm_code_hk: int
) -> str:
Expand All @@ -52,20 +54,22 @@ def _send_cmd_and_confirm(
cmd_args: tuple,
tlm_code_hk: int,
) -> str:
hk_tlm_info = ope.get_obc_info()["hk_tlm_info"]
hk_tlm_name = hk_tlm_info["tlm_name"]
tlm_HK, _ = ope.get_latest_tlm(tlm_code_hk)
command_count_before = tlm_HK["HK.OBC_GS_CMD_COUNTER"]
command_count_before = tlm_HK[hk_tlm_name + "." + hk_tlm_info["cmd_counter"]]

func_send_cmd(cmd_code, cmd_args)

for _ in range(50):
time.sleep(0.2)

tlm_HK, _ = ope.get_latest_tlm(tlm_code_hk)
command_count_after = tlm_HK["HK.OBC_GS_CMD_COUNTER"]
command_exec_id = tlm_HK["HK.OBC_GS_CMD_LAST_EXEC_ID"]
command_count_after = tlm_HK[hk_tlm_name + "." + hk_tlm_info["cmd_counter"]]
command_exec_id = tlm_HK[hk_tlm_name + "." + hk_tlm_info["cmd_last_exec_id"]]

if command_count_after > command_count_before and command_exec_id == cmd_code:
return tlm_HK["HK.OBC_GS_CMD_LAST_EXEC_STS"]
return tlm_HK[hk_tlm_name + "." + hk_tlm_info["cmd_last_exec_sts"]]

raise Exception("No response to command code:" + str(cmd_code) + ".")

Expand Down

0 comments on commit c057a61

Please sign in to comment.