Skip to content

Commit

Permalink
Added a generic F_MOVE where the type can be configured during deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
azoitl committed Mar 21, 2024
1 parent 92f61c5 commit 38049e0
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/modules/IEC61131-3/Arithmetic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ forte_add_sourcefile_hcpp(F_DIV)
forte_add_sourcefile_hcpp(F_MOD)
forte_add_sourcefile_hcpp(F_EXPT)
forte_add_sourcefile_hcpp(F_MOVE)
forte_add_sourcefile_hcpp(GEN_F_MOVE_fct)
forte_add_sourcefile_hcpp(F_MULTIME)
forte_add_sourcefile_hcpp(F_DIVTIME)
forte_add_sourcefile_hcpp(GEN_ADD)
Expand Down
110 changes: 110 additions & 0 deletions src/modules/IEC61131-3/Arithmetic/GEN_F_MOVE_fct.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*******************************************************************************
* Copyright (c) 2013, 2024 ACIN, Martin Erich Jobst,
* Primetals Technologies Austria 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
*
* Contributors:
* Alois Zoitl - refactored from F_MOVE
*******************************************************************************/

#include "GEN_F_MOVE_fct.h"
#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP
#include "GEN_F_MOVE_fct_gen.cpp"
#endif

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

DEFINE_GENERIC_FIRMWARE_FB(GEN_FORTE_F_MOVE, g_nStringIdGEN_F_MOVE)

const CStringDictionary::TStringId GEN_FORTE_F_MOVE::scmDataInputNames[] = {g_nStringIdIN};

const CStringDictionary::TStringId GEN_FORTE_F_MOVE::scmDataOutputNames[] = {g_nStringIdOUT};

const TDataIOID GEN_FORTE_F_MOVE::scmEIWith[] = {0, scmWithListDelimiter};
const TForteInt16 GEN_FORTE_F_MOVE::scmEIWithIndexes[] = {0};
const CStringDictionary::TStringId GEN_FORTE_F_MOVE::scmEventInputNames[] = {g_nStringIdREQ};

const TDataIOID GEN_FORTE_F_MOVE::scmEOWith[] = {0, scmWithListDelimiter};
const TForteInt16 GEN_FORTE_F_MOVE::scmEOWithIndexes[] = {0};
const CStringDictionary::TStringId GEN_FORTE_F_MOVE::scmEventOutputNames[] = {g_nStringIdCNF};


GEN_FORTE_F_MOVE::GEN_FORTE_F_MOVE(const CStringDictionary::TStringId paInstanceNameId, forte::core::CFBContainer &paContainer) :
CGenFunctionBlock<CFunctionBlock>(paContainer, paInstanceNameId) {
}

GEN_FORTE_F_MOVE::~GEN_FORTE_F_MOVE(){
if(nullptr!= mInterfaceSpec){
delete[](mInterfaceSpec->mDIDataTypeNames);
delete[](mInterfaceSpec->mDODataTypeNames);
}
}

void GEN_FORTE_F_MOVE::executeEvent(TEventID paEIID, CEventChainExecutionThread *const paECET) {
switch(paEIID) {
case scmEventREQID:
var_OUT() = var_IN();
sendOutputEvent(scmEventCNFID, paECET);
break;
}
}

void GEN_FORTE_F_MOVE::readInputData(TEventID paEIID) {
if(paEIID == scmEventREQID) {
readData(0, *mDIs[0], mDIConns[0]);
}
}

void GEN_FORTE_F_MOVE::writeOutputData(TEventID paEOID) {
if(paEOID == scmEventCNFID){
writeData(0, *mDOs[0], mDOConns[0]);
}
}

