Exemplo n.º 1
0
    def post(self):
        args = self.request.arguments
        if 'scode' not in args.keys():
            msg = self.init_msgws(msgws.CommAns())
            msg.head.if_st = 0
            msg.head.if_msg = 'Missing argument scode'
        else:
            scode = args.get('scode')[0]

            leage = self.computing_security_code(scode)

            if legal:
                try:
                    try:
                        keyhead = self.get_argument('keyhead')
                        rqmsg = json.loads(self.get_argument('pb2'))
                    except:
                        keyhead = 'tcs.unknow'
                    sfilter = '{0}.{1}'.format(keyhead, rqmsg['head']['cmd'])
                    libiisi.send_to_zmq_pub(sfilter, rqmsg)
                except Exception as ex:
                    logging.error(
                        base.format_log(self.request.remote_ip, str(ex),
                                        self.request.path, 0))
            else:
                logging.error(
                    base.format_log(self.request.remote_ip,
                                    'Security code error', self.request.path,
                                    0))

        # self.write('Done.')
        self.finish()
        del legal, rqmsg, msg
Exemplo n.º 2
0
    def post(self):
        legal, rqmsg, msg = yield self.check_arguments(msgws.rqSubmitAlarm(),
                                                       msgws.CommAns(),
                                                       use_scode=1)
        if legal:
            try:
                for av in rqmsg.alarm_view:
                    try:
                        sfilter = 'jkdb.rep.alarm.{0}.{1}.{2}.{3}'.format(
                            av.dt_create, av.is_alarm, av.err_id, av.tml_id)
                        libiisi.send_to_zmq_pub(sfilter,
                                                av.SerializeToString())
                    except Exception as ex:
                        pass
                        # print(str(ex))
            except Exception as ex:
                logging.error(
                    base.format_log(self.request.remote_ip, str(ex),
                                    self.request.path, 0))
        else:
            logging.error(
                base.format_log(self.request.remote_ip, 'Security code error',
                                self.request.path, 0))

        # self.write('Done.')
        self.finish()
        del legal, rqmsg, msg
Exemplo n.º 3
0
    def post(self):
        user_data, rqmsg, msg, user_uuid = yield self.check_arguments(
            msgws.rqEluCtl(), None)

        if user_data is not None:
            if user_data['user_auth'] in libiisi.can_read & libiisi.can_exec:
                # 验证用户可操作的设备id
                yield self.update_cache('r', user_uuid)
                if 0 in user_data['area_r'] or user_data['is_buildin'] == 1:
                    rtu_ids = list(rqmsg.tml_id)
                else:
                    rtu_ids = self.check_tml_r(user_uuid, list(rqmsg.tml_id))

                if len(rtu_ids) == 0:
                    msg.head.if_st = 11
                else:
                    yield self.update_cache()
                    for tml_id in rtu_ids:
                        phy_id, fid, tml_name = self.get_phy_info(tml_id)
                        if phy_id == -1:
                            continue
                        if fid > 0:
                            addr = self.get_phy_list([fid])
                            cid = phy_id
                            tra = 2
                        else:
                            addr = [phy_id]
                            cid = 1
                            tra = 1
                        tcsmsg = libiisi.initRtuProtobuf(cmd='wlst.elu.6257',
                                                         addr=list(addr),
                                                         cid=cid,
                                                         tra=tra)
                        lp_do = []
                        i = 0
                        for loop in range(len(rqmsg.loop_id)):
                            if i == 8:
                                break
                            lp_do.append(loop if loop <= 2 else 2)
                        if len(lp_do) < 8:
                            lp_do.extend([2] * (8 - len(lp_do)))
                        tcsmsg.wlst_tml.wlst_elu_6257.opt_do.extend(lp_do)
                        libiisi.send_to_zmq_pub(
                            'tcs.req.{1}.{0}'.format(tcsmsg.head.cmd,
                                                     libiisi.cfg_tcs_port),
                            tcsmsg.SerializeToString())
            else:
                msg.head.if_st = 11

        self.write(mx.code_pb2(msg, self._go_back_format))
        self.finish()
        del msg, rqmsg, user_data, user_uuid
