tcMenu
Public Member Functions | Static Public Member Functions | List of all members
CombinedMessageProcessor Class Reference

#include <MessageProcessors.h>

Public Member Functions

 CombinedMessageProcessor ()
 
void initialise ()
 
void newMsg (uint16_t msgType)
 
void fieldUpdate (TagValueRemoteConnector *connector, FieldAndValue *field)
 
void addCustomMsgHandler (uint16_t msgType, FieldUpdateFunction callback)
 

Static Public Member Functions

static void setFormTemplatesInFlash (const EmbedControlFlashedForm **formTemplatesInFlash)
 
static const EmbedControlFlashedForm ** getFormTemplatesInFlash ()
 

Detailed Description

This message processor is responsible for handling messages coming off the wire and processing them into usable events by the rest of the system. Usually, the message processor actually handles the event in full.

When a new message arrives, this class attempts to find a suitable processor function (or ignore if we can't process), then each field in the message is passed to the function to processed.

You can customize a message process by adding your own additional message types that it can process using the addCustomMsgHandler(..) function.

Constructor & Destructor Documentation

◆ CombinedMessageProcessor()

CombinedMessageProcessor::CombinedMessageProcessor ( )

Constructor takes an array of processors and the number of processors in the array.

Member Function Documentation

◆ initialise()

void CombinedMessageProcessor::initialise ( )

Called by the remote server component to initialise the message handlers before use.

◆ newMsg()

void CombinedMessageProcessor::newMsg ( uint16_t  msgType)

Whenever there is a new message, this will be called, to re-initialise the internal state

◆ fieldUpdate()

void CombinedMessageProcessor::fieldUpdate ( TagValueRemoteConnector connector,
FieldAndValue field 
)

Called whenever a field has been processed in the current message, after a call to newMsg

◆ addCustomMsgHandler()

void CombinedMessageProcessor::addCustomMsgHandler ( uint16_t  msgType,
FieldUpdateFunction  callback 
)
inline

If you want to be able to process a custom incoming message, simply add it here as a MsgHandler, see above. It can be a local, even inline object as it will be copy constructed to an internal list. Step 1. You define a custom message type using something similar to

 `#define MSG_CUSTOM msgFieldToWord('Z','Z')`

Step 2. You create a function that is called back for each field as it arrives

void myFieldProcessor(TagValueRemoteConnector* connector, FieldAndValue* field, MessageProcessorInfo* info) {
// The info is a pointer to 16 bytes of memory that you can use for any purpose.
if(field->fieldType == FVAL_END_MSG) {
// message is ending. All fields are processed
} else {
// process fields as they arrive.
if(field->field == FIELD_HB_MODE) {
// do something, or maybe store in the info area temporarily.
}
}
}
Definition: MessageProcessors.h:35
@ FVAL_END_MSG
Definition: RemoteConnector.h:58
Definition: RemoteConnector.h:90
Definition: RemoteConnector.h:187

Step 3. Register the processor

myProcessor.addCustomMsgHandler(MSG_CUSTOM, myFieldProcessor);
See also
RemoteConnector for how to create a custom message rather than receive it.
FieldAndValue for more information about how the field callback works.

The documentation for this class was generated from the following files: