Page MenuHomePhorge

No OneTemporary

Size
171 KB
Referenced Files
None
Subscribers
None
diff --git a/Version_Max_07_05_2018_CMake/src/Agent.cpp b/Version_Max_07_05_2018_CMake/src/Agent.cpp
index ec72717..7f5ed8f 100755
--- a/Version_Max_07_05_2018_CMake/src/Agent.cpp
+++ b/Version_Max_07_05_2018_CMake/src/Agent.cpp
@@ -1,262 +1,237 @@
#include "Agent.h"
#include "printError.h"
#include <stdio.h>
-//TODO: Move this include to ControlModule
+// TODO: Move this include to ControlModule
#include "instruction_set_architecture.h"
/*
#include "Evaluation.h"
#include "instruction_set_architecture.h"
*/
-#define PRINT_READING
+//TODO: do we need PRINT_READING .. I cannot find it anywhere!
+//#define PRINT_READING
-void Agent :: init_agent() {
- sensorHandlerOfAgent = NULL;
- slaveAgentHandlerOfAgent = NULL;
- masterAgentHandlerOfAgent = NULL;
- stateHandler = NULL;
+//#define PRINT
- workingCycleCounter = 0;
-}
-Agent :: Agent() {
- set_name(NO_NAME);
- init_agent();
+void Agent ::init_agent() {
+ sensorHandlerOfAgent = NULL;
+ slaveAgentHandlerOfAgent = NULL;
+ masterAgentHandlerOfAgent = NULL;
+ stateHandler = NULL;
+
+ workingCycleCounter = 0;
}
-Agent :: Agent(string name) {
- set_name(name);
- init_agent();
+Agent ::Agent() {
+ set_name(NO_NAME);
+ init_agent();
+}
+Agent ::Agent(string name) {
+ set_name(name);
+ init_agent();
}
-bool Agent :: set_sensorHandlerOfAgent() {
- sensorHandlerOfAgent = new SensorHandlerOfAgent();
+bool Agent ::set_sensorHandlerOfAgent() {
+ sensorHandlerOfAgent = new SensorHandlerOfAgent();
- if(sensorHandlerOfAgent == NULL) {
- printError("Couldn't create Sensor Handler!");
- return false;
- }
- return true;
+ if (sensorHandlerOfAgent == NULL) {
+ printError("Couldn't create Sensor Handler!");
+ return false;
+ }
+ return true;
}
-bool Agent :: del_sensorHandlerOfAgent() {
- if(sensorHandlerOfAgent != NULL) {
- //TODO: Unmount/delete all sensorSlots with everything inside (history module, confidence module, ...)
- delete sensorHandlerOfAgent;
- return true;
- }
- return false;
+bool Agent ::del_sensorHandlerOfAgent() {
+ if (sensorHandlerOfAgent != NULL) {
+ // TODO: Unmount/delete all sensorSlots with everything inside (history
+ // module, confidence module, ...)
+ delete sensorHandlerOfAgent;
+ return true;
+ }
+ return false;
}
-SensorHandlerOfAgent* Agent :: get_sensorHandlerOfAgent() {
- if(sensorHandlerOfAgent == NULL) {
- set_sensorHandlerOfAgent();
- }
- return sensorHandlerOfAgent;
+SensorHandlerOfAgent *Agent ::get_sensorHandlerOfAgent() {
+ if (sensorHandlerOfAgent == NULL) {
+ set_sensorHandlerOfAgent();
+ }
+ return sensorHandlerOfAgent;
}
-bool Agent :: set_slaveAgentHandlerOfAgent() {
- slaveAgentHandlerOfAgent = new SlaveAgentHandlerOfAgent();
+bool Agent ::set_slaveAgentHandlerOfAgent() {
+ slaveAgentHandlerOfAgent = new SlaveAgentHandlerOfAgent();
- if(slaveAgentHandlerOfAgent == NULL) {
- printError("Couldn't create Slave Agent Handler!");
- return false;
- }
- return true;
+ if (slaveAgentHandlerOfAgent == NULL) {
+ printError("Couldn't create Slave Agent Handler!");
+ return false;
+ }
+ return true;
}
-bool Agent :: del_slaveAgentHandlerOfAgent() {
- if(slaveAgentHandlerOfAgent != NULL) {
- //TODO: Unmount/delete all SlaveAgentSlots with everything inside (history module, confidence module, ...)
- delete slaveAgentHandlerOfAgent;
- return true;
- }
- return false;
+bool Agent ::del_slaveAgentHandlerOfAgent() {
+ if (slaveAgentHandlerOfAgent != NULL) {
+ // TODO: Unmount/delete all SlaveAgentSlots with everything inside (history
+ // module, confidence module, ...)
+ delete slaveAgentHandlerOfAgent;
+ return true;
+ }
+ return false;
}
-SlaveAgentHandlerOfAgent* Agent :: get_slaveAgentHandlerOfAgent() {
- if(slaveAgentHandlerOfAgent == NULL) {
- set_slaveAgentHandlerOfAgent();
- }
- return slaveAgentHandlerOfAgent;
+SlaveAgentHandlerOfAgent *Agent ::get_slaveAgentHandlerOfAgent() {
+ if (slaveAgentHandlerOfAgent == NULL) {
+ set_slaveAgentHandlerOfAgent();
+ }
+ return slaveAgentHandlerOfAgent;
}
-bool Agent :: set_masterAgentHandlerOfAgent() {
- masterAgentHandlerOfAgent = new MasterAgentHandlerOfAgent();
+bool Agent ::set_masterAgentHandlerOfAgent() {
+ masterAgentHandlerOfAgent = new MasterAgentHandlerOfAgent();
- if(masterAgentHandlerOfAgent == NULL) {
- printError("Couldn't create Master Agent Handler!");
- return false;
- }
- return true;
+ if (masterAgentHandlerOfAgent == NULL) {
+ printError("Couldn't create Master Agent Handler!");
+ return false;
+ }
+ return true;
}
-bool Agent :: del_masterAgentHandlerOfAgent() {
- if(masterAgentHandlerOfAgent != NULL) {
- //TODO: Unmount/delete (all) MasterAgentSlot(s) with everything inside
- delete masterAgentHandlerOfAgent;
- return true;
- }
- return false;
+bool Agent ::del_masterAgentHandlerOfAgent() {
+ if (masterAgentHandlerOfAgent != NULL) {
+ // TODO: Unmount/delete (all) MasterAgentSlot(s) with everything inside
+ delete masterAgentHandlerOfAgent;
+ return true;
+ }
+ return false;
}
-MasterAgentHandlerOfAgent* Agent :: get_masterAgentHandlerOfAgent() {
- if(masterAgentHandlerOfAgent == NULL) {
- set_masterAgentHandlerOfAgent();
- }
- return masterAgentHandlerOfAgent;
+MasterAgentHandlerOfAgent *Agent ::get_masterAgentHandlerOfAgent() {
+ if (masterAgentHandlerOfAgent == NULL) {
+ set_masterAgentHandlerOfAgent();
+ }
+ return masterAgentHandlerOfAgent;
}
-bool Agent :: set_stateHandler() {
- stateHandler = new StateHandler();
+bool Agent ::set_stateHandler() {
+ stateHandler = new StateHandler();
- if(stateHandler == NULL) {
- printError("Couldn't create Master Agent Handler!");
- return false;
- }
- return true;
+ if (stateHandler == NULL) {
+ printError("Couldn't create Master Agent Handler!");
+ return false;
+ }
+ return true;
}
bool Agent ::set_stateHandler(std::string csvWriterPath) {
stateHandler = new StateHandler(NO_NAME, csvWriterPath);
if (stateHandler == NULL) {
printError("Couldn't create Master Agent Handler!");
return false;
}
return true;
}
-bool Agent ::set_stateHandler(
- std::string name, std::string csvWriterPath) {
+bool Agent ::set_stateHandler(std::string name, std::string csvWriterPath) {
stateHandler = new StateHandler(name, csvWriterPath);
if (stateHandler == NULL) {
printError("Couldn't create Master Agent Handler!");
return false;
}
return true;
}
-
-bool Agent :: set_stateHandler(StateHandler* stateHandler) {
- if(stateHandler == NULL) {
- this->stateHandler = stateHandler;
- return true;
- }
- return false;
-}
-
-
-bool Agent :: del_stateHandler() {
- if(stateHandler != NULL) {
- //TODO: Unmount/delete (all) MasterAgentSlot(s) with everything inside
- delete stateHandler;
- return true;
- }
- return false;
-}
-
-StateHandler* Agent :: get_stateHandler() {
-
- if(stateHandler == NULL) {
- set_stateHandler();
- }
-
- return stateHandler;
-}
-
-
-StateHandler* Agent::get_stateHandler2() {
-
- return stateHandler;
+bool Agent ::set_stateHandler(StateHandler *stateHandler) {
+ if (stateHandler == NULL) {
+ this->stateHandler = stateHandler;
+ return true;
+ }
+ return false;
}
-Agent::~Agent()
-{
- del_masterAgentHandlerOfAgent();
- del_slaveAgentHandlerOfAgent();
- del_sensorHandlerOfAgent();
- del_stateHandler();
+bool Agent ::del_stateHandler() {
+ if (stateHandler != NULL) {
+ // TODO: Unmount/delete (all) MasterAgentSlot(s) with everything inside
+ delete stateHandler;
+ return true;
+ }
+ return false;
}
+StateHandler *Agent ::get_stateHandler() {
-void Agent :: trigger(unsigned int cycle) {
-
- if (workingCycleCounter < get_workingCycle())
- workingCycleCounter++;
- else
- workingCycleCounter = 1;
-
- if (workingCycleCounter == 1) {
-
- //TODO: make control_module to set the method of operating for each agent individual
-
- //Job: Read all sensory data
- if(sensorHandlerOfAgent != NULL) {
- //printf("%s->sensorHandler: ", name);
- sensorHandlerOfAgent->read_allSensorValues();
- }
-
- //Job: Read all slave agent data
- if(slaveAgentHandlerOfAgent != NULL) {
- //TODO: do this in HistoryModule //TODO: this for all slots (not only for slaveagents)
- slaveAgentHandlerOfAgent->saveAllValuesInHistory();
- //getchar();
-
- slaveAgentHandlerOfAgent->read_allSlaveAgentValues();
- }
-
- //Job: Just pass the Sensory Data (without abstraction) to master
- if(masterAgentHandlerOfAgent != NULL) {
- if(sensorHandlerOfAgent != NULL) {
- vector<SensorSlotOfAgent*>* vSensoryData = sensorHandlerOfAgent->get_vMountedSensors();
- for(auto &sensorSlot : *vSensoryData) {
- //TODO: also for int
- float sensorValue;
- if(sensorSlot->get_sensorValue(&sensorValue)) {
- masterAgentHandlerOfAgent->pass_msgToSendBuffer(ISA_SensoryData);
- masterAgentHandlerOfAgent->pass_msgToSendBuffer(sensorValue);
- }
- }
- }
- masterAgentHandlerOfAgent->send_msgs();
- }
-
-
- if (stateHandler != NULL) {
- stateHandler->trigger(cycle);
- }
-
-
- }
+ if (stateHandler == NULL) {
+ set_stateHandler();
+ }
+ return stateHandler;
+}
+
+StateHandler *Agent::get_stateHandler2() { return stateHandler; }
+
+Agent::~Agent() {
+ del_masterAgentHandlerOfAgent();
+ del_slaveAgentHandlerOfAgent();
+ del_sensorHandlerOfAgent();
+ del_stateHandler();
+}
+
+void Agent ::trigger(unsigned int cycle) {
+
+ if (workingCycleCounter < get_workingCycle())
+ workingCycleCounter++;
+ else
+ workingCycleCounter = 1;
+
+ if (workingCycleCounter == 1) {
+
+ // TODO: make control_module to set the method of operating for each agent
+ // individual
+
+ // Job: Read all sensory data
+ if (sensorHandlerOfAgent != NULL) {
+ // printf("%s->sensorHandler: ", name);
+ sensorHandlerOfAgent->read_allSensorValues();
+ }
+
+ // Job: Read all slave agent data
+ if (slaveAgentHandlerOfAgent != NULL) {
+ //NOTE: at the moment we don't need to save here the values because the stateHandler saves them already.
+ //TODO: we could save them here (in slaveAgentHandlerOfAgent), and the stateHandler couls read them from there.
+ // slaveAgentHandlerOfAgent->saveAllValuesInHistory();
+
+ slaveAgentHandlerOfAgent->read_allSlaveAgentValues();
+ }
+
+ // Job: Just pass the Sensory Data (without abstraction) to master
+ if (masterAgentHandlerOfAgent != NULL) {
+ if (sensorHandlerOfAgent != NULL) {
+ vector<SensorSlotOfAgent *> *vSensoryData =
+ sensorHandlerOfAgent->get_vMountedSensors();
+ for (auto &sensorSlot : *vSensoryData) {
+ // TODO: also for int
+ float sensorValue;
+ if (sensorSlot->get_sensorValue(&sensorValue)) {
+ masterAgentHandlerOfAgent->pass_msgToSendBuffer(ISA_SensoryData);
+ masterAgentHandlerOfAgent->pass_msgToSendBuffer(sensorValue);
+#ifdef PRINT
+ printf("Agent %s sends: %f\n", name.c_str(), sensorValue);
+#endif // PRINT
+ }
+ }
+ }
+ masterAgentHandlerOfAgent->send_msgs();
+ }
+
+ if (stateHandler != NULL) {
+#ifdef PRINT
+ printf("agent %s starts state handler\n", name.c_str());
+#endif // PRINT
+ stateHandler->trigger(cycle);
+ }
+ }
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Version_Max_07_05_2018_CMake/src/Channel.cpp b/Version_Max_07_05_2018_CMake/src/Channel.cpp
index 2f66a50..f240e56 100755
--- a/Version_Max_07_05_2018_CMake/src/Channel.cpp
+++ b/Version_Max_07_05_2018_CMake/src/Channel.cpp
@@ -1,418 +1,406 @@
#include "Channel.h"
#include <stdio.h>
#define MAX_BUFFER_LENGTH 100
-#define PRINT
+//#define PRINT
//#define STOP_AFTER_CHANNEL_TRANSFARED
void Channel ::init_channel() {
maxBufferLength = MAX_BUFFER_LENGTH;
transferRate = MAX_BUFFER_LENGTH;
}
Channel ::Channel() { init_channel(); }
Channel ::Channel(std::string name) {
set_name(name);
init_channel();
}
bool Channel ::set_maxBufferLength(unsigned int maxBufferLength) {
if (maxBufferLength <= MAX_BUFFER_LENGTH) {
this->maxBufferLength = maxBufferLength;
return true;
}
return false;
}
unsigned int Channel ::get_maxBufferLength() { return maxBufferLength; }
unsigned int Channel ::get_avlInputBufferUp() {
return maxBufferLength - lInputMsgBufferUp.size();
}
unsigned int Channel ::get_avlOutputBufferUp() {
return maxBufferLength - lOutputMsgBufferUp.size();
}
unsigned int Channel ::get_avlInputBufferDown() {
return maxBufferLength - lInputMsgBufferDown.size();
}
unsigned int Channel ::get_avlOutputBufferDown() {
return maxBufferLength - lOutputMsgBufferDown.size();
}
bool Channel ::set_transferRate(unsigned int transferRate) {
if (transferRate <= MAX_BUFFER_LENGTH) {
this->transferRate = transferRate;
return true;
}
return false;
}
unsigned int Channel ::get_transferRate() { return transferRate; }
bool Channel ::add_msgAtBegin(list<Message *> *buffer, Message *message) {
try {
buffer->push_front(message);
} catch (bad_alloc &error) {
+ cerr << "bad_alloc caught: " << error.what() << endl;
delete message;
return false;
}
return true;
}
-//removes the message from the lsit and also delets the message
+// removes the message from the lsit and also delets the message
bool Channel ::del_msgAtBegin(list<Message *> *buffer) {
try {
if (buffer != NULL && buffer->empty() == false) {
Message *first_Message = buffer->front();
// NOTE: I had to change the order of pop and delete. Before, i crashed.
buffer->pop_front();
delete first_Message;
- }
+ }
} catch (bad_alloc &error) {
+ cerr << "bad_alloc caught: " << error.what() << endl;
return false;
}
return true;
}
-//just removes the message from the list
+// just removes the message from the list
bool Channel::rem_msgAtBegin(list<Message *> *buffer) {
try {
if (buffer != NULL && buffer->empty() == false) {
buffer->pop_front();
}
} catch (bad_alloc &error) {
+ cerr << "bad_alloc caught: " << error.what() << endl;
return false;
}
return true;
}
bool Channel ::add_msgAtEnd(list<Message *> *buffer, Message *message) {
try {
buffer->push_back(message);
} catch (bad_alloc &error) {
cerr << "bad_alloc caught: " << error.what() << endl;
delete message;
return false;
}
return true;
}
bool del_msgAtEnd(list<Message *> *buffer) {
try {
Message *last_Message = buffer->back();
delete last_Message;
buffer->pop_back();
} catch (bad_alloc &error) {
+ cerr << "bad_alloc caught: " << error.what() << endl;
return false;
}
return true;
}
bool Channel ::send_MsgUp(Message *message) {
if (message != NULL) {
if (transferRate == 0) {
// TODO: at the moment only one packet (in the front) gets deleted if
// buffer is full. However, the whole message (instruction+value) should
// be deleted in case of a full buffer
if (lOutputMsgBufferUp.size() == maxBufferLength) {
del_msgAtBegin(&lOutputMsgBufferUp);
}
return add_msgAtEnd(&lOutputMsgBufferUp, message);
} else {
if (lInputMsgBufferUp.size() == maxBufferLength) {
// TODO: at the moment only one packet (in the front) gets deleted if
// buffer is full. However, the whole message (instruction+value) should
// be deleted in case of a full buffer
del_msgAtBegin(&lInputMsgBufferUp);
}
return add_msgAtEnd(&lInputMsgBufferUp, message);
}
}
// TODO: check if NULL is a good default return value
return NULL;
}
bool Channel ::send_MsgUp(float msg) {
Message *message = new Message(msg);
return send_MsgUp(message);
}
bool Channel ::send_MsgUp(int msg) {
Message *message = new Message(msg);
return send_MsgUp(message);
}
// blub1
bool Channel ::get_MsgUp(float *msg) {
if (isThereFloatMsgUp()) {
float tempMsg;
if (lOutputMsgBufferUp.front()->getMsg(&tempMsg)) {
*msg = tempMsg;
del_msgAtBegin(&lOutputMsgBufferUp);
return true;
}
}
return false;
}
bool Channel ::get_MsgUp(int *msg) {
if (isThereIntMsgUp()) {
int tempMsg;
if (lOutputMsgBufferUp.front()->getMsg(&tempMsg)) {
*msg = tempMsg;
del_msgAtBegin(&lOutputMsgBufferUp);
return true;
}
}
return false;
}
bool Channel ::isThereFloatMsgUp() {
if (lOutputMsgBufferUp.size() > 0) {
if (lOutputMsgBufferUp.front() != NULL) {
return lOutputMsgBufferUp.front()->isMsgFloat();
}
}
return false;
}
bool Channel ::isThereIntMsgUp() {
- printf("a\n");
if (lOutputMsgBufferUp.size() > 0) {
- printf("b\n");
if (lOutputMsgBufferUp.front() != NULL) {
- printf("c\n");
return lOutputMsgBufferUp.front()->isMsgInt();
}
}
return false;
}
bool Channel ::send_MsgDown(Message *message) {
if (message != NULL) {
if (transferRate == 0) {
if (lOutputMsgBufferDown.size() == maxBufferLength) {
del_msgAtBegin(&lOutputMsgBufferDown);
}
return add_msgAtEnd(&lOutputMsgBufferDown, message);
} else {
if (lInputMsgBufferDown.size() == maxBufferLength) {
del_msgAtBegin(&lInputMsgBufferDown);
}
return add_msgAtEnd(&lInputMsgBufferDown, message);
}
}
// TODO: check if NULL is a good default return value
return NULL;
}
bool Channel ::send_MsgDown(float msg) {
Message *message = new Message(msg);
return send_MsgDown(message);
}
bool Channel ::send_MsgDown(int msg) {
Message *message = new Message(msg);
return send_MsgDown(message);
}
bool Channel ::get_MsgDown(float *msg) {
if (isThereFloatMsgDown()) {
float tempMsg;
if (lOutputMsgBufferDown.front()->getMsg(&tempMsg)) {
*msg = tempMsg;
del_msgAtBegin(&lOutputMsgBufferDown);
return true;
}
}
return false;
}
bool Channel ::get_MsgDown(int *msg) {
if (isThereIntMsgDown()) {
int tempMsg;
if (lOutputMsgBufferDown.front()->getMsg(&tempMsg)) {
*msg = tempMsg;
del_msgAtBegin(&lOutputMsgBufferDown);
return true;
}
}
return false;
}
bool Channel ::isThereFloatMsgDown() {
if (lOutputMsgBufferDown.size() > 0) {
if (lOutputMsgBufferDown.front() != NULL) {
return lOutputMsgBufferDown.front()->isMsgFloat();
}
}
return false;
}
bool Channel ::isThereIntMsgDown() {
if (lOutputMsgBufferDown.size() > 0) {
if (lOutputMsgBufferDown.front() != NULL) {
return lOutputMsgBufferDown.front()->isMsgInt();
}
}
return false;
}
bool Channel ::transferMsgs(list<Message *> *dest_buffer,
list<Message *> *src_buffer) {
unsigned int NumOfMsgsToMove;
if (transferRate <= src_buffer->size()) {
NumOfMsgsToMove = transferRate;
} else {
NumOfMsgsToMove = src_buffer->size();
}
if (NumOfMsgsToMove <= maxBufferLength - dest_buffer->size()) {
for (unsigned int i = 0; i < NumOfMsgsToMove; i++) {
if (add_msgAtEnd(dest_buffer, src_buffer->front())) {
-#ifdef PRINT
- if (src_buffer->front()->isMsgFloat()) {
- float m;
- dest_buffer->back()->getMsg(&m);
- printf("Sent: %f - Channel %s\n", m, name.c_str());
- } else if (src_buffer->front()->isMsgInt()) {
- int m;
- dest_buffer->back()->getMsg(&m);
- printf("Sent: %i - Channel %s\n", m, name.c_str());
- } else {
- printf("nothing!!!!!!!!!!!\n");
- }
- getchar();
-#endif // PRINT
- //just remove the message from the source buffer, don't delete it, it is still needed in the output buffer!
+ // just remove the message from the source buffer, don't delete it, it is
+ // still needed in the output buffer!
if (!rem_msgAtBegin(src_buffer)) {
return false;
}
} else {
return false;
}
}
return true;
}
return false;
}
bool Channel ::trigger() {
#ifdef PRINT
printf("Before - in_up %u, out_up %u, in_dn %u, out_dn %u - Channel %s\n",
(int)lInputMsgBufferUp.size(), (int)lOutputMsgBufferUp.size(),
(int)lInputMsgBufferDown.size(), (int)lOutputMsgBufferDown.size(),
name.c_str());
#endif // PRINT
// TODO: there are two time the same transferMsgs functions called with
// exactly the same buffers.. I guess one side should be with "...BufferDown"
bool flag_worked = transferMsgs(&lOutputMsgBufferUp, &lInputMsgBufferUp) &&
transferMsgs(&lOutputMsgBufferDown, &lInputMsgBufferDown);
// bool flag_worked = transferMsgs(&lOutputMsgBufferUp, &lInputMsgBufferUp) &&
// transferMsgs(&lOutputMsgBufferUp, &lInputMsgBufferUp);
#ifdef PRINT
printf("After - in_up %u, out_up %u, in_dn %u, out_dn %u - Channel %s\n\n",
(int)lInputMsgBufferUp.size(), (int)lOutputMsgBufferUp.size(),
(int)lInputMsgBufferDown.size(), (int)lOutputMsgBufferDown.size(),
name.c_str());
-
+ /*
printf("outputBufferUp filled with:\n");
for (auto msg : lOutputMsgBufferUp) {
if (msg == NULL) {
printf("msg = NULL!!!!!!!!!!!!!!!!!!!!!!!!!\n");
} else {
-
- if (msg->isMsgFloat()) {
- float m;
- msg->getMsg(&m);
- printf("Send: %f - Channel %s\n", m, name.c_str());
- } else if (msg->isMsgInt()) {
- int m;
- msg->getMsg(&m);
- printf("Send: %i - Channel %s\n", m, name.c_str());
- } else {
- printf("empty!\n");
+
+ if (msg->isMsgFloat()) {
+ float m;
+ msg->getMsg(&m);
+ printf("Send: %f - Channel %s\n", m, name.c_str());
+ } else if (msg->isMsgInt()) {
+ int m;
+ msg->getMsg(&m);
+ printf("Send: %i - Channel %s\n", m, name.c_str());
+ } else {
+ printf("empty!\n");
+ }
}
- }
}
-
+ */
#endif // PRINT
#ifdef STOP_AFTER_CHANNEL_TRANSFARED
getchar();
#endif // #ifdef STOP_AFTER_CHANNEL_TRANSFARED
return flag_worked;
}
bool Channel ::delete_all_InputMsgBufferUp() {
Message *cur_Message;
unsigned int cur_index_Message = 0;
unsigned int size_li_Inp_MsgBufUp = lInputMsgBufferUp.size();
// changed - "cur_index_Message" to "cur_index_Message++" .. is it right?
for (cur_index_Message = 0; cur_index_Message < size_li_Inp_MsgBufUp;
cur_index_Message++) {
cur_Message = lInputMsgBufferUp.front();
delete cur_Message;
lInputMsgBufferUp.pop_front();
}
return true; // added by Ali, it is an error in VS.
}
bool Channel ::delete_all_OuputMsgBufferUp() {
Message *cur_Message;
unsigned int cur_index_Message = 0;
unsigned int size_li_Out_MsgBufUp = lOutputMsgBufferUp.size();
// changed - "cur_index_Message" to "cur_index_Message++" .. is it right?
for (cur_index_Message = 0; cur_index_Message < size_li_Out_MsgBufUp;
cur_index_Message++) {
cur_Message = lOutputMsgBufferUp.front();
delete cur_Message;
lOutputMsgBufferUp.pop_front();
}
return true; // added by Ali, it is an error in VS.
}
bool Channel ::delete_all_InputMsgBufferDown() {
Message *cur_Message;
unsigned int cur_index_Message = 0;
unsigned int size_li_Out_MsgBufDown = lInputMsgBufferDown.size();
// changed - "cur_index_Message" to "cur_index_Message++" .. is it right?
for (cur_index_Message = 0; cur_index_Message < size_li_Out_MsgBufDown;
cur_index_Message++) {
cur_Message = lInputMsgBufferDown.front();
delete cur_Message;
lInputMsgBufferDown.pop_front();
}
return true; // added by Ali, it is an error in VS.
}
bool Channel ::delete_all_OutputMsgBufferDown() {
Message *cur_Message;
unsigned int cur_index_Message = 0;
unsigned int size_li_Out_MsgBufDown = lOutputMsgBufferDown.size();
// changed - "cur_index_Message" to "cur_index_Message++" .. is it right?
for (cur_index_Message = 0; cur_index_Message < size_li_Out_MsgBufDown;
cur_index_Message++) {
cur_Message = lOutputMsgBufferDown.front();
delete cur_Message;
lOutputMsgBufferDown.pop_front();
}
return true; // added by Ali, it is an error in VS.
}
Channel ::~Channel() {
delete_all_InputMsgBufferUp();
delete_all_OuputMsgBufferUp();
delete_all_InputMsgBufferDown();
delete_all_OutputMsgBufferDown();
}
diff --git a/Version_Max_07_05_2018_CMake/src/LinearFunctionBlock.cpp b/Version_Max_07_05_2018_CMake/src/LinearFunctionBlock.cpp
index 231eaf5..5863d0f 100755
--- a/Version_Max_07_05_2018_CMake/src/LinearFunctionBlock.cpp
+++ b/Version_Max_07_05_2018_CMake/src/LinearFunctionBlock.cpp
@@ -1,132 +1,131 @@
#include "LinearFunctionBlock.h"
#include <limits>
-#define PRINT
+//#define PRINT
LinearFunctionBlock::LinearFunctionBlock() {
#ifdef PRINT
printf(" > Linear Function Block created\n");
#endif // PRINT
}
LinearFunctionBlock::LinearFunctionBlock(std::string name) : Module(name) {
#ifdef PRINT
printf(" > %s (id:%u) created\n", name.c_str(), id);
#endif // PRINT
}
LinearFunctionBlock::~LinearFunctionBlock() {
LinearFunction* cur_Linear_Function;
unsigned int index_cur_Linear_Function;
unsigned int size_vec_Linear_Functions = vLinearFunctions.size();
for(index_cur_Linear_Function = 0; index_cur_Linear_Function < size_vec_Linear_Functions; index_cur_Linear_Function++){
cur_Linear_Function = vLinearFunctions[index_cur_Linear_Function];
delete cur_Linear_Function;
}
vLinearFunctions.clear();
}
//NOTE: for this time being, linear functions have to be filled beginning from lowest x value
bool LinearFunctionBlock::addLinearFunction(LinearFunction *linearFunction) {
if (vLinearFunctions.empty()) {
//printf("empty\n");
if (!(linearFunction->getDomain()->lowerBoundaryExist())) {
vLinearFunctions.push_back(linearFunction);
#ifdef PRINT
printf(" - added function\n");
#endif // PRINT
return true;
}
}
else
{
//printf("nicht empty\n");
if (vLinearFunctions.back()->getDomain()->upperBoundaryExist() && linearFunction->getDomain()->lowerBoundaryExist()) {
//printf("last function ub = %f, new function lb = %f\n", lLinearFunctions.back()->getDomain()->getUpperBoundary(), linearFunction->getDomain()->getLowerBoundary());
if (vLinearFunctions.back()->getDomain()->getUpperBoundary() == linearFunction->getDomain()->getLowerBoundary()) {
vLinearFunctions.push_back(linearFunction);
#ifdef PRINT
printf(" - added function\n");
#endif // PRINT
return true;
}
}
}
#ifdef PRINT
printf(" - couldn't add function\n");
#endif // PRINT
return false;
}
//NOTE: Specific Function for CAH Project (DATE18)
void LinearFunctionBlock::changeFunctionBlockIncr(float newBoundary) {
vLinearFunctions[1]->setDomain(true, (float)0, true, newBoundary);
vLinearFunctions[1]->setKandD((float)0, (float)0, newBoundary, (float)1);
vLinearFunctions[2]->setDomain(true, newBoundary, false);
}
void LinearFunctionBlock::changeFunctionBlockDecr(float newBoundary) {
vLinearFunctions[1]->setDomain(true, (float)0, true, newBoundary);
vLinearFunctions[1]->setKandD((float)0, (float)1, newBoundary, (float)0);
vLinearFunctions[2]->setDomain(true, newBoundary, false);
}
//TODO: jump discontinuity -> user must have the probability to set the value there
float LinearFunctionBlock::getY(float x) {
for (auto &linearFunction : vLinearFunctions) {
if (linearFunction->getDomain()->lowerBoundaryExist() && linearFunction->getDomain()->upperBoundaryExist()) {
if (x >= linearFunction->getDomain()->getLowerBoundary() && x <= linearFunction->getDomain()->getUpperBoundary()) {
return linearFunction->getY(x);
}
}
else if (linearFunction->getDomain()->lowerBoundaryExist()) {
if (x >= linearFunction->getDomain()->getLowerBoundary()) {
return linearFunction->getY(x);
}
}
else if (linearFunction->getDomain()->upperBoundaryExist()) {
if (x <= linearFunction->getDomain()->getUpperBoundary()) {
return linearFunction->getY(x);
}
}
else {
return linearFunction->getY(x);
}
}
//the next two lines should be deleted, but if you call the function getY you have to check for NaN!
printf("DEFAULT!!!!!!!!!!!\n");
getchar();
return std::numeric_limits<float>::quiet_NaN();
}
void LinearFunctionBlock ::printFunctionBlock(std::string name) {
printf("Name: %s", name.c_str());
-
for (auto &lf : vLinearFunctions) {
float lowerBoundary;
float upperBoundary;
if (lf->getDomain()->getLowerBoundary(&lowerBoundary))
printf("(x,y) %f, %f - ", lowerBoundary, lf->getY(lowerBoundary));
else
printf("oo - ");
if (lf->getDomain()->getUpperBoundary(&upperBoundary))
printf("%f, %f", upperBoundary, lf->getY(upperBoundary));
else
printf("oo");
printf("\n");
}
}
vector<LinearFunction*>& LinearFunctionBlock::get_all_LinearFunctions()
{
return vLinearFunctions;
}
diff --git a/Version_Max_07_05_2018_CMake/src/Message.cpp b/Version_Max_07_05_2018_CMake/src/Message.cpp
index 9d0ddae..4ef9b99 100755
--- a/Version_Max_07_05_2018_CMake/src/Message.cpp
+++ b/Version_Max_07_05_2018_CMake/src/Message.cpp
@@ -1,58 +1,54 @@
#include "Message.h"
#include <stdio.h>
#define MSG_IS_FLOAT true
#define MSG_IS_INT false
/*
Message :: Message() {
}
*/
-Message :: Message(float msg) {
- messageType = MSG_IS_FLOAT;
- fMsg = msg;
+Message ::Message(float msg) {
+ messageType = MSG_IS_FLOAT;
+ fMsg = msg;
}
-Message :: Message(int msg) {
- messageType = MSG_IS_INT;
- iMsg = msg;
+Message ::Message(int msg) {
+ messageType = MSG_IS_INT;
+ iMsg = msg;
}
-bool Message :: isMsgFloat() {
- if(messageType == MSG_IS_FLOAT) {
- return true;
- }
-
- if(messageType == MSG_IS_INT) {
- return false;
- }
-
-
- return false;
+bool Message ::isMsgFloat() {
+ // TODO: just make "return messageType == MSG_IS_FLOAT;"
+ if (messageType == MSG_IS_FLOAT) {
+ return true;
+ }
+ return false;
}
-bool Message :: isMsgInt() {
- if(messageType == MSG_IS_INT) {
- return true;
- }
- return false;
+bool Message ::isMsgInt() {
+ //TODO: just make "return messageType == MSG_IS_INT;"
+ if (messageType == MSG_IS_INT) {
+ return true;
+ }
+ return false;
}
-bool Message :: getMsg(float* msg) {
- if(messageType == MSG_IS_FLOAT) {
- *msg = fMsg;
- return true;
- }
- return false;
+bool Message ::getMsg(float *msg) {
+ if (messageType == MSG_IS_FLOAT) {
+ *msg = fMsg;
+ return true;
+ }
+ return false;
}
-bool Message :: getMsg(int* msg) {
- if(messageType == MSG_IS_INT) {
- *msg = iMsg;
- return true;
- }
- return false;
+bool Message ::getMsg(int *msg) {
+ if (messageType == MSG_IS_INT) {
+ *msg = iMsg;
+ return true;
+ }
+ return false;
}
\ No newline at end of file
diff --git a/Version_Max_07_05_2018_CMake/src/Sensor.cpp b/Version_Max_07_05_2018_CMake/src/Sensor.cpp
index 97c2ba5..e312158 100755
--- a/Version_Max_07_05_2018_CMake/src/Sensor.cpp
+++ b/Version_Max_07_05_2018_CMake/src/Sensor.cpp
@@ -1,184 +1,169 @@
#include "Sensor.h"
#include <stdio.h>
-//unsigned int Sensor :: number_of_sensors = 0;
+// unsigned int Sensor :: number_of_sensors = 0;
-void Sensor :: initialize_sensor() {
- this->flag_masteragent_is_mounted = UNMOUNTED;
- this->flag_masteragent_outputport_is_active = INACTIVE;
- this->flag_sensor_value_is_valid = INVALID;
- this->flag_sensor_value_has_changed = NO;
- this->flag_send_value_only_when_changed = NO;
+//#define PRINT
- workingCycleCounter = 1;
-}
+void Sensor ::initialize_sensor() {
+ this->flag_masteragent_is_mounted = UNMOUNTED;
+ this->flag_masteragent_outputport_is_active = INACTIVE;
+ this->flag_sensor_value_is_valid = INVALID;
+ this->flag_sensor_value_has_changed = NO;
+ this->flag_send_value_only_when_changed = NO;
-Sensor :: Sensor() {
- set_name(NO_NAME);
- initialize_sensor();
+ workingCycleCounter = 1;
}
-Sensor :: Sensor(std::string name) {
- set_name(name);
- initialize_sensor();
+Sensor ::Sensor() {
+ set_name(NO_NAME);
+ initialize_sensor();
}
+Sensor ::Sensor(std::string name) {
+ set_name(name);
+ initialize_sensor();
+}
// ----- Runtime Functions -----
-void Sensor :: set_sensorValue(float sensor_value) {
-
- if (sensor_value != sensor_value) { //If NaN
- if (flag_sensor_value_is_valid == true) {
- // don't do anything .. just keep old value
- }
- else {
- this->sensor_value = 0; //xxx - don't know if 0 is the best default value.. but in the beginning of a dataset, it most likely won't affact anything
- }
- }
- else {
- if (flag_sensor_value_is_valid == true) {
- if (this->sensor_value != sensor_value) {
- flag_sensor_value_has_changed = YES;
- }
- }
-
- flag_sensor_value_is_valid = VALID;
- this->sensor_value = sensor_value;
- }
-
-
-
-
-
- //printf("Sensor %s updated with: %f\n", name, sensor_value);
-}
-
-float Sensor :: get_sensorValue() {
- return sensor_value;
-}
-
-void Sensor :: trigger() {
- if (workingCycleCounter == 1) {
- //TODO: difference int and float
- if(this->flag_sensor_value_is_valid && this->flag_masteragent_is_mounted && this->flag_masteragent_outputport_is_active){
- if(flag_send_value_only_when_changed) {
- if(flag_sensor_value_has_changed) {
- mounted_masteragent_outputport->send_MsgUp(sensor_value);
- flag_sensor_value_has_changed = NO;
- }
- }
- else {
- mounted_masteragent_outputport->send_MsgUp(sensor_value);
- flag_sensor_value_has_changed = NO;
- }
- }
- }
-
- if (workingCycleCounter < get_workingCycle())
- workingCycleCounter++;
- else
- workingCycleCounter = 1;
+void Sensor ::set_sensorValue(float sensor_value) {
+
+ if (sensor_value != sensor_value) { // If NaN
+ if (flag_sensor_value_is_valid == true) {
+ // don't do anything .. just keep old value
+ } else {
+ this->sensor_value =
+ 0; // xxx - don't know if 0 is the best default value.. but in the
+ // beginning of a dataset, it most likely won't affact anything
+ }
+ } else {
+ if (flag_sensor_value_is_valid == true) {
+ if (this->sensor_value != sensor_value) {
+ flag_sensor_value_has_changed = YES;
+ }
+ }
+
+ flag_sensor_value_is_valid = VALID;
+ this->sensor_value = sensor_value;
+ }
+
+ // printf("Sensor %s updated with: %f\n", name, sensor_value);
+}
+
+float Sensor ::get_sensorValue() { return sensor_value; }
+
+void Sensor ::trigger() {
+ if (workingCycleCounter == 1) {
+ // TODO: difference int and float
+ if (this->flag_sensor_value_is_valid && this->flag_masteragent_is_mounted &&
+ this->flag_masteragent_outputport_is_active) {
+ if (flag_send_value_only_when_changed) {
+ if (flag_sensor_value_has_changed) {
+ mounted_masteragent_outputport->send_MsgUp(sensor_value);
+ flag_sensor_value_has_changed = NO;
+ }
+ } else {
+ mounted_masteragent_outputport->send_MsgUp(sensor_value);
+#ifdef PRINT
+ printf("Sensor %s sends: %f\n", name.c_str(), sensor_value);
+#endif // PRINT
+ flag_sensor_value_has_changed = NO;
+ }
+ }
+ }
+
+ if (workingCycleCounter < get_workingCycle())
+ workingCycleCounter++;
+ else
+ workingCycleCounter = 1;
}
-
// ----- Setup Functions -----
-bool Sensor :: mount_agent(Channel* outputport) {
- if(outputport != NULL) {
- this->mounted_masteragent_outputport = outputport;
- this->flag_masteragent_is_mounted = MOUNTED;
- this->flag_masteragent_outputport_is_active = ACTIVE;
- return true;
- }
- return false;
+bool Sensor ::mount_agent(Channel *outputport) {
+ if (outputport != NULL) {
+ this->mounted_masteragent_outputport = outputport;
+ this->flag_masteragent_is_mounted = MOUNTED;
+ this->flag_masteragent_outputport_is_active = ACTIVE;
+ return true;
+ }
+ return false;
}
-void Sensor :: set_flag_send_value_only_when_changed(bool flag_send_value_only_when_changed) {
- this->flag_send_value_only_when_changed = flag_send_value_only_when_changed;
+void Sensor ::set_flag_send_value_only_when_changed(
+ bool flag_send_value_only_when_changed) {
+ this->flag_send_value_only_when_changed = flag_send_value_only_when_changed;
}
-bool Sensor :: get_flag_send_value_only_when_changed() {
- return this->flag_send_value_only_when_changed;
+bool Sensor ::get_flag_send_value_only_when_changed() {
+ return this->flag_send_value_only_when_changed;
}
// ----- set/get -----
-void Sensor :: set_flag_sensor_value_is_valid(bool flag_sensor_value_is_valid) {
- this->flag_sensor_value_is_valid = flag_sensor_value_is_valid;
+void Sensor ::set_flag_sensor_value_is_valid(bool flag_sensor_value_is_valid) {
+ this->flag_sensor_value_is_valid = flag_sensor_value_is_valid;
}
-bool Sensor :: get_flag_sensor_value_is_valid() {
- return this->flag_sensor_value_is_valid;
+bool Sensor ::get_flag_sensor_value_is_valid() {
+ return this->flag_sensor_value_is_valid;
}
-void Sensor :: set_flag_sensor_value_has_changed(bool flag_sensor_value_has_changed) {
- this->flag_sensor_value_has_changed = flag_sensor_value_has_changed;
+void Sensor ::set_flag_sensor_value_has_changed(
+ bool flag_sensor_value_has_changed) {
+ this->flag_sensor_value_has_changed = flag_sensor_value_has_changed;
}
-bool Sensor :: get_flag_sensor_value_has_changed() {
- return this->flag_sensor_value_has_changed;
+bool Sensor ::get_flag_sensor_value_has_changed() {
+ return this->flag_sensor_value_has_changed;
}
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
void Sensor :: set_sensor_id(unsigned int id) {
- sensor_id = id;
+ sensor_id = id;
}
unsigned int Sensor :: get_sensor_id() {
- return sensor_id;
+ return sensor_id;
}*/
-
-
-void Sensor :: set_active_state_flag(bool flag) {
- active_state_flag = flag;
-}
-bool Sensor :: get_active_state_flag() {
- return active_state_flag;
-}
+void Sensor ::set_active_state_flag(bool flag) { active_state_flag = flag; }
+bool Sensor ::get_active_state_flag() { return active_state_flag; }
/*
void Sensor :: set_number_of_scores (unsigned int number) {
- number_of_scores = number;
+ number_of_scores = number;
}
unsigned int Sensor :: get_number_of_scores() {
- return number_of_scores;
+ return number_of_scores;
}
*/
-float Sensor :: get_hardcoded_threshold(unsigned int score, unsigned int boundary) {
- return hardcoded_thresholds[score][boundary];
+float Sensor ::get_hardcoded_threshold(unsigned int score,
+ unsigned int boundary) {
+ return hardcoded_thresholds[score][boundary];
}
-void Sensor :: set_hardcoded_threshold(unsigned int score, unsigned int boundary, float value) {
- hardcoded_thresholds[score][boundary] = value;
+void Sensor ::set_hardcoded_threshold(unsigned int score, unsigned int boundary,
+ float value) {
+ hardcoded_thresholds[score][boundary] = value;
}
-float Sensor :: get_learned_threshold(unsigned int score, unsigned int boundary) {
- return learned_thresholds[score][boundary];
+float Sensor ::get_learned_threshold(unsigned int score,
+ unsigned int boundary) {
+ return learned_thresholds[score][boundary];
}
-void Sensor :: set_learned_threshold(unsigned int score, unsigned int boundary, float value) {
- learned_thresholds[score][boundary] = value;
+void Sensor ::set_learned_threshold(unsigned int score, unsigned int boundary,
+ float value) {
+ learned_thresholds[score][boundary] = value;
}
-void Sensor :: set_flag_learned_boundary_exist(unsigned int score, unsigned int boundary, bool flag) {
- flag_learned_boundary_exist[score][boundary] = flag;
+void Sensor ::set_flag_learned_boundary_exist(unsigned int score,
+ unsigned int boundary,
+ bool flag) {
+ flag_learned_boundary_exist[score][boundary] = flag;
}
-bool Sensor :: get_flag_learned_boundary_exist(unsigned int score, unsigned int boundary) {
- return flag_learned_boundary_exist[score][boundary];
+bool Sensor ::get_flag_learned_boundary_exist(unsigned int score,
+ unsigned int boundary) {
+ return flag_learned_boundary_exist[score][boundary];
}
-void Sensor :: set_flag_use_learned_data(bool flag) {
- flag_use_learned_data = flag;
-}
-bool Sensor :: get_flag_use_learned_data() {
- return flag_use_learned_data;
+void Sensor ::set_flag_use_learned_data(bool flag) {
+ flag_use_learned_data = flag;
}
+bool Sensor ::get_flag_use_learned_data() { return flag_use_learned_data; }
diff --git a/Version_Max_07_05_2018_CMake/src/SensorHandlerOfAgent.cpp b/Version_Max_07_05_2018_CMake/src/SensorHandlerOfAgent.cpp
index 7b09c56..473f3a0 100755
--- a/Version_Max_07_05_2018_CMake/src/SensorHandlerOfAgent.cpp
+++ b/Version_Max_07_05_2018_CMake/src/SensorHandlerOfAgent.cpp
@@ -1,207 +1,212 @@
#include "SensorHandlerOfAgent.h"
#include <stdio.h>
#include "printError.h"
#include <algorithm>
#define MAXNUMOF_MOUNTEDSENSORS 100
+//#define PRINT
+
using namespace std;
SensorHandlerOfAgent :: SensorHandlerOfAgent() {
init_sensorHandler();
}
void SensorHandlerOfAgent :: init_sensorHandler() {
maxNumOf_mountedSensors = MAXNUMOF_MOUNTEDSENSORS;
}
//TODO: if(vMountedSensors.size() < maxNumOf_mountedSensors) als aller erste Abfrage machen ... noch bevor "SensorSlotOfAgent* sensorSlotOfAgent = new SensorSlotOfAgent();"
//TODO: delete object if it cannot added to vector
bool SensorHandlerOfAgent :: mount_sensorIntoSensorSlot(Channel* inputPort) {
SensorSlotOfAgent* sensorSlotOfAgent = new SensorSlotOfAgent();
if(sensorSlotOfAgent != NULL) {
if(sensorSlotOfAgent->set_comPort(inputPort)) {
try {
if(vMountedSensors.size() < maxNumOf_mountedSensors) {
vMountedSensors.push_back(sensorSlotOfAgent);
}
else {
printError("Max number of mounted sensors is already reached!");
return false;
}
}
catch(bad_alloc& error) {
printError("bad_alloc caught: ", error.what());
return false;
}
return true;
}
else {
printError("Input port is no set!");
vMountedSensors.pop_back(); //TODO: check if it is right?!?!
return false;
}
}
else {
printError("Couldn't create SensorSlot!");
return false;
}
}
//TODO: what to do when 2 sensorSlots have the same inputPort??!!
SensorSlotOfAgent* SensorHandlerOfAgent :: get_sensorSlotAddress(Channel* inputPort) {
for(auto &sensorSlot : vMountedSensors) {
if(sensorSlot->get_comPort() == inputPort) {
return sensorSlot;
}
}
return NULL;
}
//TODO: what to do when 2 slaveAgentSlots have the same inputPort??!!
//TODO: case if slot with comPort is not in this vector
unsigned int SensorHandlerOfAgent :: get_sensorSlotNumber(Channel* inputPort) {
unsigned int slotNumber = 0;
for(auto &sensorSlot : vMountedSensors) {
if(sensorSlot->get_comPort() == inputPort) {
return slotNumber;
}
slotNumber++;
}
return std::numeric_limits<int>::quiet_NaN();
}
//TODO: what to do when 2 sensorSlots have the same historyModule??!!
SensorSlotOfAgent* SensorHandlerOfAgent :: get_sensorSlotAddress(HistoryModule* historyModule) {
for(auto &sensorSlot : vMountedSensors) {
if(sensorSlot->get_historyModule() == historyModule) {
return sensorSlot;
}
}
return NULL;
}
//TODO: what to do when 2 sensorSlots have the same confidenceModule??!!
SensorSlotOfAgent* SensorHandlerOfAgent :: get_sensorSlotAddress(ConfidenceModule* confidenceModule) {
for(auto &sensorSlot : vMountedSensors) {
if(sensorSlot->get_confidenceModule() == confidenceModule) {
return sensorSlot;
}
}
return NULL;
}
bool SensorHandlerOfAgent :: demount_sensor(Channel* inputPort) {
vMountedSensors.erase(vMountedSensors.begin() + get_sensorSlotNumber(inputPort));
return false;
}
//TODO: do it also for integer variables
bool SensorHandlerOfAgent :: read_sensorValue(SensorSlotOfAgent* sensorSlotOfAgent) {
if(sensorSlotOfAgent != NULL) {
Channel* channel = sensorSlotOfAgent->get_comPort();
if(channel != NULL) {
float inputValue;
if(channel->get_MsgUp(&inputValue)) {
sensorSlotOfAgent->set_sensorValue(inputValue);
+#ifdef PRINT
+ printf("Agent read from %s: %f\n", channel->get_name().c_str(), inputValue);
+#endif // PRINT
return true;
}
}
}
return false;
}
bool SensorHandlerOfAgent :: read_allSensorValues() {
bool flag_readSensor = false;
for(auto &sensorSlot : vMountedSensors) {
if(read_sensorValue(sensorSlot)) {
flag_readSensor = true;
}
}
return flag_readSensor;
}
bool SensorHandlerOfAgent :: attach_historyModule(Channel* inputPort, HistoryModule* historyModule) {
SensorSlotOfAgent* sensorSlotOfAgent = get_sensorSlotAddress(inputPort);
if(sensorSlotOfAgent != NULL) {
return sensorSlotOfAgent->set_historyModule(historyModule);
}
return false;
}
bool SensorHandlerOfAgent :: detach_historyModule(SensorSlotOfAgent* sensorSlotOfAgent) {
if(sensorSlotOfAgent != NULL) {
return sensorSlotOfAgent->del_historyModule();
}
return false;
}
bool SensorHandlerOfAgent :: detach_historyModule(Channel* inputPort) {
SensorSlotOfAgent* sensorSlotOfAgent = get_sensorSlotAddress(inputPort);
return detach_historyModule(sensorSlotOfAgent);
}
bool SensorHandlerOfAgent :: detach_historyModule(HistoryModule* historyModule) {
SensorSlotOfAgent* sensorSlotOfAgent = get_sensorSlotAddress(historyModule);
return detach_historyModule(sensorSlotOfAgent);
}
HistoryModule* SensorHandlerOfAgent :: get_historyModuleOfSensorSlot(Channel* inputPort) {
SensorSlotOfAgent* sensorSlotOfAgent = get_sensorSlotAddress(inputPort);
return sensorSlotOfAgent->get_historyModule();
}
bool SensorHandlerOfAgent :: attach_confidenceModule(Channel* inputPort, ConfidenceModule* confidenceModule) {
SensorSlotOfAgent* sensorSlotOfAgent = get_sensorSlotAddress(inputPort);
if(sensorSlotOfAgent != NULL) {
return sensorSlotOfAgent->set_confidenceModule(confidenceModule);
}
return false;
}
bool SensorHandlerOfAgent :: detach_confidenceModule(SensorSlotOfAgent* sensorSlotOfAgent) {
if(sensorSlotOfAgent != NULL) {
return sensorSlotOfAgent->del_confidenceModule();
}
return false;
}
bool SensorHandlerOfAgent :: detach_confidenceModule(Channel* inputPort) {
SensorSlotOfAgent* sensorSlotOfAgent = get_sensorSlotAddress(inputPort);
return detach_confidenceModule(sensorSlotOfAgent);
}
bool SensorHandlerOfAgent :: detach_confidenceModule(ConfidenceModule* confidenceModule) {
SensorSlotOfAgent* sensorSlotOfAgent = get_sensorSlotAddress(confidenceModule);
return detach_confidenceModule(sensorSlotOfAgent);
}
ConfidenceModule* SensorHandlerOfAgent :: get_confidenceModuleOfSensorSlot(Channel* inputPort) {
SensorSlotOfAgent* sensorSlotOfAgent = get_sensorSlotAddress(inputPort);
return sensorSlotOfAgent->get_confidenceModule();
}
vector<SensorSlotOfAgent*>* SensorHandlerOfAgent :: get_vMountedSensors() {
return &vMountedSensors;
}
void SensorHandlerOfAgent :: delete_all_Mounted_Sensors()
{
SensorSlotOfAgent* cur_Sensor_Slot_Agent;
unsigned int index_cur_Sen_Slo_Ag;
unsigned int size_vec_Mount_Sensors = vMountedSensors.size();
for(index_cur_Sen_Slo_Ag = 0; index_cur_Sen_Slo_Ag < size_vec_Mount_Sensors; index_cur_Sen_Slo_Ag++){
cur_Sensor_Slot_Agent = vMountedSensors[index_cur_Sen_Slo_Ag];
delete cur_Sensor_Slot_Agent;
}
vMountedSensors.clear();
}
SensorHandlerOfAgent :: ~SensorHandlerOfAgent()
{
delete_all_Mounted_Sensors();
}
diff --git a/Version_Max_07_05_2018_CMake/src/SlaveAgentHandlerOfAgent.cpp b/Version_Max_07_05_2018_CMake/src/SlaveAgentHandlerOfAgent.cpp
index 3a805a3..71fcf00 100755
--- a/Version_Max_07_05_2018_CMake/src/SlaveAgentHandlerOfAgent.cpp
+++ b/Version_Max_07_05_2018_CMake/src/SlaveAgentHandlerOfAgent.cpp
@@ -1,231 +1,259 @@
#include "SlaveAgentHandlerOfAgent.h"
#include "instruction_set_architecture.h"
-#include <stdio.h>
#include "printError.h"
+#include <stdio.h>
-
-#include <algorithm>
+#include <algorithm>
#define MAXNUMOF_MOUNTEDSENSORS 100
-#define PRINT
-
+//#define PRINT
using namespace std;
-SlaveAgentHandlerOfAgent :: SlaveAgentHandlerOfAgent() {
- initSlaveAgentHandler();
-}
-
-void SlaveAgentHandlerOfAgent :: initSlaveAgentHandler() {
- maxNumOfMountedSlaveAgents = MAXNUMOF_MOUNTEDSENSORS;
-}
-
-bool SlaveAgentHandlerOfAgent :: mount_slaveAgentIntoSlaveAgentSlot(Channel* inputPort) {
- SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent = new SlaveAgentSlotOfAgent();
- if(slaveAgentSlotOfAgent != NULL) {
- if(slaveAgentSlotOfAgent->set_comPort(inputPort)) {
- if(vMountedSlaveAgents.size() < maxNumOfMountedSlaveAgents) {
- try {
- vMountedSlaveAgents.push_back(slaveAgentSlotOfAgent);
- }
- catch(bad_alloc& error) {
- printError("bad_alloc caught: ", error.what());
- delete slaveAgentSlotOfAgent;
- return false;
- }
- }
- else {
- printError("Max number of mounted slaveAgents is already reached!");
- delete slaveAgentSlotOfAgent;
- return false;
- }
- return true;
- }
- else {
- printError("Input port is no set!");
- vMountedSlaveAgents.pop_back(); //TODO: check if it is right?!?!
- delete slaveAgentSlotOfAgent;
- return false;
- }
- }
- else {
- printError("Couldn't create SlaveAgentSlot!");
- return false;
- }
-}
-
-//TODO: what to do when 2 slaveAgentSlots have the same inputPort??!!
-SlaveAgentSlotOfAgent* SlaveAgentHandlerOfAgent :: get_slaveAgentSlotAddress(Channel* inputPort) {
- for(auto &slaveAgentSlot : vMountedSlaveAgents) {
- if(slaveAgentSlot->get_comPort() == inputPort) {
- return slaveAgentSlot;
- }
- }
- return NULL;
-}
-
-//TODO: what to do when 2 slaveAgentSlots have the same inputPort??!!
-//TODO: case if slot with comPort is not in this vector
-unsigned int SlaveAgentHandlerOfAgent :: get_slaveAgentSlotNumber(Channel* inputPort) {
- unsigned int slotNumber = 0;
- for(auto &slaveAgentSlot : vMountedSlaveAgents) {
- if(slaveAgentSlot->get_comPort() == inputPort) {
- return slotNumber;
- }
- slotNumber++;
- }
- return std::numeric_limits<int>::quiet_NaN();
-}
-
-//TODO: what to do when 2 slaveAgentSlots have the same historyModule??!!
-SlaveAgentSlotOfAgent* SlaveAgentHandlerOfAgent :: get_slaveAgentSlotAddress(HistoryModule* historyModule) {
- for(auto &slaveAgentSlot : vMountedSlaveAgents) {
- if(slaveAgentSlot->get_historyModule() == historyModule) {
- return slaveAgentSlot;
- }
- }
- return NULL;
-}
-
-//TODO: what to do when 2 slaveAgentSlots have the same confidenceModule??!!
-SlaveAgentSlotOfAgent* SlaveAgentHandlerOfAgent :: get_slaveAgentSlotAddress(ConfidenceModule* confidenceModule) {
- for(auto &slaveAgentSlot : vMountedSlaveAgents) {
- if(slaveAgentSlot->get_confidenceModule() == confidenceModule) {
- return slaveAgentSlot;
- }
- }
- return NULL;
-}
-
-bool SlaveAgentHandlerOfAgent :: demount_slaveAgentIntoSlaveAgentSlot(Channel* inputPort) {
- vMountedSlaveAgents.erase(vMountedSlaveAgents.begin() + get_slaveAgentSlotNumber(inputPort));
- return false;
-}
-
-//TODO: do it also for integer variables
-bool SlaveAgentHandlerOfAgent :: read_slaveAgentValue(SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent) {
- if(slaveAgentSlotOfAgent != NULL) {
- Channel* channel = slaveAgentSlotOfAgent->get_comPort();
- if(channel != NULL) {
- int msg;
- if(channel->get_MsgUp(&msg)) {
- if(msg == ISA_SensoryData) {
- //printf("got msg: \n");
- float inputValue;
- if(channel->get_MsgUp(&inputValue)) {
- slaveAgentSlotOfAgent->setSlaveAgentValue(inputValue);
- //printf("got value: %f\n", inputValue);
- return true;
- }
- }
- }
- }
- }
- return false;
-}
-
-bool SlaveAgentHandlerOfAgent :: read_allSlaveAgentValues() {
- bool flag_readSlaveAgent = true;
- for(auto &slaveAgentSlot : vMountedSlaveAgents) {
- if(!read_slaveAgentValue(slaveAgentSlot)) {
- flag_readSlaveAgent = false;
- }
- }
-
+SlaveAgentHandlerOfAgent ::SlaveAgentHandlerOfAgent() {
+ initSlaveAgentHandler();
+}
+
+void SlaveAgentHandlerOfAgent ::initSlaveAgentHandler() {
+ maxNumOfMountedSlaveAgents = MAXNUMOF_MOUNTEDSENSORS;
+}
+
+bool SlaveAgentHandlerOfAgent ::mount_slaveAgentIntoSlaveAgentSlot(
+ Channel *inputPort) {
+ SlaveAgentSlotOfAgent *slaveAgentSlotOfAgent = new SlaveAgentSlotOfAgent();
+ if (slaveAgentSlotOfAgent != NULL) {
+ if (slaveAgentSlotOfAgent->set_comPort(inputPort)) {
+ if (vMountedSlaveAgents.size() < maxNumOfMountedSlaveAgents) {
+ try {
+ vMountedSlaveAgents.push_back(slaveAgentSlotOfAgent);
+ } catch (bad_alloc &error) {
+ printError("bad_alloc caught: ", error.what());
+ delete slaveAgentSlotOfAgent;
+ return false;
+ }
+ } else {
+ printError("Max number of mounted slaveAgents is already reached!");
+ delete slaveAgentSlotOfAgent;
+ return false;
+ }
+ return true;
+ } else {
+ printError("Input port is no set!");
+ vMountedSlaveAgents.pop_back(); // TODO: check if it is right?!?!
+ delete slaveAgentSlotOfAgent;
+ return false;
+ }
+ } else {
+ printError("Couldn't create SlaveAgentSlot!");
+ return false;
+ }
+}
+
+// TODO: what to do when 2 slaveAgentSlots have the same inputPort??!!
+SlaveAgentSlotOfAgent *
+SlaveAgentHandlerOfAgent ::get_slaveAgentSlotAddress(Channel *inputPort) {
+ for (auto &slaveAgentSlot : vMountedSlaveAgents) {
+ if (slaveAgentSlot->get_comPort() == inputPort) {
+ return slaveAgentSlot;
+ }
+ }
+ return NULL;
+}
+
+// TODO: what to do when 2 slaveAgentSlots have the same inputPort??!!
+// TODO: case if slot with comPort is not in this vector
+unsigned int
+SlaveAgentHandlerOfAgent ::get_slaveAgentSlotNumber(Channel *inputPort) {
+ unsigned int slotNumber = 0;
+ for (auto &slaveAgentSlot : vMountedSlaveAgents) {
+ if (slaveAgentSlot->get_comPort() == inputPort) {
+ return slotNumber;
+ }
+ slotNumber++;
+ }
+ return std::numeric_limits<int>::quiet_NaN();
+}
+
+// TODO: what to do when 2 slaveAgentSlots have the same historyModule??!!
+SlaveAgentSlotOfAgent *SlaveAgentHandlerOfAgent ::get_slaveAgentSlotAddress(
+ HistoryModule *historyModule) {
+ for (auto &slaveAgentSlot : vMountedSlaveAgents) {
+ if (slaveAgentSlot->get_historyModule() == historyModule) {
+ return slaveAgentSlot;
+ }
+ }
+ return NULL;
+}
+
+// TODO: what to do when 2 slaveAgentSlots have the same confidenceModule??!!
+SlaveAgentSlotOfAgent *SlaveAgentHandlerOfAgent ::get_slaveAgentSlotAddress(
+ ConfidenceModule *confidenceModule) {
+ for (auto &slaveAgentSlot : vMountedSlaveAgents) {
+ if (slaveAgentSlot->get_confidenceModule() == confidenceModule) {
+ return slaveAgentSlot;
+ }
+ }
+ return NULL;
+}
+
+bool SlaveAgentHandlerOfAgent ::demount_slaveAgentIntoSlaveAgentSlot(
+ Channel *inputPort) {
+ vMountedSlaveAgents.erase(vMountedSlaveAgents.begin() +
+ get_slaveAgentSlotNumber(inputPort));
+ return false;
+}
+
+// TODO: do it also for integer variables
+bool SlaveAgentHandlerOfAgent ::read_slaveAgentValue(
+ SlaveAgentSlotOfAgent *slaveAgentSlotOfAgent) {
+ if (slaveAgentSlotOfAgent != NULL) {
+ Channel *channel = slaveAgentSlotOfAgent->get_comPort();
#ifdef PRINT
- printf("\n");
+ printf("Receiver: %s - ", channel->get_name().c_str());
+#endif // PRINT
+ if (channel != NULL) {
+ int msg;
+ if (channel->get_MsgUp(&msg)) {
+ if (msg == ISA_SensoryData) {
+ float inputValue;
+ if (channel->get_MsgUp(&inputValue)) {
+ slaveAgentSlotOfAgent->setSlaveAgentValue(inputValue);
+#ifdef PRINT
+ printf("Agent got via %s: %f\n", channel->get_name().c_str(),
+ inputValue);
+#endif
+ return true;
+ }
+ } else {
+ //TODO: Error Handling!
+ }
+ }
+ }
+ }
+ return false;
+}
+
+bool SlaveAgentHandlerOfAgent ::read_allSlaveAgentValues() {
+ bool flag_readSlaveAgent = true;
+ for (auto &slaveAgentSlot : vMountedSlaveAgents) {
+ if (!read_slaveAgentValue(slaveAgentSlot)) {
+ flag_readSlaveAgent = false;
+ }
+ }
+
+#ifdef PRINT
+ printf("\n");
#endif // PRINT
- return flag_readSlaveAgent;
+ return flag_readSlaveAgent;
}
-bool SlaveAgentHandlerOfAgent :: attach_historyModule(Channel* inputPort, HistoryModule* historyModule) {
- SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent = get_slaveAgentSlotAddress(inputPort);
- if(slaveAgentSlotOfAgent != NULL) {
- return slaveAgentSlotOfAgent->set_historyModule(historyModule);
- }
- return false;
+bool SlaveAgentHandlerOfAgent ::attach_historyModule(
+ Channel *inputPort, HistoryModule *historyModule) {
+ SlaveAgentSlotOfAgent *slaveAgentSlotOfAgent =
+ get_slaveAgentSlotAddress(inputPort);
+ if (slaveAgentSlotOfAgent != NULL) {
+ return slaveAgentSlotOfAgent->set_historyModule(historyModule);
+ }
+ return false;
}
-bool SlaveAgentHandlerOfAgent :: detach_historyModule(SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent) {
- if(slaveAgentSlotOfAgent != NULL) {
- return slaveAgentSlotOfAgent->del_historyModule();
- }
- return false;
+bool SlaveAgentHandlerOfAgent ::detach_historyModule(
+ SlaveAgentSlotOfAgent *slaveAgentSlotOfAgent) {
+ if (slaveAgentSlotOfAgent != NULL) {
+ return slaveAgentSlotOfAgent->del_historyModule();
+ }
+ return false;
}
-bool SlaveAgentHandlerOfAgent :: detach_historyModule(Channel* inputPort) {
- SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent = get_slaveAgentSlotAddress(inputPort);
- return detach_historyModule(slaveAgentSlotOfAgent);
+bool SlaveAgentHandlerOfAgent ::detach_historyModule(Channel *inputPort) {
+ SlaveAgentSlotOfAgent *slaveAgentSlotOfAgent =
+ get_slaveAgentSlotAddress(inputPort);
+ return detach_historyModule(slaveAgentSlotOfAgent);
}
-bool SlaveAgentHandlerOfAgent :: detach_historyModule(HistoryModule* historyModule) {
- SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent = get_slaveAgentSlotAddress(historyModule);
- return detach_historyModule(slaveAgentSlotOfAgent);
+bool SlaveAgentHandlerOfAgent ::detach_historyModule(
+ HistoryModule *historyModule) {
+ SlaveAgentSlotOfAgent *slaveAgentSlotOfAgent =
+ get_slaveAgentSlotAddress(historyModule);
+ return detach_historyModule(slaveAgentSlotOfAgent);
}
-HistoryModule* SlaveAgentHandlerOfAgent :: get_historyModuleOfSlaveAgentSlot(Channel* inputPort) {
- SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent = get_slaveAgentSlotAddress(inputPort);
- return slaveAgentSlotOfAgent->get_historyModule();
+HistoryModule *SlaveAgentHandlerOfAgent ::get_historyModuleOfSlaveAgentSlot(
+ Channel *inputPort) {
+ SlaveAgentSlotOfAgent *slaveAgentSlotOfAgent =
+ get_slaveAgentSlotAddress(inputPort);
+ return slaveAgentSlotOfAgent->get_historyModule();
}
-bool SlaveAgentHandlerOfAgent :: attach_confidenceModule(Channel* inputPort, ConfidenceModule* confidenceModule) {
- SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent = get_slaveAgentSlotAddress(inputPort);
- if(slaveAgentSlotOfAgent != NULL) {
- return slaveAgentSlotOfAgent->set_confidenceModule(confidenceModule);
- }
- return false;
+bool SlaveAgentHandlerOfAgent ::attach_confidenceModule(
+ Channel *inputPort, ConfidenceModule *confidenceModule) {
+ SlaveAgentSlotOfAgent *slaveAgentSlotOfAgent =
+ get_slaveAgentSlotAddress(inputPort);
+ if (slaveAgentSlotOfAgent != NULL) {
+ return slaveAgentSlotOfAgent->set_confidenceModule(confidenceModule);
+ }
+ return false;
}
-bool SlaveAgentHandlerOfAgent :: detach_confidenceModule(SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent) {
- if(slaveAgentSlotOfAgent != NULL) {
- return slaveAgentSlotOfAgent->del_confidenceModule();
- }
- return false;
+bool SlaveAgentHandlerOfAgent ::detach_confidenceModule(
+ SlaveAgentSlotOfAgent *slaveAgentSlotOfAgent) {
+ if (slaveAgentSlotOfAgent != NULL) {
+ return slaveAgentSlotOfAgent->del_confidenceModule();
+ }
+ return false;
}
-bool SlaveAgentHandlerOfAgent :: detach_confidenceModule(Channel* inputPort) {
- SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent = get_slaveAgentSlotAddress(inputPort);
- return detach_confidenceModule(slaveAgentSlotOfAgent);
+bool SlaveAgentHandlerOfAgent ::detach_confidenceModule(Channel *inputPort) {
+ SlaveAgentSlotOfAgent *slaveAgentSlotOfAgent =
+ get_slaveAgentSlotAddress(inputPort);
+ return detach_confidenceModule(slaveAgentSlotOfAgent);
}
-bool SlaveAgentHandlerOfAgent :: detach_confidenceModule(ConfidenceModule* confidenceModule) {
- SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent = get_slaveAgentSlotAddress(confidenceModule);
- return detach_confidenceModule(slaveAgentSlotOfAgent);
+bool SlaveAgentHandlerOfAgent ::detach_confidenceModule(
+ ConfidenceModule *confidenceModule) {
+ SlaveAgentSlotOfAgent *slaveAgentSlotOfAgent =
+ get_slaveAgentSlotAddress(confidenceModule);
+ return detach_confidenceModule(slaveAgentSlotOfAgent);
}
-ConfidenceModule* SlaveAgentHandlerOfAgent :: get_confidenceModuleOfSlaveAgentSlot(Channel* inputPort) {
- SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent = get_slaveAgentSlotAddress(inputPort);
- return slaveAgentSlotOfAgent->get_confidenceModule();
+ConfidenceModule *
+SlaveAgentHandlerOfAgent ::get_confidenceModuleOfSlaveAgentSlot(
+ Channel *inputPort) {
+ SlaveAgentSlotOfAgent *slaveAgentSlotOfAgent =
+ get_slaveAgentSlotAddress(inputPort);
+ return slaveAgentSlotOfAgent->get_confidenceModule();
}
-vector<SlaveAgentSlotOfAgent*>* SlaveAgentHandlerOfAgent :: get_vMountedSlaveAgents() {
- return &vMountedSlaveAgents;
+vector<SlaveAgentSlotOfAgent *> *
+SlaveAgentHandlerOfAgent ::get_vMountedSlaveAgents() {
+ return &vMountedSlaveAgents;
}
-bool SlaveAgentHandlerOfAgent::saveValueInHistory(SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent) {
- if (slaveAgentSlotOfAgent != NULL) {
- //TODO: change this hardcoded value //Zeitfenster Sliding Window!!!!
- while (slaveAgentSlotOfAgent->getHistoryLength() >= 10) {
- slaveAgentSlotOfAgent->deleteOldestHistoryEntry();
- }
+bool SlaveAgentHandlerOfAgent::saveValueInHistory(
+ SlaveAgentSlotOfAgent *slaveAgentSlotOfAgent) {
+ if (slaveAgentSlotOfAgent != NULL) {
+ // TODO: change this hardcoded value //Zeitfenster Sliding Window!!!!
+ while (slaveAgentSlotOfAgent->getHistoryLength() >= 10) {
+ slaveAgentSlotOfAgent->deleteOldestHistoryEntry();
+ }
+
+ // JUST FOR TESTING
+ // slaveAgentSlotOfAgent->printHistory();
- //JUST FOR TESTING
- //slaveAgentSlotOfAgent->printHistory();
-
- return slaveAgentSlotOfAgent->saveValueInHistory();
- }
- return false;
+ return slaveAgentSlotOfAgent->saveValueInHistory();
+ }
+ return false;
}
bool SlaveAgentHandlerOfAgent::saveAllValuesInHistory() {
- bool flagSavingSuccesful = true;
- for (auto &slaveAgentSlot : vMountedSlaveAgents) {
- if (!saveValueInHistory(slaveAgentSlot)) {
- flagSavingSuccesful = false;
- }
- }
- return flagSavingSuccesful;
+ bool flagSavingSuccesful = true;
+ for (auto &slaveAgentSlot : vMountedSlaveAgents) {
+ if (!saveValueInHistory(slaveAgentSlot)) {
+ flagSavingSuccesful = false;
+ }
+ }
+ return flagSavingSuccesful;
}
diff --git a/Version_Max_07_05_2018_CMake/src/Testbench.cpp b/Version_Max_07_05_2018_CMake/src/Testbench.cpp
index 241488e..8410a65 100755
--- a/Version_Max_07_05_2018_CMake/src/Testbench.cpp
+++ b/Version_Max_07_05_2018_CMake/src/Testbench.cpp
@@ -1,1026 +1,684 @@
#include "Testbench.h"
#include "printError.h"
#include <stdio.h>
using namespace std;
void Testbench :: init_testbench() {
//TODO
//some init source code to add, if necessary
}
Testbench :: Testbench() {
set_name(NO_NAME);
}
Testbench :: Testbench(std::string name) {
set_name(name);
}
bool Testbench :: register_agent(Agent* agent) {
AgentSlotOfTestbench* agentSlot = new AgentSlotOfTestbench();
if(agentSlot != NULL) {
if(agentSlot->set_agent(agent)) {
try {
if(vector_registeredAgents.size() < MAXNUM_OF_REGISTERED_AGENTS) {
vector_registeredAgents.push_back(agentSlot);
}
else {
printError("Max number of registered agents is already reached!");
return false;
}
}
catch(bad_alloc& error) {
printError("bad_alloc caught: ", error.what());
return false;
}
return true;
}
else {
printError("Agent is not set!");
vector_registeredAgents.pop_back(); //TODO: check if it is right?!?!
return false;
}
}
else {
printError("Couldn't create AgentSlot!");
return false;
}
}
bool Testbench :: register_sensor(Sensor* sensor) {
SensorSlotOfTestbench* sensorSlot = new SensorSlotOfTestbench();
if(sensorSlot != NULL) {
if(sensorSlot->set_sensor(sensor)) {
try {
if(vector_registeredSensors.size() < MAXNUM_OF_REGISTERED_SENSORS) {
vector_registeredSensors.push_back(sensorSlot);
}
else {
printError("Max number of registered sensors is already reached!");
return false;
}
}
catch(bad_alloc& error) {
printError("bad_alloc caught: ", error.what());
return false;
}
return true;
}
else {
printError("Input port is no set!");
vector_registeredSensors.pop_back(); //TODO: check if it is right?!?!
return false;
}
}
else {
printError("Couldn't create SensorSlot!");
return false;
}
}
SensorSlotOfTestbench* Testbench :: get_sensorSlotAddressOfTestbench(Sensor* sensor) {
for(auto &sensorSlot : vector_registeredSensors) {
if(sensorSlot->get_sensor() == sensor) {
return sensorSlot;
}
}
return NULL;
}
bool Testbench :: register_channel(Channel* channel) {
ChannelSlotOfTestbench* channelSlot = new ChannelSlotOfTestbench();
if(channelSlot != NULL) {
if(channelSlot->set_channel(channel)) {
try {
if(vector_registeredChannels.size() < MAXNUM_OF_REGISTERED_CHANNELS) {
vector_registeredChannels.push_back(channelSlot);
}
else {
printError("Max number of registered channels is already reached!");
return false;
}
}
catch(bad_alloc& error) {
printError("bad_alloc caught: ", error.what());
return false;
}
return true;
}
else {
printError("Channel is not set!");
vector_registeredChannels.pop_back(); //TODO: check if it is right?!?!
return false;
}
}
else {
printError("Couldn't create ChannelSlot!");
return false;
}
}
+
bool Testbench :: register_testbench_config(Testbench_Config* tb_config)
{
vector_registered_Configs.push_back(tb_config);
return true; //added by Ali, it is an error in VS.
}
vector<Testbench_Config*>& Testbench :: get_all_registered_testbench_configs()
{
return vector_registered_Configs;
}
+
void Testbench :: simulate(unsigned int rounds) {
for(unsigned int cycle = 1; cycle <=rounds; cycle++) {
-
- if (cycle == 312) {
- printf("DEBUG: Break point");
- }
- //printf("cycle %u\n", sec);
-
//update sensor values
for(auto &sensorSlot : vector_registeredSensors) {
Sensor *sensor = sensorSlot->get_sensor();
//printf("Name of Sensor %s \n", sensor->get_name().c_str());
if(sensor != NULL) {
CSVreaderModule *csvReader = sensorSlot->get_csvReaderModule();
if(csvReader != NULL) {
float inputValue;
if(csvReader->get_next_value(&inputValue)) {
sensor->set_sensorValue(inputValue);
}
}
}
}
//trigger sensors
for(auto &sensorSlot : vector_registeredSensors) {
Sensor *sensor = sensorSlot->get_sensor();
if(sensor != NULL) {
sensor->trigger();
}
}
//trigger channels
for(auto &channelSlot : vector_registeredChannels) {
Channel *channel = channelSlot->get_channel();
if(channel != NULL) {
channel->trigger();
}
}
//trigger agents
for(auto &agentSlot : vector_registeredAgents) {
Agent *agent = agentSlot->get_agent();
if(agent != NULL) {
agent->trigger(cycle);
}
}
-
-
-
-
-
- //if(sec % 500 == 0)
- //getchar();
}
//XXX - only for now
for (auto &agentSlot : vector_registeredAgents) {
Agent *agent = agentSlot->get_agent();
if (agent != NULL) {
StateHandler *stateHandler = agent->get_stateHandler2();
if (stateHandler != NULL) {
stateHandler->closeCsvFile();
}
}
}
-
-
}
vector<AgentSlotOfTestbench*>& Testbench :: get_all_registeredAgents()
{
return vector_registeredAgents;
}
void Testbench :: set_current_tb_config_index(const int index)
{
Testbench_Config::set_active_Config(index);
}
void Testbench :: remove_all_Testbench_Configs()
{
unsigned int index_tb_conf = 0;
unsigned int size_vec_tb_conf = vector_registered_Configs.size();
for(index_tb_conf = 0; index_tb_conf < size_vec_tb_conf; index_tb_conf++) {
Testbench_Config* cur_config = vector_registered_Configs[index_tb_conf];
delete cur_config;
}
vector_registered_Configs.clear();
}
void Testbench :: remove_all_Agents()
{
AgentSlotOfTestbench* cur_AgentSlot;
unsigned int index_ag;
unsigned int size_vec_reg_ag = vector_registeredAgents.size();
for(index_ag = 0; index_ag < size_vec_reg_ag; index_ag++) {
cur_AgentSlot = vector_registeredAgents[index_ag];
delete cur_AgentSlot;
}
vector_registeredAgents.clear();
}
void Testbench :: remove_all_Channels()
{
unsigned int index_ch;
unsigned int size_vec_reg_chan = vector_registeredChannels.size();
for(index_ch = 0; index_ch < size_vec_reg_chan; index_ch++) {
ChannelSlotOfTestbench* cur_ChaSlot = vector_registeredChannels[index_ch];
delete cur_ChaSlot;
}
vector_registeredChannels.clear();
}
void Testbench :: remove_all_Sensors()
{
unsigned int index_sen;
unsigned int size_vec_reg_sens = vector_registeredSensors.size();
for(index_sen = 0; index_sen < size_vec_reg_sens; index_sen++) {
SensorSlotOfTestbench* cur_SenSlot = vector_registeredSensors[index_sen];
delete cur_SenSlot;
}
vector_registeredSensors.clear();
}
bool Testbench :: free_resources()
{
AgentSlotOfTestbench* cur_Ag_Sl_Tb;
unsigned int index_reg_Agents;
unsigned int size_vec_reg_Agents = vector_registeredAgents.size();
for(index_reg_Agents = 0; index_reg_Agents < size_vec_reg_Agents; index_reg_Agents++)
{
cur_Ag_Sl_Tb = vector_registeredAgents[index_reg_Agents];
//Agent* cur_Ag = cur_Ag_Sl_Tb->get_agent();
//cur_Ag->del_stateHandler();
}
return true; //added by Ali, it is an error in VS.
}
+
void Testbench::set_CSV_Writer_parameter()
{
unsigned int size_of_vec_reg_Agents = vector_registeredAgents.size();
AgentSlotOfTestbench* viability_slot_Agent = vector_registeredAgents[size_of_vec_reg_Agents - 1];
Agent* viability_Agent = viability_slot_Agent->get_agent();
StateHandler* cur_state_Handl = viability_Agent->get_stateHandler();
Testbench_Config* cur_tb_cfg;
string tb_cfg;
cur_tb_cfg = get_current_Testbench_config();
if(cur_tb_cfg != NULL) {
tb_cfg = cur_tb_cfg->get_Config_as_String();
cur_state_Handl->set_CSV_Writer_parameter(tb_cfg);
}
}
Testbench_Config* Testbench :: get_current_Testbench_config()
{
unsigned int index_cur_tb_cfg = 0;
unsigned int size_tb_cfg = vector_registered_Configs.size();
Testbench_Config* cur_tb_cfg;
for(index_cur_tb_cfg = 0; index_cur_tb_cfg < size_tb_cfg; index_cur_tb_cfg++){
cur_tb_cfg = vector_registered_Configs[index_cur_tb_cfg];
if(cur_tb_cfg->get_own_index() == Testbench_Config::get_active_Config()){
return cur_tb_cfg;
}
}
return NULL;
}
void Testbench :: set_config_values_in_linear_functions()
{
//unsigned int index_reg_Agents = 0;
unsigned int size_of_vec_reg_Agents;
vector<AgentSlotOfTestbench*> vec_reg_Agents = this->get_all_registeredAgents();
size_of_vec_reg_Agents = vec_reg_Agents.size();
AgentSlotOfTestbench* viability_slot_Agent = vec_reg_Agents[vec_reg_Agents.size()-1];
Agent* viability_Agent = viability_slot_Agent->get_agent();
StateHandler* cur_state_Handl = viability_Agent->get_stateHandler();
+ /*
+ //TODO: the Function Blocks of Statehandler should be private members of state handler. There already exist public set functions.
set_parameters_FuncBlockConfSim2StateDev(cur_state_Handl->FuncBlockConfSim2StateDev);
set_parameters_FuncBlockConfDif2StateDev(cur_state_Handl->FuncBlockConfDif2StateDev);
set_parameters_FuncBlockConfSim2StateTime(cur_state_Handl->FuncBlockConfSim2StateTime);
set_parameters_FuncBlockConfDif2StateTime(cur_state_Handl->FuncBlockConfDif2StateTime);
set_parameters_FuncBlockConfValStateDev(cur_state_Handl->FuncBlockConfValStateDev);
set_parameters_FuncBlockConfInvStateDev(cur_state_Handl->FuncBlockConfInvStateDev);
set_parameters_FuncBlockConfValStateTime(cur_state_Handl->FuncBlockConfValStateTime);
set_parameters_FuncBlockConfInvStateTime(cur_state_Handl->FuncBlockConfInvStateTime);
set_parameters_DriftDeviation(cur_state_Handl->DriftDeviation);
set_parameters_FuncBlockConfBrokenSamples(cur_state_Handl->FuncBlockConfBrokenSamples);
+ */
+
+ set_parameters_FuncBlockConfSim2StateDev(
+ cur_state_Handl->getSimilarToStateDeviationFuzzyFunction());
+ set_parameters_FuncBlockConfDif2StateDev(
+ cur_state_Handl->getDifferentToStateDeviationFuzzyFunction());
+ set_parameters_FuncBlockConfSim2StateTime(
+ cur_state_Handl->getSimilarToStateTimeFuzzyFunction());
+ set_parameters_FuncBlockConfDif2StateTime(
+ cur_state_Handl->getDifferentToStateTimeFuzzyFunction());
+ set_parameters_FuncBlockConfValStateDev(
+ cur_state_Handl->getSimilarityInStateDeviationFuzzyFunction());
+ set_parameters_FuncBlockConfInvStateDev(
+ cur_state_Handl->getUnsimilarityInStateDeviationFuzzyFunction());
+ set_parameters_FuncBlockConfValStateTime(
+ cur_state_Handl->getSimilarityInStateTimeFuzzyFunction());
+ set_parameters_FuncBlockConfInvStateTime(
+ cur_state_Handl->getUnsimilarityInStateTimeFuzzyFunction());
+ set_parameters_DriftDeviation(cur_state_Handl->getDriftFuzzyFunction());
+ set_parameters_FuncBlockConfBrokenSamples(
+ cur_state_Handl->getBrokenFuzzyFunction());
}
void Testbench :: set_parameters_FuncBlockConfSim2StateDev(LinearFunctionBlock* FuncBlockConfSim2StateDev)
{
LinearFunction* cur_Lin_Fun;
vector<LinearFunction*> vec_Lin_Fun = FuncBlockConfSim2StateDev->get_all_LinearFunctions();
unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size();
unsigned int index_cur_Lin_Fun = 0;
Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config();
for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++)
{
One_Config_t cur_values = cur_Tb_cfg->get_Config();
cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun];
if(cur_Lin_Fun->getName() == CONF_SIM2_STATE_DEV_1) {
cur_Lin_Fun->setDomain(false, true, (float)-cur_values.outter_bound_sim_dif);
cur_Lin_Fun->setKandD((float)0, (float)0);
}else if (cur_Lin_Fun->getName() == CONF_SIM2_STATE_DEV_2) {
cur_Lin_Fun->setDomain(true, (float)-cur_values.outter_bound_sim_dif, true, (float)-cur_values.inner_bound_sim_dif);
cur_Lin_Fun->setKandD((float)-cur_values.outter_bound_sim_dif, (float)0, (float)-cur_values.inner_bound_sim_dif, (float)1);
}else if (cur_Lin_Fun->getName() == CONF_SIM2_STATE_DEV_3) {
cur_Lin_Fun->setDomain(true, (float)-cur_values.inner_bound_sim_dif, true, (float)cur_values.inner_bound_sim_dif);
cur_Lin_Fun->setKandD((float)0, (float)1);
}else if(cur_Lin_Fun->getName() == CONF_SIM2_STATE_DEV_4){
cur_Lin_Fun->setDomain(true, (float)cur_values.inner_bound_sim_dif, true, (float)cur_values.outter_bound_sim_dif);
cur_Lin_Fun->setKandD((float)cur_values.inner_bound_sim_dif, (float)1, (float)cur_values.outter_bound_sim_dif, (float)0);
}else if(cur_Lin_Fun->getName() == CONF_SIM2_STATE_DEV_5){
cur_Lin_Fun->setDomain(true, (float)cur_values.outter_bound_sim_dif, false);
cur_Lin_Fun->setKandD((float)0, (float)0);
}
}
}
void Testbench :: set_parameters_FuncBlockConfDif2StateDev(LinearFunctionBlock* FuncBlockConfDif2StateDev)
{
LinearFunction* cur_Lin_Fun;
vector<LinearFunction*> vec_Lin_Fun = FuncBlockConfDif2StateDev->get_all_LinearFunctions();
unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size();
unsigned int index_cur_Lin_Fun = 0;
Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config();
for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++)
{
One_Config_t cur_values = cur_Tb_cfg->get_Config();
cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun];
if(cur_Lin_Fun->getName() == CONF_DIF2_STATE_DEV_1) {
cur_Lin_Fun->setDomain(false, true, (float)-cur_values.outter_bound_sim_dif);
cur_Lin_Fun->setKandD((float)0, (float)1);
}else if (cur_Lin_Fun->getName() == CONF_DIF2_STATE_DEV_2) {
cur_Lin_Fun->setDomain(true, (float)-cur_values.outter_bound_sim_dif, true, (float)-cur_values.inner_bound_sim_dif);
cur_Lin_Fun->setKandD((float)-cur_values.outter_bound_sim_dif, (float)1, (float)-cur_values.inner_bound_sim_dif, (float)0);
}else if (cur_Lin_Fun->getName() == CONF_DIF2_STATE_DEV_3) {
cur_Lin_Fun->setDomain(true, (float)-cur_values.inner_bound_sim_dif, true, (float)cur_values.inner_bound_sim_dif);
cur_Lin_Fun->setKandD((float)0, (float)0);
}else if(cur_Lin_Fun->getName() == CONF_DIF2_STATE_DEV_4){
cur_Lin_Fun->setDomain(true, (float)cur_values.inner_bound_sim_dif, true, (float)cur_values.outter_bound_sim_dif);
cur_Lin_Fun->setKandD((float)cur_values.inner_bound_sim_dif, (float)0, (float)cur_values.outter_bound_sim_dif, (float)1);
}else if(cur_Lin_Fun->getName() == CONF_DIF2_STATE_DEV_5){
cur_Lin_Fun->setDomain(true, (float)cur_values.outter_bound_sim_dif, false);
cur_Lin_Fun->setKandD((float)0, (float)1);
}
}
}
void Testbench :: set_parameters_FuncBlockConfSim2StateTime(LinearFunctionBlock* FuncBlockConfSim2StateTime)
{
LinearFunction* cur_Lin_Fun;
vector<LinearFunction*> vec_Lin_Fun = FuncBlockConfSim2StateTime->get_all_LinearFunctions();
unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size();
unsigned int index_cur_Lin_Fun = 0;
Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config();
for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++)
{
One_Config_t cur_values = cur_Tb_cfg->get_Config();
cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun];
if(cur_Lin_Fun->getName() == CONF_SIM2_STATE_TIME_1) {
cur_Lin_Fun->setDomain(false, true, (float)0);
cur_Lin_Fun->setKandD((float)0, (float)0);
}else if (cur_Lin_Fun->getName() == CONF_SIM2_STATE_TIME_2) {
cur_Lin_Fun->setDomain(true, (float)0, true, (float)cur_values.length);
cur_Lin_Fun->setKandD((float)0, (float)0, (float)cur_values.length, (float)1);
}else if (cur_Lin_Fun->getName() == CONF_SIM2_STATE_TIME_3) {
cur_Lin_Fun->setDomain(true, (float)cur_values.length, false);
cur_Lin_Fun->setKandD((float)0, (float)1);
}
}
}
void Testbench :: set_parameters_FuncBlockConfDif2StateTime(LinearFunctionBlock* FuncBlockConfDif2StateTime)
{
LinearFunction* cur_Lin_Fun;
vector<LinearFunction*> vec_Lin_Fun = FuncBlockConfDif2StateTime->get_all_LinearFunctions();
unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size();
unsigned int index_cur_Lin_Fun = 0;
Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config();
for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++)
{
One_Config_t cur_values = cur_Tb_cfg->get_Config();
cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun];
if(cur_Lin_Fun->getName() == CONF_DIF2_STATE_TIME_1) {
cur_Lin_Fun->setDomain(false, true, (float)0);
cur_Lin_Fun->setKandD((float)0, (float)1);
}else if (cur_Lin_Fun->getName() == CONF_DIF2_STATE_TIME_2) {
cur_Lin_Fun->setDomain(true, (float)0, true, (float)cur_values.length);
cur_Lin_Fun->setKandD((float)0, (float)1, (float)cur_values.length, (float)0);
}else if (cur_Lin_Fun->getName() == CONF_DIF2_STATE_TIME_3) {
cur_Lin_Fun->setDomain(true, (float)cur_values.length, false);
cur_Lin_Fun->setKandD((float)0, (float)0);
}
}
}
void Testbench :: set_parameters_FuncBlockConfValStateDev(LinearFunctionBlock* FuncBlockConfValStateDev)
{
LinearFunction* cur_Lin_Fun;
vector<LinearFunction*> vec_Lin_Fun = FuncBlockConfValStateDev->get_all_LinearFunctions();
unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size();
unsigned int index_cur_Lin_Fun = 0;
Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config();
for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++)
{
One_Config_t cur_values = cur_Tb_cfg->get_Config();
cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun];
if(cur_Lin_Fun->getName() == CONF_VALID_STATE_DEV_1) {
cur_Lin_Fun->setDomain(false, true, (float)-cur_values.outter_bound_sim_dif);
cur_Lin_Fun->setKandD((float)0, (float)0);
}else if (cur_Lin_Fun->getName() == CONF_VALID_STATE_DEV_2) {
cur_Lin_Fun->setDomain(true, (float)-cur_values.outter_bound_sim_dif, true, (float)-cur_values.inner_bound_sim_dif);
cur_Lin_Fun->setKandD((float)-cur_values.outter_bound_sim_dif, (float)0, (float)-cur_values.inner_bound_sim_dif, (float)1);
}else if (cur_Lin_Fun->getName() == CONF_VALID_STATE_DEV_3) {
cur_Lin_Fun->setDomain(true, (float)-cur_values.inner_bound_sim_dif, true, (float)cur_values.inner_bound_sim_dif);
cur_Lin_Fun->setKandD((float)0, (float)1);
}else if(cur_Lin_Fun->getName() == CONF_VALID_STATE_DEV_4){
cur_Lin_Fun->setDomain(true, (float)cur_values.inner_bound_sim_dif, true, (float)cur_values.outter_bound_sim_dif);
cur_Lin_Fun->setKandD((float)cur_values.inner_bound_sim_dif, (float)1, (float)cur_values.outter_bound_sim_dif, (float)0);
}else if(cur_Lin_Fun->getName() == CONF_VALID_STATE_DEV_5){
cur_Lin_Fun->setDomain(true, (float)cur_values.outter_bound_sim_dif, false);
cur_Lin_Fun->setKandD((float)0, (float)0);
}
}
}
void Testbench :: set_parameters_FuncBlockConfInvStateDev(LinearFunctionBlock* FuncBlockConfInvStateDev)
{
LinearFunction* cur_Lin_Fun;
vector<LinearFunction*> vec_Lin_Fun = FuncBlockConfInvStateDev->get_all_LinearFunctions();
unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size();
unsigned int index_cur_Lin_Fun = 0;
Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config();
for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++)
{
One_Config_t cur_values = cur_Tb_cfg->get_Config();
cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun];
if(cur_Lin_Fun->getName() == CONF_INVALID_STATE_DEV_1) {
cur_Lin_Fun->setDomain(false, true, (float)-cur_values.outter_bound_sim_dif);
cur_Lin_Fun->setKandD((float)0, (float)1);
}else if (cur_Lin_Fun->getName() == CONF_INVALID_STATE_DEV_2) {
cur_Lin_Fun->setDomain(true, (float)-cur_values.outter_bound_sim_dif, true, (float)-cur_values.inner_bound_sim_dif);
cur_Lin_Fun->setKandD((float)-cur_values.outter_bound_sim_dif, (float)1, (float)-cur_values.inner_bound_sim_dif, (float)0);
}else if (cur_Lin_Fun->getName() == CONF_INVALID_STATE_DEV_3) {
cur_Lin_Fun->setDomain(true, (float)-cur_values.inner_bound_sim_dif, true, (float)cur_values.inner_bound_sim_dif);
cur_Lin_Fun->setKandD((float)0, (float)0);
}else if(cur_Lin_Fun->getName() == CONF_INVALID_STATE_DEV_4){
cur_Lin_Fun->setDomain(true, (float)cur_values.inner_bound_sim_dif, true, (float)cur_values.outter_bound_sim_dif);
cur_Lin_Fun->setKandD((float)cur_values.inner_bound_sim_dif, (float)0, (float)cur_values.outter_bound_sim_dif, (float)1);
}else if(cur_Lin_Fun->getName() == CONF_INVALID_STATE_DEV_5){
cur_Lin_Fun->setDomain(true, (float)cur_values.outter_bound_sim_dif, false);
cur_Lin_Fun->setKandD((float)0, (float)1);
}
}
}
void Testbench :: set_parameters_FuncBlockConfValStateTime(LinearFunctionBlock* FuncBlockConfValStateTime)
{
LinearFunction* cur_Lin_Fun;
vector<LinearFunction*> vec_Lin_Fun = FuncBlockConfValStateTime->get_all_LinearFunctions();
unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size();
unsigned int index_cur_Lin_Fun = 0;
Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config();
for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++)
{
One_Config_t cur_values = cur_Tb_cfg->get_Config();
cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun];
if(cur_Lin_Fun->getName() == VALID_STATE_TIME_1) {
cur_Lin_Fun->setDomain(false, true, (float)0);
cur_Lin_Fun->setKandD((float)0, (float)0);
}else if (cur_Lin_Fun->getName() == VALID_STATE_TIME_2) {
cur_Lin_Fun->setDomain(true, (float)0, true, (float)cur_values.length);
cur_Lin_Fun->setKandD((float)0, (float)0, (float)cur_values.length, (float)1);
}else if (cur_Lin_Fun->getName() == VALID_STATE_TIME_3) {
cur_Lin_Fun->setDomain(true, (float)cur_values.length, false);
cur_Lin_Fun->setKandD((float)0, (float)1);
}
}
}
void Testbench :: set_parameters_FuncBlockConfInvStateTime(LinearFunctionBlock* FuncBlockConfInvStateTime)
{
LinearFunction* cur_Lin_Fun;
vector<LinearFunction*> vec_Lin_Fun = FuncBlockConfInvStateTime->get_all_LinearFunctions();
unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size();
unsigned int index_cur_Lin_Fun = 0;
Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config();
for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++)
{
One_Config_t cur_values = cur_Tb_cfg->get_Config();
cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun];
if(cur_Lin_Fun->getName() == INVALID_STATE_TIME_1) {
cur_Lin_Fun->setDomain(false, true, (float)0);
cur_Lin_Fun->setKandD((float)0, (float)1);
}else if (cur_Lin_Fun->getName() == INVALID_STATE_TIME_2) {
cur_Lin_Fun->setDomain(true, (float)0, true, (float)cur_values.length);
cur_Lin_Fun->setKandD((float)0, (float)1, (float)cur_values.length, (float)0);
}else if (cur_Lin_Fun->getName() == INVALID_STATE_TIME_3) {
cur_Lin_Fun->setDomain(true, (float)cur_values.length, false);
cur_Lin_Fun->setKandD((float)0, (float)0);
}
}
}
void Testbench :: set_parameters_DriftDeviation(LinearFunctionBlock* DriftDeviation)
{
LinearFunction* cur_Lin_Fun;
vector<LinearFunction*> vec_Lin_Fun = DriftDeviation->get_all_LinearFunctions();
unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size();
unsigned int index_cur_Lin_Fun = 0;
Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config();
for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++)
{
One_Config_t cur_values = cur_Tb_cfg->get_Config();
cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun];
if(cur_Lin_Fun->getName() == CONFIDENCE_DRIFT_DEVIATION_1) {
cur_Lin_Fun->setDomain(false, true, (float)-cur_values.outter_bound_drift);
cur_Lin_Fun->setKandD((float)0, (float)1);
}else if (cur_Lin_Fun->getName() == CONFIDENCE_DRIFT_DEVIATION_2) {
cur_Lin_Fun->setDomain(true, (float)-cur_values.outter_bound_drift, true, (float)-cur_values.inner_bound_drift);
cur_Lin_Fun->setKandD((float)-cur_values.inner_bound_drift, (float)1, (float)-cur_values.inner_bound_drift, (float)0);
}else if (cur_Lin_Fun->getName() == CONFIDENCE_DRIFT_DEVIATION_3) {
//this line causes a small deviation between the old solution with define and the new one
//I didn't figure out how to get an totally equal result.
cur_Lin_Fun->setDomain(true,(float) -cur_values.inner_bound_drift, true,(float) cur_values.inner_bound_drift);
cur_Lin_Fun->setKandD((float)0, (float)0);
}else if(cur_Lin_Fun->getName() == CONFIDENCE_DRIFT_DEVIATION_4){
cur_Lin_Fun->setDomain(true, (float)cur_values.inner_bound_drift, true, (float)cur_values.outter_bound_drift);
cur_Lin_Fun->setKandD((float)cur_values.inner_bound_drift, (float)0, (float)cur_values.outter_bound_drift, (float)1);
}else if(cur_Lin_Fun->getName() == CONFIDENCE_DRIFT_DEVIATION_5){
cur_Lin_Fun->setDomain(true, (float)cur_values.outter_bound_drift, false);
cur_Lin_Fun->setKandD((float)0, (float)1);
}
}
}
void Testbench :: set_parameters_FuncBlockConfBrokenSamples(LinearFunctionBlock* FuncBlockConfBrokenSamples)
{
LinearFunction* cur_Lin_Fun;
vector<LinearFunction*> vec_Lin_Fun = FuncBlockConfBrokenSamples->get_all_LinearFunctions();
unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size();
unsigned int index_cur_Lin_Fun = 0;
Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config();
for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++)
{
One_Config_t cur_values = cur_Tb_cfg->get_Config();
cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun];
if(cur_Lin_Fun->getName() == CONFIDENCE_BROKEN_1) {
cur_Lin_Fun->setDomain(false, true, (float)0);
cur_Lin_Fun->setKandD((float)0, (float)0);
}else if (cur_Lin_Fun->getName() == CONFIDENCE_BROKEN_2) {
cur_Lin_Fun->setDomain(true, (float)0, true, (float)cur_values.bound_broken);
cur_Lin_Fun->setKandD((float)0, (float)0, (float)cur_values.bound_broken, (float)1);
}else if (cur_Lin_Fun->getName() == CONFIDENCE_BROKEN_3) {
cur_Lin_Fun->setDomain(true, (float)cur_values.bound_broken, false);
cur_Lin_Fun->setKandD((float)0, (float)1);
}
}
}
void Testbench :: set_CSV_Reader_row(const int start_row)
{
unsigned int size_of_vec_reg_Sens = vector_registeredSensors.size();
SensorSlotOfTestbench* cur_sens_Slot;
unsigned int index_cur_Slot = 0;
CSVreaderModule* assigned_CSVReader;
for(index_cur_Slot = 0; index_cur_Slot < size_of_vec_reg_Sens; index_cur_Slot++){
cur_sens_Slot = vector_registeredSensors[index_cur_Slot];
assigned_CSVReader = cur_sens_Slot->get_csvReaderModule();
assigned_CSVReader->reset_row(start_row);
}
}
void Testbench :: set_CSV_Reader_to_beginning()
{
unsigned int size_of_vec_reg_Sens = vector_registeredSensors.size();
SensorSlotOfTestbench* cur_sens_Slot;
unsigned int index_cur_Slot = 0;
CSVreaderModule* assigned_CSVReader;
//unsigned const int START_ROW = 1;
for(index_cur_Slot = 0; index_cur_Slot < size_of_vec_reg_Sens; index_cur_Slot++){
cur_sens_Slot = vector_registeredSensors[index_cur_Slot];
assigned_CSVReader = cur_sens_Slot->get_csvReaderModule();
assigned_CSVReader->set_position_fpointer_to_start();
}
}
void Testbench:: reset_States()
{
unsigned int size_of_vec_reg_Agents = vector_registeredAgents.size();
AgentSlotOfTestbench* viability_slot_Agent = vector_registeredAgents[size_of_vec_reg_Agents - 1];
Agent* viability_Agent = viability_slot_Agent->get_agent();
StateHandler* cur_state_Handl = viability_Agent->get_stateHandler();
cur_state_Handl->reset_States();
}
void Testbench:: reset_States_and_Slave_Agents()
{
unsigned int size_of_vec_reg_Agents = vector_registeredAgents.size();
AgentSlotOfTestbench* viability_slot_Agent = vector_registeredAgents[size_of_vec_reg_Agents - 1];
Agent* viability_Agent = viability_slot_Agent->get_agent();
StateHandler* cur_state_Handl = viability_Agent->get_stateHandler();
cur_state_Handl->reset_States_and_Slave_Agents();
}
Testbench :: ~Testbench()
{
remove_all_Testbench_Configs();
+
remove_all_Agents();
remove_all_Channels();
remove_all_Sensors();
}
-
-/*
-Testbench :: Testbench() {
- num_of_registered_agents = 0;
- num_of_registered_sensors = 0;
- num_of_registered_channels = 0;
-
- this->id = num_of_units;
- num_of_units++;
- this->set_name(NO_NAME);
-
- //csv
- flag_csv_reader_exist = false;
- flag_csv_writer_exist = false;
-}
-
-Testbench :: Testbench(char* name) {
- num_of_registered_agents = 0;
- num_of_registered_sensors = 0;
- num_of_registered_channels = 0;
-
- this->id = num_of_units;
- num_of_units++;
- this->set_name(name);
-
- //csv
- flag_csv_reader_exist = false;
- flag_csv_writer_exist = false;
-}
-
-void Testbench :: simulate() {
-
- if(flag_csv_writer_exist) {
-
- csv_writer->write_field("second");
- csv_writer->make_new_field();
-
- for(unsigned int s_ix=0; s_ix<num_of_registered_sensors; s_ix++) {
- csv_writer->write_field(registered_sensors[s_ix]->get_name());
- csv_writer->make_new_field();
- }
-
- for(unsigned int a_ix=0; a_ix<num_of_registered_agents; a_ix++) {
-
- csv_writer->write_field(registered_agents[a_ix]->get_name());
- csv_writer->make_new_field();
-
- }
-
- csv_writer->write_field("confidence counter");
- csv_writer->make_new_field();
-
- csv_writer->make_new_line();
- }
-
-
- //TODO: HIER ENDLOSSCHLEIFE ODER SO - Irgendwas, dass stoppt, wenn file zu ende
- for(unsigned int sec=1; sec<=29208; sec++) {
-
- printf("second %u\n", sec);
-
- if(flag_csv_writer_exist) {
- csv_writer->write_field((int)sec);
- csv_writer->make_new_field();
- }
-
-
- //Update Sensor Values
- for(unsigned int s_ix = 0; s_ix < num_of_registered_sensors; s_ix++) {
- //TODO: make possibility of non-registered csv-reader
- if(flag_sensor_has_csvr[s_ix]) {
-
- float value_from_csv;
-
- if(registered_sensors_csvr[s_ix] != NULL) {
-
- if(registered_sensors_csvr[s_ix]->get_next_value(&value_from_csv)) {
-
- registered_sensors[s_ix]->update_sensor_value(value_from_csv);
-
- //printf("field of %s: %f", registered_sensors[s_ix]->get_name(), value_from_csv);
- }
- }
- }
- }
-
-
- for(unsigned int s_ix = 0; s_ix < num_of_registered_sensors; s_ix++) {
- registered_sensors[s_ix]->trigger();
-
- if(flag_csv_writer_exist) {
- if(registered_sensors[s_ix]->get_flag_sensor_value_is_valid()) {
- csv_writer->write_field(registered_sensors[s_ix]->get_sensor_value());
- }
- csv_writer->make_new_field();
- }
- }
-
-
-
-
-
- for(unsigned int c_ix = 0; c_ix < num_of_registered_channels; c_ix++) {
-
- //printf("\n\n\nTRIGGER CHANNELS\n");
-
- registered_channels[c_ix]->trigger();
- }
-
-
-
-
-
-
- for(unsigned int a_ix = 0; a_ix < num_of_registered_agents; a_ix++) {
-
- registered_agents[a_ix]->trigger();
-
- if(flag_csv_writer_exist) {
-
- if(registered_agents[a_ix]->get_flag_bunched_score_exist()) {
- csv_writer->write_field(registered_agents[a_ix]->get_bunched_score());
- csv_writer->make_new_field();
- csv_writer->write_field((int)registered_agents[a_ix]->get_bunch_score_confidency());
- }
- else if(registered_agents[a_ix]->get_flag_abstracted_sensor_score_exist(0)) {
- csv_writer->write_field(registered_agents[a_ix]->get_abstracted_sensor_score(0));
- }
-
- if(a_ix < num_of_registered_agents-1) {
- csv_writer->make_new_field();
- }
- }
- }
-
- if(flag_csv_writer_exist) {
- csv_writer->make_new_line();
- }
-
-
- getchar();
-
- }
-
-
- if(flag_csv_writer_exist) {
- csv_writer->close_file();
- }
-
-
-}
-
-//for agents:
-unsigned int Testbench :: get_num_of_registered_agents() {
- return num_of_registered_agents;
-}
-
-bool Testbench :: register_agent(Agent *agent) {
- if(num_of_registered_agents < MAX_NUM_OF_AGENTS) {
- registered_agents[num_of_registered_agents] = agent;
- num_of_registered_agents++;
- return true;
- }
- return false;
-}
-
-bool Testbench :: deregister_agent(Agent *agent) {
- unsigned int agent_ix;
-
- if(get_ix_of_agent(agent, &agent_ix)) {
- return deregister_agent(agent_ix);
- }
-
- return false;
-}
-
-bool Testbench :: deregister_agent(unsigned int agent_ix) {
- if(agent_ix < num_of_registered_agents) {
- for(unsigned int a_ix=agent_ix; a_ix<num_of_registered_agents-1; a_ix++) {
- registered_agents[a_ix] = registered_agents[a_ix+1];
- }
- num_of_registered_agents--;
-
- return true;
- }
- return false;
-}
-
-bool Testbench :: get_ix_of_agent(Agent *agent, unsigned int *agent_ix) {
- for(unsigned int a_ix=0; a_ix<num_of_registered_agents; a_ix++) {
- if(registered_agents[a_ix] == agent) {
- *agent_ix = a_ix;
- return true;
- }
- }
- return false;
-}
-
-
-//for sensors:
-unsigned int Testbench :: get_num_of_registered_sensors() {
- return num_of_registered_sensors;
-}
-
-bool Testbench :: register_sensor(Sensor* sensor) {
- if(num_of_registered_sensors < MAX_NUM_OF_SENSORS) {
- registered_sensors[num_of_registered_sensors] = sensor;
- num_of_registered_sensors++;
- return true;
- }
- return false;
-}
-
-bool Testbench :: register_sensor(Sensor* sensor, CSV_Reader *csvr) {
- if(num_of_registered_sensors < MAX_NUM_OF_SENSORS) {
- registered_sensors[num_of_registered_sensors] = sensor;
- registered_sensors_csvr[num_of_registered_sensors] = csvr;
- flag_sensor_has_csvr[num_of_registered_sensors] = true;
-
- num_of_registered_sensors++;
- return true;
- }
-
- return false;
-}
-
-bool Testbench :: deregister_sensor(Sensor* sensor) {
- unsigned int sensor_ix;
-
- if(get_ix_of_sensor(sensor, &sensor_ix)) {
- return deregister_sensor(sensor_ix);
- }
-
- return false;
-}
-
-bool Testbench :: deregister_sensor(unsigned int sensor_ix) {
- if(sensor_ix < num_of_registered_sensors) {
- for(unsigned int s_ix=sensor_ix; s_ix<num_of_registered_sensors-1; s_ix++) {
- registered_sensors[s_ix] = registered_sensors[s_ix+1];
- //todo: next 2 lines are untested - test then
- registered_sensors_csvr[s_ix] = registered_sensors_csvr[s_ix+1];
- flag_sensor_has_csvr[s_ix] = flag_sensor_has_csvr[s_ix+1];
- }
- num_of_registered_sensors--;
-
- return true;
- }
- return false;
-}
-
-bool Testbench :: get_ix_of_sensor(Sensor* sensor, unsigned int *sensor_ix) {
- for(unsigned int s_ix=0; s_ix<num_of_registered_sensors; s_ix++) {
- if(registered_sensors[s_ix] == sensor) {
- *sensor_ix = s_ix;
- return true;
- }
- }
- return false;
-}
-
-bool Testbench :: get_flag_sensor_has_csvr(unsigned int sensor_ix) {
- return flag_sensor_has_csvr[sensor_ix];
-}
-
-CSV_Reader* Testbench :: get_registered_sensors_csvr(unsigned int sensor_ix) {
- if(flag_sensor_has_csvr[sensor_ix]) {
- return registered_sensors_csvr[sensor_ix];
- }
- return NULL;
-}
-
-//TODO: test following function! ...until now it is untested
-CSV_Reader* Testbench :: get_registered_sensors_csvr(Sensor* sensor) {
- unsigned int sensor_ix;
-
- if(get_ix_of_sensor(sensor, &sensor_ix)) {
- if(flag_sensor_has_csvr[sensor_ix]) {
- return registered_sensors_csvr[sensor_ix];
- }
- }
-
- return NULL;
-}
-
-
-
-
-
-
-//for channels:
-unsigned int Testbench :: get_num_of_registered_channels() {
- return num_of_registered_channels;
-}
-
-bool Testbench :: register_channel(Channel* channel) {
- if(num_of_registered_channels < MAX_NUM_OF_CHANNELS) {
- registered_channels[num_of_registered_channels] = channel;
- num_of_registered_channels++;
- return true;
- }
- return false;
-}
-
-bool Testbench :: deregister_channel(Channel* channel) {
- unsigned int channel_ix;
-
- if(get_ix_of_channel(channel, &channel_ix)) {
- return deregister_channel(channel_ix);
- }
-
- return false;
-}
-
-bool Testbench :: deregister_channel(unsigned int channel_ix) {
- if(channel_ix < num_of_registered_channels) {
- for(unsigned int c_ix=channel_ix; c_ix<num_of_registered_channels-1; c_ix++) {
- registered_channels[channel_ix] = registered_channels[channel_ix+1];
- }
- num_of_registered_channels--;
-
- return true;
- }
- return false;
-}
-
-bool Testbench :: get_ix_of_channel(Channel* channel, unsigned int *channel_ix) {
- for(unsigned int c_ix=0; c_ix<num_of_registered_channels; c_ix++) {
- if(registered_channels[c_ix] == channel) {
- *channel_ix = c_ix;
- return true;
- }
- }
- return false;
-}
-
-bool Testbench :: register_csv_reader(CSV_Reader* csv_reader) {
- if(csv_reader != NULL) {
- this->csv_reader = csv_reader;
- flag_csv_reader_exist = true;
- return true;
- }
- return false;
-}
-
-bool Testbench :: register_csv_writer(CSV_Writer* csv_writer) {
- if(csv_writer != NULL) {
- this->csv_writer = csv_writer;
- flag_csv_writer_exist = true;
- return true;
- }
- return false;
-}
-*/
diff --git a/Version_Max_07_05_2018_CMake/src/Testbench.h b/Version_Max_07_05_2018_CMake/src/Testbench.h
index 7ad9dfc..390b98b 100755
--- a/Version_Max_07_05_2018_CMake/src/Testbench.h
+++ b/Version_Max_07_05_2018_CMake/src/Testbench.h
@@ -1,219 +1,165 @@
#ifndef TESTBENCH_HEADERFILE
#define TESTBENCH_HEADERFILE
#include <vector>
#include "AgentSlotOfTestbench.h"
#include "ChannelSlotOfTestbench.h"
#include "CSVreaderModule.h"
#include "SensorSlotOfTestbench.h"
#include "Unit.h"
#include "Agent.h"
#include "Testbench_Config.h"
/*
#include "Agent.h"
#include "Channel.h"
#include "CSVreader.h"
#include "CSV_Writer.h"
#define MAX_NUM_OF_AGENTS 20
#define MAX_NUM_OF_CHANNELS 80
#define MAX_NUM_OF_SENSORS 20
*/
using namespace std;
//definitions for the linear function blocks, with their associated linear function names
//first name of the linear function block and then the names of the linear functions registered
//within this function block, is later used to identify the right linear function
//to parameterize it correctly.
const string FUNC_BLOCK_NAME_SAME_STATE_DEV = "funcBlock:confSim2StateDev";
const string CONF_SIM2_STATE_DEV_1 = "ConfSim2StateDev1";
const string CONF_SIM2_STATE_DEV_2 = "ConfSim2StateDev2";
const string CONF_SIM2_STATE_DEV_3 = "ConfSim2StateDev3";
const string CONF_SIM2_STATE_DEV_4 = "ConfSim2StateDev4";
const string CONF_SIM2_STATE_DEV_5 = "ConfSim2StateDev5";
const string FUNC_BLOCK_NAME_ANOTHER_STATE_DEV = "funcBlock:confDif2StateDev";
const string CONF_DIF2_STATE_DEV_1 = "ConfDif2StateDev1";
const string CONF_DIF2_STATE_DEV_2 = "ConfDif2StateDev2";
const string CONF_DIF2_STATE_DEV_3 = "ConfDif2StateDev3";
const string CONF_DIF2_STATE_DEV_4 = "ConfDif2StateDev4";
const string CONF_DIF2_STATE_DEV_5 = "ConfDif2StateDev5";
const string FUNC_BLOCK_NAME_SAME_TIME = "funcBlock:confSim2StateTime";
const string CONF_SIM2_STATE_TIME_1 = "ConfSim2StateTime1";
const string CONF_SIM2_STATE_TIME_2 = "ConfSim2StateTime2";
const string CONF_SIM2_STATE_TIME_3 = "ConfSim2StateTime3";
const string FUNC_BLOCK_NAME_ANOTHER_STATE_TIME = "funcBlock:confDif2StateTime";
const string CONF_DIF2_STATE_TIME_1 = "ConfDif2StateTime1";
const string CONF_DIF2_STATE_TIME_2 = "ConfDif2StateTime2";
const string CONF_DIF2_STATE_TIME_3 = "ConfDif2StateTime3";
const string FUNC_BLOCK_NAME_VAILD_STATE_DEV = "funcBlock:confValidStateDev";
const string CONF_VALID_STATE_DEV_1 = "ConfValidStateDev1";
const string CONF_VALID_STATE_DEV_2 = "ConfValidStateDev2";
const string CONF_VALID_STATE_DEV_3 = "ConfValidStateDev3";
const string CONF_VALID_STATE_DEV_4 = "ConfValidStateDev4";
const string CONF_VALID_STATE_DEV_5 = "ConfValidStateDev5";
const string FUNC_BLOCK_NAME_INVALID_STATE_DEV = "funcBlock:confInvalidStateDev";
const string CONF_INVALID_STATE_DEV_1 = "ConfInvalidStateDev1";
const string CONF_INVALID_STATE_DEV_2 = "ConfInvalidStateDev2";
const string CONF_INVALID_STATE_DEV_3 = "ConfInvalidStateDev3";
const string CONF_INVALID_STATE_DEV_4 = "ConfInvalidStateDev4";
const string CONF_INVALID_STATE_DEV_5 = "ConfInvalidStateDev5";
const string FUNC_BLOCK_NAME_VALID_STATE_TIME = "funcBlock:confValidStateTime";
const string VALID_STATE_TIME_1 = "ValidStateTime1";
const string VALID_STATE_TIME_2 = "ValidStateTime2";
const string VALID_STATE_TIME_3 = "ValidStateTime3";
const string FUNC_BLOCK_NAME_INVALID_STATE_TIME = "funcBlock:confInvalidStateTime";
const string INVALID_STATE_TIME_1 = "InvalidStateTime1";
const string INVALID_STATE_TIME_2 = "InvalidStateTime2";
const string INVALID_STATE_TIME_3 = "InvalidStateTime3";
const string FUNC_BLOCK_NAME_CONFIDENCE_STATE_DRIFTS = "confidence:confStateDrifts";
const string CONFIDENCE_DRIFT_DEVIATION_1 = "ConfidenceDriftDeviation1";
const string CONFIDENCE_DRIFT_DEVIATION_2 = "ConfidenceDriftDeviation2";
const string CONFIDENCE_DRIFT_DEVIATION_3 = "ConfidenceDriftDeviation3";
const string CONFIDENCE_DRIFT_DEVIATION_4 = "ConfidenceDriftDeviation4";
const string CONFIDENCE_DRIFT_DEVIATION_5 = "ConfidenceDriftDeviation5";
const string FUNC_BLOCK_NAME_CONFIDENCE_BROKEN = "confidence:broken";
const string CONFIDENCE_BROKEN_1 = "ConfidenceBroken1";
const string CONFIDENCE_BROKEN_2 = "ConfidenceBroken2";
const string CONFIDENCE_BROKEN_3 = "ConfidenceBroken3";
class Testbench : public Module {
private:
//TODO: set- and get function for maxNumOf_registeredAgents;
vector<AgentSlotOfTestbench*> vector_registeredAgents;
//TODO: set- and get function for maxNumOf_registeredChannels;
vector<ChannelSlotOfTestbench*> vector_registeredChannels;
//TODO: set- and get function for maxNumOf_registeredSensors;
vector<SensorSlotOfTestbench*> vector_registeredSensors;
vector<Testbench_Config*> vector_registered_Configs;
+
void remove_all_Testbench_Configs();
+
+
void remove_all_Agents();
void remove_all_Channels();
void remove_all_Sensors();
+
void set_parameters_FuncBlockConfSim2StateDev(LinearFunctionBlock* FuncBlockConfSim2StateDev);
void set_parameters_FuncBlockConfDif2StateDev(LinearFunctionBlock* FuncBlockConfDif2StateDev);
void set_parameters_FuncBlockConfSim2StateTime(LinearFunctionBlock* FuncBlockConfSim2StateTime);
void set_parameters_FuncBlockConfDif2StateTime(LinearFunctionBlock* FuncBlockConfDif2StateTime);
void set_parameters_FuncBlockConfValStateDev(LinearFunctionBlock* FuncBlockConfValStateDev);
void set_parameters_FuncBlockConfInvStateDev(LinearFunctionBlock* FuncBlockConfInvStateDev);
void set_parameters_FuncBlockConfValStateTime(LinearFunctionBlock* FuncBlockConfValStateTime);
void set_parameters_FuncBlockConfInvStateTime(LinearFunctionBlock* FuncBlockConfInvStateTime);
void set_parameters_DriftDeviation(LinearFunctionBlock* DriftDeviation);
void set_parameters_FuncBlockConfBrokenSamples(LinearFunctionBlock* FuncBlockConfBrokenSamples);
public:
static const unsigned int MAXNUM_OF_REGISTERED_AGENTS = 1000;
static const unsigned int MAXNUM_OF_REGISTERED_CHANNELS = 1000;
static const unsigned int MAXNUM_OF_REGISTERED_SENSORS = 1000;
Testbench();
Testbench(std::string name);
void init_testbench();
bool register_agent(Agent* agent);
bool register_sensor(Sensor* sensor);
SensorSlotOfTestbench* get_sensorSlotAddressOfTestbench(Sensor* sensor);
bool register_channel(Channel* channel);
bool register_testbench_config(Testbench_Config* tb_config);
vector<Testbench_Config*>& get_all_registered_testbench_configs();
void set_current_tb_config_index(const int index);
Testbench_Config* get_current_Testbench_config();
+
void set_config_values_in_linear_functions();
bool free_resources();
+
void set_CSV_Writer_parameter();
+
void set_CSV_Reader_row(const int start_row);
void set_CSV_Reader_to_beginning();
void reset_States();
void reset_States_and_Slave_Agents();
void simulate(unsigned int rounds);
vector<AgentSlotOfTestbench*>& get_all_registeredAgents();
~Testbench();
-
-
-
-
- /*
- private:
-
- unsigned int num_of_registered_agents;
- Agent* registered_agents[MAX_NUM_OF_AGENTS];
-
- unsigned int num_of_registered_channels;
- Channel* registered_channels[MAX_NUM_OF_CHANNELS];
-
- unsigned int num_of_registered_sensors;
- Sensor* registered_sensors[MAX_NUM_OF_SENSORS];
- CSV_Reader* registered_sensors_csvr[MAX_NUM_OF_SENSORS];
- bool flag_sensor_has_csvr[MAX_NUM_OF_SENSORS];
-
- //csv
- CSV_Reader* csv_reader;
- bool flag_csv_reader_exist;
-
- CSV_Writer* csv_writer;
- bool flag_csv_writer_exist;
-
- public:
- Testbench();
- Testbench(char* name);
-
- void simulate();
-
- //for agents:
- unsigned int get_num_of_registered_agents();
- bool register_agent(Agent* agent);
- bool deregister_agent(Agent* agent);
- bool deregister_agent(unsigned int agent_ix);
- bool get_ix_of_agent(Agent* agent, unsigned int *agent_ix);
-
- //for sensors:
- unsigned int get_num_of_registered_sensors();
- bool register_sensor(Sensor* sensor);
- bool register_sensor(Sensor* sensor, CSV_Reader *csvr);
- bool deregister_sensor(Sensor* sensor);
- bool deregister_sensor(unsigned int sensor_ix);
- bool get_ix_of_sensor(Sensor* sensor, unsigned int *sensor_ix);
- bool get_flag_sensor_has_csvr(unsigned int sensor_ix);
- CSV_Reader* get_registered_sensors_csvr(unsigned int sensor_ix);
- CSV_Reader* get_registered_sensors_csvr(Sensor* sensor);
-
-
-
- //for channels:
- unsigned int get_num_of_registered_channels();
- bool register_channel(Channel* channel);
- bool deregister_channel(Channel* channel);
- bool deregister_channel(unsigned int channel_ix);
- bool get_ix_of_channel(Channel* channel, unsigned int *channel_ix);
-
- //csv
- bool register_csv_reader(CSV_Reader* csv_reader);
- bool register_csv_writer(CSV_Writer* csv_writer);
- */
+
};
#endif
diff --git a/Version_Max_07_05_2018_CMake/src/Testbench_Config.cpp b/Version_Max_07_05_2018_CMake/src/Testbench_Config.cpp
index 2aefc48..ffda640 100755
--- a/Version_Max_07_05_2018_CMake/src/Testbench_Config.cpp
+++ b/Version_Max_07_05_2018_CMake/src/Testbench_Config.cpp
@@ -1,234 +1,235 @@
/*
* Testbench_Config.cpp
*
* Created on: 26.06.2018
* Author: edwin
*/
#include "Testbench_Config.h"
vector<Testbench_Config*> Testbench_Config::s_vec_all_created_Configs;
int Testbench_Config::s_counter_of_all_created_configs = 0;
int Testbench_Config::s_active_Config = 0;
/*
*
*/
void Testbench_Config::register_Config()
{
if(s_vec_all_created_Configs.max_size() > s_vec_all_created_Configs.size()){
s_vec_all_created_Configs.push_back(this);
this->m_current_index = s_counter_of_all_created_configs;
s_counter_of_all_created_configs = s_counter_of_all_created_configs + 1;
} else {
cout << "It is not possible to add an Testbench_Config to vector, Testbench_Config not registered" << endl;
}
}
/*
*
*/
void Testbench_Config::deregister_Config()
{
if (!s_vec_all_created_Configs.empty()) {
- int index = 0;
- int old_max_index = 0;
+ unsigned int index = 0;
+ unsigned int old_max_index = 0;
std::vector<Testbench_Config*>::iterator it = s_vec_all_created_Configs.begin();
for (; index != this->m_current_index; it++) {
index = index + 1;
}
old_max_index = s_vec_all_created_Configs.size() -1;
if (index == this->m_current_index) {
s_vec_all_created_Configs.erase(it);
}
if(index < old_max_index) {
adapt_Indices(index);
}
this->m_current_index = s_object_is_deleted;
s_counter_of_all_created_configs = s_counter_of_all_created_configs - 1;
}
}
/*
*
*/
-void Testbench_Config::adapt_Indices(int from_index_to_change)
+
+void Testbench_Config::adapt_Indices(unsigned int from_index_to_change)
{
- int index = 0;
+ unsigned int index = 0;
for(index = 0; index < s_vec_all_created_Configs.size(); index++){
if(index >= from_index_to_change) {
Testbench_Config* cur_config = s_vec_all_created_Configs[index];
cur_config->m_current_index = cur_config->m_current_index - 1;
}
}
}
Testbench_Config::Testbench_Config()
{
this->configuration.bound_broken = float(2);
this->configuration.outter_bound_sim_dif = (float)0.20;
this->configuration.inner_bound_sim_dif = (float)0.01;
this->configuration.outter_bound_drift = 3 * this->configuration.outter_bound_sim_dif;
this->configuration.inner_bound_drift = this->configuration.outter_bound_sim_dif;
- this->configuration.length = (float) 10;
+ this->configuration.length = (int) 10;
register_Config();
}
/*
*
*/
Testbench_Config::Testbench_Config(One_Config_t& a_config)
{
this->configuration = a_config;
register_Config();
}
/*
* return the index of the object in the static class vector
*/
int Testbench_Config::get_own_index()
{
return this->m_current_index;
}
/*
*
*/
One_Config_t Testbench_Config::get_Config()
{
One_Config_t dummy_config;
//if(this != NULL && this->m_current_index != s_object_is_deleted){
if (this->m_current_index != s_object_is_deleted) {
this->configuration.valid = true;
return this->configuration;
}
dummy_config.valid = false;
return dummy_config;
}
/*
*
*/
void Testbench_Config::print()
{
//if (this != NULL && this->m_current_index != s_object_is_deleted) {
if (this->m_current_index != s_object_is_deleted) {
std::cout << "Index of the configuration: " << this->m_current_index;
std::cout << "The values of the configuration are: ";
std::cout << "Broken boundary: " << this->configuration.bound_broken << " ";
std::cout << "Inner boundary similar state: " << this->configuration.inner_bound_sim_dif << " ";
std::cout << "Outter boundary similar state: " << this->configuration.outter_bound_sim_dif << " ";
std::cout << "Inner boundary drift: " << this->configuration.inner_bound_drift << " ";
std::cout << "Outter boundary drift: " << this->configuration.outter_bound_drift << " ";
std::cout << "Length: " << this->configuration.length << " ";
std::cout << std::endl;
}else {
std::cout << "Object points to NULL" << std::endl;
}
}
/**
* returns the index of the active config of the Testbench.
*/
int Testbench_Config::get_active_Config()
{
return s_active_Config;
}
/**
* Sets the index for the current config used.
* @param index value >= 0, -1 = Invalid Index
*
*/
void Testbench_Config::set_active_Config(const int index)
{
if(index < s_counter_of_all_created_configs) {
s_active_Config = index;
}else {
s_active_Config = s_INVALID_INDEX;
}
}
void Testbench_Config::cut_number_of_decimal_digits(std::string & str_number)
{ const std::string delimeter = ".";
const std::string zero = "0";
std::string str_temp;
std::size_t first_pos;
std::size_t length;
std::size_t first_not_zero;
std::size_t index;
length = str_number.length();
first_pos = str_number.find_first_of(delimeter);
if (first_pos != std::string::npos)
{
//0 is the start of the string, add 1 to get also the delimeter into the string
str_temp =str_number.substr(0, first_pos + 1);
length = length - first_pos - 1;
str_number = str_number.substr(first_pos + 1, length);
first_not_zero = str_number.find_first_not_of(zero);
if(first_not_zero == std::string::npos)
{
str_number = str_temp + str_number[0] + str_number[1];
}
else
{
for(index = 0; index <= first_not_zero; index++){
str_temp = str_temp + str_number[index];
}
str_number = str_temp;
}
}
}
/**
* returns all parameters of the config as a string.
* B_b means bound broken border, I_B_d means inner bound drift border
* O_B_d means outter bound drift border, I_B_s_d means inner bound simular signal border
* O_B_s_d means outter bound simular signalr border
*/
std::string Testbench_Config::get_Config_as_String()
{
//Ali for file name compatebility in Windows, all ':' chars converted to '-', also blanks removed or changed to '_'
std::string config;
std::string str_part;
str_part = std::to_string(this->configuration.bound_broken);
cut_number_of_decimal_digits(str_part);
config = "_B_b-" + str_part;
str_part = std::to_string(this->configuration.inner_bound_drift);
cut_number_of_decimal_digits(str_part);
config = config + "_I_B_d-"+ str_part;
str_part = std::to_string(this->configuration.outter_bound_drift);
cut_number_of_decimal_digits(str_part);
config = config + "_O_B_d-" + str_part;
str_part = std::to_string(this->configuration.inner_bound_sim_dif);
cut_number_of_decimal_digits(str_part);
config = config + "_I_B_s_d-" + str_part;
str_part = std::to_string(this->configuration.outter_bound_sim_dif);
cut_number_of_decimal_digits(str_part);
config = config + "_O_B_s_d-" + str_part + "";
config = config + "_Length-" + std::to_string(this->configuration.length) + "";
return config;
}
/*
*
*/
Testbench_Config::~Testbench_Config()
{
deregister_Config();
}
diff --git a/Version_Max_07_05_2018_CMake/src/Testbench_Config.h b/Version_Max_07_05_2018_CMake/src/Testbench_Config.h
index 14877bd..d22ab91 100755
--- a/Version_Max_07_05_2018_CMake/src/Testbench_Config.h
+++ b/Version_Max_07_05_2018_CMake/src/Testbench_Config.h
@@ -1,74 +1,74 @@
/*
* Testbench_Config.h
*
* Created on: 26.06.2018
* Author: edwin
*/
#ifndef TESTBENCH_CONFIG_H_
#define TESTBENCH_CONFIG_H_
#include <iostream>
#include <cstddef>
#include <vector>
#include <string>
#include <stdio.h>
using namespace std;
typedef struct One_Config {
///parameter of outter boundary for similar function
float outter_bound_sim_dif;
///parameter of inner boundary for similar function
float inner_bound_sim_dif;
///parameters of outter boundary for drift.
float outter_bound_drift;
///parameters of inner boundary for drift.
float inner_bound_drift;
///timer telling, after downsampling how many samples after input has changed it is allowed
///that output is changing, for very slow system high value and for fast system low value
float bound_broken;
///length where fuzzy function raises from 0 to 1 or 1 to 0 for the complementery.
///history of the data depends of it, and should change, if it changes.
int length;
//to show if the config was parameterised correctly.
bool valid;
} One_Config_t;
class Testbench_Config {
private:
static vector<Testbench_Config*> s_vec_all_created_Configs;
static int s_counter_of_all_created_configs;
static int s_active_Config;
const static int s_object_is_deleted = -1;
const static int s_INVALID_INDEX = -1;
const static int s_MAX_LENGTH_FLOAT_STRING = 20;
int m_current_index;
One_Config_t configuration;
void register_Config();
void deregister_Config();
- void adapt_Indices(int from_index_to_change);
+ void adapt_Indices(unsigned int from_index_to_change);
void cut_number_of_decimal_digits(std::string & str_number);
public:
Testbench_Config();
Testbench_Config(One_Config_t& a_config);
int get_own_index();
One_Config_t get_Config();
void print();
string get_Config_as_String();
~Testbench_Config();
static int get_active_Config();
static void set_active_Config(const int index);
};
#endif /* TESTBENCH_CONFIG_H_ */
diff --git a/Version_Max_07_05_2018_CMake/src/abstraction_interface.cpp b/Version_Max_07_05_2018_CMake/src/abstraction_interface.cpp
index 0b35364..07db2a3 100755
--- a/Version_Max_07_05_2018_CMake/src/abstraction_interface.cpp
+++ b/Version_Max_07_05_2018_CMake/src/abstraction_interface.cpp
@@ -1,20 +1,20 @@
//GENERATED FILE
#include "abstraction_interface.h"
#include "abstraction_functions.h"
bool abstract_interface(unsigned int abstraction_method,
unsigned int num_of_mounted_slaveagents, bool* flag_input_data_int_is_in_use, int* input_data_int,
unsigned int num_of_mounted_sensors, bool* flag_input_data_float_is_in_use, float* input_data_float) {
-
+ /*
switch(abstraction_method) {
default: return false;
}
-
+ */
return false;
}
\ No newline at end of file
diff --git a/Version_Max_07_05_2018_CMake/src/attach_modules.cpp b/Version_Max_07_05_2018_CMake/src/attach_modules.cpp
index c4d6f21..db59842 100755
--- a/Version_Max_07_05_2018_CMake/src/attach_modules.cpp
+++ b/Version_Max_07_05_2018_CMake/src/attach_modules.cpp
@@ -1,60 +1,60 @@
#include "attach_modules.h"
#include "rlutil.h"
-#define PRINT
+//#define PRINT
using namespace rlutil;
bool attach_historyModuleToSensorSlotInAgent(Agent* agent, Sensor* sensor, Channel* inputPort, HistoryModule* historyModule) {
if(agent != NULL && inputPort != NULL && historyModule != NULL) {
SensorSlotOfAgent* sensorSlotOfAgent = agent->get_sensorHandlerOfAgent()->get_sensorSlotAddress(inputPort);
if(sensorSlotOfAgent != NULL) {
#ifdef PRINT
printf(" > HistoryModule ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", historyModule->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", historyModule->get_id());
#endif // PRINT
if(sensorSlotOfAgent->set_historyModule(historyModule)) {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTGREEN);
printf("attached ");
setColor(TXTCOLOR_GREY);
printf("to Sensor ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) in Agent ", sensor->get_id());
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", agent->get_id());
#endif // PRINT
return true;
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf("Couldn't attach the HistoryModule!\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Couldn't attach the HistoryModule because Sensor isn't mounted in %s (id: %03u)!\n", agent->get_name().c_str(), agent->get_id());
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Couldn't attach the HistoryModule because Agent, Channel, or HistoryModule is not valid!\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
return false;
}
\ No newline at end of file
diff --git a/Version_Max_07_05_2018_CMake/src/attach_modulesToTestbench.cpp b/Version_Max_07_05_2018_CMake/src/attach_modulesToTestbench.cpp
index d90ffe6..db8bb30 100755
--- a/Version_Max_07_05_2018_CMake/src/attach_modulesToTestbench.cpp
+++ b/Version_Max_07_05_2018_CMake/src/attach_modulesToTestbench.cpp
@@ -1,62 +1,62 @@
#include "attach_modulesToTestbench.h"
#include "rlutil.h"
#include "SensorSlotOfTestbench.h"
-#define PRINT
+//#define PRINT
using namespace rlutil;
bool attach_csvReaderModuleToSensorSlotInAgent(Testbench* testbench, Sensor* sensor, CSVreaderModule* csvReaderModule) {
if(testbench != NULL && sensor != NULL && csvReaderModule != NULL) {
SensorSlotOfTestbench* sensorSlot = testbench->get_sensorSlotAddressOfTestbench(sensor);
if(sensorSlot != NULL) {
#ifdef PRINT
printf(" > CSV-Reader ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", csvReaderModule->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", csvReaderModule->get_id());
#endif // PRINT
if(sensorSlot->set_csvReaderModule(csvReaderModule)) {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTGREEN);
printf("attached ");
setColor(TXTCOLOR_GREY);
printf("to Sensor ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) in Testbench ", sensor->get_id());
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", testbench->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", testbench->get_id());
#endif // PRINT
return true;
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf("Couldn't attach the CSVreaderModule!\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Couldn't attach the CSVreaderModule because Sensor isn't registered in %s (id: %03u)!\n", testbench->get_name().c_str(), testbench->get_id());
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Couldn't attach the CSVreaderModule because Testbench, Sensorm or CSVreaderModule is not valid!\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
return false;
}
\ No newline at end of file
diff --git a/Version_Max_07_05_2018_CMake/src/config.h b/Version_Max_07_05_2018_CMake/src/config.h
index 76ab559..9fbd8d6 100644
--- a/Version_Max_07_05_2018_CMake/src/config.h
+++ b/Version_Max_07_05_2018_CMake/src/config.h
@@ -1,13 +1,13 @@
#ifndef CONFIG_H
#define CONFIG_H
#define NUM_DATA_POINTS 4
#define DATA_NAMES "a096FC6204", "a096FC6204_Y", "a096FC6204_SP", "a096PI6284"
#define OUTTER_BOUND_SIM_DIF 0.2
#define INNER_BOUND_SIM_DIF 0.01
#define BOUND_BROKEN 2
#define LENGTH 20
#define INPUT_FILE_NAME "export_2018-03-21_170700-2018-03-22_030000.csv"
#define INPUT_FILE_PATH "../data"
#define INPUT_FILE_LENGTH 593
-#define PRINT
+//#define PRINT
#endif //CONFIG_H
diff --git a/Version_Max_07_05_2018_CMake/src/create_unit.cpp b/Version_Max_07_05_2018_CMake/src/create_unit.cpp
index 448176c..273539c 100755
--- a/Version_Max_07_05_2018_CMake/src/create_unit.cpp
+++ b/Version_Max_07_05_2018_CMake/src/create_unit.cpp
@@ -1,419 +1,413 @@
#include "create_unit.h"
#include "errno.h"
#include "rlutil.h"
#include <stdio.h>
using namespace rlutil;
-#define PRINT
+//#define PRINT
void print_agent(Agent agent) {}
Agent *create_agent() { return create_agent(NO_NAME); }
Agent *create_agent(std::string name) {
Agent *agent = new Agent(name);
#ifdef PRINT
printf(" > Agent ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", agent->get_id());
setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
return agent;
}
Sensor *create_sensor() { return create_sensor(NO_NAME); }
Sensor *create_sensor(std::string name) {
Sensor *sensor = new Sensor(name);
#ifdef PRINT
printf(" > Sensor ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", sensor->get_id());
setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
return sensor;
}
HistoryModule create_historyModule(unsigned int history_length,
int delimitation_mode) {
return create_historyModule(NO_NAME, history_length, delimitation_mode);
}
HistoryModule create_historyModule(std::string name,
unsigned int history_length,
int delimitation_mode) {
HistoryModule historyModule(name);
#ifdef PRINT
printf(" > History ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", historyModule.get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", historyModule.get_id());
setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
if (historyModule.set_maxHistoryLength(history_length)) {
#ifdef PRINT
printf(" > History length ");
setColor(TXTCOLOR_LIGHTGREEN);
printf("set ");
setColor(TXTCOLOR_GREY);
printf("to %u\n", history_length);
#endif // PRINT
} else {
setColor(TXTCOLOR_LIGHTRED);
printf(" > historyLength could not set (out of allowed range).");
setColor(TXTCOLOR_GREY);
}
if (historyModule.set_delimitationMode(delimitation_mode)) {
#ifdef PRINT
printf(" > Delimitation Mode ");
setColor(TXTCOLOR_LIGHTGREEN);
printf("set ");
setColor(TXTCOLOR_GREY);
printf("to %u\n", delimitation_mode);
#endif // PRINT
} else {
setColor(TXTCOLOR_LIGHTRED);
printf(" > Delimitation Mode could not set (out of allowed range).");
setColor(TXTCOLOR_GREY);
}
return historyModule;
}
Channel *create_channel(unsigned int transfer_rate) {
return create_channel(NO_NAME, transfer_rate);
}
Channel *create_channel(std::string name, unsigned int transfer_rate) {
Channel *channel = new Channel(name);
#ifdef PRINT
printf(" > Channel ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", channel->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", channel->get_id());
setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
if (channel->set_transferRate(transfer_rate)) {
if (transfer_rate != 0) {
#ifdef PRINT
printf(" > transfer rate ");
setColor(TXTCOLOR_LIGHTGREEN);
printf("set ");
setColor(TXTCOLOR_GREY);
printf("to %i\n", transfer_rate);
#endif // PRINT
} else {
#ifdef PRINT
printf(" > transfer ");
setColor(TXTCOLOR_LIGHTGREEN);
printf("set ");
setColor(TXTCOLOR_GREY);
printf("to immediately transportation\n");
#endif // PRINT
}
} else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Transfer Rate out of allowed bounds!\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
return channel;
}
Testbench *create_testbench() { return create_testbench(NO_NAME); }
Testbench *create_testbench(std::string name) {
Testbench *testbench = new Testbench(name);
#ifdef PRINT
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", testbench->get_name().c_str());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", testbench->get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
rlutil::setColor(TXTCOLOR_GREY);
#endif // PRINT
testbench->init_testbench();
return testbench;
}
/*
Lookuptable create_lookuptable() {
Lookuptable lut;
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", lut.get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", lut.get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
rlutil::setColor(TXTCOLOR_GREY);
return lut;
}
Lookuptable create_lookuptable(char* name) {
Lookuptable lut(name);
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", lut.get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", lut.get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
rlutil::setColor(TXTCOLOR_GREY);
return lut;
}
void print_confidence_validator(Confidence_Validator conf_valid) {
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", conf_valid.get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", conf_valid.get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
rlutil::setColor(TXTCOLOR_GREY);
printf(" - range of validity ");
if(conf_valid.get_flag_lower_bound_exist())
printf("[ %.3f, ", conf_valid.get_lower_bound());
else
printf("] -inf, ");
if(conf_valid.get_flag_upper_bound_exist())
printf("%.3f ] ", conf_valid.get_upper_bound());
else
printf("+inf [ ");
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("set\n");
rlutil::setColor(TXTCOLOR_GREY);
if(conf_valid.get_flag_rates_of_change_exist()) {
printf(" - validity for rates of change of ");
printf("%.3f ", conf_valid.get_rates_of_change());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("set\n");
rlutil::setColor(TXTCOLOR_GREY);
}
}
Confidence_Validator create_confidence_validator(float lower_bound, bool
flag_lower_bound_exist, float upper_bound, bool flag_upper_bound_exist, float
rates_of_change, bool flag_rates_of_change_exist) { Confidence_Validator
conf_valid(lower_bound, flag_lower_bound_exist, upper_bound,
flag_upper_bound_exist, rates_of_change, flag_rates_of_change_exist);
print_confidence_validator(conf_valid);
return conf_valid;
}
Confidence_Validator create_confidence_validator(char* name, float lower_bound,
bool flag_lower_bound_exist, float upper_bound, bool flag_upper_bound_exist,
float rates_of_change, bool flag_rates_of_change_exist) { Confidence_Validator
conf_valid(name, lower_bound, flag_lower_bound_exist, upper_bound,
flag_upper_bound_exist, rates_of_change, flag_rates_of_change_exist);
print_confidence_validator(conf_valid);
return conf_valid;
}
void print_abstraction_module(Abstraction abstraction) {
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", abstraction.get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", abstraction.get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
rlutil::setColor(TXTCOLOR_GREY);
//TODO: abstraction method printen
printf(" - abstraction method %u ",
abstraction.get_abstraction_method()); rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("set\n");
rlutil::setColor(TXTCOLOR_GREY);
//TODO: auch das hier bissl sch�ner machen
if(abstraction.get_flag_lookuptable_exist(0)) {
printf(" - position 0 connected mit Look up Table ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", abstraction.get_lookuptable(0)->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", abstraction.get_lookuptable(0)->get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("set\n");
rlutil::setColor(TXTCOLOR_GREY);
}
}
Abstraction create_abstraction_module(Lookuptable* lut, unsigned int
abstraction_method) { Abstraction abstraction(lut, abstraction_method);
print_abstraction_module(abstraction);
return abstraction;
}
Abstraction create_abstraction_module(char* name, Lookuptable* lut, unsigned int
abstraction_method) { Abstraction abstraction(name, lut, abstraction_method);
print_abstraction_module(abstraction);
return abstraction;
}
void print_bunch_module(Bunch_Module bunch_module) {
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", bunch_module.get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", bunch_module.get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
rlutil::setColor(TXTCOLOR_GREY);
//TODO: abstraction method printen
printf(" - abstraction method %u ", bunch_module.get_bunch_method());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("set\n");
rlutil::setColor(TXTCOLOR_GREY);
}
Bunch_Module create_bunch_module(unsigned int bunch_method) {
Bunch_Module bunch_module(bunch_method);
print_bunch_module(bunch_module);
return bunch_module;
}
Bunch_Module create_bunch_module(char* name, unsigned int bunch_method) {
Bunch_Module bunch_module(name, bunch_method);
print_bunch_module(bunch_module);
return bunch_module;
}
*/
FILE *make_file_pointer(const char *filepath, int mode) {
bool file_opened;
FILE *fpointer = nullptr;
if (mode == CSV_MODE_READ) {
#ifdef _WIN32
file_opened = fopen_s(&fpointer, filepath, "r"); // only windows compatible
#else
fpointer = fopen(filepath, "r");
#endif
} else if (mode == CSV_MODE_WRITE) {
#ifdef _WIN32
file_opened = fopen_s(&fpointer, filepath, "w"); // only windows compatible
#else
fpointer = fopen(filepath, "w");
#endif
} else {
#ifdef PRINT
printf("File pointer mode for \"%s\" ", filepath);
rlutil::setColor(TXTCOLOR_LIGHTRED);
printf("is not supported!\n");
rlutil::setColor(TXTCOLOR_GREY);
#endif // PRINT
return NULL;
}
// if(file_opened == 0) {
if (fpointer != nullptr && file_opened == 0) {
return fpointer;
}
#ifdef PRINT
printf("File pointer \"%s\" ", filepath);
rlutil::setColor(TXTCOLOR_LIGHTRED);
printf("could not created!\n");
rlutil::setColor(TXTCOLOR_GREY);
#endif // PRINT
return NULL;
}
void print_csv_reader(CSVreaderModule *csvReaderModule, const char *filepath) {
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", csvReaderModule->get_name().c_str());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) for \"%s\" ", csvReaderModule->get_id(), filepath);
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
rlutil::setColor(TXTCOLOR_GREY);
}
CSVreaderModule *create_CSVreaderModule(const char *filepath,
unsigned int column,
unsigned int start_row) {
FILE *fpointer = make_file_pointer(filepath, CSV_MODE_READ);
if (fpointer) {
CSVreaderModule *csvr = new CSVreaderModule(fpointer, column, start_row);
print_csv_reader(csvr, filepath);
return csvr;
} else {
CSVreaderModule *csvr = new CSVreaderModule();
return csvr;
}
}
CSVreaderModule *create_CSVreaderModule(std::string name, const char *filepath,
unsigned int column,
unsigned int start_row) {
FILE *fpointer = make_file_pointer(filepath, CSV_MODE_READ);
- if (fpointer == NULL) {
- printf("DA IS DER HUND\n");
- } else {
- printf("ALLES GUT\n");
- }
-
if (fpointer) {
CSVreaderModule *csvr =
new CSVreaderModule(name, fpointer, column, start_row);
#ifdef PRINT
print_csv_reader(csvr, filepath);
#endif // PRINT
return csvr;
} else {
CSVreaderModule *csvr = new CSVreaderModule;
return csvr;
}
}
StateHandler create_stateHandler() { return create_stateHandler(NO_NAME); }
StateHandler create_stateHandler(std::string name) {
StateHandler stateHandler(name);
return stateHandler;
}
diff --git a/Version_Max_07_05_2018_CMake/src/inAgentsRegistrations.cpp b/Version_Max_07_05_2018_CMake/src/inAgentsRegistrations.cpp
index ab19d98..57cacdf 100755
--- a/Version_Max_07_05_2018_CMake/src/inAgentsRegistrations.cpp
+++ b/Version_Max_07_05_2018_CMake/src/inAgentsRegistrations.cpp
@@ -1,105 +1,105 @@
#include "inAgentsRegistrations.h"
#include "rlutil.h"
-#define PRINT
+//#define PRINT
using namespace rlutil;
bool registerSlaveAgentAsInputVariableInStateHandler(Agent* masteragent, Channel* channel) {
if(masteragent != NULL || channel != NULL) {
SlaveAgentSlotOfAgent* slot = masteragent->get_slaveAgentHandlerOfAgent()->get_slaveAgentSlotAddress(channel);
if(slot != NULL) {
if(masteragent->get_stateHandler()->addInputVariable(slot)){
#ifdef PRINT
printf(" > Channel ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", channel->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", channel->get_id());
setColor(TXTCOLOR_LIGHTGREEN);
printf("registered ");
setColor(TXTCOLOR_GREY);
printf("as ");
setColor(TXTCOLOR_LIGHTGREEN);
printf("Input Variable ");
setColor(TXTCOLOR_GREY);
printf("in stateHandler of ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", masteragent->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", masteragent->get_id());
#endif // PRINT
return true;
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Channel %s (id: %03u) is not connected to Agent %s (id: %03u)\n", channel->get_name().c_str(), channel->get_id(), masteragent->get_name().c_str(), masteragent->get_id());
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Channel %s (id: %03u) is not connected to Agent %s (id: %03u)\n", channel->get_name().c_str(), channel->get_id(), masteragent->get_name().c_str(), masteragent->get_id());
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Agent or Channel is not valid\n");
#endif // PRINT
}
return false;
}
bool registerSlaveAgentAsOutputVariableInStateHandler(Agent* masteragent, Channel* channel) {
if (masteragent != NULL || channel != NULL) {
SlaveAgentSlotOfAgent* slot = masteragent->get_slaveAgentHandlerOfAgent()->get_slaveAgentSlotAddress(channel);
if (slot != NULL) {
if (masteragent->get_stateHandler()->addOutputVariable(slot)) {
#ifdef PRINT
printf(" > Channel ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", channel->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", channel->get_id());
setColor(TXTCOLOR_LIGHTGREEN);
printf("registered ");
setColor(TXTCOLOR_GREY);
printf("as ");
setColor(TXTCOLOR_LIGHTGREEN);
printf("Output Variable ");
setColor(TXTCOLOR_GREY);
printf("in stateHandler of ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", masteragent->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", masteragent->get_id());
#endif // PRINT
return true;
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Channel %s (id: %03u) is not connected to Agent %s (id: %03u)\n", channel->get_name().c_str(), channel->get_id(), masteragent->get_name().c_str(), masteragent->get_id());
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Channel %s (id: %03u) is not connected to Agent %s (id: %03u)\n", channel->get_name().c_str(), channel->get_id(), masteragent->get_name().c_str(), masteragent->get_id());
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Agent or Channel is not valid\n");
#endif // PRINT
}
return false;
}
\ No newline at end of file
diff --git a/Version_Max_07_05_2018_CMake/src/main.cpp b/Version_Max_07_05_2018_CMake/src/main.cpp
index e7fd594..fcf75e9 100755
--- a/Version_Max_07_05_2018_CMake/src/main.cpp
+++ b/Version_Max_07_05_2018_CMake/src/main.cpp
@@ -1,121 +1,141 @@
#include <stdio.h>
-#include <stdlib.h>
+#include <stdlib.h>
+#include <string>
#include "configCAMforNewMotor.h"
+#include "configCAMforFluid.h"
+#include "configCAMforOldMotor.h"
-#define CAM_FOR_FLUID 1
-#define CAM_FOR_NEWMOTOR 2
+#define CAM_FOR_FLUID 1
+#define CAM_FOR_NEWMOTOR 2
+#define CAM_FOR_OLDMOTOR 3
-#define PRINT
+//#define PRINT
#define STOP_AFTER_SUMMARY
-
-
int main(int argc, char *argv[]) {
-
- // paths config
- //TODO: maybe change char[] to String
- char datasetPath[700];
- char destinationPath[700];
-
- // dataset config
- char datasetName[200];
- unsigned int datasetLength;
-
- // CAM System config
- int camConfigOption;
-
- // CAM Values config (fuzzy functions etc.)
- float innerBoundSimDif;
- float outerBoundSimDif;
- int boundTimeInSamples;
- float innerBoundDrift;
- float outerBoundDrift;
- int boundBrokenTime;
- int downSamplingFactor;
-
-
- //if the only argument is the name of the executable itself.
- if (argc <= 1) {
- //configure here everything out of the C++ code.
-
-
- }
- else if (argc > 12) {
- // paths config
+ // paths config
+ // TODO: maybe change char[] to String
+ char datasetPath[700];
+ char destinationPath[700];
+
+ // dataset config
+ char datasetName[200];
+ unsigned int datasetLength;
+
+ // CAM System config
+ int camConfigOption;
+
+ // CAM Values config (fuzzy functions etc.)
+ float innerBoundSimDif;
+ float outerBoundSimDif;
+ int boundTimeInSamples;
+ unsigned int discreteAveragePartitionSize;
+ float innerBoundDrift;
+ float outerBoundDrift;
+ int boundBrokenTime;
+ int downSamplingFactor;
+
+ // if the only argument is the name of the executable itself.
+ if (argc <= 1) {
+ // configure here everything out of the C++ code.
+ printf("Got no (or to less) arguments. Pass arguements to the executeable "
+ "or setup CAM in the C++ project!");
+ /*
+ //Only for Debugging
+ char destPath[] = "C:\\csv-data\\IJOCI_Journal\\Motor\\Results\\Step1_"
+ "experimentResults\\20190102_someLoadChanges14s10kHz";
+
+ char dataPath[] =
+ "C:\\csv-data\\IJOCI_Journal\\Motor\\datasets\\20190102_someLoadChanges14s10kHz.csv";
+
+ char namePath[] = "someLoadChanges14s10kHz";
+
+
+ configAndStartNewMotorExperiment(
+ destPath, dataPath, namePath, 140001, (float)0.01, (float)0.14, (unsigned int)10, (float)0.12, (float)0.42, (unsigned int)10, (unsigned int)50);
+ */
+
+ } else if (argc > 13) {
+ //Read all arguments that were passed to the exe
+ //NOTE: they have to be in the right order. There is no Error Handling.
+ //TODO: make error handling
+
+ // paths config
#ifdef _WIN32
- sprintf_s(destinationPath, "%s", argv[1]);
- sprintf_s(datasetPath, "%s", argv[2]);
+ sprintf_s(destinationPath, "%s", argv[1]);
+ sprintf_s(datasetPath, "%s", argv[2]);
#else
- sprintf(destinationPath, "%s", argv[1]);
- sprintf(datasetPath, "%s", argv[2]);
+ sprintf(destinationPath, "%s", argv[1]);
+ sprintf(datasetPath, "%s", argv[2]);
#endif
- // dataset config
+ // dataset config
#ifdef _WIN32
- sprintf_s(datasetName, "%s", argv[3]);
+ sprintf_s(datasetName, "%s", argv[3]);
#else
- sprintf(datasetName, "%s", argv[3]);
+ sprintf(datasetName, "%s", argv[3]);
#endif
- datasetLength = (unsigned int)atoi(argv[4]);
-
- // CAM System config
- camConfigOption = atoi(argv[5]);
-
- // CAM Values config (fuzzy functions etc.)
- innerBoundSimDif = atof(argv[6]);
- outerBoundSimDif = atof(argv[7]);
- boundTimeInSamples = atoi(argv[8]);
- innerBoundDrift = atof(argv[9]);
- outerBoundDrift = atof(argv[10]);
- boundBrokenTime = atoi(argv[11]);
- downSamplingFactor = atoi(argv[12]);
-
-
+ datasetLength = (unsigned int)atoi(argv[4]);
+ // CAM System config
+ camConfigOption = atoi(argv[5]);
+ // CAM Values config (fuzzy functions etc.)
+ innerBoundSimDif = std::stof(argv[6]);
+ outerBoundSimDif = std::stof(argv[7]);
+ boundTimeInSamples = std::stoi(argv[8]);
+ discreteAveragePartitionSize = (unsigned int)atoi(argv[9]);
+ innerBoundDrift = std::stof(argv[10]);
+ outerBoundDrift = std::stof(argv[11]);
+ boundBrokenTime = std::stoi(argv[12]);
+ downSamplingFactor = std::stoi(argv[13]);
#ifdef PRINT
- printf("destinationPath: %s\n\n", destinationPath);
- printf("datasetPath: %s\n", datasetPath);
- printf("datasetName: %s\n", datasetName);
- printf("datasetLength: %u\n", datasetLength);
-
- printf("innerBoundSimDif: %f\n", innerBoundSimDif);
- printf("outerBoundSimDif: %f\n", outerBoundSimDif);
- printf("boundTimeInSamples: %i\n", boundTimeInSamples);
- printf("innerBoundDrift: %f\n", innerBoundDrift);
- printf("outerBoundDrift: %f\n", outerBoundDrift);
- printf("boundBrokenTime: %i\n", boundBrokenTime);
- printf("downSamplingFactor: %i\n", downSamplingFactor);
-
-
+ printf("destinationPath: %s\n\n", destinationPath);
+ printf("datasetPath: %s\n", datasetPath);
+ printf("datasetName: %s\n", datasetName);
+ printf("datasetLength: %u\n", datasetLength);
+
+ printf("innerBoundSimDif: %f\n", innerBoundSimDif);
+ printf("outerBoundSimDif: %f\n", outerBoundSimDif);
+ printf("boundTimeInSamples: %i\n", boundTimeInSamples);
+ printf("innerBoundDrift: %f\n", innerBoundDrift);
+ printf("outerBoundDrift: %f\n", outerBoundDrift);
+ printf("boundBrokenTime: %i\n", boundBrokenTime);
+ printf("downSamplingFactor: %i\n", downSamplingFactor);
#ifdef STOP_AFTER_SUMMARY
- getchar();
+ getchar();
#endif // STOP_AFTER_SUMMARY
#endif
- if (camConfigOption == CAM_FOR_FLUID) {
- //start Fluid CAM config
- /*
- configAndStartFluidExperiment(
- destinationPath, datasetPath, datasetName,
- datasetLength, innerBoundSimDif, outerBoundSimDif,
- boundTimeInSamples, innerBoundDrift,
- outerBoundDrift, boundBrokenTime,
- downSamplingFactor);
- */
- }
- else if (camConfigOption == CAM_FOR_NEWMOTOR) {
- //start newMotor CAM config
- configAndStartNewMotorExperiment(
- destinationPath, datasetPath, datasetName,
- datasetLength, innerBoundSimDif, outerBoundSimDif,
- boundTimeInSamples, innerBoundDrift,
- outerBoundDrift, boundBrokenTime,
- downSamplingFactor);
- }
- }
+ if (camConfigOption == CAM_FOR_FLUID) {
+ // start Fluid CAM config
+ configAndStartFluidExperiment(
+ destinationPath, datasetPath, datasetName, datasetLength,
+ innerBoundSimDif, outerBoundSimDif, boundTimeInSamples,
+ discreteAveragePartitionSize, innerBoundDrift, outerBoundDrift,
+ boundBrokenTime, downSamplingFactor);
+ } else if (camConfigOption == CAM_FOR_NEWMOTOR) {
+ // start newMotor CAM config
+ configAndStartNewMotorExperiment(
+ destinationPath, datasetPath, datasetName, datasetLength,
+ innerBoundSimDif, outerBoundSimDif, boundTimeInSamples,
+ discreteAveragePartitionSize, innerBoundDrift, outerBoundDrift,
+ boundBrokenTime, downSamplingFactor);
+ } else if (camConfigOption == CAM_FOR_OLDMOTOR) {
+ // start oldMotor CAM config
+ configAndStartOldMotorExperiment(
+ destinationPath, datasetPath, datasetName, datasetLength,
+ innerBoundSimDif, outerBoundSimDif, boundTimeInSamples,
+ discreteAveragePartitionSize, innerBoundDrift, outerBoundDrift,
+ boundBrokenTime, downSamplingFactor);
+ }else {
+ printf("Chosen config does not exist. Check Arguments that were passed!\n");
+ }
+ }
+
+ return 0;
}
diff --git a/Version_Max_07_05_2018_CMake/src/mount_nodes.cpp b/Version_Max_07_05_2018_CMake/src/mount_nodes.cpp
index 79e3609..c87bba7 100755
--- a/Version_Max_07_05_2018_CMake/src/mount_nodes.cpp
+++ b/Version_Max_07_05_2018_CMake/src/mount_nodes.cpp
@@ -1,408 +1,408 @@
#include "attach_modules.h"
#include "mount_nodes.h"
#include "rlutil.h"
#include <stdio.h>
-#define PRINT
+//#define PRINT
using namespace rlutil;
bool mount_sensorInAgent(Agent* agent, Sensor* sensor, Channel* channel) {
if(agent != NULL && sensor != NULL && channel != NULL) {
#ifdef PRINT
printf(" > Sensor ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", sensor->get_id());
#endif // PRINT
if(agent->get_sensorHandlerOfAgent()->mount_sensorIntoSensorSlot(channel) && sensor->mount_agent(channel)) {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
setColor(TXTCOLOR_GREY);
printf("in Agent ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", agent->get_id());
#endif // PRINT
return true;
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be mounted in %s (id: %03u)\n", agent->get_name().c_str(), agent->get_id());
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Agent, Sensor, or Channel is not valid\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
return false;
}
/*
void mount_sensor_in_agent(Agent* agent, Sensor* sensor, Channel* sensor_to_slave, unsigned int position) {
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", sensor->get_id());
if(agent->mount_sensor(sensor_to_slave, position) && sensor->mount_agent(sensor_to_slave)) {
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
rlutil::setColor(TXTCOLOR_GREY);
printf("in ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n - on position %u\n", agent->get_id(), position);
}
else {
rlutil::setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be mounted in %s (id: %03u) on position %u\n", agent->get_name(), agent->get_id(), position);
rlutil::setColor(TXTCOLOR_GREY);
}
}
*/
/*
void mount_sensor_in_agent(Agent* agent, Sensor* sensor, Channel* sensor_to_slave, Abstraction* abstraction) {
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", sensor->get_id());
if(agent->mount_sensor(sensor_to_slave, abstraction) && sensor->mount_agent(sensor_to_slave)) {
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
rlutil::setColor(TXTCOLOR_GREY);
printf("in ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n - ", agent->get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("connected ");
rlutil::setColor(TXTCOLOR_GREY);
printf("with Abstraction Module ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", abstraction->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", abstraction->get_id());
}
else {
rlutil::setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be mounted in %s (id: %03u) connected with Abstraction Module %s (id: %03u)\n", agent->get_name(), agent->get_id(), abstraction->get_name(), abstraction->get_id());
rlutil::setColor(TXTCOLOR_GREY);
}
}
*/
/*
void mount_sensor_in_agent(Agent* agent, Sensor* sensor, Channel* sensor_to_slave, Confidence_Validator* confidence_validator) {
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", sensor->get_id());
if(agent->mount_sensor(sensor_to_slave, confidence_validator) && sensor->mount_agent(sensor_to_slave)) {
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
rlutil::setColor(TXTCOLOR_GREY);
printf("in ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n - ", agent->get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("connected ");
rlutil::setColor(TXTCOLOR_GREY);
printf("with Range of Validity ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", confidence_validator->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", confidence_validator->get_id());
}
else {
rlutil::setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be mounted in %s (id: %03u) connected with Look up Table %s (id: %03u)\n", agent->get_name(), agent->get_id(), confidence_validator->get_name(), confidence_validator->get_id());
rlutil::setColor(TXTCOLOR_GREY);
}
}
*/
bool mount_sensorInAgent(Agent* agent, Sensor* sensor, Channel* channel, HistoryModule* historyModule) {
if(agent != NULL && sensor != NULL && channel != NULL && historyModule != NULL) {
if(mount_sensorInAgent(agent, sensor, channel)) {
return attach_historyModuleToSensorSlotInAgent(agent, sensor, channel, historyModule);
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf("Agent, Sensor, Channel, or HistoryModule is not valid\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
return false;
}
/*
void mount_sensor_in_agent(Agent* agent, Sensor* sensor, Channel* sensor_to_slave, Confidence_Validator* confidence_validator, Abstraction* abstraction) {
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", sensor->get_id());
if(agent->mount_sensor(sensor_to_slave, confidence_validator, abstraction) && sensor->mount_agent(sensor_to_slave)) {
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
rlutil::setColor(TXTCOLOR_GREY);
printf("in ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n - ", agent->get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("connected ");
rlutil::setColor(TXTCOLOR_GREY);
printf("with Range of Validity ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", confidence_validator->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n - ", confidence_validator->get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("connected ");
rlutil::setColor(TXTCOLOR_GREY);
printf("with Abstraction Module ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", abstraction->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", abstraction->get_id());
}
else {
rlutil::setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be mounted in %s (id: %03u) connected with Look up Table %s (id: %03u) and Abstraction Module %s (id: %03u)\n", agent->get_name(), agent->get_id(), confidence_validator->get_name(), confidence_validator->get_id(), abstraction->get_name(), abstraction->get_id());
rlutil::setColor(TXTCOLOR_GREY);
}
}
*/
bool mount_agentInAgent(Agent *masteragent, Agent* slaveagent, Channel* channel) {
if(masteragent != NULL && slaveagent != NULL && channel != NULL) {
if(masteragent->get_slaveAgentHandlerOfAgent()->mount_slaveAgentIntoSlaveAgentSlot(channel)) {
if(slaveagent->get_masterAgentHandlerOfAgent()->mount_masterAgentIntoSlaveAgentSlot(channel)) {
#ifdef PRINT
printf(" > Agent ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", slaveagent->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", slaveagent->get_id());
setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
setColor(TXTCOLOR_GREY);
printf("in Agent ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", masteragent->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", masteragent->get_id());
#endif // PRINT
return true;
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Could not mount Master Agent %s (id: %03u) in Slave Agent %s (id: %03u)\n", masteragent->get_name().c_str(), masteragent->get_id(), slaveagent->get_name().c_str(), slaveagent->get_id());
setColor(TXTCOLOR_GREY);
#endif // PRINT
masteragent->get_slaveAgentHandlerOfAgent()->demount_slaveAgentIntoSlaveAgentSlot(channel);
}
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > One of the Agents or Channel not valid\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
return false;
/*
if(masteragent->mount_slaveagent(slave_to_master, master_to_slave) && slaveagent->mount_masteragent(master_to_slave, slave_to_master)) {
setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
setColor(TXTCOLOR_GREY);
printf("in Agent ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", masteragent->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", masteragent->get_id());
if(master_to_slave != NULL && slave_to_master != NULL) {
printf(" > bidirectional communication ");
}
else {
printf(" > unidirectional communication ");
if(master_to_slave != NULL) {
printf("(Master to Slave: ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", master_to_slave->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)) ", master_to_slave->get_id());
}
if(slave_to_master != NULL) {
printf("(Slave to Master: ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", slave_to_master->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)) ", slave_to_master->get_id());
}
}
setColor(TXTCOLOR_LIGHTGREEN);
printf("set\n");
setColor(TXTCOLOR_GREY);
}
else {
setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be mounted in Agent %s (id: %03u)\n", masteragent->get_name(), masteragent->get_id());
setColor(TXTCOLOR_GREY);
}
*/
}
/*
void mount_slaveagent_in_agent(Agent *masteragent, Agent* slaveagent, Channel* master_to_slave, Channel* slave_to_master, unsigned int position) {
printf(" > Slave - ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", slaveagent->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", slaveagent->get_id());
if(masteragent->mount_slaveagent(slave_to_master, master_to_slave, position) && slaveagent->mount_masteragent(master_to_slave, slave_to_master)) {
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
rlutil::setColor(TXTCOLOR_GREY);
printf("in Master - ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", masteragent->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n - on position %u\n - ", masteragent->get_id(), position);
if(master_to_slave != NULL && slave_to_master != NULL)
printf("bidirectional communication\n");
else
printf("unidirectional communication\n");
if(master_to_slave != NULL) {
printf(" - Master to Slave: ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", master_to_slave->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", master_to_slave->get_id());
}
if(slave_to_master != NULL) {
printf(" - Slave to Master: ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", slave_to_master->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", slave_to_master->get_id());
}
}
else {
rlutil::setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be mounted in Master - %s (id: %03u) on position %u\n", masteragent->get_name(), masteragent->get_id(), position);
rlutil::setColor(TXTCOLOR_GREY);
}
}
*/
/*
void mount_slaveagent_in_agent(Agent *masteragent, Agent* slaveagent, Channel* master_to_slave, Channel* slave_to_master, Cross_Confidence_Validator* ccv) {
printf(" > Slave - ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", slaveagent->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", slaveagent->get_id());
if(masteragent->mount_slaveagent(slave_to_master, master_to_slave, ccv) && slaveagent->mount_masteragent(master_to_slave, slave_to_master)) {
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
rlutil::setColor(TXTCOLOR_GREY);
printf("in Master - ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", masteragent->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n - ", masteragent->get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("connected ");
rlutil::setColor(TXTCOLOR_GREY);
printf("with Cross Confidence Validator ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", ccv->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n - ", ccv->get_id());
if(master_to_slave != NULL && slave_to_master != NULL)
printf("bidirectional communication\n");
else
printf("unidirectional communication\n");
if(master_to_slave != NULL) {
printf(" - Master to Slave: ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", master_to_slave->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", master_to_slave->get_id());
}
if(slave_to_master != NULL) {
printf(" - Slave to Master: ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", slave_to_master->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", slave_to_master->get_id());
}
}
else {
rlutil::setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be mounted in Master - %s (id: %03u) with Cross Confidence Validator %s (id: %03u)\n", masteragent->get_name(), masteragent->get_id(), ccv->get_name(), ccv->get_id());
rlutil::setColor(TXTCOLOR_GREY);
}
}
*/
/*
void mount_bunchmodule_in_agent(Agent *agent, Bunch_Module* bunch_module) {
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", bunch_module->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", bunch_module->get_id());
if(agent->mount_bunch_module(bunch_module)) {
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
rlutil::setColor(TXTCOLOR_GREY);
printf("in ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", agent->get_id());
}
else {
rlutil::setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be mounted in %s (id: %03u)\n", agent->get_name(), agent->get_id());
rlutil::setColor(TXTCOLOR_GREY);
}
}
*/
diff --git a/Version_Max_07_05_2018_CMake/src/register_in_testbench.cpp b/Version_Max_07_05_2018_CMake/src/register_in_testbench.cpp
index 49bc5d0..dbbde56 100755
--- a/Version_Max_07_05_2018_CMake/src/register_in_testbench.cpp
+++ b/Version_Max_07_05_2018_CMake/src/register_in_testbench.cpp
@@ -1,130 +1,130 @@
#include "register_in_testbench.h"
#include "attach_modulesToTestbench.h"
#include "rlutil.h"
#include <stdio.h>
-#define PRINT
+//#define PRINT
using namespace rlutil;
bool register_agentInTestbench(Testbench *tb, Agent *agent) {
if(tb != NULL && agent != NULL) {
#ifdef PRINT
printf(" > Agent ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", agent->get_id());
#endif // PRINT
if(tb->register_agent(agent)) {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTGREEN);
printf("registered ");
setColor(TXTCOLOR_GREY);
printf("in Testbench ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s\n", tb->get_name().c_str());
setColor(TXTCOLOR_GREY);
#endif // PRINT
return true;
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be registered in %s", tb->get_name().c_str());
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Testbench or Agent is not valid\n");
#endif // PRINT
}
setColor(TXTCOLOR_GREY);
return false;
}
bool register_sensorInTestbench(Testbench *tb, Sensor *sensor) {
if(tb != NULL && sensor != NULL) {
#ifdef PRINT
printf(" > Sensor ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", sensor->get_id());
#endif // PRINT
if(tb->register_sensor(sensor)) {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTGREEN);
printf("registered ");
setColor(TXTCOLOR_GREY);
printf("in ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s\n", tb->get_name().c_str());
setColor(TXTCOLOR_GREY);
#endif // PRINT
return true;
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be registered in %s\n", tb->get_name().c_str());
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Testbench or sensor is not valid\n");
#endif // PRINT
}
setColor(TXTCOLOR_GREY);
return false;
}
bool register_sensorInTestbench(Testbench *tb, Sensor *sensor, CSVreaderModule *csvReaderModule) {
if(tb != NULL && sensor != NULL && csvReaderModule != NULL) {
if(register_sensorInTestbench(tb, sensor)) {
return attach_csvReaderModuleToSensorSlotInAgent(tb, sensor, csvReaderModule);
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf("Testbench or sensor is not valid\n");
#endif // PRINT
}
setColor(TXTCOLOR_GREY);
return false;
}
bool register_channelInTestbench(Testbench *tb, Channel *channel) {
#ifdef PRINT
printf(" > Channel ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", channel->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", channel->get_id());
#endif // PRINT
if(tb->register_channel(channel)){
#ifdef PRINT
setColor(TXTCOLOR_LIGHTGREEN);
printf("registered ");
setColor(TXTCOLOR_GREY);
printf("in Testbench ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s\n", tb->get_name().c_str());
#endif // PRINT
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be registered in %s\n", tb->get_name().c_str());
#endif // PRINT
}
setColor(TXTCOLOR_GREY);
return false;
}
diff --git a/Version_Max_07_05_2018_CMake/src/setupNode.cpp b/Version_Max_07_05_2018_CMake/src/setupNode.cpp
index 1705db2..0f01725 100755
--- a/Version_Max_07_05_2018_CMake/src/setupNode.cpp
+++ b/Version_Max_07_05_2018_CMake/src/setupNode.cpp
@@ -1,54 +1,54 @@
#include "setupNode.h"
#include "rlutil.h"
-#define PRINT
+//#define PRINT
using namespace rlutil;
void setWorkingCycleOfSensor(Sensor* sensor, unsigned int workingCycle) {
if (sensor->set_workingCycle(workingCycle)) {
#ifdef PRINT
printf(" > WorkingCycle of Sensor ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", sensor->get_id());
setColor(TXTCOLOR_LIGHTGREEN);
printf("set ");
setColor(TXTCOLOR_GREY);
printf("to %u\n", workingCycle);
#endif // PRINT
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Couldn't set WorkingCycle of Sensor %s (id: %03u)\n", sensor->get_name().c_str(), sensor->get_id());
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
}
void setWorkingCycleOfAgent(Agent* agent, unsigned int workingCycle) {
if (agent->set_workingCycle(workingCycle)) {
#ifdef PRINT
printf(" > WorkingCycle of Agent ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name().c_str());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", agent->get_id());
setColor(TXTCOLOR_LIGHTGREEN);
printf("set ");
setColor(TXTCOLOR_GREY);
printf("to %u\n", workingCycle);
#endif // PRINT
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Couldn't set WorkingCycle of Sensor %s (id: %03u)\n", agent->get_name().c_str(), agent->get_id());
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
}
\ No newline at end of file

File Metadata

Mime Type
text/x-diff
Expires
Sat, May 17, 7:27 AM (1 d, 6 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
141517
Default Alt Text
(171 KB)

Event Timeline