当前位置: 首页>>代码示例>>Python>>正文


Python QueryHelper.get_terminal_sessionID方法代码示例

本文整理汇总了Python中helpers.queryhelper.QueryHelper.get_terminal_sessionID方法的典型用法代码示例。如果您正苦于以下问题:Python QueryHelper.get_terminal_sessionID方法的具体用法?Python QueryHelper.get_terminal_sessionID怎么用?Python QueryHelper.get_terminal_sessionID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在helpers.queryhelper.QueryHelper的用法示例。


在下文中一共展示了QueryHelper.get_terminal_sessionID方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_fob_info

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_terminal_sessionID [as 别名]
def handle_fob_info(info, address, connection, channel, exchange, gw_binding, db, redis):
    """
    S19 
    NOTE: deprecated 

    fob info packet: add or remove fob
    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)
        sessionID = QueryHelper.get_terminal_sessionID(dev_id, redis)
        if sessionID != head.sessionID:
            args.success = GATEWAY.RESPONSE_STATUS.INVALID_SESSIONID 
        else:
            fp = FobInfoParser(body, head)
            fobinfo = fp.ret
            update_terminal_status(redis, head.dev_id, address)
            update_fob_info(db, redis, fobinfo)

        fc = FobInfoRespComposer(args)
        request = DotDict(packet=fc.buf,
                          address=address,
                          dev_id=dev_id)
        append_gw_request(request, connection, channel, exchange, gw_binding)
    except:
        logging.exception("[GW] Handle fob info report exception.")
        GWException().notify()
开发者ID:jcsy521,项目名称:ydws,代码行数:33,代码来源:fob.py

示例2: handle_acc_status_report

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_terminal_sessionID [as 别名]
def handle_acc_status_report(info, address, connection, channel, exchange, gw_binding, db, redis):
    """
    S31
    ACC_status_report: 

    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 = ACCStatusReportParser(body, head)
            t_info = uap.ret
            #NOTE: Just record it in db.
            db.execute("INSERT INTO T_ACC_STATUS_REPORT(tid, category, timestamp)"
                       "  VALUES(%s, %s, %s)",
                       t_info['dev_id'], t_info['category'], t_info['timestamp'])
        asc = ACCStatusReportComposer(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 report exception.")
        GWException().notify()
开发者ID:jcsy521,项目名称:ydws,代码行数:36,代码来源:acc.py

示例3: handle_sleep

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_terminal_sessionID [as 别名]
def handle_sleep(info, address, connection, channel, exchange, gw_binding, db, redis):
    """
    S21
    sleep status packet: 0-sleep, 1-LQ
    0: success, then record new terminal's address
    1: invalid SessionID
    """
    try:
        head = info.head
        body = info.body
        dev_id = head.dev_id

        resend_key, resend_flag = get_resend_flag(redis, dev_id, head.timestamp, head.command) 

        args = DotDict(success=GATEWAY.RESPONSE_STATUS.SUCCESS,
                       command=head.command)
        sessionID = QueryHelper.get_terminal_sessionID(dev_id, redis)
        is_sleep = False
        if sessionID != head.sessionID:
            args.success = GATEWAY.RESPONSE_STATUS.INVALID_SESSIONID 
        else:
            if resend_flag:
                logging.warn("[GW] Recv resend packet, head: %s, body: %s and drop it!",
                             info.head, info.body)
            else: 
                redis.setvalue(resend_key, True, GATEWAY.RESEND_EXPIRY)
                hp = AsyncParser(body, head)
                sleep_info = hp.ret 
                if sleep_info['sleep_status'] == '0':
                    sleep_info['login'] = GATEWAY.TERMINAL_LOGIN.SLEEP
                    #self.send_lq_sms(head.dev_id)
                    #logging.info("[GW] Recv sleep packet, LQ it: %s", head.dev_id)
                    is_sleep = True
                elif sleep_info['sleep_status'] == '1':
                    sleep_info['login'] = GATEWAY.TERMINAL_LOGIN.ONLINE
                else:
                    logging.info("[GW] Recv wrong sleep status: %s", sleep_info)
                del sleep_info['sleep_status']
                update_terminal_info(db, redis, sleep_info)

            update_terminal_status(redis, dev_id, address, is_sleep)

        if args['success'] == GATEWAY.RESPONSE_STATUS.SUCCESS: 
            acc_status_info_key = get_acc_status_info_key(dev_id) 
            acc_status_info = redis.getvalue(acc_status_info_key) 
            if acc_status_info and (not acc_status_info['t2_status']): # T2(query) is need
                args['success'] = 3 # acc_status is changed 
                logging.info("[GW] ACC_status is changed, dev_id: %s, acc_status_info: %s", 
                             dev_id, acc_status_info)

        hc = AsyncRespComposer(args)
        request = DotDict(packet=hc.buf,
                          address=address,
                          dev_id=dev_id)
        append_gw_request(request, connection, channel, exchange, gw_binding)
    except:
        logging.exception("[GW] Handle sleep status report exception.")
        GWException().notify()
开发者ID:jcsy521,项目名称:ydws,代码行数:60,代码来源:sleep.py

示例4: handle_fob_status

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_terminal_sessionID [as 别名]
def handle_fob_status(info, address, connection, channel, exchange, gw_binding, db, redis):
    """
    S22 
    NOTE: deprecated 
    fob status packet: 0-no fob near, 1-have fob near
    0: success, then record new terminal's address
    1: invalid SessionID
    """
    try:
        head = info.head
        body = info.body
        dev_id = head.dev_id

        resend_key, resend_flag = get_resend_flag(redis, dev_id, head.timestamp, head.command) 

        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 
        else:
            if resend_flag:
                logging.warn("[GW] Recv resend packet, head: %s, body: %s and drop it!",
                             info.head, info.body)
            else: 
                redis.setvalue(resend_key, True, GATEWAY.RESEND_EXPIRY)
                hp = AsyncParser(body, head)
                fob_info = hp.ret 
                info = DotDict(fob_status=fob_info['fob_status'],
                               dev_id=fob_info['dev_id'])
                update_terminal_info(db, redis, fob_info)
            update_terminal_status(redis, head.dev_id, address)

        hc = AsyncRespComposer(args)
        request = DotDict(packet=hc.buf,
                          address=address,
                          dev_id=dev_id)
        append_gw_request(request, connection, channel, exchange, gw_binding)
    except:
        logging.exception("[GW] Handle fob status report exception.")
        GWException().notify()
开发者ID:jcsy521,项目名称:ydws,代码行数:44,代码来源:fob.py

示例5: handle_acc_status

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_terminal_sessionID [as 别名]
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()
开发者ID:jcsy521,项目名称:ydws,代码行数:44,代码来源:acc.py

示例6: handle_misc

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_terminal_sessionID [as 别名]
def handle_misc(info, address, connection, channel, exchange, gw_binding, db, redis):
    """
    S28
    misc: debugging for terminal.

    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 = MiscParser(body, head)
            t_info = uap.ret
            db.execute("UPDATE T_TERMINAL_INFO"
                       " SET misc = %s"
                       "    WHERE tid = %s ",
                       t_info['misc'], head.dev_id)

        if args['success'] == GATEWAY.RESPONSE_STATUS.SUCCESS: 
            acc_status_info_key = get_acc_status_info_key(dev_id) 
            acc_status_info = redis.getvalue(acc_status_info_key) 
            if acc_status_info and (not acc_status_info['t2_status']): # T2(query) is need
                args['success'] = 3 # acc_status is changed 
                logging.info("[GW] ACC_status is changed, dev_id: %s, acc_status_info: %s", 
                             dev_id, acc_status_info)
        uac = MiscComposer(args)
        request = DotDict(packet=uac.buf,
                          address=address,
                          dev_id=dev_id)
        append_gw_request(request, connection, channel, exchange, gw_binding)
    except:
        logging.exception("[GW] Handle misc report exception.")
        GWException().notify()
开发者ID:jcsy521,项目名称:ydws,代码行数:44,代码来源:misc.py

示例7: handle_heartbeat

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_terminal_sessionID [as 别名]
def handle_heartbeat(info, address, connection, channel, exchange, gw_binding,db, redis):
    """
    S2
    heartbeat packet

    0: success, then record new terminal's address
    1: invalid SessionID 
    3: acc_status is changed 
    """
    try:
        head = info.head
        body = info.body
        dev_id = head.dev_id
        args = DotDict(success=GATEWAY.RESPONSE_STATUS.SUCCESS)
        old_softversion = False # if version < 2.4.0, true; else false.
        sessionID = QueryHelper.get_terminal_sessionID(dev_id, redis)

        if sessionID != head.sessionID:
            args.success = GATEWAY.RESPONSE_STATUS.INVALID_SESSIONID 
        else:
            hp = HeartbeatParser(body, head)
            heartbeat_info = hp.ret 
            is_sleep = False
            if heartbeat_info['sleep_status'] == '0':
                heartbeat_info['login'] = GATEWAY.TERMINAL_LOGIN.SLEEP
                is_sleep = True
            elif heartbeat_info['sleep_status'] == '1':
                heartbeat_info['login'] = GATEWAY.TERMINAL_LOGIN.ONLINE
                is_sleep = False
            elif heartbeat_info['sleep_status'] == '2': # query mode
                acc_status_info_key = get_acc_status_info_key(dev_id)
                acc_status_info = redis.getvalue(acc_status_info_key)
                if acc_status_info and int(acc_status_info['op_status']) == 0:  
                    args.timestamp = acc_status_info['timestamp']
                    args.op_type = acc_status_info['op_type']
                    # modify t2_status in acc_status_info
                    acc_status_info['t2_status'] = 1 # T2 query occurs 
                    redis.setvalue(acc_status_info_key, acc_status_info, UWEB.ACC_STATUS_EXPIRY)
                else: # if acc_status_info['op_status'] is 1, or no acc_status_info, set op_type is 2
                    args.timestamp = '' 
                    args.op_type = 2 # wait 


            else: #NOTE: it should never occur
                logging.error("[GW] Recv wrong sleep status: %s", heartbeat_info)
            del heartbeat_info['sleep_status']


            update_terminal_status(redis, head.dev_id, address, is_sleep)
            update_terminal_info(db, redis, heartbeat_info)

        if args['success'] == GATEWAY.RESPONSE_STATUS.SUCCESS:
            acc_status_info_key = get_acc_status_info_key(dev_id)
            acc_status_info = redis.getvalue(acc_status_info_key)
            if acc_status_info and (not acc_status_info['t2_status']): # T2(query) is need
                args['success'] = 3 # acc_status is changed
                logging.info("[GW] ACC_status is changed, dev_id: %s, acc_status_info: %s", 
                             dev_id, acc_status_info)

            #NOTE: check the version. 
            # if version is less than 2.4.0(not include 2.4.0), only has  success in args
            softversion = heartbeat_info['softversion']
            item = softversion.split(".")
            if int(item[0]) > 2:
                pass
            else: # A.B.C  A <= 2
                if int(item[1]) < 4: # A.B.C  B <= 4 
                    old_softversion = True
                else:
                    pass

        if old_softversion:
            logging.info("[GW] Old softversion(<2.4.0): %s, only success is provided in S2",
                         softversion)
            args = dict(success=args['success'])
        
        hc = HeartbeatRespComposer(args)
        request = DotDict(packet=hc.buf,
                          address=address,
                          dev_id=dev_id)
        append_gw_request(request, connection, channel, exchange, gw_binding)
    except:
        logging.exception("[GW] Hand heartbeat failed.")
        GWException().notify()
开发者ID:jcsy521,项目名称:ydws,代码行数:86,代码来源:heartbeat.py

示例8: handle_config

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_terminal_sessionID [as 别名]
def handle_config(info, address, connection, channel, exchange, gw_binding, db, redis):
    """
    S17
    Config packet

    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,
                       domain="",
                       freq="",
                       trace="",
                       static_val="",
                       move_val="",
                       trace_para="",
                       vibl="",
                       use_scene="",
                       stop_interval="",
                       test="",
                       gps_enhanced="",
                       tracking_interval="")
        sessionID = QueryHelper.get_terminal_sessionID(head.dev_id, redis)
        if sessionID != head.sessionID:
            args.success = GATEWAY.RESPONSE_STATUS.INVALID_SESSIONID 
        else:
            update_terminal_status(redis, head.dev_id, address)
            #TODO:
            terminal = db.get("SELECT track, freq, trace, mannual_status,"
                              "       trace_para, vibl, domain,"
                              "       use_scene, stop_interval, test,"
                              "       gps_enhanced, tracking_interval"
                              "  FROM T_TERMINAL_INFO"
                              "  WHERE tid = %s", head.dev_id)
            args.domain = terminal.domain
            args.freq = terminal.freq
            args.trace = terminal.trace
            args.use_scene = terminal.use_scene
            args.stop_interval = terminal.stop_interval
            args.test = terminal.test
            args.gps_enhanced = terminal.gps_enhanced
            args.tracking_interval = terminal.tracking_interval
            if terminal.track == 1: # turn on track
                args.trace_para = "60:1"
            else:
                args.trace_para = terminal.trace_para
            args.vibl = terminal.vibl

            #NOTE: get move_val and static_val according to mannual_status
            if int(terminal.mannual_status) != UWEB.DEFEND_STATUS.YES: # 撤防,智能设防
                move_val = 0
                static_val = 180 
            else: # 强力设防
                move_val = 60
                static_val = 0 
            args.move_val = move_val
            args.static_val = static_val 

        #NOTE: check the version.
        # if version is after 2.4, add tracking-interval in S17
        softversion = head['softversion']
        item = softversion.split(".")
        old_softversion = False

        if int(item[0]) < 2: # 1.x.x
            old_softversion = True
        elif int(item[0]) == 2: # 2.x.x
            if int(item[1]) < 4: # 2.3.x
                old_softversion = True
            else: # 2.4.x
                old_softversion = False
        else: # 3.x
            old_softversion = False
        if old_softversion:
             del args['tracking_interval']

        if args['success'] == GATEWAY.RESPONSE_STATUS.SUCCESS: 
            acc_status_info_key = get_acc_status_info_key(dev_id) 
            acc_status_info = redis.getvalue(acc_status_info_key) 
            if acc_status_info and (not acc_status_info['t2_status']): # T2(query) is need
                args['success'] = 3 # acc_status is changed 
                logging.info("[GW] ACC_status is changed, dev_id: %s, acc_status_info: %s", 
                             dev_id, acc_status_info)

        hc = ConfigRespComposer(args)
        request = DotDict(packet=hc.buf,
                          address=address,
                          dev_id=dev_id)
        append_gw_request(request, connection, channel, exchange, gw_binding)
    except:
        logging.exception("[GW] Hand query config exception.")
        GWException().notify()