Exemplo n.º 4
0
    def post(self):
        user_data, rqmsg, msg, user_uuid = yield self.check_arguments(
            msgws.rqEluDataGet(), None)

        if user_data is not None:
            if user_data['user_auth'] in libiisi.can_read:
                # 验证用户可操作的设备id
                yield self.update_cache('r', user_uuid)
                if 0 in user_data['area_r'] or user_data['is_buildin'] == 1:
                    rtu_ids = list(rqmsg.tml_id)
                else:
                    rtu_ids = self.check_tml_r(user_uuid, list(rqmsg.tml_id))

                if len(rtu_ids) == 0:
                    msg.head.if_st = 11
                else:
                    yield self.update_cache()
                    for tml_id in rtu_ids:
                        phy_id, fid, tml_name = self.get_phy_info(tml_id)
                        if phy_id == -1:
                            continue
                        if fid > 0:
                            addr = self.get_phy_list([fid])
                            cid = phy_id
                            tra = 2
                        else:
                            addr = [phy_id]
                            cid = 1
                            tra = 1
                        tcsmsg = libiisi.initRtuProtobuf(cmd='wlst.elu.6259',
                                                         addr=list(addr),
                                                         cid=cid,
                                                         tra=tra)
                        libiisi.send_to_zmq_pub(
                            'tcs.req.{1}.{0}'.format(tcsmsg.head.cmd,
                                                     libiisi.cfg_tcs_port),
                            tcsmsg.SerializeToString())
                        tcsmsg = libiisi.initRtuProtobuf(cmd='wlst.elu.6260',
                                                         addr=list(addr),
                                                         cid=cid,
                                                         tra=tra)
                        libiisi.send_to_zmq_pub(
                            'tcs.req.{1}.{0}'.format(tcsmsg.head.cmd,
                                                     libiisi.cfg_tcs_port),
                            tcsmsg.SerializeToString())
            else:
                msg.head.if_st = 11

        self.write(mx.code_pb2(msg, self._go_back_format))
        self.finish()
        del msg, rqmsg, user_data, user_uuid
Exemplo n.º 5
0
    def post(self):
        user_data, rqmsg, msg, user_uuid = yield self.check_arguments(
            msgws.rqRtuVerGet(), None)

        env = False
        if user_data is not None:
            try:
                tver = int(self.get_argument('tver'))
            except:
                tver = 1
            if user_data['user_auth'] in libiisi.can_read:
                # 验证用户可操作的设备id
                yield self.update_cache('r', user_uuid)
                if 0 in user_data['area_r'] or user_data['is_buildin'] == 1:
                    rtu_ids = ','.join(
                        [str(a) for a in self.get_phy_list(rqmsg.tml_id)])
                else:
                    rtu_ids = ','.join([
                        str(a) for a in self.get_phy_list(
                            self.check_tml_r(user_uuid, list(rqmsg.tml_id)))
                    ])
                if len(rtu_ids) == 0:
                    msg.head.if_st = 11
                else:
                    if tver == 1:
                        tcsmsg = libiisi.initRtuJson(2, 7, 1, 1, 1,
                                                     'wlst.rtu.5c00',
                                                     self.request.remote_ip, 0,
                                                     rtu_ids, dict())
                        # libiisi.set_to_send(tcsmsg, 0, False)
                        libiisi.send_to_zmq_pub(
                            'tcs.req.{0}.wlst.rtu.5c00'.format(
                                libiisi.cfg_tcs_port),
                            json.dumps(tcsmsg, separators=(',', ':')).lower())
                    elif tver == 2:
                        tcsmsg = libiisi.initRtuProtobuf(cmd='ahhf.rtu.5c00',
                                                         tver=tver)
                        libiisi.send_to_zmq_pub(
                            'tcs.req.{0}.{1}'.format(libiisi.cfg_tcs_port,
                                                     tcsmsg.head.cmd),
                            tcsmsg.SerializeToString())
            else:
                msg.head.if_st = 11

        self.write(mx.code_pb2(msg, self._go_back_format))
        self.finish()
        del msg, rqmsg, user_data
