Ejemplo n.º 1
0
def query_netparam(devid):
    data = grab_tcp_package(devid)
    data[4] = "%s" % CMD_REMOTE_SYS_QUERY
    data[8] = "%s" % getsequence()
    sendstr = "%s" % string.join(data, ',')
    try:
        if net_train.send2mss(sendstr) != 1:
            raise 1
        log.recLog(str(devid), log.LOG_PARAM_QUERY, data[8])
        #tkMessageBox.showwarning(unicode(''),unicode('已发送网管查询!'))
    except:
        tkMessageBox.showwarning(unicode('警告!'), unicode('与MSS通信失败!'))
Ejemplo n.º 2
0
def query_netparam(devid):
	data = grab_tcp_package(devid)
	data[4]="%s"%CMD_REMOTE_SYS_QUERY
	data[8]= "%s"%getsequence()
	sendstr = "%s"%string.join(data,',')
	try:	
		if net_train.send2mss(sendstr)!=1	:
			raise 1
		log.recLog(str(devid),log.LOG_PARAM_QUERY,data[8])
		#tkMessageBox.showwarning(unicode(''),unicode('已发送网管查询!'))
	except:
		tkMessageBox.showwarning(unicode('警告!'),unicode('与MSS通信失败!'))
Ejemplo n.º 3
0
    def onsave(self):
        intval = 0
        params = []
        for w in self.widgets:
            if w[2] == 'ck':

                v = 0
                stm = "v = self.var%s.get()" % w[0]  #取checkbutton帮定的IntVar的值
                exec(stm)
                if v:
                    params.append("%s,1,1" % w[0])
                else:
                    params.append("%s,1,0" % w[0])
#					pos = constdef.alarmflags.index(w[0])
#					intval |=1<<pos

#将告警值存入数据库
#sql = "update repeaterinfo set ALARMFLAG=%d where id = %d"%(intval,self.id)
#print sql
        data = session.grab_tcp_package(self.id)
        data[4] = "%s" % constdef.cmd_list['SET_AUTO_ALARM_FLAG']
        data[8] = "%s" % session.getsequence()

        try:
            #session.dbcnn.Execute(sql)
            #notify mss by net_train
            sendstr = "%s@%s" % (string.join(data,
                                             ','), string.join(params, ";"))
            if net_train.send2mss(sendstr) != 1:

                raise 1

            tkMessageBox.showwarning('', unicode('告警使能标志设置发送中!'))

        except:
            tkMessageBox.showwarning('', unicode(' 与MSS通信失败!'))
            return
        #写入日志
        log.recLog(str(self.id), log.LOG_MODIFY_ALARMFLAG, data[8])
Ejemplo n.º 4
0
	def onsave(self):
		intval=0
		params=[]
		for w in self.widgets:
			if w[2]=='ck':
				
				v =0
				stm = "v = self.var%s.get()"%w[0]	#取checkbutton帮定的IntVar的值
				exec(stm)
				if v:
					params.append("%s,1,1"%w[0])
				else:
					params.append("%s,1,0"%w[0])
#					pos = constdef.alarmflags.index(w[0])
#					intval |=1<<pos					
					
		#将告警值存入数据库
		#sql = "update repeaterinfo set ALARMFLAG=%d where id = %d"%(intval,self.id)
		#print sql
		data = session.grab_tcp_package(self.id)
		data[4]="%s"%constdef.cmd_list['SET_AUTO_ALARM_FLAG']
		data[8]= "%s"%session.getsequence()
		
		try:
			#session.dbcnn.Execute(sql)
			#notify mss by net_train
			sendstr= "%s@%s"%(string.join(data,','),string.join(params,";"))
			if  net_train.send2mss(sendstr)!=1:
				
				raise 1

			tkMessageBox.showwarning('',unicode('告警使能标志设置发送中!'))
			
		except:
			tkMessageBox.showwarning('',unicode(' 与MSS通信失败!'))
			return 
		#写入日志
		log.recLog(str(self.id),log.LOG_MODIFY_ALARMFLAG,data[8])