开发者ID:jcsy521,项目名称:ydws,代码行数:97,代码来源:config.py

示例9: handle_locationdesc

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_terminal_sessionID [as 别名]
def handle_locationdesc(info, address, connection, channel, exchange, gw_binding, db, redis):
    """
    S10
    locationdesc packet

    0: success, then return locationdesc to terminal and record new terminal's address
    1: invalid SessionID 
    """
    try:
        head = info.head
        body = info.body
        dev_id = head.dev_id
        if len(body) == 6:
            body.append(20) 
            logging.info("[GW] old version is compatible, append locate_error")

        resend_key, resend_flag = get_resend_flag(redis, dev_id, head.timestamp, head.command) 

        go_ahead = False 
        args = DotDict(success=GATEWAY.RESPONSE_STATUS.SUCCESS,
                       locationdesc="",
                       ew="E",
                       lon=0.0,
                       ns="N",
                       lat=0.0)
        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:
            if resend_flag:
                logging.warn("[GW] Recv resend packet, head: %s, body: %s and drop it!",
                             info.head, info.body)
            else:
                go_ahead = True


        #NOTE: Check ydcw or ajt 
        ajt = QueryHelper.get_ajt_whitelist_by_mobile(head.dev_id, db) 
        if ajt: 
            url_out = ConfHelper.UWEB_CONF.ajt_url_out 
        else: 
            url_out = ConfHelper.UWEB_CONF.url_out

        if go_ahead:
            redis.setvalue(resend_key, True, GATEWAY.RESEND_EXPIRY)
            ldp = LocationDescParser(body, head)
            location = ldp.ret
            logging.info("[GW] T10 packet parsered:%s", location)
            if not  location.has_key('gps_time'):
                location['gps_time'] = int(time.time())
                logging.info("[GW] what's up? location:%s hasn't gps_time.", location)
            location['t'] = EVENTER.INFO_TYPE.POSITION
            if location['valid'] != GATEWAY.LOCATION_STATUS.SUCCESS:
                cellid = True
            else:
                cellid = False
            location = lbmphelper.handle_location(location, redis, cellid=cellid, db=db)
            location.name = location.get('name') if location.get('name') else ""
            location.name = safe_unicode(location.name)
            user = QueryHelper.get_user_by_tid(head.dev_id, db)
            tname = QueryHelper.get_alias_by_tid(head.dev_id, redis, db)
            dw_method = u'GPS' if not cellid else u'基站'
            if location.cLat and location.cLon:
                if user:
                    current_time = get_terminal_time(int(time.time()))
                    sms = SMSCode.SMS_DW_SUCCESS % (tname, dw_method,
                                                    location.name, 
                                                    safe_unicode(current_time)) 
                    url = url_out + '/wapimg?clon=' +\
                          str(location.cLon/3600000.0) + '&clat=' + str(location.cLat/3600000.0)
                    tiny_id = URLHelper.get_tinyid(url)
                    if tiny_id:
                        base_url = url_out + UWebHelper.URLS.TINYURL
                        tiny_url = base_url + '/' + tiny_id
                        logging.info("[GW] get tiny url successfully. tiny_url:%s", tiny_url)
                        redis.setvalue(tiny_id, url, time=EVENTER.TINYURL_EXPIRY)
                        sms += u"点击 " + tiny_url + u" 查看定位器位置。" 
                    else:
                        logging.info("[GW] get tiny url failed.")
                    SMSHelper.send(user.owner_mobile, sms)
            else:
                if user:
                    sms = SMSCode.SMS_DW_FAILED % (tname, dw_method)
                    SMSHelper.send(user.owner_mobile, sms)
            if not (location.lat and location.lon):
                args.success = GATEWAY.RESPONSE_STATUS.CELLID_FAILED
            else:
                insert_location(location, db, redis)

        lc = LocationDescRespComposer(args)
        request = DotDict(packet=lc.buf,
                          address=address,
                          dev_id=dev_id)
        update_terminal_status(redis, head.dev_id, address)
        append_gw_request(request, connection, channel, exchange, gw_binding)
    except:
        logging.exception("[GW] Handle locationdesc exception.")
        GWException().notify()