Exemplo n.º 6
0
Arquivo: ipc.py Projeto: xyzj/lump
 def post(self):
     legal, rqmsg, msg = yield self.check_arguments(msgws.rqIpcCtl(),
                                                    None,
                                                    use_scode=1)
     if legal:
         scmd = rqmsg.ctl_cmd
         sdownlink = ''
         for devid in rqmsg.dev_id:
             if devid.startswith('901001'):
                 if scmd == 'ipc.verf.get':
                     sdownlink = 'QV\r\n'
                 elif scmd == 'ipc.lscmd.get':
                     sdownlink = 'QH\r\n'
                 elif scmd == 'ipc.date.get':
                     sdownlink = 'QD\r\n'
                 elif scmd == 'ipc.time.get':
                     sdownlink = 'QT\r\n'
                 elif scmd == 'ipc.datetime.set':
                     x = mx.stamp2time(rqmsg.dev_datetime)
                     d, t = x.split(' ')
                     y, m, dd = d.split('-')
                     h, mm, s = t.split(':')
                     sdownlink = '\r\nQC:{0},{1},{2},{3},{4},{5}'.format(
                         y, m, dd, h, mm, s)
                 elif scmd == 'ipc.qudat.get':
                     sdownlink = 'QI\r\n'
                 else:
                     msg.head.if_st = 46
                 if len(sdownlink) > 0:
                     msgpub = self.init_msgws(msgws.rqIpcUplink(), scmd)
                     msgpub.dev_id = devid
                     msgpub.raw_string = sdownlink
                     libiisi.send_to_zmq_pub(
                         'ipc.req.{0}.{1}'.format(scmd, devid),
                         msgpub.SerializeToString())
                     del msgpub
     self.write(mx.convertProtobuf(msg))
     self.finish()
     del legal, rqmsg, msg
Exemplo n.º 7
0
    def post(self):
        legal, rqmsg, msg = yield self.check_arguments(msgtcs.MsgWithCtrl(),
                                                       msgws.CommAns(),
                                                       use_scode=1)
        if legal:
            try:
                try:
                    keyhead = self.get_argument('keyhead')
                except:
                    keyhead = 'tcs.unknow'
                sfilter = '{0}.{1}'.format(keyhead, rqmsg.head.cmd)
                libiisi.send_to_zmq_pub(sfilter, rqmsg.SerializeToString())
            except Exception as ex:
                logging.error(
                    base.format_log(self.request.remote_ip, str(ex),
                                    self.request.path, 0))
        else:
            logging.error(
                base.format_log(self.request.remote_ip, 'Security code error',
                                self.request.path, 0))

        # self.write('Done.')
        self.finish()
        del legal, rqmsg, msg
