updating code from Flying Laptop
This is the framework of Flying Laptop OBSW version A.13.0.
This commit is contained in:
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* Subsystem.cpp
|
||||
*
|
||||
* Created on: 12.07.2013
|
||||
* Author: tod
|
||||
*/
|
||||
|
||||
#include <framework/health/HealthMessage.h>
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
#include <framework/serialize/SerialArrayListAdapter.h>
|
||||
@ -20,7 +13,11 @@ Subsystem::Subsystem(object_id_t setObjectId, object_id_t parent,
|
||||
false), uptimeStartTable(0), currentTargetTable(), targetMode(
|
||||
0), targetSubmode(SUBMODE_NONE), initialMode(0), currentSequenceIterator(), modeTables(
|
||||
maxNumberOfTables), modeSequences(maxNumberOfSequences), IPCStore(
|
||||
NULL), modeStore(NULL) {
|
||||
NULL)
|
||||
#ifdef USE_MODESTORE
|
||||
,modeStore(NULL)
|
||||
#endif
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@ -78,7 +75,7 @@ void Subsystem::performChildOperation() {
|
||||
if (isInTransition) {
|
||||
if (commandsOutstanding <= 0) { //all children of the current table were commanded and replied
|
||||
if (currentSequenceIterator.value == NULL) { //we're through with this sequence
|
||||
if (checkStateAgainstTable(currentTargetTable) == RETURN_OK) {
|
||||
if (checkStateAgainstTable(currentTargetTable, targetSubmode) == RETURN_OK) {
|
||||
setMode(targetMode, targetSubmode);
|
||||
isInTransition = false;
|
||||
return;
|
||||
@ -89,19 +86,19 @@ void Subsystem::performChildOperation() {
|
||||
}
|
||||
}
|
||||
if (currentSequenceIterator->checkSuccess()) {
|
||||
if (checkStateAgainstTable(getCurrentTable()) != RETURN_OK) {
|
||||
if (checkStateAgainstTable(getCurrentTable(), targetSubmode) != RETURN_OK) {
|
||||
transitionFailed(TABLE_CHECK_FAILED,
|
||||
currentSequenceIterator->getTableId());
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (currentSequenceIterator->getWaitSeconds() != 0) {
|
||||
if (uptimeStartTable != 0) {
|
||||
OSAL::getUptime(&uptimeStartTable);
|
||||
if (uptimeStartTable == 0) {
|
||||
Clock::getUptime(&uptimeStartTable);
|
||||
return;
|
||||
} else {
|
||||
uint32_t uptimeNow;
|
||||
OSAL::getUptime(&uptimeNow);
|
||||
Clock::getUptime(&uptimeNow);
|
||||
if ((uptimeNow - uptimeStartTable)
|
||||
< (currentSequenceIterator->getWaitSeconds() * 1000)) {
|
||||
return;
|
||||
@ -111,7 +108,7 @@ void Subsystem::performChildOperation() {
|
||||
uptimeStartTable = 0;
|
||||
//next Table, but only if there is one
|
||||
if ((++currentSequenceIterator).value != NULL) { //we're through with this sequence
|
||||
executeTable(getCurrentTable());
|
||||
executeTable(getCurrentTable(), targetSubmode);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -120,7 +117,7 @@ void Subsystem::performChildOperation() {
|
||||
childrenChangedHealth = false;
|
||||
startTransition(mode, submode);
|
||||
} else if (childrenChangedMode) {
|
||||
if (checkStateAgainstTable(currentTargetTable) != RETURN_OK) {
|
||||
if (checkStateAgainstTable(currentTargetTable, submode) != RETURN_OK) {
|
||||
triggerEvent(CANT_KEEP_MODE, mode, submode);
|
||||
cantKeepMode();
|
||||
}
|
||||
@ -315,7 +312,7 @@ ReturnValue_t Subsystem::handleCommandMessage(CommandMessage* message) {
|
||||
CommandMessage reply;
|
||||
ModeSequenceMessage::setModeSequenceMessage(&reply,
|
||||
ModeSequenceMessage::FREE_SEQUENCE_SLOTS, freeSlots);
|
||||
commandQueue.reply(&reply);
|
||||
commandQueue->reply(&reply);
|
||||
}
|
||||
break;
|
||||
case ModeSequenceMessage::READ_FREE_TABLE_SLOTS: {
|
||||
@ -323,7 +320,7 @@ ReturnValue_t Subsystem::handleCommandMessage(CommandMessage* message) {
|
||||
CommandMessage reply;
|
||||
ModeSequenceMessage::setModeSequenceMessage(&reply,
|
||||
ModeSequenceMessage::FREE_TABLE_SLOTS, free);
|
||||
commandQueue.reply(&reply);
|
||||
commandQueue->reply(&reply);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -335,10 +332,10 @@ ReturnValue_t Subsystem::handleCommandMessage(CommandMessage* message) {
|
||||
void Subsystem::replyToCommand(ReturnValue_t status, uint32_t parameter) {
|
||||
if (status == RETURN_OK) {
|
||||
CommandMessage reply(CommandMessage::REPLY_COMMAND_OK, 0, 0);
|
||||
commandQueue.reply(&reply);
|
||||
commandQueue->reply(&reply);
|
||||
} else {
|
||||
CommandMessage reply(CommandMessage::REPLY_REJECTED, status, 0);
|
||||
commandQueue.reply(&reply);
|
||||
commandQueue->reply(&reply);
|
||||
}
|
||||
}
|
||||
|
||||
@ -372,13 +369,20 @@ ReturnValue_t Subsystem::addSequence(ArrayList<ModeListEntry>* sequence,
|
||||
}
|
||||
|
||||
if (inStore) {
|
||||
#ifdef USE_MODESTORE
|
||||
result = modeStore->storeArray(sequence,
|
||||
&(modeSequences.find(id)->entries.firstLinkedElement));
|
||||
if (result != RETURN_OK) {
|
||||
modeSequences.erase(id);
|
||||
}
|
||||
#else
|
||||
modeSequences.erase(id);
|
||||
return RETURN_FAILED;
|
||||
#endif
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t Subsystem::addTable(ArrayList<ModeListEntry> *table, Mode_t id,
|
||||
@ -408,11 +412,16 @@ ReturnValue_t Subsystem::addTable(ArrayList<ModeListEntry> *table, Mode_t id,
|
||||
}
|
||||
|
||||
if (inStore) {
|
||||
#ifdef USE_MODESTORE
|
||||
result = modeStore->storeArray(table,
|
||||
&(modeTables.find(id)->firstLinkedElement));
|
||||
if (result != RETURN_OK) {
|
||||
modeTables.erase(id);
|
||||
}
|
||||
#else
|
||||
modeTables.erase(id);
|
||||
return RETURN_FAILED;
|
||||
#endif
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -433,7 +442,9 @@ ReturnValue_t Subsystem::deleteSequence(Mode_t id) {
|
||||
return ACCESS_DENIED;
|
||||
}
|
||||
|
||||
#ifdef USE_MODESTORE
|
||||
modeStore->deleteList(sequenceInfo->entries.firstLinkedElement);
|
||||
#endif
|
||||
modeSequences.erase(id);
|
||||
return RETURN_OK;
|
||||
}
|
||||
@ -453,7 +464,10 @@ ReturnValue_t Subsystem::deleteTable(Mode_t id) {
|
||||
if (!pointer->islinked) {
|
||||
return ACCESS_DENIED;
|
||||
}
|
||||
|
||||
#ifdef USE_MODESTORE
|
||||
modeStore->deleteList(pointer->firstLinkedElement);
|
||||
#endif
|
||||
modeSequences.erase(id);
|
||||
return RETURN_OK;
|
||||
}
|
||||
@ -466,12 +480,18 @@ ReturnValue_t Subsystem::initialize() {
|
||||
}
|
||||
|
||||
IPCStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
||||
modeStore = objectManager->get<ModeStoreIF>(objects::MODE_STORE);
|
||||
|
||||
if ((IPCStore == NULL) || (modeStore == NULL)) {
|
||||
if (IPCStore == NULL) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
#ifdef USE_MODESTORE
|
||||
modeStore = objectManager->get<ModeStoreIF>(objects::MODE_STORE);
|
||||
|
||||
if (modeStore == NULL) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((modeSequences.maxSize() > MAX_NUMBER_OF_TABLES_OR_SEQUENCES)
|
||||
|| (modeTables.maxSize() > MAX_NUMBER_OF_TABLES_OR_SEQUENCES)) {
|
||||
return TABLE_OR_SEQUENCE_LENGTH_INVALID;
|
||||
@ -488,9 +508,10 @@ MessageQueueId_t Subsystem::getSequenceCommandQueue() const {
|
||||
|
||||
ReturnValue_t Subsystem::checkModeCommand(Mode_t mode, Submode_t submode,
|
||||
uint32_t* msToReachTheMode) {
|
||||
if (submode != SUBMODE_NONE) {
|
||||
return INVALID_SUBMODE;
|
||||
}
|
||||
//Need to accept all submodes to be able to inherit submodes
|
||||
// if (submode != SUBMODE_NONE) {
|
||||
// return INVALID_SUBMODE;
|
||||
// }
|
||||
|
||||
if (isInTransition && (mode != getFallbackSequence(targetMode))) {
|
||||
return HasModesIF::IN_TRANSITION;
|
||||
@ -516,7 +537,7 @@ void Subsystem::startTransition(Mode_t sequence, Submode_t submode) {
|
||||
++currentSequenceIterator;
|
||||
|
||||
if (currentSequenceIterator.value != NULL) {
|
||||
executeTable(getCurrentTable());
|
||||
executeTable(getCurrentTable(), targetSubmode);
|
||||
}
|
||||
}
|
||||
|
||||
@ -598,7 +619,7 @@ void Subsystem::sendSerializablesAsCommandMessage(Command_t command,
|
||||
}
|
||||
CommandMessage reply;
|
||||
ModeSequenceMessage::setModeSequenceMessage(&reply, command, address);
|
||||
if (commandQueue.reply(&reply) != RETURN_OK) {
|
||||
if (commandQueue->reply(&reply) != RETURN_OK) {
|
||||
IPCStore->deleteData(address);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* Subsystem.h
|
||||
*
|
||||
* Created on: 12.07.2013
|
||||
* Author: tod
|
||||
*/
|
||||
|
||||
#ifndef SUBSYSTEM_H_
|
||||
#define SUBSYSTEM_H_
|
||||
|
||||
@ -18,7 +11,7 @@
|
||||
|
||||
class Subsystem: public SubsystemBase, public HasModeSequenceIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = SUBSYSTEM;
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::SUBSYSTEM;
|
||||
static const ReturnValue_t SEQUENCE_ALREADY_EXISTS = MAKE_RETURN_CODE(0x01);
|
||||
static const ReturnValue_t TABLE_ALREADY_EXISTS = MAKE_RETURN_CODE(0x02);
|
||||
static const ReturnValue_t TABLE_DOES_NOT_EXIST = MAKE_RETURN_CODE(0x03);
|
||||
@ -91,7 +84,7 @@ protected:
|
||||
EntryPointer entries;
|
||||
};
|
||||
|
||||
static const uint8_t MAX_NUMBER_OF_TABLES_OR_SEQUENCES = 60;
|
||||
static const uint8_t MAX_NUMBER_OF_TABLES_OR_SEQUENCES = 70;
|
||||
|
||||
static const uint8_t MAX_LENGTH_OF_TABLE_OR_SEQUENCE = 20;
|
||||
|
||||
@ -117,7 +110,9 @@ protected:
|
||||
|
||||
StorageManagerIF *IPCStore;
|
||||
|
||||
#ifdef USE_MODESTORE
|
||||
ModeStoreIF *modeStore;
|
||||
#endif
|
||||
|
||||
bool existsModeSequence(Mode_t id);
|
||||
|
||||
|
@ -1,8 +1,19 @@
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <framework/subsystem/SubsystemBase.h>
|
||||
#include <framework/ipc/QueueFactory.h>
|
||||
|
||||
SubsystemBase::SubsystemBase(object_id_t setObjectId, object_id_t parent,
|
||||
Mode_t initialMode, uint16_t commandQueueDepth) :
|
||||
SystemObject(setObjectId), mode(initialMode), submode(SUBMODE_NONE), childrenChangedMode(
|
||||
false), commandsOutstanding(0), commandQueue(NULL), healthHelper(this,
|
||||
setObjectId), modeHelper(this), parentId(parent) {
|
||||
QueueFactory::instance()->createMessageQueue(commandQueueDepth,
|
||||
CommandMessage::MAX_MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
SubsystemBase::~SubsystemBase() {
|
||||
QueueFactory::instance()->deleteMessageQueue(commandQueue);
|
||||
|
||||
}
|
||||
|
||||
@ -38,7 +49,7 @@ ReturnValue_t SubsystemBase::registerChild(object_id_t objectId) {
|
||||
}
|
||||
|
||||
ReturnValue_t SubsystemBase::checkStateAgainstTable(
|
||||
HybridIterator<ModeListEntry> tableIter) {
|
||||
HybridIterator<ModeListEntry> tableIter, Submode_t targetSubmode) {
|
||||
|
||||
std::map<object_id_t, ChildInfo>::iterator childIter;
|
||||
|
||||
@ -52,14 +63,20 @@ ReturnValue_t SubsystemBase::checkStateAgainstTable(
|
||||
if (childIter->second.mode != tableIter.value->getMode()) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
if (childIter->second.submode != tableIter.value->getSubmode()) {
|
||||
|
||||
Submode_t submodeToCheckAgainst = tableIter.value->getSubmode();
|
||||
if (tableIter.value->inheritSubmode()) {
|
||||
submodeToCheckAgainst = targetSubmode;
|
||||
}
|
||||
|
||||
if (childIter->second.submode != submodeToCheckAgainst) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void SubsystemBase::executeTable(HybridIterator<ModeListEntry> tableIter) {
|
||||
void SubsystemBase::executeTable(HybridIterator<ModeListEntry> tableIter, Submode_t targetSubmode) {
|
||||
|
||||
CommandMessage message;
|
||||
|
||||
@ -70,11 +87,17 @@ void SubsystemBase::executeTable(HybridIterator<ModeListEntry> tableIter) {
|
||||
for (; tableIter.value != NULL; ++tableIter) {
|
||||
object_id_t object = tableIter.value->getObject();
|
||||
if ((iter = childrenMap.find(object)) == childrenMap.end()) {
|
||||
//illegal table entry
|
||||
//TODO: software error
|
||||
//illegal table entry, should only happen due to misconfigured mode table
|
||||
debug << std::hex << getObjectId() << ": invalid mode table entry"
|
||||
<< std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
Submode_t submodeToCommand = tableIter.value->getSubmode();
|
||||
if (tableIter.value->inheritSubmode()) {
|
||||
submodeToCommand = targetSubmode;
|
||||
}
|
||||
|
||||
if (healthHelper.healthTable->hasHealth(object)) {
|
||||
if (healthHelper.healthTable->isFaulty(object)) {
|
||||
ModeMessage::setModeMessage(&message,
|
||||
@ -84,14 +107,12 @@ void SubsystemBase::executeTable(HybridIterator<ModeListEntry> tableIter) {
|
||||
if (modeHelper.isForced()) {
|
||||
ModeMessage::setModeMessage(&message,
|
||||
ModeMessage::CMD_MODE_COMMAND_FORCED,
|
||||
tableIter.value->getMode(),
|
||||
tableIter.value->getSubmode());
|
||||
tableIter.value->getMode(), submodeToCommand);
|
||||
} else {
|
||||
if (healthHelper.healthTable->isCommandable(object)) {
|
||||
ModeMessage::setModeMessage(&message,
|
||||
ModeMessage::CMD_MODE_COMMAND,
|
||||
tableIter.value->getMode(),
|
||||
tableIter.value->getSubmode());
|
||||
tableIter.value->getMode(), submodeToCommand);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
@ -99,20 +120,19 @@ void SubsystemBase::executeTable(HybridIterator<ModeListEntry> tableIter) {
|
||||
}
|
||||
} else {
|
||||
ModeMessage::setModeMessage(&message, ModeMessage::CMD_MODE_COMMAND,
|
||||
tableIter.value->getMode(), tableIter.value->getSubmode());
|
||||
tableIter.value->getMode(), submodeToCommand);
|
||||
}
|
||||
//TODO: This may causes trouble with more than two layers, sys commands subsys off, which is already off, but children are on (external).
|
||||
// So, they stay on. Might only be an issue if mode is forced, so we do
|
||||
|
||||
if ((iter->second.mode == ModeMessage::getMode(&message))
|
||||
&& (iter->second.submode == ModeMessage::getSubmode(&message)) && !modeHelper.isForced()) {
|
||||
continue; //don't send redundant mode commands (produces event spam)
|
||||
&& (iter->second.submode == ModeMessage::getSubmode(&message))
|
||||
&& !modeHelper.isForced()) {
|
||||
continue; //don't send redundant mode commands (produces event spam), but still command if mode is forced to reach lower levels
|
||||
}
|
||||
ReturnValue_t result = commandQueue.sendMessage(
|
||||
ReturnValue_t result = commandQueue->sendMessage(
|
||||
iter->second.commandQueue, &message);
|
||||
if (result != RETURN_OK) {
|
||||
//TODO OBSW internal error
|
||||
if (result == RETURN_OK) {
|
||||
++commandsOutstanding;
|
||||
}
|
||||
++commandsOutstanding;
|
||||
}
|
||||
|
||||
}
|
||||
@ -132,7 +152,7 @@ ReturnValue_t SubsystemBase::updateChildMode(MessageQueueId_t queue,
|
||||
}
|
||||
|
||||
ReturnValue_t SubsystemBase::updateChildChangedHealth(MessageQueueId_t queue,
|
||||
bool changedHealth) {
|
||||
bool changedHealth) {
|
||||
for (auto iter = childrenMap.begin(); iter != childrenMap.end(); iter++) {
|
||||
if (iter->second.commandQueue == queue) {
|
||||
iter->second.healthChanged = changedHealth;
|
||||
@ -142,15 +162,8 @@ ReturnValue_t SubsystemBase::updateChildChangedHealth(MessageQueueId_t queue,
|
||||
return CHILD_NOT_FOUND;
|
||||
}
|
||||
|
||||
SubsystemBase::SubsystemBase(object_id_t setObjectId, object_id_t parent,
|
||||
Mode_t initialMode, uint16_t commandQueueDepth) :
|
||||
SystemObject(setObjectId), mode(initialMode), submode(SUBMODE_NONE), childrenChangedMode(
|
||||
false), commandsOutstanding(0), commandQueue(commandQueueDepth,
|
||||
CommandMessage::MAX_MESSAGE_SIZE), healthHelper(this, setObjectId), modeHelper(this), parentId(parent) {
|
||||
}
|
||||
|
||||
MessageQueueId_t SubsystemBase::getCommandQueue() const {
|
||||
return commandQueue.getId();
|
||||
return commandQueue->getId();
|
||||
}
|
||||
|
||||
ReturnValue_t SubsystemBase::initialize() {
|
||||
@ -186,7 +199,7 @@ ReturnValue_t SubsystemBase::initialize() {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t SubsystemBase::performOperation() {
|
||||
ReturnValue_t SubsystemBase::performOperation(uint8_t opCode) {
|
||||
|
||||
childrenChangedMode = false;
|
||||
|
||||
@ -217,7 +230,8 @@ ReturnValue_t SubsystemBase::handleModeReply(CommandMessage* message) {
|
||||
for (auto iter = childrenMap.begin(); iter != childrenMap.end();
|
||||
iter++) {
|
||||
if (iter->second.commandQueue == message->getSender()) {
|
||||
triggerEvent(MODE_CMD_REJECTED, iter->first, message->getParameter());
|
||||
triggerEvent(MODE_CMD_REJECTED, iter->first,
|
||||
message->getParameter());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -249,13 +263,14 @@ ReturnValue_t SubsystemBase::checkTable(
|
||||
}
|
||||
|
||||
void SubsystemBase::replyToCommand(CommandMessage* message) {
|
||||
commandQueue.reply(message);
|
||||
commandQueue->reply(message);
|
||||
}
|
||||
|
||||
void SubsystemBase::setMode(Mode_t newMode, Submode_t newSubmode) {
|
||||
modeHelper.modeChanged(newMode, newSubmode);
|
||||
mode = newMode;
|
||||
submode = newSubmode;
|
||||
modeChanged();
|
||||
announceMode(false);
|
||||
}
|
||||
|
||||
@ -266,7 +281,7 @@ void SubsystemBase::setMode(Mode_t newMode) {
|
||||
void SubsystemBase::commandAllChildren(CommandMessage* message) {
|
||||
std::map<object_id_t, ChildInfo>::iterator iter;
|
||||
for (iter = childrenMap.begin(); iter != childrenMap.end(); ++iter) {
|
||||
commandQueue.sendMessage(iter->second.commandQueue, message);
|
||||
commandQueue->sendMessage(iter->second.commandQueue, message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -293,8 +308,8 @@ void SubsystemBase::checkCommandQueue() {
|
||||
ReturnValue_t result;
|
||||
CommandMessage message;
|
||||
|
||||
for (result = commandQueue.receiveMessage(&message); result == RETURN_OK;
|
||||
result = commandQueue.receiveMessage(&message)) {
|
||||
for (result = commandQueue->receiveMessage(&message); result == RETURN_OK;
|
||||
result = commandQueue->receiveMessage(&message)) {
|
||||
|
||||
result = healthHelper.handleHealthCommand(&message);
|
||||
if (result == RETURN_OK) {
|
||||
@ -314,7 +329,8 @@ void SubsystemBase::checkCommandQueue() {
|
||||
result = handleCommandMessage(&message);
|
||||
if (result != RETURN_OK) {
|
||||
CommandMessage reply;
|
||||
reply.setReplyRejected(CommandMessage::UNKNOW_COMMAND, message.getCommand());
|
||||
reply.setReplyRejected(CommandMessage::UNKNOW_COMMAND,
|
||||
message.getCommand());
|
||||
replyToCommand(&reply);
|
||||
}
|
||||
}
|
||||
@ -334,3 +350,7 @@ ReturnValue_t SubsystemBase::setHealth(HealthState health) {
|
||||
HasHealthIF::HealthState SubsystemBase::getHealth() {
|
||||
return healthHelper.getHealth();
|
||||
}
|
||||
|
||||
void SubsystemBase::modeChanged() {
|
||||
}
|
||||
|
||||
|
@ -4,22 +4,21 @@
|
||||
#include <framework/container/HybridIterator.h>
|
||||
#include <framework/health/HasHealthIF.h>
|
||||
#include <framework/health/HealthHelper.h>
|
||||
#include <framework/ipc/MessageQueue.h>
|
||||
#include <framework/modes/HasModesIF.h>
|
||||
#include <framework/objectmanager/SystemObject.h>
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/subsystem/modes/HasModeSequenceIF.h>
|
||||
#include <framework/tasks/ExecutableObjectIF.h>
|
||||
#include <framework/ipc/MessageQueueIF.h>
|
||||
#include <map>
|
||||
|
||||
|
||||
class SubsystemBase: public SystemObject,
|
||||
public HasModesIF,
|
||||
public HasHealthIF,
|
||||
public HasReturnvaluesIF,
|
||||
public ExecutableObjectIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = SUBSYSTEM_BASE;
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::SUBSYSTEM_BASE;
|
||||
static const ReturnValue_t CHILD_NOT_FOUND = MAKE_RETURN_CODE(0x01);
|
||||
static const ReturnValue_t CHILD_INFO_UPDATED = MAKE_RETURN_CODE(0x02);
|
||||
static const ReturnValue_t CHILD_DOESNT_HAVE_MODES = MAKE_RETURN_CODE(0x03);
|
||||
@ -37,7 +36,7 @@ public:
|
||||
|
||||
virtual ReturnValue_t initialize();
|
||||
|
||||
virtual ReturnValue_t performOperation();
|
||||
virtual ReturnValue_t performOperation(uint8_t opCode);
|
||||
|
||||
virtual ReturnValue_t setHealth(HealthState health);
|
||||
|
||||
@ -47,8 +46,7 @@ protected:
|
||||
struct ChildInfo {
|
||||
MessageQueueId_t commandQueue;
|
||||
Mode_t mode;
|
||||
Submode_t submode;
|
||||
bool healthChanged;
|
||||
Submode_t submode;bool healthChanged;
|
||||
};
|
||||
|
||||
Mode_t mode;
|
||||
@ -62,7 +60,7 @@ protected:
|
||||
*/
|
||||
int32_t commandsOutstanding;
|
||||
|
||||
MessageQueue commandQueue;
|
||||
MessageQueueIF* commandQueue;
|
||||
|
||||
HealthHelper healthHelper;
|
||||
|
||||
@ -75,15 +73,24 @@ protected:
|
||||
|
||||
void checkCommandQueue();
|
||||
|
||||
/**
|
||||
* We need to know the target Submode, as children are able to inherit the submode
|
||||
*/
|
||||
ReturnValue_t checkStateAgainstTable(
|
||||
HybridIterator<ModeListEntry> tableIter);
|
||||
HybridIterator<ModeListEntry> tableIter, Submode_t targetSubmode);
|
||||
|
||||
void executeTable(HybridIterator<ModeListEntry> tableIter);
|
||||
/**
|
||||
* We need to know the target Submode, as children are able to inherit the submode
|
||||
* Still, we have a default for all child implementations which do not use submode inheritance
|
||||
*/
|
||||
void executeTable(HybridIterator<ModeListEntry> tableIter,
|
||||
Submode_t targetSubmode = SUBMODE_NONE);
|
||||
|
||||
ReturnValue_t updateChildMode(MessageQueueId_t queue, Mode_t mode,
|
||||
Submode_t submode);
|
||||
|
||||
ReturnValue_t updateChildChangedHealth(MessageQueueId_t queue, bool changedHealth = true);
|
||||
ReturnValue_t updateChildChangedHealth(MessageQueueId_t queue,
|
||||
bool changedHealth = true);
|
||||
|
||||
virtual ReturnValue_t handleModeReply(CommandMessage *message);
|
||||
|
||||
@ -111,6 +118,8 @@ protected:
|
||||
virtual void setToExternalControl();
|
||||
|
||||
virtual void announceMode(bool recursive);
|
||||
|
||||
virtual void modeChanged();
|
||||
};
|
||||
|
||||
#endif /* SUBSYSTEMBASE_H_ */
|
||||
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* ModeTable.h
|
||||
*
|
||||
* Created on: 12.07.2013
|
||||
* Author: tod
|
||||
*/
|
||||
|
||||
#ifndef MODEDEFINITIONS_H_
|
||||
#define MODEDEFINITIONS_H_
|
||||
|
||||
@ -15,13 +8,15 @@
|
||||
class ModeListEntry: public SerializeIF, public LinkedElement<ModeListEntry> {
|
||||
public:
|
||||
ModeListEntry() :
|
||||
LinkedElement<ModeListEntry>(this), value1(0), value2(0), value3(0) {
|
||||
LinkedElement<ModeListEntry>(this), value1(0), value2(0), value3(0), value4(
|
||||
0) {
|
||||
|
||||
}
|
||||
|
||||
uint32_t value1;
|
||||
uint32_t value2;
|
||||
uint8_t value3;
|
||||
uint8_t value4;
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size,
|
||||
const uint32_t max_size, bool bigEndian) const {
|
||||
@ -43,16 +38,23 @@ public:
|
||||
result = SerializeAdapter<uint8_t>::serialize(&value3, buffer, size,
|
||||
max_size, bigEndian);
|
||||
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = SerializeAdapter<uint8_t>::serialize(&value4, buffer, size,
|
||||
max_size, bigEndian);
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
virtual uint32_t getSerializedSize() const {
|
||||
return sizeof(value1) + sizeof(value2) + sizeof(value3);
|
||||
return sizeof(value1) + sizeof(value2) + sizeof(value3) + sizeof(value4);
|
||||
}
|
||||
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,
|
||||
bool bigEndian) {
|
||||
bool bigEndian) {
|
||||
ReturnValue_t result;
|
||||
|
||||
result = SerializeAdapter<uint32_t>::deSerialize(&value1, buffer, size,
|
||||
@ -70,6 +72,12 @@ public:
|
||||
result = SerializeAdapter<uint8_t>::deSerialize(&value3, buffer, size,
|
||||
bigEndian);
|
||||
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = SerializeAdapter<uint8_t>::deSerialize(&value4, buffer, size,
|
||||
bigEndian);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -98,7 +106,6 @@ public:
|
||||
this->value3 = checkSuccess;
|
||||
}
|
||||
|
||||
|
||||
//for Tables
|
||||
object_id_t getObject() const {
|
||||
return value1;
|
||||
@ -108,7 +115,6 @@ public:
|
||||
this->value1 = object;
|
||||
}
|
||||
|
||||
//TODO no cast!
|
||||
Mode_t getMode() const {
|
||||
return value2;
|
||||
}
|
||||
@ -125,6 +131,18 @@ public:
|
||||
this->value3 = submode;
|
||||
}
|
||||
|
||||
bool inheritSubmode() const {
|
||||
return value4 == 1;
|
||||
}
|
||||
|
||||
void setInheritSubmode(bool inherit){
|
||||
if (inherit){
|
||||
value4 = 1;
|
||||
} else {
|
||||
value4 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(ModeListEntry other) {
|
||||
return ((value1 == other.value1) && (value2 == other.value2)
|
||||
&& (value3 == other.value3));
|
||||
|
@ -69,7 +69,7 @@ void ModeSequenceMessage::clear(CommandMessage *message) {
|
||||
ipcStore->deleteData(ModeSequenceMessage::getStoreAddress(message));
|
||||
}
|
||||
}
|
||||
/*NO BREAK*/
|
||||
/* NO BREAK falls through*/
|
||||
case DELETE_SEQUENCE:
|
||||
case DELETE_TABLE:
|
||||
case READ_SEQUENCE:
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
class ModeSequenceMessage {
|
||||
public:
|
||||
static const uint8_t MESSAGE_ID = MODE_SEQUENCE_MESSAGE_ID;
|
||||
static const uint8_t MESSAGE_ID = MESSAGE_TYPE::MODE_SEQUENCE;
|
||||
|
||||
static const Command_t ADD_SEQUENCE = MAKE_COMMAND_ID(0x01);
|
||||
static const Command_t ADD_TABLE = MAKE_COMMAND_ID(0x02);
|
||||
|
@ -1,8 +1,10 @@
|
||||
#include <framework/subsystem/modes/ModeStore.h>
|
||||
|
||||
#ifdef USE_MODESTORE
|
||||
|
||||
ModeStore::ModeStore(object_id_t objectId, uint32_t slots) :
|
||||
SystemObject(objectId), store(slots), emptySlot(store.front()) {
|
||||
mutex = new MutexId_t;
|
||||
mutex = MutexFactory::instance()->createMutex();;
|
||||
OSAL::createMutex(objectId + 1, mutex);
|
||||
clear();
|
||||
}
|
||||
@ -38,7 +40,7 @@ ReturnValue_t ModeStore::storeArray(ArrayList<ModeListEntry>* sequence,
|
||||
|
||||
ArrayList<ModeListEntry>::Iterator iter;
|
||||
for (iter = sequence->begin(); iter != sequence->end(); ++iter) {
|
||||
//TODO: I need to check this in detail. What is the idea? Why does it not work?
|
||||
//SHOULDDO: I need to check this in detail. What is the idea? Why does it not work?
|
||||
pointer = pointer->getNext()->value;
|
||||
if (pointer == NULL) {
|
||||
deleteListNoLock(*storedFirstEntry);
|
||||
@ -120,3 +122,5 @@ ReturnValue_t ModeStore::isValidEntry(ModeListEntry* sequence) {
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef MODESTORE_H_
|
||||
#define MODESTORE_H_
|
||||
|
||||
#ifdef USE_MODESTORE
|
||||
|
||||
#include <framework/container/ArrayList.h>
|
||||
#include <framework/container/SinglyLinkedList.h>
|
||||
#include <framework/objectmanager/SystemObject.h>
|
||||
@ -37,5 +39,7 @@ private:
|
||||
ReturnValue_t isValidEntry(ModeListEntry *sequence);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* MODESTORE_H_ */
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef MODESTOREIF_H_
|
||||
#define MODESTOREIF_H_
|
||||
|
||||
#ifdef USE_MODESTORE
|
||||
|
||||
#include <framework/container/ArrayList.h>
|
||||
#include <framework/container/SinglyLinkedList.h>
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
@ -8,7 +10,7 @@
|
||||
|
||||
class ModeStoreIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = MODE_STORE_IF;
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::MODE_STORE_IF;
|
||||
static const ReturnValue_t INVALID_ENTRY = MAKE_RETURN_CODE(0x02);
|
||||
static const ReturnValue_t TOO_MANY_ELEMENTS = MAKE_RETURN_CODE(0x03);
|
||||
static const ReturnValue_t CANT_STORE_EMPTY = MAKE_RETURN_CODE(0x04);
|
||||
@ -30,4 +32,6 @@ public:
|
||||
virtual uint32_t getFreeSlots() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* MODESTOREIF_H_ */
|
||||
|
Reference in New Issue
Block a user