Ejemplo n.º 1
0
 char* Shm::getShmNoCreateAndCheck(int iFlag, int *piSize) {
     int iRealShmSize = 0;
     
     if (getShmId(iFlag) == 0) {
         return NULL;
     }
     
     iRealShmSize = getShmSize();
     if (iRealShmSize == 0) {
         return NULL;
     }
     
     if (*piSize != 0 && *piSize != iRealShmSize) {
         snprintf(lastErrorBuf, sizeof(lastErrorBuf),
                 "*piSize[%d] != iRealShmSize[%d]", *piSize, iRealShmSize);
         return NULL;
     }
     
     if (*piSize == 0) {
         *piSize = iRealShmSize;
     }
     
     return getAdr();
 }
Ejemplo n.º 2
0
	/*******************************************************//**
	 * Loads the DLL.
	 *
	 * @return	The DLL.
	 *******************************************************/
	int MainController::loadDll( ) {
		Logger::getInstance()->printDebug2 (_T("MainController::loadDll unzipFolderPath_: %s\n"), unzipFolderPath_);
		const char* modelId = getModelIdentifier(fmu_->modelDescription);
		
		int len = strlen(unzipFolderPath_) + strlen(DLL_DIR_STR)
			+ strlen(modelId) + strlen(_T(".dll")) + 1;

		dllFilePath_ = (char *)calloc(sizeof(char), len);


		sprintf_s(dllFilePath_,
			len,
			_T("%s%s%s.dll"),
			unzipFolderPath_,
			DLL_DIR_STR,
			modelId
			);

		if (dllFilePath_ == NULL){
			Logger::getInstance()->printfError(_T("Failed to allocate memory for wText\n"), dllFilePath_);
			return 1;
		}

		Logger::getInstance()->printDebug2 (_T("dllFilePath_: %s \n"), dllFilePath_);

		HINSTANCE h;
		h = LoadLibrary(dllFilePath_);

		if(!h) {
			Logger::getInstance()->printfError(_T("Can not load %s\n"), dllFilePath_);
			exit(EXIT_FAILURE);
		}

		fmu_->dllHandle = h;
		fmu_->getVersion = (fGetVersion) getAdr("fmiGetVersion");
		fmu_->instantiateSlave = (fInstantiateSlave) getAdr("fmiInstantiateSlave");
		fmu_->freeSlaveInstance = (fFreeSlaveInstance) getAdr( "fmiFreeSlaveInstance");
		fmu_->setDebugLogging = (fSetDebugLogging) getAdr( "fmiSetDebugLogging");
		fmu_->setReal = (fSetReal) getAdr( "fmiSetReal");
		fmu_->setInteger = (fSetInteger) getAdr( "fmiSetInteger");
		fmu_->setBoolean = (fSetBoolean) getAdr( "fmiSetBoolean");
		fmu_->setString = (fSetString) getAdr( "fmiSetString");
		fmu_->initializeSlave = (fInitializeSlave) getAdr("fmiInitializeSlave");
		fmu_->getReal = (fGetReal) getAdr( "fmiGetReal");
		fmu_->getInteger = (fGetInteger) getAdr( "fmiGetInteger");
		fmu_->getBoolean = (fGetBoolean) getAdr("fmiGetBoolean");
		fmu_->getString = (fGetString) getAdr( "fmiGetString");
		fmu_->doStep = (fDoStep) getAdr("fmiDoStep");
		fmu_->terminateSlave = (fTerminateSlave) getAdr("fmiTerminateSlave");
		
		//resetSlave does not seem to be implented 
		fmu_->resetSlave = (fResetSlave) getAdr("fmiResetSlave");

		setState_( simStateNative_3_init_dllLoaded );

		return 0;
	}