Exemplo n.º 8
0
    def post(self):
        user_data, rqmsg, msg, user_uuid = yield self.check_arguments(
            msgws.rqRtuTimerCtl(), None)
        env = False
        contents = ''
        if user_data is not None:
            try:
                tver = int(self.get_argument('tver'))
            except:
                tver = 1
            if rqmsg.data_mark == 0:
                user_auth = libiisi.can_read
            else:
                user_auth = libiisi.can_exec & libiisi.can_write
            if user_data['user_auth'] in user_auth:
                env = True
                contents = 'user from {0} set rtu timer'.format(
                    self.request.remote_ip)
                # 验证用户可操作的设备id
                yield self.update_cache('r', user_uuid)
                if 0 in user_data['area_r'] or user_data['is_buildin'] == 1:
                    rtu_ids = ','.join(
                        [str(a) for a in self.get_phy_list(rqmsg.tml_id)])
                else:
                    rtu_ids = ','.join([
                        str(a) for a in self.get_phy_list(
                            self.check_tml_r(user_uuid, list(rqmsg.tml_id)))
                    ])
                if len(rtu_ids) == 0:
                    msg.head.if_st = 11
                else:
                    if tver == 1:
                        if rqmsg.data_mark == 0:
                            cmd = 'wlst.rtu.1200'
                        else:
                            cmd = 'wlst.rtu.1300'
                        tcsmsg = libiisi.initRtuJson(2, 7, 1, 1, 1, cmd,
                                                     self.request.remote_ip, 0,
                                                     rtu_ids, dict())
                        # libiisi.set_to_send(tcsmsg, 0, False)
                        libiisi.send_to_zmq_pub(
                            'tcs.req.{1}.{0}'.format(cmd,
                                                     libiisi.cfg_tcs_port),
                            json.dumps(tcsmsg, separators=(',', ':')).lower())
                    elif tver == 2:
                        if rqmsg.data_mark == 0:
                            cmd = 'ahhf.rtu.1200'
                        else:
                            cmd = 'ahhf.rtu.1300'
                        tcsmsg = libiisi.initRtuProtobuf(cmd=cmd, tver=2)
                        libiisi.send_to_zmq_pub(
                            'tcs.req.{0}.{1}'.format(libiisi.cfg_tcs_port,
                                                     cmd),
                            tcsmsg.SerializeToString())
            else:
                msg.head.if_st = 11

        self.write(mx.code_pb2(msg, self._go_back_format))
        self.finish()
        if env and rqmsg.data_mark == 1:
            self.write_event(11,
                             contents,
                             2,
                             user_name=user_data['user_name'],
                             app_unique=rqmsg.head.unique)
        del msg, rqmsg, user_data
