34#include <NDEVR/BaseValues.h>
35#include <NDEVR/String.h>
36#include <NDEVR/Dictionary.h>
37#include <NDEVR/RWLock.h>
38#include <NDEVR/Time.h>
39#include <NDEVR/TimeSpan.h>
40#include <NDEVR/Thread.h>
41#include <NDEVR/JSONNode.h>
42#include <NDEVR/InfoPipe.h>
43#include <NDEVR/LogMessage.h>
44#include <NDEVR/Exception.h>
80 template<
class t_type>
315 bool finished =
false;
447 for (
uint04 i = 0; i < Constant<uint04>::Invalid; i++)
451 if (display.size() == 0)
462 const JSONNode& node = root[display];
463 if (node.
hasNode(
"Attempt Count"))
465 if (node.
hasNode(
"Failure Count"))
467 if (node.
hasNode(
"Total Response Time"))
469 if (allow_command_override)
475 if (node.
hasNode(
"Validation Regex"))
477 if (node.
hasNode(
"Default Args"))
479 if (node.
hasNode(
"Transmission Delay"))
481 if (node.
hasNode(
"Receive Delay"))
483 if (node.
hasNode(
"Response Timeout"))
501 for (
uint04 i = 0; i < Constant<uint04>::Invalid; i++)
506 if (display.size() == 0)
516 node[
"Command"] = info.
command;
525 node[
"Average Response Time"] = 0;
527 node[
"Transmission Delay"] = info.
tx_delay;
528 node[
"Receive Delay"] = info.
rx_delay;
543 root +=
"Command" + del;
545 root +=
"Supported" + del;
546 root +=
"Attempt Count" + del;
547 root +=
"Failure Count" + del;
548 root +=
"Total Response Time" + del;
549 root +=
"Average Response Time" + del;
550 if (include_identity_info)
552 root +=
"Default Args" + del;
553 root +=
"Transmission Delay" + del;
554 root +=
"Receive Delay" + del;
555 root +=
"Response Timeout" + del;
556 root +=
"Validation Regex" + del;
558 for (
uint04 i = 0; i < Constant<uint04>::Invalid; i++)
564 if (display.size() == 0)
573 root += display + del;
583 if (include_identity_info)
The equivelent of std::vector but with a bit more control.
A hash-based key-value store, useful for quick associative lookups.
Provides consistent interface to handle errors through the throw expression.
A base class for communicating with Hardware, typically firmware by the software.
static const uint04 s_buffer_size
The default buffer size for command data.
void removeCommand(t_type command)
Removes all instances of the given command from the queue.
void setSupport(t_type command, CommandSupport support)
Sets the support status for a command.
void postCommand(t_type command, const StringView &args=StringView(), const StringView ®ex=StringView())
Posts a command to the end of the queue.
virtual void cancelCommand()
Cancels the currently executing command and records its statistics.
void addCommandToFront(t_type command, const String &args=String(), const String ®ex=String())
Adds a command to the front of the queue so it executes next.
Time m_current_command_start_time
When the current command began executing.
JSONNode getCommandJSONInfo(bool only_supported) const
Serializes all command information to a JSON tree.
CommandQueueItem m_pending_block_command
A blocking command waiting to be executed with priority.
Dictionary< t_type, uint04 > m_pending_commands
Map of pending command types to their count in the queue.
Dictionary< t_type, CommandInformation > m_command_info
Map of command types to their configuration and statistics.
bool popCommandAndExecute()
Pops the next command from the queue and executes it.
void setBufferOffset(uint04 buffer_offset)
Sets the buffer offset for data reads.
void disableCommand(t_type command)
Disables a command, removing it from the queue and marking it as unsupported.
TimeSpan rxDelay() const
Returns the receive delay for the currently executing command.
virtual void onFailure(const t_type &command)
Called when a command fails.
uint04 bufferOffset() const
Returns the current buffer offset for data reads.
t_type currentCommand() const
Returns the currently executing command type.
virtual bool allowMultipleCommandsInStream(t_type command, const StringView &args) const
Returns whether multiple instances of the same command are allowed in the queue.
void setSupported(t_type command, bool supported)
Sets whether a command is supported or not.
CommandInformation commandInformation(t_type command)
Returns the stored statistics and configuration for the given command.
Buffer< CommandRecord > m_records
Historical records of executed commands.
void executeCommandBlocking(const t_type &command, const StringView &args=StringView())
Posts a command and blocks until it has been executed and completed.
String getCommandCSVInfo(bool only_supported, bool include_identity_info, char deliminator=',') const
Serializes all command information to a CSV-formatted string.
Buffer< CommandQueueItem > m_ordered_commands
The ordered list of commands waiting to be executed.
void clearCommands()
Removes all pending and blocking commands from the queue.
TimeSpan txDelay() const
Returns the transmission delay for the currently executing command.
bool hasPendingCommand(t_type command) const
Checks whether a specific command is pending in the queue.
virtual void executeCommand(const t_type &command, const StringView &args)=0
Executes a command with the given arguments.
bool hasPending() const
Returns whether there are any pending or currently executing commands.
CommandQueueItem m_current_command
The command currently being executed.
uint04 m_buffer_offset
The current offset into the data buffer.
virtual void retryCommand()
Cancels the current command and re-adds it to the front of the queue for retry.
TimeSpan commandTimeout() const
Returns the response timeout for the currently executing command.
virtual void endCommandQueue()
Called when the command queue is shutting down.
const String & currentRegex() const
Returns the validation regex for the currently executing command.
const String & currentArgs() const
Returns the arguments for the currently executing command.
virtual bool supportsCommand(t_type command) const
Checks whether the hardware supports the given command.
void setFromJSONInfo(const JSONNode &root, bool allow_command_override, LogPtr log)
Loads command configuration and statistics from a JSON tree.
void finishCommand()
Marks the current command as finished and records its execution statistics.
JavaScript Object Notation or JSON is an open - standard file format that uses human - readable text ...
decltype(auto) getAs() const
bool hasNode(const StringView &child_node) const
Checks whether a child node with the given name exists.
@ e_error
Error indicating a failure in an operation.
A light-weight wrapper that will be a no-op if there is not a valid log reference,...
Used to lock a particular variable for reading.
Logic for reading or writing to a string or a user friendly, TranslatedString.
The core String View class for the NDEVR API.
The core String class for the NDEVR API.
static TranslatedString DisplayString(const t_type &value)
Converts an object into a TranslatedString.
static void RequestSleep(const TimeSpan &interval)
Puts the current thread to sleep for a specified duration.
Stores a time span, or difference between two times, with an optional start time.
constexpr fltp08 elapsedSeconds() const
Returns the elapsed duration in seconds.
Represents a timestamp with utilities for manipulation and conversion.
static Time SystemTime()
Retrieves the current system time which is a combination of std::chrono::steady_clock to ensure smoot...
String englishTranslation() const
Returns the English translation of this string.
Used to lock a particular variable for writing.
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
static constexpr bool IsValid(const Angle< t_type > &value)
Checks whether the given Angle holds a valid value.
CommandSupport
Describes whether a HardwareCommandQueue supports certain commands.
@ e_supported
The command is supported by the hardware.
@ e_not_known
Whether the command is supported has not yet been determined.
@ e_not_supported
The command is not supported by the hardware.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
An item in the command queue containing the command, arguments, and validation regex.
void clear()
Resets this item to its default empty state.
String regex
A regex pattern for validating the command response.
String args
The arguments for the command.
t_type command
The command to execute.
A record of a command execution with timing information.
t_type command
The command that was executed.
Time start_time
When the command began executing.
Time end_time
When the command finished executing.