def run(self): """ Peridocially send an announcement packet over our datalink """ tx_client = TxClient(self.tx_socket) gps_prev = None while True: logger.debug("Announcing Presence.") if self.db_retrans is not None: # Get a dict of all our current message ids msg_dict = self.db_retrans.get_message_id_dict(self.node_id) tx_client.send(G.MESSAGE_TYPE.RT_NODE_ANNOUNCEMENT, json.dumps(msg_dict)) else: tx_client.send(G.MESSAGE_TYPE.RT_NODE_ANNOUNCEMENT) # Checking for GPS if self.gps_receiver is not None and self.db_client is not None: # Get our GPS coords logger.debug("Getting GPS coordinates") gps_info = self.gps_receiver.get_coordinates() # If we got GPS data, report it. if gps_info is None: logger.error("Could not receive GPS info.") elif gps_info != gps_prev: logger.debug("Sending GPS info: %s" % gps_info) db_obj = CatanDatabaseNodeObject() db_obj.node_info.gps_latitude = gps_info['latitude'] db_obj.node_info.gps_longitude = gps_info['longitude'] db_obj.node_info.gps_altitude = gps_info['altitude'] db_obj.node_info.gps_sat_count = gps_info[ 'satillite_count'] logger.debug("Sending GPS info to databse.") self.db_client.send(G.MESSAGE_TYPE.DB_GPS, ` db_obj `) logger.debug("Sending GPS info to other nodes.") tx_client.send(G.MESSAGE_TYPE.DB_GPS, ` db_obj `) # Update previous gps_prev = gps_info # Update our time using our GPS logger.debug("Getting time/date date from GPS.") gps_time = self.gps_receiver.get_time() if gps_time is not None: logger.debug("Updated time to: %s" % gps_time) utils.linux_set_time(gps_time.timetuple()) # No reason to beat this to death time.sleep(G.RT_NODE_ANNOUNCEMENT_DELAY)
def run(self): """ Peridocially send an announcement packet over our datalink """ tx_client = TxClient(self.tx_socket) gps_prev = None while True: logger.debug("Announcing Presence.") if self.db_retrans is not None: # Get a dict of all our current message ids msg_dict = self.db_retrans.get_message_id_dict(self.node_id) tx_client.send(G.MESSAGE_TYPE.RT_NODE_ANNOUNCEMENT, json.dumps(msg_dict) ) else: tx_client.send(G.MESSAGE_TYPE.RT_NODE_ANNOUNCEMENT) # Checking for GPS if self.gps_receiver is not None and self.db_client is not None: # Get our GPS coords logger.debug("Getting GPS coordinates") gps_info = self.gps_receiver.get_coordinates() # If we got GPS data, report it. if gps_info is None: logger.error("Could not receive GPS info.") elif gps_info != gps_prev: logger.debug("Sending GPS info: %s"% gps_info) db_obj = CatanDatabaseNodeObject() db_obj.node_info.gps_latitude = gps_info['latitude'] db_obj.node_info.gps_longitude = gps_info['longitude'] db_obj.node_info.gps_altitude = gps_info['altitude'] db_obj.node_info.gps_sat_count = gps_info['satillite_count'] logger.debug("Sending GPS info to databse.") self.db_client.send(G.MESSAGE_TYPE.DB_GPS,`db_obj`) logger.debug("Sending GPS info to other nodes.") tx_client.send(G.MESSAGE_TYPE.DB_GPS,`db_obj`) # Update previous gps_prev = gps_info # Update our time using our GPS logger.debug("Getting time/date date from GPS.") gps_time = self.gps_receiver.get_time() if gps_time is not None: logger.debug("Updated time to: %s"%gps_time) utils.linux_set_time(gps_time.timetuple()) # No reason to beat this to death time.sleep(G.RT_NODE_ANNOUNCEMENT_DELAY)
parser.add_argument("-d", "--debug", action="store_true", default=False, help="Enable debugging output.") parser.add_argument("-m", "--message", type=str, default="Test", help="Message to send as data") args = parser.parse_args() if args.debug: print "* DEBUG Enabled." logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig() data = args.message # Create a TxClient client = TxClient(G.TX_DEFAULT_SOCK) rtn = client.send(0, data, destination=args.remote_node_id) if rtn: print "Sent: ", print data else: print "Error Sending message"
data = "Test" if __name__ == "__main__": import argparse parser = argparse.ArgumentParser() parser.add_argument("-r", "--remote_node_id", type=int, default=0, help="Send test message to remote node id.") parser.add_argument("-d", "--debug", action="store_true", default=False, help="Enable debugging output.") parser.add_argument("-m", "--message", type=str, default="Test", help="Message to send as data") args = parser.parse_args() if args.debug: print "* DEBUG Enabled." logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig() data = args.message # Create a TxClient client = TxClient(G.TX_DEFAULT_SOCK) rtn = client.send(0, data, destination=args.remote_node_id) if rtn: print "Sent: ", print data else: print "Error Sending message"