Ejemplo n.º 5
0
	def onsave(self):
		'''数据储存'''
		save_to_close=1
		sql =''
		data=[]
		id =0
		
		
		
		if self.devinfo!=None:
			if self.check('UPDATE')==0:
				return 
			else:
				# do update 
				sql = """
						update repeaterinfo  set 
						NAME=:NAME,
						REPEATERTYPE=:REPEATERTYPE,						
						AREA_ID=:AREA_ID,						
						RUN_DATE=:RUN_DATE,
						REPEATER_PHONE=:REPEATER_PHONE,						
						PRODUCT_ID=:PRODUCT_ID,
						PROVIDER_ID=:PROVIDER_ID,
						QUERY_INTERVAL=:QUERY_INTERVAL,
						SITE=:SITE 
						where id=%s 
						"""%self.devinfo['ID']
		else:
			if self.check('INSERT')==0:
				return 		
			else:
				sql ="""
						insert into repeaterinfo 
						(ID,NAME,REPEATERTYPE,AREA_ID,
						RUN_DATE,REPEATER_PHONE,
						PRODUCT_ID,PROVIDER_ID,
						QUERY_INTERVAL,SITE) 
						values(:ID,:NAME,:REPEATERTYPE,:AREA_ID,
						:RUN_DATE,:REPEATER_PHONE,
						:PRODUCT_ID,:PROVIDER_ID,
						:QUERY_INTERVAL,:SITE)
					"""
				id = session.getsequence()
				data.append(['ID',id])
				
		data.append(['NAME',self.devname.getvalue().strip()])
		providerid = session.match(session.providers,'NAME','STRING',self.manufaturer.cget('value').strip(),'ID')
		productid =   session.match(session.products,'DESCRIPT','STRING',self.devtype.cget('value').strip(),'ID')
		repeatertype = 0
		devcat =0
		subdevno =0 #设备编号
		for i in session.repeatertype:#查找设备类别
			if providerid==i['PROVIDER'] and productid==i['PRODUCT_ID']:				
				repeatertype=i['TYPE_ID']
				devcat =8
					
		data.append(['REPEATERTYPE',int(repeatertype)])
		
		area_id = session.match(session.areas,'NAME','STRING',self.area.cget('value').strip(),'ID')
		data.append(['AREA_ID',int(area_id)])
		
		data.append(['RUN_DATE',self.runtime.getvalue()])
		data.append(['REPEATER_PHONE',self.devphone.getvalue()])
		data.append(['PRODUCT_ID',productid])
		data.append(['PROVIDER_ID',providerid])
		data.append(['QUERY_INTERVAL',int(self.query_interval.getvalue())])
		data.append(['SITE',self.site.getvalue()])
		#print data
		try:
			session.dbcnn.Execute2(sql,data)		
		except:
			tkMessageBox.showwarning(unicode('警告'),unicode('数据操作失败 !'))				
			return
		


		if self.devinfo!=None:
			id = int(self.devinfo['ID'])

		#更新当前记录
		sql ="select * from repeaterinfo where id =%s"%id
		devs = session.getdata(sql)
		self.devinfo = devs[0]

		#更新设备缓存信息
		session.user.load_repeaters()


		# send updatelist package to mss 
		str ="0,1,2,3,%s,4,5,6,7,8"%constdef.cmd_list["UPDATE_DEV_LIST"]
		
		if net_train.send2mss(str)==0:
			tkMessageBox.showwarning(unicode('设备更新'),unicode('通知MSS失败!'))				
			return 
		
			
		

		#窗口关闭
		self.destroy()
    def onset(self):
        """ 系统参数设置"""
        if self.devinfo['MONI_ALARM_ID1'] == None:
            tkMessageBox.showwarning(unicode('警告!'), unicode('设备当前无系统参数返回!'))
            return
        data = []
        data = session.grab_tcp_package(self.devinfo['ID'])
        data[4] = "%s" % constdef.CMD_REMOTE_SYS_SET
        data[8] = "%s" % session.getsequence()
        #-------------------------------------------------------
        s = []
        if sys_value_can_set['NMS_PHONE']:  #
            if self.central_phone.getvalue().strip() == '':
                tkMessageBox.showwarning(unicode('警告!'),
                                         unicode('控制中心电话不能为空!'))
                return
            s.append("QUERY_PHONE,2,%s" %
                     self.central_phone.getvalue().strip())
        else:
            s.append("NMS_PHONE,2,%s" % self.devinfo['QUERY_PHONE'].strip())

        if sys_value_can_set['ALARM_PHONE']:  #
            if self.alert_phone.getvalue().strip() == '':
                tkMessageBox.showwarning(unicode('警告!'), unicode('告警电话不能为空!'))
                return
            s.append("ALARM_PHONE,2,%s" % self.alert_phone.getvalue().strip())
        else:
            s.append("ALARM_PHONE,2,%s" % self.devinfo['ALARAM_PHONE'].strip())

        if sys_value_can_set['MONI_ALARM_ID1']:  #
            #if self.alert_phone.getvalue().strip()=='':
            #	tkMessageBox.showwarning(unicode('警告!'),unicode('告警电话不能为空!'))
            #	return
            #s.append('ALARM_PHONE',2,self.alert_phone.getvalue().strip())
            pass
        else:
            s.append("MONI_ALARM_ID1,1,%s" % self.devinfo['MONI_ALARM_ID1'])

        if sys_value_can_set['MONI_ALARM_ID2']:  #
            #if self.alert_phone.getvalue().strip()=='':
            #	tkMessageBox.showwarning(unicode('警告!'),unicode('告警电话不能为空!'))
            #	return
            #s.append('ALARM_PHONE',2,self.alert_phone.getvalue().strip())
            pass
        else:
            s.append("MONI_ALARM_ID2,1,%s" % self.devinfo['MONI_ALARM_ID2'])

        if sys_value_can_set['MONI_ALARMFLAG']:
            v = 0
            mask = constdef.LT_ALARM_SWITCH[self.ad0_alert.cget('value')]
            v = v | (mask << 4)
            mask = constdef.LT_ALARM_SWITCH[self.ad1_alert.cget('value')]
            v = v | (mask << 5)
            mask = constdef.LT_ALARM_SWITCH[self.ad2_alert.cget('value')]
            v = v | (mask << 6)
            mask = constdef.LT_ALARM_SWITCH[self.ad3_alert.cget('value')]
            v = v | (mask << 7)
            s.append("MONI_ALARMFLAG,1,%s" % str(v))
        else:
            s.append("MONI_ALARMFLAG,1,%s" % self.devinfo['MONI_ALARMFLAG'])

        if sys_value_can_set['AD0MIN']:
            if not self.ad0min.valid():
                tkMessageBox.showwarning(unicode('警告!'), unicode('AD0MIN 无效!'))
                return
            else:
                s.append("AD0MIN,1,%s" % self.ad0min.getvalue().strip())
        else:
            s.append("AD0MIN,1,%s" % self.devinfo['AD0MIN'])

        if sys_value_can_set['AD0MAX']:
            if not self.ad0max.valid():
                tkMessageBox.showwarning(unicode('警告!'), unicode('AD0MAX 无效!'))
                return
            else:
                s.append("AD0MAX,1,%s" % self.ad0max.getvalue().strip())
        else:
            s.append("AD0MAX,1,%s" % self.devinfo['AD0MAX'])
        #------------------------------------------------------------------
        if sys_value_can_set['AD1MIN']:
            if not self.ad1min.valid():
                tkMessageBox.showwarning(unicode('警告!'), unicode('AD1MIN 无效!'))
                return
            else:
                s.append("AD1MIN,1,%s" % self.ad1min.getvalue().strip())
        else:
            s.append("AD1MIN,1,%s" % self.devinfo['AD1MIN'])

        if sys_value_can_set['AD1MAX']:
            if not self.ad1max.valid():
                tkMessageBox.showwarning(unicode('警告!'), unicode('AD1MAX 无效!'))
                return
            else:
                s.append("AD1MAX,1,%s" % self.ad1max.getvalue().strip())
        else:
            s.append("AD1MAX,1,%s" % self.devinfo['AD1MAX'])
        #------------------------------------------------------------------

        if sys_value_can_set['AD2MIN']:
            if not self.ad2min.valid():
                tkMessageBox.showwarning(unicode('警告!'), unicode('AD2MIN 无效!'))
                return
            else:
                s.append("AD2MIN,1,%s" % self.ad2min.getvalue().strip())
        else:
            s.append("AD2MIN,1,%s" % self.devinfo['AD2MIN'])

        if sys_value_can_set['AD2MAX']:
            if not self.ad2max.valid():
                tkMessageBox.showwarning(unicode('警告!'), unicode('AD2MAX 无效!'))
                return
            else:
                s.append("AD2MAX,1,%s" % self.ad2max.getvalue().strip())
        else:
            s.append("AD2MAX,1,%s" % self.devinfo['AD2MAX'])
        #------------------------------------------------------------------
        if sys_value_can_set['AD3MIN']:
            if not self.ad3min.valid():
                tkMessageBox.showwarning(unicode('警告!'), unicode('AD3MIN 无效!'))
                return
            else:
                s.append("AD3MIN,1,%s" % self.ad3min.getvalue().strip())
        else:
            s.append("AD3MIN,1,%s" % self.devinfo['AD3MIN'])

        if sys_value_can_set['AD3MAX']:
            if not self.ad3max.valid():
                tkMessageBox.showwarning(unicode('警告!'), unicode('AD3MAX 无效!'))
                return
            else:
                s.append("AD3MAX,1,%s" % self.ad3max.getvalue().strip())
        else:
            s.append("AD3MAX,1,%s" % self.devinfo['AD3MAX'])
        #------------------------------------------------------------------

        if sys_value_can_set['DIGIT_ALARM1']:
            pass
            #if not self.digit_alert.valid():
            #	tkMessageBox.showwarning(unicode('警告!'),unicode('数字量告警值无效!'))
            #	return
            #else:
            #	s.append("AD3MAX,1,%s"%self.ad3max.getvalue().strip())
        else:
            s.append("DIGIT_ALARM1,1,%s" % self.devinfo['DIGIT_ALARM1'])

        if sys_value_can_set['DIGIT_ALARM2']:
            pass
        else:
            s.append("DIGIT_ALARM2,1,%s" % self.devinfo['DIGIT_ALARM2'])

        #------------------------------------------------------------------
        mask_val = 0
        if sys_value_can_set['DIGIT_ALARMFLAG1']:  #bit 0-15
            for i in range(16):
                stm = "v =self.d%s_alert.cget('value')" % i
                exec(stm)
                print v
                stm = "v = constdef.LT_ALARM_SWITCH[unicode('%s')]" % v
                print stm
                exec(stm)
                mask_val = mask_val | (int(v) << i)
            print hex(mask_val)
            s.append("DIGIT_ALARMFLAG1,1,%s" % (mask_val & 0x0ff))  #low 8 bits
            s.append("DIGIT_ALARMFLAG2,1,%s" %
                     ((mask_val & 0xff00) >> 8))  #==>high 8 bits

        else:
            s.append("DIGIT_ALARMFLAG1,1,%s" %
                     self.devinfo['DIGIT_ALARMFLAG1'])
            s.append("DIGIT_ALARMFLAG2,1,%s" %
                     self.devinfo['DIGIT_ALARMFLAG2'])

        sendstr = "%s@%s" % (string.join(data, ','), string.join(s, ';'))
        print sendstr
        try:
            if net_train.send2mss(sendstr) != 1:
                print "invoke send2mss failed"
                raise 1

            tkMessageBox.showwarning('', unicode('控制命令发送中!'))
        except:
            tkMessageBox.showwarning('', unicode(' 与MSS通信失败!'))
            return
        log.recLog(str(self.devinfo['ID']), log.LOG_CONTROL, data[8])
