Skip to content

Commit

Permalink
Merge pull request #379 from jsouter/fr-commands
Browse files Browse the repository at this point in the history
Implement command API in FrameReceiver
  • Loading branch information
GDYendell authored Feb 6, 2025
2 parents e9d757a + b726af5 commit cfbce93
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 9 deletions.
18 changes: 9 additions & 9 deletions cpp/frameProcessor/src/FrameProcessorPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ std::vector<std::string> FrameProcessorPlugin::get_warnings()

/** Configure the plugin.
*
* In this abstract class the configure method does perform any
* In this abstract class the configure method doesn't perform any
* actions, this should be overridden by subclasses.
*
* \param[in] config - IpcMessage containing configuration data.
Expand All @@ -158,7 +158,7 @@ void FrameProcessorPlugin::configure(OdinData::IpcMessage& config, OdinData::Ipc

/** Request the plugin's current configuration.
*
* In this abstract class the request method does perform any
* In this abstract class the request method doesn't perform any
* actions, this should be overridden by subclasses.
*
* \param[out] reply - Response IpcMessage with current configuration.
Expand All @@ -170,7 +170,7 @@ void FrameProcessorPlugin::requestConfiguration(OdinData::IpcMessage& reply)

/** Execute a command within the plugin.
*
* In this abstract class the command method does perform any
* In this abstract class the command method doesn't perform any
* actions, this should be overridden by subclasses.
*
* \param[in] command - String containing the command to execute.
Expand All @@ -180,15 +180,15 @@ void FrameProcessorPlugin::execute(const std::string& command, OdinData::IpcMess
{
// A command has been submitted and this plugin has no execute implementation defined,
// throw a runtime error to report this.
std::stringstream is;
is << "Submitted command not supported: " << command;
LOG4CXX_ERROR(logger_, is.str());
throw std::runtime_error(is.str().c_str());
std::stringstream ss;
ss << "Submitted command not supported: " << command;
LOG4CXX_ERROR(logger_, ss.str());
reply.set_nack(ss.str());
}

/** Request the plugin's supported commands.
*
* In this abstract class the request method does perform any
* In this abstract class the request method doesn't perform any
* actions, this should be overridden by subclasses.
*
* \return - Vector containing supported command strings.
Expand All @@ -204,7 +204,7 @@ std::vector<std::string> FrameProcessorPlugin::requestCommands()
* Collate status information for the plugin.
*
* The status is added to the status IpcMessage object.
* In this abstract class the status method does perform any
* In this abstract class the status method doesn't perform any
* actions, this should be overridden by subclasses.
*
* \param[out] status - Reference to an IpcMessage value to store the status.
Expand Down
2 changes: 2 additions & 0 deletions cpp/frameReceiver/include/FrameDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class FrameDecoder : public OdinData::IVersionedObject
virtual void init(OdinData::IpcMessage& config_msg);
virtual void request_configuration(const std::string param_prefix,
OdinData::IpcMessage& config_reply);
virtual std::vector<std::string> request_commands();
virtual void execute(const std::string& command, OdinData::IpcMessage& reply);
virtual const size_t get_frame_buffer_size(void) const = 0;
virtual const size_t get_frame_header_size(void) const = 0;

Expand Down
2 changes: 2 additions & 0 deletions cpp/frameReceiver/include/FrameReceiverController.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ namespace FrameReceiver
void get_version(OdinData::IpcMessage& version_reply);
void reset_statistics(OdinData::IpcMessage& reset_reply);
void request_configuration(OdinData::IpcMessage& config_reply);
void request_commands(OdinData::IpcMessage& command_reply);
void execute(OdinData::IpcMessage& config, OdinData::IpcMessage& reply);

#ifdef FR_CONTROLLER_TICK_TIMER
void tick_timer(void);
Expand Down
32 changes: 32 additions & 0 deletions cpp/frameReceiver/src/FrameDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,38 @@ void FrameDecoder::request_configuration(const std::string param_prefix,
config_reply.set_param(param_prefix + CONFIG_DECODER_FRAME_TIMEOUT_MS, frame_timeout_ms_);
}

/** Request the decoder's supported commands.
*
* In this abstract class the request method doesn't perform any
* actions, this should be overridden by subclasses.
*
* \return - Vector containing supported command strings.
*/
std::vector<std::string> FrameDecoder::request_commands()
{
// Default returns an empty vector.
std::vector<std::string> reply;
return reply;
}

