Softata: Service Commands - 2
softata rpipico firmata arduino csharp bme280 grove pico sdk-for-c-arduino tcpip
The previous post covered the simple basic high level commands that only required the first letter of the command to be sent as ASCII coded byte. This post cover the more detailed commands for communicating with eth Pico W hosted devices.
The structure of these commands, as an array of byte is:
- cmd
- pin
- param
- other
- otherData = NULL;
The command, cmd
, is the overall command or class of commands. For example, commands 0xD0 to 0xD3 are for digital commands Pinmode, Write (set), Read or Toggle respectively. The pin
specifies the target pin, such as for setting up a digital input or output pin with the PinMode command.
other
is used for additional data for commands. For example, for Serial commands it is 1 or 2 indicating the target is Serial1 or Serial2. The param
parameter is also used for additional data such as for Serial setup it specifies index of the BAUD rate to use from a standard list.
The other
data is an array of bytes past these first 4. The first byte of that array specifies the length of the array apart from that first byte. This data is used by more complex commands.
default:
// Get Softata command and parameters
byte cmd = msg[0];
byte pin = 0xff;
byte param = 0xff;
byte other = 0xff;
byte * otherData = NULL;
if (length > 1) {
pin = msg[1];
if (length > 2) {
param = msg[2];
if (length > 3) {
other = msg[3];
if(length>4)
{
otherData = msg+4;
}
}
}
}
Server code for getting the command components
The rest of the Server code is then a switch statement using cmd
as the pivot. Each branch will return data with a command such as:
client.print("OK:");
Commands returning data such as from a read will embed that in the string sent.
Note that the Grove class of commands is discussed in the a subsequent post. The mechanism for these is a bit more complex using the otherData.
Client Commands
These make use of the SendMessage method:
string SendMessage(Commands MsgType, byte pin = 0xff, byte state = 0xff, string expect = "OK", byte other=0xff, byte[]? Data=null )
{
}
This is implemented similar to the simpler SendMessage
for basic commands as covered in the previous post. The extra data, the parameters of the method, are added byte by byte to the SendMsg
list before it is converted to an array of bytes, etc. This maps to the server message structure thus:
- MsgType … cmd
- pin … pin
- state … param
- other … other
- Data … otherData
expect
is not sent as it used for validation of the received response.
The Console app does not, in the main, call this method but uses device specific methods that call it. These higher level commands are implemented in device type specific classes. For example the Digital class calls are:
SoftataLib.Digital.SetPinMode(BUTTON, SoftataLib.PinMode.DigitalInput);
SoftataLib.Digital.SetPinMode(LED, SoftataLib.PinMode.DigitalOutput);
SoftataLib.Digital.SetPinState(LED,PinState.LOW);
while (SoftataLib.Digital.GetPinState(BUTTON))
Thread.Sleep(100);
SoftataLib.Digital.TogglePinState(LED);
BUTTON
and LED
just define their pins.
The client device classes are:
- Digital
- Analog (Nb includes PWM)
- Sensor
- Serial
- Display
Topic | Subtopic | |
This Category Links | ||
Category: | Softata Index: | Softata |
Next: > | Softata | Service Commands - 3 |
< Prev: | Softata | Service Commands - 1 |