-
Notifications
You must be signed in to change notification settings - Fork 0
Command callback
Once a command is received, there are different types of callbacks that will be invoked.
A callback is a function from witch the pointer is stored and so this function can be executed later on.
Any command callback must have this signature: void nameOfTheFunction(int address, byte *data, int messageLength).
- address: will hold the address of the command.
- data: an array of byte (8 bit) values with the data for the command.
- messageLenght: the length of the data sinds data is a dynamic array.
There are 3 types of command callbacks:
When there is a function set for this callback, this will be invoked every time any command is received.
void setup()
{
Cmd.setCommand(processAnyCommands);
}
void processAnyCommands(int address, byte *data, int messageSize)
{
// This will be invoked every time a command is received.
// Do something amazing with the command.
}Note
Only one default callback can be set. Setting another callback will override the existing one.
A function can also be registered at a certain address.
After executing the general callback, the registered callback will be executed with the same paramerters.
void setup()
{
Cmd.addCommand(10, sampleCommand10);
}
void sampleCommand10(int address, byte *data, int messageLenth)
{
// This will only be invoked for a command with address 10.
}Note
Only one callback can be registered at a certain address. Adding another callback at an already existing address will override the existing one.
The first 10 commands are "reserved" for internal commands. These commands can alter the internal settings of the instance of
the SerialCommands.
They can easily be overridden by adding a registered command at those addresses (see 2) but the addresses cannot be changed.
- Set the address length (default 1)
- Set the address factor (default 200)(see todo)
- Spare
- Spare
- Spare
- Spare
- Spare
- Spare
- Set internal logging on/off. Internal logging will be send as plain text via the same Serial stream
- Get the status of internal settings (see todo)