freemyipod r343 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r342‎ | r343 | r344 >
Date:22:36, 19 December 2010
Author:farthen
Status:new
Tags:
Comment:
libembios/embios.py: fix a silly bug and let embios.py actually use the cached values
Modified paths:
  • /embios/trunk/tools/embios.py (modified) (history)
  • /embios/trunk/tools/libembios.py (modified) (history)

Diff [purge]

Index: embios/trunk/tools/embios.py
@@ -264,19 +264,19 @@
265265 <infotype> may be either of 'version', 'packetsize', 'usermemrange'.
266266 """
267267 if infotype == "version":
268 - resp = self.embios.getversioninfo()
269268 try:
270 - hwtype = libembiosdata.hwtypes[resp.hwtypeid]
 269+ hwtype = libembiosdata.hwtypes[self.embios.lib.dev.hwtypeid]
271270 except KeyError:
272 - hwtype = "UNKNOWN (ID = " + self._hex(resp.hwtypeid) + ")"
273 - self.logger.info("Connected to "+libembiosdata.swtypes[resp.swtypeid] + " v" + str(resp.majorv) + "." + str(resp.minorv) +
274 - "." + str(resp.patchv) + " r" + str(resp.revision) + " running on " + hwtype + "\n")
 271+ hwtype = "UNKNOWN (ID = " + self._hex(self.embios.lib.dev.hwtypeid) + ")"
 272+ self.logger.info("Connected to "+libembiosdata.swtypes[self.embios.lib.dev.swtypeid] + " v" + str(self.embios.lib.dev.version.majorv) + "." + str(self.embios.lib.dev.version.minorv) +
 273+ "." + str(self.embios.lib.dev.version.patchv) + " r" + str(self.embios.lib.dev.version.revision) + " running on " + hwtype + "\n")
 274+
275275 elif infotype == "packetsize":
276 - resp = self.embios.getpacketsizeinfo()
277 - self.logger.info("Maximum packet sizes: "+str(resp))
 276+ self.logger.info("Maximum packet sizes: \n command out: " + str(self.embios.lib.dev.packetsizelimit.cout) + "\n command in: " + str(self.embios.lib.dev.packetsizelimit.cin) + "\n data in: " + str(self.embios.lib.dev.packetsizelimit.din) + "\n data out: " + str(self.embios.lib.dev.packetsizelimit.dout))
 277+
278278 elif infotype == "usermemrange":
279279 resp = self.embios.getusermemrange()
280 - self.logger.info("The user memory range is "+self._hex(resp.lower)+" - "+self._hex(resp.upper-1))
 280+ self.logger.info("The user memory range is "+self._hex(self.embios.lib.dev.usermem.lower)+" - "+self._hex(self.embios.lib.dev.usermem.upper - 1))
281281 else:
282282 raise ArgumentTypeError("one out of 'version', 'packetsize', 'usermemrange'", infotype)
283283
Index: embios/trunk/tools/libembios.py
@@ -72,7 +72,10 @@
7373 """
7474 def __init__(self):
7575 self.lib = Lib()
 76+
 77+ self.getversioninfo()
7678 self.getpacketsizeinfo()
 79+ self.getusermemrange()
7780
7881 @staticmethod
7982 def _alignsplit(addr, size, blksize, align):
@@ -131,10 +134,10 @@
132135 It also sets the properties of the device object accordingly.
133136 """
134137 resp = self.lib.monitorcommand(struct.pack("IIII", 1, 1, 0, 0), "HHII", ("coutmax", "cinmax", "doutmax", "dinmax"))
135 - self.lib.dev.packetsizelimit['cout'] = resp.coutmax
136 - self.lib.dev.packetsizelimit['cin'] = resp.cinmax
137 - self.lib.dev.packetsizelimit['din'] = resp.dinmax
138 - self.lib.dev.packetsizelimit['dout'] = resp.doutmax
 138+ self.lib.dev.packetsizelimit.cout = resp.coutmax
 139+ self.lib.dev.packetsizelimit.cin = resp.cinmax
 140+ self.lib.dev.packetsizelimit.din = resp.dinmax
 141+ self.lib.dev.packetsizelimit.dout = resp.doutmax
139142 return resp
140143
141144 def getusermemrange(self):
@@ -163,8 +166,8 @@
164167 from the device. This cares about too long packages
165168 and decides whether to use DMA or not.
166169 """
167 - cin_maxsize = self.lib.dev.packetsizelimit["cin"] - self.lib.headersize
168 - din_maxsize = self.lib.dev.packetsizelimit["din"]
 170+ cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
 171+ din_maxsize = self.lib.dev.packetsizelimit.din
