Skip to content

Commit

Permalink
added based on new develop
Browse files Browse the repository at this point in the history
  • Loading branch information
MoritzO02 committed Jun 30, 2024
1 parent f000900 commit a3b1d3b
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ add_subdirectory(device)
add_subdirectory(mapper)

forte_add_sourcefile_hcpp(processinterface)
forte_set_process_interface("Modular IO" IE IX QX IB QB IW QW ID QD IL QL)
forte_set_process_interface("Modular IO" IE IX QE_fbt QX IB QB IW QW ID QD IL QL)
7 changes: 5 additions & 2 deletions src/core/io/processinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ bool ProcessInterface::initialise(bool paIsInput, CEventChainExecutionThread *co
if(paIsInput && (getFBInterfaceSpec()->mNumDOs < 3)) {
mType = CIEC_ANY::e_Max; //we assume that any FB which has no "IN" Output must be a EVENT-Only FB.
}
else if(!paIsInput && (getFBInterfaceSpec()->mNumDIs < 3)) {
mType = CIEC_ANY::e_Max; //we assume that any FB which has no "OUT" Input must be a EVENT-Only FB.
}
else {
//as it has a index 2 here, we safely can do this
mType = (paIsInput ? getDO(2) : getDI(2))->getDataTypeID();
Expand Down Expand Up @@ -153,8 +156,8 @@ bool ProcessInterface::write() {
mHandle->set(OUT_L());
break;
case CIEC_ANY::e_Max:
// we are an event only IO FB
return true; //it has no "OUT" ...
mHandle->set(QI()); //DUMMY, TODO what is right here ??!!??
break;
default:
return false;
}
Expand Down
160 changes: 160 additions & 0 deletions src/stdfblib/io/QE_fbt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*******************************************************************************
* Copyright (c) 2014, 2024 fortiss GmbH, HR Agrartechnik GmbH
* 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
*
*** Name: QE
*** Description: Output service interface function block for event output data
*** Version:
*** 1.0: 2014-08-26/Waldemar Eisenmenger - fortiss GmbH -
*** 1.1: 2014-08-30/Alois Zoitl - fortiss GmbH -
*** 1.2: 2015-06-10/Monika Wenger - fortiss GmbH -
*** 1.3: 2024-05-16/Franz Höpfinger - HR Agrartechnik GmbH - copied over QX to QE, and removed the OUT
*************************************************************************/

#include "QE_fbt.h"
#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP
#include "QE_fbt_gen.cpp"
#endif

#include "criticalregion.h"
#include "resource.h"

DEFINE_FIRMWARE_FB(FORTE_QE, g_nStringIdQE)

const CStringDictionary::TStringId FORTE_QE::scmDataInputNames[] = {g_nStringIdQI, g_nStringIdPARAMS};
const CStringDictionary::TStringId FORTE_QE::scmDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdSTRING};
const CStringDictionary::TStringId FORTE_QE::scmDataOutputNames[] = {g_nStringIdQO, g_nStringIdSTATUS};
const CStringDictionary::TStringId FORTE_QE::scmDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdSTRING};
const TDataIOID FORTE_QE::scmEIWith[] = {0, 1, scmWithListDelimiter, 0, scmWithListDelimiter};
const TForteInt16 FORTE_QE::scmEIWithIndexes[] = {0, 3};
const CStringDictionary::TStringId FORTE_QE::scmEventInputNames[] = {g_nStringIdINIT, g_nStringIdREQ};
const TDataIOID FORTE_QE::scmEOWith[] = {0, 1, scmWithListDelimiter, 0, 1, scmWithListDelimiter};
const TForteInt16 FORTE_QE::scmEOWithIndexes[] = {0, 3};
const CStringDictionary::TStringId FORTE_QE::scmEventOutputNames[] = {g_nStringIdINITO, g_nStringIdCNF};
const SFBInterfaceSpec FORTE_QE::scmFBInterfaceSpec = {
2, scmEventInputNames, scmEIWith, scmEIWithIndexes,
2, scmEventOutputNames, scmEOWith, scmEOWithIndexes,
2, scmDataInputNames, scmDataInputTypeIds,
2, scmDataOutputNames, scmDataOutputTypeIds,
0, nullptr,
0, nullptr
};