Ejemplo n.º 7
0
	def oncontrol(self):
		if self.status==[]:
			return
		if self.control_params==[]:
			return 
		sel_list =[]
		has_sel=0
		for pc in self.control_params:
			
			stm = "v= self.var%s.get()"%pc['PARAMNAME']			
			exec(stm)
			if v:	#如果选择设置 
				print pc['PARAMNAME']
				has_sel=1
				for c in self.control_widget:
					
					if c[0]==pc['PARAMNAME']:						
						
						w = c[1]
						val =''
						if c[2]=='en':
							if not w.valid():
								tkMessageBox.showwarning(unicode('警告!'),unicode('参数值无效:')+pc['DESCRIPT'])
								return
							else:															
								sel_list.append([pc['PARAMNAME'],w.getvalue(),0,1])
						if c[2]=='cb':
							val = w.cget('value')
							try:
								ls1=[]
								ls1 = re.split(';',pc['UI_VALUE_RANGE'])
								for s in ls1:
									ls2 =re.split(':',s)
									
									if ls2[0]==val:	#
										print ls2[0],val,"compare"
										val = int(ls2[1])
										break
									
								
							except:
								val =0
								#tkMessageBox.showwarning(unicode('警告!'),unicode('参数值无效:')+pc['DESCRIPT'])
								#return
							sel_list.append([pc['PARAMNAME'],val,0,1])
						
			else:				
				#取当前状态记录的当前字段值
				fieldname=pc['FIELDNAME']							
				
				cur_rec = self.status[0]	
				try:
					v =cur_rec[fieldname]
					if v==None:
						v=str(session.control_run_param_default)
				except:
					v =str(session.control_run_param_default)
					
				sel_list.append([pc['PARAMNAME'],v,0,0])
		
				
		
		if has_sel==0:	#当前无控制参数,撤销操作 
			return		
		
			
			
		s=[]
		for ctrl_item in sel_list:
			type =""
			type = self.get_paramtype(self.cur_dev['REPEATERTYPE'],ctrl_item[0])
			s.append("%s,%s,%s"%(ctrl_item[0],type,ctrl_item[1]))
			
		data = session.grab_tcp_package(self.id)
		data[4]="%s"%constdef.CMD_REMOTE_CTRL
		data[8]= "%s"%session.getsequence()
		sendstr = "%s@%s"%(string.join(data,','),string.join(s,';'))
		print sendstr
		try:
			if  net_train.send2mss(sendstr)!=1:
				raise 1
			log.recLog(str(self.id),log.LOG_CONTROL,data[8])			
			tkMessageBox.showwarning('',unicode('控制命令发送中!'))			
		except:
			tkMessageBox.showwarning('',unicode(' 与MSS通信失败!'))
			return 
