import time #------------------------------------------------------------------------------ ## @package mlx.pyuipc_emu # # A very simple PyUIPC emulator. # # This is not used currently. #------------------------------------------------------------------------------ ## The ratio between kg and lbs KGTOLBS=1/0.4536 ## Feet to metres FEETTOMETRES=0.3048 #------------------------------------------------------------------------------ def interpolate_proportion(proportion, value0, value1): """ Interpolate between value0 and value1 using the given proportion. """ return value0 + (value1-value0)*1.0*proportion #------------------------------------------------------------------------------ def interpolate(point0, point, point1, value0, value1): """ Interpolate linearly between the given points for the given values. """ if point0==point1: if point>=point1: return value1 else: return value0 else: return interpolate_proportion((point-point0)*1.0/(point1-point0), value0, value1) #------------------------------------------------------------------------------ ## Version constants SIM_ANY=0 SIM_FS98=1 SIM_FS2K=2 SIM_CFS2=3 SIM_CFS1=4 SIM_FLY=5 SIM_FS2K2=6 SIM_FS2K4=7 #------------------------------------------------------------------------------ ## Error constants ERR_OK=0 ERR_OPEN=1 ERR_NOFS=2 ERR_REGMSG=3 ERR_ATOM=4 ERR_MAP=5 ERR_VIEW=6 ERR_VERSION=7 ERR_WRONGFS=8 ERR_NOTOPEN=9 ERR_NODATA=10 ERR_TIMEOUT=11 ERR_SENDMSG=12 ERR_DATA=13 ERR_RUNNING=14 ERR_SIZE=15 #------------------------------------------------------------------------------ ## The version of FSUIPC fsuipc_version=0x0401 lib_version=0x0302 fs_version=SIM_FS2K4 #------------------------------------------------------------------------------ class FSUIPCException(Exception): """ FSUIPC exception class. It contains a member variable named errorCode. The string is a text describing the error. """ errors=["OK", "Attempt to Open when already Open", "Cannot link to FSUIPC or WideClient", "Failed to Register common message with Windows", "Failed to create Atom for mapping filename", "Failed to create a file mapping object", "Failed to open a view to the file map", "Incorrect version of FSUIPC, or not FSUIPC", "Sim is not version requested", "Call cannot execute, link not Open", "Call cannot execute: no requests accumulated", "IPC timed out all retries", "IPC sendmessage failed all retries", "IPC request contains bad data", "Maybe running on WideClient, but FS not running on Server, or wrong FSUIPC", "Read or Write request cannot be added, memory for Process is full"] def __init__(self, errorCode): """ Construct the exception """ if errorCodeside_tank_capacity: fuel = side_tank_capacity results.append(long(round(fuel/side_tank_capacity*128.0*65536.0))) elif offset==0x0b80 or \ offset==0x0b98: # Left and right main tank capacity (gallons) results.append(long(round(side_tank_capacity*KGTOLBS/fuel_weight))) elif offset in [0x0b84, 0x0b88, 0x0b8c, 0x0b90, 0x0b9c, 0x0ba0, 0x0ba4, 0x0ba8, 0x1244, 0x1248, 0x124c, 0x1250, 0x1254, 0x1258, 0x125c, 0x1260]: # Other tank capacities and levels results.append(long(0)) elif offset==0x023a: # Second of time results.append(int(tm[5])) elif offset==0x023b: # Hour of UTC time results.append(int(tm[3])) elif offset==0x023c: # Minute of UTC time results.append(int(tm[4])) elif offset==0x023e: # Day number in year results.append(int(tm[7])) elif offset==0x0240: # Year results.append(int(tm[0])) elif offset==0x0020: # Ground altitude (metres*256) results.append(int(round(ground_altitude*FEETTOMETRES*256.0))) else: raise FSUIPCException(ERR_DATA) read_count += 1 return results #------------------------------------------------------------------------------ def close(): """ Close the connection """ global open_count open_count = 0 #------------------------------------------------------------------------------