[51] | 1 | # Simulator for the pyuipc module
|
---|
| 2 | #------------------------------------------------------------------------------
|
---|
| 3 |
|
---|
| 4 | import time
|
---|
| 5 |
|
---|
| 6 | #------------------------------------------------------------------------------
|
---|
| 7 |
|
---|
| 8 | # Version constants
|
---|
| 9 | SIM_ANY=0
|
---|
| 10 | SIM_FS98=1
|
---|
| 11 | SIM_FS2K=2
|
---|
| 12 | SIM_CFS2=3
|
---|
| 13 | SIM_CFS1=4
|
---|
| 14 | SIM_FLY=5
|
---|
| 15 | SIM_FS2K2=6
|
---|
| 16 | SIM_FS2K4=7
|
---|
| 17 |
|
---|
| 18 | #------------------------------------------------------------------------------
|
---|
| 19 |
|
---|
| 20 | # Error constants
|
---|
| 21 | ERR_OK=0
|
---|
| 22 | ERR_OPEN=1
|
---|
| 23 | ERR_NOFS=2
|
---|
| 24 | ERR_REGMSG=3
|
---|
| 25 | ERR_ATOM=4
|
---|
| 26 | ERR_MAP=5
|
---|
| 27 | ERR_VIEW=6
|
---|
| 28 | ERR_VERSION=7
|
---|
| 29 | ERR_WRONGFS=8
|
---|
| 30 | ERR_NOTOPEN=9
|
---|
| 31 | ERR_NODATA=10
|
---|
| 32 | ERR_TIMEOUT=11
|
---|
| 33 | ERR_SENDMSG=12
|
---|
| 34 | ERR_DATA=13
|
---|
| 35 | ERR_RUNNING=14
|
---|
| 36 | ERR_SIZE=15
|
---|
| 37 |
|
---|
| 38 | #------------------------------------------------------------------------------
|
---|
| 39 |
|
---|
| 40 | # The version of FSUIPC
|
---|
| 41 | fsuipc_version=0x0401
|
---|
| 42 | lib_version=0x0302
|
---|
| 43 | fs_version=SIM_FS2K4
|
---|
| 44 |
|
---|
| 45 | #------------------------------------------------------------------------------
|
---|
| 46 |
|
---|
| 47 | class FSUIPCException(Exception):
|
---|
| 48 | """FSUIPC exception class.
|
---|
| 49 |
|
---|
| 50 | It contains a member variable named errorCode. The string is a text
|
---|
| 51 | describing the error."""
|
---|
| 52 |
|
---|
| 53 | errors=["OK",
|
---|
| 54 | "Attempt to Open when already Open",
|
---|
| 55 | "Cannot link to FSUIPC or WideClient",
|
---|
| 56 | "Failed to Register common message with Windows",
|
---|
| 57 | "Failed to create Atom for mapping filename",
|
---|
| 58 | "Failed to create a file mapping object",
|
---|
| 59 | "Failed to open a view to the file map",
|
---|
| 60 | "Incorrect version of FSUIPC, or not FSUIPC",
|
---|
| 61 | "Sim is not version requested",
|
---|
| 62 | "Call cannot execute, link not Open",
|
---|
| 63 | "Call cannot execute: no requests accumulated",
|
---|
| 64 | "IPC timed out all retries",
|
---|
| 65 | "IPC sendmessage failed all retries",
|
---|
| 66 | "IPC request contains bad data",
|
---|
| 67 | "Maybe running on WideClient, but FS not running on Server, or wrong FSUIPC",
|
---|
| 68 | "Read or Write request cannot be added, memory for Process is full"]
|
---|
| 69 |
|
---|
| 70 | def __init__(self, errorCode):
|
---|
| 71 | """
|
---|
| 72 | Construct the exception
|
---|
| 73 | """
|
---|
| 74 | if errorCode<len(self.errors):
|
---|
| 75 | self.errorString = self.errors[errorCode]
|
---|
| 76 | else:
|
---|
| 77 | self.errorString = "Unknown error"
|
---|
| 78 | Exception.__init__(self, self.errorString)
|
---|
| 79 | self.errorCode = errorCode
|
---|
| 80 |
|
---|
| 81 | def __str__(self):
|
---|
| 82 | """
|
---|
| 83 | Convert the excption to string
|
---|
| 84 | """
|
---|
| 85 | return "FSUIPC error: %d (%s)" % (self.errorCode, self.errorString)
|
---|
| 86 |
|
---|
| 87 | #------------------------------------------------------------------------------
|
---|
| 88 |
|
---|
| 89 | def open(request):
|
---|
| 90 | """Open the connection."""
|
---|
| 91 | return True
|
---|
| 92 |
|
---|
| 93 | #------------------------------------------------------------------------------
|
---|
| 94 |
|
---|
| 95 | def prepare_data(pattern, forRead = True):
|
---|
| 96 | """Prepare the given pattern for reading and/or writing."""
|
---|
| 97 | return pattern
|
---|
| 98 |
|
---|
| 99 | #------------------------------------------------------------------------------
|
---|
| 100 |
|
---|
| 101 | def read(data):
|
---|
| 102 | """Read the given data."""
|
---|
| 103 | result = []
|
---|
| 104 | for (offset, type) in data:
|
---|
| 105 | if offset==0x023a: # Second of time
|
---|
| 106 | result.append(time.gmtime().tm_sec)
|
---|
| 107 | elif offset==0x023b: # Hour of Zulu time
|
---|
| 108 | result.append(time.gmtime().tm_hour)
|
---|
| 109 | elif offset==0x023c: # Minute of Zulu time
|
---|
| 110 | result.append(time.gmtime().tm_min)
|
---|
| 111 | elif offset==0x023e: # Day number on year
|
---|
| 112 | result.append(time.gmtime().tm_yday)
|
---|
| 113 | elif offset==0x0240: # Year in FS
|
---|
| 114 | result.append(time.gmtime().tm_year)
|
---|
| 115 | elif offset==0x3c00: # Path of the current AIR file
|
---|
| 116 | result.append("c:\\Program Files\\Microsoft Games\\FS9\\Aircraft\\kutya")
|
---|
| 117 | elif offset==0x3d00: # Name of the current aircraft
|
---|
| 118 | result.append("Cessna 172")
|
---|
| 119 | else:
|
---|
| 120 | print "Unhandled offset: %04x" % (offset,)
|
---|
| 121 | raise FSUIPCException(ERR_DATA)
|
---|
| 122 | return result
|
---|
| 123 |
|
---|
| 124 | #------------------------------------------------------------------------------
|
---|
| 125 |
|
---|
| 126 | def close():
|
---|
| 127 | """Close the connection."""
|
---|
| 128 | pass
|
---|
| 129 |
|
---|
| 130 | #------------------------------------------------------------------------------
|
---|