Skip to content

Commander API Public methods.

CreativeRobotics edited this page Jan 26, 2020 · 8 revisions

Constructor and update

Commander();

Commander(uint16_t reservedBuffer)

Constructors. An optional argument can be used to reserve memory for the buffer.

void begin(Stream *sPort)

void begin(Stream *sPort, const commandList_t *commands, uint32_t size)

void begin(Stream *sPort, Stream *oPort, const commandList_t *commands, uint32_t size)

Initialise Commander with a Stream object for the input and output ports. Commander also needs a command list and a size variable before it can work. Optionally Commander can be initialised with a different output port (oPort). Any data printed using the commanders print and write functions will use this port.

bool update()

Update the Commander object. Commander will copu any new bytes from the inport to its buffer and try and handle a command if an end of line character is found.

Returns true if there are more bytes available in the stream.

Locking mechanism:

Commander can be locked and unlocked. If a passphrase is set then it must be used to unlock the command system. There are two lock levels, soft or hard. A soft lock allows internal commands to be used and will print help data. A hard lock prevents all internal commands except the unlock command.

void setPassPhrase(String& phrase)

Set a String containing the passphrase for the locking system. The passphrase String is passed as a reference and so it is not stored inside Commander.

void printPassPhrase()

Prints the passphrase to the output port

void lock()

Locks the command system.

void unlock()

Unlocks the command system.

void setLockType(bool hlState)

Set to HARD_LOCK to use hard locking, or SOFT_LOCK to use soft locking.

bool isLocked()

returns true if Commander is locked

bool getLockType()

Returns HARD_LOCK if the hard locking is enabled, SOFT_LOCK if soft locking is enabled.

HARD_LOCK and SOFT_LOCK are defined as macros for true and false

bool feed(Commander& Cmdr)

Feeds another commander object to this one. Commander will then extract any payload from the other Commander and try and process it as a command.

bool hasPayload()

Returns true if the buffer contains a payload - any characters except an end of like character found after a valid command is a payload.

String getPayload()

Returns a String containing the payload. The end of line character will be included in the String.

String getPayloadString()

Returns a String containing the payload. The end of line character will be removed from the String.

bool feedString(String newString)

Overwrites the buffer with newString before processing the buffer and handling any commands. An end of line character is appended to the string if it is not already there.

void loadString(String newString)

Overwrites the buffer with newString and sets the pending command bit to true. Unlike feedString, the buffer will not be processed imediatly but when update() is next called. An end of line character is appended to the string if it is not already there.

bool endLine()

Appends a newline to the buffer and processes it. This is used when reading files to handle the end line of a file that does not contain an end of line character.

File streaming and number commands:

void startStream()

Start streaming incoming data to a special handler function.

void stopStream()

End the file streaming and return to normal operation

`void setStream(bool streamState) set the state of the streaming system.

bool isStreaming()

Returns true if the streaming system is on.

void attachSpecialHandler(cmdHandler handler)

Attach a handler function for streaming or number commands. The function must match the template for command handlers and accapt a Commander object as an argument, and return a bool.

Multi command system:

void transfer(Commander& Cmdr)

bool transferTo(const commandList_t *commands, uint32_t size, String newName)

void transferBack(const commandList_t *commands, uint32_t size, String newName)

Streams

void attachOutputPort(Stream *oPort)

`Stream* getOutputPort()

void attachAltPort(Stream *aPort)

`Stream* getAltPort()

void attachInputPort(Stream *iPort)

Stream* getInputPort()

void deleteAltPort()

void attachDefaultHandler(cmdHandler handler)

void setBuffer(uint16_t buffSize)

void attachCommands(const commandList_t *commands, uint32_t size)

void setStreamType(streamType_t newType)

streamType_t getStreamType()

Quick set and get system

void quickSetHelp()

bool quickSet(String cmd, int& var)

bool quickSet(String cmd, float& var)

bool quickSet(String cmd, double& var)

void quickGet(String cmd, int var)

void quickGet(String cmd, float var)

Print methods:

These replicate the print and write methods for Stream objects but also handle pre and postfix Strings, and copying to the alt port.

size_t println()

size_t print(printType printableVariable)

size_t print(printType printableVariable, int fmt)

size_t println(printType printableVariable)

size_t println(printType printableVariable, int fmt)

size_t write(printType printableVariable)

size_t write(printType printableVariable, int length)

Prefix and Postfix methods

void setPrefix(String prfx)

void startPrefix()

void setPostfix(String pofx)

void startPostfix()

void startFormatting()

void setAutoFormat(bool state)

bool getAutoFormat()

Commander settings:

void printCommandPrompt()

bool containsTrue()

bool containsOn()

void setCommentChar(char cmtChar)

void setReloadChar(char reloadChar)

void setEndOfLineChar(char eol)

void setPromptChar(char eol)

void setDelimChar(char eol)

void echo(bool sState)

void printComments(bool cState)

enables comment printing. When enabled and if a line in the buffer starts with a comment character, the buffer will be printed to the outport.

void echoToAlt(bool sState)

void copyRepyAlt(bool sState)

void commandProcessor(bool state)

bool commandProcessor()

enable or disable the command processor

void stripCR(bool sState)

bool stripCR()

strip carriage returns from the buffer

void multiCommander(bool enable)

bool multiCommander()

Set multi command mode

void errorMessages(bool state)

bool errorMessages()

Enable internal and error messages

void commandPrompt(bool state)

bool commandPrompt()

Enable command prompt

void showHelp(bool state)}

bool showHelp()

Enable help system

void internalCommands(bool state)

bool internalCommands()

enable or disable the internal commands

void showInternalCommands(bool state)

bool showInternalCommands()

Display internal commande in the help system

Port settings

cmdSettings_t getSettings()

void setSettings(cmdSettings_t newSet)

portSettings_t getPortSettings()

void setPortSettings(portSettings_t newPorts)

void printDiagnostics()

Extratcing data from the payload:

bool getInt(iType &myIvar)

bool getFloat(float &myFloat)

bool getDouble(double &myDouble)

bool getString(String &myString)

Help system

uint16_t getCommandListLength()

returns the number of items in the command list

String getCommandItem(uint16_t commandItem)

Returns a String containing the help system text for that command item. The text consists of the command, and the help text.

The line is formatted with a tab at the start, a tab after the command string, the | character followed by another tab and the help text.

uint8_t getInternalCommandLength()

Returns the number of internal command items

String getInternalCommandItem(uint8_t internalItem)

Get the help text line for the specified internal item

void printCommandList()

print a formatted command list - this method is used when the internal help command is used.

void printCommanderVersion()

Print the commander version and settings - used by the internal ? command

Clone this wiki locally