Skip to content

Namespace espos_n2k

Namespace List > espos_n2k

A CAN frame as espOS sees it, deliberately not the driver's struct. More...

Classes

Type Name
struct CanFrame
struct CanMessage
class CandumpTcpServer
TCP server that streams candump ASCII to connected clients and accepts inbound candump lines for transmission on the CAN bus.
struct CandumpTcpServerConfig
class TwaiReceiver
Reads CAN frames from the TWAI peripheral and emits them as CanMessage values, on the shared node's RX task.
struct TwaiReceiverConfig
class TwaiTransmitter
Accepts CanMessage values and transmits them on the CAN bus.

Public Types

Type Name
typedef CanMessage TwaiMessage

Public Attributes

Type Name
constexpr size_t kCanMaxData = 8
Classic CAN, which is all NMEA 2000 uses: up to 8 data bytes.

Public Functions

Type Name
bool candump_decode (const char * line, CanMessage * out)
Decode a candump ASCII line into a CanMessage .
int candump_encode (const CanMessage & msg, const char * iface, char * buf, size_t buf_len)
Encode a CanMessage to candump ASCII format: (1234567890.123456) vcan0 09F10203::FF00FF00FF00FF00 Returns number of bytes written (excluding null terminator), or -1 if buf is too small.
size_t candump_resync_offset (const char * buf, size_t len, size_t sent)
How much of a partly-sent transmit buffer to discard.

Detailed Description

Compatibility header.

This used to be twai_message_t straight out of driver/twai.h, which meant the candump encoder — pure text munging, no hardware in sight — could not be compiled on the host and therefore had no tests. It also meant that changing IDF's TWAI API changed the type every consumer of this component names. One small struct fixes both: the driver types now appear only in the two files that talk to the peripheral.

TwaiMessage was a thin wrapper around the driver's twai_message_t; it is now an alias for CanMessage, which carries the same information without naming a driver type. The FIELDS changed with it — identifier/data_length_code/extd are id/dlc/extended — so this keeps code that names the type compiling, not code that reaches inside it.

Include espos_n2k/can_frame.h directly in new code.

Public Types Documentation

typedef TwaiMessage

using espos_n2k::TwaiMessage = typedef CanMessage;

Public Attributes Documentation

variable kCanMaxData

Classic CAN, which is all NMEA 2000 uses: up to 8 data bytes.

constexpr size_t espos_n2k::kCanMaxData;


Public Functions Documentation

function candump_decode

Decode a candump ASCII line into a CanMessage .

bool espos_n2k::candump_decode (
    const char * line,
    CanMessage * out
) 

Returns true on success, false on parse error.


function candump_encode

Encode a CanMessage to candump ASCII format: (1234567890.123456) vcan0 09F10203::FF00FF00FF00FF00 Returns number of bytes written (excluding null terminator), or -1 if buf is too small.

int espos_n2k::candump_encode (
    const CanMessage & msg,
    const char * iface,
    char * buf,
    size_t buf_len
) 


function candump_resync_offset

How much of a partly-sent transmit buffer to discard.

size_t espos_n2k::candump_resync_offset (
    const char * buf,
    size_t len,
    size_t sent
) 

send() on a nearly-full socket takes fewer bytes than it was offered, and the tail it did not take usually ends mid-line. Continuing from exactly sent would append the next frame onto that fragment, and a reader would parse one corrupt line rather than cleanly missing a frame for a CAN id that means a plausible wrong PGN, which is worse than a gap.

Given a buffer of newline-terminated lines and the number of bytes the socket accepted, returns the offset to keep from: the byte after the first newline at or beyond sent, or len when no newline follows (the whole remainder is one partial line and goes). Bytes between sent and the result are the dropped fragment.

Pure, so it is host-tested: see test/host/espos_n2k_test.



The documentation for this class was generated from the following file espos_n2k/include/espos_n2k/can_frame.h