FORTE_QE::FORTE_QE(const CStringDictionary::TStringId paInstanceNameId, forte::core::CFBContainer &paContainer) :
CProcessInterface(paContainer, &scmFBInterfaceSpec, paInstanceNameId),
var_conn_QO(var_QO),
var_conn_STATUS(var_STATUS),
conn_INITO(this, 0),
conn_CNF(this, 1),
conn_QI(nullptr),
conn_PARAMS(nullptr),
conn_QO(this, 0, &var_conn_QO),
conn_STATUS(this, 1, &var_conn_STATUS) {
};

void FORTE_QE::setInitialValues() {
var_QI = 0_BOOL;
var_PARAMS = ""_STRING;
var_QO = 0_BOOL;
var_STATUS = ""_STRING;
}

void FORTE_QE::executeEvent(const TEventID paEIID, CEventChainExecutionThread *const paECET) {
switch(paEIID) {
case scmEventINITID:
if (var_QI) {
var_QO = CIEC_BOOL(CProcessInterface::initialise(false, paECET)); //initialise as output
} else {
var_QO = CIEC_BOOL(CProcessInterface::deinitialise());
}
sendOutputEvent(scmEventINITOID, paECET);
break;
case scmEventREQID:
if (var_QI) {
var_QO = CIEC_BOOL(CProcessInterface::write(var_QO));
} else {
var_QO = false_BOOL;
}
sendOutputEvent(scmEventCNFID, paECET);
break;
}
}

void FORTE_QE::readInputData(const TEventID paEIID) {
switch(paEIID) {
case scmEventINITID: {
readData(0, var_QI, conn_QI);
readData(1, var_PARAMS, conn_PARAMS);
break;
}
case scmEventREQID: {
readData(0, var_QI, conn_QI);
break;
}
default:
break;
}
}

void FORTE_QE::writeOutputData(const TEventID paEIID) {
switch(paEIID) {
case scmEventINITOID: {
writeData(0, var_QO, conn_QO);
writeData(1, var_STATUS, conn_STATUS);
break;
}
case scmEventCNFID: {
writeData(0, var_QO, conn_QO);
writeData(1, var_STATUS, conn_STATUS);
break;
}
default:
break;
}
}

CIEC_ANY *FORTE_QE::getDI(const size_t paIndex) {
switch(paIndex) {
case 0: return &var_QI;
case 1: return &var_PARAMS;
}
return nullptr;
}

CIEC_ANY *FORTE_QE::getDO(const size_t paIndex) {
switch(paIndex) {
case 0: return &var_QO;
case 1: return &var_STATUS;
}
return nullptr;
}

CEventConnection *FORTE_QE::getEOConUnchecked(const TPortId paIndex) {
switch(paIndex) {
case 0: return &conn_INITO;
case 1: return &conn_CNF;
}
return nullptr;
}

CDataConnection **FORTE_QE::getDIConUnchecked(const TPortId paIndex) {
switch(paIndex) {
case 0: return &conn_QI;
case 1: return &conn_PARAMS;
}
return nullptr;
}

CDataConnection *FORTE_QE::getDOConUnchecked(const TPortId paIndex) {
switch(paIndex) {
case 0: return &conn_QO;
case 1: return &conn_STATUS;
}
return nullptr;
}

