DH IF and DH message form improved

This commit is contained in:
Robin Müller 2020-10-01 11:01:52 +02:00
parent cdadf48f38
commit adf528fce9
3 changed files with 48 additions and 69 deletions

View File

@ -1,12 +1,19 @@
#ifndef DEVICEHANDLERIF_H_ #ifndef FSFW_DEVICEHANDLERS_DEVICEHANDLERIF_H_
#define DEVICEHANDLERIF_H_ #define FSFW_DEVICEHANDLERS_DEVICEHANDLERIF_H_
#include "DeviceHandlerMessage.h"
#include "../action/HasActionsIF.h" #include "../action/HasActionsIF.h"
#include "DeviceHandlerMessage.h"
#include "../events/Event.h" #include "../events/Event.h"
#include "../modes/HasModesIF.h" #include "../modes/HasModesIF.h"
#include "../ipc/MessageQueueSenderIF.h" #include "../ipc/MessageQueueSenderIF.h"
/**
* This is used to uniquely identify commands that are sent to a device
* The values are defined in the device-specific implementations
*/
using DeviceCommandId_t = uint32_t;
/** /**
* @brief This is the Interface used to communicate with a device handler. * @brief This is the Interface used to communicate with a device handler.
* @details Includes all expected return values, events and modes. * @details Includes all expected return values, events and modes.
@ -15,6 +22,7 @@
class DeviceHandlerIF { class DeviceHandlerIF {
public: public:
static const uint8_t TRANSITION_MODE_CHILD_ACTION_MASK = 0x20; static const uint8_t TRANSITION_MODE_CHILD_ACTION_MASK = 0x20;
static const uint8_t TRANSITION_MODE_BASE_ACTION_MASK = 0x10; static const uint8_t TRANSITION_MODE_BASE_ACTION_MASK = 0x10;
@ -47,6 +55,8 @@ public:
//! This is a transitional state which can not be commanded. //! This is a transitional state which can not be commanded.
//! The device handler performs all actions and commands to get the device //! The device handler performs all actions and commands to get the device
//! shut down. When the device is off, the mode changes to @c MODE_OFF. //! shut down. When the device is off, the mode changes to @c MODE_OFF.
//! It is possible to set the mode to _MODE_SHUT_DOWN to use the to off
//! transition if available.
static const Mode_t _MODE_SHUT_DOWN = TRANSITION_MODE_CHILD_ACTION_MASK | 6; static const Mode_t _MODE_SHUT_DOWN = TRANSITION_MODE_CHILD_ACTION_MASK | 6;
//! It is possible to set the mode to _MODE_TO_ON to use the to on //! It is possible to set the mode to _MODE_TO_ON to use the to on
//! transition if available. //! transition if available.
@ -96,7 +106,7 @@ public:
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_IF; static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_IF;
// Standard codes used when building commands. // Standard codes used when building commands.
static const ReturnValue_t NO_COMMAND_DATA = MAKE_RETURN_CODE(0xA0); //!< If the command size is 0. Checked in DHB static const ReturnValue_t NO_COMMAND_DATA = MAKE_RETURN_CODE(0xA0); //!< If no command data was given when expected.
static const ReturnValue_t COMMAND_NOT_SUPPORTED = MAKE_RETURN_CODE(0xA1); //!< Command ID not in commandMap. Checked in DHB static const ReturnValue_t COMMAND_NOT_SUPPORTED = MAKE_RETURN_CODE(0xA1); //!< Command ID not in commandMap. Checked in DHB
static const ReturnValue_t COMMAND_ALREADY_SENT = MAKE_RETURN_CODE(0xA2); //!< Command was already executed. Checked in DHB static const ReturnValue_t COMMAND_ALREADY_SENT = MAKE_RETURN_CODE(0xA2); //!< Command was already executed. Checked in DHB
static const ReturnValue_t COMMAND_WAS_NOT_SENT = MAKE_RETURN_CODE(0xA3); static const ReturnValue_t COMMAND_WAS_NOT_SENT = MAKE_RETURN_CODE(0xA3);
@ -150,4 +160,4 @@ public:
}; };
#endif /* DEVICEHANDLERIF_H_ */ #endif /* FSFW_DEVICEHANDLERS_DEVICEHANDLERIF_H_ */

View File