开发者ID:jcsy521,项目名称:ydws,代码行数:101,代码来源:locationdesc.py

示例10: foward_packet_to_si

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_terminal_sessionID [as 别名]
    def foward_packet_to_si(self, info, packet, address, connection, channel, db):
        """
        Response packet or position/report/charge packet

        0: success, then forward it to SIServer and record new terminal's address
        1: invalid SessionID 
        """
        try:
            head = info.head
            args = DotDict(success=GATEWAY.RESPONSE_STATUS.SUCCESS,
                           command=head.command)
            dev_id = head.dev_id
            resend_key, resend_flag = get_resend_flag(self.redis, dev_id, head.timestamp, head.command)
            sessionID = QueryHelper.get_terminal_sessionID(dev_id, self.redis)
            if sessionID != head.sessionID:
                args.success = GATEWAY.RESPONSE_STATUS.INVALID_SESSIONID
                logging.error("[GW] Invalid sessionID, Terminal: %s", dev_id)
            else:
                seq = str(int(time.time() * 1000))[-4:]
                uargs = DotDict(seq=seq,
                                dev_id=dev_id,
                                content=packet)
                content = UploadDataComposer(uargs).buf
                logging.info("[GW] Forward message to SI:\n%s", content)
                if resend_flag:
                    logging.warn("[GW] Recv resend packet: %s, and drop it!", packet)
                else:
                    append_si_request(content, connection, channel, self.exchange, self.si_binding)
                update_terminal_status(self.redis, dev_id, address)

            #NOTE: Handle the packet.
            if head.command in (GATEWAY.T_MESSAGE_TYPE.POSITION, GATEWAY.T_MESSAGE_TYPE.MULTIPVT,
                                GATEWAY.T_MESSAGE_TYPE.CHARGE, GATEWAY.T_MESSAGE_TYPE.ILLEGALMOVE,
                                GATEWAY.T_MESSAGE_TYPE.POWERLOW, GATEWAY.T_MESSAGE_TYPE.ILLEGALSHAKE,
                                GATEWAY.T_MESSAGE_TYPE.EMERGENCY, GATEWAY.T_MESSAGE_TYPE.POWERDOWN, 
                                GATEWAY.T_MESSAGE_TYPE.STOP):
                logging.info("[GW] Head command: %s.", head.command)
                if args['success'] == GATEWAY.RESPONSE_STATUS.SUCCESS: 
                    acc_status_info_key = get_acc_status_info_key(dev_id) 
                    acc_status_info = self.redis.getvalue(acc_status_info_key) 
                    if acc_status_info and (not acc_status_info['t2_status']): # T2(query) is need 
                        logging.info("[GW] ACC_status is changed, dev_id: %s, acc_status_info: %s", 
                                     dev_id, acc_status_info)
                        args['success'] = 3 # acc_status is changed

                #NOTE: composer response for terminal 
                rc = AsyncRespComposer(args)
                request = DotDict(packet=rc.buf,
                                  address=address,
                                  dev_id=dev_id)
              
                append_gw_request(request, connection, channel, self.exchange, self.gw_binding)
                # resend flag
                if not resend_flag:
                    self.redis.setvalue(resend_key, True, GATEWAY.RESEND_EXPIRY)
            elif head.command == GATEWAY.T_MESSAGE_TYPE.UNBIND: # S24-->T24
                logging.info("[GW] Head command: %s.", head.command)
                up = UNBindParser(info.body, info.head)
                status = up.ret['status']
                if status == GATEWAY.STATUS.SUCCESS:
                    delete_terminal_new(dev_id, db, self.redis)
            else:
                logging.exception("[GW] Invalid command: %s.", head.command)
        except:
            logging.exception("[GW] Handle SI message exception.")
            GWException().notify()
