in tools/cansim/can_command_server.py [0:0]
def handle_message(self, receive_msg):
for config in self.command_configs:
if receive_msg.arbitration_id == self.mask_id(
config["canRequestId"]
) and receive_msg.is_extended_id == self.is_extended_id(config["canRequestId"]):
break
else:
return
try:
self.data = bytearray(receive_msg.data)
command_id = self.pop_string()
issued_timestamp_ms = self.pop_arg(">Q")
execution_timeout_ms = self.pop_arg(">Q")
arg_value = self.pop_arg(config["argumentType"])
print(
f"Received request for {config['actuatorName']}"
f" with command id {command_id}, value {arg_value},"
f" issued timestamp {issued_timestamp_ms}, execution timeout {execution_timeout_ms}"
)
self.args[command_id] = arg_value
execution_state = {"in_progress_counter": config["inProgressCount"]}
def send_response():
status = 10 if execution_state["in_progress_counter"] > 0 else config["status"]
print(
f"Sending response to request for {config['actuatorName']}"
f" with command id {command_id}, status {status},"
f" reason code {config['reasonCode']},"
f" reason description {config['reasonDescription']}"
)
self.data = bytearray()
send_msg = can.Message()
send_msg.arbitration_id = self.mask_id(config["canResponseId"])
send_msg.is_extended_id = self.is_extended_id(config["canResponseId"])
send_msg.is_fd = True
self.push_string(command_id)
self.push_arg("B", status)
self.push_arg(">I", config["reasonCode"])
self.push_string(config["reasonDescription"])
send_msg.data = self.data
send_msg.dlc = len(self.data)
self.can_bus.send(send_msg)
if execution_state["in_progress_counter"] > 0:
execution_state["in_progress_counter"] -= 1
self.loop.call_later(config["responseDelay"], send_response)
self.loop.call_later(config["responseDelay"], send_response)
except Exception as e:
print(e)