bool GEN_FORTE_F_MOVE::createInterfaceSpec(const char *paConfigString, SFBInterfaceSpec &paInterfaceSpec) {
CTypeLib::CTypeEntry *poToCreate = CTypeLib::findType(getDataTypeNameId(paConfigString), CTypeLib::getDTLibStart());
if (nullptr == poToCreate) {
return false;
}

CStringDictionary::TStringId *diDataTypeNames = new CStringDictionary::TStringId[1];
diDataTypeNames[0] = poToCreate->getTypeNameId();
CStringDictionary::TStringId *doDataTypeNames = new CStringDictionary::TStringId[1];
doDataTypeNames[0] = poToCreate->getTypeNameId();

paInterfaceSpec.mNumEIs = 1;
paInterfaceSpec.mEINames = scmEventInputNames;
paInterfaceSpec.mEIWith = scmEIWith;
paInterfaceSpec.mEIWithIndexes = scmEIWithIndexes;
paInterfaceSpec.mNumEOs = 1;
paInterfaceSpec.mEONames = scmEventOutputNames;
paInterfaceSpec.mEOWith = scmEOWith;
paInterfaceSpec.mEOWithIndexes = scmEOWithIndexes;
paInterfaceSpec.mNumDIs = 1;
paInterfaceSpec.mDINames = scmDataInputNames;
paInterfaceSpec.mDIDataTypeNames = diDataTypeNames;
paInterfaceSpec.mNumDOs = 1;
paInterfaceSpec.mDONames = scmDataOutputNames;
paInterfaceSpec.mDODataTypeNames = doDataTypeNames;

return true;
}

CStringDictionary::TStringId GEN_FORTE_F_MOVE::getDataTypeNameId(const char *paConfigString) {
const char *acPos = strchr(paConfigString, '_');
if(nullptr != acPos){
acPos++;
acPos = strchr(acPos, '_');
if(nullptr != acPos){
acPos += 2; //put the position one after the separating number
return CStringDictionary::getInstance().getId(acPos);
}
}
return CStringDictionary::scmInvalidStringId;
}

70 changes: 70 additions & 0 deletions src/modules/IEC61131-3/Arithmetic/GEN_F_MOVE_fct.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*******************************************************************************
* Copyright (c) 2013, 2024 ACIN, Martin Erich Jobst,
* Primetals Technologies Austria 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
*
* Contributors:
* Alois Zoitl - refactored from F_MOVE
*******************************************************************************/

#pragma once

#include <genfb.h>
#include "forte_any_variant.h"
#include "iec61131_functions.h"
#include "forte_array_common.h"
#include "forte_array.h"
#include "forte_array_fixed.h"
#include "forte_array_variable.h"


class GEN_FORTE_F_MOVE : public CGenFunctionBlock<CFunctionBlock> {
DECLARE_GENERIC_FIRMWARE_FB(GEN_FORTE_F_MOVE)

private:
static const CStringDictionary::TStringId scmDataInputNames[];

static const CStringDictionary::TStringId scmDataOutputNames[];

static const TEventID scmEventREQID = 0;

static const TDataIOID scmEIWith[];
static const TForteInt16 scmEIWithIndexes[];
static const CStringDictionary::TStringId scmEventInputNames[];

static const TEventID scmEventCNFID = 0;

static const TDataIOID scmEOWith[];
static const TForteInt16 scmEOWithIndexes[];
static const CStringDictionary::TStringId scmEventOutputNames[];


bool createInterfaceSpec(const char *paConfigString, SFBInterfaceSpec &paInterfaceSpec) override;

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

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

static CStringDictionary::TStringId getDataTypeNameId(const char *paConfigString);

public:
GEN_FORTE_F_MOVE(const CStringDictionary::TStringId paInstanceNameId, forte::core::CFBContainer &paContainer);
~GEN_FORTE_F_MOVE() override;

CIEC_ANY_VARIANT& var_IN() {
return *static_cast<CIEC_ANY_VARIANT*>(getDI(0));
}

CIEC_ANY_VARIANT& var_OUT() {
return *static_cast<CIEC_ANY_VARIANT*>(getDO(0));
}

};



0 comments on commit 38049e0

Please sign in to comment.