1
0
forked from fsfw/fsfw

DHB/Cookie refactoring

This commit is contained in:
2020-04-01 12:41:54 +02:00
parent 5218a0d84f
commit 996dbc9e4b
14 changed files with 142 additions and 213 deletions

View File

@ -8,7 +8,7 @@ ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId,
uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId,
uint32_t parent, FailureIsolationBase* customFdir, size_t cmdQueueSize) :
DeviceHandlerBase(setObjectId, deviceCommunication, cookie,
maxDeviceReplyLen, setDeviceSwitch, thermalStatePoolId,
setDeviceSwitch, thermalStatePoolId,
thermalRequestPoolId, (customFdir == NULL? &childHandlerFdir : customFdir),
cmdQueueSize),
parentId(parent), childHandlerFdir(setObjectId) {

View File

@ -1,26 +0,0 @@
/**
* @file Cookie.cpp
*
* @date 23.03.2020
*/
#include <framework/devicehandlers/Cookie.h>
Cookie::Cookie(address_t logicalAddress_): logicalAddress(logicalAddress_) {
}
void Cookie::setAddress(address_t logicalAddress_) {
logicalAddress = logicalAddress_;
}
void Cookie::setMaxReplyLen(size_t maxReplyLen_) {
maxReplyLen = maxReplyLen_;
}
address_t Cookie::getAddress() const {
return logicalAddress;
}
size_t Cookie::getMaxReplyLen() const {
return maxReplyLen;
}

View File

@ -1,38 +0,0 @@
#ifndef COOKIE_H_
#define COOKIE_H_
#include <framework/devicehandlers/CookieIF.h>
/**
* @brief This datatype is used to identify different connection over a single interface
* (like RMAP or I2C)
* @details
* To use this class, implement a communication specific child cookie which
* inherits Cookie. Cookie instances are created in config/ Factory.cpp by calling
* CookieIF* childCookie = new ChildCookie(...).´
*
* This cookie is then passed to the child device handlers, which stores the
* pointer and passes it to the communication interface functions.
*
* The cookie can be used to store all kinds of information
* about the communication, like slave addresses, communication status,
* communication parameters etc.
*
* @ingroup comm
*/
class Cookie: public CookieIF {
public:
Cookie();
Cookie(address_t logicalAddress_);
virtual ~Cookie() {};
virtual void setAddress(address_t logicalAddres_);
virtual void setMaxReplyLen(size_t maxReplyLen_);
virtual address_t getAddress() const;
virtual size_t getMaxReplyLen() const;
private:
address_t logicalAddress = 0;
size_t maxReplyLen = 0;
};
#endif /* COOKIE_H_ */

View File

@ -1,30 +1,33 @@
/**
* @file CookieIF.h
*
* @date 23.03.2020
*/
#ifndef FRAMEWORK_DEVICEHANDLERS_COOKIEIF_H_
#define FRAMEWORK_DEVICEHANDLERS_COOKIEIF_H_
#include <framework/devicehandlers/DeviceHandlerIF.h>
/**
* @brief Physical address type
*/
typedef uint32_t address_t;
class CookieIF {
public:
/**
* Default empty virtual destructor.
*/
virtual ~CookieIF() {};
virtual void setAddress(address_t logicalAddress_) = 0;
virtual address_t getAddress() const = 0;
virtual void setMaxReplyLen(size_t maxReplyLen_) = 0;
virtual size_t getMaxReplyLen() const = 0;
};
#endif /* FRAMEWORK_DEVICEHANDLERS_COOKIEIF_H_ */
#ifndef COOKIE_H_
#define COOKIE_H_
#include <framework/devicehandlers/CookieIF.h>
#include <stdint.h>
/**
* @brief Physical address type
*/
typedef uint32_t address_t;
/**
* @brief This datatype is used to identify different connection over a single interface
* (like RMAP or I2C)
* @details
* To use this class, implement a communication specific child cookie which
* inherits Cookie. Cookie instances are created in config/ Factory.cpp by calling
* CookieIF* childCookie = new ChildCookie(...).
*
* This cookie is then passed to the child device handlers, which stores the
* pointer and passes it to the communication interface functions.
*
* The cookie can be used to store all kinds of information
* about the communication, like slave addresses, communication status,
* communication parameters etc.
*
* @ingroup comm
*/
class CookieIF {
public:
virtual ~CookieIF() {};
};
#endif /* COOKIE_H_ */

View File

@ -1,7 +1,7 @@
#ifndef DEVICECOMMUNICATIONIF_H_
#define DEVICECOMMUNICATIONIF_H_
#include <framework/devicehandlers/Cookie.h>
#include <framework/devicehandlers/CookieIF.h>
#include <framework/devicehandlers/DeviceHandlerIF.h>
#include <framework/returnvalues/HasReturnvaluesIF.h>
/**
@ -88,11 +88,14 @@ public:
/**
* Called by DHB in the SEND_WRITE doSendRead().
* Request a reply.
* It is assumed that it is always possible to request a reply
* from a device. If a requestLen of 0 is supplied, no reply was enabled
* and communication specific action should be taken (e.g. read nothing
* or read everything).
*
* @param cookie
* @param requestLen Size of data to read
* @return -@c RETURN_OK to confirm the request for data has been sent.
* -@c NO_READ_REQUEST if no request shall be made. readReceivedMessage()
* will not be called in the respective communication cycle.
* - Everything else triggers failure event with returnvalue as parameter 1
*/
virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) = 0;

