Skip to content
Snippets Groups Projects
Commit cbb82edc authored by athatheocsd's avatar athatheocsd
Browse files

Removed stateOfEventAction into a boolean

parent 2d6343dd
No related branches found
No related tags found
No related merge requests found
...@@ -26,12 +26,12 @@ ...@@ -26,12 +26,12 @@
class EventActionService : public Service { class EventActionService : public Service {
public: public:
uint8_t eventActionFunctionStatus; // Indicates if actions are enabled uint8_t eventActionFunctionStatus; // Indicates if actions are enabled
std::bitset<256> stateOfEventAction;
struct EventActionDefinition { struct EventActionDefinition {
uint8_t empty = 1; // 1 means empty, 0 means full bool empty = true; // 1 means empty, 0 means full
uint16_t applicationId = 0; uint16_t applicationId = 0;
uint16_t eventDefinitionID = 65535; uint16_t eventDefinitionID = 65535;
String<64> request = ""; String<64> request = "";
bool enabled = false;
}; };
// If the size is changed maybe then indexOfAvailableSlots as well as the initiating loop in the // If the size is changed maybe then indexOfAvailableSlots as well as the initiating loop in the
// constructor should be changed from uint16_t // constructor should be changed from uint16_t
...@@ -40,7 +40,6 @@ public: ...@@ -40,7 +40,6 @@ public:
EventActionService() { EventActionService() {
serviceType = 19; serviceType = 19;
eventActionFunctionStatus = enabledFunction; eventActionFunctionStatus = enabledFunction;
stateOfEventAction.set();
} }
/** /**
......
...@@ -14,7 +14,7 @@ void EventActionService::addEventActionDefinitions(Message message) { ...@@ -14,7 +14,7 @@ void EventActionService::addEventActionDefinitions(Message message) {
19) { 19) {
uint16_t index = 0; uint16_t index = 0;
uint8_t flag = 0; // used as boolean 0 is false, 1 is true uint8_t flag = 0; // used as boolean 0 is false, 1 is true
while (eventActionDefinitionArray[index].empty == 0) { while (eventActionDefinitionArray[index].empty == false) {
if (index == 255) { // 255 should be changed depending on size of the array if (index == 255) { // 255 should be changed depending on size of the array
flag = 1; flag = 1;
break; break;
...@@ -23,14 +23,14 @@ void EventActionService::addEventActionDefinitions(Message message) { ...@@ -23,14 +23,14 @@ void EventActionService::addEventActionDefinitions(Message message) {
} }
if (flag == 0) { if (flag == 0) {
char data[128]; char data[128];
eventActionDefinitionArray[index].empty = 0; eventActionDefinitionArray[index].empty = false;
eventActionDefinitionArray[index].enabled = true;
eventActionDefinitionArray[index].applicationId = message.readEnum16(); eventActionDefinitionArray[index].applicationId = message.readEnum16();
eventActionDefinitionArray[index].eventDefinitionID = message.readEnum16(); eventActionDefinitionArray[index].eventDefinitionID = message.readEnum16();
// Tests pass with message.dataSize - 3, message.dataSize - 4, but not // Tests pass with message.dataSize - 3, message.dataSize - 4, but not
// message.dataSize - 5 // message.dataSize - 5
message.readString(data, message.dataSize); message.readString(data, message.dataSize);
eventActionDefinitionArray[index].request = String<64>(data); eventActionDefinitionArray[index].request = String<64>(data);
stateOfEventAction[index] = 1;
} }
} }
} }
...@@ -47,11 +47,11 @@ void EventActionService::deleteEventActionDefinitions(Message message) { ...@@ -47,11 +47,11 @@ void EventActionService::deleteEventActionDefinitions(Message message) {
while (index < 255) { while (index < 255) {
if (eventActionDefinitionArray[index].applicationId == applicationID && if (eventActionDefinitionArray[index].applicationId == applicationID &&
eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID) { eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID) {
eventActionDefinitionArray[index].empty = 1; eventActionDefinitionArray[index].empty = true;
eventActionDefinitionArray[index].eventDefinitionID = 65535; eventActionDefinitionArray[index].eventDefinitionID = 65535;
eventActionDefinitionArray[index].request = ""; eventActionDefinitionArray[index].request = "";
eventActionDefinitionArray[index].applicationId = 0; eventActionDefinitionArray[index].applicationId = 0;
stateOfEventAction[index] = 0; eventActionDefinitionArray[index].enabled = false;
} }
index++; index++;
} }
...@@ -66,8 +66,9 @@ void EventActionService::deleteAllEventActionDefinitions(Message message) { ...@@ -66,8 +66,9 @@ void EventActionService::deleteAllEventActionDefinitions(Message message) {
if (message.messageType == 3 && message.packetType == Message::TC && message.serviceType if (message.messageType == 3 && message.packetType == Message::TC && message.serviceType
== 19) { == 19) {
for (uint16_t index = 0; index < 256; index++) { for (uint16_t index = 0; index < 256; index++) {
if (eventActionDefinitionArray[index].empty == 0) { if (eventActionDefinitionArray[index].empty == false) {
eventActionDefinitionArray[index].empty = 1; eventActionDefinitionArray[index].empty = true;
eventActionDefinitionArray[index].enabled = false;
eventActionDefinitionArray[index].eventDefinitionID = 65535; eventActionDefinitionArray[index].eventDefinitionID = 65535;
eventActionDefinitionArray[index].request = ""; eventActionDefinitionArray[index].request = "";
eventActionDefinitionArray[index].applicationId = 0; eventActionDefinitionArray[index].applicationId = 0;
...@@ -88,7 +89,7 @@ void EventActionService::enableEventActionDefinitions(Message message) { ...@@ -88,7 +89,7 @@ void EventActionService::enableEventActionDefinitions(Message message) {
while (index < 255) { while (index < 255) {
if (eventActionDefinitionArray[index].applicationId == applicationID && if (eventActionDefinitionArray[index].applicationId == applicationID &&
eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID) { eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID) {
stateOfEventAction[index] = 1; eventActionDefinitionArray[index].enabled = true;
} }
index++; index++;
} }
...@@ -109,7 +110,7 @@ void EventActionService::disableEventActionDefinitions(Message message) { ...@@ -109,7 +110,7 @@ void EventActionService::disableEventActionDefinitions(Message message) {
while (index < 256) { while (index < 256) {
if (eventActionDefinitionArray[index].applicationId == applicationID && if (eventActionDefinitionArray[index].applicationId == applicationID &&
eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID) { eventActionDefinitionArray[index].eventDefinitionID == eventDefinitionID) {
stateOfEventAction[index] = 0; eventActionDefinitionArray[index].enabled = false;
} }
index++; index++;
} }
...@@ -131,16 +132,16 @@ void EventActionService::eventActionStatusReport() { ...@@ -131,16 +132,16 @@ void EventActionService::eventActionStatusReport() {
Message report = createTM(7); Message report = createTM(7);
uint8_t count = 0; uint8_t count = 0;
for (uint16_t i = 0; i < 256; i++) { for (uint16_t i = 0; i < 256; i++) {
if (eventActionDefinitionArray[i].empty == 0) { if (eventActionDefinitionArray[i].empty == false) {
count++; count++;
} }
} }
report.appendUint8(count); report.appendUint8(count);
for (uint16_t i = 0; i < 256; i++) { for (uint16_t i = 0; i < 256; i++) {
if (eventActionDefinitionArray[i].empty == 0) { if (eventActionDefinitionArray[i].empty == false) {
report.appendEnum16(eventActionDefinitionArray[i].applicationId); report.appendEnum16(eventActionDefinitionArray[i].applicationId);
report.appendEnum16(eventActionDefinitionArray[i].eventDefinitionID); report.appendEnum16(eventActionDefinitionArray[i].eventDefinitionID);
report.appendUint8(stateOfEventAction[i]); report.appendBoolean(eventActionDefinitionArray[i].enabled);
} }
} }
storeMessage(report); storeMessage(report);
...@@ -169,7 +170,9 @@ void EventActionService::executeAction(uint16_t eventID) { ...@@ -169,7 +170,9 @@ void EventActionService::executeAction(uint16_t eventID) {
if (eventActionFunctionStatus == enabledFunction) { if (eventActionFunctionStatus == enabledFunction) {
uint16_t i = 0; uint16_t i = 0;
while (i < 256) { while (i < 256) {
if (eventActionDefinitionArray[i].empty == 0) { if (eventActionDefinitionArray[i].empty == false &&
eventActionDefinitionArray[i].enabled ==
true) {
if (eventActionDefinitionArray[i].eventDefinitionID == eventID) { if (eventActionDefinitionArray[i].eventDefinitionID == eventID) {
MessageParser messageParser; MessageParser messageParser;
Message message = messageParser.parseRequestTC( Message message = messageParser.parseRequestTC(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment