Index: embios/trunk/tools/embios.py |
— | — | @@ -264,19 +264,19 @@ |
265 | 265 | <infotype> may be either of 'version', 'packetsize', 'usermemrange'.
|
266 | 266 | """
|
267 | 267 | if infotype == "version":
|
268 | | - resp = self.embios.getversioninfo()
|
269 | 268 | try:
|
270 | | - hwtype = libembiosdata.hwtypes[resp.hwtypeid]
|
| 269 | + hwtype = libembiosdata.hwtypes[self.embios.lib.dev.hwtypeid]
|
271 | 270 | 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 | +
|
275 | 275 | 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 | +
|
278 | 278 | elif infotype == "usermemrange":
|
279 | 279 | 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))
|
281 | 281 | else:
|
282 | 282 | raise ArgumentTypeError("one out of 'version', 'packetsize', 'usermemrange'", infotype)
|
283 | 283 |
|
Index: embios/trunk/tools/libembios.py |
— | — | @@ -72,7 +72,10 @@ |
73 | 73 | """
|
74 | 74 | def __init__(self):
|
75 | 75 | self.lib = Lib()
|
| 76 | +
|
| 77 | + self.getversioninfo()
|
76 | 78 | self.getpacketsizeinfo()
|
| 79 | + self.getusermemrange()
|
77 | 80 |
|
78 | 81 | @staticmethod
|
79 | 82 | def _alignsplit(addr, size, blksize, align):
|
— | — | @@ -131,10 +134,10 @@ |
132 | 135 | It also sets the properties of the device object accordingly.
|
133 | 136 | """
|
134 | 137 | 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
|
139 | 142 | return resp
|
140 | 143 |
|
141 | 144 | def getusermemrange(self):
|
— | — | @@ -163,8 +166,8 @@ |
164 | 167 | from the device. This cares about too long packages
|
165 | 168 | and decides whether to use DMA or not.
|
166 | 169 | """
|
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
|
169 | 172 | data = ""
|
170 | 173 | (headsize, bodysize, tailsize) = self._alignsplit(addr, size, cin_maxsize, 16)
|
171 | 174 | if headsize != 0:
|
— | — | @@ -188,8 +191,8 @@ |
189 | 192 | in the memory of the device. This cares about too long packages
|
190 | 193 | and decides whether to use DMA or not.
|
191 | 194 | """
|
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
|
194 | 197 | (headsize, bodysize, tailsize) = self._alignsplit(addr, len(data), cout_maxsize, 16)
|
195 | 198 | offset = 0
|
196 | 199 | if headsize != 0:
|
— | — | @@ -214,7 +217,7 @@ |
215 | 218 | """ Reads a zero terminated string from memory
|
216 | 219 | Reads only a maximum of 'maxlength' chars.
|
217 | 220 | """
|
218 | | - cin_maxsize = self.lib.dev.packetsizelimit["cin"] - self.lib.headersize
|
| 221 | + cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
219 | 222 | string = ""
|
220 | 223 | while (len(string) < maxlength or maxlength < 0):
|
221 | 224 | data = self._readmem(addr, min(maxlength - len(string), cin_maxsize))
|
— | — | @@ -246,7 +249,7 @@ |
247 | 250 |
|
248 | 251 | def usbcread(self):
|
249 | 252 | """ 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
|
251 | 254 | resp = self.lib.monitorcommand(struct.pack("IIII", 10, cin_maxsize, 0, 0), "III%ds" % cin_maxsize, ("validsize", "buffersize", "queuesize", "data"))
|
252 | 255 | resp.data = resp.data[:resp.validsize]
|
253 | 256 | resp.maxsize = cin_maxsize
|
— | — | @@ -254,7 +257,7 @@ |
255 | 258 |
|
256 | 259 | def usbcwrite(self, data):
|
257 | 260 | """ 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
|
259 | 262 | size = len(data)
|
260 | 263 | while len(data) > 0:
|
261 | 264 | writesize = min(cin_maxsize, len(data))
|
— | — | @@ -266,7 +269,7 @@ |
267 | 270 | """ Reads one packet with the maximal cin size from the device consoles
|
268 | 271 | identified with the specified bitmask
|
269 | 272 | """
|
270 | | - cin_maxsize = self.lib.dev.packetsizelimit["cin"] - self.lib.headersize
|
| 273 | + cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
271 | 274 | resp = self.lib.monitorcommand(struct.pack("IIII", 13, bitmask, cin_maxsize, 0), "III%ds" % cin_maxsize, ("size", None, None))
|
272 | 275 | resp.data = resp.data[size:]
|
273 | 276 | resp.maxsize = cin_maxsize
|
— | — | @@ -276,7 +279,7 @@ |
277 | 280 | """ Writes data to the device consoles
|
278 | 281 | identified with the specified bitmask.
|
279 | 282 | """
|
280 | | - cin_maxsize = self.lib.dev.packetsizelimit["cin"] - self.lib.headersize
|
| 283 | + cin_maxsize = self.lib.dev.packetsizelimit.cin - self.lib.headersize
|
281 | 284 | size = len(data)
|
282 | 285 | while len(data) > 0:
|
283 | 286 | writesize = min(cin_maxsize, len(data))
|
— | — | @@ -290,7 +293,7 @@ |
291 | 294 |
|
292 | 295 | def getprocinfo(self):
|
293 | 296 | """ 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
|
295 | 298 | # Get the size
|
296 | 299 | schedulerstate = self.lockscheduler()
|
297 | 300 | resp = self.lib.monitorcommand(struct.pack("IIII", 15, 0, 0, 0), "III", ("structver", "tablesize", None))
|
— | — | @@ -543,12 +546,13 @@ |
544 | 547 |
|
545 | 548 |
|
546 | 549 | # 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
|
552 | 555 |
|
| 556 | + self.version = Bunch()
|
553 | 557 | self.version.revision = None
|
554 | 558 | self.version.majorv = None
|
555 | 559 | self.version.minorv = None
|
— | — | @@ -556,6 +560,7 @@ |
557 | 561 | self.swtypeid = None
|
558 | 562 | self.hwtypeid = None
|
559 | 563 |
|
| 564 | + self.usermem = Bunch()
|
560 | 565 | self.usermem.lower = None
|
561 | 566 | self.usermem.upper = None
|
562 | 567 |
|
— | — | @@ -564,18 +569,18 @@ |
565 | 570 |
|
566 | 571 | def findEndpoints(self):
|
567 | 572 | epcounter = 0
|
568 | | - self.endpoint = {}
|
| 573 | + self.endpoint = Bunch()
|
569 | 574 | for cfg in self.dev:
|
570 | 575 | for intf in cfg:
|
571 | 576 | for ep in intf:
|
572 | 577 | if epcounter == 0:
|
573 | | - self.endpoint['cout'] = ep.bEndpointAddress
|
| 578 | + self.endpoint.cout = ep.bEndpointAddress
|
574 | 579 | elif epcounter == 1:
|
575 | | - self.endpoint['cin'] = ep.bEndpointAddress
|
| 580 | + self.endpoint.cin = ep.bEndpointAddress
|
576 | 581 | elif epcounter == 2:
|
577 | | - self.endpoint['dout'] = ep.bEndpointAddress
|
| 582 | + self.endpoint.dout = ep.bEndpointAddress
|
578 | 583 | elif epcounter == 3:
|
579 | | - self.endpoint['din'] = ep.bEndpointAddress
|
| 584 | + self.endpoint.din = ep.bEndpointAddress
|
580 | 585 | epcounter += 1
|
581 | 586 | if epcounter <= 3:
|
582 | 587 | raise DeviceError("Not all endpoints found in the descriptor. Only "+str(epcounter)+" found, we need 4")
|
— | — | @@ -602,24 +607,24 @@ |
603 | 608 | return read
|
604 | 609 |
|
605 | 610 | 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:
|
607 | 612 | raise SendError("Packet too big")
|
608 | | - return self.send(self.endpoint['cout'], data)
|
| 613 | + return self.send(self.endpoint.cout, data)
|
609 | 614 |
|
610 | 615 | def cin(self, size):
|
611 | | - if self.packetsizelimit['cin'] and size > self.packetsizelimit['cin']:
|
| 616 | + if self.packetsizelimit.cin and size > self.packetsizelimit.cin:
|
612 | 617 | raise ReceiveError("Packet too big")
|
613 | | - return self.receive(self.endpoint['cin'], size)
|
| 618 | + return self.receive(self.endpoint.cin, size)
|
614 | 619 |
|
615 | 620 | 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:
|
617 | 622 | raise SendError("Packet too big")
|
618 | | - return self.send(self.endpoint['dout'], data)
|
| 623 | + return self.send(self.endpoint.dout, data)
|
619 | 624 |
|
620 | 625 | def din(self, size):
|
621 | | - if self.packetsizelimit['din'] and size > self.packetsizelimit['din']:
|
| 626 | + if self.packetsizelimit.din and size > self.packetsizelimit.din:
|
622 | 627 | raise ReceiveError("Packet too big")
|
623 | | - return self.receive(self.endpoint['din'], size)
|
| 628 | + return self.receive(self.endpoint.din, size)
|
624 | 629 |
|
625 | 630 |
|
626 | 631 | if __name__ == "__main__":
|