3.2. Messages, Commands and Responses

This page includes all information respecting the pyrobotics.messages module.

3.2.1. Messages

class pyrobotics.messages.MessageTypes

Internal pseudo-enum to set the type of message to a message.

The existing values are:

  • MessageTypes.COMMAND
  • MessageTypes.RESPONSE
  • MessageTypes.SHARED_VAR
class pyrobotics.messages.Message(commandName, params=None)

Internal abstract class, parent of Command, Response and SharedVar classes.

All derived classes of Message have the members:

name
The command name. (The actual text that is sent and is included as key in a functionMap in the module that process it).
params
The parameters for this message, they are always serialized and received as string. In case of a Command object, it represents the parameters of the command. In the case of a Response object, it represents the response generated by a command. If a command is not meant to produce any response additional to the boolean result of successful or unsuccessful, it does not matter what this filed has, although it is usually the original parameters sent by the command.
type
One of the class variables from MessageTypes
isNotification
This value is False in Command and Response objects, and True in SharedVar objects.

3.2.2. Commands

class pyrobotics.messages.Command(commandName, params = "")

Creates a command object with commandName name and parameters params.

This class should be instantiated every time a command is sent to the BlackBoad.

3.2.3. Response

class pyrobotics.messages.Response(commandName, successful=False, response='')

A Response object for the command commandName.

A Response should include a boolean stating whether the execution was successful or unsuccessful, this is set by the parameter successful.

The third field of the constructor is the response of the command, if this command is not meant to produce a response additional to the boolean result of successful or unsuccessful, it does not matter what this parameter is, although it is usually the original parameters sent by the command.

The result of a Response object is stored in the member result.

Warning

Ideally no Response objects should be built with this constructor, but with the class method Response.FromCommandObject(). This is important because an internal id is generated to keep track of the commands and their responses.

classmethod FromCommandObject(commandObj, successful=False, response=None)

Builds a Response object from a Command object and sets its successful and response members. (See Response.__init__())

This method should be used in every command handler function to create a response from the Command object it receives as parameter. (See examples in Creating a command handler).

Table Of Contents

Previous topic

3.1. BB module

Next topic

3.3. Shared Variables

This Page