Cleaned up GAMS and duplicated code
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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_ */
|
||||
|
||||
Reference in New Issue
Block a user