开发者ID:jcsy521,项目名称:ydws,代码行数:68,代码来源:base.py

示例11: handle_defend

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_terminal_sessionID [as 别名]
def handle_defend(info, address, connection, channel, exchange, gw_binding, db, redis):
    """
    S18
    defend status report packet
    0: success, then record new terminal's address
    1: invalid SessionID 
    """
    try:
        head = info.head
        body = info.body
        dev_id = head.dev_id

        resend_key, resend_flag = get_resend_flag(redis, dev_id, head.timestamp, head.command) 

        # old version is compatible
        if len(body) == 1:
            body.append('0')
            logging.info("[GW] old version is compatible, append mannual status 0")
        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 
        else:
            if resend_flag:
                logging.warn("[GW] Recv resend packet, head: %s, body: %s and drop it!",
                             info.head, info.body)
            else: 
                redis.setvalue(resend_key, True, GATEWAY.RESEND_EXPIRY)
                hp = AsyncParser(body, head)
                defend_info = hp.ret 
                defend_info['mannual_status'] = defend_info['defend_status']
                if defend_info['defend_source'] != 0:
                    # come from sms or web 
                    if defend_info['defend_source'] == "1":
                        _status = u"设防" if defend_info['defend_status'] == "1" else u"撤防"
                        tname = QueryHelper.get_alias_by_tid(head.dev_id, redis, db)
                        sms = SMSCode.SMS_DEFEND_SUCCESS % (tname, _status) 
                        user = QueryHelper.get_user_by_tid(head.dev_id, db)
                        if user:
                            SMSHelper.send(user.owner_mobile, sms)
                    del defend_info['defend_status']
                del defend_info['defend_source']
                update_mannual_status(db, redis, head.dev_id, defend_info['mannual_status'])
            update_terminal_status(redis, head.dev_id, address)

        if args['success'] == GATEWAY.RESPONSE_STATUS.SUCCESS: 
            acc_status_info_key = get_acc_status_info_key(dev_id) 
            acc_status_info = redis.getvalue(acc_status_info_key) 
            if acc_status_info and (not acc_status_info['t2_status']): # T2(query) is need
                args['success'] = 3 # acc_status is changed 
                logging.info("[GW] ACC_status is changed, dev_id: %s, acc_status_info: %s", 
                             dev_id, acc_status_info)
        hc = AsyncRespComposer(args)
        request = DotDict(packet=hc.buf,
                          address=address,
                          dev_id=dev_id)
        append_gw_request(request, connection, channel, exchange, gw_binding)
    except:
        logging.exception("[GW] Handle defend status report exception.")
        GWException().notify()
