VLCB SDK
An opinionated SDK for VLCB protocol
Loading...
Searching...
No Matches
packet_parse.c File Reference
#include "vlcb/net/adapter/can/packet_parse.h"
#include <assert.h>
#include <stdbool.h>
#include <string.h>
#include "vlcb/platform/log.h"
Include dependency graph for packet_parse.c:

Go to the source code of this file.

Functions

VlcbNetAdptErr vlcb_net_adpt_ParseRawCanData (const VlcbCanFrameId id, const bool is_rtr, const uint8_t payload_len, const VlcbNetAdptPayload *const payload, VlcbNetAdptPkt *const packet)
 Parse the CAN packet data into the inner format.
 
int vlcb_net_adpt_NewCanFrameIdFromPkt (const VlcbNetAdptPkt *const packet, VlcbCanFrameId *const id)
 Construct new CAN frame ID from a packet.
 
bool vlcb_net_adpt_IsPacketValid (const VlcbNetAdptPkt *const packet)
 

Function Documentation

◆ vlcb_net_adpt_IsPacketValid()

bool vlcb_net_adpt_IsPacketValid ( const VlcbNetAdptPkt *const packet)

Valid packet needs to have: CAN medium flag Payload must be smaller or equal to the MTU of the CAN device Payload must have size 0 if rtr flag is set CAN ID of this device must be in a valid range CAN Priority must be in range of known values

Definition at line 71 of file packet_parse.c.

Here is the call graph for this function:

◆ vlcb_net_adpt_NewCanFrameIdFromPkt()

int vlcb_net_adpt_NewCanFrameIdFromPkt ( const VlcbNetAdptPkt *const packet,
VlcbCanFrameId *const id )
inline

Construct new CAN frame ID from a packet.

This method is useful when constructing outbound packets, provides minimal validation to the packet and maps certain values, like priority, based on the OPCODE.

It is worthy to note that unknown priority values get alias to the default one.

Parameters
[in]packetThe device packet we're about to send out
[out]idThe variable to store the constructed frame id
Returns
Whether the ID was constructed successfully
Return values
0The id is valid
1The id is invalid

Definition at line 52 of file packet_parse.c.

Here is the call graph for this function:

◆ vlcb_net_adpt_ParseRawCanData()

VlcbNetAdptErr vlcb_net_adpt_ParseRawCanData ( VlcbCanFrameId id,
bool is_rtr,
uint8_t payload_len,
const VlcbNetAdptPayload *const payload,
VlcbNetAdptPkt *const packet )
inline

Parse the CAN packet data into the inner format.

This function validates and constructs a new VlcbNetAdptPacket from raw data and flags passed in from the device deriver adapter. Device driver adapters should use this function instead of their own implementation, unless it's desirable.

It is worthy to note that unknown priority values get aliased to the default one.

Parameters
[in]idThe raw value of CAN ID (11 bits, does not have to be masked)
[in]is_rtrWhether the received CAN frame had RTR flag set
[in]payload_lenLength of the received payload. [0, 8]
[in]payloadThe payload buffer containing data from received CAN frame
[out]packetDestination memory space for the constructed packets
Returns
The error code (returns VLCB_NET_ADPT_ERR_OK when there is no error)

Definition at line 9 of file packet_parse.c.

Here is the call graph for this function: