Exemplo n.º 1
0
    def post():
        """Upload a new sector definition"""

        req_args = utils.parse_args(_PARSER)

        sector_name = req_args["name"]

        if not sector_name:
            return responses.bad_request_resp("Sector name must be provided")

        sector_json = req_args["content"]

        if sector_json:
            sector_element = validate_geojson_sector(sector_json)
            if not isinstance(sector_element, SectorElement):
                return responses.bad_request_resp(
                    f"Invalid sector content: {sector_element}"
                )
        else:
            sector_element = None

        sector = SectorWrapper(sector_name, sector_element)
        err = utils.sim_proxy().simulation.load_sector(sector)

        return responses.checked_resp(err, HTTPStatus.CREATED)
Exemplo n.º 2
0
    def post():
        """Logic for POST events"""

        req_args = utils.parse_args(_PARSER)

        if not utils.sim_proxy().simulation.sector:
            return responses.bad_request_resp(
                "A sector definition is required before uploading a scenario")

        # TODO(rkm 2020-01-12) Should never include the file extension
        name = req_args["name"]
        if not name:
            return responses.bad_request_resp("Scenario name must be provided")

        content = req_args["content"]

        if content:
            err = validate_json_scenario(content)
            if err:
                return responses.bad_request_resp(
                    f"Invalid scenario content: {err}")

        scenario = ScenarioWrapper(name, content)
        err = utils.sim_proxy().simulation.load_scenario(scenario)

        return responses.checked_resp(err, HTTPStatus.CREATED)
Exemplo n.º 3
0
    def post():
        """
        Logic for POST events. If the request contains valid aircraft information, then
        a request is sent to the simulator to create it
        """

        req_args = utils.parse_args(_PARSER)
        callsign = req_args[utils.CALLSIGN_LABEL]

        resp = utils.check_exists(utils.sim_proxy(), callsign, negate=True)
        if resp:
            return resp

        position_or_resp = utils.try_parse_lat_lon(req_args)
        if not isinstance(position_or_resp, LatLon):
            return position_or_resp

        if not req_args["type"]:
            return responses.bad_request_resp(
                "Aircraft type must be specified")

        err = utils.sim_proxy().aircraft.create(
            callsign,
            req_args["type"],
            position_or_resp,
            req_args["hdg"],
            req_args["alt"],
            req_args["gspd"],
        )

        return responses.checked_resp(err, HTTPStatus.CREATED)
Exemplo n.º 4
0
Arquivo: op.py Projeto: rkm/bluebird
    def post():
        """Logic for post events"""

        if Settings.SIM_MODE != SimMode.Sandbox:
            return responses.bad_request_resp(
                f"Can't resume sim from mode {Settings.SIM_MODE.name}")

        err = utils.sim_proxy().simulation.resume()

        return responses.checked_resp(err)
Exemplo n.º 5
0
    def post():
        """Logic for POST events"""

        if Settings.SIM_MODE != SimMode.Agent:
            return responses.bad_request_resp(
                "Must be in agent mode to use step")

        err = utils.sim_proxy().simulation.step()

        return responses.checked_resp(err)
Exemplo n.º 6
0
Arquivo: seed.py Projeto: rkm/bluebird
    def post():
        """Logic for POST events. Sets the seed of the simulator"""

        req_args = utils.parse_args(_PARSER)
        seed: int = req_args["value"]

        if not is_valid_seed(seed):
            return responses.bad_request_resp(
                "Invalid seed specified. Must be a positive integer less than 2^32"
            )

        err = utils.sim_proxy().simulation.set_seed(seed)
        return responses.checked_resp(err)
Exemplo n.º 7
0
    def post():
        """Logic for POST events. Sets the speed multiplier for the simulation"""

        req_args = utils.parse_args(_PARSER)
        multiplier = round(req_args["multiplier"], 2)

        if multiplier <= 0:
            return responses.bad_request_resp(
                "Multiplier must be greater than 0")

        # TODO Check if we still need to keep track of step_dt in the client
        err = utils.sim_proxy().simulation.set_speed(multiplier)

        return responses.checked_resp(err)
Exemplo n.º 8
0
Arquivo: alt.py Projeto: rkm/bluebird
    def post():
        """
        Logic for POST events. If the request contains an existing aircraft ID, then a
        request is sent to alter its altitude
        """

        req_args = utils.parse_args(_PARSER_POST)
        callsign: Callsign = req_args[utils.CALLSIGN_LABEL]
        fl_cleared: Altitude = req_args["alt"]

        err = utils.sim_proxy().aircraft.set_cleared_fl(
            callsign, fl_cleared, vspd=req_args.get("vspd"))

        return responses.checked_resp(err)
Exemplo n.º 9
0
    def post():
        """
        Logic for POST events. If the request contains an existing aircraft ID, then a
        request is sent to alter its ground speed
        """

        req_args = utils.parse_args(_PARSER)

        callsign = req_args[utils.CALLSIGN_LABEL]
        resp = utils.check_exists(utils.sim_proxy(), callsign)
        if resp:
            return resp

        err = utils.sim_proxy().aircraft.set_ground_speed(callsign, req_args["gspd"])

        return checked_resp(err)
Exemplo n.º 10
0
    def post():
        """
        Logic for POST events. If the request contains an existing aircraft ID, then a
        request is sent to alter its heading
        """

        req_args = utils.parse_args(_PARSER)

        callsign = req_args[utils.CALLSIGN_LABEL]
        resp = utils.check_exists(utils.sim_proxy(), callsign)
        if resp:
            return resp

        heading = req_args["hdg"]

        err = utils.sim_proxy().aircraft.set_heading(callsign, heading)

        return responses.checked_resp(err)
Exemplo n.º 11
0
    def post():
        """
        Requests that the specified aircraft proceeds immediately to the specified
        waypoint
        """

        req_args = utils.parse_args(_PARSER)
        waypoint_name = req_args["waypoint"]

        if not waypoint_name:
            return responses.bad_request_resp(
                "Waypoint name must be specified")

        callsign = req_args[utils.CALLSIGN_LABEL]

        resp = utils.check_exists(utils.sim_proxy(), callsign)
        if resp:
            return resp

        err = utils.sim_proxy().aircraft.direct_to_waypoint(
            callsign, waypoint_name)

        return responses.checked_resp(err)
Exemplo n.º 12
0
    def post():
        """Logic for POST events. Resets and clears the simulation"""

        err = utils.sim_proxy().simulation.reset()

        return properties.checked_resp(err)