169172 data = ""
170173 (headsize, bodysize, tailsize) = self._alignsplit(addr, size, cin_maxsize, 16)
171174 if headsize != 0:
@@ -188,8 +191,8 @@
189192 in the memory of the device. This cares about too long packages
190193 and decides whether to use DMA or not.
191194 """
192 - cout_maxsize = self.lib.dev.packetsizelimit["cout"] - self.lib.headersize
193 - dout_maxsize = self.lib.dev.packetsizelimit["dout"]
 195+ cout_maxsize = self.lib.dev.packetsizelimit.cout - self.lib.headersize
 196+ dout_maxsize = self.lib.dev.packetsizelimit.dout
194197 (headsize, bodysize, tailsize) = self._alignsplit(addr, len(data), cout_maxsize, 16)
195198 offset = 0
196199 if headsize != 0:
@@ -214,7 +217,7 @@
215218 """ Reads a zero terminated string from memory
216219 Reads only a maximum of 'maxlength' chars.
217220 """
218 - cin_maxsize = self.lib.dev.packetsizelimit["cin"] - self.lib.headersize
 221+ cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
219222 string = ""
220223 while (len(string) < maxlength or maxlength < 0):
221224 data = self._readmem(addr, min(maxlength - len(string), cin_maxsize))
@@ -246,7 +249,7 @@
247250
248251 def usbcread(self):
249252 """ Reads one packet with the maximal cin size """
250 - cin_maxsize = self.lib.dev.packetsizelimit["cin"] - self.lib.headersize
 253+ cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
251254 resp = self.lib.monitorcommand(struct.pack("IIII", 10, cin_maxsize, 0, 0), "III%ds" % cin_maxsize, ("validsize", "buffersize", "queuesize", "data"))
252255 resp.data = resp.data[:resp.validsize]
253256 resp.maxsize = cin_maxsize
@@ -254,7 +257,7 @@
255258
256259 def usbcwrite(self, data):
257260 """ Writes data to the USB console """
258 - cin_maxsize = self.lib.dev.packetsizelimit["cin"] - self.lib.headersize
 261+ cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
259262 size = len(data)
260263 while len(data) > 0:
261264 writesize = min(cin_maxsize, len(data))
@@ -266,7 +269,7 @@
267270 """ Reads one packet with the maximal cin size from the device consoles
268271 identified with the specified bitmask
269272 """
270 - cin_maxsize = self.lib.dev.packetsizelimit["cin"] - self.lib.headersize
 273+ cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
271274 resp = self.lib.monitorcommand(struct.pack("IIII", 13, bitmask, cin_maxsize, 0), "III%ds" % cin_maxsize, ("size", None, None))
272275 resp.data = resp.data[size:]
273276 resp.maxsize = cin_maxsize
@@ -276,7 +279,7 @@
277280 """ Writes data to the device consoles
278281 identified with the specified bitmask.
279282 """
280 - cin_maxsize = self.lib.dev.packetsizelimit["cin"] - self.lib.headersize
 283+ cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
281284 size = len(data)
282285 while len(data) > 0:
283286 writesize = min(cin_maxsize, len(data))
@@ -290,7 +293,7 @@
291294
292295 def getprocinfo(self):
293296 """ Gets current state of the scheduler """
294 - cin_maxsize = self.lib.dev.packetsizelimit["cin"] - self.lib.headersize
 297+ cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
295298 # Get the size
296299 schedulerstate = self.lockscheduler()
297300 resp = self.lib.monitorcommand(struct.pack("IIII", 15, 0, 0, 0), "III", ("structver", "tablesize", None))
@@ -543,12 +546,13 @@
544547
545548
546549 # Device properties
547 - self.packetsizelimit = {}
548 - self.packetsizelimit['cout'] = None
549 - self.packetsizelimit['cin'] = None
550 - self.packetsizelimit['dout'] = None
551 - self.packetsizelimit['din'] = None
 550+ self.packetsizelimit = Bunch()
 551+ self.packetsizelimit.cout = None
 552+ self.packetsizelimit.cin = None
 553+ self.packetsizelimit.dout = None
 554+ self.packetsizelimit.din = None
552555
 556+ self.version = Bunch()
553557 self.version.revision = None
554558 self.version.majorv = None
555559 self.version.minorv = None
@@ -556,6 +560,7 @@
557561 self.swtypeid = None
558562 self.hwtypeid = None
559563
 564+ self.usermem = Bunch()
560565 self.usermem.lower = None
561566 self.usermem.upper = None
562567
@@ -564,18 +569,18 @@
565570
566571 def findEndpoints(self):
567572 epcounter = 0
568 - self.endpoint = {}
 573+ self.endpoint = Bunch()
569574 for cfg in self.dev:
570575 for intf in cfg:
571576 for ep in intf:
572577 if epcounter == 0:
573 - self.endpoint['cout'] = ep.bEndpointAddress
 578+ self.endpoint.cout = ep.bEndpointAddress
574579 elif epcounter == 1:
575 - self.endpoint['cin'] = ep.bEndpointAddress
 580+ self.endpoint.cin = ep.bEndpointAddress
576581 elif epcounter == 2:
577 - self.endpoint['dout'] = ep.bEndpointAddress
 582+ self.endpoint.dout = ep.bEndpointAddress
578583 elif epcounter == 3:
579 - self.endpoint['din'] = ep.bEndpointAddress
 584+ self.endpoint.din = ep.bEndpointAddress
580585 epcounter += 1
581586 if epcounter <= 3:
582587 raise DeviceError("Not all endpoints found in the descriptor. Only "+str(epcounter)+" found, we need 4")
@@ -602,24 +607,24 @@
603608 return read
604609
605610 def cout(self, data):
606 - if self.packetsizelimit['cout'] and len(data) > self.packetsizelimit['cout']:
 611+ if self.packetsizelimit.cout and len(data) > self.packetsizelimit.cout:
607612 raise SendError("Packet too big")
608 - return self.send(self.endpoint['cout'], data)
 613+ return self.send(self.endpoint.cout, data)
609614
610615 def cin(self, size):
611 - if self.packetsizelimit['cin'] and size > self.packetsizelimit['cin']:
 616+ if self.packetsizelimit.cin and size > self.packetsizelimit.cin:
612617 raise ReceiveError("Packet too big")
613 - return self.receive(self.endpoint['cin'], size)
 618+ return self.receive(self.endpoint.cin, size)
614619
615620 def dout(self, data):
616 - if self.packetsizelimit['dout'] and len(data) > self.packetsizelimit['dout']:
 621+ if self.packetsizelimit.dout and len(data) > self.packetsizelimit.dout:
617622 raise SendError("Packet too big")
618 - return self.send(self.endpoint['dout'], data)
 623+ return self.send(self.endpoint.dout, data)
619624
620625 def din(self, size):
621 - if self.packetsizelimit['din'] and size > self.packetsizelimit['din']:
 626+ if self.packetsizelimit.din and size > self.packetsizelimit.din:
622627 raise ReceiveError("Packet too big")
623 - return self.receive(self.endpoint['din'], size)
 628+ return self.receive(self.endpoint.din, size)
624629
625630
626631 if __name__ == "__main__":