Beispiel #1
0
 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
Beispiel #2
0
 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
Beispiel #3
0
    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
Beispiel #4
0
 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
Beispiel #5
0
 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
Beispiel #6
0
    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
Beispiel #7
0
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"
Beispiel #8
0
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]
Beispiel #9
0
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]
Beispiel #10
0
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"
Beispiel #11
0
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"
Beispiel #12
0
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"
Beispiel #13
0
def pytrans(content,adress):
    cmodem.doSleep(1)
    return "OK"  
Beispiel #14
0
     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)
Beispiel #15
0
def pytrans(content, adress):
    cmodem.doSleep(1)
    return "OK"
Beispiel #16
0
        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)