def workWmR(self,content,readsize,waitsec=1,maxARead=1024): # after 0.8.6 if(maxARead<1): return [self.workWR(content, readsize, waitsec)] cpr=str(content) wlog.getLogger().debug("CDTU workWmR towrite :" +cpr[0:60]) self.write(content) cmodem.doSleep(waitsec) datas=[] worksize=readsize cworksize=min(worksize,maxARead) while(worksize>0): data= self.doRead(cworksize) wlog.getLogger().debug(str(len(data))+" bytes--CDTU workWmR readed:" +str(data)[:21]) if(data is None): cmodem.doSleep(waitsec) data= self.doRead(cworksize) if(data is None): break datas.append(data) worksize=worksize-cworksize if(worksize>0): raise "error rcv" return datas
def work(self,content,waitsec=1): self.write(content) cmodem.doSleep(waitsec) data= self.readline() #print "work" , data wlog.getLogger().debug("CDTU work readed:" +str(data)) return data
def workWmR(self, content, readsize, waitsec=1, maxARead=1024): # after 0.8.6 if (maxARead < 1): return [self.workWR(content, readsize, waitsec)] cpr = str(content) wlog.getLogger().debug("CDTU workWmR towrite :" + cpr[0:60]) self.write(content) cmodem.doSleep(waitsec) datas = [] worksize = readsize cworksize = min(worksize, maxARead) while (worksize > 0): data = self.doRead(cworksize) wlog.getLogger().debug( str(len(data)) + " bytes--CDTU workWmR readed:" + str(data)[:21]) if (data is None): cmodem.doSleep(waitsec) data = self.doRead(cworksize) if (data is None): break datas.append(data) worksize = worksize - cworksize if (worksize > 0): raise "error rcv" return datas
def work(self, content, waitsec=1): self.write(content) cmodem.doSleep(waitsec) data = self.readline() #print "work" , data wlog.getLogger().debug("CDTU work readed:" + str(data)) return data
def workWR(self,content,readsize,waitsec=1): # after 0.8.5 cpr=str(content) wlog.getLogger().debug("CDTU workWR towrite :" +cpr[0:60]) self.write(content) cmodem.doSleep(waitsec) data= self.doRead(readsize) #print "work" , data wlog.getLogger().debug(str(len(data))+" bytes--CDTU workWR readed:" +str(data)) return data
def workWR(self, content, readsize, waitsec=1): # after 0.8.5 cpr = str(content) wlog.getLogger().debug("CDTU workWR towrite :" + cpr[0:60]) self.write(content) cmodem.doSleep(waitsec) data = self.doRead(readsize) #print "work" , data wlog.getLogger().debug( str(len(data)) + " bytes--CDTU workWR readed:" + str(data)) return data
def dtutrans(content,adress): rok="OK" ddelay=cmodem.getDelay() sdtu=None try: sdtu=cdtu.getDTU() sdtu.open() except Exception,x: wlog.getLogger().error("FAIL_DTU remote dtu error") wlog.doTraceBack() cmodem.doSleep(10)# ddelay['socket']['recv'] 10 return "FAIL_DTU"
def sizeTranBydtu(content,adress,readsize,maxARead=1024): rok=["OK",None] ddelay=cmodem.getDelay() sdtu=None try: sdtu=cdtu.getDTU() sdtu.open() except Exception,x: wlog.getLogger().error("FAIL_DTU remote dtu error") wlog.doTraceBack() cmodem.doSleep(10)# ddelay['socket']['recv'] 10 return ["FAIL_DTU",None]
def sizeTranBydtu(content, adress, readsize, maxARead=1024): rok = ["OK", None] ddelay = cmodem.getDelay() sdtu = None try: sdtu = cdtu.getDTU() sdtu.open() except Exception, x: wlog.getLogger().error("FAIL_DTU remote dtu error") wlog.doTraceBack() cmodem.doSleep(10) # ddelay['socket']['recv'] 10 return ["FAIL_DTU", None]
def dtutrans(content, adress): rok = "OK" ddelay = cmodem.getDelay() sdtu = None try: sdtu = cdtu.getDTU() sdtu.open() except Exception, x: wlog.getLogger().error("FAIL_DTU remote dtu error") wlog.doTraceBack() cmodem.doSleep(10) # ddelay['socket']['recv'] 10 return "FAIL_DTU"
def socktrans(content,adress): sock=None; rok="OK" ddelay=cmodem.getDelay() try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(30) sock.connect(adress) except Exception,x: wlog.getLogger().error("FAIL_CON remote socket error:"+str(adress)) wlog.doTraceBack() cmodem.doSleep(10)# ddelay['socket']['recv'] 10 return "FAIL_CON"
def socktrans(content, adress): sock = None rok = "OK" ddelay = cmodem.getDelay() try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(30) sock.connect(adress) except Exception, x: wlog.getLogger().error("FAIL_CON remote socket error:" + str(adress)) wlog.doTraceBack() cmodem.doSleep(10) # ddelay['socket']['recv'] 10 return "FAIL_CON"
def pytrans(content,adress): cmodem.doSleep(1) return "OK"
wlog.getLogger().error("FAIL_CON remote socket error:"+str(adress)) wlog.doTraceBack() cmodem.doSleep(10)# ddelay['socket']['recv'] 10 return "FAIL_CON" # wlog.getLogger().debug( lmsg ) try: sock.setblocking(False) r=sock.send(content) #print r #todo data=None dtimes=0 while dtimes<ddelay['socket']['times']: dtimes+=1 cmodem.doSleep(ddelay['socket']['recv']) # reduce cpu usage and syn socket try: data=sock.recv(1024) except Exception,x: wlog.getLogger().error("ignor sock.recv:"+str(dtimes)) wlog.doTraceBack() continue if(data) : break if(data is not None and len(data)>0) : linux.doPrint( data) if(data[0]=='1'): rok="OK" wlog.getLogger().debug("send data success:" + data)
def pytrans(content, adress): cmodem.doSleep(1) return "OK"
wlog.getLogger().error("FAIL_CON remote socket error:" + str(adress)) wlog.doTraceBack() cmodem.doSleep(10) # ddelay['socket']['recv'] 10 return "FAIL_CON" # wlog.getLogger().debug( lmsg ) try: sock.setblocking(False) r = sock.send(content) #print r #todo data = None dtimes = 0 while dtimes < ddelay['socket']['times']: dtimes += 1 cmodem.doSleep( ddelay['socket']['recv']) # reduce cpu usage and syn socket try: data = sock.recv(1024) except Exception, x: wlog.getLogger().error("ignor sock.recv:" + str(dtimes)) wlog.doTraceBack() continue if (data): break if (data is not None and len(data) > 0): linux.doPrint(data) if (data[0] == '1'): rok = "OK" wlog.getLogger().debug("send data success:" + data)