Cookie -> CookieIF, DHB changes

According to changes agreed on 01.04.2020,
slight refactoring of DHB:
requestLen is set to 0 if no respective reply is enabled
This commit is contained in:
Robin Müller 2020-04-01 12:43:53 +02:00
parent ac4275ef05
commit 511c0db8c7
6 changed files with 75 additions and 116 deletions

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,10 +0,0 @@
#ifndef COOKIE_H_
#define COOKIE_H_
class Cookie{
public:
virtual ~Cookie(){}
};
#endif /* COOKIE_H_ */

View File

@ -1,25 +1,33 @@
/**
* @file CookieIF.h
*
* @date 23.03.2020
*/
#ifndef FRAMEWORK_DEVICEHANDLERS_COOKIEIF_H_
#define FRAMEWORK_DEVICEHANDLERS_COOKIEIF_H_
#include <framework/devicehandlers/DeviceHandlerIF.h>
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>
/**
@ -10,7 +10,7 @@
*/
/**
* @defgroup communication comm
* @defgroup comm Communication
* @brief Communication software components.
*/
@ -18,7 +18,7 @@
* @brief This is an interface to decouple device communication from
* the device handler to allow reuse of these components.
* @details
* Documentation: Dissertation Baetz p.138
* Documentation: Dissertation Baetz p.138.
* It works with the assumption that received data
* is polled by a component. There are four generic steps of device communication:
*
@ -38,11 +38,16 @@ class DeviceCommunicationIF: public HasReturnvaluesIF {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_COMMUNICATION_IF;
static const ReturnValue_t INVALID_COOKIE_TYPE = MAKE_RETURN_CODE(0x01);
static const ReturnValue_t NOT_ACTIVE = MAKE_RETURN_CODE(0x02);
static const ReturnValue_t TOO_MUCH_DATA = MAKE_RETURN_CODE(0x03);
static const ReturnValue_t NULLPOINTER = MAKE_RETURN_CODE(0x04);
static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0x05);
//!< This is used if no read request is to be made by the device handler.
static const ReturnValue_t NO_READ_REQUEST = MAKE_RETURN_CODE(0x01);
//! General protocol error. Define more concrete errors in child handler
static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0x02);
//! If cookie is a null pointer
static const ReturnValue_t NULLPOINTER = MAKE_RETURN_CODE(0x03);
static const ReturnValue_t INVALID_COOKIE_TYPE = MAKE_RETURN_CODE(0x04);
// is this needed if there is no open/close call?
static const ReturnValue_t NOT_ACTIVE = MAKE_RETURN_CODE(0x05);
static const ReturnValue_t TOO_MUCH_DATA = MAKE_RETURN_CODE(0x06);
virtual ~DeviceCommunicationIF() {}
@ -54,7 +59,8 @@ public:
* this can be performed in this function, which is called on device handler
* initialization.
* @param cookie
* @return
* @return -@c RETURN_OK if initialization was successfull
* - Everything else triggers failure event with returnvalue as parameter 1
*/
virtual ReturnValue_t initializeInterface(CookieIF * cookie) = 0;
@ -66,8 +72,7 @@ public:
* @param data
* @param len
* @return -@c RETURN_OK for successfull send
* - Everything else triggers sending failed event with
* returnvalue as parameter 1
* - Everything else triggers failure event with returnvalue as parameter 1
*/
virtual ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t * sendData,
size_t sendLen) = 0;
@ -77,16 +82,21 @@ public:
* 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 sending failed event with
* returnvalue as parameter 1
* - Everything else triggers falure event with returnvalue as parameter 1
*/
virtual ReturnValue_t getSendSuccess(CookieIF *cookie) = 0;
/**
* 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
* @return
* @param requestLen Size of data to read
* @return -@c RETURN_OK to confirm the request for data has been sent.
* - Everything else triggers failure event with returnvalue as parameter 1
*/
virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) = 0;
@ -98,8 +108,7 @@ public:
* @param data
* @param len
* @return @c RETURN_OK for successfull receive
* - Everything else triggers receiving failed with
* returnvalue as parameter 1
* - Everything else triggers failure event with returnvalue as parameter 1
*/
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
size_t *size) = 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.
*