Ejemplo n.º 1
0
def get_anomaly_collection():
    """Get the anomaly from central server."""
    try:
        get_anomaly_collection_ = RES_CS.find_suitable_operation(
            operation_type=None,
            input_type=None,
            output_type=CENTRAL_SERVER.AnomalyCollection)
        resp, body = get_anomaly_collection_()
        assert resp.status in [200, 201], "%s %s" % (resp.status, resp.reason)

        anomalies = json.loads(body.decode('utf-8'))
        anomalies.pop("@context", None)
        anomalies.pop("@id", None)

        anomaly_list = list()
        for anomaly in anomalies["members"]:
            regex = r'/(.*)/(\d)'
            matchObj = re.match(regex, anomaly["@id"])
            if matchObj:
                anomaly = get_anomaly(matchObj.group(2))
                anomaly_list.append(anomaly)
        return anomaly_list

    except ConnectionRefusedError:
        raise ConnectionRefusedError(
            "Connection Refused! Please check the drone server.")
Ejemplo n.º 2
0
def get_data_collection():
    """Get command collection from the central server."""
    get_data_collection_ = RES_CS.find_suitable_operation(None, None, CENTRAL_SERVER.DatastreamCollection)
    resp, body = get_data_collection_()
    assert resp.status in [200, 201], "%s %s" % (resp.status, resp.reason)

    body = json.loads(body.decode('utf-8'))
    return body
Ejemplo n.º 3
0
def create_command(command):
    """Add a command entity to the central server."""
    create_command_ = RES_CS.find_suitable_operation(SCHEMA.AddAction, CENTRAL_SERVER.Command)
    resp, body = create_command_(command)

    assert resp.status in [200, 201], "%s %s" % (resp.status, resp.reason)
    new_command = Resource.from_iri(resp['location'])
    print("Command created successfully.")
    return new_command
def send_http_api_log(http_api_log):
    """Post the drone http Api Log to the central server."""
    post_http_api_log = RES_CS.find_suitable_operation(SCHEMA.AddAction, CENTRAL_SERVER.HttpApiLog)
    resp, body = post_http_api_log(http_api_log)

    assert resp.status in [200, 201], "%s %s" % (resp.status, resp.reason)
    new_http_api_log = Resource.from_iri(resp['location'])
    print("Http Api Log posted successfully.")
    return new_http_api_log
def add_location(location):
    """Update the area of interest on central server."""
    add_location_ = RES_CS.find_suitable_operation(
                   operation_type=SCHEMA.AddAction,
                   input_type=CENTRAL_SERVER.Location)
    resp, body = add_location_(location)
    assert resp.status in [200, 201], "%s %s" % (resp.status, resp.reason)

    return Resource.from_iri(resp['location'])
def get_command_collection():
    """Get command collection from the central server."""
    try:
        get_command_collection_ = RES_CS.find_suitable_operation(
            None, None, CENTRAL_SERVER.CommandCollection)
        resp, body = get_command_collection_()
        assert resp.status in [200, 201], "%s %s" % (resp.status, resp.reason)

        body = json.loads(body.decode('utf-8'))
        return body["members"]
    except Exception as e:
        print(e)
        return None
Ejemplo n.º 7
0
def update_location(location):
    """Update the area of interest on central server."""
    try:
        update_location_ = RES_CS.find_suitable_operation(
            operation_type=SCHEMA.UpdateAction,
            input_type=CENTRAL_SERVER.Location)
        resp, body = update_location_(location)
        assert resp.status in [200, 201], "%s %s" % (resp.status, resp.reason)

        return Resource.from_iri(resp['location'])
    except Exception as e:
        print(e)
        return None
Ejemplo n.º 8
0
def send_controllerlog(controllerlog):
    """Post the controller log to the central server."""
    try:
        post_controllerlog = RES_CS.find_suitable_operation(
            SCHEMA.AddAction, CENTRAL_SERVER.ControllerLog)
        resp, body = post_controllerlog(controllerlog)

        assert resp.status in [200, 201], "%s %s" % (resp.status, resp.reason)
        new_controllerlog = Resource.from_iri(resp['location'])
        print("Controller Log successfully.")
        return new_controllerlog
    except Exception as e:
        print(e)
        return None
Ejemplo n.º 9
0
def get_anomaly_collection():
    """Get the anomaly collection from central server."""
    try:
        get_anomaly_collection_ = RES_CS.find_suitable_operation(
            operation_type=None,
            input_type=None,
            output_type=CENTRAL_SERVER.AnomalyCollection)
        resp, body = get_anomaly_collection_()
        assert resp.status in [200, 201], "%s %s" % (resp.status, resp.reason)

        anomalies = json.loads(body.decode('utf-8'))
        anomalies.pop("@context", None)
        anomalies.pop("@id", None)
        return anomalies["members"]

    except Exception as e:
        print(e)
        return None
def get_drone_collection():
    """Get the collection of drones from the server."""
    get_drone_collection_ = RES_CS.find_suitable_operation(
        None, None, CENTRAL_SERVER.DroneCollection)
    resp, body = get_drone_collection_()
    assert resp.status in [200, 201], "%s %s" % (resp.status, resp.reason)
    body = json.loads(body.decode('utf-8'))

    body.pop("@context")
    body.pop("@type")

    drone_list = list()
    for drone in body["members"]:
        regex = r'/(.*)/(\d)'
        matchObj = re.match(regex, drone["@id"])
        if matchObj:
            drone = get_drone(matchObj.group(2))
            drone_list.append(drone)
    return drone_list