import time
from pyaubo_agvc_sdk import RpcClient, RunningInfo


def login():
    ip = "192.168.192.100"
    port = 30104
    rpc_name = "aa"
    rpc_password = "bb"
    agv = RpcClient()
    agv.setRequestTimeout(10000)

    ret = agv.connect(ip, port)
    print(f"connect result: {ret}")
    ret = agv.login(rpc_name, rpc_password)
    print(f"login result: {ret}")
    return agv


def getAgvInfo(agv):
    # 获取运行信息  
    run_info = agv.getRunningInfo()
    print(f"sn : {run_info.header.id}")
    print(f"name : {run_info.header.name}")
    print(f"battery_current : {run_info.battery_current}")
    print(f"battery_voltage : {run_info.battery_voltage}")
    print(f"current_dist : {run_info.current_dist}")
    print(f"current_speed v : {run_info.current_speed.v}")
    print(f"current_speed w : {run_info.current_speed.w}")
    print(f"map_id : {run_info.header.map_id}")
    print(f"location_score : {run_info.location_score}")
    print(f"total_dist : {run_info.total_dist}")
    print(f"total_running_time : {run_info.total_running_time}")
    print(f"running_mode : {run_info.running_mode}")
    print(f"low_battery : {run_info.low_battery}")
    print(f"pause : {run_info.pause}")
    print(f"emergency_stop : {run_info.emergency_stop}")
    print(f"blocked  : {run_info.blocked}")
    print(f"localization_loss  : {run_info.localization_loss}")
    print(f"fault_alarm  : {run_info.fault_alarm}")
    print(f"safety_edge_status  : {run_info.safety_edge_status}")

    # 获取agv的信息 
    agv_details = agv.getAgvDetails()
    print(f"hardware_abstraction_version  : {agv_details.hardware_abstraction_version}")
    print(f"left_motor_firmware_version  : {agv_details.left_motor_firmware_version}")
    print(f"right_motor_firmware_version  : {agv_details.right_motor_firmware_version}")
    print(f"master_board_firmware_version  : {agv_details.master_board_firmware_version}")
    print(f"battery_version  : {agv_details.battery_version}")
    print(f"communication_version : {agv_details.communication_version}")
    print(f"loop_times : {agv_details.loop_times}")
    print(f"surplus_capacity : {agv_details.surplus_capacity}")
    print(f"max_speed : {agv_details.max_speed}")
    print(f"max_angular : {agv_details.max_angular}")
    print(f"MFD : {agv_details.MFD}")
    print(f"name : {agv_details.name}")
    print(f"SN  : {agv_details.SN}")
    print(f"version  : {agv_details.version}")


if __name__ == "__main__":
    agv = login()
    getAgvInfo(agv)
    agv.disconnect()
