"""This is the main package of SMIA, that includes all source code and all subpackages."""__author__="""Ekaitz Hurtado"""__email__="ekaitz.hurtado@ehu.eus"__version__='0.2.0'importloggingimportntpathimportspadefrom.aas_model.aas_model_utilsimportAASModelUtilsfrom.utilities.aas_model_extension_utilsimportAASModelExtensionUtilsfrom.utilitiesimportconfigmap_utils,smia_archive_utilsfrom.utilities.general_utilsimportGeneralUtilsfrom.utilities.smia_general_infoimportSMIAGeneralInfo
[docs]definitial_self_configuration():""" This method executes the initial configuration of the SMIA software. """# First, the BaSyx Python SDK is extended to have all new methods availableAASModelExtensionUtils.extend_basyx_aas_model()# Initialize SMIA archivesmia_archive_utils.initialize_smia_archive()# Configure loggingGeneralUtils.configure_logging()
[docs]defrun(agent_object):""" This method runs the SMIA software with a given agent. """_logger=logging.getLogger(__name__)ifagent_objectisNone:_logger.error('To launch SMIA, an agent must be passed to the method "smia.run".')returnasyncdefmain():awaitagent_object.start()awaitspade.wait_until_finished(agent_object)# In the general properties file you can select the web interface (provided by SPADE).web_ui=configmap_utils.get_dt_general_property('web-ui')ifweb_ui.lower()in('yes','true','t','1'):# bool(string) cannot be used as it is true as long as the string is not empty.agent_object.web.start(hostname="0.0.0.0",port="10002")spade.run(main())
[docs]defload_aas_model(file_path):""" This method loads the AAS model using a given path to the AASX package file. Args: file_path (str): path to the AASX package file. """_logger=logging.getLogger(__name__)# TODO At the moment it only collects models in AASX, think about whether to leave option to XML and JSON as well.iffile_pathisNone:_logger.error("The file path to the AAS model is None, so it cannot be loaded.")return# The variable with the AAS model file name is updatedaas_model_file_name=ntpath.split(file_path)[1]orntpath.basename(ntpath.split(file_path)[0])SMIAGeneralInfo.CM_AAS_MODEL_FILENAME=aas_model_file_nameconfig_file_path=AASModelUtils.get_configuration_file_path_from_standard_submodel()init_config_file_name=ntpath.split(config_file_path)[1]orntpath.basename(ntpath.split(config_file_path)[0])config_file_bytes=AASModelUtils.get_file_bytes_from_aasx_by_path(config_file_path)ifconfig_file_bytesisNone:_logger.error("The AAS model is invalid: the initialization configuration file has not been specified inside ""the AASX package.")withopen(SMIAGeneralInfo.CONFIGURATION_FOLDER_PATH+'/'+init_config_file_name,"wb")asbinary_file:binary_file.write(config_file_bytes)# Write bytes to fileSMIAGeneralInfo.CM_GENERAL_PROPERTIES_FILENAME=init_config_file_name