Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F1496865
SlaveAgentSlotOfAgent.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Size
7 KB
Referenced Files
None
Subscribers
None
SlaveAgentSlotOfAgent.cpp
View Options
#include
"SlaveAgentSlotOfAgent.h"
#include
"printError.h"
#include
"relationChecker.h"
SlaveAgentSlotOfAgent
::
SlaveAgentSlotOfAgent
()
{
flagSlaveAgentValueIsSet
=
false
;
/*
flagSlaveAgentValueHasChanged = false;
flagSlaveAgentValueChangeIsSet = false;
/*
activeState = NULL;
backupState = NULL;
*/
possibleScoreCount
=
0
;
timeSinceScoreChange
=
0
;
historySet
=
false
;
}
void
SlaveAgentSlotOfAgent
::
setSlaveAgentValue
(
float
slaveAgentValue
)
{
this
->
slaveAgentValue
=
slaveAgentValue
;
flagSlaveAgentValueIsSet
=
true
;
/*
if(flagSlaveAgentValueIsSet == false) {
this->slaveAgentValue = slaveAgentValue;
flagSlaveAgentValueIsSet = true;
flagSlaveAgentValueHasChanged = true;
}
else {
if(this->slaveAgentValue != slaveAgentValue) {
flagSlaveAgentValueHasChanged = true;
flagSlaveAgentValueChangeIsSet = true;
slaveAgentValueChange = slaveAgentValue - this->slaveAgentValue;
this->slaveAgentValue = slaveAgentValue;
}
else {
flagSlaveAgentValueHasChanged = false;
flagSlaveAgentValueChangeIsSet = true;
slaveAgentValueChange = 0;
}
}
*/
//printf("slaveAgentSlot updated with: %f\n", this->slaveAgentValue);
}
bool
SlaveAgentSlotOfAgent
::
get_slaveAgentValue
(
float
*
slaveAgentValue
)
{
if
(
flagSlaveAgentValueIsSet
==
true
)
{
*
slaveAgentValue
=
this
->
slaveAgentValue
;
return
true
;
}
return
false
;
}
bool
SlaveAgentSlotOfAgent
::
get_flagSlaveAgentValueIsSet
()
{
return
flagSlaveAgentValueIsSet
;
}
//TODO: move these functions into -> HistoryHandler
bool
SlaveAgentSlotOfAgent
::
saveValueInHistory
()
{
if
(
flagSlaveAgentValueIsSet
)
{
//NOTE: For the case of overstep the history boundaries, I make a while-loop instead of an if-statement "if(getHistoryLength() >= MAXHISTORYLENGTH)".
while
(
getHistoryLength
()
>=
MAXHISTORYLENGTH
)
{
if
(
!
deleteOldestHistoryEntry
())
return
false
;
}
try
{
//printf("history saving - value: %f\n", slaveAgentValue);
lSlaveAgentHistory
.
push_back
(
slaveAgentValue
);
return
true
;
}
catch
(
bad_alloc
&
error
)
{
printError
(
"bad_alloc caught: "
,
error
.
what
());
}
}
return
false
;
}
unsigned
int
SlaveAgentSlotOfAgent
::
getHistoryLength
()
{
return
lSlaveAgentHistory
.
size
();
}
bool
SlaveAgentSlotOfAgent
::
deleteOldestHistoryEntry
()
{
if
(
!
lSlaveAgentHistory
.
empty
())
{
lSlaveAgentHistory
.
pop_front
();
return
true
;
}
return
false
;
}
unsigned
int
SlaveAgentSlotOfAgent
::
getNumberOfRelativesToActualValue
(
float
threshold
)
{
unsigned
int
numberOfRelativesToActualValue
=
0
;
for
(
auto
&
entry
:
lSlaveAgentHistory
)
{
if
(
valueIsRelatedToReferenceValue
(
slaveAgentValue
,
entry
,
threshold
))
{
numberOfRelativesToActualValue
++
;
}
}
return
numberOfRelativesToActualValue
;
}
void
SlaveAgentSlotOfAgent
::
printHistory
()
{
printf
(
"History: "
);
for
(
auto
&
entry
:
lSlaveAgentHistory
)
{
printf
(
"%f, "
,
entry
);
}
printf
(
"
\n
"
);
}
bool
SlaveAgentSlotOfAgent
::
mountStabilityModule
(
StabilityModule
*
stabilityModule
)
{
if
(
this
->
stabilityModule
==
NULL
&&
stabilityModule
!=
NULL
)
{
this
->
stabilityModule
=
stabilityModule
;
return
true
;
}
return
false
;
}
StabilityModule
*
SlaveAgentSlotOfAgent
::
getStabilityModule
()
{
return
stabilityModule
;
}
float
*
SlaveAgentSlotOfAgent
::
getObservationPointer
()
{
printf
(
" - was sagt er hier? %p
\n
"
,
&
slaveAgentValue
);
getchar
();
return
&
slaveAgentValue
;
}
//SHORTCUT/WORKAUROUND -> TODO: make this better!
void
SlaveAgentSlotOfAgent
::
setScoreValue
(
int
scoreValue
)
{
this
->
scoreValue
=
scoreValue
;
}
int
SlaveAgentSlotOfAgent
::
getScoreValue
()
{
return
scoreValue
;
}
void
SlaveAgentSlotOfAgent
::
setReliabilityValue
(
float
reliabilityValue
)
{
this
->
reliabilityValue
=
reliabilityValue
;
}
float
SlaveAgentSlotOfAgent
::
getReliabilityValue
()
{
return
reliabilityValue
;
}
void
SlaveAgentSlotOfAgent
::
addPossibleScore
(
int
score
,
float
reliability
)
{
PossibleScore
*
possibleScore
=
new
PossibleScore
;
possibleScore
->
score
=
score
;
possibleScore
->
confOrRel
=
reliability
;
//=reliability!
//printf("bekommen: score = %i, reliability = %.2f\n", score, reliability);
possibleScores
.
push_back
(
possibleScore
);
flagSlaveAgentValueIsSet
=
true
;
}
bool
SlaveAgentSlotOfAgent
::
getPossibleScore
(
unsigned
int
rank
,
int
*
score
,
float
*
reliability
)
{
if
(
rank
<
possibleScores
.
size
())
{
*
score
=
possibleScores
.
at
(
rank
)
->
score
;
*
reliability
=
possibleScores
.
at
(
rank
)
->
confOrRel
;
return
true
;
}
return
false
;
}
unsigned
int
SlaveAgentSlotOfAgent
::
getNumOfPossibleScores
()
{
return
possibleScores
.
size
();
}
void
SlaveAgentSlotOfAgent
::
incPossibleScoreCount
()
{
if
(
possibleScoreCount
>=
possibleScores
.
size
()
-1
)
possibleScoreCount
=
0
;
else
possibleScoreCount
++
;
}
unsigned
int
SlaveAgentSlotOfAgent
::
getPossibleScoreCount
()
{
return
possibleScoreCount
;
}
void
SlaveAgentSlotOfAgent
::
resetPossibleScoreCount
()
{
possibleScoreCount
=
0
;
}
void
SlaveAgentSlotOfAgent
::
clearPossibleScores
()
{
possibleScores
.
clear
();
}
//NEW Journal
void
SlaveAgentSlotOfAgent
::
preSaveInScoreHistory
()
{
preLastScore
=
possibleScores
.
at
(
possibleScoreCount
)
->
score
;
preLastReliability
=
possibleScores
.
at
(
possibleScoreCount
)
->
confOrRel
;
}
void
SlaveAgentSlotOfAgent
::
saveInScoreHistory
()
{
lastScore
=
preLastScore
;
lastReliability
=
preLastReliability
;
timeSinceScoreChange
=
0
;
historySet
=
true
;
}
int
SlaveAgentSlotOfAgent
::
getScoreFromHistory
()
{
return
lastScore
;
}
float
SlaveAgentSlotOfAgent
::
getReliabilityFromHistory
()
{
return
lastReliability
;
}
void
SlaveAgentSlotOfAgent
::
increaseTimeSinceScoreChange
()
{
timeSinceScoreChange
++
;
}
unsigned
int
SlaveAgentSlotOfAgent
::
getTimeSinceScoreChange
()
{
return
timeSinceScoreChange
;
}
bool
SlaveAgentSlotOfAgent
::
isHistroySet
()
{
return
historySet
;
}
void
SlaveAgentSlotOfAgent
::
resetSlot
()
{
flagSlaveAgentValueIsSet
=
false
;
possibleScoreCount
=
0
;
timeSinceScoreChange
=
0
;
historySet
=
false
;
lSlaveAgentHistory
.
clear
();
scoreValue
=
0
;
reliabilityValue
=
0
;
possibleScores
.
clear
();
preLastScore
=
0
;
lastScore
=
0
;
preLastReliability
=
0
;
lastReliability
=
0
;
timeSinceScoreChange
=
0
;
historySet
=
false
;
}
bool
SlaveAgentSlotOfAgent
::
pass_msgToSendBuffer
(
float
msg
)
{
//TODO: make message handler and shift following lines to it!
//TODO: try/catch for pushback function!
Message
*
message
=
new
Message
(
msg
);
lSendBuffer
.
push_back
(
message
);
return
false
;
}
bool
SlaveAgentSlotOfAgent
::
pass_msgToSendBuffer
(
int
msg
)
{
//TODO: make message handler and shift following lines to it!
//TODO: try/catch for pushback function!
Message
*
message
=
new
Message
(
msg
);
lSendBuffer
.
push_back
(
message
);
return
false
;
}
unsigned
int
SlaveAgentSlotOfAgent
::
get_avlSendBuffer
()
{
return
maxBufferLength
-
get_occSendBuffer
();
}
unsigned
int
SlaveAgentSlotOfAgent
::
get_occSendBuffer
()
{
return
lSendBuffer
.
size
();
}
bool
SlaveAgentSlotOfAgent
::
send_msgs
()
{
Channel
*
comPort
=
get_comPort
();
if
(
comPort
!=
NULL
)
{
//TODO: also other sending mode... current MODE: only send it when all packets can be sended
if
(
get_occSendBuffer
()
<=
comPort
->
get_avlInputBufferUp
())
{
//for(unsigned int i=0; i<get_occSendBuffer(); i++)
while
(
get_occSendBuffer
()
>
0
)
{
//TODO: make message handler and shift following lines to it!
//TODO: try/catch for pushback function!
comPort
->
send_MsgDown
(
lSendBuffer
.
front
());
lSendBuffer
.
pop_front
();
}
}
}
return
false
;
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sun, Mar 1, 9:23 PM (10 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
287717
Default Alt Text
SlaveAgentSlotOfAgent.cpp (7 KB)
Attached To
Mode
R20 SoC_Rosa_repo
Attached
Detach File
Event Timeline
Log In to Comment