107 changes: 107 additions & 0 deletions src/stdfblib/io/QE_fbt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*******************************************************************************
* Copyright (c) 2014, 2024 fortiss GmbH, HR Agrartechnik GmbH
* 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
*
*** Name: QE
*** Description: Output service interface function block for event output data
*** Version:
*** 1.0: 2014-08-26/Waldemar Eisenmenger - fortiss GmbH -
*** 1.1: 2014-08-30/Alois Zoitl - fortiss GmbH -
*** 1.2: 2015-06-10/Monika Wenger - fortiss GmbH -
*** 1.3: 2024-05-16/Franz Höpfinger - HR Agrartechnik GmbH - copied over QX to QE, and removed the OUT
*************************************************************************/

#pragma once

#include "funcbloc.h"
#include "forte_bool.h"
#include "forte_string.h"
#include "iec61131_functions.h"
#include "forte_array_common.h"
#include "forte_array.h"
#include "forte_array_fixed.h"
#include "forte_array_variable.h"

#include "processinterface.h"

class FORTE_QE final : public CProcessInterface {
DECLARE_FIRMWARE_FB(FORTE_QE)

private:
static const CStringDictionary::TStringId scmDataInputNames[];
static const CStringDictionary::TStringId scmDataInputTypeIds[];
static const CStringDictionary::TStringId scmDataOutputNames[];
static const CStringDictionary::TStringId scmDataOutputTypeIds[];
static const TEventID scmEventINITID = 0;
static const TEventID scmEventREQID = 1;
static const TDataIOID scmEIWith[];
static const TForteInt16 scmEIWithIndexes[];
static const CStringDictionary::TStringId scmEventInputNames[];
static const TEventID scmEventINITOID = 0;
static const TEventID scmEventCNFID = 1;
static const TDataIOID scmEOWith[];
static const TForteInt16 scmEOWithIndexes[];
static const CStringDictionary::TStringId scmEventOutputNames[];

static const SFBInterfaceSpec scmFBInterfaceSpec;

void executeEvent(TEventID paEIID, CEventChainExecutionThread *const paECET) override;

void readInputData(TEventID paEIID) override;
void writeOutputData(TEventID paEIID) override;
void setInitialValues() override;

public:
FORTE_QE(CStringDictionary::TStringId paInstanceNameId, forte::core::CFBContainer &paContainer);

CIEC_BOOL var_QI;
CIEC_STRING var_PARAMS;

CIEC_BOOL var_QO;
CIEC_STRING var_STATUS;

CIEC_BOOL var_conn_QO;
CIEC_STRING var_conn_STATUS;

CEventConnection conn_INITO;
CEventConnection conn_CNF;

CDataConnection *conn_QI;
CDataConnection *conn_PARAMS;

CDataConnection conn_QO;
CDataConnection conn_STATUS;

CIEC_ANY *getDI(size_t) override;
CIEC_ANY *getDO(size_t) override;
CEventConnection *getEOConUnchecked(TPortId) override;
CDataConnection **getDIConUnchecked(TPortId) override;
CDataConnection *getDOConUnchecked(TPortId) override;

void evt_INIT(const CIEC_BOOL &paQI, const CIEC_STRING &paPARAMS, CIEC_BOOL &paQO, CIEC_STRING &paSTATUS) {
var_QI = paQI;
var_PARAMS = paPARAMS;
executeEvent(scmEventINITID, nullptr);
paQO = var_QO;
paSTATUS = var_STATUS;
}

void evt_REQ(const CIEC_BOOL &paQI, const CIEC_STRING &paPARAMS, CIEC_BOOL &paQO, CIEC_STRING &paSTATUS) {
var_QI = paQI;
var_PARAMS = paPARAMS;
executeEvent(scmEventREQID, nullptr);
paQO = var_QO;
paSTATUS = var_STATUS;
}

void operator()(const CIEC_BOOL &paQI, const CIEC_STRING &paPARAMS, CIEC_BOOL &paQO, CIEC_STRING &paSTATUS) {
evt_INIT(paQI, paPARAMS, paQO, paSTATUS);
}
};


0 comments on commit a3b1d3b

Please sign in to comment.