@ -1,10 +1,6 @@
#include "../objectmanager/ObjectManagerIF.h"
#include "DeviceHandlerMessage.h" #include "DeviceHandlerMessage.h"
#include "../objectmanager/ObjectManagerIF.h" #include "../objectmanager/ObjectManagerIF.h"
DeviceHandlerMessage::DeviceHandlerMessage() {
}
store_address_t DeviceHandlerMessage::getStoreAddress( store_address_t DeviceHandlerMessage::getStoreAddress(
const CommandMessage* message) { const CommandMessage* message) {
return store_address_t(message->getParameter2()); return store_address_t(message->getParameter2());
@ -25,14 +21,6 @@ uint8_t DeviceHandlerMessage::getWiretappingMode(
return message->getParameter(); return message->getParameter();
} }
//void DeviceHandlerMessage::setDeviceHandlerDirectCommandMessage(
// CommandMessage* message, DeviceCommandId_t deviceCommand,
// store_address_t commandParametersStoreId) {
// message->setCommand(CMD_DIRECT);
// message->setParameter(deviceCommand);
// message->setParameter2(commandParametersStoreId.raw);
//}
void DeviceHandlerMessage::setDeviceHandlerRawCommandMessage( void DeviceHandlerMessage::setDeviceHandlerRawCommandMessage(
CommandMessage* message, store_address_t rawPacketStoreId) { CommandMessage* message, store_address_t rawPacketStoreId) {
message->setCommand(CMD_RAW); message->setCommand(CMD_RAW);
@ -47,7 +35,7 @@ void DeviceHandlerMessage::setDeviceHandlerWiretappingMessage(
void DeviceHandlerMessage::setDeviceHandlerSwitchIoBoardMessage( void DeviceHandlerMessage::setDeviceHandlerSwitchIoBoardMessage(
CommandMessage* message, uint32_t ioBoardIdentifier) { CommandMessage* message, uint32_t ioBoardIdentifier) {
message->setCommand(CMD_SWITCH_IOBOARD); message->setCommand(CMD_SWITCH_ADDRESS);
message->setParameter(ioBoardIdentifier); message->setParameter(ioBoardIdentifier);
} }
@ -79,18 +67,17 @@ void DeviceHandlerMessage::setDeviceHandlerDirectCommandReply(
void DeviceHandlerMessage::clear(CommandMessage* message) { void DeviceHandlerMessage::clear(CommandMessage* message) {
switch (message->getCommand()) { switch (message->getCommand()) {
case CMD_RAW: case CMD_RAW:
// case CMD_DIRECT:
case REPLY_RAW_COMMAND: case REPLY_RAW_COMMAND:
case REPLY_RAW_REPLY: case REPLY_RAW_REPLY:
case REPLY_DIRECT_COMMAND_DATA: { case REPLY_DIRECT_COMMAND_DATA: {
StorageManagerIF *ipcStore = objectManager->get<StorageManagerIF>( StorageManagerIF *ipcStore = objectManager->get<StorageManagerIF>(
objects::IPC_STORE); objects::IPC_STORE);
if (ipcStore != NULL) { if (ipcStore != nullptr) {
ipcStore->deleteData(getStoreAddress(message)); ipcStore->deleteData(getStoreAddress(message));
} }
} }
/* NO BREAK falls through*/ /* NO BREAK falls through*/
case CMD_SWITCH_IOBOARD: case CMD_SWITCH_ADDRESS:
case CMD_WIRETAPPING: case CMD_WIRETAPPING:
message->setCommand(CommandMessage::CMD_NONE); message->setCommand(CommandMessage::CMD_NONE);
message->setParameter(0); message->setParameter(0);

View File

@ -1,69 +1,56 @@
#ifndef DEVICEHANDLERMESSAGE_H_ #ifndef FSFW_DEVICEHANDLERS_DEVICEHANDLERMESSAGE_H_
#define DEVICEHANDLERMESSAGE_H_ #define FSFW_DEVICEHANDLERS_DEVICEHANDLERMESSAGE_H_
#include "../action/ActionMessage.h" #include "../action/ActionMessage.h"
#include "../ipc/CommandMessage.h" #include "../ipc/CommandMessage.h"
#include "../objectmanager/SystemObjectIF.h" #include "../objectmanager/SystemObjectIF.h"
#include "../storagemanager/StorageManagerIF.h" #include "../storagemanager/StorageManagerIF.h"
//SHOULDDO: rework the static constructors to name the type of command they are building, maybe even hide setting the commandID. // SHOULDDO: rework the static constructors to name the type of command
// they are building, maybe even hide setting the commandID.
/** /**
* This is used to uniquely identify commands that are sent to a device * @brief The DeviceHandlerMessage is used to send commands to classes
* * implementing DeviceHandlerIF
* The values are defined in the device-specific implementations
*/
typedef uint32_t DeviceCommandId_t;
/**
* The DeviceHandlerMessage is used to send Commands to a DeviceHandlerIF
*/ */
class DeviceHandlerMessage { class DeviceHandlerMessage {
private:
DeviceHandlerMessage();
public: public:
/**
* Instantiation forbidden. Instead, use static functions to operate
* on messages.
*/
DeviceHandlerMessage() = delete;
virtual ~DeviceHandlerMessage() {}
/** /**
* These are the commands that can be sent to a DeviceHandlerBase * These are the commands that can be sent to a DeviceHandlerBase
*/ */
static const uint8_t MESSAGE_ID = messagetypes::DEVICE_HANDLER_COMMAND; static const uint8_t MESSAGE_ID = messagetypes::DEVICE_HANDLER_COMMAND;
static const Command_t CMD_RAW = MAKE_COMMAND_ID( 1 ); //!< Sends a raw command, setParameter is a ::store_id_t containing the raw packet to send //! Sends a raw command, setParameter is a storeId containing the
// static const Command_t CMD_DIRECT = MAKE_COMMAND_ID( 2 ); //!< Sends a direct command, setParameter is a ::DeviceCommandId_t, setParameter2 is a ::store_id_t containing the data needed for the command //! raw packet to send
static const Command_t CMD_SWITCH_IOBOARD = MAKE_COMMAND_ID( 3 ); //!< Requests a IO-Board switch, setParameter() is the IO-Board identifier static const Command_t CMD_RAW = MAKE_COMMAND_ID(1);
static const Command_t CMD_WIRETAPPING = MAKE_COMMAND_ID( 4 ); //!< (De)Activates the monitoring of all raw traffic in DeviceHandlers, setParameter is 0 to deactivate, 1 to activate //! Requests a IO-Board switch, setParameter() is the IO-Board identifier
static const Command_t CMD_SWITCH_ADDRESS = MAKE_COMMAND_ID(3);
//! (De)Activates the monitoring of all raw traffic in DeviceHandlers,
//! setParameter is 0 to deactivate, 1 to activate
static const Command_t CMD_WIRETAPPING = MAKE_COMMAND_ID(4);
/*static const Command_t REPLY_SWITCHED_IOBOARD = MAKE_COMMAND_ID(1 );//!< Reply to a @c CMD_SWITCH_IOBOARD, indicates switch was successful, getParameter() contains the board switched to (0: nominal, 1: redundant) //! Signals that a direct command was sent
static const Command_t REPLY_CANT_SWITCH_IOBOARD = MAKE_COMMAND_ID( 2); //!< Reply to a @c CMD_SWITCH_IOBOARD, indicating the switch could not be performed, getParameter() contains the error message static const Command_t REPLY_DIRECT_COMMAND_SENT = ActionMessage::STEP_SUCCESS;
static const Command_t REPLY_WIRETAPPING = MAKE_COMMAND_ID( 3); //!< Reply to a @c CMD_WIRETAPPING, getParameter() is the current state, 1 enabled, 0 disabled //! Contains a raw command sent to the Device
static const Command_t REPLY_RAW_COMMAND = MAKE_COMMAND_ID(0x11);
static const Command_t REPLY_COMMAND_WAS_SENT = MAKE_COMMAND_ID(4 );//!< Reply to a @c CMD_RAW or @c CMD_DIRECT, indicates the command was successfully sent to the device, getParameter() contains the ::DeviceCommandId_t //! Contains a raw reply from the Device, getParameter() is the ObjcetId
static const Command_t REPLY_COMMAND_NOT_SUPPORTED = MAKE_COMMAND_ID(5 );//!< Reply to a @c CMD_DIRECT, the requested ::DeviceCommand_t is not supported, getParameter() contains the requested ::DeviceCommand_t, getParameter2() contains the ::DeviceCommandId_t //! of the sender, getParameter2() is a ::store_id_t containing the
static const Command_t REPLY_COMMAND_WAS_NOT_SENT = MAKE_COMMAND_ID(6 );//!< Reply to a @c CMD_RAW or @c CMD_DIRECT, indicates the command was not sent, getParameter contains the RMAP Return code (@see rmap.h), getParameter2() contains the ::DeviceCommandId_t //! raw packet received
static const Command_t REPLY_RAW_REPLY = MAKE_COMMAND_ID(0x12);
static const Command_t REPLY_COMMAND_ALREADY_SENT = MAKE_COMMAND_ID(7 );//!< Reply to a @c CMD_DIRECT, the requested ::DeviceCommand_t has already been sent to the device and not ye been answered
static const Command_t REPLY_WRONG_MODE_FOR_CMD = MAKE_COMMAND_ID(8 );//!< Reply to a @c CMD_RAW or @c CMD_DIRECT, indicates that the requested command can not be sent in the curent mode, getParameter() contains the DeviceHandlerCommand_t
static const Command_t REPLY_NO_DATA = MAKE_COMMAND_ID(9 ); //!< Reply to a CMD_RAW or @c CMD_DIRECT, indicates that the ::store_id_t was invalid, getParameter() contains the ::DeviceCommandId_t, getPrameter2() contains the error code
*/
static const Command_t REPLY_DIRECT_COMMAND_SENT = ActionMessage::STEP_SUCCESS; //!< Signals that a direct command was sent
static const Command_t REPLY_RAW_COMMAND = MAKE_COMMAND_ID(0x11 ); //!< Contains a raw command sent to the Device
static const Command_t REPLY_RAW_REPLY = MAKE_COMMAND_ID( 0x12); //!< Contains a raw reply from the Device, getParameter() is the ObjcetId of the sender, getParameter2() is a ::store_id_t containing the raw packet received
static const Command_t REPLY_DIRECT_COMMAND_DATA = ActionMessage::DATA_REPLY; static const Command_t REPLY_DIRECT_COMMAND_DATA = ActionMessage::DATA_REPLY;
/**
* Default Destructor
*/
virtual ~DeviceHandlerMessage() {
}
static store_address_t getStoreAddress(const CommandMessage* message); static store_address_t getStoreAddress(const CommandMessage* message);
static uint32_t getDeviceCommandId(const CommandMessage* message); static uint32_t getDeviceCommandId(const CommandMessage* message);
static object_id_t getDeviceObjectId(const CommandMessage *message); static object_id_t getDeviceObjectId(const CommandMessage *message);
static object_id_t getIoBoardObjectId(const CommandMessage* message); static object_id_t getIoBoardObjectId(const CommandMessage* message);
static uint8_t getWiretappingMode(const CommandMessage* message); static uint8_t getWiretappingMode(const CommandMessage* message);
// static void setDeviceHandlerDirectCommandMessage(CommandMessage* message,
// DeviceCommandId_t deviceCommand,
// store_address_t commandParametersStoreId);
static void setDeviceHandlerDirectCommandReply(CommandMessage* message, static void setDeviceHandlerDirectCommandReply(CommandMessage* message,
object_id_t deviceObjectid, object_id_t deviceObjectid,
store_address_t commandParametersStoreId); store_address_t commandParametersStoreId);
@ -75,11 +62,6 @@ public:
object_id_t deviceObjectid, store_address_t rawPacketStoreId, object_id_t deviceObjectid, store_address_t rawPacketStoreId,
bool isCommand); bool isCommand);
// static void setDeviceHandlerMessage(CommandMessage* message,
// Command_t command, DeviceCommandId_t deviceCommand,
// store_address_t commandParametersStoreId);
// static void setDeviceHandlerMessage(CommandMessage* message,
// Command_t command, store_address_t rawPacketStoreId);
static void setDeviceHandlerWiretappingMessage(CommandMessage* message, static void setDeviceHandlerWiretappingMessage(CommandMessage* message,
uint8_t wiretappingMode); uint8_t wiretappingMode);
static void setDeviceHandlerSwitchIoBoardMessage(CommandMessage* message, static void setDeviceHandlerSwitchIoBoardMessage(CommandMessage* message,
@ -88,4 +70,4 @@ public:
static void clear(CommandMessage* message); static void clear(CommandMessage* message);
}; };
#endif /* DEVICEHANDLERMESSAGE_H_ */ #endif /* FSFW_DEVICEHANDLERS_DEVICEHANDLERMESSAGE_H_ */