has health IF improvements
This commit is contained in:
parent
f5d793a1cf
commit
320a5ac355
@ -1,5 +1,5 @@
|
|||||||
#ifndef HASHEALTHIF_H_
|
#ifndef FSFW_HEALTH_HASHEALTHIF_H_
|
||||||
#define HASHEALTHIF_H_
|
#define FSFW_HEALTH_HASHEALTHIF_H_
|
||||||
|
|
||||||
#include "../events/Event.h"
|
#include "../events/Event.h"
|
||||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||||
@ -8,9 +8,13 @@
|
|||||||
class HasHealthIF {
|
class HasHealthIF {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef enum {
|
enum HealthState: uint8_t {
|
||||||
HEALTHY = 1, FAULTY = 0, EXTERNAL_CONTROL = 2, NEEDS_RECOVERY = 3, PERMANENT_FAULTY = 4
|
HEALTHY = 1,
|
||||||
} HealthState;
|
FAULTY = 0,
|
||||||
|
EXTERNAL_CONTROL = 2,
|
||||||
|
NEEDS_RECOVERY = 3,
|
||||||
|
PERMANENT_FAULTY = 4
|
||||||
|
};
|
||||||
|
|
||||||
static const uint8_t INTERFACE_ID = CLASS_ID::HAS_HEALTH_IF;
|
static const uint8_t INTERFACE_ID = CLASS_ID::HAS_HEALTH_IF;
|
||||||
static const ReturnValue_t OBJECT_NOT_HEALTHY = MAKE_RETURN_CODE(1);
|
static const ReturnValue_t OBJECT_NOT_HEALTHY = MAKE_RETURN_CODE(1);
|
||||||
@ -47,4 +51,4 @@ public:
|
|||||||
virtual HasHealthIF::HealthState getHealth() = 0;
|
virtual HasHealthIF::HealthState getHealth() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* HASHEALTHIF_H_ */
|
#endif /* FSFW_HEALTH_HASHEALTHIF_H_ */
|
||||||
|
@ -114,7 +114,8 @@ private:
|
|||||||
* @param health the health is passed as parameter so that the number of calls to the health table can be minimized
|
* @param health the health is passed as parameter so that the number of calls to the health table can be minimized
|
||||||
* @param oldHealth information of the previous health state.
|
* @param oldHealth information of the previous health state.
|
||||||
*/
|
*/
|
||||||
void informParent(HasHealthIF::HealthState health, HasHealthIF::HealthState oldHealth);
|
void informParent(HasHealthIF::HealthState health,
|
||||||
|
HasHealthIF::HealthState oldHealth);
|
||||||
|
|
||||||
void handleSetHealthCommand(CommandMessage *message);
|
void handleSetHealthCommand(CommandMessage *message);
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "../health/HealthMessage.h"
|
#include "HealthMessage.h"
|
||||||
|
|
||||||
void HealthMessage::setHealthMessage(CommandMessage* message, Command_t command,
|
void HealthMessage::setHealthMessage(CommandMessage* message, Command_t command,
|
||||||
HasHealthIF::HealthState health, HasHealthIF::HealthState oldHealth) {
|
HasHealthIF::HealthState health, HasHealthIF::HealthState oldHealth) {
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
#ifndef HEALTHMESSAGE_H_
|
#ifndef FSFW_HEALTH_HEALTHMESSAGE_H_
|
||||||
#define HEALTHMESSAGE_H_
|
#define FSFW_HEALTH_HEALTHMESSAGE_H_
|
||||||
|
|
||||||
#include "../health/HasHealthIF.h"
|
#include "HasHealthIF.h"
|
||||||
#include "../ipc/CommandMessage.h"
|
#include "../ipc/CommandMessage.h"
|
||||||
|
|
||||||
class HealthMessage {
|
class HealthMessage {
|
||||||
public:
|
public:
|
||||||
static const uint8_t MESSAGE_ID = messagetypes::HEALTH_COMMAND;
|
static const uint8_t MESSAGE_ID = messagetypes::HEALTH_COMMAND;
|
||||||
static const Command_t HEALTH_SET = MAKE_COMMAND_ID(1);//REPLY_COMMAND_OK/REPLY_REJECTED
|
// REPLY_COMMAND_OK/REPLY_REJECTED
|
||||||
static const Command_t HEALTH_ANNOUNCE = MAKE_COMMAND_ID(3); //NO REPLY!
|
static const Command_t HEALTH_SET = MAKE_COMMAND_ID(1);
|
||||||
|
// NO REPLY!
|
||||||
|
static const Command_t HEALTH_ANNOUNCE = MAKE_COMMAND_ID(3);
|
||||||
static const Command_t HEALTH_INFO = MAKE_COMMAND_ID(5);
|
static const Command_t HEALTH_INFO = MAKE_COMMAND_ID(5);
|
||||||
static const Command_t REPLY_HEALTH_SET = MAKE_COMMAND_ID(6);
|
static const Command_t REPLY_HEALTH_SET = MAKE_COMMAND_ID(6);
|
||||||
|
|
||||||
static void setHealthMessage(CommandMessage *message, Command_t command,
|
static void setHealthMessage(CommandMessage *message, Command_t command,
|
||||||
HasHealthIF::HealthState health, HasHealthIF::HealthState oldHealth = HasHealthIF::FAULTY);
|
HasHealthIF::HealthState health,
|
||||||
|
HasHealthIF::HealthState oldHealth = HasHealthIF::FAULTY);
|
||||||
|
|
||||||
static void setHealthMessage(CommandMessage *message, Command_t command);
|
static void setHealthMessage(CommandMessage *message, Command_t command);
|
||||||
|
|
||||||
@ -27,4 +30,4 @@ private:
|
|||||||
HealthMessage();
|
HealthMessage();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* HEALTHMESSAGE_H_ */
|
#endif /* FSFW_HEALTH_HEALTHMESSAGE_H_ */
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "../health/HealthTable.h"
|
#include "HealthTable.h"
|
||||||
#include "../serialize/SerializeAdapter.h"
|
#include "../ipc/MutexHelper.h"
|
||||||
#include "../ipc/MutexFactory.h"
|
#include "../ipc/MutexFactory.h"
|
||||||
|
#include "../serialize/SerializeAdapter.h"
|
||||||
|
|
||||||
HealthTable::HealthTable(object_id_t objectid) :
|
HealthTable::HealthTable(object_id_t objectid) :
|
||||||
SystemObject(objectid) {
|
SystemObject(objectid) {
|
||||||
@ -18,74 +19,64 @@ ReturnValue_t HealthTable::registerObject(object_id_t object,
|
|||||||
if (healthMap.count(object) != 0) {
|
if (healthMap.count(object) != 0) {
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
healthMap.insert(
|
healthMap.emplace(object, initilialState);
|
||||||
std::pair<object_id_t, HasHealthIF::HealthState>(object,
|
|
||||||
initilialState));
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HealthTable::setHealth(object_id_t object,
|
void HealthTable::setHealth(object_id_t object,
|
||||||
HasHealthIF::HealthState newState) {
|
HasHealthIF::HealthState newState) {
|
||||||
mutex->lockMutex(MutexIF::BLOCKING);
|
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, 20);
|
||||||
HealthMap::iterator iter = healthMap.find(object);
|
HealthMap::iterator iter = healthMap.find(object);
|
||||||
if (iter != healthMap.end()) {
|
if (iter != healthMap.end()) {
|
||||||
iter->second = newState;
|
iter->second = newState;
|
||||||
}
|
}
|
||||||
mutex->unlockMutex();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HasHealthIF::HealthState HealthTable::getHealth(object_id_t object) {
|
HasHealthIF::HealthState HealthTable::getHealth(object_id_t object) {
|
||||||
HasHealthIF::HealthState state = HasHealthIF::HEALTHY;
|
HasHealthIF::HealthState state = HasHealthIF::HEALTHY;
|
||||||
mutex->lockMutex(MutexIF::BLOCKING);
|
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, 20);
|
||||||
HealthMap::iterator iter = healthMap.find(object);
|
HealthMap::iterator iter = healthMap.find(object);
|
||||||
if (iter != healthMap.end()) {
|
if (iter != healthMap.end()) {
|
||||||
state = iter->second;
|
state = iter->second;
|
||||||
}
|
}
|
||||||
mutex->unlockMutex();
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t HealthTable::getPrintSize() {
|
|
||||||
mutex->lockMutex(MutexIF::BLOCKING);
|
bool HealthTable::hasHealth(object_id_t object) {
|
||||||
uint32_t size = healthMap.size() * 5 + 2;
|
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, 20);
|
||||||
mutex->unlockMutex();
|
HealthMap::iterator iter = healthMap.find(object);
|
||||||
|
if (iter != healthMap.end()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t HealthTable::getPrintSize() {
|
||||||
|
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, 20);
|
||||||
|
uint32_t size = healthMap.size() * sizeof(object_id_t) +
|
||||||
|
sizeof(HasHealthIF::HealthState) + sizeof(uint16_t);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HealthTable::hasHealth(object_id_t object) {
|
|
||||||
bool exits = false;
|
|
||||||
mutex->lockMutex(MutexIF::BLOCKING);
|
|
||||||
HealthMap::iterator iter = healthMap.find(object);
|
|
||||||
if (iter != healthMap.end()) {
|
|
||||||
exits = true;
|
|
||||||
}
|
|
||||||
mutex->unlockMutex();
|
|
||||||
return exits;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HealthTable::printAll(uint8_t* pointer, size_t maxSize) {
|
void HealthTable::printAll(uint8_t* pointer, size_t maxSize) {
|
||||||
mutex->lockMutex(MutexIF::BLOCKING);
|
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, 20);
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
uint16_t count = healthMap.size();
|
uint16_t count = healthMap.size();
|
||||||
ReturnValue_t result = SerializeAdapter::serialize(&count,
|
SerializeAdapter::serialize(&count,
|
||||||
&pointer, &size, maxSize, SerializeIF::Endianness::BIG);
|
&pointer, &size, maxSize, SerializeIF::Endianness::BIG);
|
||||||
HealthMap::iterator iter;
|
for (const auto& health: healthMap) {
|
||||||
for (iter = healthMap.begin();
|
SerializeAdapter::serialize(&health.first,
|
||||||
iter != healthMap.end() && result == HasReturnvaluesIF::RETURN_OK;
|
|
||||||
++iter) {
|
|
||||||
result = SerializeAdapter::serialize(&iter->first,
|
|
||||||
&pointer, &size, maxSize, SerializeIF::Endianness::BIG);
|
&pointer, &size, maxSize, SerializeIF::Endianness::BIG);
|
||||||
uint8_t health = iter->second;
|
uint8_t healthValue = health.second;
|
||||||
result = SerializeAdapter::serialize(&health, &pointer, &size,
|
SerializeAdapter::serialize(&healthValue, &pointer, &size,
|
||||||
maxSize, SerializeIF::Endianness::BIG);
|
maxSize, SerializeIF::Endianness::BIG);
|
||||||
}
|
}
|
||||||
mutex->unlockMutex();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t HealthTable::iterate(
|
ReturnValue_t HealthTable::iterate(HealthEntry *value, bool reset) {
|
||||||
std::pair<object_id_t, HasHealthIF::HealthState> *value, bool reset) {
|
|
||||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
mutex->lockMutex(MutexIF::BLOCKING);
|
MutexHelper(mutex, MutexIF::TimeoutType::WAITING, 20);
|
||||||
if (reset) {
|
if (reset) {
|
||||||
mapIterator = healthMap.begin();
|
mapIterator = healthMap.begin();
|
||||||
}
|
}
|
||||||
@ -94,7 +85,5 @@ ReturnValue_t HealthTable::iterate(
|
|||||||
}
|
}
|
||||||
*value = *mapIterator;
|
*value = *mapIterator;
|
||||||
mapIterator++;
|
mapIterator++;
|
||||||
mutex->unlockMutex();
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,31 @@
|
|||||||
#ifndef FRAMEWORK_HEALTH_HEALTHTABLE_H_
|
#ifndef FSFW_HEALTH_HEALTHTABLE_H_
|
||||||
#define FRAMEWORK_HEALTH_HEALTHTABLE_H_
|
#define FSFW_HEALTH_HEALTHTABLE_H_
|
||||||
|
|
||||||
#include "../health/HealthTableIF.h"
|
#include "HealthTableIF.h"
|
||||||
#include "../objectmanager/SystemObject.h"
|
#include "../objectmanager/SystemObject.h"
|
||||||
#include "../ipc/MutexIF.h"
|
#include "../ipc/MutexIF.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
typedef std::map<object_id_t, HasHealthIF::HealthState> HealthMap;
|
typedef std::map<object_id_t, HasHealthIF::HealthState> HealthMap;
|
||||||
|
using HealthEntry = std::pair<object_id_t, HasHealthIF::HealthState>;
|
||||||
|
|
||||||
class HealthTable: public HealthTableIF, public SystemObject {
|
class HealthTable: public HealthTableIF, public SystemObject {
|
||||||
public:
|
public:
|
||||||
HealthTable(object_id_t objectid);
|
HealthTable(object_id_t objectid);
|
||||||
virtual ~HealthTable();
|
virtual ~HealthTable();
|
||||||
|
|
||||||
|
/** HealthTableIF overrides */
|
||||||
virtual ReturnValue_t registerObject(object_id_t object,
|
virtual ReturnValue_t registerObject(object_id_t object,
|
||||||
HasHealthIF::HealthState initilialState = HasHealthIF::HEALTHY);
|
HasHealthIF::HealthState initilialState =
|
||||||
|
HasHealthIF::HEALTHY) override;
|
||||||
|
virtual size_t getPrintSize() override;
|
||||||
|
virtual void printAll(uint8_t *pointer, size_t maxSize) override;
|
||||||
|
|
||||||
virtual bool hasHealth(object_id_t object);
|
/** ManagesHealthIF overrides */
|
||||||
virtual void setHealth(object_id_t object, HasHealthIF::HealthState newState);
|
virtual bool hasHealth(object_id_t object) override;
|
||||||
virtual HasHealthIF::HealthState getHealth(object_id_t);
|
virtual void setHealth(object_id_t object,
|
||||||
|
HasHealthIF::HealthState newState) override;
|
||||||
virtual uint32_t getPrintSize();
|
virtual HasHealthIF::HealthState getHealth(object_id_t) override;
|
||||||
virtual void printAll(uint8_t *pointer, size_t maxSize);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MutexIF* mutex;
|
MutexIF* mutex;
|
||||||
@ -29,7 +33,9 @@ protected:
|
|||||||
|
|
||||||
HealthMap::iterator mapIterator;
|
HealthMap::iterator mapIterator;
|
||||||
|
|
||||||
virtual ReturnValue_t iterate(std::pair<object_id_t,HasHealthIF::HealthState> *value, bool reset = false);
|
virtual ReturnValue_t iterate(
|
||||||
|
HealthEntry* value,
|
||||||
|
bool reset = false) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* HEALTHTABLE_H_ */
|
#endif /* FSFW_HEALTH_HEALTHTABLE_H_ */
|
||||||
|
@ -1,28 +1,24 @@
|
|||||||
#ifndef FRAMEWORK_HEALTH_HEALTHTABLEIF_H_
|
#ifndef FSFW_HEALTH_HEALTHTABLEIF_H_
|
||||||
#define FRAMEWORK_HEALTH_HEALTHTABLEIF_H_
|
#define FSFW_HEALTH_HEALTHTABLEIF_H_
|
||||||
|
|
||||||
#include "../health/ManagesHealthIF.h"
|
#include "ManagesHealthIF.h"
|
||||||
#include "../objectmanager/ObjectManagerIF.h"
|
#include "../objectmanager/ObjectManagerIF.h"
|
||||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||||
#include <map>
|
|
||||||
|
|
||||||
|
|
||||||
class HealthTableIF: public ManagesHealthIF {
|
class HealthTableIF: public ManagesHealthIF {
|
||||||
// TODO: This is in the mission folder and not in the framework folder.
|
|
||||||
// delete it?
|
|
||||||
friend class HealthCommandingService;
|
|
||||||
public:
|
public:
|
||||||
virtual ~HealthTableIF() {
|
virtual ~HealthTableIF() {}
|
||||||
}
|
|
||||||
|
|
||||||
virtual ReturnValue_t registerObject(object_id_t object,
|
virtual ReturnValue_t registerObject(object_id_t object,
|
||||||
HasHealthIF::HealthState initilialState = HasHealthIF::HEALTHY) = 0;
|
HasHealthIF::HealthState initilialState = HasHealthIF::HEALTHY) = 0;
|
||||||
|
|
||||||
virtual uint32_t getPrintSize() = 0;
|
virtual size_t getPrintSize() = 0;
|
||||||
virtual void printAll(uint8_t *pointer, size_t maxSize) = 0;
|
virtual void printAll(uint8_t *pointer, size_t maxSize) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ReturnValue_t iterate(std::pair<object_id_t,HasHealthIF::HealthState> *value, bool reset = false) = 0;
|
virtual ReturnValue_t iterate(
|
||||||
|
std::pair<object_id_t,HasHealthIF::HealthState> *value,
|
||||||
|
bool reset = false) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FRAMEWORK_HEALTH_HEALTHTABLEIF_H_ */
|
#endif /* FRAMEWORK_HEALTH_HEALTHTABLEIF_H_ */
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#ifndef FRAMEWORK_HEALTH_MANAGESHEALTHIF_H_
|
#ifndef FSFW_HEALTH_MANAGESHEALTHIF_H_
|
||||||
#define FRAMEWORK_HEALTH_MANAGESHEALTHIF_H_
|
#define FSFW_HEALTH_MANAGESHEALTHIF_H_
|
||||||
|
|
||||||
#include "../health/HasHealthIF.h"
|
#include "HasHealthIF.h"
|
||||||
#include "../objectmanager/ObjectManagerIF.h"
|
#include "../objectmanager/ObjectManagerIF.h"
|
||||||
|
|
||||||
class ManagesHealthIF {
|
class ManagesHealthIF {
|
||||||
public:
|
public:
|
||||||
virtual ~ManagesHealthIF() {
|
virtual ~ManagesHealthIF() {
|
||||||
@ -49,4 +50,4 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FRAMEWORK_HEALTH_MANAGESHEALTHIF_H_ */
|
#endif /* FSFW_HEALTH_MANAGESHEALTHIF_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user