Ejemplo n.º 8
0
    def onsave(self):
        '''数据储存'''
        save_to_close = 1
        sql = ''
        data = []
        id = 0

        if self.devinfo != None:
            if self.check('UPDATE') == 0:
                return
            else:
                # do update
                sql = """
						update repeaterinfo  set 
						NAME=:NAME,
						REPEATERTYPE=:REPEATERTYPE,						
						AREA_ID=:AREA_ID,						
						RUN_DATE=:RUN_DATE,
						REPEATER_PHONE=:REPEATER_PHONE,						
						PRODUCT_ID=:PRODUCT_ID,
						PROVIDER_ID=:PROVIDER_ID,
						QUERY_INTERVAL=:QUERY_INTERVAL,
						SITE=:SITE 
						where id=%s 
						""" % self.devinfo['ID']
        else:
            if self.check('INSERT') == 0:
                return
            else:
                sql = """
						insert into repeaterinfo 
						(ID,NAME,REPEATERTYPE,AREA_ID,
						RUN_DATE,REPEATER_PHONE,
						PRODUCT_ID,PROVIDER_ID,
						QUERY_INTERVAL,SITE) 
						values(:ID,:NAME,:REPEATERTYPE,:AREA_ID,
						:RUN_DATE,:REPEATER_PHONE,
						:PRODUCT_ID,:PROVIDER_ID,
						:QUERY_INTERVAL,:SITE)
					"""
                id = session.getsequence()
                data.append(['ID', id])

        data.append(['NAME', self.devname.getvalue().strip()])
        providerid = session.match(session.providers, 'NAME', 'STRING',
                                   self.manufaturer.cget('value').strip(),
                                   'ID')
        productid = session.match(session.products, 'DESCRIPT', 'STRING',
                                  self.devtype.cget('value').strip(), 'ID')
        repeatertype = 0
        devcat = 0
        subdevno = 0  #设备编号
        for i in session.repeatertype:  #查找设备类别
            if providerid == i['PROVIDER'] and productid == i['PRODUCT_ID']:
                repeatertype = i['TYPE_ID']
                devcat = 8

        data.append(['REPEATERTYPE', int(repeatertype)])

        area_id = session.match(session.areas, 'NAME', 'STRING',
                                self.area.cget('value').strip(), 'ID')
        data.append(['AREA_ID', int(area_id)])

        data.append(['RUN_DATE', self.runtime.getvalue()])
        data.append(['REPEATER_PHONE', self.devphone.getvalue()])
        data.append(['PRODUCT_ID', productid])
        data.append(['PROVIDER_ID', providerid])
        data.append(['QUERY_INTERVAL', int(self.query_interval.getvalue())])
        data.append(['SITE', self.site.getvalue()])
        #print data
        try:
            session.dbcnn.Execute2(sql, data)
        except:
            tkMessageBox.showwarning(unicode('警告'), unicode('数据操作失败 !'))
            return

        if self.devinfo != None:
            id = int(self.devinfo['ID'])

        #更新当前记录
        sql = "select * from repeaterinfo where id =%s" % id
        devs = session.getdata(sql)
        self.devinfo = devs[0]

        #更新设备缓存信息
        session.user.load_repeaters()

        # send updatelist package to mss
        str = "0,1,2,3,%s,4,5,6,7,8" % constdef.cmd_list["UPDATE_DEV_LIST"]

        if net_train.send2mss(str) == 0:
            tkMessageBox.showwarning(unicode('设备更新'), unicode('通知MSS失败!'))
            return

        #窗口关闭
        self.destroy()
