예제 #1
0
파일: acc.py 프로젝트: jcsy521/ydws
def handle_acc_status(info, address, connection, channel, exchange, gw_binding, db, redis):
    """
    S30
    ACC_status: 

    0: success, then record new terminal's address
    1: invalid SessionID 
    """
    try:
        head = info.head
        body = info.body
        dev_id = head.dev_id

        args = DotDict(success=GATEWAY.RESPONSE_STATUS.SUCCESS,
                       command=head.command)
        
        sessionID = QueryHelper.get_terminal_sessionID(dev_id, redis)
        if sessionID != head.sessionID: 
            args.success = GATEWAY.RESPONSE_STATUS.INVALID_SESSIONID
            logging.error("[GW] Invalid sessionID, terminal: %s", head.dev_id)
        else:
            uap = ACCStatusParser(body, head)
            t_info = uap.ret
            acc_status_info_key = get_acc_status_info_key(dev_id)
            acc_status_info = redis.getvalue(acc_status_info_key)
            if acc_status_info:  
                acc_status_info['op_status'] = 1 # success
                redis.setvalue(acc_status_info_key, acc_status_info, UWEB.ACC_STATUS_EXPIRY)
                WSPushHelper.pushS8(dev_id, 1, db, redis)
            else: # It should never occur. 
                logging.error("[GW] ACC_status can not be found. dev_id: %s",
                              dev_id)
                pass

        asc = ACCStatusComposer(args)
        request = DotDict(packet=asc.buf,
                          address=address,
                          dev_id=dev_id)
        append_gw_request(request, connection, channel, exchange, gw_binding)
    except:
        logging.exception("[GW] Handle acc status exception.")
        GWException().notify()
예제 #2
0
파일: test_wspush.py 프로젝트: jcsy521/ydws
    def post(self):
        """Acquire push account through uid

        @uid: user uid
        """
        status = ErrorCode.SUCCESS
        try:
            data = DotDict(json_decode(self.request.body))
            tid = data.tid
            s_type = data.s_type
            if data.get("category", None):
                category = int(data.get("category"))
            else:
                category = 1

            logging.info("[UWEB] Test wspush request: %s.", data)
        except Exception as e:
            status = ErrorCode.ILLEGAL_DATA_FORMAT
            logging.exception("[UWEB] Invalid data format. body: %s, Exception: %s", self.request.body, e.args)
            self.write_ret(status)
            return

        try:
            # user = self.db.get("select owner_mobile")
            user = QueryHelper.get_user_by_tid(tid, self.db)
            uid = user.owner_mobile
            if s_type == "S3":
                WSPushHelper.pushS3(tid, self.db, self.redis)
            elif s_type == "S4":
                WSPushHelper.pushS4(tid, self.db, self.redis)
            elif s_type == "S5":
                body = dict(
                    tid=tid,
                    category=category,
                    pbat=100,
                    type=1,
                    timestamp=int(time.time()),
                    longitude=419004000,
                    latitude=143676000,
                    clongitude=419004000,
                    clatitude=143676000,
                    name="test name",
                    speed=111,
                    degree=203,
                    gsm=0,
                    locate_error=100,
                    gps=25,
                    alias="111",
                    region_id=11,
                )
                WSPushHelper.pushS5(tid, body, self.db, self.redis)
            elif s_type == "S6":
                WSPushHelper.pushS6(tid, self.db, self.redis)
            elif s_type == "S7":
                WSPushHelper.pushS7(tid, self.db, self.redis)
            elif s_type == "S8":
                acc_message = 1
                WSPushHelper.pushS8(tid, acc_message, self.db, self.redis)

            self.write_ret(status=status)
        except Exception as e:
            logging.exception("[UWEB] WSPushHandler get push account failed, Exception:%s", e.args)
            status = ErrorCode.SERVER_BUSY
            self.write_ret(status)