def who_is(self,config): function.log('whoIs',config) self.userdata=[] BIPSimpleApplication.who_is(self, low_limit=config['lowlimits'], high_limit=config['highlimits'] ) return self.userdata
def loop(self): while self.config['enable']: for child in self.config['children']: if child.config['enable'] and child.has_thread: child.loop() self.num=(self.num+1)%1000000 time.sleep(self.config.get('interval',1000)/1000) function.log(self,'exit')
def loads(self,v): rt=None try: rt=json.loads(v,object_hook=self.as_complex) except Exception as e: traceback.print_exc() function.log('jsonloads',e,v) return rt
def do_IAmRequest(self,apdu): function.log('iam',apdu.iAmDeviceIdentifier[0],apdu.iAmDeviceIdentifier[1]) device=dict( Id="%s:%s"%(apdu.iAmDeviceIdentifier[0],apdu.iAmDeviceIdentifier[1]), pduSource=[apdu.pduSource.addrNet,[d for d in apdu.pduSource.addrAddr]], ) if self.userdata is not None: self.userdata.append(device) self.read(device['pduSource'],device['Id'],'objectList',device)
def updateBefore(self,cls,Id,value): if 'datetime' in value and os.name != "nt": from datetime import datetime t=value['datetime'] if isinstance(t,int): t=datetime.fromtimestamp(t).strftime('%Y.%m.%d-%H:%M:%S') os.system('date -s %s'%t) os.system('hwclock -w') dt = datetime.now() function.log('now_data %s',dt.strftime('%Y-%m-%d %H:%M:%S'))
def initFinish(self): function.log(self.config) self.ctx=DLL.modbus_new_rtu( msg.COM_NAMES[self.config["port"]], self.config["baudrate"], self.config["parity"], self.config["databit"], self.config["stopbit"], ) _thread.start_new_thread(self.loop,())
def add(self,cls,Id,**kwargs): device=self._search(None,Id) if len(device)==0: device=cls(Id,self,**kwargs) self.config['children'].append(device) self.save() return self.error("success",statu=0) else: function.log('add error',Id,[d.config['Id'] for d in self.config['children']]) return self.error("id exist")
def run(self,name): f=os.popen('candump %s'%name) size=50 while self.config['enable']: if size!=1: s=f.read(size) size=1 function.log('can readfirst',s) else: s=f.read(size) self.buff+=s
def test(self,testlist): function.log('testBegin') for testTask in testlist: function.log(testTask) if len(testTask)==3: num=testTask[2] else: num=1 for i in range(num): function.log(i,self.dumps(self.callback(testTask[0],testTask[1]))) function.log('testFinish')
def runTer(self): function.log('runTer') while True: for key in self.sysIden: value=DEVICES_TREE[key].config if key=='L0': if self.io.flag==1: value['value']=1 else: value['value']=0 self.deviceWrite(**value) elif key=='L1': if self.io.flag==2: value['value']=1 else: value['value']=0 self.deviceWrite(**value) self.io.flag=0 time.sleep(1.5)
def do_GET(self): function.log(self.path) paths = self.path.split('?') path = None if len(paths) >= 2: inp = {} path, paramStr = paths rt = dict(statu=0, msg="", data={}, array=[]) paramStr = paramStr.replace('\\&', '(').replace('\\=', ')') for keyValue in paramStr.split('&'): pm = keyValue.split('=') if len(pm) == 2: inp[pm[0]] = pm[1].replace('(', '&').replace(')', '=') function.log('input', inp, paths[0], paramStr) if inp.get('account', None) != msg.FG['account'] or inp.get( 'password', None) != msg.FG['password']: rt['msg'] = "用户名或者密码错误" rt["statu"] = -1 elif path == '/login': rt["statu"] = 0 elif path in [ '/savePf', '/saveMqtt', '/saveNet', '/saveUser', '/recover', '/restart' ]: if inp.get('method', None) == 'get': if path == '/saveNet': data = function.networkInfo( inp.get('name', msg.FG["localcom"])) msg.FG.update( dict(localcom=inp.get('name', msg.FG["localcom"]), mac=data['HWaddr'], localip=data.get('addr', ''), netmask=data.get("Mask", ''), gateway=data.get('Bcast', ''))) for key in data: msg.FG[key] = data[key] for name in inp['names'].split(','): rt['array'].append(msg.FG[name]) elif inp.get('method', None) == 'save': rt['msg'] = "设置成功" if path == '/saveUser': if inp['newpassword1'] != inp['newpassword2']: rt['msg'] = "两次输入密码不相同" elif inp['password'] != msg.FG['password']: rt['msg'] = '请确认原密码是否正确' else: msg.FG['password'] = inp['password'] elif path == '/saveNet': if inp['localcom'] == 'eth0': with open('/etc/network/interfaces', 'w') as f: f.write(msg.SET_NETIP % (inp['localip'], inp['netmask'])) wifi = msg.WIFISET % (inp['wifiName'], inp['wifiPassword']) print('set wifi %s' % wifi) with open('/etc/wpa_supplicant.conf', 'w') as f: f.write(wifi) elif path == '/recover': msg.FG.update(msg.DEFAULT_PARAM) elif path == '/restart': os.system('reboot') else: for key in inp: msg.FG[key] = inp[key] rs = json.dumps(rt).encode('utf_8') function.log('out', rs) else: with open('app/bLink/client/html/index.html', 'rb') as f: rs = f.read() sends = (HTTP_S % (len(rs), rs.decode('utf-8'))).encode('utf-8') self.wfile.write(sends)