|
LCC Fusion Project 1.0
LCC Automation
|
Bridges Python application serial communication with the CAN bus. More...
#include <LccNodeSlcanSerialBridge.h>
Inherits Executable.

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 | |
| LccNodeSlcanSerialBridge (SerialType *port, CanHubFlow *pCanHub) | |
| Constructor. More... | |
| ~LccNodeSlcanSerialBridge () | |
| 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 () |
| uint8_t | _encodeCanFrameToGcPacket (const can_frame *pCanFrame, unsigned char buf[]) |
| Encode a CAN frame (struct) to a GridConnect packet in the following format: ':' (0x3A) start of packet 'X' (0x58) extended id (4 bytes) ID converted from 4-bytes to 8 byte ascii 'R' (0x52) remote indicator data bytes converted to 2-byte ascii ';' (0x3F) end of packet. More... | |
| char | nibble_to_ascii (const uint8_t nibble) |
| Converts a nibble to its ASCII character representation. More... | |
| String | _readSlcanFrameFromSerial () |
| Read a CAN frame from the serial port. More... | |
| bool | _decodeSlcanFrameToCanFrame (const String *pSlcanFrame, can_frame *pCanFrame) |
| Deocode a Slcan frame to CAN frame: More... | |
| void | _loop_for_write () |
| bool | _decodeGcPacketToCanFrame (can_frame *pCanFrame) |
| Decodes a GridConnect packet in to a CAN frame (struc) 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... | |
| String | _encodeCanFrameAsSlcanFrame (const can_frame *pCanFrame) |
| Encodes a CAN frame into a Slcan Frame. More... | |
| void | _printHex (const uint8_t *data, const uint8_t length) |
| Print data in hexadecimal form for debugging. More... | |
Private Attributes | |
| SerialType * | pPort_ |
| Serial port object. | |
| 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) | |
Bridges Python application serial communication with the CAN bus.
This class handles bridging between OpenMRN GridConnect packet format and the expected CAN frame format over used by Python CAN-libary with serial communication.
Definition at line 69 of file LccNodeSlcanSerialBridge.h.
|
inline |
Constructor.
| port | Serial port object (HardwareSerial, SoftwareSerial, or BluetoothSerial). |
| pCanHub | Core CAN frame router of the OpenMRN stack, usually from stack()->pCanHub(). |
Format of the CAN Frame over Serial is defined here: https://python-can.readthedocs.io/en/stable/interfaces/serial.html 0xAA start of frame, 4-byte timestamp, DLC byte, Arbitration ID - 4 byte, Payload, 0xBB end of frame.
Definition at line 80 of file LccNodeSlcanSerialBridge.h.
|
inlineprivate |
Decodes a GridConnect packet in to a CAN frame (struc) 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)
| pCanFrame | hold the decode GC packet's frame |
< Get start of a packet's CAN frame
< Check next character
< udpate offset as packet is processed
< Packet found?
< return whether or not CAN data was found and converted
Definition at line 322 of file LccNodeSlcanSerialBridge.h.

|
inlineprivate |
Deocode a Slcan frame to CAN frame:
| pSlcanFrame | string holding slcan frame to be decoded. |
Slcan frame start with either a 't' (standard id) or 'T' (extended ID); followed by the ID, DLC byte, and data.
| pCanFrame | holds the decode CAN frame |
Definition at line 271 of file LccNodeSlcanSerialBridge.h.

|
inlineprivate |
Encodes a CAN frame into a Slcan Frame.
| pCanFrame | to hold the encoded Slcan frame |
Definition at line 344 of file LccNodeSlcanSerialBridge.h.

|
inlineprivate |
Encode a CAN frame (struct) to a GridConnect packet in the following format: ':' (0x3A) start of packet 'X' (0x58) extended id (4 bytes) ID converted from 4-bytes to 8 byte ascii 'R' (0x52) remote indicator data bytes converted to 2-byte ascii ';' (0x3F) end of packet.
| pCanFrame | CAN pCanFrame to encode. |
| buf | Buffer to store the encoded packet. |
Definition at line 203 of file LccNodeSlcanSerialBridge.h.


|
inlineprivate |
Handles Slcan frame coming from serial port and going out to the OpenMRN Grid Connect Hub. Process Slcan frames from serial by:
< Allocate a buffer to build the GridConnect frame and data in
< yes, adjust the buffer to the actual size of the packet
Definition at line 157 of file LccNodeSlcanSerialBridge.h.


|
inlineprivate |
Handles processing OpenMRN GridConnect packet and sending Slcan frame towards the serial port. Process GC packets to Slcan frames and out to serial by:
< Clear the buffer after writing
< Wake up state flow to release buffer and take next from the queue
Definition at line 299 of file LccNodeSlcanSerialBridge.h.


|
inlineprivate |
Print data in hexadecimal form for debugging.
| data | Data to print. |
| length | Length of the data. |
Definition at line 362 of file LccNodeSlcanSerialBridge.h.

|
inlineprivate |
Read a CAN frame from the serial port.
Definition at line 254 of file LccNodeSlcanSerialBridge.h.

|
inlineprivate |
Converts a nibble to its ASCII character representation.
| nibble | Nibble value to convert. |
Definition at line 245 of file LccNodeSlcanSerialBridge.h.

|
inline |
Called by the loop to check for possible serial or GridConnect packets to be read and processed.
< Send to serial any queued GridConnect CAN packets.
< Read from serial slcan frames, convert to GC packets, queue with GC hub.
Definition at line 92 of file LccNodeSlcanSerialBridge.h.
