Skip to content

Commit

Permalink
Move command parsing outside of the DEV_MGR class
Browse files Browse the repository at this point in the history
* move command parsing outside of the DEV_MGR class
* replace IBootFileCallback class with a callback function
* move string representation of response message out of the DEV_MGR
* add parameter to ForteBootFileLoader
* remove include not needed anymore
* remove unused variables
* move parser into its own class to avoid passing the command around
* implement feedback from PR
* fix logging string
* make the command parser a member of DEV_MGR
  • Loading branch information
cochicde authored Jan 19, 2025
1 parent 000d5c2 commit 09d7712
Show file tree
Hide file tree
Showing 23 changed files with 885 additions and 775 deletions.
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,6 @@ SET(FORTE_IPLayerRecvBufferSize "1500" CACHE STRING "FORTE IP layer recv buffer
endif(FORTE_DYNAMIC_TYPE_LOAD)
mark_as_advanced(FORTE_IPLayerRecvBufferSize)

SET(FORTE_MGMCOMMANDPROTOCOL "DEV_MGR" CACHE STRING "FORTE management command protocol")
set_property(CACHE FORTE_MGMCOMMANDPROTOCOL PROPERTY STRINGS DEV_MGR)
mark_as_advanced(FORTE_MGMCOMMANDPROTOCOL)

SET(FORTE_MGM_MAX_SUPPORTED_NAME_HIERACHY "30" CACHE STRING "Max supported hierarchy that can be provided in a management commands")
mark_as_advanced(FORTE_MGM_MAX_SUPPORTED_NAME_HIERACHY)

Expand Down
8 changes: 0 additions & 8 deletions forte_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ const unsigned int cgCommunicationInterruptQueueSize = ${FORTE_CommunicationInte
*/
const unsigned int cgIPLayerRecvBufferSize = ${FORTE_IPLayerRecvBufferSize};

/*! \brief Define the management encapsulation protocol
*
* Currently two protocols are supported:
* # DEV_MGR for FBDK compliant XML encoded commands
* # WBXML_DEV_MGR for WAP Binary XML encoded commands
*/
#define FORTE_MGM_COMMAND_PROTOCOL ${FORTE_MGMCOMM-ANDPROTOCOL}

//! Max supported hierarchy that can be provided in a management commands
#define FORTE_MGM_MAX_SUPPORTED_NAME_HIERARCHY ${FORTE_MGM_MAX_SUPPORTED_NAME_HIERACHY}

Expand Down
4 changes: 2 additions & 2 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ forte_add_subdirectory(fmi)
forte_add_sourcefile_hcpp(conn dataconn inoutdataconn eventconn)
forte_add_sourcefile_h(connectiondestinationtype.h)

forte_add_sourcefile_h(esfb.h event.h mgmcmd.h fortenode.h fortelist.h genfb.h simplefb.h)
forte_add_sourcefile_hcpp(basicfb cfb device devexec forteinstance)
forte_add_sourcefile_h(esfb.h event.h fortenode.h fortelist.h genfb.h simplefb.h)
forte_add_sourcefile_hcpp(basicfb cfb device devexec forteinstance mgmcmd)
forte_add_sourcefile_hcpp(extevhan funcbloc fbcontainer if2indco)
forte_add_sourcefile_hcpp(resource stringdict typelib ecet)
forte_add_sourcefile_hcpp(adapterconn adapter anyadapter iec61131_functions)
Expand Down
44 changes: 44 additions & 0 deletions src/core/mgmcmd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (c) 2024 Jose Cabral
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Jose Cabral:
* - initial implementation and rework communication infrastructure
*******************************************************************************/

#include "mgmcmd.h"

#include <type_traits>

namespace forte::mgm_cmd {

/*!\brief Type for the response of MGM command messages
*
* TODO fully define all responses as defined in IEC 61499 inc. numbers.
*/
const std::string scmMGMResponseTexts[] = {
"RDY",
"BAD_PARAMS",
"LOCAL_TERMINATION",
"SYSTEM_TERMINATION",
"NOT_READY",
"UNSUPPORTED_CMD",
"UNSUPPORTED_TYPE",
"NO_SUCH_OBJECT",
"INVALID_OBJECT",
"INVALID_OPERATION",
"INVALID_STATE",
"OVERFLOW",
"INVALID_DST"
};

const std::string& getResponseText(EMGMResponse paResp) {
return scmMGMResponseTexts[static_cast<std::underlying_type_t<EMGMResponse>>(paResp)];
}

} // namespace forte::mgm_cmd
10 changes: 9 additions & 1 deletion src/core/mgmcmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
#ifndef _MGMCMD_H_
#define _MGMCMD_H_

#include <cstdint>
#include <forte_config.h>

#include <string>

/** \ingroup CORE \defgroup MGMCommands Management Commands Internal Representation
* \brief In this section the FORTE representation of the management commands is described.
Expand Down Expand Up @@ -266,5 +268,11 @@ enum class EMGMResponse {
InvalidDst
};

namespace forte::mgm_cmd {

const std::string& getResponseText(EMGMResponse paResp);

} // namespace forte::mgm_cmd

/*@}*/
#endif /*MGMCMD_H_*/
3 changes: 1 addition & 2 deletions src/modules/reconfiguration/EC_KILL_ELEM_fbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "criticalregion.h"
#include "resource.h"

#include "../../stdfblib/ita/DEV_MGR.h"
#include "device.h"

DEFINE_FIRMWARE_FB(FORTE_EC_KILL_ELEM, g_nStringIdEC_KILL_ELEM)
Expand Down Expand Up @@ -88,7 +87,7 @@ void FORTE_EC_KILL_ELEM::executeRQST(){

//calculate return value
var_QO = CIEC_BOOL(resp == EMGMResponse::Ready);
const std::string retVal(DEV_MGR::getResponseText(resp));
const std::string retVal(forte::mgm_cmd::getResponseText(resp));
DEVLOG_DEBUG("%s\n", retVal.c_str());
var_STATUS = CIEC_WSTRING(retVal.c_str());
}
Expand Down
3 changes: 1 addition & 2 deletions src/modules/reconfiguration/EC_SET_EVT_fbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include "device.h"
#include "mgmcmdstruct.h"
#include "../../stdfblib/ita/DEV_MGR.h"

DEFINE_FIRMWARE_FB(FORTE_EC_SET_EVT, g_nStringIdEC_SET_EVT)

Expand Down Expand Up @@ -91,7 +90,7 @@ void FORTE_EC_SET_EVT::executeRQST(){

//calculate return value
var_QO = CIEC_BOOL(resp == EMGMResponse::Ready);
const std::string retVal(DEV_MGR::getResponseText(resp));
const std::string retVal(forte::mgm_cmd::getResponseText(resp));
DEVLOG_DEBUG("%s\n", retVal.c_str());
var_STATUS = CIEC_WSTRING(retVal.c_str());
}
Expand Down
3 changes: 1 addition & 2 deletions src/modules/reconfiguration/EC_START_ELEM_fbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "resource.h"

#include "device.h"
#include "../../stdfblib/ita/DEV_MGR.h"

DEFINE_FIRMWARE_FB(FORTE_EC_START_ELEM, g_nStringIdEC_START_ELEM)

Expand Down Expand Up @@ -88,7 +87,7 @@ void FORTE_EC_START_ELEM::executeRQST(){

//calculate return value
var_QO = CIEC_BOOL(resp == EMGMResponse::Ready);
const std::string retVal(DEV_MGR::getResponseText(resp));
const std::string retVal(forte::mgm_cmd::getResponseText(resp));
DEVLOG_DEBUG("%s\n", retVal.c_str());
var_STATUS = CIEC_WSTRING(retVal.c_str());
}
Expand Down
3 changes: 1 addition & 2 deletions src/modules/reconfiguration/EC_STOP_ELEM_fbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "resource.h"

#include "device.h"
#include "../../stdfblib/ita/DEV_MGR.h"

DEFINE_FIRMWARE_FB(FORTE_EC_STOP_ELEM, g_nStringIdEC_STOP_ELEM)

Expand Down Expand Up @@ -88,7 +87,7 @@ void FORTE_EC_STOP_ELEM::executeRQST(){

//calculate return value
var_QO = CIEC_BOOL(resp == EMGMResponse::Ready);
const std::string retVal(DEV_MGR::getResponseText(resp));
const std::string retVal(forte::mgm_cmd::getResponseText(resp));
DEVLOG_DEBUG("%s\n", retVal.c_str());
var_STATUS = CIEC_WSTRING(retVal.c_str());
}
Expand Down
3 changes: 1 addition & 2 deletions src/modules/reconfiguration/ST_CREATE_CONN_fbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "resource.h"

#include "device.h"
#include "../../stdfblib/ita/DEV_MGR.h"

DEFINE_FIRMWARE_FB(FORTE_ST_CREATE_CONN, g_nStringIdST_CREATE_CONN)

Expand Down Expand Up @@ -97,7 +96,7 @@ void FORTE_ST_CREATE_CONN::executeRQST(){

//calculate return value
var_QO = CIEC_BOOL(resp == EMGMResponse::Ready);
const std::string retVal(DEV_MGR::getResponseText(resp));
const std::string retVal(forte::mgm_cmd::getResponseText(resp));
DEVLOG_DEBUG("%s\n", retVal.c_str());
var_STATUS = CIEC_WSTRING(retVal.c_str());
}
Expand Down
3 changes: 1 addition & 2 deletions src/modules/reconfiguration/ST_CREATE_FB_fbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include "device.h"
#include "mgmcmdstruct.h"
#include "../../stdfblib/ita/DEV_MGR.h"

DEFINE_FIRMWARE_FB(FORTE_ST_CREATE_FB, g_nStringIdST_CREATE_FB)

Expand Down Expand Up @@ -92,7 +91,7 @@ void FORTE_ST_CREATE_FB::executeRQST(){

//calculate return value
var_QO = CIEC_BOOL(resp == EMGMResponse::Ready);
const std::string retVal(DEV_MGR::getResponseText(resp));
const std::string retVal(forte::mgm_cmd::getResponseText(resp));
DEVLOG_DEBUG("%s\n", retVal.c_str());
var_STATUS = CIEC_WSTRING(retVal.c_str());
}
Expand Down
3 changes: 1 addition & 2 deletions src/modules/reconfiguration/ST_DEL_CONN_fbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "resource.h"

#include "device.h"
#include "../../stdfblib/ita/DEV_MGR.h"

DEFINE_FIRMWARE_FB(FORTE_ST_DEL_CONN, g_nStringIdST_DEL_CONN)

Expand Down Expand Up @@ -97,7 +96,7 @@ void FORTE_ST_DEL_CONN::executeRQST(){

//calculate return value
var_QO = CIEC_BOOL(resp == EMGMResponse::Ready);
const std::string retVal(DEV_MGR::getResponseText(resp));
const std::string retVal(forte::mgm_cmd::getResponseText(resp));
DEVLOG_DEBUG("%s\n", retVal.c_str());
var_STATUS = CIEC_WSTRING(retVal.c_str());
}
Expand Down
3 changes: 1 addition & 2 deletions src/modules/reconfiguration/ST_DEL_FB_fbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "resource.h"

#include "device.h"
#include "../../stdfblib/ita/DEV_MGR.h"

DEFINE_FIRMWARE_FB(FORTE_ST_DEL_FB, g_nStringIdST_DEL_FB)

Expand Down Expand Up @@ -88,7 +87,7 @@ void FORTE_ST_DEL_FB::executeRQST(){

//calculate return value
var_QO = CIEC_BOOL(resp == EMGMResponse::Ready);
const std::string retVal(DEV_MGR::getResponseText(resp));
const std::string retVal(forte::mgm_cmd::getResponseText(resp));
DEVLOG_DEBUG("%s\n", retVal.c_str());
var_STATUS = CIEC_WSTRING(retVal.c_str());
}
Expand Down
3 changes: 1 addition & 2 deletions src/modules/reconfiguration/ST_REC_CONN_fbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "resource.h"

#include "device.h"
#include "../../stdfblib/ita/DEV_MGR.h"

DEFINE_FIRMWARE_FB(FORTE_ST_REC_CONN, g_nStringIdST_REC_CONN)

Expand Down Expand Up @@ -117,7 +116,7 @@ void FORTE_ST_REC_CONN::executeRQST(){

//calculate return value
var_QO = CIEC_BOOL(resp == EMGMResponse::Ready);
const std::string retVal(DEV_MGR::getResponseText(resp));
const std::string retVal(forte::mgm_cmd::getResponseText(resp));
DEVLOG_DEBUG("%s\n", retVal.c_str());
var_STATUS = CIEC_WSTRING(retVal.c_str());
}
Expand Down
3 changes: 1 addition & 2 deletions src/modules/reconfiguration/ST_SET_PARM_fbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "resource.h"

#include "device.h"
#include "../../stdfblib/ita/DEV_MGR.h"

DEFINE_FIRMWARE_FB(FORTE_ST_SET_PARM, g_nStringIdST_SET_PARM)

Expand Down Expand Up @@ -93,7 +92,7 @@ void FORTE_ST_SET_PARM::executeRQST() {

//calculate return value
var_QO = CIEC_BOOL(resp == EMGMResponse::Ready);
const std::string retVal(DEV_MGR::getResponseText(resp));
const std::string retVal(forte::mgm_cmd::getResponseText(resp));
DEVLOG_DEBUG("%s\n", retVal.c_str());
var_STATUS = CIEC_WSTRING(retVal.c_str());
}
Expand Down
2 changes: 1 addition & 1 deletion src/stdfblib/ita/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Ita FB
#############################################################################
SET(SOURCE_GROUP ${SOURCE_GROUP}\\ita)
forte_add_sourcefile_hcpp(DEV_MGR EMB_RES RMT_DEV RMT_RES)
forte_add_sourcefile_hcpp(DEV_MGR EMB_RES RMT_DEV RMT_RES CommandParser)

forte_add_device(RMT_DEV)

Expand Down
Loading

0 comments on commit 09d7712

Please sign in to comment.