开发者ID:jcsy521,项目名称:ydws,代码行数:63,代码来源:defend.py

示例12: handle_old_login

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_terminal_sessionID [as 别名]

#.........这里部分代码省略.........
            append_gw_request(request, connection, channel, exchange, gw_binding)
            logging.error("[GW] Login failed! Terminal %s execute HK, but tid is not exist",
                          t_info['dev_id'])
            return
        # HK, change terminal mobile or owner mobile
        logging.info("[GW] Checking password. Terminal: %s",
                     t_info['dev_id'])
        owner = db.get("SELECT id FROM T_USER"
                       "  WHERE mobile = %s"
                       "    AND password = password(%s)",
                       terminal.owner_mobile, t_info['psd'])
        if not owner:
            # psd wrong
            sms = SMSCode.SMS_PSD_WRONG
            args.success = GATEWAY.LOGIN_STATUS.PSD_WRONG
            logging.error("[GW] Login failed! Password invalid. Terminal: %s",
                          t_info['dev_id'])
        else:
            if terminal:
                if terminal.mobile != t_info['t_msisdn']:
                    # terminal HK
                    logging.info("[GW] Terminal: %s HK started.", t_info['dev_id'])
                    # unbind old tmobile
                    old_bind = db.get("SELECT id, tid FROM T_TERMINAL_INFO"
                                      "  WHERE mobile = %s"
                                      "    AND id != %s",
                                      t_info['t_msisdn'], terminal.id)
                    if old_bind:
                        # clear db
                        db.execute("DELETE FROM T_TERMINAL_INFO"
                                   "  WHERE id = %s", 
                                   old_bind.id) 
                        # clear redis
                        sessionID_key = get_terminal_sessionID_key(old_bind.tid)
                        address_key = get_terminal_address_key(old_bind.tid)
                        info_key = get_terminal_info_key(old_bind.tid)
                        lq_sms_key = get_lq_sms_key(old_bind.tid)
                        lq_interval_key = get_lq_interval_key(old_bind.tid)
                        keys = [sessionID_key, address_key, info_key, lq_sms_key, lq_interval_key]
                        redis.delete(*keys)
                        logging.info("[GW] Delete old bind Terminal: %s, SIM: %s",
                                     t_info['dev_id'], t_info['t_msisdn'])

                    # update new tmobile
                    db.execute("UPDATE T_TERMINAL_INFO"
                               "  SET mobile = %s,"
                               "      imsi = %s"
                               "  WHERE id = %s",
                               t_info['t_msisdn'],
                               t_info['imsi'], terminal.id)
                    # clear redis
                    sessionID_key = get_terminal_sessionID_key(t_info['dev_id'])
                    address_key = get_terminal_address_key(t_info['dev_id'])
                    info_key = get_terminal_info_key(t_info['dev_id'])
                    lq_sms_key = get_lq_sms_key(t_info['dev_id'])
                    lq_interval_key = get_lq_interval_key(t_info['dev_id'])
                    keys = [sessionID_key, address_key, info_key, lq_sms_key, lq_interval_key]
                    redis.delete(*keys)
                    # HK sms
                    sms = SMSCode.SMS_TERMINAL_HK_SUCCESS % (terminal.mobile, t_info['t_msisdn'])
                    # subscription LE for new sim
                    thread.start_new_thread(subscription_lbmp, (t_info,)) 
                    logging.info("[GW] Terminal: %s HK success!", t_info['dev_id'])

                if terminal.owner_mobile != t_info['u_msisdn']:
                    logging.info("[GW] Owner HK started. Terminal: %s", t_info['dev_id'])