Exemplo n.º 9
0
    def post(self):
        user_data, rqmsg, msg, user_uuid = yield self.check_arguments(
            msgws.rqRtuCtl(), None)

        env = False
        event_id = 0
        if user_data is not None:
            try:
                tver = int(self.get_argument('tver'))
            except:
                tver = 1
            if user_data['user_auth'] in libiisi.can_exec:
                env = True
                self.get_eventinfo()
                dosomething = False
                for x in list(rqmsg.rtu_do):
                    event_id = 0
                    if len(x.tml_id) == 0:
                        continue
                    dosomething = True
                    tcsdata = dict()

                    # 验证用户可操作的设备id
                    yield self.update_cache('x', user_uuid)
                    if 0 in user_data['area_x'] or user_data['is_buildin'] == 1:
                        rtu_ids = ','.join(
                            [str(a) for a in self.get_phy_list(x.tml_id)])
                    else:
                        rtu_ids = ','.join([
                            str(a) for a in self.get_phy_list(
                                self.check_tml_x(user_uuid, list(x.tml_id)))
                        ])
                    if len(rtu_ids) > 0:
                        if x.opt == 1:  # 单回路操作
                            event_id = 19
                            i = 0
                            for k in list(x.loop_do):
                                if k in (0, 1):
                                    tcsdata['k'] = i
                                    tcsdata['o'] = k
                                    tcsmsg = libiisi.initRtuJson(
                                        2, 7, 1, 1, 1, 'wlst.rtu.2210',
                                        self.request.remote_ip, 0, rtu_ids,
                                        tcsdata)
                                    # libiisi.set_to_send(tcsmsg, 0, False)
                                    libiisi.send_to_zmq_pub(
                                        'tcs.req.{0}.wlst.rtu.2210'.format(
                                            libiisi.cfg_tcs_port),
                                        json.dumps(tcsmsg,
                                                   separators=(',',
                                                               ':')).lower())
                                i += 1
                        elif x.opt == 2:  # 多回路操作
                            event_id = 19
                            if tver == 1:
                                i = 1
                                for k in list(x.loop_do):
                                    tcsdata['k{0}'.format(i)] = k
                                    if i == 6:
                                        break
                                    i += 1
                                tcsmsg = libiisi.initRtuJson(
                                    2, 7, 1, 1, 1, 'wlst.rtu.4b00',
                                    self.request.remote_ip, 0, rtu_ids,
                                    tcsdata)
                                # libiisi.set_to_send(tcsmsg, 0, False)
                                libiisi.send_to_zmq_pub(
                                    'tcs.req.{0}.wlst.rtu.4b00'.format(
                                        libiisi.cfg_tcs_port),
                                    json.dumps(tcsmsg,
                                               separators=(',', ':')).lower())
                            elif tver == 2:
                                tcsmsg = libiisi.initRtuProtobuf(
                                    cmd='ahhf.rtu.4b00', tver=tver)
                                tcsmsg.wlst_tml.wlst_rtu_4b00.operation.extend(
                                    list(x.loop_do))
                                libiisi.send_to_zmq_pub(
                                    'tcs.req.{0}.{1}'.format(
                                        libiisi.cfg_tcs_port, tcsmsg.head.cmd),
                                    tcsmsg.SerializeToString())
                        elif x.opt == 3:  # 停运
                            event_id = 17
                            tcsmsg = libiisi.initRtuJson(
                                2, 7, 1, 1, 1, 'wlst.rtu.2800',
                                self.request.remote_ip, 0, rtu_ids, tcsdata)
                            # libiisi.set_to_send(tcsmsg, 0, False)
                            libiisi.send_to_zmq_pub(
                                'tcs.req.{0}.wlst.rtu.2800'.format(
                                    libiisi.cfg_tcs_port),
                                json.dumps(tcsmsg,
                                           separators=(',', ':')).lower())
                        elif x.opt == 4:  # 解除停运
                            event_id = 18
                            tcsmsg = libiisi.initRtuJson(
                                2, 7, 1, 1, 1, 'wlst.rtu.2900',
                                self.request.remote_ip, 0, rtu_ids, tcsdata)
                            # libiisi.set_to_send(tcsmsg, 0, False)
                            libiisi.send_to_zmq_pub(
                                'tcs.req.{0}.wlst.rtu.2900'.format(
                                    libiisi.cfg_tcs_port),
                                json.dumps(tcsmsg,
                                           separators=(',', ':')).lower())
                if not dosomething:
                    msg.head.if_st = 11
                contents = u'{0},build-in user from {1} ctrl rtu '.format(
                    libiisi.events_def.get(event_id), self.request.remote_ip)
            else:
                msg.head.if_st = 11

        self.write(mx.code_pb2(msg, self._go_back_format))
        self.finish()
        if env:
            cur = yield self.write_event(event_id,
                                         contents,
                                         2,
                                         user_name=user_data['user_name'],
                                         app_unique=rqmsg.head.unique)
        del msg, rqmsg, user_data, user_uuid
