Esempio n. 1
0
 def write(self, data):
     """Output the given string over the serial port."""
     if self.sock is None:
         raise serial.portNotOpenError
     t = len(data)
     d = data
     while t > 0:
         try:
             if self._writeTimeout is not None and self._writeTimeout > 0:
                 _,ready,_ = select.select([],[self.sock],[],
                                               self._writeTimeout)
                 if not ready:
                     raise serial.writeTimeoutError
             n = self.sock.send(d)
             if self._dump:
                 print hexdump(d[:n])
             if self._writeTimeout is not None and self._writeTimeout > 0:
                 _,ready,_ = select.select([],[self.sock],[],
                                           self._writeTimeout)
                 if not ready:
                     raise serial.writeTimeoutError
             d = d[n:]
             t = t - n
         except OSError,v:
             if v.errno != errno.EAGAIN:
                 raise
Esempio n. 2
0
 def write(self, data):
     """Output the given string over the serial port."""
     if self.sock is None:
         import serial
         raise serial.portNotOpenError()
     t = len(data)
     d = data
     while t > 0:
         try:
             if self._writeTimeout is not None and self._writeTimeout > 0:
                 _, ready, _ = select.select([], [self.sock], [],
                                             self._writeTimeout)
                 if not ready:
                     raise serial.writeTimeoutError
             n = self.sock.send(d)
             if self._dump:
                 print hexdump(d[:n])
             if self._writeTimeout is not None and self._writeTimeout > 0:
                 _, ready, _ = select.select([], [self.sock], [],
                                             self._writeTimeout)
                 if not ready:
                     raise serial.writeTimeoutError
             d = d[n:]
             t = t - n
         except OSError, v:
             if v.errno != errno.EAGAIN:
                 raise
Esempio n. 3
0
 def _log_write(self, data):
     if not self._logger:
         return
     try:
         print >>self._logger, "WRITE:\n%s" % hexdump(data)
     except:
         print >>sys.stderr, "Cannot log written data"
Esempio n. 4
0
 def _log_read(self, data):
     if not self._logger:
         return
     try:
         print >>self._logger, "READ:\n%s" % hexdump(data)
     except:
         print >>sys.stderr, "Cannot log read data"
Esempio n. 5
0
 def _log_write(self, data):
     if not self._logger:
         return
     try:
         print >> self._logger, "WRITE:\n%s" % hexdump(data)
     except:
         print >> sys.stderr, 'Cannot log written data'
Esempio n. 6
0
 def _log_read(self, data):
     if not self._logger:
         return
     try:
         print >> self._logger, "READ:\n%s" % hexdump(data)
     except:
         print >> sys.stderr, 'Cannot log read data'
Esempio n. 7
0
    def test_rw_sector_1(self):
        from hashlib import sha1
        buf = Array('I')
        #		length = 65536
        length = len(self.flash)
        print "length: " + str(length)
        print "Build Sequence"
        for address in range(0, length):
            buf.append(address)
        print "Swap sequence"
        buf = buf.byteswap()
        #print "Erase flash from %08X to %08X" % (0, length)
        print "Erase all of the flash"
        self.flash.erase(0, len(self.flash))
        bufstr = buf.tostring()
        dout = Array('B')
        dout.fromstring(bufstr)
        self.flash.write(0, bufstr)
        print "Verify Flash"
        wmd = sha1()
        wmd.update(buf.tostring())
        refdigest = wmd.hexdigest()
        print "Read Flash"
        din = self.flash.read(0, length)
        print "Dump Flash"
        print hexdump(din.tostring())
        print "Verify Flash"
        rmd = sha1()
        rmd.update(din.tostring())
        newdigest = rmd.hexdigest()
        print "Reference: ", refdigest
        print "Retrieved: ", newdigest

        try:
            f = open("din.hex", "w")
            din.tofile(f)
            f.close()
        except IOError, err:
            print "Error writing to din file"
Esempio n. 8
0
	def test_rw_sector_1(self):
		from hashlib import sha1
		buf = Array('I')
#		length = 65536
		length = len(self.flash)
		print "length: " + str(length)
		print "Build Sequence"
		for address in range (0, length):
			buf.append(address)
		print "Swap sequence"
		buf = buf.byteswap()
		#print "Erase flash from %08X to %08X" % (0, length)
		print "Erase all of the flash"
		self.flash.erase(0, len(self.flash))
		bufstr = buf.tostring()
		dout = Array('B')
		dout.fromstring(bufstr)
		self.flash.write(0, bufstr)
		print "Verify Flash"
		wmd = sha1()
		wmd.update(buf.tostring())
		refdigest = wmd.hexdigest()
		print "Read Flash"
		din = self.flash.read(0, length)
		print "Dump Flash"
		print hexdump(din.tostring())
		print "Verify Flash"
		rmd = sha1()
		rmd.update(din.tostring())
		newdigest = rmd.hexdigest()
		print "Reference: ", refdigest
		print "Retrieved: ", newdigest

		try:
			f = open("din.hex", "w")
			din.tofile(f)
			f.close()
		except IOError, err:
			print "Error writing to din file"