Exemple #1
0
 def get_agps_from_ublox(self):
     LON_LAT = GATEWAY.LON_LAT
     for key, lon_lat in LON_LAT.items():
         u_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         try:
             request = "cmd=aid;user=%s;pwd=%s;lat=%s;lon=%s;pacc=%s\n" % (
                                                 ConfHelper.UBLOX_CONF.user,
                                                 ConfHelper.UBLOX_CONF.pwd,
                                                 lon_lat[1],
                                                 lon_lat[0],
                                                 ConfHelper.UBLOX_CONF.pacc)
             u_socket.connect((ConfHelper.UBLOX_CONF.host, int(ConfHelper.UBLOX_CONF.port)))
             u_socket.send(request)
             agps_data = self.recv_ublox(u_socket) 
             agps_key = get_agps_data_key(key)
             if agps_data:
                 self.redis.set(agps_key, base64.b64encode(agps_data))
                 logging.info("[AGPS] Get agps data [%s] from ublox success.", key)
             else:
                 self.redis.delete(agps_key)
                 logging.info("[AGPS] Get agps data [%s] from ublox faild.", key)
         except:
             logging.exception("[AGPS] Get agps from u-blox exception.")
         finally:
             try:
                 u_socket.close()
             except:
                 logging.exception("[AGPS] U-blox socket close exception.")               
         time.sleep(10)
Exemple #2
0
 def get_agps_from_redis(self, agps):
     try:
         logging.info("[AGPS] Terminal lon=%s, lat=%s", agps.lon, agps.lat)
         partition_key = self.get_partition_key(float(agps.lon), float(agps.lat))
         agps_key = get_agps_data_key(partition_key)
         agps_data = self.redis.get(agps_key)
         agps_data = agps_data if agps_data else ""
         return agps_data
     except:
         logging.exception("[AGPS] Get agps from redis exception.")
         return ""