Cleaned up GAMS and duplicated code

This commit is contained in:
Martino Ferrari
2026-02-05 12:09:34 +01:00
parent 084b18d095
commit d18a573a5a
94 changed files with 667 additions and 12021 deletions

View File

@@ -17,7 +17,8 @@
* 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 JAConditionalSignalUpdateGAM (public, protected, and private). Be aware that some
* the class JAConditionalSignalUpdateGAM (public, protected, and private). Be
aware that some
* methods, such as those inline could be defined on the header file, instead.
*/
@@ -28,8 +29,11 @@
/*---------------------------------------------------------------------------*/
/* Project header includes */
/*---------------------------------------------------------------------------*/
#include "JAConditionalSignalUpdateGAM.h"
#include "AdvancedErrorManagement.h"
#include "Architecture/x86_gcc/CompilerTypes.h"
#include "ErrorType.h"
#include "JAConditionalSignalUpdateGAM.h"
#include "TypeDescriptor.h"
/*---------------------------------------------------------------------------*/
/* Static definitions */
@@ -39,271 +43,269 @@
/* Method definitions */
/*---------------------------------------------------------------------------*/
bool parse_comparator(const MARTe::StreamString &str,
JAConditionalSignalUpdateGAM::ComparisonMode &op) {
if (str == "EQUALS") {
op = JAConditionalSignalUpdateGAM::Equals;
return true;
}
if (str == "NOT") {
op = JAConditionalSignalUpdateGAM::Not;
return true;
}
if (str == "GREATER") {
op = JAConditionalSignalUpdateGAM::Greater;
return true;
}
if (str == "EQUALS_OR_GREATER") {
op = JAConditionalSignalUpdateGAM::EqualsOrGreater;
return true;
}
if (str == "LESS") {
op = JAConditionalSignalUpdateGAM::Less;
return true;
}
if (str == "EQUALS_OR_LESS") {
op = JAConditionalSignalUpdateGAM::EqualsOrLess;
return true;
}
return false;
}
JAConditionalSignalUpdateGAM::JAConditionalSignalUpdateGAM() {
inputSignals = NULL_PTR(void **);
inputSignalTypes = NULL_PTR(MARTe::TypeDescriptor *);
values = NULL_PTR(MARTe::uint32 *);
valuesCount = 0u;
outputSignals = NULL_PTR(MARTe::uint32 **);
defaultValues = NULL_PTR(MARTe::uint32 **);
needsReset = false;
expectedValues = NULL_PTR(MARTe::uint32 *);
expectedValuesCount = 0u;
operation = And;
comparators = NULL_PTR(ComparisonMode *);
inputSignals = NULL_PTR(void **);
inputSignalTypes = NULL_PTR(MARTe::TypeDescriptor *);
comparators = NULL_PTR(comparator_t *);
outputSignals = NULL_PTR(MARTe::uint32 **);
outputs = NULL_PTR(output_t *);
needsReset = false;
operation = And;
}
JAConditionalSignalUpdateGAM::~JAConditionalSignalUpdateGAM() {
if (outputSignals != NULL_PTR(MARTe::uint32 **)) {
delete[] outputSignals;
}
if (inputSignals != NULL_PTR(void **)) {
delete[] inputSignals;
}
if (inputSignalTypes != NULL_PTR(MARTe::TypeDescriptor *)) {
delete[] inputSignalTypes;
}
if (values != NULL_PTR(MARTe::uint32 *)) {
delete[] values;
}
if (comparators != NULL_PTR(ComparisonMode *)) {
delete[] comparators;
}
if (defaultValues != NULL_PTR(MARTe::uint32 **)) {
delete[] defaultValues;
}
if (outputSignals != NULL_PTR(MARTe::uint32 **)) {
delete[] outputSignals;
}
if (inputSignals != NULL_PTR(void **)) {
delete[] inputSignals;
}
if (inputSignalTypes != NULL_PTR(MARTe::TypeDescriptor *)) {
delete[] inputSignalTypes;
}
if (outputs != NULL_PTR(output_t *)) {
delete[] outputs;
}
if (comparators != NULL_PTR(comparator_t *)) {
delete[] comparators;
}
}
bool JAConditionalSignalUpdateGAM::Initialise(MARTe::StructuredDataI & data) {
using namespace MARTe;
bool ok = GAM::Initialise(data);
if (ok) {
// Read expected values.
AnyType valuesArray = data.GetType("ExpectedValues");
if (valuesArray.GetDataPointer() != NULL) {
expectedValuesCount = valuesArray.GetNumberOfElements(0u);
expectedValues = new uint32[expectedValuesCount];
Vector<uint32> valuesVector(expectedValues, expectedValuesCount);
ok = (data.Read("ExpectedValues", valuesVector));
}
bool JAConditionalSignalUpdateGAM::Initialise(MARTe::StructuredDataI &data) {
using namespace MARTe;
bool ok = GAM::Initialise(data);
if (ok) {
MARTe::StreamString operationStr;
if (data.Read("Operation", operationStr)) {
if (operationStr == "AND") {
operation = And;
} else if (operationStr == "OR") {
operation = Or;
} else if (operationStr == "NOR") {
operation = Nor;
} else if (operationStr == "XOR") {
operation = Xor;
} else {
ok = false;
REPORT_ERROR(ErrorManagement::ParametersError,
"Operation %s is not defined", operationStr.Buffer());
}
}
}
if (ok) {
ok = data.MoveRelative("InputSignals");
uint32 level = 0;
if (ok) {
// Read comparators.
AnyType comparatorsArray = data.GetType("Comparators");
if (comparatorsArray.GetDataPointer() != NULL) {
uint32 count;
if (ok) {
count = comparatorsArray.GetNumberOfElements(0u);
ok = count == expectedValuesCount;
}
if (ok) {
comparators = new ComparisonMode[count];
StreamString* comp = new StreamString[count];
Vector<StreamString> compVector(comp, count);
ok = (data.Read("Comparators", compVector));
if (ok) {
for (uint32 i = 0; i < count; ++i) {
if (comp[i] == "EQUALS") {
comparators[i] = Equals;
} else if (comp[i] == "NOT") {
comparators[i] = Not;
} else if (comp[i] == "GREATER") {
comparators[i] = Greater;
} else if (comp[i] == "EQUALS_OR_GREATER") {
comparators[i] = EqualsOrGreater;
} else if (comp[i] == "LESS") {
comparators[i] = Less;
} else if (comp[i] == "EQUALS_OR_LESS") {
comparators[i] = EqualsOrLess;
} else {
ok = false;
REPORT_ERROR(ErrorManagement::ParametersError, "Comparator %s is not defined.", comp[i].Buffer());
}
}
}
delete[] comp;
} else {
REPORT_ERROR(ErrorManagement::ParametersError, "Expected values and operators shall have the same "
"number of elements.");
}
} else {
// Create default comparators (equals) when they aren't provided in the configuration.
comparators = new ComparisonMode[expectedValuesCount];
for (uint32 i = 0; i < expectedValuesCount; ++i) {
comparators[i] = Equals;
}
}
}
if (ok) {
MARTe::StreamString operationStr;
if (data.Read("Operation", operationStr)) {
if (operationStr == "AND") {
operation = And;
}
else if (operationStr == "OR") {
operation = Or;
}
else if (operationStr == "NOR") {
operation = Nor;
}
else if (operationStr == "XOR") {
operation = Xor;
}
else {
ok = false;
REPORT_ERROR(ErrorManagement::ParametersError, "Operation %s is not defined", operationStr.Buffer());
}
}
}
if (ok) {
// Read output signal values to be set.
AnyType valuesArray = data.GetType("Values");
ok = (valuesArray.GetDataPointer() != NULL);
if (ok) {
valuesCount = valuesArray.GetNumberOfElements(0u);
ok = valuesCount > 0u;
}
if (ok) {
values = new uint32[valuesCount];
Vector<uint32> valuesVector(values, valuesCount);
ok = (data.Read("Values", valuesVector));
}
level++;
uint32 n_inputs = data.GetNumberOfChildren();
comparators = new comparator_t[n_inputs];
StreamString buffer;
TypeDescriptor td;
for (uint32 i = 0; ok && i < n_inputs; i++) {
ok = data.MoveToChild(i);
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "Values shall be defined.");
REPORT_ERROR(ErrorManagement::ParametersError,
"Impossible to move to InputSignals[%lu]", i);
break;
}
level++;
ok = data.Read("Type", buffer);
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError,
"Missing mandatory field Type from InputSignals[%lu]",
i);
break;
}
td = TypeDescriptor::GetTypeDescriptorFromTypeName(buffer.Buffer());
ok = (td == UnsignedInteger8Bit) || (td == UnsignedInteger16Bit) ||
(td == UnsignedInteger32Bit);
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError,
"Wrong value for field Type from InputSignals[%lu]", i);
break;
}
ok = data.Read("Comparator", buffer);
if (!ok) {
REPORT_ERROR(
ErrorManagement::ParametersError,
"Missing mandatory field Comparator from InputSignals[%lu]", i);
break;
}
ok = parse_comparator(buffer, comparators[i].comparator);
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError,
"Non Valid Comparator `%s` from InputSignals[%lu]",
buffer, i);
break;
}
ok = data.Read("Value", comparators[i].value);
if (!ok) {
REPORT_ERROR(
ErrorManagement::ParametersError,
"Missing field Value (expecting int) from InputSignals[%lu]", i);
break;
}
if (data.MoveToAncestor(1)) {
level--;
} else {
ok = false;
}
}
data.MoveToAncestor(level);
} else {
REPORT_ERROR(ErrorManagement::ParametersError,
"Impossible to move to InputSignals");
}
return ok;
}
if (ok) {
ok = data.MoveRelative("OutputSignals");
uint32 level = 0;
if (ok) {
level++;
uint32 n_outputs = data.GetNumberOfChildren();
outputs = new output_t[n_outputs];
for (uint32 i = 0; ok && i < n_outputs; i++) {
ok = data.MoveToChild(i);
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError,
"Impossible to move to InputSignals[%lu]", i);
break;
}
level++;
ok = data.Read("DefaultValue", outputs[i].defaultValue);
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError,
"Impossible to read field DefaultValue for output %lu",
i);
break;
}
ok = data.Read("Value", outputs[i].value);
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError,
"Impossible to read field Value for output %lu", i);
break;
}
ok = data.MoveToAncestor(1);
if (ok) {
level--;
}
}
data.MoveToAncestor(level);
} else {
REPORT_ERROR(ErrorManagement::ParametersError,
"Impossible to move to OutputSignals");
}
}
return ok;
}
bool JAConditionalSignalUpdateGAM::Setup() {
using namespace MARTe;
bool ok = numberOfInputSignals == (expectedValuesCount + numberOfOutputSignals);
using namespace MARTe;
bool ok = numberOfInputSignals > 0;
if (ok) {
inputSignals = new void *[numberOfInputSignals];
uint32 i;
for (uint32 i = 0u; i < numberOfOutputSignals; i++) {
inputSignals[i] = GetInputSignalMemory(i);
}
} else {
REPORT_ERROR(ErrorManagement::ParametersError,
"Number of input signals shall be greater then 0 ");
}
if (ok) {
ok = numberOfOutputSignals > 0u;
if (ok) {
inputSignals = new void*[expectedValuesCount];
defaultValues = new uint32*[numberOfOutputSignals];
uint32 i;
for (i = 0u; i < expectedValuesCount; i++) {
inputSignals[i] = GetInputSignalMemory(i);
}
for (; i < numberOfInputSignals; i++) {
defaultValues[i - expectedValuesCount] = reinterpret_cast<uint32 *>(GetInputSignalMemory(i));
}
outputSignals = new uint32 *[numberOfOutputSignals];
for (uint32 i = 0u; i < numberOfOutputSignals; i++) {
outputSignals[i] = reinterpret_cast<uint32 *>(GetOutputSignalMemory(i));
}
} else {
REPORT_ERROR(ErrorManagement::ParametersError, "Number of input signals shall be equal to number "
"of expected values plus number of output signals.");
}
if (ok) {
inputSignalTypes = new TypeDescriptor[expectedValuesCount];
uint32 i;
for (i = 0u; (i < expectedValuesCount) && (ok); i++) {
inputSignalTypes[i] = GetSignalType(InputSignals, i);
ok = ((inputSignalTypes[i] == UnsignedInteger32Bit) || (inputSignalTypes[i] == UnsignedInteger16Bit));
if (!ok) {
StreamString signalName;
(void) GetSignalName(InputSignals, i, signalName);
REPORT_ERROR(ErrorManagement::ParametersError, "Signal %s shall be defined as uint32 or uint16", signalName.Buffer());
}
}
}
if (ok) {
ok = numberOfOutputSignals == valuesCount;
if (ok) {
ok = numberOfOutputSignals > 0u;
if (ok) {
outputSignals = new uint32*[numberOfOutputSignals];
uint32 i;
for (i = 0u; i < numberOfOutputSignals; i++) {
outputSignals[i] = reinterpret_cast<uint32 *>(GetOutputSignalMemory(i));
}
}
else {
REPORT_ERROR(ErrorManagement::ParametersError, "At least one output signal shall be defined");
}
}
else {
REPORT_ERROR(ErrorManagement::ParametersError, "Number of output signals shall be the same as "
"number of provided values.");
}
REPORT_ERROR(ErrorManagement::ParametersError,
"At least one output signal shall be defined");
}
}
return ok;
return ok;
}
bool JAConditionalSignalUpdateGAM::PrepareNextState(const MARTe::char8 * const currentStateName, const MARTe::char8 * const nextStateName) {
needsReset = false;
return true;
bool JAConditionalSignalUpdateGAM::PrepareNextState(
const MARTe::char8 *const currentStateName,
const MARTe::char8 *const nextStateName) {
needsReset = false;
return true;
}
bool accumulate(JAConditionalSignalUpdateGAM::OperationMode mode, bool next,
bool current) {
switch (mode) {
case JAConditionalSignalUpdateGAM::Or:
return next || current;
case JAConditionalSignalUpdateGAM::And:
return next && current;
case JAConditionalSignalUpdateGAM::Nor:
return !(next || current);
case JAConditionalSignalUpdateGAM::Xor:
return (!next != !current);
}
return false;
}
bool JAConditionalSignalUpdateGAM::Execute() {
if (!needsReset) {
bool eventDetected = expectedValuesCount == 0;
if (!eventDetected) {
if (operation == Or) {
MARTe::uint32 j;
for (j = 0; (j < expectedValuesCount) && (!eventDetected); j++) {
eventDetected = Compare(j);
}
}
else if (operation == Nor) {
MARTe::uint32 j;
for (j = 0; (j < expectedValuesCount) && (!eventDetected); j++) {
eventDetected = Compare(j);
}
eventDetected = !eventDetected;
}
else if (operation == And) {
MARTe::uint32 j;
eventDetected = Compare(0);
for (j = 1; (j < expectedValuesCount); j++) {
eventDetected &= Compare(j);
}
}
else if (operation == Xor) {
MARTe::uint32 j;
MARTe::uint32 eventDetectedUint32;
if (inputSignalTypes[0] == MARTe::UnsignedInteger32Bit) {
eventDetectedUint32 = *static_cast<MARTe::uint32 *>(inputSignals[0]);
}
else {
eventDetectedUint32 = *static_cast<MARTe::uint16 *>(inputSignals[0]);
}
for (j = 1; (j < expectedValuesCount); j++) {
eventDetectedUint32 ^= Compare(j);
}
eventDetected = (eventDetectedUint32 == 1u);
}
}
if (eventDetected) {
needsReset = true;
MARTe::uint32 i;
for (i = 0u; i < numberOfOutputSignals; ++i) {
*outputSignals[i] = values[i];
MARTe::StreamString signalName;
(void) GetSignalName(MARTe::OutputSignals, i, signalName);
}
}
else {
MARTe::uint32 i;
for (i = 0u; i < numberOfOutputSignals; ++i) {
*outputSignals[i] = *defaultValues[i];
}
}
if (!needsReset) {
bool state = Compare(0);
for (MARTe::uint32 i = 1; i < numberOfInputSignals; i++) {
state = accumulate(operation, Compare(i), state);
}
return true;
if (state) {
needsReset = true;
MARTe::uint32 i;
for (i = 0u; i < numberOfOutputSignals; ++i) {
*outputSignals[i] = outputs[i].value;
}
} else {
MARTe::uint32 i;
for (i = 0u; i < numberOfOutputSignals; ++i) {
*outputSignals[i] = outputs[i].defaultValue;
}
}
}
return true;
}
bool JAConditionalSignalUpdateGAM::Compare(MARTe::uint32 index) {
if (inputSignalTypes[index] == MARTe::UnsignedInteger32Bit) {
return Compare<MARTe::uint32>(index);
}
return Compare<MARTe::uint16>(index);
if (inputSignalTypes[index] == MARTe::UnsignedInteger32Bit) {
return Compare<MARTe::uint32>(index);
}
return Compare<MARTe::uint16>(index);
}
CLASS_REGISTER(JAConditionalSignalUpdateGAM, "1.0")

View File

@@ -11,12 +11,13 @@
* 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,
* @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 JAConditionalSignalUpdateGAM
* @details This header file contains the declaration of the class
JAConditionalSignalUpdateGAM
* 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.
*/
@@ -31,6 +32,7 @@
/*---------------------------------------------------------------------------*/
/* Project header includes */
/*---------------------------------------------------------------------------*/
#include "Architecture/x86_gcc/CompilerTypes.h"
#include "GAM.h"
/*---------------------------------------------------------------------------*/
@@ -38,20 +40,24 @@
/*---------------------------------------------------------------------------*/
/**
* @brief GAM that writes predefined values to output signals when a condition is met.
* If there are no conditional signals provided, the condition is presumed to be met.
* @brief GAM that writes predefined values to output signals when a condition
* is met. If there are no conditional signals provided, the condition is
* presumed to be met.
*
* +ASYNCShotlengthControlGAM = {
* Class = JAConditionalSignalUpdateGAM
* Operation = OR // Logical operation performed between conditional signals
* Operation = OR // Logical operation performed between conditional
* signals
* // Supported values: AND, OR, XOR, NOR
* // Default: AND
* ExpectedValues = {1 1} // Values to which conditional signals will be compared.
* Comparators = {EQUALS EQUALS} // Operator between conditional signal an expected value
* // Supported values: EQUALS, NOT, GREATER, EQUALS_OR_GREATER, LESS, EQUALS_OR_LESS
* ExpectedValues = {1 1} // Values to which conditional signals will
* be compared. Comparators = {EQUALS EQUALS} // Operator between conditional
* signal an expected value
* // Supported values: EQUALS, NOT,
* GREATER, EQUALS_OR_GREATER, LESS, EQUALS_OR_LESS
* // Default: EQUALS
* Values = {0 3} // Values that will be written to output signals when condition is met.
* InputSignals = {
* Values = {0 3} // Values that will be written to output signals when
* condition is met. InputSignals = {
* // Conditional Signals
* SHOTLEN_FLAG = {
* DataSource = DDB1
@@ -61,15 +67,13 @@
* DataSource = DDB1
* Type = uint32
* }
* // Default values (set to output signals before the condition is met)
* APS_SWON = { // APS_SWON will keep the value from previous state.
* // Default values (set to output signals before the condition is
* met) APS_SWON = { // APS_SWON will keep the value from previous state.
* DataSource = DDB1
* Type = uint32
* }
* BPS_SWON_DEFAULT = { // BPS_SWON will be set to 7 before condition is met.
* DataSource = DDB1
* Type = uint32
* Default = 7
* BPS_SWON_DEFAULT = { // BPS_SWON will be set to 7 before
* condition is met. DataSource = DDB1 Type = uint32 Default = 7
* }
* }
* OutputSignals = {
@@ -84,97 +88,96 @@
* }
* }
*/
class JAConditionalSignalUpdateGAM : public MARTe::GAM, public MARTe::StatefulI {
class JAConditionalSignalUpdateGAM : public MARTe::GAM,
public MARTe::StatefulI {
public:
CLASS_REGISTER_DECLARATION()
CLASS_REGISTER_DECLARATION()
JAConditionalSignalUpdateGAM();
JAConditionalSignalUpdateGAM();
virtual ~JAConditionalSignalUpdateGAM();
virtual ~JAConditionalSignalUpdateGAM();
virtual bool Initialise(MARTe::StructuredDataI & data);
virtual bool Initialise(MARTe::StructuredDataI &data);
virtual bool Setup();
virtual bool Setup();
virtual bool Execute();
virtual bool Execute();
virtual bool PrepareNextState(const MARTe::char8 * const currentStateName,
const MARTe::char8 * const nextStateName);
virtual bool PrepareNextState(const MARTe::char8 *const currentStateName,
const MARTe::char8 *const nextStateName);
enum ComparisonMode {
Equals,
Not,
Greater,
EqualsOrGreater,
Less,
EqualsOrLess
};
enum OperationMode { And, Or, Xor, Nor };
private:
/**
* @brief Does the input signal at provided index have the expected value.
* @param[in] index of the signal.
* @return true if the signal has expected value.
*/
bool Compare(MARTe::uint32 index);
/**
* @brief Does the input signal at provided index have the expected value.
* @param[in] index of the signal.
* @return true if the signal has expected value.
*/
bool Compare(MARTe::uint32 index);
template <class T>
bool Compare(MARTe::uint32 index);
template <class T> bool Compare(MARTe::uint32 index);
enum OperationMode {
And, Or, Xor, Nor
};
enum ComparisonMode {
Equals, Not, Greater, EqualsOrGreater, Less, EqualsOrLess
};
// Input signals
void **inputSignals;
// Input signals
void **inputSignals;
MARTe::TypeDescriptor *inputSignalTypes;
struct comparator_t {
ComparisonMode comparator;
MARTe::uint32 value;
};
comparator_t *comparators;
// Condition operation.
OperationMode operation;
MARTe::TypeDescriptor *inputSignalTypes;
// Output signals
MARTe::uint32 **outputSignals;
struct output_t {
MARTe::uint32 value;
MARTe::uint32 defaultValue;
};
output_t *outputs;
// Condition operation.
OperationMode operation;
// Array of expected values of input signals.
MARTe::uint32* expectedValues;
// Expected values count (must be equal to numberOfInputSignals)
MARTe::uint32 expectedValuesCount;
// Array of comparators
ComparisonMode* comparators;
// Values to be written on output signals when input signal has the expected value.
MARTe::uint32 *values;
// Number of values (must be equal to numberOfOutputSignals)
MARTe::uint32 valuesCount;
// Output signals
MARTe::uint32 **outputSignals;
// Default values of output signals
MARTe::uint32 **defaultValues;
// Were output signals already set and we are waiting for a state change before they are set again.
bool needsReset;
// Were output signals already set and we are waiting for a state change
// before they are set again.
bool needsReset;
};
/*---------------------------------------------------------------------------*/
/* Inline method definitions */
/*---------------------------------------------------------------------------*/
template <class T>
bool JAConditionalSignalUpdateGAM::Compare(MARTe::uint32 index) {
switch (comparators[index]) {
case Equals:
return *static_cast<T *>(inputSignals[index]) == static_cast<T>(expectedValues[index]);
case Not:
return *static_cast<T *>(inputSignals[index]) != static_cast<T>(expectedValues[index]);
case Greater:
return *static_cast<T *>(inputSignals[index]) > static_cast<T>(expectedValues[index]);
case EqualsOrGreater:
return *static_cast<T *>(inputSignals[index]) >= static_cast<T>(expectedValues[index]);
case Less:
return *static_cast<T *>(inputSignals[index]) < static_cast<T>(expectedValues[index]);
default: // case EqualsOrLess:
return *static_cast<T *>(inputSignals[index]) <= static_cast<T>(expectedValues[index]);
}
switch (comparators[index].comparator) {
case Equals:
return *static_cast<T *>(inputSignals[index]) ==
static_cast<T>(comparators[index].value);
case Not:
return *static_cast<T *>(inputSignals[index]) !=
static_cast<T>(comparators[index].value);
case Greater:
return *static_cast<T *>(inputSignals[index]) >
static_cast<T>(comparators[index].value);
case EqualsOrGreater:
return *static_cast<T *>(inputSignals[index]) >=
static_cast<T>(comparators[index].value);
case Less:
return *static_cast<T *>(inputSignals[index]) <
static_cast<T>(comparators[index].value);
default: // case EqualsOrLess:
return *static_cast<T *>(inputSignals[index]) <=
static_cast<T>(comparators[index].value);
}
}
#endif /* GAMS_JACONDITIONALSIGNALUPDATEGAM_H_ */

View File

@@ -29,8 +29,12 @@
/* Project header includes */
/*---------------------------------------------------------------------------*/
#include "AdvancedErrorManagement.h"
#include "Architecture/x86_gcc/CompilerTypes.h"
#include "ErrorType.h"
#include "JAMessageGAM.h"
#include "MessageI.h"
#include "StreamString.h"
#include "TypeDescriptor.h"
/*---------------------------------------------------------------------------*/
/* Static definitions */
@@ -40,308 +44,336 @@
/* Method definitions */
/*---------------------------------------------------------------------------*/
template<class T, class U>
bool Compare(JAMessageGAM::ComparisonMode comparator, void *inputSignal, U expectedValue) {
switch (comparator) {
case JAMessageGAM::Equals:
return *static_cast<T *>(inputSignal) == expectedValue;
case JAMessageGAM::Not:
return *static_cast<T *>(inputSignal) != expectedValue;
case JAMessageGAM::Greater:
return *static_cast<T *>(inputSignal) > expectedValue;
case JAMessageGAM::EqualsOrGreater:
return *static_cast<T *>(inputSignal) >= expectedValue;
case JAMessageGAM::Less:
return *static_cast<T *>(inputSignal) < expectedValue;
default: // case EqualsOrLess:
return *static_cast<T *>(inputSignal) <= expectedValue;
}
template <class T, class U>
bool Compare(JAMessageGAM::ComparisonMode comparator, void *inputSignal,
U expectedValue) {
switch (comparator) {
case JAMessageGAM::Equals:
return *static_cast<T *>(inputSignal) == expectedValue;
case JAMessageGAM::Not:
return *static_cast<T *>(inputSignal) != expectedValue;
case JAMessageGAM::Greater:
return *static_cast<T *>(inputSignal) > expectedValue;
case JAMessageGAM::EqualsOrGreater:
return *static_cast<T *>(inputSignal) >= expectedValue;
case JAMessageGAM::Less:
return *static_cast<T *>(inputSignal) < expectedValue;
default: // case EqualsOrLess:
return *static_cast<T *>(inputSignal) <= expectedValue;
}
}
bool parse_comparator(const MARTe::StreamString &str,
JAMessageGAM::ComparisonMode &op) {
if (str == "EQUALS") {
op = JAMessageGAM::Equals;
return true;
}
if (str == "NOT") {
op = JAMessageGAM::Not;
return true;
}
if (str == "GREATER") {
op = JAMessageGAM::Greater;
return true;
}
if (str == "EQUALS_OR_GREATER") {
op = JAMessageGAM::EqualsOrGreater;
return true;
}
if (str == "LESS") {
op = JAMessageGAM::Less;
return true;
}
if (str == "EQUALS_OR_LESS") {
op = JAMessageGAM::EqualsOrLess;
return true;
}
return false;
}
bool is_int(const MARTe::TypeDescriptor &td) {
return (td == MARTe::UnsignedInteger32Bit) ||
(td == MARTe::SignedInteger32Bit) ||
(td == MARTe::UnsignedInteger16Bit) ||
(td == MARTe::SignedInteger16Bit) ||
(td == MARTe::UnsignedInteger8Bit) || (td == MARTe::SignedInteger8Bit);
}
bool is_float(const MARTe::TypeDescriptor &td) {
return (td == MARTe::Float32Bit) || (td == MARTe::Float64Bit);
}
JAMessageGAM::JAMessageGAM() {
inputSignals = NULL_PTR(void **);
inputSignalTypes = NULL_PTR(MARTe::TypeDescriptor *);
operation = And;
needsReset = false;
expectedValuesInt = NULL_PTR(MARTe::uint64 *);
expectedValuesFloat = NULL_PTR(MARTe::float64 *);
intValuesCount = 0u;
floatValuesCount = 0u;
comparators = NULL_PTR(ComparisonMode *);
inputSignals = NULL_PTR(void **);
inputSignalTypes = NULL_PTR(MARTe::TypeDescriptor *);
comparators = NULL_PTR(comparator_t *);
operation = And;
needsReset = false;
}
JAMessageGAM::~JAMessageGAM() {
if (inputSignals != NULL_PTR(void **)) {
delete[] inputSignals;
}
if (inputSignalTypes != NULL_PTR(MARTe::TypeDescriptor *)) {
delete[] inputSignalTypes;
}
if (expectedValuesInt != NULL_PTR(MARTe::uint64 *)) {
delete[] expectedValuesInt;
}
if (expectedValuesFloat != NULL_PTR(MARTe::float64 *)) {
delete[] expectedValuesFloat;
}
if (comparators != NULL_PTR(ComparisonMode *)) {
delete[] comparators;
}
if (inputSignals != NULL_PTR(void **)) {
delete[] inputSignals;
}
if (inputSignalTypes != NULL_PTR(MARTe::TypeDescriptor *)) {
delete[] inputSignalTypes;
}
if (comparators != NULL_PTR(comparator_t *)) {
delete[] comparators;
}
}
bool JAMessageGAM::Initialise(MARTe::StructuredDataI & data) {
using namespace MARTe;
bool ok = GAM::Initialise(data);
if (ok) {
// Read expected integer values.
AnyType valuesArray = data.GetType("ExpectedIntValues");
bool intValuesProvided = (valuesArray.GetDataPointer() != NULL);
if (intValuesProvided) {
intValuesCount = valuesArray.GetNumberOfElements(0u);
}
if (intValuesProvided) {
expectedValuesInt = new uint64[intValuesCount];
Vector<uint64> valuesVector(expectedValuesInt, intValuesCount);
ok = (data.Read("ExpectedIntValues", valuesVector));
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "Failed to read ExpectedIntValues.");
return ok;
}
}
// Read expected float values.
valuesArray = data.GetType("ExpectedFloatValues");
bool floatValuesProvided = (valuesArray.GetDataPointer() != NULL);
if (floatValuesProvided) {
floatValuesCount = valuesArray.GetNumberOfElements(0u);
}
if (floatValuesProvided) {
expectedValuesFloat = new float64[floatValuesCount];
Vector<float64> valuesVector(expectedValuesFloat, floatValuesCount);
ok = (data.Read("ExpectedFloatValues", valuesVector));
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "Failed to read ExpectedFloatValues.");
return ok;
}
}
ok = (floatValuesCount + intValuesCount) > 0u;
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "ExpectedFloatValues and or ExpectedIntValues shall be defined.");
}
bool JAMessageGAM::Initialise(MARTe::StructuredDataI &data) {
using namespace MARTe;
bool ok = GAM::Initialise(data);
if (ok) {
MARTe::StreamString operationStr;
if (data.Read("Operation", operationStr)) {
if (operationStr == "AND") {
operation = And;
} else if (operationStr == "OR") {
operation = Or;
} else if (operationStr == "NOR") {
operation = Nor;
} else if (operationStr == "XOR") {
operation = Xor;
} else {
ok = false;
REPORT_ERROR(ErrorManagement::ParametersError,
"Operation %s is not defined", operationStr.Buffer());
}
}
}
if (ok) {
ok = (Size() == 1);
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError,
"A Message object shall be added to this container");
}
}
if (ok) {
eventMsg = Get(0);
ok = (eventMsg.IsValid());
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError,
"A valid Message shall be added to this container");
}
}
if (ok) {
ok = data.MoveRelative("InputSignals");
uint32 level = 0;
if (ok) {
// Read comparators.
AnyType comparatorsArray = data.GetType("Comparators");
if (comparatorsArray.GetDataPointer() != NULL) {
uint32 count = comparatorsArray.GetNumberOfElements(0u);
ok = count == (intValuesCount + floatValuesCount);
if (ok) {
comparators = new ComparisonMode[count];
StreamString* comp = new StreamString[count];
Vector<StreamString> compVector(comp, count);
ok = (data.Read("Comparators", compVector));
if (ok) {
for (uint32 i = 0; i < count; ++i) {
if (comp[i] == "EQUALS") {
comparators[i] = Equals;
} else if (comp[i] == "NOT") {
comparators[i] = Not;
} else if (comp[i] == "GREATER") {
comparators[i] = Greater;
} else if (comp[i] == "EQUALS_OR_GREATER") {
comparators[i] = EqualsOrGreater;
} else if (comp[i] == "LESS") {
comparators[i] = Less;
} else if (comp[i] == "EQUALS_OR_LESS") {
comparators[i] = EqualsOrLess;
} else {
ok = false;
REPORT_ERROR(ErrorManagement::ParametersError, "Comparator %s is not defined.", comp[i].Buffer());
}
}
}
} else {
REPORT_ERROR(ErrorManagement::ParametersError, "Expected values and operators shall have the same "
"number of elements.");
}
level++;
uint32 n_inputs = data.GetNumberOfChildren();
comparators = new comparator_t[n_inputs];
StreamString buffer;
TypeDescriptor td;
for (uint32 i = 0; ok && i < n_inputs; i++) {
ok = data.MoveToChild(i);
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError,
"Impossible to move to InputSignals[%lu]", i);
break;
}
level++;
ok = data.Read("Type", buffer);
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError,
"Missing mandatory field Type from InputSignals[%lu]",
i);
break;
}
td = TypeDescriptor::GetTypeDescriptorFromTypeName(buffer.Buffer());
ok = (td != InvalidType) && (is_float(td) || is_int(td));
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError,
"Wrong value for field Type from InputSignals[%lu]", i);
break;
}
ok = data.Read("Comparator", buffer);
if (!ok) {
REPORT_ERROR(
ErrorManagement::ParametersError,
"Missing mandatory field Comparator from InputSignals[%lu]", i);
break;
}
ok = parse_comparator(buffer, comparators[i].comparator);
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError,
"Non Valid Comparator `%s` from InputSignals[%lu]",
buffer, i);
break;
}
if (is_int(td)) {
ok = data.Read("Value", comparators[i].value.i64);
if (!ok) {
REPORT_ERROR(
ErrorManagement::ParametersError,
"Missing field Value (expecting int) from InputSignals[%lu]",
i);
break;
}
} else {
uint32 count = intValuesCount + floatValuesCount;
if (ok) {
// Create default comparators (equals) when they aren't provided in the configuration.
comparators = new ComparisonMode[count];
for (uint32 i = 0; i < count; ++i) {
comparators[i] = Equals;
}
} else {
REPORT_ERROR(ErrorManagement::ParametersError, "Expected values and operators shall have the same "
"number of elements.");
}
ok = data.Read("Value", comparators[i].value.f64);
if (!ok) {
REPORT_ERROR(
ErrorManagement::ParametersError,
"Missing field Value (expecting float) from InputSignals[%lu]",
i);
break;
}
}
}
if (ok) {
MARTe::StreamString operationStr;
if (data.Read("Operation", operationStr)) {
if (operationStr == "AND") {
operation = And;
}
else if (operationStr == "OR") {
operation = Or;
}
else if (operationStr == "NOR") {
operation = Nor;
}
else if (operationStr == "XOR") {
operation = Xor;
}
else {
ok = false;
REPORT_ERROR(ErrorManagement::ParametersError, "Operation %s is not defined", operationStr.Buffer());
}
if (data.MoveToAncestor(1)) {
level--;
}
}
data.MoveToAncestor(level);
} else {
REPORT_ERROR(ErrorManagement::ParametersError,
"Impossible to move to InputSignals");
}
if (ok) {
ok = (Size() == 1);
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "A Message object shall be added to this container");
}
}
if (ok) {
eventMsg = Get(0);
ok = (eventMsg.IsValid());
if (!ok) {
REPORT_ERROR(ErrorManagement::ParametersError, "A valid Message shall be added to this container");
}
}
return ok;
}
return ok;
}
bool JAMessageGAM::Setup() {
using namespace MARTe;
bool ok = numberOfInputSignals == (intValuesCount + floatValuesCount);
if (ok) {
ok = numberOfInputSignals > 0u;
if (ok) {
inputSignals = new void*[numberOfInputSignals];
uint32 i;
for (i = 0u; i < numberOfInputSignals; i++) {
inputSignals[i] = GetInputSignalMemory(i);
}
}
else {
REPORT_ERROR(ErrorManagement::ParametersError, "At least one input signal shall be defined");
}
} else {
REPORT_ERROR(ErrorManagement::ParametersError, "Number of input signals shall be the same as "
"number of expected values.");
using namespace MARTe;
bool ok = numberOfInputSignals > 0u;
if (ok) {
inputSignals = new void *[numberOfInputSignals];
uint32 i;
for (i = 0u; i < numberOfInputSignals; i++) {
inputSignals[i] = GetInputSignalMemory(i);
}
if (ok) {
inputSignalTypes = new TypeDescriptor[numberOfInputSignals];
uint32 i;
for (i = 0u; (i < numberOfInputSignals) && (ok); i++) {
TypeDescriptor inputType = GetSignalType(InputSignals, i);
inputSignalTypes[i] = inputType;
ok = (inputType == UnsignedInteger32Bit) || (inputType == SignedInteger32Bit) ||
(inputType == UnsignedInteger16Bit) || (inputType == SignedInteger16Bit) ||
(inputType == UnsignedInteger8Bit) || (inputType == SignedInteger8Bit) ||
(inputType == Float64Bit) || (inputType == Float32Bit);
if (!ok) {
StreamString signalName;
(void) GetSignalName(InputSignals, i, signalName);
REPORT_ERROR(ErrorManagement::ParametersError, "Signal %s shall be defined as 32/16/8 bit signed/unsigned integer "
"or as 64/32 float.", signalName.Buffer());
}
}
} else {
REPORT_ERROR(ErrorManagement::ParametersError,
"At least one input signal shall be defined");
}
if (ok) {
inputSignalTypes = new TypeDescriptor[numberOfInputSignals];
uint32 i;
for (i = 0u; (i < numberOfInputSignals) && (ok); i++) {
TypeDescriptor inputType = GetSignalType(InputSignals, i);
inputSignalTypes[i] = inputType;
ok = (inputType == UnsignedInteger32Bit) ||
(inputType == SignedInteger32Bit) ||
(inputType == UnsignedInteger16Bit) ||
(inputType == SignedInteger16Bit) ||
(inputType == UnsignedInteger8Bit) ||
(inputType == SignedInteger8Bit) || (inputType == Float64Bit) ||
(inputType == Float32Bit);
if (!ok) {
StreamString signalName;
(void)GetSignalName(InputSignals, i, signalName);
REPORT_ERROR(ErrorManagement::ParametersError,
"Signal %s shall be defined as 32/16/8 bit "
"signed/unsigned integer "
"or as 64/32 float.",
signalName.Buffer());
}
}
}
return ok;
return ok;
}
bool JAMessageGAM::PrepareNextState(const MARTe::char8 * const currentStateName, const MARTe::char8 * const nextStateName) {
needsReset = false;
return true;
bool JAMessageGAM::PrepareNextState(const MARTe::char8 *const currentStateName,
const MARTe::char8 *const nextStateName) {
needsReset = false;
return true;
}
bool JAMessageGAM::Execute() {
using namespace MARTe;
bool ok = true;
bool eventDetected = false;
uint32 inputPortIndex = 0;
uint32 intIndex = 0;
uint32 floatIndex = 0;
if (operation == Or) {
for (inputPortIndex = 0; (inputPortIndex < numberOfInputSignals) && (!eventDetected); inputPortIndex++) {
eventDetected = Compare(inputPortIndex, floatIndex, intIndex);
}
using namespace MARTe;
bool ok = true;
bool eventDetected = false;
uint32 inputPortIndex = 0;
uint32 intIndex = 0;
uint32 floatIndex = 0;
if (operation == Or) {
for (inputPortIndex = 0;
(inputPortIndex < numberOfInputSignals) && (!eventDetected);
inputPortIndex++) {
eventDetected = Compare(inputPortIndex, floatIndex, intIndex);
}
else if (operation == Nor) {
for (inputPortIndex = 0; (inputPortIndex < numberOfInputSignals) && (!eventDetected); inputPortIndex++) {
eventDetected = Compare(inputPortIndex, floatIndex, intIndex);
}
eventDetected = !eventDetected;
} else if (operation == Nor) {
for (inputPortIndex = 0;
(inputPortIndex < numberOfInputSignals) && (!eventDetected);
inputPortIndex++) {
eventDetected = Compare(inputPortIndex, floatIndex, intIndex);
}
else if (operation == And) {
eventDetected = Compare(0, floatIndex, intIndex);
for (inputPortIndex = 1; (inputPortIndex < numberOfInputSignals); inputPortIndex++) {
eventDetected &= Compare(inputPortIndex, floatIndex, intIndex);
}
eventDetected = !eventDetected;
} else if (operation == And) {
eventDetected = Compare(0, floatIndex, intIndex);
for (inputPortIndex = 1; (inputPortIndex < numberOfInputSignals);
inputPortIndex++) {
eventDetected = Compare(inputPortIndex, floatIndex, intIndex);
}
else if (operation == Xor) {
uint32 eventDetectedUInt32 = Compare(inputPortIndex, floatIndex, intIndex);
for (inputPortIndex = 1; (inputPortIndex < numberOfInputSignals); inputPortIndex++) {
eventDetectedUInt32 ^= Compare(inputPortIndex, floatIndex, intIndex);
}
eventDetected = (eventDetectedUInt32 == 1u);
} else if (operation == Xor) {
uint32 eventDetectedUInt32 = Compare(inputPortIndex, floatIndex, intIndex);
for (inputPortIndex = 1; (inputPortIndex < numberOfInputSignals);
inputPortIndex++) {
eventDetectedUInt32 ^= Compare(inputPortIndex, floatIndex, intIndex);
}
if (eventDetected) {
if (!needsReset) {
ok = (MessageI::SendMessage(eventMsg, this) == ErrorManagement::NoError);
needsReset = true;
}
eventDetected = (eventDetectedUInt32 == 1u);
}
if (eventDetected) {
if (!needsReset) {
ok = (MessageI::SendMessage(eventMsg, this) == ErrorManagement::NoError);
needsReset = true;
}
return ok;
}
return ok;
}
bool JAMessageGAM::Compare(MARTe::uint32 inputPortIndex, MARTe::uint32 &floatValueIndex, MARTe::uint32 &intValueIndex) {
using namespace MARTe;
bool ret = false;
if (inputSignalTypes[inputPortIndex] == UnsignedInteger32Bit) {
ret = ::Compare<uint32>(comparators[inputPortIndex], inputSignals[inputPortIndex], expectedValuesInt[intValueIndex]);
++intValueIndex;
}
else if (inputSignalTypes[inputPortIndex] == SignedInteger32Bit) {
ret = ::Compare<int32>(comparators[inputPortIndex], inputSignals[inputPortIndex], expectedValuesInt[intValueIndex]);
++intValueIndex;
}
else if (inputSignalTypes[inputPortIndex] == UnsignedInteger16Bit) {
ret = ::Compare<uint16>(comparators[inputPortIndex], inputSignals[inputPortIndex], expectedValuesInt[intValueIndex]);
++intValueIndex;
}
else if (inputSignalTypes[inputPortIndex] == SignedInteger16Bit) {
ret = ::Compare<int16>(comparators[inputPortIndex], inputSignals[inputPortIndex], expectedValuesInt[intValueIndex]);
++intValueIndex;
}
else if (inputSignalTypes[inputPortIndex] == UnsignedInteger8Bit) {
ret = ::Compare<uint8>(comparators[inputPortIndex], inputSignals[inputPortIndex], expectedValuesInt[intValueIndex]);
++intValueIndex;
}
else if (inputSignalTypes[inputPortIndex] == SignedInteger8Bit) {
ret = ::Compare<int8>(comparators[inputPortIndex], inputSignals[inputPortIndex], expectedValuesInt[intValueIndex]);
++intValueIndex;
}
else if (inputSignalTypes[inputPortIndex] == Float64Bit) {
ret = ::Compare<float64>(comparators[inputPortIndex], inputSignals[inputPortIndex], expectedValuesFloat[floatValueIndex]);
++floatValueIndex;
}
else {
ret = ::Compare<float32>(comparators[inputPortIndex], inputSignals[inputPortIndex], expectedValuesFloat[floatValueIndex]);
++floatValueIndex;
}
return ret;
bool JAMessageGAM::Compare(MARTe::uint32 inputPortIndex,
MARTe::uint32 &floatValueIndex,
MARTe::uint32 &intValueIndex) {
using namespace MARTe;
bool ret = false;
if (inputSignalTypes[inputPortIndex] == UnsignedInteger32Bit) {
ret = ::Compare<uint32>(comparators[inputPortIndex].comparator,
inputSignals[inputPortIndex],
comparators[inputPortIndex].value.i64);
++intValueIndex;
} else if (inputSignalTypes[inputPortIndex] == SignedInteger32Bit) {
ret = ::Compare<int32>(comparators[inputPortIndex].comparator,
inputSignals[inputPortIndex],
comparators[inputPortIndex].value.i64);
++intValueIndex;
} else if (inputSignalTypes[inputPortIndex] == UnsignedInteger16Bit) {
ret = ::Compare<uint16>(comparators[inputPortIndex].comparator,
inputSignals[inputPortIndex],
comparators[inputPortIndex].value.i64);
++intValueIndex;
} else if (inputSignalTypes[inputPortIndex] == SignedInteger16Bit) {
ret = ::Compare<int16>(comparators[inputPortIndex].comparator,
inputSignals[inputPortIndex],
comparators[inputPortIndex].value.i64);
++intValueIndex;
} else if (inputSignalTypes[inputPortIndex] == UnsignedInteger8Bit) {
ret = ::Compare<uint8>(comparators[inputPortIndex].comparator,
inputSignals[inputPortIndex],
comparators[inputPortIndex].value.i64);
++intValueIndex;
} else if (inputSignalTypes[inputPortIndex] == SignedInteger8Bit) {
ret = ::Compare<int8>(comparators[inputPortIndex].comparator,
inputSignals[inputPortIndex],
comparators[inputPortIndex].value.i64);
++intValueIndex;
} else if (inputSignalTypes[inputPortIndex] == Float64Bit) {
ret = ::Compare<float64>(comparators[inputPortIndex].comparator,
inputSignals[inputPortIndex],
comparators[inputPortIndex].value.f64);
++floatValueIndex;
} else {
ret = ::Compare<float32>(comparators[inputPortIndex].comparator,
inputSignals[inputPortIndex],
comparators[inputPortIndex].value.f64);
++floatValueIndex;
}
return ret;
}
CLASS_REGISTER(JAMessageGAM, "1.0")

View File

@@ -32,6 +32,7 @@
/* Project header includes */
/*---------------------------------------------------------------------------*/
#include "Architecture/x86_gcc/CompilerTypes.h"
#include "GAM.h"
#include "Message.h"
@@ -48,22 +49,23 @@
* +MessageGAM = {
* Class = JAMessageGAM
* Operation = AND // Accepted values are: AND, OR, XOR, NOR. Default value is AND.
* ExpectedIntValues = {1 10} // Expected values for input signals of integral type.
* ExpectedFloatValues = {3.5} // Expected values for float signals of floting point type.
* Comparators = {EQUALS GREATER NOT} // Accepted values are: EQUALS, NOT, GREATER, EQUALS_OR_GREATER, LESS, EQUALS_OR_LESS
* // Comparators element is optional. Default comparator is EQUALS.
* InputSignals = {
* Sig1 = {
* DataSource = EPICSCAInput
* Type = uint32
* Comparator = "EQUALS" | "GREATER" | "NOT" | "EQUALS_OR_GREATER" | "LESS" | "EQUALS_OR_LESS"
* ExpectedValue = 1
* }
* Sig2 = {
* DataSource = EPICSCAInput
* Type = float32
* Comparator = "EQUALS" | "GREATER" | "NOT" | "EQUALS_OR_GREATER" | "LESS" | "EQUALS_OR_LESS"
* ExpectedValue = 3.5
* }
* Sig3 = {
* DataSource = EPICSCAInput
* Type = uint32
* Comparator = "EQUALS" | "GREATER" | "NOT" | "EQUALS_OR_GREATER" | "LESS" | "EQUALS_OR_LESS"
* }
* }
* +Event = { // Message to be sent when condition is true.
@@ -113,6 +115,17 @@ private:
// Input signals
void **inputSignals;
struct comparator_t {
ComparisonMode comparator;
union {
MARTe::int64 i64;
MARTe::float64 f64;
} value;
};
comparator_t * comparators;
MARTe::TypeDescriptor *inputSignalTypes;
// Condition operation.
@@ -123,21 +136,6 @@ private:
// Was the message already sent and we are waiting for a state change before next message can be sent.
bool needsReset;
// Array of expected integer values of input signals.
MARTe::uint64* expectedValuesInt;
// Array of expected float values for input signals.
MARTe::float64* expectedValuesFloat;
// Expected integer values count (must be equal to numberOfInputSignals - floatValuesCount)
MARTe::uint32 intValuesCount;
// Expected integer values count (must be equal to numberOfInputSignals - floatValuesCount)
MARTe::uint32 floatValuesCount;
// Array of comparators
ComparisonMode* comparators;
};

View File

@@ -27,7 +27,7 @@ OBJSX=JAMessageGAM.x
PACKAGE=GAMs
ROOT_DIR=../../../../obj
ROOT_DIR=../../
MAKEDEFAULTDIR=$(MARTe2_DIR)/MakeDefaults
include $(MAKEDEFAULTDIR)/MakeStdLibDefs.$(TARGET)

View File

@@ -1,6 +1,6 @@
/**
* @file JASourceChoiseGAM.cpp
* @brief Source file for class JASourceChoiseGAM
* @file JASourceChoiceGAM.cpp
* @brief Source file for class JASourceChoiceGAM
* @date Nov 26, 2018
* @author aneto
*
@@ -17,7 +17,7 @@
* 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 JASourceChoiseGAM (public, protected, and private). Be aware that some
* the class JASourceChoiceGAM (public, protected, and private). Be aware that some
* methods, such as those inline could be defined on the header file, instead.
*/
@@ -29,7 +29,7 @@
/* Project header includes */
/*---------------------------------------------------------------------------*/
#include "JASourceChoiseGAM.h"
#include "JASourceChoiceGAM.h"
#include "AdvancedErrorManagement.h"
@@ -41,15 +41,15 @@
/* Method definitions */
/*---------------------------------------------------------------------------*/
JASourceChoiseGAM::JASourceChoiseGAM() {
JASourceChoiceGAM::JASourceChoiceGAM() {
// initialize member variables.
numberOfPVs = 0;
}
JASourceChoiseGAM::~JASourceChoiseGAM() {
JASourceChoiceGAM::~JASourceChoiceGAM() {
}
bool JASourceChoiseGAM::Initialise(MARTe::StructuredDataI & data) {
bool JASourceChoiceGAM::Initialise(MARTe::StructuredDataI & data) {
//GAM parameters are initialized.
using namespace MARTe;
bool ok = GAM::Initialise(data);
@@ -62,12 +62,12 @@ bool JASourceChoiseGAM::Initialise(MARTe::StructuredDataI & data) {
return ok;
}
bool JASourceChoiseGAM::PrepareNextState(const MARTe::char8 * const currentStateName, const MARTe::char8 * const nextStateName) {
bool JASourceChoiceGAM::PrepareNextState(const MARTe::char8 * const currentStateName, const MARTe::char8 * const nextStateName) {
//This method changes internal parameter based on next realtime state.
return true;
}
bool JASourceChoiseGAM::Setup() {
bool JASourceChoiceGAM::Setup() {
// Setup memory for input/output signals on the GAM.
using namespace MARTe;
bool ok = (numberOfInputSignals == numberOfPVs*3u);
@@ -147,7 +147,7 @@ bool JASourceChoiseGAM::Setup() {
return ok;
}
bool JASourceChoiseGAM::Execute() {
bool JASourceChoiceGAM::Execute() {
// This method is called every realtime state thread cycle.
using namespace MARTe;
@@ -185,4 +185,4 @@ bool JASourceChoiseGAM::Execute() {
return true;
}
CLASS_REGISTER(JASourceChoiseGAM, "1.0")
CLASS_REGISTER(JASourceChoiceGAM, "1.0")

View File

@@ -38,13 +38,13 @@
/* Class declaration */
/*---------------------------------------------------------------------------*/
class JASourceChoiseGAM : public MARTe::GAM, public MARTe::StatefulI {
class JASourceChoiceGAM : public MARTe::GAM, public MARTe::StatefulI {
public:
CLASS_REGISTER_DECLARATION()
JASourceChoiseGAM();
JASourceChoiceGAM();
virtual ~JASourceChoiseGAM();
virtual ~JASourceChoiceGAM();
virtual bool Initialise(MARTe::StructuredDataI & data);

View File

@@ -23,11 +23,11 @@
# $Id: Makefile.inc 3 2012-01-15 16:26:07Z aneto $
#
#############################################################
OBJSX=JASourceChoiseGAM.x
OBJSX=JASourceChoiceGAM.x
PACKAGE=GAMs
ROOT_DIR=../../../../obj
ROOT_DIR=../../
MAKEDEFAULTDIR=$(MARTe2_DIR)/MakeDefaults
include $(MAKEDEFAULTDIR)/MakeStdLibDefs.$(TARGET)
@@ -48,8 +48,8 @@ INCLUDES += -I$(MARTe2_DIR)/Source/Core/FileSystem/L3Streams
all: $(OBJS) $(SUBPROJ) \
$(BUILD_DIR)/JASourceChoiseGAM$(LIBEXT) \
$(BUILD_DIR)/JASourceChoiseGAM$(DLLEXT)
$(BUILD_DIR)/JASourceChoiceGAM$(LIBEXT) \
$(BUILD_DIR)/JASourceChoiceGAM$(DLLEXT)
echo $(OBJS)
include $(MAKEDEFAULTDIR)/MakeStdLibRules.$(TARGET)

View File

@@ -27,7 +27,7 @@
SPB = JAMessageGAM.x JAPreProgrammedGAM.x JAModeControlGAM.x \
JAWFRecordGAM.x JATriangleWaveGAM.x JARampupGAM.x \
JARTStateMachineGAM.x JASDNRTStateMachineGAM.x JATerminalInterfaceGAM.x \
JABitSumGAM.x JAConditionalSignalUpdateGAM.x JASourceChoiseGAM.x JABitReverseGAM.x \
JABitSumGAM.x JAConditionalSignalUpdateGAM.x JASourceChoiceGAM.x JABitReverseGAM.x \
JAESDNTimeCompareGAM.x
MAKEDEFAULTDIR=$(MARTe2_DIR)/MakeDefaults