updating code from Flying Laptop
This is the framework of Flying Laptop OBSW version A.13.0.
This commit is contained in:
@ -1,13 +1,3 @@
|
||||
/*
|
||||
* Event.cpp
|
||||
*
|
||||
* Created on: 25.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <framework/events/Event.h>
|
||||
namespace EVENT {
|
||||
EventId_t getEventId(Event event) {
|
||||
|
@ -1,14 +1,9 @@
|
||||
/*
|
||||
* Event.h
|
||||
*
|
||||
* Created on: 18.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef EVENTOBJECT_EVENT_H_
|
||||
#define EVENTOBJECT_EVENT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <framework/events/fwSubsystemIdRanges.h>
|
||||
//could be move to more suitable location
|
||||
#include <config/tmtc/subsystemIdRanges.h>
|
||||
|
||||
typedef uint16_t EventId_t;
|
||||
|
@ -1,40 +1,43 @@
|
||||
#include <config/objects/translateObjects.h>
|
||||
#include <config/events/translateEvents.h>
|
||||
|
||||
#include <framework/events/EventManager.h>
|
||||
#include <framework/events/EventMessage.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <framework/ipc/QueueFactory.h>
|
||||
#include <framework/ipc/MutexFactory.h>
|
||||
|
||||
|
||||
const uint16_t EventManager::POOL_SIZES[N_POOLS] = {
|
||||
sizeof(EventMatchTree::Node), sizeof(EventIdRangeMatcher),
|
||||
sizeof(ReporterRangeMatcher) };
|
||||
//TODO: Rather arbitrary. Adjust!
|
||||
//If one checks registerListener calls, there are around 40 (to max 50) objects registering for certain events.
|
||||
//Each listener requires 1 or 2 EventIdMatcher and 1 or 2 ReportRangeMatcher. So a good guess is 75 to a max of 100 pools required for each, which fits well.
|
||||
const uint16_t EventManager::N_ELEMENTS[N_POOLS] = { 240, 120, 120 };
|
||||
|
||||
EventManager::EventManager(object_id_t setObjectId) :
|
||||
SystemObject(setObjectId), eventReportQueue(MAX_EVENTS_PER_CYCLE,
|
||||
EventMessage::EVENT_MESSAGE_SIZE), mutex(NULL), factoryBackend(
|
||||
SystemObject(setObjectId), eventReportQueue(NULL), mutex(NULL), factoryBackend(
|
||||
0, POOL_SIZES, N_ELEMENTS, false, true) {
|
||||
mutex = new MutexId_t;
|
||||
OSAL::createMutex(setObjectId + 1, (mutex));
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
eventReportQueue = QueueFactory::instance()->createMessageQueue(
|
||||
MAX_EVENTS_PER_CYCLE, EventMessage::EVENT_MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
EventManager::~EventManager() {
|
||||
OSAL::deleteMutex(mutex);
|
||||
delete mutex;
|
||||
QueueFactory::instance()->deleteMessageQueue(eventReportQueue);
|
||||
MutexFactory::instance()->deleteMutex(mutex);
|
||||
}
|
||||
|
||||
MessageQueueId_t EventManager::getEventReportQueue() {
|
||||
return eventReportQueue.getId();
|
||||
return eventReportQueue->getId();
|
||||
}
|
||||
|
||||
ReturnValue_t EventManager::performOperation() {
|
||||
ReturnValue_t EventManager::performOperation(uint8_t opCode) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
while (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
EventMessage message;
|
||||
result = eventReportQueue.receiveMessage(&message);
|
||||
result = eventReportQueue->receiveMessage(&message);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
#ifdef DEBUG
|
||||
printEvent(&message);
|
||||
#endif
|
||||
notifyListeners(&message);
|
||||
}
|
||||
}
|
||||
@ -45,7 +48,7 @@ void EventManager::notifyListeners(EventMessage* message) {
|
||||
lockMutex();
|
||||
for (auto iter = listenerList.begin(); iter != listenerList.end(); ++iter) {
|
||||
if (iter->second.match(message)) {
|
||||
eventForwardingSender.sendMessage(iter->first, message,
|
||||
MessageQueueSenderIF::sendMessage(iter->first, message,
|
||||
message->getSender());
|
||||
}
|
||||
}
|
||||
@ -103,21 +106,27 @@ ReturnValue_t EventManager::unsubscribeFromEventRange(MessageQueueId_t listener,
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
//forward declaration, should be implemented by mission
|
||||
const char* translateObject(object_id_t object);
|
||||
const char * translateEvents(Event event);
|
||||
|
||||
void EventManager::printEvent(EventMessage* message) {
|
||||
const char *string = 0;
|
||||
switch (message->getSeverity()) {
|
||||
case SEVERITY::INFO:
|
||||
string = translateObject(message->getReporter());
|
||||
info << "EVENT: ";
|
||||
if (string != 0) {
|
||||
info << string;
|
||||
} else {
|
||||
info << "0x" << std::hex << message->getReporter() << std::dec;
|
||||
}
|
||||
info << " reported " << translateEvents(message->getEvent()) << " ("
|
||||
<< std::dec << message->getEventId() << std::hex << ") P1: 0x"
|
||||
<< message->getParameter1() << " P2: 0x"
|
||||
<< message->getParameter2() << std::dec << std::endl;
|
||||
// string = translateObject(message->getReporter());
|
||||
// info << "EVENT: ";
|
||||
// if (string != 0) {
|
||||
// info << string;
|
||||
// } else {
|
||||
// info << "0x" << std::hex << message->getReporter() << std::dec;
|
||||
// }
|
||||
// info << " reported " << translateEvents(message->getEvent()) << " ("
|
||||
// << std::dec << message->getEventId() << std::hex << ") P1: 0x"
|
||||
// << message->getParameter1() << " P2: 0x"
|
||||
// << message->getParameter2() << std::dec << std::endl;
|
||||
break;
|
||||
default:
|
||||
string = translateObject(message->getReporter());
|
||||
@ -135,11 +144,12 @@ void EventManager::printEvent(EventMessage* message) {
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
void EventManager::lockMutex() {
|
||||
OSAL::lockMutex(this->mutex, OSAL::NO_TIMEOUT);
|
||||
mutex->lockMutex(MutexIF::NO_TIMEOUT);
|
||||
}
|
||||
|
||||
void EventManager::unlockMutex() {
|
||||
OSAL::unlockMutex(this->mutex);
|
||||
mutex->unlockMutex();
|
||||
}
|
||||
|
@ -4,16 +4,17 @@
|
||||
#include <framework/events/eventmatching/EventMatchTree.h>
|
||||
#include <framework/events/EventManagerIF.h>
|
||||
#include <framework/objectmanager/SystemObject.h>
|
||||
#include <framework/osal/OSAL.h>
|
||||
#include <framework/storagemanager/LocalPool.h>
|
||||
#include <framework/tasks/ExecutableObjectIF.h>
|
||||
#include <framework/ipc/MessageQueueIF.h>
|
||||
#include <framework/ipc/MutexIF.h>
|
||||
#include <map>
|
||||
|
||||
class EventManager: public EventManagerIF,
|
||||
public ExecutableObjectIF,
|
||||
public SystemObject {
|
||||
public:
|
||||
static const uint16_t MAX_EVENTS_PER_CYCLE = 150;
|
||||
static const uint16_t MAX_EVENTS_PER_CYCLE = 80;
|
||||
|
||||
EventManager(object_id_t setObjectId);
|
||||
virtual ~EventManager();
|
||||
@ -32,17 +33,15 @@ public:
|
||||
EventId_t idFrom = 0, EventId_t idTo = 0, bool idInverted = false,
|
||||
object_id_t reporterFrom = 0, object_id_t reporterTo = 0,
|
||||
bool reporterInverted = false);
|
||||
ReturnValue_t performOperation();
|
||||
ReturnValue_t performOperation(uint8_t opCode);
|
||||
|
||||
protected:
|
||||
|
||||
MessageQueue eventReportQueue;
|
||||
|
||||
MessageQueueSender eventForwardingSender;
|
||||
MessageQueueIF* eventReportQueue;
|
||||
|
||||
std::map<MessageQueueId_t, EventMatchTree> listenerList;
|
||||
|
||||
MutexId_t* mutex;
|
||||
MutexIF* mutex;
|
||||
|
||||
static const uint8_t N_POOLS = 3;
|
||||
LocalPool<N_POOLS> factoryBackend;
|
||||
@ -51,7 +50,9 @@ protected:
|
||||
|
||||
void notifyListeners(EventMessage *message);
|
||||
|
||||
#ifdef DEBUG
|
||||
void printEvent(EventMessage *message);
|
||||
#endif
|
||||
|
||||
void lockMutex();
|
||||
|
||||
|
@ -3,13 +3,13 @@
|
||||
|
||||
#include <framework/events/eventmatching/eventmatching.h>
|
||||
#include <framework/events/EventMessage.h>
|
||||
#include <framework/ipc/MessageQueue.h>
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
#include <framework/ipc/MessageQueueSenderIF.h>
|
||||
|
||||
class EventManagerIF {
|
||||
public:
|
||||
|
||||
static const uint8_t INTERFACE_ID = EVENT_MANAGER_IF;
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::EVENT_MANAGER_IF;
|
||||
static const ReturnValue_t LISTENER_NOT_FOUND = MAKE_RETURN_CODE(1);
|
||||
virtual ~EventManagerIF() {
|
||||
}
|
||||
@ -44,8 +44,7 @@ public:
|
||||
eventmanagerQueue = eventmanager->getEventReportQueue();
|
||||
}
|
||||
}
|
||||
MessageQueueSender sender(eventmanagerQueue);
|
||||
sender.sendToDefault(message, sentFrom);
|
||||
MessageQueueSenderIF::sendMessage(eventmanagerQueue, message, sentFrom);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -15,7 +15,7 @@ public:
|
||||
static const uint8_t CONFIRMATION_REQUEST = 1; //!< Request to parent if event is caused by child or not.
|
||||
static const uint8_t YOUR_FAULT = 2; //!< The fault was caused by child, parent believes it's ok.
|
||||
static const uint8_t MY_FAULT = 3; //!< The fault was caused by the parent, child is ok.
|
||||
//TODO: Add other messageIDs here if necessary.
|
||||
//Add other messageIDs here if necessary.
|
||||
static const uint8_t EVENT_MESSAGE_SIZE = HEADER_SIZE + sizeof(Event)
|
||||
+ 3 * sizeof(uint32_t);
|
||||
|
||||
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* EventReportingProxyIF.h
|
||||
*
|
||||
* Created on: 19.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_EVENTS_EVENTREPORTINGPROXYIF_H_
|
||||
#define FRAMEWORK_EVENTS_EVENTREPORTINGPROXYIF_H_
|
||||
|
||||
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* EventIdRangeMatcher.cpp
|
||||
*
|
||||
* Created on: 27.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#include <framework/events/eventmatching/EventIdRangeMatcher.h>
|
||||
|
||||
EventIdRangeMatcher::EventIdRangeMatcher(EventId_t lower, EventId_t upper,
|
||||
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* EventIdRangeMatcher.h
|
||||
*
|
||||
* Created on: 27.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_EVENTIDRANGEMATCHER_H_
|
||||
#define FRAMEWORK_EVENTS_EVENTMATCHING_EVENTIDRANGEMATCHER_H_
|
||||
|
||||
|
@ -1,17 +1,12 @@
|
||||
/*
|
||||
* EventMatchTree.cpp
|
||||
*
|
||||
* Created on: 27.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#include <framework/events/eventmatching/EventIdRangeMatcher.h>
|
||||
#include <framework/events/eventmatching/EventMatchTree.h>
|
||||
#include <framework/events/eventmatching/ReporterRangeMatcher.h>
|
||||
#include <framework/events/eventmatching/SeverityRangeMatcher.h>
|
||||
|
||||
EventMatchTree::EventMatchTree(StorageManagerIF* storageBackend, bool invertedMatch) :
|
||||
MatchTree<EventMessage*>(end(), 1), factory(storageBackend), invertedMatch(invertedMatch) {
|
||||
EventMatchTree::EventMatchTree(StorageManagerIF* storageBackend,
|
||||
bool invertedMatch) :
|
||||
MatchTree<EventMessage*>(end(), 1), factory(storageBackend), invertedMatch(
|
||||
invertedMatch) {
|
||||
}
|
||||
|
||||
EventMatchTree::~EventMatchTree() {
|
||||
@ -25,9 +20,9 @@ bool EventMatchTree::match(EventMessage* number) {
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t EventMatchTree::addMatch(EventId_t idFrom,
|
||||
EventId_t idTo, bool idInverted, object_id_t reporterFrom,
|
||||
object_id_t reporterTo, bool reporterInverted) {
|
||||
ReturnValue_t EventMatchTree::addMatch(EventId_t idFrom, EventId_t idTo,
|
||||
bool idInverted, object_id_t reporterFrom, object_id_t reporterTo,
|
||||
bool reporterInverted) {
|
||||
if (idFrom == 0) {
|
||||
//Assuming all events shall be forwarded.
|
||||
idTo = 0;
|
||||
@ -37,8 +32,8 @@ ReturnValue_t EventMatchTree::addMatch(EventId_t idFrom,
|
||||
idTo = idFrom;
|
||||
}
|
||||
iterator lastTest;
|
||||
ReturnValue_t result = findOrInsertRangeMatcher<EventId_t, EventIdRangeMatcher>(
|
||||
begin(), idFrom, idTo, idInverted, &lastTest);
|
||||
ReturnValue_t result = findOrInsertRangeMatcher<EventId_t,
|
||||
EventIdRangeMatcher>(begin(), idFrom, idTo, idInverted, &lastTest);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
@ -54,9 +49,9 @@ ReturnValue_t EventMatchTree::addMatch(EventId_t idFrom,
|
||||
&lastTest);
|
||||
}
|
||||
|
||||
ReturnValue_t EventMatchTree::removeMatch(EventId_t idFrom,
|
||||
EventId_t idTo, bool idInverted, object_id_t reporterFrom,
|
||||
object_id_t reporterTo, bool reporterInverted) {
|
||||
ReturnValue_t EventMatchTree::removeMatch(EventId_t idFrom, EventId_t idTo,
|
||||
bool idInverted, object_id_t reporterFrom, object_id_t reporterTo,
|
||||
bool reporterInverted) {
|
||||
|
||||
iterator foundElement;
|
||||
|
||||
@ -68,8 +63,8 @@ ReturnValue_t EventMatchTree::removeMatch(EventId_t idFrom,
|
||||
if (idTo == 0) {
|
||||
idTo = idFrom;
|
||||
}
|
||||
foundElement = findRangeMatcher<EventId_t, EventIdRangeMatcher>(
|
||||
begin(), idFrom, idTo, idInverted);
|
||||
foundElement = findRangeMatcher<EventId_t, EventIdRangeMatcher>(begin(),
|
||||
idFrom, idTo, idInverted);
|
||||
if (foundElement == end()) {
|
||||
return NO_MATCH; //Can't tell if too detailed or just not found.
|
||||
}
|
||||
@ -117,6 +112,8 @@ inline ReturnValue_t EventMatchTree::findOrInsertRangeMatcher(iterator start,
|
||||
}
|
||||
Node* newNode = factory.generate<Node>(newContent);
|
||||
if (newNode == NULL) {
|
||||
//Need to make sure partially generated content is deleted, otherwise, that's a leak.
|
||||
factory.destroy<INSERTION_T>(static_cast<INSERTION_T*>(newContent));
|
||||
return FULL;
|
||||
}
|
||||
*lastTest = insert(attachToBranch, *lastTest, newNode);
|
||||
@ -145,7 +142,8 @@ EventMatchTree::iterator EventMatchTree::findRangeMatcher(iterator start,
|
||||
}
|
||||
|
||||
ReturnValue_t EventMatchTree::cleanUpElement(iterator position) {
|
||||
//TODO: What if first deletion fails?
|
||||
factory.destroy(position.element->value);
|
||||
//If deletion fails, delete element anyway, nothing we can do.
|
||||
//SHOULDO: Throw event, or write debug output.
|
||||
return factory.destroy(position.element);
|
||||
}
|
||||
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* EventMatchTree.h
|
||||
*
|
||||
* Created on: 27.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_EVENTMATCHTREE_H_
|
||||
#define FRAMEWORK_EVENTS_EVENTMATCHING_EVENTMATCHTREE_H_
|
||||
|
||||
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* EventRangeMatcherBase.h
|
||||
*
|
||||
* Created on: 27.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_EVENTRANGEMATCHERBASE_H_
|
||||
#define FRAMEWORK_EVENTS_EVENTMATCHING_EVENTRANGEMATCHERBASE_H_
|
||||
|
||||
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* ReporterRangeMatcher.cpp
|
||||
*
|
||||
* Created on: 27.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#include <framework/events/eventmatching/ReporterRangeMatcher.h>
|
||||
|
||||
ReporterRangeMatcher::ReporterRangeMatcher(object_id_t lower, object_id_t upper,
|
||||
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* ReporterRangeMatcher.h
|
||||
*
|
||||
* Created on: 27.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_REPORTERRANGEMATCHER_H_
|
||||
#define FRAMEWORK_EVENTS_EVENTMATCHING_REPORTERRANGEMATCHER_H_
|
||||
|
||||
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* SeverityRangeMatcher.cpp
|
||||
*
|
||||
* Created on: 27.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#include <framework/events/eventmatching/SeverityRangeMatcher.h>
|
||||
#include <framework/events/EventMessage.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* SeverityRangeMatcher.h
|
||||
*
|
||||
* Created on: 27.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_SEVERITYRANGEMATCHER_H_
|
||||
#define FRAMEWORK_EVENTS_EVENTMATCHING_SEVERITYRANGEMATCHER_H_
|
||||
|
||||
|
25
events/fwSubsystemIdRanges.h
Normal file
25
events/fwSubsystemIdRanges.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef FRAMEWORK_EVENTS_FWSUBSYSTEMIDRANGES_H_
|
||||
#define FRAMEWORK_EVENTS_FWSUBSYSTEMIDRANGES_H_
|
||||
|
||||
namespace SUBSYSTEM_ID {
|
||||
enum {
|
||||
OBSW = 26,
|
||||
CDH = 28,
|
||||
TCS_1 = 59,
|
||||
PCDU_1 = 42,
|
||||
PCDU_2 = 43,
|
||||
HEATER = 50,
|
||||
T_SENSORS = 52,
|
||||
FDIR = 70,
|
||||
FDIR_1 = 71,
|
||||
FDIR_2 = 72,
|
||||
HK = 73,
|
||||
SYSTEM_MANAGER = 74,
|
||||
SYSTEM_MANAGER_1 = 75,
|
||||
SYSTEM_1 = 79,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_EVENTS_FWSUBSYSTEMIDRANGES_H_ */
|
Reference in New Issue
Block a user