Exemplo n.º 10
0
    def post(self):
        user_data, rqmsg, msg, user_uuid = yield self.check_arguments(
            msgws.rqMruDataGet(), None)

        if user_data is not None:
            if user_data['user_auth'] in libiisi.can_read:
                # 验证用户可操作的设备id
                if 0 in user_data['area_r'] or user_data['is_buildin'] == 1:
                    if len(rqmsg.tml_id) > 0:
                        tml_ids = list(rqmsg.tml_id)
                    else:
                        tml_ids = []
                else:
                    if len(rqmsg.tml_id) > 0:
                        tml_ids = self.check_tml_r(user_uuid, list(
                            rqmsg.tml_id))
                    else:
                        tml_ids = libiisi.cache_tml_r[user_uuid]
                    if len(tml_ids) == 0:
                        msg.head.if_st = 11

                if msg.head.if_st == 1:
                    if len(tml_ids) == 0:
                        str_tmls = ''
                    else:
                        str_tmls = ' where a.rtu_id in ({0}) '.format(
                            ','.join([str(a) for a in tml_ids]))

                    strsql = '''select a.rtu_id,a.rtu_fid,
                    b.mru_addr_1,b.mru_addr_2,b.mru_addr_3,b.mru_addr_4,b.mru_addr_5,b.mru_addr_6
                    from {0}.para_base_equipment as a left join {0}.para_mru as b on a.rtu_id=b.rtu_id {1} '''.format(
                        self._db_name, str_tmls)

                    yield self.update_cache()
                    record_total, buffer_tag, paging_idx, paging_total, cur = yield self.mydata_collector(
                        strsql, need_fetch=1)

                    for d in cur:
                        if int(d[1]) > 0:
                            tra = 2
                        else:
                            tra = 1
                        tcsmsg = libiisi.initRtuJson(
                            mod=2,
                            src=7,
                            ver=1,
                            tver=1,
                            tra=tra,
                            cmd='wlst.mru.9100',
                            ip=self.request.remote_ip,
                            port=0,
                            addr=','.join(
                                [str(a) for a in self.get_phy_list([d[1]])]),
                            data=dict(
                                addr1=int(d[2]),
                                addr2=int(d[3]),
                                addr3=int(d[4]),
                                addr4=int(d[5]),
                                addr5=int(d[6]),
                                addr6=int(d[7]),
                                ver=rqmsg.dev_ver,
                                type=rqmsg.data_mark,
                                date=rqmsg.dt_mark,
                                br=rqmsg.baud_rate))
                        # libiisi.set_to_send(tcsmsg, 0, False)
                        print(tcsmsg)
                        libiisi.send_to_zmq_pub(
                            'tcs.req.{0}.wlst.mru.9100'.format(
                                libiisi.cfg_tcs_port),
                            json.dumps(tcsmsg, separators=(',', ':')).lower())
            else:
                msg.head.if_st = 11

        self.write(mx.code_pb2(msg, self._go_back_format))
        self.finish()
        del msg, rqmsg, user_data, user_uuid
