Beispiel #1
0
def top_secret():
    """Flask API to obtain the location of the cargo ship and the message.
    """
    sat1 = Satelite('kenobi', 0, 0)
    sat2 = Satelite('skywalker', 3, 0)
    sat3 = Satelite('sato', 5, 3)
    trilateration = Trilateration([sat1, sat2, sat3])
    decoder = MessageDecoder()

    if request.method == 'POST':
        try:
            request_data = request.get_json()
            satellites = request_data["satellites"]
            trilat_distances = list()
            received_msgs = list()
            for satellite in satellites:
                trilat_distances.append(satellite['distance'])
                received_msgs.append(satellite['message'])
            ship_pos = trilateration.get_location(trilat_distances)
            message_decoded = decoder.get_messages(received_msgs)
            response = {
                "position": {
                    "x": str(ship_pos[0]),
                    "y": str(ship_pos[1])
                },
                "message": message_decoded
            }
        except Exception:
            response = {
                "msg": "The message or the position of the ship \
                    could not be determined. Please check the payload."
            }
            return response, STATUS_ERROR
        return response, STATUS_OK
    return 'Invalid request.', 404
Beispiel #2
0
def main(datafile=DEF_FILE_NAME):
    data = read_data(datafile)
    drone_data = read_drone_data()
    drone_locs = {}

    for index, row in drone_data.iterrows():
        drone_locs[row["drone_id"]] = [float(row["x_m"]), float(row["y_m"]), float(row["z_m"])]

    time_grouped = group_data(data[PI_MAC], 0)
    sensors_per_time = []

    for time_group in time_grouped:
        ap_ids = []
        sensors = []
        used_sensors = set()
        sorted_data = sorted(time_group[1], key=lambda x: x[2])

        for sensor in sorted_data:
            if(sensor[1] in used_sensors):
                continue
            used_sensors.add(sensor[1])

            try:
                loc = drone_locs[sensor[1]]
            except KeyError:
                continue

            ap_ids.append(sensor[1])

            sensors.append({'x': loc[0],
                            'y': loc[1],
                            'z': loc[2],
                            'signal': int(sensor[2])})

        if count_unique_aps(ap_ids) > 3:
            sensors_per_time.append([time_group[0], sensors])
        else:
            print('JAMMER')

    for param in range(0, 301, 5):
        gamma = param / 100

        with open("../results/trilateration/results_trilateration_{}_{}.csv".format(SECONDS_GROUPING, gamma), "a") as f:
            writer = csv.writer(f, delimiter=";")
            writer.writerow(["sourcemac", "timestamp", "x_m", "y_m", "z_m", "eta"])

            trilateration = Trilateration(gamma)

            for row in sensors_per_time:
                est = trilateration.get_location(row[1])
                writer.writerow([PI_MAC, row[0]] + list(est.x))