Added GAM
Signed-off-by: Bernardo Carvalho <bernardo.carvalho@tecnico.ulisboa.pt>
This commit is contained in:
486
GAMs/MagneticRZPosGAM/MagneticRZPosGAM.cpp
Normal file
486
GAMs/MagneticRZPosGAM/MagneticRZPosGAM.cpp
Normal file
@@ -0,0 +1,486 @@
|
|||||||
|
/**
|
||||||
|
* @file MagneticRZPosGAM.cpp
|
||||||
|
* @brief Source file for class MagneticRZPosGAM
|
||||||
|
* @date 06/04/2018
|
||||||
|
* @author Andre Neto
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2015 F4E | European Joint Undertaking for ITER and
|
||||||
|
* the Development of Fusion Energy ('Fusion for Energy').
|
||||||
|
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
|
||||||
|
* by the European Commission - subsequent versions of the EUPL (the "Licence")
|
||||||
|
* You may not use this work except in compliance with the Licence.
|
||||||
|
* You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
|
||||||
|
*
|
||||||
|
* @warning Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the Licence is distributed on an "AS IS"
|
||||||
|
* basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||||
|
* or implied. See the Licence permissions and limitations under the Licence.
|
||||||
|
|
||||||
|
* @details This source file contains the definition of all the methods for
|
||||||
|
* the class MagneticRZPosGAM (public, protected, and private). Be aware that some
|
||||||
|
* methods, such as those inline could be defined on the header file, instead.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/* Standard header includes */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/* Project header includes */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
#include "AdvancedErrorManagement.h"
|
||||||
|
#include "CLASSMETHODREGISTER.h"
|
||||||
|
|
||||||
|
#include "MagneticRZPosGAM.h"
|
||||||
|
#include "RegisteredMethodsMessageFilter.h"
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/* Static definitions */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
//namespace MARTeIsttok {
|
||||||
|
namespace MARTe {
|
||||||
|
/**
|
||||||
|
* The number of signals
|
||||||
|
*/
|
||||||
|
const uint32 EP_NUM_INPUTS = 4u;
|
||||||
|
const uint32 EP_NUM_OUTPUTS = 2u;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/* Method definitions */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
//namespace MARTeIsttok {
|
||||||
|
MagneticRZPosGAM::MagneticRZPosGAM() :
|
||||||
|
GAM(),
|
||||||
|
MessageI() {
|
||||||
|
gain = 0u;
|
||||||
|
numberOfSamplesAvg = 1u;
|
||||||
|
numberOfInputElements = 0u;
|
||||||
|
|
||||||
|
//outputSignals = NULL_PTR(MARTe::float32 **);
|
||||||
|
/*
|
||||||
|
inputElectricTop = NULL_PTR(MARTe::float32 *);
|
||||||
|
inputElectricInner = NULL_PTR(MARTe::float32 *);
|
||||||
|
inputElectricOuter = NULL_PTR(MARTe::float32 *);
|
||||||
|
inputElectricBottom = NULL_PTR(MARTe::float32 *);
|
||||||
|
*/
|
||||||
|
triggerSdas = NULL_PTR(MARTe::uint32 *);
|
||||||
|
inputSignal = NULL; // NULL_PTR(MARTe::float32*);
|
||||||
|
|
||||||
|
outputEpR = NULL_PTR(MARTe::float32 *);
|
||||||
|
outputEpZ = NULL_PTR(MARTe::float32 *);
|
||||||
|
resetInEachState = false;
|
||||||
|
|
||||||
|
lastInputs = NULL_PTR(MARTe::float32**);
|
||||||
|
lastTriggerSdas = 0u;
|
||||||
|
}
|
||||||
|
|
||||||
|
MagneticRZPosGAM::~MagneticRZPosGAM() {
|
||||||
|
//if (inputSignal != NULL_PTR(MARTe::float32 **)) {
|
||||||
|
// delete[] inputSignal;
|
||||||
|
//}
|
||||||
|
inputSignal = NULL; //NULL_PTR(MARTe::float32*);
|
||||||
|
/*if (outputSignals != NULL_PTR(MARTe::float32 **)) {
|
||||||
|
delete[] outputSignals;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
if (lastInputs != NULL_PTR(MARTe::float32**)) {
|
||||||
|
MARTe::uint32 k;
|
||||||
|
for (k=0u; k < EP_NUM_INPUTS; k++) {
|
||||||
|
if (lastInputs[k] != NULL_PTR(MARTe::float32*)) {
|
||||||
|
delete[] lastInputs[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete[] lastInputs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MagneticRZPosGAM::Initialise(MARTe::StructuredDataI & data) {
|
||||||
|
using namespace MARTe;
|
||||||
|
bool ok = GAM::Initialise(data);
|
||||||
|
if (!ok) {
|
||||||
|
REPORT_ERROR(ErrorManagement::ParametersError, "Could not Initialise the GAM");
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
ok = data.Read("Gain", gain);
|
||||||
|
if (!ok) {
|
||||||
|
REPORT_ERROR(ErrorManagement::ParametersError, "The parameter Gain shall be set");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
REPORT_ERROR(ErrorManagement::Information, "Parameter Gain set to %d", gain);
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
ok = data.Read("NumberOfSamplesAvg", numberOfSamplesAvg);
|
||||||
|
if (!ok) {
|
||||||
|
REPORT_ERROR(ErrorManagement::ParametersError,
|
||||||
|
"The parameter NumberOfSamplesAvg shall be set");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
REPORT_ERROR(ErrorManagement::Information, "Parameter NumberOfSamplesAvg set to %d",
|
||||||
|
numberOfSamplesAvg);
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
uint32 auxResetInEachState = 0u;
|
||||||
|
ok = data.Read("ResetInEachState", auxResetInEachState);
|
||||||
|
if (!ok) {
|
||||||
|
REPORT_ERROR(ErrorManagement::InitialisationError, "Error reading ResetInEachState");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (auxResetInEachState == 1u) {
|
||||||
|
resetInEachState = true;
|
||||||
|
}
|
||||||
|
else if (auxResetInEachState == 0u) {
|
||||||
|
resetInEachState = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ok = false;
|
||||||
|
REPORT_ERROR(ErrorManagement::InitialisationError, "Wrong value for ResetInEachState. Possible values 0 (false) or 1 (true)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MagneticRZPosGAM::Setup() {
|
||||||
|
using namespace MARTe;
|
||||||
|
uint32 numberOfInputSignals = GetNumberOfInputSignals();
|
||||||
|
bool ok = (numberOfInputSignals == 2u);
|
||||||
|
if (!ok) {
|
||||||
|
REPORT_ERROR(ErrorManagement::ParametersError, "The number of input signals shall be equal to 2. numberOfInputSignals = %d ", numberOfInputSignals);
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
|
||||||
|
StreamString inputSignalName;
|
||||||
|
ok = GetSignalName(InputSignals, 0u, inputSignalName);
|
||||||
|
TypeDescriptor inputSignalType = GetSignalType(InputSignals, 0u);
|
||||||
|
ok = (inputSignalType == UnsignedInteger32Bit);
|
||||||
|
if (!ok) {
|
||||||
|
const char8 * const inputSignalTypeStr = TypeDescriptor::GetTypeNameFromTypeDescriptor(inputSignalType);
|
||||||
|
REPORT_ERROR(ErrorManagement::ParametersError,
|
||||||
|
"The type of the input signals shall be uint32. inputSignalType = %s", inputSignalTypeStr);
|
||||||
|
}
|
||||||
|
uint32 numberOfInputSamples = 0u;
|
||||||
|
if (ok) {
|
||||||
|
ok = GetSignalNumberOfSamples(InputSignals, 0u, numberOfInputSamples);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
ok = (numberOfInputSamples == 1u);
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
REPORT_ERROR(ErrorManagement::ParametersError,
|
||||||
|
"The number of input signals samples shall be equal to 1. numberOfInputSamples = %d", numberOfInputSamples);
|
||||||
|
}
|
||||||
|
uint32 numberOfInputDimensions = 0u;
|
||||||
|
if (ok) {
|
||||||
|
ok = GetSignalNumberOfDimensions(InputSignals, 0u, numberOfInputDimensions);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
ok = (numberOfInputDimensions == 0u);
|
||||||
|
if (!ok) {
|
||||||
|
REPORT_ERROR(
|
||||||
|
ErrorManagement::ParametersError,
|
||||||
|
"The number of input signals dimensions shall be equal to 0. numberOfInputDimensions(%s) = %d", inputSignalName.Buffer(), numberOfInputDimensions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
ok = GetSignalNumberOfElements(InputSignals, 0u, numberOfInputElements);
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
ok = (numberOfInputElements == 1u);
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
REPORT_ERROR(ErrorManagement::ParametersError,
|
||||||
|
"The number of input signal elements shall be equal to 1. numberOfInputElements(%s) = %d", inputSignalName.Buffer(), numberOfInputElements);
|
||||||
|
}
|
||||||
|
ok = GetSignalName(InputSignals, 1u, inputSignalName);
|
||||||
|
inputSignalType = GetSignalType(InputSignals, 1u);
|
||||||
|
ok = (inputSignalType == Float32Bit);
|
||||||
|
if (!ok) {
|
||||||
|
const char8 * const inputSignalTypeStr = TypeDescriptor::GetTypeNameFromTypeDescriptor(inputSignalType);
|
||||||
|
REPORT_ERROR(ErrorManagement::ParametersError,
|
||||||
|
"The type of the input signals shall be float32. inputSignalType = %s", inputSignalTypeStr);
|
||||||
|
}
|
||||||
|
numberOfInputSamples = 0u;
|
||||||
|
if (ok) {
|
||||||
|
ok = GetSignalNumberOfSamples(InputSignals, 1u, numberOfInputSamples);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
ok = (numberOfInputSamples == 1u);
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
REPORT_ERROR(ErrorManagement::ParametersError,
|
||||||
|
"The number of input signals samples shall be equal to 1. numberOfInputSamples = %d", numberOfInputSamples);
|
||||||
|
}
|
||||||
|
numberOfInputDimensions = 0u;
|
||||||
|
if (ok) {
|
||||||
|
ok = GetSignalNumberOfDimensions(InputSignals, 1u, numberOfInputDimensions);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
ok = (numberOfInputDimensions == 0u);
|
||||||
|
if (!ok) {
|
||||||
|
REPORT_ERROR(
|
||||||
|
ErrorManagement::ParametersError,
|
||||||
|
"The number of input signals dimensions shall be equal to 0. numberOfInputDimensions(%s) = %d", inputSignalName.Buffer(), numberOfInputDimensions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
ok = GetSignalNumberOfElements(InputSignals, 1u, numberOfInputElements);
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
ok = (numberOfInputElements == 4u);
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
REPORT_ERROR(ErrorManagement::ParametersError,
|
||||||
|
"The number of input signal elements shall be equal to 4. numberOfInputElements(%s) = %d", inputSignalName.Buffer(), numberOfInputElements);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
lastInputs = new float32*[numberOfInputElements];
|
||||||
|
uint32 n;
|
||||||
|
for (n = 0u; n < numberOfInputElements ; n++) {
|
||||||
|
if (numberOfSamplesAvg > 1u) {
|
||||||
|
lastInputs[n] = new float32[numberOfSamplesAvg - 1u];
|
||||||
|
if (lastInputs[n] != NULL_PTR(MARTe::float32*)) {
|
||||||
|
uint32 i;
|
||||||
|
for (i = 0u; i < (numberOfSamplesAvg - 1u); i++) {
|
||||||
|
lastInputs[n][i] = 0.0F;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
triggerSdas = reinterpret_cast<uint32 *>(GetInputSignalMemory(0u));
|
||||||
|
inputSignal = reinterpret_cast<float32 *>(GetInputSignalMemory(1u));
|
||||||
|
/*
|
||||||
|
inputElectricTop = reinterpret_cast<float32 *>(GetInputSignalMemory(0u));
|
||||||
|
inputElectricInner = reinterpret_cast<float32 *>(GetInputSignalMemory(1u));
|
||||||
|
inputElectricOuter = reinterpret_cast<float32 *>(GetInputSignalMemory(2u));
|
||||||
|
inputElectricBottom = reinterpret_cast<float32 *>(GetInputSignalMemory(3u));
|
||||||
|
*/
|
||||||
|
REPORT_ERROR(ErrorManagement::Information, "InputSignals reinterpret_cast OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// OutputSignals
|
||||||
|
uint32 numberOfOutputSignals = GetNumberOfOutputSignals();
|
||||||
|
ok = (numberOfOutputSignals == 2u);
|
||||||
|
if (!ok) {
|
||||||
|
REPORT_ERROR(ErrorManagement::ParametersError, "The number of output signals shall be equal to 2. numberOfOutputSignals = %d ", numberOfOutputSignals);
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
uint32 n;
|
||||||
|
for (n = 0u; (n < numberOfOutputSignals) && (ok); n++) {
|
||||||
|
StreamString outputSignalName;
|
||||||
|
ok = GetSignalName(OutputSignals, n, outputSignalName);
|
||||||
|
TypeDescriptor outputSignalType = GetSignalType(OutputSignals, n);
|
||||||
|
ok = (outputSignalType == Float32Bit);
|
||||||
|
if (!ok) {
|
||||||
|
const char8 * const outputSignalTypeStr = TypeDescriptor::GetTypeNameFromTypeDescriptor(outputSignalType);
|
||||||
|
REPORT_ERROR(ErrorManagement::ParametersError,
|
||||||
|
"The type of the output signals shall be float32. outputSignalType = %s", outputSignalTypeStr);
|
||||||
|
}
|
||||||
|
uint32 numberOfOutputSamples = 0u;
|
||||||
|
if (ok) {
|
||||||
|
ok = GetSignalNumberOfSamples(OutputSignals, n, numberOfOutputSamples);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
ok = (numberOfOutputSamples == 1u);
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
REPORT_ERROR(ErrorManagement::ParametersError,
|
||||||
|
"The number of output signals samples shall be equal to 1. numberOfOutputSamples = %d", numberOfOutputSamples);
|
||||||
|
}
|
||||||
|
uint32 numberOfOutputDimensions = 0u;
|
||||||
|
if (ok) {
|
||||||
|
ok = GetSignalNumberOfDimensions(OutputSignals, n, numberOfOutputDimensions);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
ok = (numberOfOutputDimensions == 0u);
|
||||||
|
if (!ok) {
|
||||||
|
REPORT_ERROR(ErrorManagement::ParametersError,
|
||||||
|
"The number of output signals dimensions shall be equal to 0. numberOfOutputDimensions (%s) = %d", outputSignalName.Buffer(), numberOfOutputDimensions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uint32 numberOfOutputElements = 0u;
|
||||||
|
if (ok) {
|
||||||
|
ok = GetSignalNumberOfElements(OutputSignals, n, numberOfOutputElements);
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
ok = (numberOfOutputElements == 1u);
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
REPORT_ERROR(ErrorManagement::ParametersError,
|
||||||
|
"The number of output signals elements shall be equal to 1. (%s) numberOfOutputElements = %d", outputSignalName.Buffer(), numberOfOutputElements);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
outputEpR = reinterpret_cast<float32 *>(GetOutputSignalMemory(0u));
|
||||||
|
outputEpZ = reinterpret_cast<float32 *>(GetOutputSignalMemory(1u));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Install message filter
|
||||||
|
ReferenceT<RegisteredMethodsMessageFilter> registeredMethodsMessageFilter("RegisteredMethodsMessageFilter");
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
ok = registeredMethodsMessageFilter.IsValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
registeredMethodsMessageFilter->SetDestination(this);
|
||||||
|
ok = InstallMessageFilter(registeredMethodsMessageFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MagneticRZPosGAM::Execute() {
|
||||||
|
/* inputElectricOuter - inputElectricInner */
|
||||||
|
*outputEpR = (inputSignal[2] - inputOffset[2]) -
|
||||||
|
(inputSignal[1] - inputOffset[1]);
|
||||||
|
*outputEpZ = inputSignal[0] - inputOffset[0];
|
||||||
|
//*outputEpZ = inputSignal[0] - inputSignal[3];
|
||||||
|
|
||||||
|
/* update the last value arrays */
|
||||||
|
for (MARTe::uint32 i = 0u; i < numberOfInputElements; i++) {
|
||||||
|
|
||||||
|
if (numberOfSamplesAvg > 2u) {
|
||||||
|
for (MARTe::uint32 k = (numberOfSamplesAvg - 1u); k > 0u; k--) {
|
||||||
|
lastInputs[i][k] = lastInputs[i][k - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (numberOfSamplesAvg > 1u) {
|
||||||
|
lastInputs[i][0] = inputSignal[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if (numberOfSamplesAvg > 1u) {
|
||||||
|
lastInputs[0][0] = *inputElectricTop;
|
||||||
|
lastInputs[1][0] = *inputElectricInner;
|
||||||
|
lastInputs[2][0] = *inputElectricOuter;
|
||||||
|
lastInputs[3][0] = *inputElectricBottom;
|
||||||
|
|
||||||
|
lastInputs[i][0] = input[i][numberOfSamples - 1u];
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Should use a MARTe2 Message.
|
||||||
|
* Here for Sdas recorded signel with Trigger pseudo-signal
|
||||||
|
* */
|
||||||
|
if ((lastTriggerSdas == 0u) && (*triggerSdas == 1u)) {
|
||||||
|
CalcOffSets();
|
||||||
|
}
|
||||||
|
lastTriggerSdas = *triggerSdas;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MagneticRZPosGAM::PrepareNextState(const char8 * const currentStateName,
|
||||||
|
const char8 * const nextStateName) {
|
||||||
|
bool ret = true;
|
||||||
|
|
||||||
|
if (resetInEachState) {
|
||||||
|
lastStateExecuted = nextStateName;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
bool cond1 = (stateVector.GetDataPointer() != NULL_PTR(float64 **));
|
||||||
|
bool cond2 = (derivativeStateVector.GetDataPointer() != NULL_PTR(float64 **));
|
||||||
|
if (cond1 && cond2) {
|
||||||
|
for (uint32 i = 0u; i < sizeStateVector; i++) {
|
||||||
|
stateVector(i, 0u) = 0.0;
|
||||||
|
derivativeStateVector(i, 0u) = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
REPORT_ERROR(ErrorManagement::ParametersError, "stateVector or derivativeStateVector = NULL ");
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//If the currentStateName and lastStateExecuted are different-> rest values
|
||||||
|
if (lastStateExecuted != currentStateName) {
|
||||||
|
bool cond1 = (stateVector.GetDataPointer() != NULL_PTR(float64 **));
|
||||||
|
bool cond2 = (derivativeStateVector.GetDataPointer() != NULL_PTR(float64 **));
|
||||||
|
if (cond1 && cond2) {
|
||||||
|
for (uint32 i = 0u; i < sizeStateVector; i++) {
|
||||||
|
stateVector(i, 0u) = 0.0;
|
||||||
|
derivativeStateVector(i, 0u) = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
REPORT_ERROR(ErrorManagement::ParametersError, "stateVector or derivativeStateVector = NULL ");
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastStateExecuted = nextStateName;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool MagneticRZPosGAM::ExportData(MARTe::StructuredDataI & data) {
|
||||||
|
using namespace MARTe;
|
||||||
|
bool ok = GAM::ExportData(data);
|
||||||
|
if (ok) {
|
||||||
|
ok = data.CreateRelative("Parameters");
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
ok = data.Write("Gain", gain);
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
ok = data.MoveToAncestor(1u);
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorManagement::ErrorType MagneticRZPosGAM::CalcOffSets() {
|
||||||
|
|
||||||
|
ErrorManagement::ErrorType ret = MARTe::ErrorManagement::NoError;
|
||||||
|
REPORT_ERROR(ErrorManagement::Information,
|
||||||
|
"CalcOffSets. Inputs:%f, %f, %f, %f.",
|
||||||
|
inputSignal[0],
|
||||||
|
inputSignal[1],
|
||||||
|
inputSignal[2],
|
||||||
|
inputSignal[3]);
|
||||||
|
if (numberOfSamplesAvg > 1u) {
|
||||||
|
for (uint32 i = 0u; i < EP_NUM_INPUTS; i++) {
|
||||||
|
inputOffset[i] = 0.0f;
|
||||||
|
for (uint32 k = 0 ; k < numberOfSamplesAvg; k++) {
|
||||||
|
inputOffset[i] += lastInputs[i][k];
|
||||||
|
}
|
||||||
|
inputOffset[i] /= numberOfSamplesAvg;
|
||||||
|
}
|
||||||
|
REPORT_ERROR(ErrorManagement::Information,
|
||||||
|
"CalcOffSets. Offset:%f, %f, %f, %f.",
|
||||||
|
inputOffset[0],
|
||||||
|
inputOffset[1],
|
||||||
|
inputOffset[2],
|
||||||
|
inputOffset[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CLASS_REGISTER(MagneticRZPosGAM, "0.1")
|
||||||
|
|
||||||
|
CLASS_METHOD_REGISTER(MagneticRZPosGAM, CalcOffSets)
|
||||||
|
|
||||||
|
} /* namespace MARTeIsttok */
|
||||||
|
|
||||||
|
// vim: syntax=cpp ts=4 sw=4 sts=4 sr et
|
||||||
203
GAMs/MagneticRZPosGAM/MagneticRZPosGAM.h
Normal file
203
GAMs/MagneticRZPosGAM/MagneticRZPosGAM.h
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
/**
|
||||||
|
* @file MagneticRZPosGAM.h
|
||||||
|
* @brief Header file for class MagneticRZPosGAM
|
||||||
|
* @date 06/04/2018
|
||||||
|
* @author Andre Neto
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2015 F4E | European Joint Undertaking for ITER and
|
||||||
|
* the Development of Fusion Energy ('Fusion for Energy').
|
||||||
|
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
|
||||||
|
* by the European Commission - subsequent versions of the EUPL (the "Licence")
|
||||||
|
* You may not use this work except in compliance with the Licence.
|
||||||
|
* You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
|
||||||
|
*
|
||||||
|
* @warning Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the Licence is distributed on an "AS IS"
|
||||||
|
* basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||||
|
* or implied. See the Licence permissions and limitations under the Licence.
|
||||||
|
|
||||||
|
* @details This header file contains the declaration of the class MagneticRZPosGAM
|
||||||
|
* with all of its public, protected and private members. It may also include
|
||||||
|
* definitions for inline methods which need to be visible to the compiler.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MAGNETICRZPOSGAM_H_
|
||||||
|
#define MAGNETICRZPOSGAM_H_
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/* Standard header includes */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/* Project header includes */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "GAM.h"
|
||||||
|
#include "MessageI.h"
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/* Class declaration */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
namespace MARTe {
|
||||||
|
/**
|
||||||
|
* @brief An example of a GAM which has fixed inputs and outputs.
|
||||||
|
*
|
||||||
|
* @details This GAM multiplies the input signal by a Gain.
|
||||||
|
* The configuration syntax is (names and types are only given as an example):
|
||||||
|
*
|
||||||
|
* +GAM_MagneticRZPos = {
|
||||||
|
* Class = MagneticRZPosGAM
|
||||||
|
* Gain = 5 //Compulsory
|
||||||
|
* NumberOfSamplesAvg = 4 //Compulsory
|
||||||
|
* ResetInEachState = 0//Compulsory. 1--> reset in each state, 0--> reset if the previous state is different from the next state
|
||||||
|
|
||||||
|
* InputSignals = {
|
||||||
|
* Signal1 = {
|
||||||
|
* DataSource = "DDB1"
|
||||||
|
* Type = uint32
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* OutputSignals = {
|
||||||
|
* Signal1 = {
|
||||||
|
* DataSource = "DDB1"
|
||||||
|
* Type = uint32
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
class MagneticRZPosGAM : public MARTe::GAM, public MARTe::MessageI {
|
||||||
|
public:
|
||||||
|
CLASS_REGISTER_DECLARATION()
|
||||||
|
/**
|
||||||
|
* @brief Constructor. NOOP.
|
||||||
|
*/
|
||||||
|
MagneticRZPosGAM();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destructor. NOOP.
|
||||||
|
*/
|
||||||
|
virtual ~MagneticRZPosGAM();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reads the Gain from the configuration file.
|
||||||
|
* @param[in] data see GAM::Initialise. The parameter Gain shall exist and will be read as an uint32.
|
||||||
|
* @return true if the parameter Gain can be read.
|
||||||
|
*/
|
||||||
|
virtual bool Initialise(MARTe::StructuredDataI & data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Verifies correctness of the GAM configuration.
|
||||||
|
* @details Checks that the number of input signals is equal to the number of output signals is equal to one and that the same type is used.
|
||||||
|
* @return true if the pre-conditions are met.
|
||||||
|
* @pre
|
||||||
|
* SetConfiguredDatabase() &&
|
||||||
|
* GetNumberOfInputSignals() == 4
|
||||||
|
* GetNumberOfInputSignals() ==
|
||||||
|
* GetSignalType(InputSignals, 0) == GetSignalType(OutputSignals, 0) == uint32 &&
|
||||||
|
*/
|
||||||
|
virtual bool Setup();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Multiplies the input signal by the Gain.
|
||||||
|
* @return true.
|
||||||
|
*/
|
||||||
|
virtual bool Execute();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reset the states if required.
|
||||||
|
* @details This functions has two operations modes:
|
||||||
|
* <ul>
|
||||||
|
* <li> Reset the GAM states every time the state changes.
|
||||||
|
* </li>
|
||||||
|
* <li> Reset the GAM if it was not executed in the previous state. e.i. if the GAM goes from
|
||||||
|
* "A" to "B" and then from "B" to "C" it will not be reset. In the other hand if the GAM goes
|
||||||
|
* from "A" to "B" and then from "C" to "D" the GAM will be reset the states.
|
||||||
|
* </li>
|
||||||
|
* </ul>
|
||||||
|
* @param[in] currentStateName indicates the current state.
|
||||||
|
* @param[in] nextStateName indicates the next state.
|
||||||
|
* @return true if the state vectors are not NULL.
|
||||||
|
*/
|
||||||
|
virtual bool PrepareNextState(const char8 * const currentStateName,
|
||||||
|
const char8 * const nextStateName);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CalcOffSets method.
|
||||||
|
* @details The method is registered as a messageable function.
|
||||||
|
* @return ErrorManagement::NoError if the pre-conditions are met, ErrorManagement::ParametersError
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
|
||||||
|
MARTe::ErrorManagement::ErrorType CalcOffSets();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Export information about the component
|
||||||
|
*/
|
||||||
|
virtual bool ExportData(MARTe::StructuredDataI & data);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The configured gain.
|
||||||
|
*/
|
||||||
|
MARTe::uint32 gain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The configured numberOfSamplesAvg.
|
||||||
|
*/
|
||||||
|
uint32 numberOfSamplesAvg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The input signals
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint32 *triggerSdas;
|
||||||
|
/**
|
||||||
|
* The input Electric Probes signals
|
||||||
|
*/
|
||||||
|
float32 *inputSignal;
|
||||||
|
|
||||||
|
/*
|
||||||
|
MARTe::float32 *inputElectricTop;
|
||||||
|
MARTe::float32 *inputElectricInner;
|
||||||
|
MARTe::float32 *inputElectricOuter;
|
||||||
|
MARTe::float32 *inputElectricBottom;
|
||||||
|
*/
|
||||||
|
uint32 numberOfInputElements;
|
||||||
|
|
||||||
|
float32 inputOffset[4];
|
||||||
|
|
||||||
|
MARTe::float32 **lastInputs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The output signals
|
||||||
|
*/
|
||||||
|
// MARTe::float32 **outputSignals;
|
||||||
|
float32 *outputEpR;
|
||||||
|
float32 *outputEpZ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates the behaviour of the reset when MARTe changes the state
|
||||||
|
*/
|
||||||
|
bool resetInEachState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remember the last executed state.
|
||||||
|
*/
|
||||||
|
StreamString lastStateExecuted;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag to detect SDAS Trigger Edge.
|
||||||
|
*/
|
||||||
|
uint32 lastTriggerSdas;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/* Inline method definitions */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#endif /* MAGNETICRZPOSGAM_H_ */
|
||||||
|
|
||||||
|
// vim: syntax=cpp ts=4 sw=4 sts=4 sr et
|
||||||
28
GAMs/MagneticRZPosGAM/Makefile.gcc
Normal file
28
GAMs/MagneticRZPosGAM/Makefile.gcc
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#############################################################
|
||||||
|
#
|
||||||
|
# Copyright 2015 F4E | European Joint Undertaking for ITER
|
||||||
|
# and the Development of Fusion Energy ('Fusion for Energy')
|
||||||
|
#
|
||||||
|
# Licensed under the EUPL, Version 1.1 or - as soon they
|
||||||
|
# will be approved by the European Commission - subsequent
|
||||||
|
# versions of the EUPL (the "Licence");
|
||||||
|
# You may not use this work except in compliance with the
|
||||||
|
# Licence.
|
||||||
|
# You may obtain a copy of the Licence at:
|
||||||
|
#
|
||||||
|
# http://ec.europa.eu/idabc/eupl
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in
|
||||||
|
# writing, software distributed under the Licence is
|
||||||
|
# distributed on an "AS IS" basis,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||||
|
# express or implied.
|
||||||
|
# See the Licence for the specific language governing
|
||||||
|
# permissions and limitations under the Licence.
|
||||||
|
#
|
||||||
|
#############################################################
|
||||||
|
|
||||||
|
|
||||||
|
include Makefile.inc
|
||||||
|
|
||||||
|
LIBRARIES += -L$(MDSPLUS_DIR)/lib64 -L$(MDSPLUS_DIR)/lib -lMdsObjectsCppShr
|
||||||
56
GAMs/MagneticRZPosGAM/Makefile.inc
Normal file
56
GAMs/MagneticRZPosGAM/Makefile.inc
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#############################################################
|
||||||
|
#
|
||||||
|
# Copyright 2015 F4E | European Joint Undertaking for ITER
|
||||||
|
# and the Development of Fusion Energy ('Fusion for Energy')
|
||||||
|
#
|
||||||
|
# Licensed under the EUPL, Version 1.1 or - as soon they
|
||||||
|
# will be approved by the European Commission - subsequent
|
||||||
|
# versions of the EUPL (the "Licence");
|
||||||
|
# You may not use this work except in compliance with the
|
||||||
|
# Licence.
|
||||||
|
# You may obtain a copy of the Licence at:
|
||||||
|
#
|
||||||
|
# http://ec.europa.eu/idabc/eupl
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in
|
||||||
|
# writing, software distributed under the Licence is
|
||||||
|
# distributed on an "AS IS" basis,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||||
|
# express or implied.
|
||||||
|
# See the Licence for the specific language governing
|
||||||
|
# permissions and limitations under the Licence.
|
||||||
|
#
|
||||||
|
#############################################################
|
||||||
|
|
||||||
|
OBJSX=MagneticRZPosGAM.x
|
||||||
|
|
||||||
|
PACKAGE=Components/GAMs
|
||||||
|
|
||||||
|
ROOT_DIR=../../
|
||||||
|
|
||||||
|
MAKEDEFAULTDIR=$(MARTe2_DIR)/MakeDefaults
|
||||||
|
|
||||||
|
include $(MAKEDEFAULTDIR)/MakeStdLibDefs.$(TARGET)
|
||||||
|
|
||||||
|
INCLUDES += -I.
|
||||||
|
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L0Types
|
||||||
|
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L1Portability
|
||||||
|
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L2Objects
|
||||||
|
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L3Streams
|
||||||
|
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L4Messages
|
||||||
|
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L4Configuration
|
||||||
|
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L5GAMs
|
||||||
|
INCLUDES += -I$(MARTe2_DIR)/Source/Core/Scheduler/L1Portability
|
||||||
|
INCLUDES += -I$(MARTe2_DIR)/Source/Core/Scheduler/L3Services
|
||||||
|
INCLUDES += -I$(MARTe2_DIR)/Source/Core/Scheduler/L4Messages
|
||||||
|
INCLUDES += -I$(MARTe2_DIR)/Source/Core/Scheduler/L5GAMs
|
||||||
|
|
||||||
|
all: $(OBJS) \
|
||||||
|
$(BUILD_DIR)/MagneticRZPosGAM$(LIBEXT) \
|
||||||
|
$(BUILD_DIR)/MagneticRZPosGAM$(DLLEXT)
|
||||||
|
echo $(OBJS)
|
||||||
|
|
||||||
|
include depends.$(TARGET)
|
||||||
|
|
||||||
|
include $(MAKEDEFAULTDIR)/MakeStdLibRules.$(TARGET)
|
||||||
|
|
||||||
Reference in New Issue
Block a user