Changeset 919:2ce8ca39525b for src/mlx/pyuipc_sim.py
- Timestamp:
- 03/24/19 08:15:59 (5 years ago)
- Branch:
- python3
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/pyuipc_sim.py
r877 r919 1 1 2 import const2 from . import const 3 3 4 4 import cmd … … 9 9 import sys 10 10 import struct 11 import cPickle11 import pickle 12 12 import math 13 13 … … 342 342 try: 343 343 return self._read(offset, type) 344 except Exception ,e:345 print "failed to read offset %04x: %s" % (offset, str(e))344 except Exception as e: 345 print("failed to read offset %04x: %s" % (offset, str(e))) 346 346 raise FSUIPCException(ERR_DATA) 347 347 … … 414 414 return 1 if self.overspeed else 0 415 415 elif offset==0x0560: # Latitude 416 return long(self.latitude * 10001750.0 * 65536.0 * 65536.0 / 90.0)416 return int(self.latitude * 10001750.0 * 65536.0 * 65536.0 / 90.0) 417 417 elif offset==0x0568: # Longitude 418 return long(self.longitude * 65536.0 * 65536.0 * 65536.0 * 65536.0 / 360.0)418 return int(self.longitude * 65536.0 * 65536.0 * 65536.0 * 65536.0 / 360.0) 419 419 elif offset==0x0570: # Altitude 420 return long(self.altitude * const.FEETTOMETRES * 65536.0 * 65536.0)420 return int(self.altitude * const.FEETTOMETRES * 65536.0 * 65536.0) 421 421 elif offset==0x0578: # Pitch 422 422 return int(self.pitch * 65536.0 * 65536.0 / 360.0) … … 584 584 return value 585 585 else: 586 print "Unhandled offset: %04x" % (offset,)586 print("Unhandled offset: %04x" % (offset,)) 587 587 raise FSUIPCException(ERR_DATA) 588 588 else: 589 print "Unhandled offset: %04x" % (offset,)589 print("Unhandled offset: %04x" % (offset,)) 590 590 raise FSUIPCException(ERR_DATA) 591 591 elif offset==0x32fa: # Message duration … … 616 616 return 0 if self.xpdrC else 1 617 617 else: 618 print "Unhandled offset: %04x" % (offset,)618 print("Unhandled offset: %04x" % (offset,)) 619 619 raise FSUIPCException(ERR_DATA) 620 620 … … 623 623 try: 624 624 return self._write(offset, value, type) 625 except TypeError ,e:625 except TypeError as e: 626 626 raise e 627 except Exception ,e:628 print "failed to write offset %04x: %s" % (offset, str(e))627 except Exception as e: 628 print("failed to write offset %04x: %s" % (offset, str(e))) 629 629 raise FSUIPCException(ERR_DATA) 630 630 … … 852 852 hotkey[3] = (value>>24) & 0xff 853 853 else: 854 print "Unhandled offset: %04x for type '%s'" % (offset, type)854 print("Unhandled offset: %04x for type '%s'" % (offset, type)) 855 855 raise FSUIPCException(ERR_DATA) 856 856 else: 857 print "Unhandled offset: %04x for type '%s'" % (offset, type)857 print("Unhandled offset: %04x for type '%s'" % (offset, type)) 858 858 raise FSUIPCException(ERR_DATA) 859 859 elif offset==0x32fa: # Message duration … … 882 882 self.xpdrC = value==0 883 883 else: 884 print "Unhandled offset: %04x" % (offset,)884 print("Unhandled offset: %04x" % (offset,)) 885 885 raise FSUIPCException(ERR_DATA) 886 886 … … 1039 1039 (length,) = struct.unpack("I", clientSocket.recv(4)) 1040 1040 data = clientSocket.recv(length) 1041 (call, args) = cPickle.loads(data)1041 (call, args) = pickle.loads(data) 1042 1042 exception = None 1043 1043 … … 1061 1061 else: 1062 1062 break 1063 except Exception ,e:1063 except Exception as e: 1064 1064 exception = e 1065 1065 1066 1066 if exception is None: 1067 data = cPickle.dumps((RESULT_RETURNED, result))1067 data = pickle.dumps((RESULT_RETURNED, result)) 1068 1068 else: 1069 data = cPickle.dumps((RESULT_EXCEPTION, str(exception)))1069 data = pickle.dumps((RESULT_EXCEPTION, str(exception))) 1070 1070 clientSocket.send(struct.pack("I", len(data)) + data) 1071 except Exception ,e:1072 print >> sys.stderr, "pyuipc_sim.Server._process: failed with exception:", str(e)1071 except Exception as e: 1072 print("pyuipc_sim.Server._process: failed with exception:", str(e), file=sys.stderr) 1073 1073 finally: 1074 1074 try: … … 1112 1112 def quit(self): 1113 1113 """Quit from the simulator.""" 1114 data = cPickle.dumps((CALL_QUIT, None))1114 data = pickle.dumps((CALL_QUIT, None)) 1115 1115 self._socket.send(struct.pack("I", len(data)) + data) 1116 1116 1117 1117 def _call(self, command, data): 1118 1118 """Perform a call with the given command and data.""" 1119 data = cPickle.dumps((command, [data]))1119 data = pickle.dumps((command, [data])) 1120 1120 self._socket.send(struct.pack("I", len(data)) + data) 1121 1121 (length,) = struct.unpack("I", self._socket.recv(4)) 1122 1122 data = self._socket.recv(length) 1123 (resultCode, result) = cPickle.loads(data)1123 (resultCode, result) = pickle.loads(data) 1124 1124 if resultCode==RESULT_RETURNED: 1125 1125 return result … … 1234 1234 lambda value: value * 90.0 / 1235 1235 10001750.0 / 65536.0 / 65536.0, 1236 lambda word: long(float(word) *1236 lambda word: int(float(word) * 1237 1237 10001750.0 * 1238 1238 65536.0 * 65536.0 / 90.0)) … … 1240 1240 lambda value: value * 360.0 / 1241 1241 65536.0 / 65536.0 / 65536.0 / 65536.0, 1242 lambda word: long(float(word) *1242 lambda word: int(float(word) * 1243 1243 65536.0 * 65536.0 * 1244 1244 65536.0 * 65536.0 / … … 1300 1300 const.FEETTOMETRES / 65536.0 / 1301 1301 65536.0, 1302 lambda word: long(float(word) *1302 lambda word: int(float(word) * 1303 1303 const.FEETTOMETRES * 1304 1304 65536.0 * 65536.0)) … … 1487 1487 self._valueHandlers["hotkey%d" % (i,)] = ([(0x3210 + i*4, "u")], 1488 1488 lambda value: "0x%08x" % (value,), 1489 lambda word: long(word, 16))1489 lambda word: int(word, 16)) 1490 1490 1491 1491 self._valueHandlers["cog"] = ([(0x2ef8, "f")], lambda value: value, … … 1537 1537 """Handle unhandle commands.""" 1538 1538 if line=="EOF": 1539 print 1539 print() 1540 1540 return self.do_quit("") 1541 1541 else: … … 1548 1548 for name in names: 1549 1549 if name not in self._valueHandlers: 1550 print >> sys.stderr, "Unknown variable: " + name1550 print("Unknown variable: " + name, file=sys.stderr) 1551 1551 return False 1552 1552 valueHandler = self._valueHandlers[name] … … 1565 1565 else thisResults) 1566 1566 1567 print name + "=" + str(value)1567 print(name + "=" + str(value)) 1568 1568 1569 1569 index += numResults 1570 1570 i+=1 1571 except Exception ,e:1572 print >> sys.stderr, "Failed to read data: " + str(e)1571 except Exception as e: 1572 print("Failed to read data: " + str(e), file=sys.stderr) 1573 1573 1574 1574 return False … … 1576 1576 def help_get(self): 1577 1577 """Print help for the get command.""" 1578 print "get <variable> [<variable>...]"1578 print("get <variable> [<variable>...]") 1579 1579 1580 1580 def complete_get(self, text, line, begidx, endidx): … … 1608 1608 words = argument.split("=") 1609 1609 if len(words)!=2: 1610 print >> sys.stderr, "Invalid argument: " + argument1610 print("Invalid argument: " + argument, file=sys.stderr) 1611 1611 return False 1612 1612 1613 1613 (name, value) = words 1614 1614 if name not in self._valueHandlers: 1615 print >> sys.stderr, "Unknown variable: " + name1615 print("Unknown variable: " + name, file=sys.stderr) 1616 1616 return False 1617 1617 … … 1625 1625 data.append((offset, type, values[index])) 1626 1626 index += 1 1627 except Exception ,e:1628 print >> sys.stderr,"Invalid value '%s' for variable %s: %s" % \1629 (value, name, str(e)) 1627 except Exception as e: 1628 print("Invalid value '%s' for variable %s: %s" % \ 1629 (value, name, str(e)), file=sys.stderr) 1630 1630 return False 1631 1631 1632 1632 try: 1633 1633 self._client.write(data) 1634 print "Data written"1635 except Exception ,e:1636 print >> sys.stderr, "Failed to write data: " + str(e)1634 print("Data written") 1635 except Exception as e: 1636 print("Failed to write data: " + str(e), file=sys.stderr) 1637 1637 1638 1638 return False … … 1640 1640 def help_set(self): 1641 1641 """Print help for the set command.""" 1642 print "set <variable>=<value> [<variable>=<value>...]"1642 print("set <variable>=<value> [<variable>=<value>...]") 1643 1643 1644 1644 def complete_set(self, text, line, begidx, endidx): … … 1654 1654 value = int(args) 1655 1655 self._client.setVersion(value) 1656 print "Emulating version %d" % (value,)1657 except Exception ,e:1658 print >> sys.stderr, "Failed to set the version: " + str(e)1656 print("Emulating version %d" % (value,)) 1657 except Exception as e: 1658 print("Failed to set the version: " + str(e), file=sys.stderr) 1659 1659 1660 1660 def help_setversion(self, usage = False): 1661 1661 """Help for the setversion command""" 1662 if usage: print "Usage:",1663 print "setversion <number>"1662 if usage: print("Usage:", end=' ') 1663 print("setversion <number>") 1664 1664 1665 1665 def do_close(self, args): … … 1667 1667 try: 1668 1668 self._client.close() 1669 print "Connection closed"1670 except Exception ,e:1671 print >> sys.stderr, "Failed to close the connection: " + str(e)1669 print("Connection closed") 1670 except Exception as e: 1671 print("Failed to close the connection: " + str(e), file=sys.stderr) 1672 1672 1673 1673 def do_failopen(self, args): … … 1676 1676 value = self.str2bool(args) 1677 1677 self._client.failOpen(value) 1678 print "Opening will%s fail" % ("" if value else " not",)1679 except Exception ,e:1680 print >> sys.stderr, "Failed to set open failure: " + str(e)1678 print("Opening will%s fail" % ("" if value else " not",)) 1679 except Exception as e: 1680 print("Failed to set open failure: " + str(e), file=sys.stderr) 1681 1681 1682 1682 def help_failopen(self, usage = False): 1683 1683 """Help for the failopen command""" 1684 if usage: print "Usage:",1685 print "failopen yes|no"1684 if usage: print("Usage:", end=' ') 1685 print("failopen yes|no") 1686 1686 1687 1687 def complete_failopen(self, text, line, begidx, endidx):
Note:
See TracChangeset
for help on using the changeset viewer.