RemoteLogRK
Public Member Functions | Protected Member Functions | Protected Attributes
RemoteLogEventServer Class Reference

Sends out debug logs as Particle events. More...

#include <RemoteLogRK.h>

Inheritance diagram for RemoteLogEventServer:
RemoteLogServer

Public Member Functions

 RemoteLogEventServer (const char *eventName)
 Constructor. More...
 
virtual ~RemoteLogEventServer ()
 Destructor. More...
 
void loop (size_t &readIndex)
 Perform loop time operations such as reading and writing sockets. More...
 
- Public Member Functions inherited from RemoteLogServer
 RemoteLogServer ()
 Base class constructor. Doesn't do anything.
 
virtual ~RemoteLogServer ()
 This class is not typically deleted, because you can't unregister one.
 
virtual void setup ()
 Perform setup operations. More...
 
virtual void reset ()
 Reset is about to occur, do things like disconnect sockets. More...
 

Protected Member Functions

void stateWaitForMessage (size_t &readIndex)
 State handler to wait for cloud connected and messages to send. Called from loop(). More...
 
void stateTryPublish (size_t &readIndex)
 If still connected to the cloud and it has been at least 1010 milliseconds, publish. More...
 
void stateFutureWait (size_t &readIndex)
 Wait for the publish to succeed or fail. More...
 
- Protected Member Functions inherited from RemoteLogServer
 RemoteLogServer (const RemoteLogServer &)=delete
 This class is not copyable.
 
RemoteLogServeroperator= (const RemoteLogServer &)=delete
 This class is not copyable.
 

Protected Attributes

String eventName
 The event name to publish, passed to the constructor.
 
char buf [particle::protocol::MAX_EVENT_DATA_LENGTH+1]
 Buffer to hold the event to be published. More...
 
unsigned long lastPublish = 0
 The millis() counter at the time of the last publish. More...
 
particle::Future< bool > publishFuture
 The Future used to determine if the publish has completed yet.
 
std::function< void(RemoteLogEventServer &, size_t &readIndex)> stateHandler = &RemoteLogEventServer::stateWaitForMessage
 State handler, called from loop.
 

Detailed Description

Sends out debug logs as Particle events.

Works on both cellular and Wi-Fi. Automatically meters out data at 1 second intervals to avoid event throttling. Sends multiple messages in a single publish up to the maximum publish size of 622 bytes if there are multiple messages queued. However, if there is only one available, that one will be sent immediately to keep the events in approximately real-time.

Constructor & Destructor Documentation

◆ RemoteLogEventServer()

RemoteLogEventServer::RemoteLogEventServer ( const char *  eventName)

Constructor.

Parameters
eventNameThe event name to use for the publish

◆ ~RemoteLogEventServer()

RemoteLogEventServer::~RemoteLogEventServer ( )
virtual

Destructor.

This object is not typically deleted as you can't unregister a server, so deleting it would cause a dangling pointer.

Member Function Documentation

◆ loop()

void RemoteLogEventServer::loop ( size_t &  readIndex)
virtual

Perform loop time operations such as reading and writing sockets.

Calls the state handler in stateHandler.

Reimplemented from RemoteLogServer.

◆ stateFutureWait()

void RemoteLogEventServer::stateFutureWait ( size_t &  readIndex)
protected

Wait for the publish to succeed or fail.

Next state: stateWaitForMessage (success) or stateTryPublish (failure)

◆ stateTryPublish()

void RemoteLogEventServer::stateTryPublish ( size_t &  readIndex)
protected

If still connected to the cloud and it has been at least 1010 milliseconds, publish.

The publish is non-blocking using a future.

Previous state: stateWaitForMessage Next state: stateFutureWait

◆ stateWaitForMessage()

void RemoteLogEventServer::stateWaitForMessage ( size_t &  readIndex)
protected

State handler to wait for cloud connected and messages to send. Called from loop().

If cloud connected and there is a message, the message is consumed and copied into buf.

Next state: stateTryPublish

Field Documentation

◆ buf

char RemoteLogEventServer::buf[particle::protocol::MAX_EVENT_DATA_LENGTH+1]
protected

Buffer to hold the event to be published.

It's copied into a buffer because otherwise it would need to lock the main circular buffer during the entire publish operation, which would take way too long.

◆ lastPublish

unsigned long RemoteLogEventServer::lastPublish = 0
protected

The millis() counter at the time of the last publish.

This is used to prevent publishing more than once every 1010 milliseconds.


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