void FSAPI gaugecall(PGAUGEHDR pgauge, int service_id, UINT32 extra_data) { // Added to call all lookups and the license check routine // switch(service_id) { case PANEL_SERVICE_CONNECT_TO_WINDOW: { // Add here, all inicializations and conections. OpenLinkFsUIPC(); InitializeIFlyVariables(); break; } case PANEL_SERVICE_PRE_INSTALL: InitializeIFlyVariables(); break; case PANEL_SERVICE_PRE_UPDATE: break; case PANEL_SERVICE_DISCONNECT: { // free resouces and close conections. FSUIPC_Close(); /* Shut down */ //FMOD_Sound_Release(sound); FMOD_System_Close(systemFMOD); FMOD_System_Release(systemFMOD); break; } case PANEL_SERVICE_PRE_KILL: break; } }
Fsuipc::~Fsuipc() { // disconnect from FSUIPC FSUIPC_Close(); if( gFsuipc==this ) gFsuipc = 0; DeleteCriticalSection( &d->critSect ); delete d; }
int Simulator::Connect() { //Ensure any previous connections are closed first then connect to simulator. DWORD result; FSUIPC_Close(); if (FSUIPC_Open(SIM_ANY, &result) == TRUE) isConnected = true; else isConnected = false; return static_cast<int>(result); }
FSUIPC::FSUIPC() { m_buffer=0; FSUIPC_Close(); #if VASFMC_GAUGE // Can't open link yet because that would cause a deadlock // (FSUIPC would try to send a message to the main thread, but that thread // is still within the window procedure) m_link_ok = false; #else m_link_ok = openLink(); #endif // m_debug_write_counter = 0; // m_debug_timer.start(); };
// // Update Headpose in Game. // void FTNoIR_Protocol::sendHeadposeToGame(const double *headpose ) { DWORD result; TFSState pitch; TFSState yaw; TFSState roll; WORD FSZoom; float virtPosX; float virtPosY; float virtPosZ; float virtRotX; float virtRotY; float virtRotZ; // qDebug() << "FSUIPCServer::run() says: started!"; virtRotX = -headpose[Pitch]; // degrees virtRotY = headpose[Yaw]; virtRotZ = headpose[Roll]; virtPosX = 0.0f; // cm, X and Y are not working for FS2002/2004! virtPosY = 0.0f; virtPosZ = headpose[TZ]; // // Init. the FSUIPC offsets (derived from Free-track...) // pitch.Control = 66503; yaw.Control = 66504; roll.Control = 66505; // // Only do this when the data has changed. This way, the HAT-switch can be used when tracking is OFF. // if ((prevPosX != virtPosX) || (prevPosY != virtPosY) || (prevPosZ != virtPosZ) || (prevRotX != virtRotX) || (prevRotY != virtRotY) || (prevRotZ != virtRotZ)) { // // Open the connection // FSUIPC_Open(SIM_ANY, &result); // // Check the FS-version // if (((result == FSUIPC_ERR_OK) || (result == FSUIPC_ERR_OPEN)) && ((FSUIPC_FS_Version == SIM_FS2K2) || (FSUIPC_FS_Version == SIM_FS2K4))) { // qDebug() << "FSUIPCServer::run() says: FSUIPC opened succesfully"; // // Write the 4! DOF-data to FS. Only rotations and zoom are possible. // pitch.Value = scale2AnalogLimits(virtRotX, -180, 180); FSUIPC_Write(0x3110, 8, &pitch, &result); yaw.Value = scale2AnalogLimits(virtRotY, -180, 180); FSUIPC_Write(0x3110, 8, &yaw, &result); roll.Value = scale2AnalogLimits(virtRotZ, -180, 180); FSUIPC_Write(0x3110, 8, &roll, &result); FSZoom = (WORD) (64/50) * virtPosZ + 64; FSUIPC_Write(0x832E, 2, &FSZoom, &result); // // Write the data, in one go! // FSUIPC_Process(&result); if (result == FSUIPC_ERR_SENDMSG) { FSUIPC_Close(); //timeout (1 second) so assume FS closed } } } prevPosX = virtPosX; prevPosY = virtPosY; prevPosZ = virtPosZ; prevRotX = virtRotX; prevRotY = virtRotY; prevRotZ = virtRotZ; }
JNIEXPORT void JNICALL Java_com_flightSim_wrapper_FSWrapper_Close(JNIEnv *, jclass) { FSUIPC_Close(); }
void CConnector::close() { FSUIPC_Close(); m_bOpened = false; }
// Start the client // return: TRUE if successful, FALSE otherwise BOOL FSUIPC_Open(DWORD dwFSReq, DWORD *pdwResult) { char szName[MAX_PATH]; static int nTry = 0; BOOL fWideFS = FALSE; int i = 0; // abort if already started if (m_pView) { *pdwResult = FSUIPC_ERR_OPEN; return FALSE; } // Clear version information, so know when connected FSUIPC_Version = FSUIPC_FS_Version = 0; // Connect via FSUIPC, which is known to be FSUIPC's own // and isn't subject to user modificiation m_hWnd = FindWindowEx(NULL, NULL, "UIPCMAIN", NULL); if (!m_hWnd) { // If there's no UIPCMAIN, we may be using WideClient // which only simulates FS98 m_hWnd = FindWindowEx(NULL, NULL, "FS98MAIN", NULL); fWideFS = TRUE; if (!m_hWnd) { *pdwResult = FSUIPC_ERR_NOFS; return FALSE; } } // register the window message m_msg = RegisterWindowMessage(FS6IPC_MSGNAME1); if (m_msg == 0) { *pdwResult = FSUIPC_ERR_REGMSG; return FALSE; } // create the name of our file-mapping object nTry++; // Ensures a unique string is used in case user closes and reopens wsprintf(szName, FS6IPC_MSGNAME1 ":%X:%X", GetCurrentProcessId(), nTry); // stuff the name into a global atom m_atom = GlobalAddAtom(szName); if (m_atom == 0) { *pdwResult = FSUIPC_ERR_ATOM; FSUIPC_Close(); return FALSE; } // create the file-mapping object m_hMap = CreateFileMapping( (HANDLE)0xFFFFFFFF, // use system paging file NULL, // security PAGE_READWRITE, // protection 0, MAX_SIZE+256, // size szName); // name if ((m_hMap == 0) || (GetLastError() == ERROR_ALREADY_EXISTS)) { *pdwResult = FSUIPC_ERR_MAP; FSUIPC_Close(); return FALSE; } // get a view of the file-mapping object m_pView = (BYTE*)MapViewOfFile(m_hMap, FILE_MAP_WRITE, 0, 0, 0); if (m_pView == NULL) { *pdwResult = FSUIPC_ERR_VIEW; FSUIPC_Close(); return FALSE; } // Okay, now determine FSUIPC version AND FS type m_pNext = m_pView; // Try up to 5 times with a 100mSec rest between each // Note that WideClient returns zeroes initially, whilst waiting // for the Server to get the data while ((i++ < 5) && ((FSUIPC_Version == 0) || (FSUIPC_FS_Version == 0))) { // Read FSUIPC version if (!FSUIPC_Read(0x3304, 4, &FSUIPC_Version, pdwResult)) { FSUIPC_Close(); return FALSE; } // and FS version and validity check pattern if (!FSUIPC_Read(0x3308, 4, &FSUIPC_FS_Version, pdwResult)) { FSUIPC_Close(); return FALSE; } // Write our Library version number to a special read-only offset // This is to assist diagnosis from FSUIPC logging // But only do this on first try if ((i < 2) && !FSUIPC_Write(0x330a, 2, &FSUIPC_Lib_Version, pdwResult)) { FSUIPC_Close(); return FALSE; } // Actually send the requests and get the responses ("process") if (!FSUIPC_Process(pdwResult)) { FSUIPC_Close(); return FALSE; } // Maybe running on WideClient, and need another try Sleep(100); // Give it a chance } // Only allow running on FSUIPC 1.998e or later // with correct check pattern 0xFADE if ((FSUIPC_Version < 0x19980005) || ((FSUIPC_FS_Version & 0xFFFF0000L) != 0xFADE0000)) { *pdwResult = fWideFS ? FSUIPC_ERR_RUNNING : FSUIPC_ERR_VERSION; FSUIPC_Close(); return FALSE; } FSUIPC_FS_Version &= 0xffff; // Isolates the FS version number if (dwFSReq && (dwFSReq != FSUIPC_FS_Version)) // Optional user specific FS request { *pdwResult = FSUIPC_ERR_WRONGFS; FSUIPC_Close(); return FALSE; } *pdwResult = FSUIPC_ERR_OK; return TRUE; }
void Simulator::Disconnect() { FSUIPC_Close(); isConnected = false; }
void FSUIPC::closeLink() { FSUIPC_Close(); m_link_ok = false; };
FSUIPC::~FSUIPC() { FSUIPC_Close(); delete [] m_buffer; };