View File

@ -17,7 +17,7 @@ object_id_t DeviceHandlerBase::rawDataReceiverId = 0;
object_id_t DeviceHandlerBase::defaultFDIRParentId = 0;
DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication,
CookieIF * comCookie_, size_t maxReplyLen, uint8_t setDeviceSwitch,
CookieIF * comCookie_, uint8_t setDeviceSwitch,
uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId,
FailureIsolationBase* fdirInstance, size_t cmdQueueSize) :
SystemObject(setObjectId), mode(MODE_OFF), submode(SUBMODE_NONE),
@ -31,7 +31,6 @@ DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, object_id_t device
childTransitionDelay(5000), transitionSourceMode(_MODE_POWER_DOWN),
transitionSourceSubMode(SUBMODE_NONE), deviceSwitch(setDeviceSwitch)
{
this->comCookie->setMaxReplyLen(maxReplyLen);
commandQueue = QueueFactory::instance()->
createMessageQueue(cmdQueueSize, CommandMessage::MAX_MESSAGE_SIZE);
cookieInfo.state = COOKIE_UNUSED;
@ -540,23 +539,27 @@ void DeviceHandlerBase::doGetWrite() {
}
void DeviceHandlerBase::doSendRead() {
ReturnValue_t result;
DeviceReplyIter iter = deviceReplyMap.find(cookieInfo.pendingCommand->first);
if(iter != deviceReplyMap.end()) {
requestLen = iter->second.replyLen;
}
else {
requestLen = comCookie->getMaxReplyLen();
ReturnValue_t result = RETURN_FAILED;
size_t requestLen = 0;
// If the device handler can only request replies after a command
// has been sent, there should be only one reply enabled and the
// correct reply length will be mapped.
for(DeviceReplyIter iter = deviceReplyMap.begin();
iter != deviceReplyMap.end();iter++)
{
if(iter->second.delayCycles != 0) {
requestLen = iter->second.replyLen;
break;
}
}
result = communicationInterface->requestReceiveMessage(comCookie, requestLen);
if (result == RETURN_OK) {
cookieInfo.state = COOKIE_READ_SENT;
}
else if(result == DeviceCommunicationIF::NO_READ_REQUEST) {
/* else if(result == DeviceCommunicationIF::NO_READ_REQUEST) {
return;
}
}*/
else {
triggerEvent(DEVICE_REQUESTING_REPLY_FAILED, result);
//We can't inform anyone, because we don't know which command was sent last.
@ -1288,9 +1291,5 @@ void DeviceHandlerBase::setTaskIF(PeriodicTaskIF* task_){
void DeviceHandlerBase::debugInterface(uint8_t positionTracker, object_id_t objectId, uint32_t parameter) {
}
uint32_t DeviceHandlerBase::getLogicalAddress() {
return this->comCookie->getAddress();
}
void DeviceHandlerBase::performOperationHook() {
}

View File

@ -101,7 +101,7 @@ public:
* @param cmdQueueSize
*/
DeviceHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication,
CookieIF * comCookie_, size_t maxReplyLen, uint8_t setDeviceSwitch,
CookieIF * comCookie_, uint8_t setDeviceSwitch,
uint32_t thermalStatePoolId = PoolVariableIF::NO_PARAMETER,
uint32_t thermalRequestPoolId = PoolVariableIF::NO_PARAMETER,
FailureIsolationBase* fdirInstance = nullptr, size_t cmdQueueSize = 20);
@ -439,11 +439,6 @@ protected:
*/
size_t rawPacketLen = 0;
/**
* Size of data to request.
*/
size_t requestLen = 0;
/**
* The mode the device handler is currently in.
*
@ -463,11 +458,6 @@ protected:
*/
uint8_t pstStep = 0;
/**
* This will be used in the RMAP getRead command as expected length, is set by the constructor, can be modiefied at will.
*/
const uint32_t maxDeviceReplyLen = 0;
/**
* wiretapping flag:
*
@ -526,7 +516,6 @@ protected:
struct DeviceCommandInfo {
bool isExecuting; //!< Indicates if the command is already executing.
uint8_t expectedReplies; //!< Dynamic value to indicate how many replies are expected. Inititated with 0.
uint8_t expectedRepliesWhenEnablingReplyMap; //!< Constant value which specifies expected replies when enabling reply map. Inititated in insertInCommandAndReplyMap()
MessageQueueId_t sendReplyTo; //!< if this is != NO_COMMANDER, DHB was commanded externally and shall report everything to commander.
};
typedef std::map<DeviceCommandId_t, DeviceCommandInfo> DeviceCommandMap;
@ -847,11 +836,6 @@ protected:
*/
virtual bool dontCheckQueue();
/**
* Used to retrieve logical address
* @return logicalAddress
*/
virtual uint32_t getLogicalAddress();
Mode_t getBaseMode(Mode_t transitionMode);
bool isAwaitingReply();
@ -962,11 +946,6 @@ private:
*/
CookieInfo cookieInfo;
/**
* cached from ctor for initialize()
*/
//const uint32_t logicalAddress = 0;
/**
* Used for timing out mode transitions.
*