⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compilation.c

📁 RT-LAB分布式实时仿真平台下API函数的调用例程
💻 C
字号:
/****************************************************************************

		Example using RT-LAB API.
		Gives the main step in order to compile a model.

*****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// Header for getcwd() is platform-dependent
#if defined(WIN32)
	#include <direct.h>
#elif defined(__linux__)
	#include <unistd.h>
	#define _MAX_PATH 256
#endif
#include "OpalApi.h"

#define FALSE 0
#define TRUE 1

void PrintError(int rc, char *funcName);

int main(void)
{
	char modelName[_MAX_PATH] = "compilation.mdl";
	char modelPath[_MAX_PATH];
	char modelPathName[_MAX_PATH*2];
#if defined(WIN32)
	char relativePath[] = "\\..\\models\\simulink\\";
#elif defined(__linux__)
	char relativePath[] = "/../models/simulink/";
#endif

	int					rc;
	unsigned int		option;
	unsigned short		compilationStatus, displayId;
	char				displayBuf[512];

	if (NULL != getcwd(modelPath, sizeof(modelPath))
	  && (strlen(modelPath) + strlen(relativePath) < _MAX_PATH))
	{
		strcat(modelPath, relativePath);
	}
	else
	{
		PrintError(0, "Invalid path");
		return 1;
	}

	// Set current model
	strcpy(modelPathName, modelPath);
	strcat(modelPathName, modelName);
	rc = OpalSetCurrentModel(modelPathName, NULL);
    if(EOK != rc)
	{
		PrintError(rc, "OpalSetCurrentModel");
		return(rc);
	}
    printf("- Setting of model '%s' is completed.\n", modelName);
	
	// Compile the model
	rc = OpalRegisterDisplay(DISPLAY_REGISTER_ALL);
	if(rc != EOK)
	{
		PrintError(rc, "OpalRegisterDisplay");
		OpalDisconnect();
		return rc;
	}
	
	option = OP_SEPARATE_ONLY |
		     OP_GENERATE_ONLY |
		     OP_TRANSFER_ONLY |
			 OP_COMPIL_ONLY  |
			 OP_RETRIEVE_FILES_ONLY;
	rc = OpalStartCompile(option);
	if(rc != EOK)
	{
		PrintError(rc, "OpalStartCompile");
		OpalDisconnect();
		return rc;
	}
	
	compilationStatus = FALSE;
	while(compilationStatus != TRUE)
	{
		rc = OpalDisplayInformation(displayBuf, 512, OP_API_INFINITE, &compilationStatus, &displayId);
		if(rc != EOK)
		{
			PrintError(rc, "OpalDisplayInformation");
			OpalDisconnect();
			return rc;
		}
		printf("%s",displayBuf);
	}
	
	rc = OpalRegisterDisplay(DISPLAY_UNREGISTER);
	if(rc != EOK)
	{
		PrintError(rc, "OpalRegisterDisplay");
		OpalDisconnect();
		return rc;
	}
	printf("- Model %s is compiled.\n", modelName);
	
	// Disconnect from the model
	OpalDisconnect();
	printf("- Model %s is disconnected.\n", modelName);

	return 0;
}


void PrintError(int rc, char *funcName)
{
	char			buf[512];
	unsigned short	len;

	OpalGetLastErrMsg(buf, sizeof(buf), &len);
	printf("Error %s (code %d) from %s\n", buf, rc, funcName);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -