Skip to content

Commit

Permalink
Add new functions for retrieving current time and monotonic time. (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
franz-hoepfinger-4diac authored Oct 11, 2024
1 parent 1f9ac07 commit d13a4d1
Show file tree
Hide file tree
Showing 5 changed files with 406 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/modules/utils/timing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#*******************************************************************************
# Copyright (c) 2024 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
#
# Contributors:
# Franz Höpfinger - initial API and implementation and/or initial documentation
# *******************************************************************************/
forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
#############################################################################
# timing
#############################################################################

forte_add_sourcefile_hcpp(F_NOW_fct)
forte_add_sourcefile_hcpp(F_NOW_MONOTONIC_fct)
116 changes: 116 additions & 0 deletions src/modules/utils/timing/F_NOW_MONOTONIC_fct.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*******************************************************************************
* Copyright (c) 2024 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
*** This file was generated using the 4DIAC FORTE Export Filter V1.0.x NG!
***
*** Name: F_NOW_MONOTONIC
*** Description: return a clear monotonic time
*** Version:
*** 1.0: 2024-10-01/Franz Höpfinger - HR Agrartechnik GmbH -
*************************************************************************/

#include "F_NOW_MONOTONIC_fct.h"
#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP
#include "F_NOW_MONOTONIC_fct_gen.cpp"
#endif

#include "forte_time.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 "F_NOW_MONOTONIC_fct.h"

DEFINE_FIRMWARE_FB(FORTE_utils__timing__F_NOW_MONOTONIC, g_nStringIdutils__timing__F_NOW_MONOTONIC)

const CStringDictionary::TStringId FORTE_utils__timing__F_NOW_MONOTONIC::scmDataOutputNames[] = {g_nStringId};
const CStringDictionary::TStringId FORTE_utils__timing__F_NOW_MONOTONIC::scmDataOutputTypeIds[] = {g_nStringIdTIME};
const TForteInt16 FORTE_utils__timing__F_NOW_MONOTONIC::scmEIWithIndexes[] = {-1};
const CStringDictionary::TStringId FORTE_utils__timing__F_NOW_MONOTONIC::scmEventInputNames[] = {g_nStringIdREQ};
const TDataIOID FORTE_utils__timing__F_NOW_MONOTONIC::scmEOWith[] = {0, scmWithListDelimiter};
const TForteInt16 FORTE_utils__timing__F_NOW_MONOTONIC::scmEOWithIndexes[] = {0};
const CStringDictionary::TStringId FORTE_utils__timing__F_NOW_MONOTONIC::scmEventOutputNames[] = {g_nStringIdCNF};
const SFBInterfaceSpec FORTE_utils__timing__F_NOW_MONOTONIC::scmFBInterfaceSpec = {
1, scmEventInputNames, nullptr, scmEIWithIndexes,
1, scmEventOutputNames, scmEOWith, scmEOWithIndexes,
0, nullptr, nullptr,
1, scmDataOutputNames, scmDataOutputTypeIds,
0, nullptr,
0, nullptr
};

FORTE_utils__timing__F_NOW_MONOTONIC::FORTE_utils__timing__F_NOW_MONOTONIC(const CStringDictionary::TStringId paInstanceNameId, forte::core::CFBContainer &paContainer) :
CFunctionBlock(paContainer, scmFBInterfaceSpec, paInstanceNameId),
var_conn_(var_),
conn_CNF(this, 0),
conn_(this, 0, &var_conn_) {
}

void FORTE_utils__timing__F_NOW_MONOTONIC::setInitialValues() {
var_ = 0_TIME;
}

void FORTE_utils__timing__F_NOW_MONOTONIC::readInputData(TEventID) {
// nothing to do
}

void FORTE_utils__timing__F_NOW_MONOTONIC::writeOutputData(const TEventID paEIID) {
switch(paEIID) {
case scmEventCNFID: {
writeData(0, var_, conn_);
break;
}
default:
break;
}
}

CIEC_ANY *FORTE_utils__timing__F_NOW_MONOTONIC::getDI(size_t) {
return nullptr;
}

CIEC_ANY *FORTE_utils__timing__F_NOW_MONOTONIC::getDO(const size_t paIndex) {
switch(paIndex) {
case 0: return &var_;
}
return nullptr;
}

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

CDataConnection **FORTE_utils__timing__F_NOW_MONOTONIC::getDIConUnchecked(TPortId) {
return nullptr;
}

CDataConnection *FORTE_utils__timing__F_NOW_MONOTONIC::getDOConUnchecked(const TPortId paIndex) {
switch(paIndex) {
case 0: return &conn_;
}
return nullptr;
}

void FORTE_utils__timing__F_NOW_MONOTONIC::executeEvent(const TEventID, CEventChainExecutionThread *const paECET) {
var_ = func_F_NOW_MONOTONIC();
sendOutputEvent(scmEventCNFID, paECET);
}

CIEC_TIME func_F_NOW_MONOTONIC() {
CIEC_TIME st_ret_val = 0_TIME;

#line 5 "F_NOW_MONOTONIC.fct"
st_ret_val = func_NOW_MONOTONIC();

return st_ret_val;
}
78 changes: 78 additions & 0 deletions src/modules/utils/timing/F_NOW_MONOTONIC_fct.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*******************************************************************************
* Copyright (c) 2024 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
*** This file was generated using the 4DIAC FORTE Export Filter V1.0.x NG!
***
*** Name: F_NOW_MONOTONIC
*** Description: return a clear monotonic time
*** Version:
*** 1.0: 2024-10-01/Franz Höpfinger - HR Agrartechnik GmbH -
*************************************************************************/

#pragma once

#include "funcbloc.h"
#include "forte_time.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 FORTE_utils__timing__F_NOW_MONOTONIC final : public CFunctionBlock {
DECLARE_FIRMWARE_FB(FORTE_utils__timing__F_NOW_MONOTONIC)

private:
static const CStringDictionary::TStringId scmDataOutputNames[];
static const CStringDictionary::TStringId scmDataOutputTypeIds[];
static const TEventID scmEventREQID = 0;
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[];

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_utils__timing__F_NOW_MONOTONIC(CStringDictionary::TStringId paInstanceNameId, forte::core::CFBContainer &paContainer);

CIEC_TIME var_;

CIEC_TIME var_conn_;

CEventConnection conn_CNF;

CDataConnection conn_;

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_REQ(CIEC_TIME &pa) {
executeEvent(scmEventREQID, nullptr);
pa = var_;
}

void operator()(CIEC_TIME &pa) {
evt_REQ(pa);
}
};

CIEC_TIME func_F_NOW_MONOTONIC();

116 changes: 116 additions & 0 deletions src/modules/utils/timing/F_NOW_fct.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*******************************************************************************
* Copyright (c) 2024 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
*** This file was generated using the 4DIAC FORTE Export Filter V1.0.x NG!
***
*** Name: F_NOW
*** Description: return the current time
*** Version:
*** 1.0: 2024-10-01/Franz Höpfinger - HR Agrartechnik GmbH -
*************************************************************************/

#include "F_NOW_fct.h"
#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP
#include "F_NOW_fct_gen.cpp"
#endif

#include "forte_date_and_time.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 "F_NOW_fct.h"

DEFINE_FIRMWARE_FB(FORTE_utils__timing__F_NOW, g_nStringIdutils__timing__F_NOW)

const CStringDictionary::TStringId FORTE_utils__timing__F_NOW::scmDataOutputNames[] = {g_nStringId};
const CStringDictionary::TStringId FORTE_utils__timing__F_NOW::scmDataOutputTypeIds[] = {g_nStringIdDATE_AND_TIME};
const TForteInt16 FORTE_utils__timing__F_NOW::scmEIWithIndexes[] = {-1};
const CStringDictionary::TStringId FORTE_utils__timing__F_NOW::scmEventInputNames[] = {g_nStringIdREQ};
const TDataIOID FORTE_utils__timing__F_NOW::scmEOWith[] = {0, scmWithListDelimiter};
const TForteInt16 FORTE_utils__timing__F_NOW::scmEOWithIndexes[] = {0};
const CStringDictionary::TStringId FORTE_utils__timing__F_NOW::scmEventOutputNames[] = {g_nStringIdCNF};
const SFBInterfaceSpec FORTE_utils__timing__F_NOW::scmFBInterfaceSpec = {
1, scmEventInputNames, nullptr, scmEIWithIndexes,
1, scmEventOutputNames, scmEOWith, scmEOWithIndexes,
0, nullptr, nullptr,
1, scmDataOutputNames, scmDataOutputTypeIds,
0, nullptr,
0, nullptr
};

FORTE_utils__timing__F_NOW::FORTE_utils__timing__F_NOW(const CStringDictionary::TStringId paInstanceNameId, forte::core::CFBContainer &paContainer) :
CFunctionBlock(paContainer, scmFBInterfaceSpec, paInstanceNameId),
var_conn_(var_),
conn_CNF(this, 0),
conn_(this, 0, &var_conn_) {
}

void FORTE_utils__timing__F_NOW::setInitialValues() {
var_ = 0_DATE_AND_TIME;
}

void FORTE_utils__timing__F_NOW::readInputData(TEventID) {
// nothing to do
}

void FORTE_utils__timing__F_NOW::writeOutputData(const TEventID paEIID) {
switch(paEIID) {
case scmEventCNFID: {
writeData(0, var_, conn_);
break;
}
default:
break;
}
}

CIEC_ANY *FORTE_utils__timing__F_NOW::getDI(size_t) {
return nullptr;
}

CIEC_ANY *FORTE_utils__timing__F_NOW::getDO(const size_t paIndex) {
switch(paIndex) {
case 0: return &var_;
}
return nullptr;
}

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

CDataConnection **FORTE_utils__timing__F_NOW::getDIConUnchecked(TPortId) {
return nullptr;
}

CDataConnection *FORTE_utils__timing__F_NOW::getDOConUnchecked(const TPortId paIndex) {
switch(paIndex) {
case 0: return &conn_;
}
return nullptr;
}

void FORTE_utils__timing__F_NOW::executeEvent(const TEventID, CEventChainExecutionThread *const paECET) {
var_ = func_F_NOW();
sendOutputEvent(scmEventCNFID, paECET);
}

CIEC_DATE_AND_TIME func_F_NOW() {
CIEC_DATE_AND_TIME st_ret_val = 0_DATE_AND_TIME;

#line 5 "F_NOW.fct"
st_ret_val = func_NOW();

return st_ret_val;
}
Loading

0 comments on commit d13a4d1

Please sign in to comment.