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")
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 == "start": acknowledge(address, msg_type) elif msg_type == "addMission": area = msg["searchArea"] search_area = SearchArea(area["center"], area["rad1"], area["rad2"]) autonomy.start_mission = True 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")
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)