File service_protocol.hpp
FileList > SensorHub_FW > src > service_protocol.hpp
Go to the source code of this file
#include <Arduino.h>#include <FreeRTOS.h>#include <queue.h>#include <device_settings.hpp>#include <device_status.hpp>#include <ringbuffer.hpp>#include <usb_service_protocol.hpp>
Classes
| Type | Name |
|---|---|
| struct | ArgSpecs Struct used to pass options for argument parsing between methods. |
Public Attributes
| Type | Name |
|---|---|
| constexpr uint8_t | ParseFail = = 0 |
| constexpr uint8_t | ParseOK = = 1 |
| const char | kHelpUsageString = = "**********************************HELP************************************" |
| "\r\n" | |
| "CMDS: STATUS - Prints: status of the system, connected devices and " | |
| "sampletime\r\n" | |
| " SETPORT [DeviceType portA] [DeviceType portB] [DeviceType BackBone] " | |
| "\r\n" | |
| " - Setup (sensor) software drivers on the selected port in " | |
| "argument\r\n" | |
| " SETID [UniqueDeviceID] - Sets a unique identifier for the system\r\n" | |
| " STREAM - Stream current sensor measurements to this console\r\n" | |
| " SETSR [Sample rate port a] [Sample rate port b] - Sets the sample rate for \r\n" | |
| " port a in b in milliseconds (10-1000 ms)\r" |
|
| const char | kInvalidArgumentValues = = "!E Invalid arguments entered!" |
| constexpr int | kLowerRangeArgSetID = = 0 |
| constexpr int | kLowerRangeArgSetPort = = 0 |
| constexpr int | kLowerRangeArgSetSR = = 10 |
| constexpr int | kMessageBufferSize = = 1024 Statically assigned (output) messagebuffer, used to store the output of commands in. Gets used by multiple callback methods. |
| constexpr uint8_t | kNumOfArgumentsSetID = = 1 |
| constexpr uint8_t | kNumOfArgumentsSetPort = = 3 Argument parser constants. |
| constexpr uint8_t | kNumOfArgumentsSetSR = = 2 |
| constexpr uint8_t | kNumOfRegisters = = 7 The num of registers defined in the usb service protocol registers array. |
| const char | kSetIDFormatString = = "!OK Device id is set to: %d" |
| const char | kSetPortFormatString = = "!OK Port A set to: %d, Port B set to: %d, Port BB set to: %d" |
| const char | kSetSampleTimeFormatString = = "!OK Sampletime on Port A set to: %d, Port B set to: %d" |
| const char | kStreamDataFormatString = = "{ \"Val\": %d}" |
| const char | kStreamFormatString = = "{\"NumOfShorts\": %d, \"SampleNum\": %d, \"Sensor\": %d, \"Buf\": [" Format strings, used to create the responses with! |
| constexpr int | kUpperRangeArgSetID = = 255 |
| constexpr int | kUpperRangeArgSetPort = = kNumOfSupportedSensors-1 |
| constexpr int | kUpperRangeArgSetSR = = 1000 |
Public Static Attributes
| Type | Name |
|---|---|
| char | MessageBuffer |
| usb_service_protocol::USBServiceProtocolRegisters | USBRegisters = { {"STATUS", 0, false, CMD_STATUS_CB}, |
| {"SETPORT", kNumOfArgumentsSetPort, false, CMD_SETPORT_CB}, | |
| {"SETID", kNumOfArgumentsSetID, false, CMD_SETID_CB}, | |
| {"STREAM", 0, true, CMD_STREAM_CB}, | |
| {"SETSR", kNumOfArgumentsSetSR, false, CMD_SETSR_CB}, | |
| {"HELP", 0, false, CMD_HELP_CB}} STATIC declaration of all the CB methods and command information. |
Public Functions
| Type | Name |
|---|---|
| const char * | CMD_HELP_CB (char ** args, int num_of_args) Callback function for the HELP command. This function will be ran when HELP command is entered. The HELP command return the usage of the console in a formatted string. |
| const char * | CMD_SETID_CB (char ** args, int num_of_args) Callback function for the SETID command. This function will be ran when SETID command is entered. The SETID command sets an unique identifier for this subsystem (ID will be written to external flash!). ID can be read using STATUS command! |
| const char * | CMD_SETPORT_CB (char ** args, int num_of_args) Callback function for the SETPORT command. This function will be ran when SETPORT command is entered. The SETPORT command sets the sensortypes for the given ports.. |
| const char * | CMD_SETSR_CB (char ** args, int num_of_args) Callback function for the SETSR command. This function will be ran when SETSR command is entered. The SETSR command sets the sample rate for the sensorports. |
| const char * | CMD_STATUS_CB (char ** args, int num_of_args) Callback function for the STATUS command. This function will be ran when STATUS command is entered. The STATUS command return the status of the system in a formatted JSON string. |
| const char * | CMD_STREAM_CB (char ** args, int num_of_args) Callback function for the STREAM command. This function will be ran when STREAM command is entered. This command is an stream command, meaning it will run repeatedly until \r (ENTER) is detected in serial console. The Stream command returns the sensordata of each sensor in a formatted json string. |
| void | ComposeJsonFormattedStringOfSensorData (SensorData * data) This function will compose a Json formatted string of the sensordata and put it in to the messagebuffer. |
| uint8_t | ParseEnteredArgumentsToInt (char ** argument, int * buffer, const ArgSpecs ArgSpec) This function will convert the string type arguments to an integer and check if the argument value falls within the given Argspec range. |
Public Attributes Documentation
variable ParseFail
constexpr uint8_t ParseFail;
variable ParseOK
constexpr uint8_t ParseOK;
variable kHelpUsageString
const char kHelpUsageString[];
variable kInvalidArgumentValues
const char kInvalidArgumentValues[];
variable kLowerRangeArgSetID
constexpr int kLowerRangeArgSetID;
variable kLowerRangeArgSetPort
constexpr int kLowerRangeArgSetPort;
variable kLowerRangeArgSetSR
constexpr int kLowerRangeArgSetSR;
variable kMessageBufferSize
constexpr int kMessageBufferSize;
variable kNumOfArgumentsSetID
constexpr uint8_t kNumOfArgumentsSetID;
variable kNumOfArgumentsSetPort
constexpr uint8_t kNumOfArgumentsSetPort;
variable kNumOfArgumentsSetSR
constexpr uint8_t kNumOfArgumentsSetSR;
variable kNumOfRegisters
constexpr uint8_t kNumOfRegisters;
variable kSetIDFormatString
const char kSetIDFormatString[];
variable kSetPortFormatString
const char kSetPortFormatString[];
variable kSetSampleTimeFormatString
const char kSetSampleTimeFormatString[];
variable kStreamDataFormatString
const char kStreamDataFormatString[];
variable kStreamFormatString
const char kStreamFormatString[];
variable kUpperRangeArgSetID
constexpr int kUpperRangeArgSetID;
variable kUpperRangeArgSetPort
constexpr int kUpperRangeArgSetPort;
variable kUpperRangeArgSetSR
constexpr int kUpperRangeArgSetSR;
Public Static Attributes Documentation
variable MessageBuffer
char MessageBuffer[kMessageBufferSize];
variable USBRegisters
STATIC declaration of all the CB methods and command information.
usb_service_protocol::USBServiceProtocolRegisters USBRegisters[kNumOfRegisters];
Note:
The format of the struct is { "String of the command", Number of Arguments, Command is stream command, Pointer to callback method}
Note:
Stream command means that command will be ran repeatedly when entered. Command can be stopped by pressing enter key or '\r' character
Public Functions Documentation
function CMD_HELP_CB
Callback function for the HELP command. This function will be ran when HELP command is entered. The HELP command return the usage of the console in a formatted string.
const char * CMD_HELP_CB (
char ** args,
int num_of_args
)
Parameters:
argsA two dimensional array containing the arguments entered after the commandnum_of_argsThe number of arguments entered after the command
Returns:
Command response string, which will be a formatted string explaining how to use this console!
function CMD_SETID_CB
Callback function for the SETID command. This function will be ran when SETID command is entered. The SETID command sets an unique identifier for this subsystem (ID will be written to external flash!). ID can be read using STATUS command!
const char * CMD_SETID_CB (
char ** args,
int num_of_args
)
Parameters:
argsA two dimensional array containing the arguments entered after the commandnum_of_argsThe number of arguments entered after the command
Returns:
Command response string, which will be a !OK ..[confirmation of entered arguments] if arguments where valid numbers !E Invalid arguments entered if the arguments where not valid!
function CMD_SETPORT_CB
Callback function for the SETPORT command. This function will be ran when SETPORT command is entered. The SETPORT command sets the sensortypes for the given ports..
const char * CMD_SETPORT_CB (
char ** args,
int num_of_args
)
Parameters:
argsA two dimensional array containing the arguments entered after the commandnum_of_argsThe number of arguments entered after the command
Returns:
Command response string, which will be a !OK ..[confirmation of entered arguments] if arguments where valid numbers !E Invalid arguments entered if the arguments where not valid!
function CMD_SETSR_CB
Callback function for the SETSR command. This function will be ran when SETSR command is entered. The SETSR command sets the sample rate for the sensorports.
const char * CMD_SETSR_CB (
char ** args,
int num_of_args
)
Parameters:
argsA two dimensional array containing the arguments entered after the commandnum_of_argsThe number of arguments entered after the command
Returns:
Command response string, which will be a !OK ..[confirmation of entered arguments] if arguments where valid numbrs !E Invalid arguments entered if the arguments where not valid!
function CMD_STATUS_CB
Callback function for the STATUS command. This function will be ran when STATUS command is entered. The STATUS command return the status of the system in a formatted JSON string.
const char * CMD_STATUS_CB (
char ** args,
int num_of_args
)
Parameters:
argsA two dimensional array containing the arguments entered after the commandnum_of_argsThe number of arguments entered after the command
Returns:
Command response string, which will be a json formatted status string.
function CMD_STREAM_CB
Callback function for the STREAM command. This function will be ran when STREAM command is entered. This command is an stream command, meaning it will run repeatedly until \r (ENTER) is detected in serial console. The Stream command returns the sensordata of each sensor in a formatted json string.
const char * CMD_STREAM_CB (
char ** args,
int num_of_args
)
Parameters:
argsA two dimensional array containing the arguments entered after the commandnum_of_argsThe number of arguments entered after the command
Returns:
Command response string, which will be a json formatted string!
function ComposeJsonFormattedStringOfSensorData
This function will compose a Json formatted string of the sensordata and put it in to the messagebuffer.
void ComposeJsonFormattedStringOfSensorData (
SensorData * data
)
Parameters:
dataThe SensorData to convert to Json String
function ParseEnteredArgumentsToInt
This function will convert the string type arguments to an integer and check if the argument value falls within the given Argspec range.
uint8_t ParseEnteredArgumentsToInt (
char ** argument,
int * buffer,
const ArgSpecs ArgSpec
)
Parameters:
argumentAn two dimensional array containing the string argument values.bufferAn integer buffer to save the parsed arguments to.ArgSpecA struct containing the number of arguments to parse, the permitted max value of the argument and the permitted min value of the argument
Returns:
1 on Succes! 0 on Fail!
Note:
All arguments are checked with the same upper and lower range from the ArgSpec struct!
The documentation for this class was generated from the following file SensorHub_FW/src/service_protocol.hpp