Ejemplo n.º 9
0
    def oncontrol(self):
        if self.status == []:
            return
        if self.control_params == []:
            return
        sel_list = []
        has_sel = 0
        for pc in self.control_params:

            stm = "v= self.var%s.get()" % pc['PARAMNAME']
            exec(stm)
            if v:  #如果选择设置
                print pc['PARAMNAME']
                has_sel = 1
                for c in self.control_widget:

                    if c[0] == pc['PARAMNAME']:

                        w = c[1]
                        val = ''
                        if c[2] == 'en':
                            if not w.valid():
                                tkMessageBox.showwarning(
                                    unicode('警告!'),
                                    unicode('参数值无效:') + pc['DESCRIPT'])
                                return
                            else:
                                sel_list.append(
                                    [pc['PARAMNAME'],
                                     w.getvalue(), 0, 1])
                        if c[2] == 'cb':
                            val = w.cget('value')
                            try:
                                ls1 = []
                                ls1 = re.split(';', pc['UI_VALUE_RANGE'])
                                for s in ls1:
                                    ls2 = re.split(':', s)

                                    if ls2[0] == val:  #
                                        print ls2[0], val, "compare"
                                        val = int(ls2[1])
                                        break

                            except:
                                val = 0
                                #tkMessageBox.showwarning(unicode('警告!'),unicode('参数值无效:')+pc['DESCRIPT'])
                                #return
                            sel_list.append([pc['PARAMNAME'], val, 0, 1])

            else:
                #取当前状态记录的当前字段值
                fieldname = pc['FIELDNAME']

                cur_rec = self.status[0]
                try:
                    v = cur_rec[fieldname]
                    if v == None:
                        v = str(session.control_run_param_default)
                except:
                    v = str(session.control_run_param_default)

                sel_list.append([pc['PARAMNAME'], v, 0, 0])

        if has_sel == 0:  #当前无控制参数,撤销操作
            return

        s = []
        for ctrl_item in sel_list:
            type = ""
            type = self.get_paramtype(self.cur_dev['REPEATERTYPE'],
                                      ctrl_item[0])
            s.append("%s,%s,%s" % (ctrl_item[0], type, ctrl_item[1]))

        data = session.grab_tcp_package(self.id)
        data[4] = "%s" % constdef.CMD_REMOTE_CTRL
        data[8] = "%s" % session.getsequence()
        sendstr = "%s@%s" % (string.join(data, ','), string.join(s, ';'))
        print sendstr
        try:
            if net_train.send2mss(sendstr) != 1:
                raise 1
            log.recLog(str(self.id), log.LOG_CONTROL, data[8])
            tkMessageBox.showwarning('', unicode('控制命令发送中!'))
        except:
            tkMessageBox.showwarning('', unicode(' 与MSS通信失败!'))
            return