示例#1
0
def sendPackets(s, filename):

    stream = file(filename, 'rb')
    sequence = 1

    data = stream.read(packet_size)
    if not data:
        print "File Empty"
        return 

    errcnt = 0
    fullcrc = 0

    print "Packet Transferred: "
    while 1:
        pkt = asmPkt(data, sequence)
        fullcrc = verify(data, fullcrc)

        for ch in pkt:
            s.write(ch)
            if debug: sys.stdout.write(hex(ord(ch))+' ')
        if debug:
            print
            print

        if debug: debugPrint(s)

        if checkAck(s) == True:
            if debug:
                print "checkAck -> True"
                print " %r" % sequence
            else:
                sys.stdout.write('>')
                sys.stdout.flush()
            sequence = (sequence + 1) % 0x100  # increment sequence number
            if debug: print sequence
            data = stream.read(packet_size)
            if not data:
                print
                print "CRC of file = " + hex(fullcrc)
                return True
        else:
            print
            print "checkAck -> False"
            print "Packet %r Failed" % sequence
            errcnt += 1
            if errcnt > 0:
                print "Transfer Errors"
                return False

        continue

    print "Transfer Complete"

    return True
示例#2
0
def sendPackets(s, filename):

    stream = file(filename, 'rb')
    sequence = 1

    data = stream.read(packet_size)
    if not data:
        print "Error: Empty Compiled Script File"
        return False 

    errcnt = 0
    fullcrc = 0
    
    print
    
    while 1:
        pkt = asmPkt(data, sequence)
        fullcrc = verify(data, fullcrc)

        for ch in pkt:
            s.write(ch)
            if debug: sys.stdout.write(hex(ord(ch))+' ')
        if debug:
            print
            print

        if debug: debugPrint(s)

        if checkAck(s) == True:
            if debug:
                print "checkAck -> True"
                print " %r" % sequence
            else:
                sys.stdout.write('.')
                sys.stdout.flush()
            sequence = (sequence + 1) % 0x100  # increment sequence number
            if debug: print sequence
            data = stream.read(packet_size)
            if not data:
                print
                print "CRC:" + hex(fullcrc)
                return True
        else:
            print
            print "Packet %r Failed to Upload" % sequence
            errcnt += 1
            if errcnt > 0:
                sys.stdout.flush()
                return False

        continue

    print 
    return True