Skip to content
CreateiveRobotics edited this page Mar 7, 2020 · 21 revisions

Welcome to the Commander wiki!

Commander API:


Constructor and update

Commander()

begin()

update()


Configuration

setBuffer()

printCommandPrompt()

setCommentChar()

setReloadChar()

setEndOfLineChar()

setPromptChar()

echo()

printComments()

echoToAlt()

copyRepyAlt()

commandProcessor()

stripCR()

multiCommander()

errorMessages()

commandPrompt()

showHelp()

internalCommands()

showInternalCommands()

cmdSettings_t getSettings()

setSettings()

getPortSettings()

setPortSettings()

printDiagnostics()

autoChain()

autoChainErrors()

setPrintDelay()

getPrintDelay()

printDelay()

setDelimiters(String myDelims)

getDelimiters()

addDelimiter(char newDelim)


Payload processing

These methods can be used to query and extract items from the payload. The payload is anything that is found in the buffer after a command has been identified. The command will always be at the start of the buffer and the payload comes after it. The payload can be processed as discrete 'items' and each item is defined as a group of characters that have a delimiter at each end, or a delimiter at the start and an end of line at the end. The exception is when characters are enclosed with quote marks.

Here is an example payload:

Hi my name is bill

It contains five items, so the method countItems() will return 5.

Here is another payload example:

Hi my "name is bill"

This contains three items because the last three words are enclosed in quotes, so countItems() will return 3.

Commander has several methods for extracting payload items and it uses an internal variable to keep track of where it is in the buffer so that repeated calls to these methods can be used to extract items in sequence.

countItems()

getReadIndex()

rewind()

containsTrue()

containsFalse()

containsOn()

containsOff()

hasPayload()

getPayload()

getPayloadString()

getInt(iType &myIvar)

getFloat(float &myFloat)

getDouble(double &myDouble)

getString(String &myString)

chain()

unchain()


Print methods

Commander has a set of print methods which, when called, invoke the same methods for whatever outgoing Stream object is attached to the Commander object. These print methods should always be used within command handler functions to ensure that the command list and its handlers can work transparently with any Stream object. This way the same command list can serve a USB serial port, a Bluetooth SSP connection, and a hardware UART serial port, and all responses to commands sent from any of those streams will be sent back to the stream that the command came from.

Commander also uses some internal checks to apply prefix and postfix formatting where user sp0ecified tect is applied at the start and end of any line. It relies on the user of its own print methods to correctly apply formatting.

println()

print(printType printableVariable)

print(printType printableVariable, int fmt)

println(printType printableVariable)

println(printType printableVariable, int fmt)

write(printType printableVariable)

write(printType printableVariable, int length)


Prefix and Postfix methods

setPrefix(String prfx)

startPrefix()

setPostfix(String pofx)

startFormatting()

setAutoFormat(bool state)

getAutoFormat()


Locking

Commander can be locked and unlocked. If an optional 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. HARD_LOCK and SOFT_LOCK are defined as macros for true and false.

setPassPhrase(String& phrase)

printPassPhrase()

lock()

unlock()

setLockType(bool hlState)

isLocked()

getLockType()


Reloading the buffer

feed(Commander& Cmdr)

feedString(String newString)

loadString(String newString)

endLine()


Switching between command lists

attachCommands(const commandList_t *commands, uint32_t size)

transfer(Commander& Cmdr)

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

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


File streaming and number commands

startStream()

stopStream()

setStream(bool streamState)

isStreaming()

attachSpecialHandler(cmdHandler handler)


Stream objects

attachOutputPort(Stream *oPort)

getOutputPort()

attachAltPort(Stream *aPort)

getAltPort()

attachInputPort(Stream *iPort)

getInputPort()

deleteAltPort()

attachDefaultHandler(cmdHandler handler)

setStreamType(streamType_t newType)

getStreamType()


Quick set and get system

quickSetHelp()

quickSet(String cmd, int& var)

quickSet(String cmd, float& var)

quickSet(String cmd, double& var)

quickGet(String cmd, int var)

quickGet(String cmd, float var)


Help system

getCommandListLength()

getCommandItem(uint16_t commandItem)

getInternalCommandLength()

getInternalCommandItem(uint8_t internalItem)

printCommandList()

printCommanderVersion()

Clone this wiki locally