예제 #1
0
def xbee_callback(compressed_message, autonomyToCV):
    global search_area
    global comm_sim_on
    if (comm_sim_on):
        message = compressed_message
    else:
        message = msgpack.unpackb(compressed_message)
    address = message.remote_device.get_64bit_addr()
    msg = json.loads(message.data)
    print("Received data from %s: %s" % (address, msg))

    try:
        msg_type = msg["type"]

        if msg_type == "addMission":
            area = msg["missionInfo"]["searchArea"]
            search_area = SearchArea(area["topLeft"], area["topRight"],
                                     area["bottomLeft"], area["bottomRight"])
            autonomy.start_mission = True
            acknowledge(address, msg["id"], autonomyToCV)

        elif msg_type == "pause":
            autonomy.pause_mission = True
            acknowledge(address, msg["id"], autonomyToCV)

        elif msg_type == "resume":
            autonomy.pause_mission = False
            acknowledge(address, msg["id"], autonomyToCV)

        elif msg_type == "stop":
            autonomy.stop_mission = True
            acknowledge(address, msg["id"], autonomyToCV)

        elif msg_type == "ack":
            autonomy.ack_id = msg["ackid"]

        else:
            bad_msg(address, "Unknown message type: \'" + msg_type + "\'",
                    autonomyToCV)

    # KeyError if message was missing an expected key
    except KeyError as e:
        bad_msg(address, "Missing \'" + e.args[0] + "\' key", autonomyToCV)
예제 #2
0
def xbee_callback(message):
    global search_area

    address = message.remote_device.get_64bit_addr()
    msg = json.loads(message.data)
    print("Received data from %s: %s" % (address, msg))

    try:
        msg_type = msg["type"]

        if msg_type == "addMission":
            area = msg["searchArea"]
            search_area = SearchArea(area["center"], area["rad1"],
                                     area["rad2"])
            autonomy.start_mission = True
            acknowledge(address, msg["id"])

        elif msg_type == "pause":
            autonomy.pause_mission = True
            acknowledge(address, msg["id"])

        elif msg_type == "resume":
            autonomy.pause_mission = False
            acknowledge(address, msg["id"])

        elif msg_type == "stop":
            autonomy.stop_mission = True
            acknowledge(address, msg["id"])

        elif msg_type == "acknowledge":
            # TODO check the ID
            pass

        else:
            bad_msg(address, "Unknown message type: \'" + msg_type + "\'")

    # KeyError if message was missing an expected key
    except KeyError as e:
        bad_msg(address, "Missing \'" + e.args[0] + "\' key")
예제 #3
0
def xbee_callback(message):
    address = message.remote_device.get_64bit_addr()
    msg = json.loads(message.data)
    print("Received data from %s: %s" % (address, msg))

    try:
        msg_type = msg["type"]

        if msg_type == "start":
            autonomy.start_mission = True
            acknowledge(address, msg_type)

        elif msg_type == "addMission":
            msg_lat = msg['missionInfo']['lat']
            msg_lon = msg['missionInfo']['lon']

            # convert mission coordinates to dronekit object, and add to POI queue
            POI_queue.put(LocationGlobalRelative(msg_lat, msg_lon, None))
            acknowledge(address, msg_type)

        elif msg_type == "pause":
            autonomy.pause_mission = True
            acknowledge(address, msg_type)

        elif msg_type == "resume":
            autonomy.pause_mission = False
            acknowledge(address, msg_type)

        elif msg_type == "stop":
            autonomy.stop_mission = True
            acknowledge(address, msg_type)

        else:
            bad_msg(address, "Unknown message type: \'" + msg_type + "\'")

    # KeyError if message was missing an expected key
    except KeyError as e:
        bad_msg(address, "Missing \'" + e.args[0] + "\' key")
예제 #4
0
def xbee_callback(message):
    global gcs_timestamp
    global connection_timestamp

    address = message.remote_device.get_64bit_addr()
    msg = json.loads(message.data)
    print("Received data from %s: %s" % (address, msg))

    try:
        msg_type = msg["type"]

        if msg_type == "connectionAck":
            gcs_timestamp = msg['clocktime']
            connection_timestamp = time.time()
            autonomy.ack_id = msg["ackid"]

        elif msg_type == "start":
            # detach this callback so that the corresponding role can use its own callback
            xbee.del_data_received_callback(xbee_callback)
            xbee.close()

            job_type = msg['jobType']
            if job_type == "quickScan":
                quick_scan(gcs_timestamp=gcs_timestamp,
                           connection_timestamp=connection_timestamp)
            elif job_type == "detailedSearch":
                detailed_search(gcs_timestamp=gcs_timestamp,
                                connection_timestamp=connection_timestamp)
            elif job_type == "guide":
                # TODO
                pass
            else:
                bad_msg(address, "Unknown jobType: \'" + job_type + "\'")

        else:
            bad_msg(address, "Unknown message type: \'" + msg_type + "\'")

    # KeyError if message was missing an expected key
    except KeyError as e:
        bad_msg(address, "Missing \'" + e.args[0] + "\' key")