Ejemplo n.º 3
0
///////////////////////////////////////////////////////////////////////////////
/// Load the given dll and set function pointers in fmu.
/// It changes the names of the standard FMI functions by adding the modlei identifer
/// and links the new functions with QTronic's FMU structure.
///
///\param dllPat Path of the dll file.
///\param fmu Name of FMU.
///\return 0 if there is no error occurred.
///////////////////////////////////////////////////////////////////////////////
static int loadDll(const char* dllPat, FMU *fmu) {
  HANDLE h = LoadLibrary(dllPat);
  if(!h) {
    printfError("Can not load %s.\n", dllPat);
    return 1;
  }
  fmu->dllHandle = h;
  fmu->getVersion              = (fGetVersion)         getAdr(fmu, "fmiGetVersion");
	fmu->instantiateSlave        = (fInstantiateSlave)   getAdr(fmu, "fmiInstantiateSlave");		
	fmu->freeSlaveInstance       = (fFreeSlaveInstance)  getAdr(fmu, "fmiFreeSlaveInstance");		
  fmu->setDebugLogging         = (fSetDebugLogging)    getAdr(fmu, "fmiSetDebugLogging");
  fmu->setReal                 = (fSetReal)            getAdr(fmu, "fmiSetReal");
  fmu->setInteger              = (fSetInteger)         getAdr(fmu, "fmiSetInteger");
  fmu->setBoolean              = (fSetBoolean)         getAdr(fmu, "fmiSetBoolean");
  fmu->setString               = (fSetString)          getAdr(fmu, "fmiSetString");
	fmu->initializeSlave         = (fInitializeSlave)    getAdr(fmu, "fmiInitializeSlave");			
  fmu->getReal                 = (fGetReal)            getAdr(fmu, "fmiGetReal");
  fmu->getInteger              = (fGetInteger)         getAdr(fmu, "fmiGetInteger");
  fmu->getBoolean              = (fGetBoolean)         getAdr(fmu, "fmiGetBoolean");
  fmu->getString               = (fGetString)          getAdr(fmu, "fmiGetString");
	fmu->doStep						       = (fDoStep)			       getAdr(fmu, "fmiDoStep");						

  return 0;
}
Ejemplo n.º 4
0
 char* Shm::getShm(int iFlag) {
     if (getShmId(iFlag) == 0) {
         return NULL;
     }
     return getAdr();
 }
Ejemplo n.º 5
0
// Load the given dll and set function pointers in fmu
static int loadDll(const char* dllPath, FMU *fmu) {
    HANDLE h = LoadLibrary(dllPath);
    if (!h) {
        printf("error: Could not load %s: %s\n", dllPath, strerror(GetLastError()));
        return 0; // failure
    }
    fmu->dllHandle = h;
    fmu->getModelTypesPlatform   = (fGetModelTypesPlatform) getAdr(fmu, "fmiGetModelTypesPlatform");
    fmu->getVersion              = (fGetVersion)         getAdr(fmu, "fmiGetVersion");
    fmu->instantiateModel        = (fInstantiateModel)   getAdr(fmu, "fmiInstantiateModel");
    fmu->freeModelInstance       = (fFreeModelInstance)  getAdr(fmu, "fmiFreeModelInstance");
    fmu->setDebugLogging         = (fSetDebugLogging)    getAdr(fmu, "fmiSetDebugLogging");
    fmu->setTime                 = (fSetTime)            getAdr(fmu, "fmiSetTime");
    fmu->setContinuousStates     = (fSetContinuousStates)getAdr(fmu, "fmiSetContinuousStates");
    fmu->completedIntegratorStep = (fCompletedIntegratorStep)getAdr(fmu, "fmiCompletedIntegratorStep");
    fmu->setReal                 = (fSetReal)            getAdr(fmu, "fmiSetReal");
    fmu->setInteger              = (fSetInteger)         getAdr(fmu, "fmiSetInteger");
    fmu->setBoolean              = (fSetBoolean)         getAdr(fmu, "fmiSetBoolean");
    fmu->setString               = (fSetString)          getAdr(fmu, "fmiSetString");
    fmu->initialize              = (fInitialize)         getAdr(fmu, "fmiInitialize");
    fmu->getDerivatives          = (fGetDerivatives)     getAdr(fmu, "fmiGetDerivatives");
    fmu->getEventIndicators      = (fGetEventIndicators) getAdr(fmu, "fmiGetEventIndicators");
    fmu->getReal                 = (fGetReal)            getAdr(fmu, "fmiGetReal");
    fmu->getInteger              = (fGetInteger)         getAdr(fmu, "fmiGetInteger");
    fmu->getBoolean              = (fGetBoolean)         getAdr(fmu, "fmiGetBoolean");
    fmu->getString               = (fGetString)          getAdr(fmu, "fmiGetString");
    fmu->eventUpdate             = (fEventUpdate)        getAdr(fmu, "fmiEventUpdate");
    fmu->getContinuousStates     = (fGetContinuousStates)getAdr(fmu, "fmiGetContinuousStates");
    fmu->getNominalContinuousStates = (fGetNominalContinuousStates)getAdr(fmu, "fmiGetNominalContinuousStates");
    fmu->getStateValueReferences = (fGetStateValueReferences)getAdr(fmu, "fmiGetStateValueReferences");
    fmu->terminate               = (fTerminate)          getAdr(fmu, "fmiTerminate");
    return 1; // success
}