开发者ID:jcsy521,项目名称:ydws,代码行数:70,代码来源:login.py

示例13: handle_new_login

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_terminal_sessionID [as 别名]

#.........这里部分代码省略.........
                                 tmobile=t_info['t_msisdn'],
                                 owner_mobile=t_info['u_msisdn'],
                                 imsi=t_info['imsi'],
                                 imei=t_info['imei'],
                                 factory_name=t_info['factory_name'],
                                 softversion=t_info['softversion'], 
                                 keys_num=t_info['keys_num'], 
                                 login=GATEWAY.TERMINAL_LOGIN.ONLINE,
                                 service_status=UWEB.SERVICE_STATUS.ON,
                                 mannual_status=mannual_status,
                                 push_status=push_status,
                                 icon_type=icon_type,
                                 begintime=int(time.mktime(begintime.timetuple())),
                                 endtime=4733481600,
                                 offline_time=int(time.mktime(begintime.timetuple())),
                                 cnum=cnum,
                                 login_permit=login_permit,
                                 bt_mac=t_info['bt_mac'],
                                 bt_name=t_info['bt_name'],
                                 vibl=vibl,
                                 use_scene=use_scene,
                                 biz_type=UWEB.BIZ_TYPE.YDWS,
                                 alias=alias,
                                 speed_limit=speed_limit,
                                 stop_interval=stop_interval,
                                 distance_current=distance_current)
            add_terminal(terminal_info, db, redis)

            # record the add action, enterprise or individual
            corp = QueryHelper.get_corp_by_gid(group_id, db)
            bind_info = dict(tid=t_info['dev_id'],
                             tmobile=t_info['t_msisdn'],
                             umobile=t_info['u_msisdn'],
                             group_id=group_id,
                             cid=corp.get('cid', '') if corp else '',
                             add_time=int(time.time()))
            record_add_action(bind_info, db)
 
            logging.info("[GW] Terminal JH success! tid: %s, mobile: %s.",
                         t_info['dev_id'], t_info['t_msisdn'])
            # subscription LE for new sim
            thread.start_new_thread(subscription_lbmp, (t_info,)) 

    if args.success == GATEWAY.LOGIN_STATUS.SUCCESS:
        # get SessionID
        if resend_flag:
            logging.warn("[GW] Recv resend login packet and use old sessionID! packet: %s, tid: %s, mobile: %s.", 
                         t_info, t_info['dev_id'], t_info['t_msisdn']) 
            args.sessionID = QueryHelper.get_terminal_sessionID(t_info['dev_id'], redis)
            if not args.sessionID:
                args.sessionID = get_sessionID()
        else:
            #NOTE: generate a sessionid and keep it in redis.
            args.sessionID = get_sessionID()
            terminal_sessionID_key = get_terminal_sessionID_key(t_info['dev_id'])
            redis.setvalue(terminal_sessionID_key, args.sessionID)
            redis.setvalue(resend_key, True, GATEWAY.RESEND_EXPIRY)
        # record terminal address
        update_terminal_status(redis, t_info["dev_id"], address)
        #NOTE: When termianl is normal login, update some properties to platform.
        info = DotDict(login=GATEWAY.TERMINAL_LOGIN.ONLINE,
                       mobile=t_info['t_msisdn'],
                       keys_num=t_info['keys_num'],
                       softversion=t_info['softversion'],
                       login_time=int(time.time()),
                       dev_id=t_info["dev_id"],
                       bt_mac=t_info['bt_mac'],
                       bt_name=t_info['bt_name'],
                       dev_type=t_info['dev_type'])
        update_terminal_info(db, redis, info)
        logging.info("[GW] Terminal login success! tid: %s, mobile: %s",
                     t_info['dev_id'], t_info['t_msisdn'])

        #NOTE: wspush to cient
        if flag != "1": # normal login
            WSPushHelper.pushS4(t_info["dev_id"], db, redis)
        else: # JH 
            pass

    lc = LoginRespComposer(args)
    request = DotDict(packet=lc.buf,
                      address=address,
                      dev_id=t_info["dev_id"])
    append_gw_request(request, connection, channel, exchange, gw_binding)

    if sms and t_info['u_msisdn']:
        logging.info("[GW] Send sms to owner. mobile: %s, content: %s",
                    t_info['u_msisdn'], sms)
        SMSHelper.send(t_info['u_msisdn'], sms)

    if t_status == UWEB.SERVICE_STATUS.TO_BE_UNBIND:
        seq = str(int(time.time()*1000))[-4:]
        args_ = DotDict(seq=seq,
                        tid=t_info["dev_id"])
        ubc = UNBindComposer(args_)
        request = DotDict(packet=ubc.buf,
                          address=address,
                          dev_id=t_info["dev_id"])
        append_gw_request(request, connection, channel, exchange, gw_binding)
        logging.warn("[GW] Terminal is unbinded, tid: %s, send unbind packet.", t_info["dev_id"])            
