Running file read

Signed-off-by: Bernardo Carvalho <bernardo.carvalho@tecnico.ulisboa.pt>
This commit is contained in:
2024-11-23 22:39:17 +00:00
parent 592d87e887
commit a6f0076ec2
2 changed files with 321 additions and 94 deletions

View File

@@ -29,31 +29,46 @@
/* Project header includes */ /* Project header includes */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#include "AdvancedErrorManagement.h" #include "AdvancedErrorManagement.h"
#include "CLASSMETHODREGISTER.h"
#include "ElectricProbesGAM.h" #include "ElectricProbesGAM.h"
#include "RegisteredMethodsMessageFilter.h"
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Static definitions */ /* Static definitions */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
//namespace MARTeIsttok {
namespace MARTe {
/**
* The number of signals
*/
const uint32 EP_NUM_INPUTS = 4u;
const uint32 EP_NUM_OUTPUTS = 2u;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Method definitions */ /* Method definitions */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
namespace MARTeIsttok { //namespace MARTeIsttok {
ElectricProbesGAM::ElectricProbesGAM() : ElectricProbesGAM::ElectricProbesGAM() :
GAM(), GAM(),
MessageI() { MessageI() {
gain = 0u; gain = 0u;
//inputSignals = NULL_PTR(MARTe::float32 **); numberOfSamplesAvg = 1u;
//outputSignals = NULL_PTR(MARTe::float32 **); //outputSignals = NULL_PTR(MARTe::float32 **);
// outputSignal1 = NULL;
inputElectricTop = NULL_PTR(MARTe::float32 *); inputElectricTop = NULL_PTR(MARTe::float32 *);
inputElectricInner = NULL_PTR(MARTe::float32 *); inputElectricInner = NULL_PTR(MARTe::float32 *);
inputElectricOuter = NULL_PTR(MARTe::float32 *); inputElectricOuter = NULL_PTR(MARTe::float32 *);
inputElectricBottom = NULL_PTR(MARTe::float32 *); inputElectricBottom = NULL_PTR(MARTe::float32 *);
lastInputs = NULL_PTR(MARTe::float32**);
outputEpR = NULL_PTR(MARTe::float32 *); outputEpR = NULL_PTR(MARTe::float32 *);
outputEpZ = NULL_PTR(MARTe::float32 *); outputEpZ = NULL_PTR(MARTe::float32 *);
resetInEachState = false;
} }
ElectricProbesGAM::~ElectricProbesGAM() { ElectricProbesGAM::~ElectricProbesGAM() {
@@ -64,6 +79,22 @@ namespace MARTeIsttok {
delete[] outputSignals; 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;
}
/*
for (k=0u; k < EP_NUM_INPUTS; k++) {
if(lastInputs[k] != NULL_PTR(MARTe::float32 *)) {
delete [] lastInputs[k];
}
}
*/
} }
bool ElectricProbesGAM::Initialise(MARTe::StructuredDataI & data) { bool ElectricProbesGAM::Initialise(MARTe::StructuredDataI & data) {
@@ -81,6 +112,37 @@ namespace MARTeIsttok {
if (ok) { if (ok) {
REPORT_ERROR(ErrorManagement::Information, "Parameter Gain set to %d", gain); 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; return ok;
} }
@@ -93,7 +155,22 @@ namespace MARTeIsttok {
} }
if (ok) { if (ok) {
lastInputs = new float32*[numberOfInputSignals];
uint32 n; uint32 n;
if (lastInputs != NULL_PTR(MARTe::float32**)) {
for (n = 0u; n < numberOfInputSignals ; 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;
}
}
}
}
}
for (n = 0u; (n < numberOfInputSignals) && (ok); n++) { for (n = 0u; (n < numberOfInputSignals) && (ok); n++) {
StreamString inputSignalName; StreamString inputSignalName;
ok = GetSignalName(InputSignals, n, inputSignalName); ok = GetSignalName(InputSignals, n, inputSignalName);
@@ -155,6 +232,7 @@ namespace MARTeIsttok {
REPORT_ERROR(ErrorManagement::Information, "InputSignals reinterpret_cast OK"); REPORT_ERROR(ErrorManagement::Information, "InputSignals reinterpret_cast OK");
} }
} }
// OutputSignals // OutputSignals
@@ -217,6 +295,19 @@ namespace MARTeIsttok {
outputEpZ = reinterpret_cast<float32 *>(GetOutputSignalMemory(1u)); 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; return ok;
} }
@@ -225,12 +316,75 @@ namespace MARTeIsttok {
//*outputSignal = *inputSignal; //*outputSignal = *inputSignal;
*outputEpR = 4.3; *outputEpR = 4.3;
// *outputEpZ = 3.4; // *outputEpZ = 3.4;
*outputEpZ = *inputElectricTop; *outputEpZ = *inputElectricTop - *inputElectricOuter;
//*outputSignal1 = *inputSignals[0]; // - *inputSignals[1]; //*outputSignal1 = *inputSignals[0]; // - *inputSignals[1];
//*outputSignal1 = *inputSignals[0] - *inputSignals[1]; //*outputSignal1 = *inputSignals[0] - *inputSignals[1];
//update the last values
for (MARTe::uint32 i = 0u; i < EP_NUM_INPUTS; i++) {
if (numberOfSamplesAvg > 2u) {
/*lint -e{9117} implicit conversion is safe*/
for (MARTe::uint32 k = (numberOfSamplesAvg - 1u); k > 0u; k--) {
lastInputs[i][k] = lastInputs[i][k - 1];
}
}
}
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];
}
return true; return true;
} }
bool ElectricProbesGAM::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 ElectricProbesGAM::ExportData(MARTe::StructuredDataI & data) { bool ElectricProbesGAM::ExportData(MARTe::StructuredDataI & data) {
using namespace MARTe; using namespace MARTe;
@@ -247,9 +401,32 @@ namespace MARTeIsttok {
return ok; return ok;
} }
CLASS_REGISTER(ElectricProbesGAM, "1.0") ErrorManagement::ErrorType ElectricProbesGAM::CalcOffSets() {
//CLASS_METHOD_REGISTER(AtcaIopConfig, WriteEoWo)
} ErrorManagement::ErrorType ret = MARTe::ErrorManagement::NoError;
REPORT_ERROR(ErrorManagement::Information,
"CalcOffSets. numberOfSamplesAvg: %d!", numberOfSamplesAvg);
if (numberOfSamplesAvg > 1u) {
for (uint32 i = 0u; i < EP_NUM_INPUTS; i++) {
inputOffsets[i] = 0.0f;
for (uint32 k = 0 ; k < numberOfSamplesAvg; k++) {
inputOffsets[i] += lastInputs[i][k];
}
inputOffsets[i] /= numberOfSamplesAvg;
REPORT_ERROR(ErrorManagement::Information,
"CalcOffSets. Offset:%d= %f!", i, inputOffsets[i]);
}
}
return ret;
}
CLASS_REGISTER(ElectricProbesGAM, "1.0")
// CLASS_METHOD_REGISTER(ElectricProbesGAM, ElectricProbesGAM::CalcOffSets)
CLASS_METHOD_REGISTER(ElectricProbesGAM, CalcOffSets)
} /* namespace MARTeIsttok */
// vim: syntax=cpp ts=4 sw=4 sts=4 sr et // vim: syntax=cpp ts=4 sw=4 sts=4 sr et

