def main(): main_interface = command_handler.CommandHandler("polyglot.db") while True: command = main_interface.parse_command(str(input("Enter command>"))) if main_interface.is_command(command, "help"): print(main_interface.trigger_help()) elif main_interface.is_command(command, "list_employees"): print(main_interface.trigger_list_employees()) elif main_interface.is_command(command, "monthly_spending"): print("The company is spending ${} every month!".format( main_interface.trigger_monthly_spending())) elif main_interface.is_command(command, "yearly_spending"): print("The company is spending ${} every year!".format( main_interface.trigger_yearly_spending())) elif main_interface.is_command(command, "add_employee"): main_interface.trigger_add_employee() elif main_interface.is_command(command, "delete_employee"): print(main_interface.trigger_delete_employee(command[1])) elif main_interface.is_command(command, "update_employee"): main_interface.trigger_update_employee(command[1]) else: print(main_interface.trigger_unknown_command())
def handle_connect(self): # get the socket that connect to the client socket self.socket = self.request self.socket.settimeout(99) # send greetings self.socket.send( ("--------------Welcome to MySSH server-------------\n") .encode() ) # create user instance to process commands self.handler = command_handler.CommandHandler( None, command_parser.CommandParser()) self.ackno = 0 self.record = {}
def __init__(self): self.request_sent = False self.first_msg_ok = False # status variables self.batt_volt = 0.0 self.last_heard = 0 self.last_heard_sys_status = 0 self.lat = 0.0 self.lon = 0.0 self.alt = 0.0 self.local_lat = 0.0 self.local_lon = 0.0 self.local_alt = -5.0 self.local_pos = np.empty((1, 3), float) self.recorded_sys_id = 0 self.recorded_comp_id = 0 self.utmconv = utm.utmconv() self.target_lat = 55.4720459 self.target_lon = 10.4148503 (_, _, _, easting, northing) = self.utmconv.geodetic_to_utm(self.target_lat, self.target_lon) self.target_easting = easting self.target_northing = northing self.mission_handler = mission_handler.MissionHandler() self.current_mission_no = 0 self.last_mission_no = 0 self.command_handler = command_handler.CommandHandler() rospy.sleep(1) # wait until everything is running self.boot_time = rospy.Time.now().to_sec() * 1000 self.drone_boot_epoch = 0 # Service handlers self.arm_service = rospy.Service("/telemetry/arm_drone", Trigger, self.command_handler.arm_drone, buff_size=10) self.disarm_service = rospy.Service("/telemetry/disarm_drone", Trigger, self.command_handler.disarm_drone, buff_size=10) self.takeoff_service = rospy.Service( "/telemetry/takeoff_drone", TakeoffDrone, self.command_handler.takeoff_drone, buff_size=10) self.land_service = rospy.Service("/telemetry/land_drone", LandDrone, self.command_handler.land_drone, buff_size=10) self.start_mission_service = rospy.Service( "/telemetry/start_mission", Trigger, self.command_handler.start_mission, buff_size=10) self.goto_waypoint = rospy.Service("/telemetry/goto_waypoint", GotoWaypoint, self.command_handler.goto_waypoint, buff_size=10) self.return_home_service = rospy.Service( "/telemetry/return_home", Trigger, self.command_handler.return_home, buff_size=10) self.set_home_service = rospy.Service("/telemetry/set_home", SetHome, self.command_handler.set_home, buff_size=10) self.set_mode_service = rospy.Service("/telemetry/set_mode", SetMode, self.command_handler.set_mode, buff_size=10) self.guided_enable_service = rospy.Service( "/telemetry/guided_enable", Trigger, self.command_handler.guided_enable, buff_size=10) self.guided_disable_service = rospy.Service( "/telemetry/guided_disable", Trigger, self.command_handler.guided_disable, buff_size=10) self.change_speed_service = rospy.Service( "/telemetry/change_speed", ChangeSpeed, self.command_handler.change_speed, buff_size=10) self.dowload_mission_service = rospy.Service( "/telemetry/download_mission", Trigger, self.mission_handler.download, buff_size=10) self.mission_upload_service = rospy.Service( "/telemetry/upload_mission", UploadMission, self.mission_handler.upload, buff_size=10) self.mission_upload_from_file_service = rospy.Service( "/telemetry/upload_mission_from_file", UploadFromFile, self.mission_handler.upload_from_file, buff_size=10) self.start_tracking_service = rospy.Service( "/telemetry/start_tracking", Trigger, self.start_tracking, buff_size=10) self.stop_tracking_service = rospy.Service("/telemetry/stop_tracking", Trigger, self.stop_tracking, buff_size=10) # Topic handlers self.mavlink_msg_pub = rospy.Publisher(mavlink_lora_pub_topic, mavlink_lora_msg, queue_size=0) self.statustext_pub = rospy.Publisher("/telemetry/statustext", telemetry_statustext, queue_size=0) self.heartbeat_status_pub = rospy.Publisher( "/telemetry/heartbeat_status", telemetry_heartbeat_status, queue_size=0) self.mav_mode_pub = rospy.Publisher("/telemetry/mav_mode", telemetry_mav_mode, queue_size=0) self.vfr_hud_pub = rospy.Publisher("/telemetry/vfr_hud", telemetry_vfr_hud, queue_size=0) self.home_position_pub = rospy.Publisher("/telemetry/home_position", telemetry_home_position, queue_size=0) self.control_commands_pub = rospy.Publisher( "/telemetry/control_commands", telemetry_control_commands, queue_size=0) self.imu_ned_pub = rospy.Publisher("/telemetry/imu_data_ned", telemetry_imu_ned, queue_size=0) self.local_position_ned_pub = rospy.Publisher( "/telemetry/local_position_ned", telemetry_local_position_ned, queue_size=0) rospy.Subscriber(mavlink_lora_sub_topic, mavlink_lora_msg, self.on_mavlink_msg) rospy.Subscriber(mavlink_lora_pos_sub_topic, mavlink_lora_pos, self.on_mavlink_lora_pos) rospy.Subscriber(mavlink_lora_status_sub_topic, mavlink_lora_status, self.on_mavlink_lora_status) rospy.Subscriber("/telemetry/new_mission", mavlink_lora_mission_list, self.mission_handler.on_mission_list) rospy.Subscriber("/telemetry/mission_set_current", Int16, self.mission_handler.mission_set_current) rospy.Subscriber("/telemetry/set_landing_target", telemetry_landing_target, self.on_landing_target) rospy.Subscriber("/mavlink_interface/mission/ack", mavlink_lora_mission_ack, self.mission_handler.on_mission_ack) rospy.Subscriber("/mavlink_interface/command/ack", mavlink_lora_command_ack, self.command_handler.on_command_ack) self.rate = rospy.Rate(update_interval)
def setUp(self): create_database("tests.db") self.test_interface = command_handler.CommandHandler("tests.db")