source: src/mlx/pyuipc_sim.py@ 51:f0f99ac21935

Last change on this file since 51:f0f99ac21935 was 51:f0f99ac21935, checked in by István Váradi <ivaradi@…>, 12 years ago

Fleet retrieval and gate selection works, started new connection handling and the fsuipc simulator

File size: 4.0 KB
Line 
1# Simulator for the pyuipc module
2#------------------------------------------------------------------------------
3
4import time
5
6#------------------------------------------------------------------------------
7
8# Version constants
9SIM_ANY=0
10SIM_FS98=1
11SIM_FS2K=2
12SIM_CFS2=3
13SIM_CFS1=4
14SIM_FLY=5
15SIM_FS2K2=6
16SIM_FS2K4=7
17
18#------------------------------------------------------------------------------
19
20# Error constants
21ERR_OK=0
22ERR_OPEN=1
23ERR_NOFS=2
24ERR_REGMSG=3
25ERR_ATOM=4
26ERR_MAP=5
27ERR_VIEW=6
28ERR_VERSION=7
29ERR_WRONGFS=8
30ERR_NOTOPEN=9
31ERR_NODATA=10
32ERR_TIMEOUT=11
33ERR_SENDMSG=12
34ERR_DATA=13
35ERR_RUNNING=14
36ERR_SIZE=15
37
38#------------------------------------------------------------------------------
39
40# The version of FSUIPC
41fsuipc_version=0x0401
42lib_version=0x0302
43fs_version=SIM_FS2K4
44
45#------------------------------------------------------------------------------
46
47class 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
89def open(request):
90 """Open the connection."""
91 return True
92
93#------------------------------------------------------------------------------
94
95def prepare_data(pattern, forRead = True):
96 """Prepare the given pattern for reading and/or writing."""
97 return pattern
98
99#------------------------------------------------------------------------------
100
101def 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
126def close():
127 """Close the connection."""
128 pass
129
130#------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.