View File

@@ -38,8 +38,9 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Class declaration */ /* Class declaration */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
namespace MARTeIsttok { //namespace MARTeIsttok {
/** namespace MARTe {
/**
* @brief An example of a GAM which has fixed inputs and outputs. * @brief An example of a GAM which has fixed inputs and outputs.
* *
* @details This GAM multiplies the input signal by a Gain. * @details This GAM multiplies the input signal by a Gain.
@@ -48,6 +49,9 @@ namespace MARTeIsttok {
* +GAMElectricProbes = { * +GAMElectricProbes = {
* Class = ElectricProbesGAM * Class = ElectricProbesGAM
* Gain = 5 //Compulsory * 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 = { * InputSignals = {
* Signal1 = { * Signal1 = {
* DataSource = "DDB1" * DataSource = "DDB1"
@@ -62,8 +66,8 @@ namespace MARTeIsttok {
* } * }
* } * }
*/ */
class ElectricProbesGAM : public MARTe::GAM, public MARTe::MessageI { class ElectricProbesGAM : public MARTe::GAM, public MARTe::MessageI {
public: public:
CLASS_REGISTER_DECLARATION() CLASS_REGISTER_DECLARATION()
/** /**
* @brief Constructor. NOOP. * @brief Constructor. NOOP.
@@ -88,11 +92,9 @@ public:
* @return true if the pre-conditions are met. * @return true if the pre-conditions are met.
* @pre * @pre
* SetConfiguredDatabase() && * SetConfiguredDatabase() &&
* GetNumberOfInputSignals() == GetNumberOfOutputSignals() == 1 && * GetNumberOfInputSignals() == 4
* GetNumberOfInputSignals() ==
* GetSignalType(InputSignals, 0) == GetSignalType(OutputSignals, 0) == uint32 && * GetSignalType(InputSignals, 0) == GetSignalType(OutputSignals, 0) == uint32 &&
* GetSignalNumberOfDimensions(InputSignals, 0) == GetSignalNumberOfDimensions(OutputSignals, 0) == 0 &&
* GetSignalNumberOfSamples(InputSignals, 0) == GetSignalNumberOfSamples(OutputSignals, 0) == 1 &&
* GetSignalNumberOfElements(InputSignals, 0) == GetSignalNumberOfElements(OutputSignals, 0) == 1
*/ */
virtual bool Setup(); virtual bool Setup();
@@ -102,37 +104,84 @@ public:
*/ */
virtual bool Execute(); 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 * @brief Export information about the component
*/ */
virtual bool ExportData(MARTe::StructuredDataI & data); virtual bool ExportData(MARTe::StructuredDataI & data);
private: private:
/**
* The configured gain.
*/
MARTe::uint32 gain;
/**
* The configured numberOfSamplesAvg.
*/
uint32 numberOfSamplesAvg;
/** /**
* The input signals * The input signals
*/ */
// MARTe::float32 **inputSignals;
MARTe::float32 *inputElectricTop; MARTe::float32 *inputElectricTop;
MARTe::float32 *inputElectricInner; MARTe::float32 *inputElectricInner;
MARTe::float32 *inputElectricOuter; MARTe::float32 *inputElectricOuter;
MARTe::float32 *inputElectricBottom; MARTe::float32 *inputElectricBottom;
MARTe::float32 inputOffsets[4];
MARTe::float32 **lastInputs;
/** /**
* The output signals * The output signals
*/ */
// MARTe::float32 **outputSignals; // MARTe::float32 **outputSignals;
//MARTe::float32 *outputSignal1; //MARTe::float32 *outputSignal1;
MARTe::float32 *outputEpR; float32 *outputEpR;
MARTe::float32 *outputEpZ; float32 *outputEpZ;
/** /**
* The configured gain. * Indicates the behaviour of the reset when MARTe changes the state
*/ */
MARTe::uint32 gain; bool resetInEachState;
};
/**
* Remember the last executed state.
*/
StreamString lastStateExecuted;
};
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Inline method definitions */ /* Inline method definitions */
@@ -140,3 +189,4 @@ private:
#endif /* ELECTRICPROBESGAM_H_ */ #endif /* ELECTRICPROBESGAM_H_ */
// vim: syntax=cpp ts=4 sw=4 sts=4 sr et