开发者ID:jcsy521,项目名称:ydws,代码行数:104,代码来源:login.py

示例14: handle_runtime

# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_terminal_sessionID [as 别名]
def handle_runtime(info, address, connection, channel, exchange, gw_binding, db, redis):
    """
    S23
    runtime status packet: {login [0:unlogin | 1:login],
                            defend_status [0:undefend | 1:defend],
                            gps:gsm:pbat [0-100:0-9:0-100]} 

    0: success, then record new terminal's address
    1: invalid SessionID
    """
    try:
        head = info.head
        body = info.body
        dev_id = head.dev_id
        resend_key, resend_flag = get_resend_flag(redis, dev_id, head.timestamp, head.command)
        if len(body) == 3:
            body.append('-1')
            body.append('0')
            logging.info("[GW] old version is compatible, append fob_pbat, is_send")
        if len(body) == 4:
            body.append('0')
            logging.info("[GW] old version is compatible, append is_send")
        args = DotDict(success=GATEWAY.RESPONSE_STATUS.SUCCESS,
                       command=head.command,
                       mannual_status='')
        sessionID = QueryHelper.get_terminal_sessionID(dev_id, redis)
        if sessionID != head.sessionID:
            args.success = GATEWAY.RESPONSE_STATUS.INVALID_SESSIONID 
        else:
            if resend_flag:
                logging.warn("[GW] Recv resend packet, head: %s, body: %s and drop it!",
                             info.head, info.body)
                terminal_info = QueryHelper.get_terminal_info(head.dev_id, db, redis)
                args.mannual_status = terminal_info['mannual_status']
            else:
                redis.setvalue(resend_key, True, GATEWAY.RESEND_EXPIRY)
                hp = AsyncParser(body, head)
                runtime_info = hp.ret 
                update_terminal_status(redis, head.dev_id, address)
                terminal_info = update_terminal_info(db, redis, runtime_info)
                args.mannual_status = terminal_info['mannual_status']
                db.execute("INSERT INTO T_RUNTIME_STATUS"
                           "  VALUES(NULL, %s, %s, %s, %s, %s, %s, %s, %s)",
                           head.dev_id, runtime_info['login'], runtime_info['defend_status'],
                           runtime_info['gps'], runtime_info['gsm'], runtime_info['pbat'],
                           runtime_info['fob_pbat'], head.timestamp)

                is_send = int(runtime_info['is_send'])
                if is_send:
                    terminal_info = QueryHelper.get_terminal_info(head.dev_id, db, redis)
                    alias = QueryHelper.get_alias_by_tid(head.dev_id, redis, db)
                    communication_staus = u'正常'
                    communication_mode = u'撤防'
                    gsm_strength = u'强'
                    gps_strength = u'强'
                    if int(terminal_info['login']) == GATEWAY.TERMINAL_LOGIN.ONLINE:
                        communication_staus = u'正常'
                    else:
                        communication_staus = u'异常'

                    if int(terminal_info['mannual_status']) == UWEB.DEFEND_STATUS.YES:
                        communication_mode = u'强力设防'
                    elif int(terminal_info['mannual_status']) == UWEB.DEFEND_STATUS.SMART:
                        communication_mode = u'智能设防'
                    else:
                        communication_mode= u'撤防'

                    pbat = int(terminal_info.get('pbat', 0))

                    gsm = int(terminal_info.get('gsm', 0))
                    if gsm < 3:
                        gsm_strength = u'弱'
                    elif gsm < 6:
                        gsm_strength = u'较弱'

                    gps = int(terminal_info.get('gps', 0))
                    if gps < 10:
                        gps_strength = u'弱' 
                    elif gps < 20:
                        gps_strength = u'较弱' 
                    elif gps < 30:
                        gps_strength = u'较强' 

                    runtime_sms = SMSCode.SMS_RUNTIME_STATUS % (alias, communication_staus, communication_mode, int(pbat), gsm_strength, gps_strength)
                    SMSHelper.send(terminal_info.owner_mobile, runtime_sms)
                    logging.info("[GW] Send runtime_status sms to user: %s, tid: %s",
                                 terminal_info.owner_mobile, head.dev_id)

            update_terminal_status(redis, head.dev_id, address)

        if args['success'] == GATEWAY.RESPONSE_STATUS.SUCCESS: 
            acc_status_info_key = get_acc_status_info_key(dev_id) 
            acc_status_info = redis.getvalue(acc_status_info_key) 
            if acc_status_info and (not acc_status_info['t2_status']): # T2(query) is need
                args['success'] = 3 # acc_status is changed 
                logging.info("[GW] ACC_status is changed, dev_id: %s, acc_status_info: %s", 
                             dev_id, acc_status_info)

        rc = RuntimeRespComposer(args)
        request = DotDict(packet=rc.buf,
#.........这里部分代码省略.........
开发者ID:jcsy521,项目名称:ydws,代码行数:103,代码来源:runtime.py


注:本文中的helpers.queryhelper.QueryHelper.get_terminal_sessionID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。