/*---------------------------------------------------------------------------*/ /* Standard header includes */ /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ /* Project header includes */ /*---------------------------------------------------------------------------*/ #include "AdvancedErrorManagement.h" #include "CompilerTypes.h" #include "DataSourceI.h" #include "ScaleGAM.h" #include "TypeDescriptor.h" /*---------------------------------------------------------------------------*/ /* Static definitions */ /*---------------------------------------------------------------------------*/ namespace MARTe {} // namespace MARTe /*---------------------------------------------------------------------------*/ /* Method definitions */ /*---------------------------------------------------------------------------*/ namespace MARTe { const MARTe::uint32 NUM_OUTPUTS = 1u; const MARTe::uint32 NUM_PARAMS = 0u; ScaleGAM::ScaleGAM() : GAM(), MessageI() { factors = NULL_PTR(float32 *); inputs = NULL_PTR(float32 *); outputs = NULL_PTR(float32 *); } ScaleGAM::~ScaleGAM() { if (factors != NULL_PTR(float32 *)) { delete[] factors; } } bool ScaleGAM::Setup() { bool ok = numberOfInputSignals == numberOfOutputSignals; for (uint32 i = 0; i < numberOfInputSignals && ok; i++) { if (GetSignalType(InputSignals, i) != Float32Bit) { REPORT_ERROR(ErrorManagement::InitialisationError, "Input %d should be float32", i); ok = false; } if (GetSignalType(OutputSignals, i) != Float32Bit) { REPORT_ERROR(ErrorManagement::InitialisationError, "Output %d should be float32", i); ok = false; } } inputs = (float32 *)inputSignalsMemory; outputs = (float32 *)outputSignalsMemory; return ok; } bool ScaleGAM::Initialise(StructuredDataI &data) { bool ret = GAM::Initialise(data); uint32 nin = 0; if (ret && data.MoveRelative("InputSignals")) { nin = data.GetNumberOfChildren(); if (nin == 0) { REPORT_ERROR(ErrorManagement::InitialisationError, "Number of inputs should > 0"); ret = false; } else { factors = new float32[nin]; } for (uint32 i = 0; i < nin && ret; i++) { ret = data.MoveToChild(i); if (!ret) { REPORT_ERROR(ErrorManagement::InitialisationError, "Impossible to move to children %d", i); data.MoveToAncestor(1u); break; } ret = data.Read("Factor", factors[i]); if (!ret) { REPORT_ERROR(ErrorManagement::InitialisationError, "Impossible to move to read `Factor` for signal n %d ", i); data.MoveToAncestor(1u); break; } } ret = data.MoveToAncestor(1u) & ret; } else { REPORT_ERROR(ErrorManagement::InitialisationError, "No input signals found"); ret &= false; } if (ret && data.MoveRelative("OutputSignals")) { uint32 nout = data.GetNumberOfChildren(); if (nout != nin) { REPORT_ERROR( ErrorManagement::InitialisationError, "Number of Outputs should be exactly equal to number of outputs", NUM_OUTPUTS); ret = false; } ret = data.MoveToAncestor(1u); } else { REPORT_ERROR(ErrorManagement::InitialisationError, "No output signals, exactly %d outputs are needed", NUM_OUTPUTS); ret = false; } REPORT_ERROR(ret ? ErrorManagement::Information : ErrorManagement::InitialisationError, ret ? "%s Initialised" : "%s Failed to initialise", GetName()); return ret; } bool ScaleGAM::Execute() { for (uint32 i = 0; i < numberOfInputSignals; i++) { outputs[i] = inputs[i] / factors[i]; } return true; } CLASS_REGISTER(ScaleGAM, "1.0") } /* namespace MARTe */