Ejemplo n.º 1
0
fmi1_import_t* fmi1_import_parse_xml( fmi_import_context_t* context, const char* dirPath) {
	char* xmlPath; 
	char absPath[FILENAME_MAX + 2];
	jm_callbacks* cb;
	fmi1_import_t* fmu;

	if(!context) return 0;

	cb = context->callbacks; 
	
	xmlPath =  fmi_import_get_model_description_path(dirPath, context->callbacks);

	fmu = fmi1_import_allocate(context->callbacks);

	if(!fmu) {
		context->callbacks->free(xmlPath);
		return 0;
	}
	
	jm_log_verbose( cb, "FMILIB", "Parsing model description XML");

	if(fmi1_xml_parse_model_description( fmu->md, xmlPath)) {
		fmi1_import_free(fmu);
		cb->free(xmlPath);
		return 0;
	}
	cb->free(xmlPath);
	
	fmu->dirPath =  (char*)cb->calloc(strlen(dirPath) + 1, sizeof(char));

	if(jm_get_dir_abspath(cb, dirPath, absPath, FILENAME_MAX + 2)) {
		fmu->location = fmi_import_create_URL_from_abs_path(cb, absPath);
	}
	
	if ((fmu->dirPath == NULL) || (fmu->location == 0)){
		jm_log_fatal( cb, "FMILIB", "Could not allocated memory");
		fmi1_import_free(fmu);
		cb->free(xmlPath);
		return 0;
	}
	strcpy(fmu->dirPath, dirPath);

	jm_log_verbose( cb, "FMILIB", "Parsing finished successfully");

	return fmu;
}
Ejemplo n.º 2
0
fmi2_import_t* fmi2_import_parse_xml( fmi_import_context_t* context, const char* dirPath, fmi2_xml_callbacks_t* xml_callbacks) {
	char* xmlPath;
	char absPath[FILENAME_MAX + 2];
	fmi2_import_t* fmu = 0;

	if(strlen(dirPath) + 20 > FILENAME_MAX) {
		jm_log_fatal(context->callbacks, module, "Directory path for FMU is too long");
		return 0;
	}

	xmlPath =  fmi_import_get_model_description_path(dirPath, context->callbacks);
	fmu = fmi2_import_allocate(context->callbacks);

	if(!fmu) {
		context->callbacks->free(xmlPath);
		return 0;
	}

	if(jm_get_dir_abspath(context->callbacks, dirPath, absPath, FILENAME_MAX + 2)) {
		size_t len = strlen(absPath);
		strcpy(absPath + len, FMI_FILE_SEP "resources");
		fmu->resourceLocation = fmi_import_create_URL_from_abs_path(context->callbacks, absPath);
	}
	fmu->dirPath =  context->callbacks->malloc(strlen(dirPath) + 1);
	if (!fmu->dirPath ||  !fmu->resourceLocation) {
		jm_log_fatal( context->callbacks, "FMILIB", "Could not allocated memory");
		fmi2_import_free(fmu);
		context->callbacks->free(xmlPath);
		return 0;
	}
	strcpy(fmu->dirPath, dirPath);

	jm_log_verbose( context->callbacks, "FMILIB", "Parsing model description XML");

	if(fmi2_xml_parse_model_description( fmu->md, xmlPath, xml_callbacks)) {
		fmi2_import_free(fmu);
		fmu = 0;
	}
	context->callbacks->free(xmlPath);

	if(fmu)
		jm_log_verbose( context->callbacks, "FMILIB", "Parsing finished successfully");

	return fmu;
}
fmi_version_enu_t fmi_import_get_fmi_version( fmi_import_context_t* c, const char* fileName, const char* dirName) {
	fmi_version_enu_t ret = fmi_version_unknown_enu;
	jm_status_enu_t status;
	char* mdpath;
	jm_log_verbose(c->callbacks, MODULE, "Detecting FMI standard version");
	if(!fileName || !*fileName) {
		jm_log_fatal(c->callbacks, MODULE, "No FMU filename specified");
		return fmi_version_unknown_enu;
	}
	if(!dirName || !*dirName) {
		jm_log_fatal(c->callbacks, MODULE, "No temporary directory name specified");
		return fmi_version_unknown_enu;
	}
	status = fmi_zip_unzip(fileName, dirName, c->callbacks);
	if(status == jm_status_error) return fmi_version_unknown_enu;
	mdpath = fmi_import_get_model_description_path(dirName, c->callbacks);
	ret = fmi_xml_get_fmi_version(c, mdpath);
	jm_log_info(c->callbacks, MODULE, "XML specifies FMI standard version %s", fmi_version_to_string(ret));
	c->callbacks->free(mdpath);
	return ret;
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
	fmiCallbackFunctions callBackFunctions;
	fmi_dll_t* fmu;	
	const char* FMUPath = "C:\\P510-JModelica\\FMIToolbox\\trunk\\src\\wrapperfolder\\Furuta.fmu";
	const char* tmpPath = "C:\\Documents and Settings\\p418_baa\\Desktop\\XMLtest\\temporaryfolder";
	const char* dllPath;
	const char* modelIdentifier;
	const char* modelName;
	const char* model_description_path;
	const char* instanceName;
	const char*  GUID;
	fmi_dll_standard_enu_t standard = 	FMI_ME1; /* or FMI_CS1 */	



	fmiBoolean loggingOn = fmiTrue;
	fmi1_xml_model_description_t* md;
	jm_status_enu_t status;

	PRINT_MY_DEBUG;

	if (jm_status_error == fmi_zip_unzip(FMUPath, tmpPath)) {
		printf("Failed to unzip the FMU file\n");
		abort();
	}

	callBackFunctions.logger = mylogger;
	callBackFunctions.allocateMemory = calloc;
	callBackFunctions.freeMemory = free;

	model_description_path = fmi_import_get_model_description_path(tmpPath, callBackFunctions);

	md = fmi1_xml_allocate_model_description(0);

    if(!md) abort();

    if(fmi1_xml_parse(md, model_description_path)) {
        printf("Error parsing XML file %s:%s\n", FMUPath, fmi1_xml_get_last_error(md));
        fmi1_xml_free_model_description(md);
        abort();
	}

	
    printf("Model name: %s\n", fmi1_xml_get_model_name(md));
    printf("Model identifier: %s\n", fmi1_xml_get_model_identifier(md));
    printf("Model GUID: %s\n", fmi1_xml_get_GUID(md));

	modelIdentifier = fmi1_xml_get_model_identifier(md);
	modelName = fmi1_xml_get_model_name(md);
	GUID = fmi1_xml_get_GUID(md);

	modelIdentifier = fmi1_xml_get_model_identifier(md);

	

	dllPath = fmi_import_get_dll_path(tmpPath, modelIdentifier, callBackFunctions);

	fmu = fmi_dll_common_create_dllfmu(dllPath, modelIdentifier, callBackFunctions, standard);
	if (fmu == NULL) {
		printf("An error occured while fmi_dll_common_create_dllfmu was called, an error message should been printed.\n");
		do_pause();
		return 0;
	}

	status = fmi_dll_common_load_dll(fmu);
	if (status == jm_status_error) {
		printf("Error in fmi_dll_common_load_dll: %s\n", fmi_dll_common_get_last_error(fmu));
		do_pause();
		return 0;
	}

	status = fmi_dll_common_load_fcn(fmu);
	if (status == jm_status_error) {
		printf("Error in fmi_dll_common_load_fcn: %s\n", fmi_dll_common_get_last_error(fmu));
		do_pause();
		return 0;
	}

	printf("fmi_dll_1_0_me_get_version:              %s\n", fmi_dll_1_0_me_get_version(fmu));

	fmi_dll_common_free_dll(fmu);
	fmi_dll_common_destroy_dllfmu(fmu);

	fmi1_xml_free_model_description(md);

	printf("Everything seems to be OK since you got this far=)!\n");

	do_pause();
}