/** Execute a command within the decoder.
*
* In this abstract class the command method doesn't perform any
* actions, this should be overridden by subclasses.
*
* \param[in] command - String containing the command to execute.
* \param[out] reply - Response IpcMessage.
*/
void FrameDecoder::execute(const std::string& command, OdinData::IpcMessage& reply)
{
// A command has been submitted and this decoder has no execute implementation defined,
// throw a runtime error to report this.
std::stringstream ss;
ss << "Submitted command not supported: " << command;
LOG4CXX_ERROR(logger_, ss.str());
reply.set_nack(ss.str());
}

//! Register a buffer manager with the decoder.
//!
//! This method registers a SharedBufferManager instance with the decoder, to be used when
Expand Down
61 changes: 61 additions & 0 deletions cpp/frameReceiver/src/FrameReceiverController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,12 @@ void FrameReceiverController::handle_ctrl_channel(void)
this->request_configuration(ctrl_reply);
break;

case IpcMessage::MsgValCmdRequestCommands:
LOG4CXX_DEBUG_LEVEL(3, logger_,
"Got control channel read commands request from client " << client_identity);
this->request_commands(ctrl_reply);
break;

case IpcMessage::MsgValCmdStatus:
LOG4CXX_DEBUG_LEVEL(3, logger_,
"Got control channel status request from client " << client_identity);
Expand All @@ -845,6 +851,13 @@ void FrameReceiverController::handle_ctrl_channel(void)
ctrl_reply.set_msg_type(IpcMessage::MsgTypeAck);
break;

case IpcMessage::MsgValCmdExecute:
ctrl_reply.set_msg_type(OdinData::IpcMessage::MsgTypeAck);
this->execute(ctrl_req, ctrl_reply);
LOG4CXX_DEBUG_LEVEL(3, logger_, "Control thread reply message (command): "
<< ctrl_reply.encode());
break;

default:
request_ok = false;
error_ss << "Illegal command request value: " << req_val;
Expand Down Expand Up @@ -1205,6 +1218,54 @@ void FrameReceiverController::request_configuration(OdinData::IpcMessage& config

}

/**
* Submit commands to the FrameReceiver
*
* Submits command(s) to execute on the frame decoder if it
* support commands. The IpcMessage should contain the command
* name and a structure of any parameters required by the command.
*
* \param[in] config - IpcMessage containing command and any parameter data.
* \param[out] reply - Response IpcMessage.
*/
void FrameReceiverController::execute(OdinData::IpcMessage& config, OdinData::IpcMessage& reply)
{
LOG4CXX_DEBUG_LEVEL(1, logger_, "Command submitted: " << config.encode());

// Check for decoder commands
bool command_present = false;
if (config.has_param("decoder")) {
OdinData::IpcMessage sub_config(config.get_param<const rapidjson::Value&>("decoder"),
config.get_msg_type(),
config.get_msg_val());
if (sub_config.has_param("command")){
command_present = true;
// Extract the command and execute on the decoder
std::string command_name = sub_config.get_param<std::string>("command");
frame_decoder_->execute(command_name, reply);
}
}
if (!command_present){
// If no valid commands have been found then NACK the reply
reply.set_nack("No valid commands found");
}
}

/**
* Request the command set supported by this FrameReceiver
*
* \param[out] reply - Response IpcMessage with the current supported command set.
*/
void FrameReceiverController::request_commands(OdinData::IpcMessage& reply)
{
LOG4CXX_DEBUG_LEVEL(3, logger_, "Request for supported commands made");
std::vector<std::string>::iterator cmd;
std::vector<std::string> decoder_commands = frame_decoder_->request_commands();
for (cmd = decoder_commands.begin(); cmd != decoder_commands.end(); ++cmd) {
reply.set_param("decoder/supported[]", *cmd);
}
}

//! Reset the frame receiver statistics.
//!
//! This method resets the frame receiver statistics present in status responses.
Expand Down

0 comments on commit cfbce93

Please sign in to comment.