Changeset 177:356d15d88060
- Timestamp:
- 05/13/12 08:49:30 (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/pyuipc_sim.py
r163 r177 141 141 ENGINE_3 = 2 142 142 143 # The number of hotkey entries 144 HOTKEY_SIZE = 56 145 143 146 @staticmethod 144 147 def _readFrequency(frequency): … … 252 255 self.messageDuration = 0 253 256 254 def read(self, offset): 257 self.hotkeyTable = [] 258 for i in range(0, Values.HOTKEY_SIZE): 259 self.hotkeyTable.append([0, 0, 0, 0]) 260 261 def read(self, offset, type): 255 262 """Read the value at the given offset.""" 256 263 try: 257 return self._read(offset )264 return self._read(offset, type) 258 265 except Exception, e: 259 266 print "failed to read offset %04x: %s" % (offset, str(e)) 260 267 raise FSUIPCException(ERR_DATA) 261 268 262 def _read(self, offset ):269 def _read(self, offset, type): 263 270 """Read the value at the given offset.""" 264 271 if offset==0x023a: # Second of time … … 432 439 if self.radioAltitude is None else self.radioAltitude 433 440 return (radioAltitude * const.FEETTOMETRES * 65536.0) 441 elif offset==0x320c: 442 return Values.HOTKEY_SIZE 443 elif offset>=0x3210 and offset<0x3210+Values.HOTKEY_SIZE*4: 444 tableOffset = offset - 0x3210 445 hotkeyIndex = tableOffset / 4 446 index = tableOffset % 4 447 if type=="b" or type=="c": 448 return self.hotkeyTable[hotkeyIndex][index] 449 elif type=="d" or type=="u": 450 if index==0: 451 hotkey = self.hotkeyTable[hotkeyIndex] 452 value = hotkey[3] 453 value <<= 8 454 value |= hotkey[2] 455 value <<= 8 456 value |= hotkey[1] 457 value <<= 8 458 value |= hotkey[0] 459 return value 460 else: 461 print "Unhandled offset: %04x" % (offset,) 462 raise FSUIPCException(ERR_DATA) 463 else: 464 print "Unhandled offset: %04x" % (offset,) 465 raise FSUIPCException(ERR_DATA) 434 466 elif offset==0x32fa: # Message duration 435 467 return self.messageDuration … … 448 480 raise FSUIPCException(ERR_DATA) 449 481 450 def write(self, offset, value ):482 def write(self, offset, value, type): 451 483 """Write the value at the given offset.""" 452 484 try: 453 return self._write(offset, value )485 return self._write(offset, value, type) 454 486 except Exception, e: 455 487 print "failed to write offset %04x: %s" % (offset, str(e)) 456 488 raise FSUIPCException(ERR_DATA) 457 489 458 def _write(self, offset, value ):490 def _write(self, offset, value, type): 459 491 """Write the given value at the given offset.""" 460 492 if offset==0x023a: # Second of time … … 617 649 elif offset==0x31e4: # Radio altitude 618 650 raise FSUIPCException(ERR_DATA) 651 elif offset==0x320c: 652 return Values.HOTKEY_SIZE 653 elif offset>=0x3210 and offset<0x3210+Values.HOTKEY_SIZE*4: 654 tableOffset = offset - 0x3210 655 hotkeyIndex = tableOffset / 4 656 index = tableOffset % 4 657 if type=="b" or type=="c": 658 self.hotkeyTable[hotkeyIndex][index] = value 659 elif type=="d" or type=="u": 660 if index==0: 661 hotkey = self.hotkeyTable[hotkeyIndex] 662 hotkey[0] = value & 0xff 663 hotkey[1] = (value>>8) & 0xff 664 hotkey[2] = (value>>16) & 0xff 665 hotkey[3] = (value>>24) & 0xff 666 else: 667 print "Unhandled offset: %04x for type '%s'" % (offset, type) 668 raise FSUIPCException(ERR_DATA) 669 else: 670 print "Unhandled offset: %04x for type '%s'" % (offset, type) 671 raise FSUIPCException(ERR_DATA) 619 672 elif offset==0x32fa: # Message duration 620 673 self.messageDuration = value … … 722 775 """Read the given data.""" 723 776 if opened: 724 return [values.read(offset ) for (offset, type) in data]777 return [values.read(offset, type) for (offset, type) in data] 725 778 else: 726 779 raise FSUIPCException(ERR_OPEN) … … 732 785 if opened: 733 786 for (offset, type, value) in data: 734 values.write(offset, value )787 values.write(offset, value, type) 735 788 else: 736 789 raise FSUIPCException(ERR_OPEN) … … 1163 1216 lambda value: value, 1164 1217 lambda word: word) 1218 1219 for i in range(0, Values.HOTKEY_SIZE): 1220 self._valueHandlers["hotkey%d" % (i,)] = (0x3210 + i*4, "u", 1221 lambda value: "0x%08x" % (value,), 1222 lambda word: long(word, 16)) 1165 1223 def default(self, line): 1166 1224 """Handle unhandle commands."""
Note:
See TracChangeset
for help on using the changeset viewer.