LCC Fusion Project 1.0
LCC Automation
Loading...
Searching...
No Matches
LccNodeNowBridge Class Reference

Bridges ESP_NOW with the CAN bus. More...

#include <LccNodeNowBridge.h>

Inherits Executable.

Collaboration diagram for LccNodeNowBridge:

Classes

class  WritePort
 State machine running in the OpenMRN cooperative executor, registered to receive data that needs to be sent to the port. More...
 

Public Member Functions

 LccNodeNowBridge (CanHubFlow *pCanHub, bool isServer)
 Constructor. More...
 
 ~LccNodeNowBridge ()
 Destructor.
 
void run ()
 Called by the loop to check for possible serial or GridConnect packets to be read and processed. More...
 

Private Member Functions

void _loop_for_read ()
 Handles reading a GC packet from ESP_NOW and sending to OpenMRN Grid Connect Hub.
 
void _loop_for_write ()
 Handles processing OpenMRN GridConnect packet and sending the GC packet to ESP_NOW. More...
 
bool _isGcPacketWriteBuf (char *pGcData, size_t size)
 Decodes a GridConnect packet into a CAN frame (structure) Supports multiple frames of data within a packet, but only processes one frame of data per invocation (uses writeOfs_ to keep position within the packet) More...
 
const char * _generateIdentMessage ()
 Generates an identification message from the NodeID. More...
 
void _printHex (const uint8_t *data, const uint8_t length)
 Print data in hexadecimal form for debugging. More...
 

Private Attributes

Service * pService_
 Access to the stack's executor.
 
HubFlow txtHub_ { pService_ }
 Hub for the textual data.
 
Buffer< HubData > * pWriteBuffer_ { nullptr }
 Buffer for outgoing data.
 
WritePort writePort_ { this, pService_ }
 State flow with queues for output frames generated by the stack.
 
size_t writeOfs_
 Offset into GC packet of data being processed (in case there is more than one frame within the packet)
 
uint8_t broadcastAddress_ [6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
 Broadcast MAC address.
 
bool isServer_
 true when configuring a ESP_NOW server
 
NowMessage outgoingMessage_
 Outgoing message structure.
 

Detailed Description

Bridges ESP_NOW with the CAN bus.

This class handles bridging between ESP_NOW and OpenMRN GridConnect using GC packet format

Definition at line 65 of file LccNodeNowBridge.h.

Constructor & Destructor Documentation

◆ LccNodeNowBridge()

LccNodeNowBridge::LccNodeNowBridge ( CanHubFlow *  pCanHub,
bool  isServer 
)
inline

Constructor.

Parameters
pCanHubCore CAN frame router of the OpenMRN stack, usually from stack()->pCanHub().
isServertrue indicates a ESP_NOW server (Hub)) is to be configured, else a client (non-Hub) is configured.

Definition at line 74 of file LccNodeNowBridge.h.

Member Function Documentation

◆ _generateIdentMessage()

const char * LccNodeNowBridge::_generateIdentMessage ( )
inlineprivate

Generates an identification message from the NodeID.

Returns
The identification message as a C-string.
openlcb::NodeID nodeId = 0x123456789ABC;
const char* identMessage = bridge._generateIdentMessage();
Serial.println(identMessage);

Definition at line 344 of file LccNodeNowBridge.h.

◆ _isGcPacketWriteBuf()

bool LccNodeNowBridge::_isGcPacketWriteBuf ( char *  pGcData,
size_t  size 
)
inlineprivate

Decodes a GridConnect packet into a CAN frame (structure) Supports multiple frames of data within a packet, but only processes one frame of data per invocation (uses writeOfs_ to keep position within the packet)

Returns
True if a GC packet found in writeBuffer

< Get start of a packet's CAN frame

< Check next character

< update offset as packet is processed

< Packet found?

Definition at line 243 of file LccNodeNowBridge.h.

Here is the caller graph for this function:

◆ _loop_for_write()

void LccNodeNowBridge::_loop_for_write ( )
inlineprivate

Handles processing OpenMRN GridConnect packet and sending the GC packet to ESP_NOW.

< Clear the buffer after writing

< Wake up state flow to release buffer and take next from the queue, also reset writeOfs_ to zero.

Definition at line 222 of file LccNodeNowBridge.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _printHex()

void LccNodeNowBridge::_printHex ( const uint8_t *  data,
const uint8_t  length 
)
inlineprivate

Print data in hexadecimal form for debugging.

Parameters
dataData to print.
lengthLength of the data.

Definition at line 376 of file LccNodeNowBridge.h.

Here is the caller graph for this function:

◆ run()

void LccNodeNowBridge::run ( )
inline

Called by the loop to check for possible serial or GridConnect packets to be read and processed.

< Read from serial slcan frames, convert to GC packets, queue with GC hub.

< Send to ESP_NOW queued GridConnect CAN packets.

Definition at line 124 of file LccNodeNowBridge.h.

Here is the call graph for this function:

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