def get_command_collection(): """Get command collection from the drone server.""" get_command_collection_ = RES_DRONE.find_suitable_operation(None, None, DRONE1.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
def add_command(command): """Add command to drone server.""" add_command_ = RES_DRONE.find_suitable_operation(SCHEMA.AddAction, DRONE1.Command) resp, body = add_command_(command) assert resp.status in [200, 201], "%s %s" % (resp.status, resp.reason) new_command = Resource.from_iri(resp['location']) print("Command posted successfully.") return new_command
def add_datastream(datastream): """Update the drone datastream on drone server.""" try: update_datastream_ = RES_DRONE.find_suitable_operation( operation_type=SCHEMA.AddAction, input_type=DRONE.Datastream) resp, body = update_datastream_(datastream) 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
def add_command(command): """Add command to drone server.""" try: add_command_ = RES_DRONE.find_suitable_operation( SCHEMA.AddAction, DRONE.Command) resp, body = add_command_(command) assert resp.status in [200, 201], "%s %s" % (resp.status, resp.reason) new_command = Resource.from_iri(resp['location']) print("Command posted successfully.") return new_command except Exception as e: print(e) return None
def get_command_collection(): """Get command collection from the drone server.""" try: get_command_collection_ = RES_DRONE.find_suitable_operation( None, None, DRONE.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
def add_drone_locally(drone): """Add the drone object to the central server and return Id.""" try: add_drone_ = RES_DRONE.find_suitable_operation(SCHEMA.AddAction, DRONE.Drone) resp, body = add_drone_(drone) assert resp.status in [200, 201], "%s %s" % (resp.status, resp.reason) drone_id = resp['location'].split("/")[-1] return drone_id except Exception as e: print(e) print("Using default id instead") return -1000
def add_drone_locally(drone): """Add the drone object to the central server and return Id.""" try: add_drone_ = RES_DRONE.find_suitable_operation( SCHEMA.AddAction, DRONE.Drone) resp, body = add_drone_(drone) assert resp.status in [200, 201], "%s %s" % (resp.status, resp.reason) drone_id = resp['location'].split("/")[-1] return drone_id except Exception as e: print(e) print("Using default id instead") return -1000
def get_anomaly(): """Get the anomaly from drone server.""" try: get_anomaly_ = RES_DRONE.find_suitable_operation( operation_type=None, input_type=None, output_type=DRONE.Anomaly) resp, body = get_anomaly_() assert resp.status in [200, 201], "%s %s" % (resp.status, resp.reason) anomaly = json.loads(body.decode('utf-8')) anomaly.pop("@context", None) anomaly.pop("@id", None) return anomaly except Exception as e: print(e) return None
def get_datastream(): """Get the drone datastream from drone server.""" try: get_datastream_ = RES_DRONE.find_suitable_operation( operation_type=None, input_type=None, output_type=DRONE.Datastream) resp, body = get_datastream_() assert resp.status in [200, 201], "%s %s" % (resp.status, resp.reason) datastream = json.loads(body.decode('utf-8')) # remove extra contexts from datastream datastream.pop("@context", None) datastream.pop("@id", None) return datastream except Exception as e: print(e) return None