DHB/Cookie refactoring

This commit is contained in:
Robin Müller 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>
#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:
/**
* 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_ */
#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()) {
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;
}
else {
requestLen = comCookie->getMaxReplyLen();
}
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.
*

View File

@ -12,8 +12,8 @@ RMAP::RMAP(){
}
ReturnValue_t RMAP::sendWriteCommand(RMAPCookie *cookie, uint8_t* buffer,
uint32_t length) {
ReturnValue_t RMAP::sendWriteCommand(RMAPCookie *cookie, const uint8_t* buffer,
size_t length) {
uint8_t instruction;
if ((buffer == NULL) && (length != 0)) {
@ -61,7 +61,7 @@ ReturnValue_t RMAP::sendReadCommand(RMAPCookie *cookie, uint32_t expLength) {
}
ReturnValue_t RMAP::getReadReply(RMAPCookie *cookie, uint8_t **buffer,
uint32_t *size) {
size_t *size) {
if (cookie->getChannel() == NULL) {
return COMMAND_NO_CHANNEL;
}

View File

@ -153,8 +153,8 @@ public:
* - @c COMMAND_NULLPOINTER datalen was != 0 but data was == NULL in write command
* - return codes of RMAPChannelIF::sendCommand()
*/
static ReturnValue_t sendWriteCommand(RMAPCookie *cookie, uint8_t* buffer,
uint32_t length);
static ReturnValue_t sendWriteCommand(RMAPCookie *cookie, const uint8_t* buffer,
size_t length);
/**
* get the reply to a write command
@ -204,7 +204,7 @@ public:
* - return codes of RMAPChannelIF::getReply()
*/
static ReturnValue_t getReadReply(RMAPCookie *cookie, uint8_t **buffer,
uint32_t *size);
size_t *size);
/**
* @see sendReadCommand()

View File

@ -3,6 +3,7 @@
#include <framework/rmap/RMAPCookie.h>
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <cstddef>
class RMAPChannelIF {
public:
@ -73,7 +74,7 @@ public:
* - @c NOT_SUPPORTED if you dont feel like implementing something...
*/
virtual ReturnValue_t sendCommand(RMAPCookie *cookie, uint8_t instruction,
uint8_t *data, uint32_t datalen)=0;
const uint8_t *data, size_t datalen)=0;
/**
* get the reply to an rmap command
@ -92,7 +93,7 @@ public:
* - all RMAP standard replies
*/
virtual ReturnValue_t getReply(RMAPCookie *cookie, uint8_t **databuffer,
uint32_t *len)=0;
size_t *len)=0;
/**
*

View File

@ -93,11 +93,11 @@ RMAPCookie::~RMAPCookie() {
}
//uint32_t RMAPCookie::getMaxReplyLen() const {
// return maxReplyLen;
//}
//
void RMAPCookie::setMaxReplyLen(uint32_t maxReplyLen) {
size_t RMAPCookie::getMaxReplyLen() const {
return maxReplyLen;
}
void RMAPCookie::setMaxReplyLen(size_t maxReplyLen) {
this->maxReplyLen = maxReplyLen;
}

View File

@ -1,12 +1,13 @@
#ifndef RMAPCOOKIE_H_
#define RMAPCOOKIE_H_
#include <framework/devicehandlers/Cookie.h>
#include <framework/devicehandlers/CookieIF.h>
#include <framework/rmap/rmapStructs.h>
#include <cstddef>
class RMAPChannelIF;
class RMAPCookie : public Cookie {
class RMAPCookie : public CookieIF {
public:
//To Uli: Sorry, I need an empty ctor to initialize an array of cookies.
RMAPCookie();
@ -28,8 +29,8 @@ public:
void setCommandMask(uint8_t commandMask);
uint8_t getCommandMask();
//size_t getMaxReplyLen() const;
void setMaxReplyLen(uint32_t maxReplyLen);
size_t getMaxReplyLen() const;
void setMaxReplyLen(size_t maxReplyLen);
uint16_t getTransactionIdentifier() const;
void setTransactionIdentifier(uint16_t id_);

View File

@ -5,43 +5,43 @@
RmapDeviceCommunicationIF::~RmapDeviceCommunicationIF() {
}
ReturnValue_t RmapDeviceCommunicationIF::sendMessage(Cookie* cookie,
uint8_t* data, uint32_t len) {
return RMAP::sendWriteCommand((RMAPCookie *) cookie, data, len);
ReturnValue_t RmapDeviceCommunicationIF::sendMessage(CookieIF *cookie,
const uint8_t * sendData, size_t sendLen) {
return RMAP::sendWriteCommand((RMAPCookie *) cookie, sendData, sendLen);
}
ReturnValue_t RmapDeviceCommunicationIF::getSendSuccess(Cookie* cookie) {
ReturnValue_t RmapDeviceCommunicationIF::getSendSuccess(CookieIF* cookie) {
return RMAP::getWriteReply((RMAPCookie *) cookie);
}
ReturnValue_t RmapDeviceCommunicationIF::requestReceiveMessage(
Cookie* cookie) {
CookieIF *cookie, size_t requestLen) {
return RMAP::sendReadCommand((RMAPCookie *) cookie,
((RMAPCookie *) cookie)->getMaxReplyLen());
}
ReturnValue_t RmapDeviceCommunicationIF::readReceivedMessage(Cookie* cookie,
uint8_t** buffer, uint32_t* size) {
ReturnValue_t RmapDeviceCommunicationIF::readReceivedMessage(CookieIF* cookie,
uint8_t** buffer, size_t * size) {
return RMAP::getReadReply((RMAPCookie *) cookie, buffer, size);
}
ReturnValue_t RmapDeviceCommunicationIF::setAddress(Cookie* cookie,
ReturnValue_t RmapDeviceCommunicationIF::setAddress(CookieIF* cookie,
uint32_t address) {
((RMAPCookie *) cookie)->setAddress(address);
return HasReturnvaluesIF::RETURN_OK;
}
uint32_t RmapDeviceCommunicationIF::getAddress(Cookie* cookie) {
uint32_t RmapDeviceCommunicationIF::getAddress(CookieIF* cookie) {
return ((RMAPCookie *) cookie)->getAddress();
}
ReturnValue_t RmapDeviceCommunicationIF::setParameter(Cookie* cookie,
ReturnValue_t RmapDeviceCommunicationIF::setParameter(CookieIF* cookie,
uint32_t parameter) {
//TODO Empty?
return HasReturnvaluesIF::RETURN_FAILED;
}
uint32_t RmapDeviceCommunicationIF::getParameter(Cookie* cookie) {
uint32_t RmapDeviceCommunicationIF::getParameter(CookieIF* cookie) {
return 0;
}

View File

@ -17,66 +17,73 @@ class RmapDeviceCommunicationIF: public DeviceCommunicationIF {
public:
virtual ~RmapDeviceCommunicationIF();
/**
* This method is mission specific as the open call will return a mission specific cookie
*
* @param cookie A cookie, can be mission specific subclass of RMAP Cookie
* @param address The address of the RMAP Cookie
* @param maxReplyLen Maximum length of expected reply
* @return
* @brief Device specific initialization, using the cookie.
* @details
* The cookie is already prepared in the factory. If the communication
* interface needs to be set up in some way and requires cookie information,
* this can be performed in this function, which is called on device handler
* initialization.
* @param cookie
* @return -@c RETURN_OK if initialization was successfull
* - Everything else triggers failure event with returnvalue as parameter 1
*/
virtual ReturnValue_t open(Cookie **cookie, uint32_t address,
uint32_t maxReplyLen) = 0;
virtual ReturnValue_t initializeInterface(CookieIF * cookie) = 0;
/**
* Use an existing cookie to open a connection to a new DeviceCommunication.
* The previous connection must not be closed.
* If the returnvalue is not RETURN_OK, the cookie is unchanged and
* can be used with the previous connection.
* Called by DHB in the SEND_WRITE doSendWrite().
* This function is used to send data to the physical device
* by implementing and calling related drivers or wrapper functions.
* @param cookie
* @param data
* @param len
* @return -@c RETURN_OK for successfull send
* - Everything else triggers failure event with returnvalue as parameter 1
*/
virtual ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t * sendData,
size_t sendLen);
/**
* Called by DHB in the GET_WRITE doGetWrite().
* Get send confirmation that the data in sendMessage() was sent successfully.
* @param cookie
* @return -@c RETURN_OK if data was sent successfull
* - Everything else triggers falure event with returnvalue as parameter 1
*/
virtual ReturnValue_t getSendSuccess(CookieIF *cookie);
/**
* Called by DHB in the SEND_WRITE doSendRead().
* It is assumed that it is always possible to request a reply
* from a device.
*
* @param cookie
* @param address
* @param maxReplyLen
* @return
* @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 reOpen(Cookie *cookie, uint32_t address,
uint32_t maxReplyLen) = 0;
virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen);
/**
* Closing call of connection and free memory of cookie.
* Mission dependent call
* Called by DHB in the GET_WRITE doGetRead().
* This function is used to receive data from the physical device
* by implementing and calling related drivers or wrapper functions.
* @param cookie
* @param data
* @param len
* @return @c RETURN_OK for successfull receive
* - Everything else triggers failure event with returnvalue as parameter 1
*/
virtual void close(Cookie *cookie) = 0;
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
size_t *size);
//SHOULDDO can data be const?
/**
*
*
* @param cookie Expects an RMAPCookie or derived from RMAPCookie Class
* @param data Data to be send
* @param len Length of the data to be send
* @return - Return codes of RMAP::sendWriteCommand()
*/
virtual ReturnValue_t sendMessage(Cookie *cookie, uint8_t *data,
uint32_t len);
virtual ReturnValue_t getSendSuccess(Cookie *cookie);
virtual ReturnValue_t requestReceiveMessage(Cookie *cookie);
virtual ReturnValue_t readReceivedMessage(Cookie *cookie, uint8_t **buffer,
uint32_t *size);
virtual ReturnValue_t setAddress(Cookie *cookie, uint32_t address);
virtual uint32_t getAddress(Cookie *cookie);
virtual ReturnValue_t setParameter(Cookie *cookie, uint32_t parameter);
virtual uint32_t getParameter(Cookie *cookie);
ReturnValue_t setAddress(CookieIF* cookie,
uint32_t address);
uint32_t getAddress(CookieIF* cookie);
ReturnValue_t setParameter(CookieIF* cookie,
uint32_t parameter);
uint32_t getParameter(CookieIF* cookie);
};
#endif /* MISSION_RMAP_RMAPDEVICECOMMUNICATIONINTERFACE_H_ */