Commands
Commands are the messages used by ArmorLink to trigger Actions across the network.
A Command is sent to a target module and contains the information required to execute matching functionality on that module.
For more information about Actions, see Actions.
Command Structure
An ArmorLink Command consists of three parts:
- Target
- Entity
- Command
Example:
ArmorLink.sendCommand(
"Helmet",
"Facemask",
"toggle"
);
In this example:
Helmetis the target moduleFacemaskis the entitytoggleis the command
The target module name determines where the Command should be delivered.
The entity and command values are used by the receiving module to match and execute an Action.
Commands Trigger Actions
Commands and Actions are closely related.
A Command is the message that travels through the network.
An Action defines what happens when a matching Command is received.
Command received
|
v
Matching Action found
|
v
onExecute() is called
Example Action:
module.actions()
.add("toggleFaceplate")
.label("Toggle Faceplate")
.command("Facemask", "toggle")
.onExecute([]{
toggleFaceplate();
});
When the module receives a Command with:
- Entity:
Facemask - Command:
toggle
ArmorLink executes the matching Action.
Commands Are Routed Through the Gateway
Commands are routed through the Gateway.
A module sends a Command to the Gateway, and the Gateway decides whether the Command is intended for itself or for another module.
For more information about routing, see Gateway.
Command Targeting the Gateway
In this example, Chest is the name of the Gateway module:
ArmorLink.sendCommand(
"Chest",
"BTN_R1",
"SINGLE_CLICK"
);
The Command is sent to the Gateway module named Chest.
Since the Gateway itself is the target, the Command is processed locally and not forwarded to another module.
The Gateway may define an Action that listens for this Command:
chestModule.actions()
.add("rightBtn1SingleClick")
.label("Right BTN1 Single Click")
.command("BTN_R1", "SINGLE_CLICK")
.onExecute([]{
dfplayer.stop();
});
When the Command is received, ArmorLink executes the matching Action on the Gateway module.
Command Targeting Another Module
A Command can also target another module.
Example:
ArmorLink.sendCommand(
"Helmet",
"Facemask",
"toggle"
);
The Command is first sent to the Gateway.
The Gateway detects that the target is Helmet and forwards the Command to the Helmet module.
The Helmet module then executes the matching Action.
Sending Module
|
v
Gateway
|
v
Target Module
|
v
Matching Action
Broadcast Commands
A Command can also be broadcast to all modules.
Broadcast Commands are useful when multiple modules should react to the same event.
Example:
ArmorLink.broadcastCommand(
"Flaps",
"toggle"
);
In this example, the Command is sent to all modules.
Any module that exposes a matching Action can react to it.
Example Action on a module:
module.actions()
.add("toggleFlaps")
.label("Toggle Flaps")
.command("Flaps", "toggle")
.onExecute([]{
toggleFlaps();
});
Broadcast Commands are routed through the Gateway and delivered as a network-wide Command.
This is useful for actions such as:
- Opening or closing all flaps
- Turning off multiple lighting modules
- Triggering a synchronized effect
- Sending a global state change
Sending Module
|
v
Gateway
|
v
All Modules
|
v
Matching Actions execute
Modules that do not expose a matching Action simply ignore the Command.
Commands from Application Logic
Commands are often sent from normal firmware code.
Example:
void btn1_handleClick()
{
ledOn();
ArmorLink.sendCommand(
"Helmet",
"Facemask",
"toggle"
);
}
In this example, the button press is not an ArmorLink Action.
It is normal application logic.
The local code turns on an LED and then sends a Command through the ArmorLink network.
For more information about the difference between module firmware and ArmorLink functionality, see Modules.
Commands vs Actions
Commands are not displayed in the ArmorLink App.
Actions are displayed in the ArmorLink App.
Commands are the internal messages that trigger Actions.
App user sees: Toggle Faceplate
ArmorLink sends: target + entity + command
Module executes: matching Action
This separation allows a module to expose user-friendly Actions while keeping the underlying communication simple and consistent.
Summary
Commands are the transport mechanism used to trigger Actions across an ArmorLink network.
A regular Command contains:
- Target module
- Entity
- Command
A Broadcast Command contains:
- Entity
- Command
Commands are routed through the Gateway and delivered to the appropriate module.
The receiving module executes the matching Action.