Exemplo n.º 11
0
Arquivo: ipc.py Projeto: xyzj/lump
    def post(self):
        legal, rqmsg, msg = yield self.check_arguments(msgws.rqIpcUplink(),
                                                       msgws.CommAns(),
                                                       use_scode=1)
        if legal:
            devid = rqmsg.dev_id
            raw_string = rqmsg.raw_string.replace('\r\n', '')
            createsql = ''
            insertsql = ''
            db_names = set()
            if devid[:6] == '901001':  # 申欣环保
                if raw_string.startswith('QI:'):
                    data = raw_string.split(':')[1]
                    lstdata = data.split(',')
                    ym = mx.stamp2time(time.time(), format_type='%y%m')
                    for i in libiisi.qudata_sxhb:
                        db_names.add('sens_data_{0:03d}_month_{1}'.format(
                            i, ym))
                    strsql = 'select TABLE_NAME from INFORMATION_SCHEMA.TABLES \
                        where TABLE_SCHEMA="{0}" and TABLE_NAME like "{1}"'.format(
                        libiisi.cfg_dbname_dg, '%sens_data_%_month_%')
                    record_total, buffer_tag, paging_idx, paging_total, cur = yield self.mydata_collector(
                        strsql,
                        need_fetch=1,
                        buffer_tag=msg.head.paging_buffer_tag,
                        paging_idx=msg.head.paging_idx,
                        paging_num=msg.head.paging_num)
                    if record_total is not None:
                        for z in cur:
                            db_names.discard(z[0])
                    del cur
                    for z in db_names:
                        createsql += libiisi.sqlstr_create_emtable.format(z)
                    if len(createsql) > 0:
                        createsql = 'use {0};'.format(
                            libiisi.cfg_dbname_dg) + createsql
                        yield self.mydata_collector(createsql, need_fetch=0)

                    t = int(time.time())
                    for i in range(len(libiisi.qudata_sxhb)):
                        try:
                            insertsql += 'insert into {5}.sens_data_{0:03d}_month_{1} (dev_id,dev_data,date_create) values ({2},{3},{4});'.format(
                                libiisi.qudata_sxhb[i], ym, devid, lstdata[i],
                                t, libiisi.cfg_dbname_dg)
                        except:
                            pass
                    if len(insertsql) > 0:
                        yield self.mydata_collector(insertsql, need_fetch=0)

                elif raw_string.startswith('QH:'):  # 读取支持的指令
                    msgpub = self.init_msgws(msgws.rqIpcCtl(), 'ipc.lscmd.get')
                    msgpub.dev_id.extend([devid])
                    msgpub.dev_cmds = raw_string[3:].replace(' ', '').replace(
                        '|', ',')
                    libiisi.send_to_zmq_pub(
                        'ipc.rep.ipc.lscmd.get.{0}'.format(devid),
                        msgpub.SerializeToString())
                elif raw_string.startswith('QD:'):  # 读取日期
                    msgpub = self.init_msgws(msgws.rqIpcCtl(), 'ipc.date.get')
                    msgpub.dev_id.extend([devid])
                    s = raw_string[3:].split(',')
                    msgpub.dev_datetime = int(
                        mx.time2stamp('{0}-{1}-{2} 00:00:00'.format(
                            s[0], s[1], s[2])))
                    libiisi.send_to_zmq_pub(
                        'ipc.rep.ipc.date.get.{0}'.format(devid),
                        msgpub.SerializeToString())
                elif raw_string.startswith('QT:'):  # 读取时间
                    msgpub = self.init_msgws(msgws.rqIpcCtl(), 'ipc.time.get')
                    msgpub.dev_id.extend([devid])
                    s = raw_string[3:].split(',')
                    msgpub.dev_datetime = int(
                        mx.time2stamp('{0}-{1}-{2} {3}:{4}:{5}'.format(
                            time.localtime()[0],
                            time.localtime()[1],
                            time.localtime()[2], s[0], s[1], s[2])))
                    libiisi.send_to_zmq_pub(
                        'ipc.rep.ipc.time.get.{0}'.format(devid),
                        msgpub.SerializeToString())
                elif raw_string.startswith('QV:') or raw_string.startswith(
                        'Device ID:'):  # 读取版本
                    msgpub = self.init_msgws(msgws.rqIpcCtl(), 'ipc.verf.get')
                    msgpub.dev_id.extend([devid])
                    msgpub.dev_ver = raw_string
                    libiisi.send_to_zmq_pub(
                        'ipc.rep.ipc.verf.get.{0}'.format(devid),
                        msgpub.SerializeToString())
                elif raw_string.startswith('QC:'):  # 设置日期和时间
                    msgpub = self.init_msgws(msgws.rqIpcCtl(),
                                             'ipc.datetime.set')
                    msgpub.dev_id.extend([devid])
                    if 'completed' in raw_string:
                        msgpub.dev_datetime = 1
                    else:
                        msgpub.dev_datetime = 0
                    libiisi.send_to_zmq_pub(
                        'ipc.rep.ipc.datetime.set.{0}'.format(devid),
                        msgpub.SerializeToString())
                else:
                    msg.head.if_st = 46
                    msg.head.if_msg = 'raw data error.'
            elif devid[:6] == "902001":  # 武汉天河机场
                x = "1,2,3,4,5,6,7,8,9,10"
                if os.path.isfile("list.txt"):
                    with open("list.txt", "r") as f:
                        x = f.readline()
                        f.close()
                y = rqmsg.raw_string.split(',')
                tcsdata = dict()
                if y[1] == "1":  # off
                    for i in range(1, 7):
                        tcsdata['k{0}'.format(i)] = 0

                    tcsmsg = libiisi.initRtuJson(2, 7, 1, 1, 1,
                                                 'wlst.rtu.4b00',
                                                 self.request.remote_ip, 0, x,
                                                 tcsdata)
                    # libiisi.set_to_send(tcsmsg, 0, False)
                    libiisi.send_to_zmq_pub(
                        'tcs.req.{0}.wlst.rtu.2210'.format(
                            libiisi.cfg_tcs_port),
                        json.dumps(tcsmsg, separators=(',', ':')).lower())
                else:
                    for i in range(1, 7):
                        tcsdata['k{0}'.format(i)] = 1
                    tcsmsg = libiisi.initRtuJson(2, 7, 1, 1, 1,
                                                 'wlst.rtu.4b00',
                                                 self.request.remote_ip, 0, x,
                                                 tcsdata)
                    # libiisi.set_to_send(tcsmsg, 0, False)
                    libiisi.send_to_zmq_pub(
                        'tcs.req.{0}.wlst.rtu.2210'.format(
                            libiisi.cfg_tcs_port),
                        json.dumps(tcsmsg, separators=(',', ':')).lower())
            del devid, raw_string, createsql, insertsql, db_names
        else:
            msg.head.if_st = 0
            msg.head.if_msg = 'Security code error'

        self.write(mx.convertProtobuf(msg))
        self.finish()
        del msg, rqmsg, legal
