Example #1
0
    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)
Example #2
0
    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)
Example #3
0
"""
    This is a simple example script showing our GPS module
    
    (c) 2015 Massachusetts Institute of Technology
"""

# CATAN
import catan.utils as utils
from catan.gps import GPSReceiver

if __name__ == "__main__":

    gps = GPSReceiver(serial_interface="/dev/ttyUSB1")

    while True:
        coords = gps.get_coordinates()

        print coords

        time = gps.get_time()

        if time is not None:
            print time.timetuple()
            utils.linux_set_time(time.timetuple())
Example #4
0
"""
    This is a simple example script showing our GPS module
    
    (c) 2015 Massachusetts Institute of Technology
"""

# CATAN
import catan.utils as utils
from catan.gps import GPSReceiver


if __name__ == "__main__":
    
    gps = GPSReceiver(serial_interface="/dev/ttyUSB1")
        
    while True:
        coords = gps.get_coordinates()
        
        print coords
        
        time = gps.get_time()
        
        if time is not None:
            print time.timetuple()
            utils.linux_set_time(time.timetuple())