Exemplo n.º 12
0
    def post(self):
        user_data, rqmsg, msg, user_uuid = yield self.check_arguments(msgws.rqLduDataGet(), None)

        if user_data is not None:
            if user_data['user_auth'] in libiisi.can_read:
                # 验证用户可操作的设备id
                yield self.update_cache('r', user_uuid)
                if 0 in user_data['area_r'] or user_data['is_buildin'] == 1:
                    rtu_ids = list(rqmsg.tml_id)
                else:
                    rtu_ids = self.check_tml_r(user_uuid, list(rqmsg.tml_id))

                if len(rtu_ids) == 0:
                    msg.head.if_st = 11
                else:
                    yield self.update_cache()
                    for tml_id in rtu_ids:
                        phy_id, fid, tml_name = self.get_phy_info(tml_id)
                        if phy_id == -1:
                            continue
                        if fid > 0:
                            addr = ','.join([str(a) for a in self.get_phy_list([fid])])
                            cid = phy_id
                            tra = 2
                        else:
                            addr = str(phy_id)
                            cid = 1
                            tra = 1
                        if tra == 2:  # 485 分解为单回路
                            noctl = False
                            for ln in rqmsg.loop_id:
                                s = ['0'] * 8
                                if ln in (1, 2):
                                    noctl = True
                                    s[8 - ln] = '1'
                                    tcsmsg = libiisi.initRtuJson(2, 7, 1, 1, tra, 'wlst.ldu.2600',
                                                                 self.request.remote_ip, 0, addr,
                                                                 dict({'ln': int(''.join(s), 2)}))
                                    libiisi.send_to_zmq_pub(
                                        'tcs.req.{0}.wlst.ldu.2600'.format(libiisi.cfg_tcs_port),
                                        json.dumps(tcsmsg,
                                                   separators=(',', ':')).lower())
                            if not noctl:
                                msg.head.if_st = 46
                        else:
                            s = ['0'] * 8
                            for ln in rqmsg.loop_id:
                                if ln in (1, 2, 3, 4, 5, 6):
                                    s[8 - ln] = '1'
                            if int(s, 2) > 0:
                                tcsmsg = libiisi.initRtuJson(2, 7, 1, 1, tra, 'wlst.ldu.2600',
                                                             self.request.remote_ip, 0, addr,
                                                             dict({'ln': int(''.join(s), 2)}))
                                libiisi.send_to_zmq_pub(
                                    'tcs.req.{0}.wlst.ldu.2600'.format(libiisi.cfg_tcs_port),
                                    json.dumps(tcsmsg,
                                               separators=(',', ':')).lower())
                            else:
                                msg.head.if_st = 46
            else:
                msg.head.if_st = 11

        self.write(mx.code_pb2(msg, self._go_back_format))
        self.finish()
        del msg, rqmsg, user_data, user_uuid