VLCB SDK
An opinionated SDK for VLCB protocol
Loading...
Searching...
No Matches
packet_parse.h File Reference
#include <stdint.h>
#include "../../adapter.h"
Include dependency graph for packet_parse.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef uint16_t VlcbCanFrameId
 CAN frame id used in transmission.
 

Functions

VlcbNetAdptErr vlcb_net_adpt_ParseRawCanData (VlcbCanFrameId id, bool is_rtr, 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_IsCanAdptPktValid (const VlcbNetAdptPkt *const packet)
 Check if the packed passed in is correctly constructed.
 

Typedef Documentation

◆ VlcbCanFrameId

typedef uint16_t VlcbCanFrameId

CAN frame id used in transmission.

This type is used to store the CAN ID (11 bits wide). First 7 bits contain the VlcbCanId (node alias used on CAN bus). Rest of the bits contain the VlcbCanPriority (CAN bus priority used to prioritize some OPCODEs over others).

Definition at line 16 of file packet_parse.h.

Function Documentation

◆ vlcb_net_adpt_IsCanAdptPktValid()

bool vlcb_net_adpt_IsCanAdptPktValid ( const VlcbNetAdptPkt *const packet)

Check if the packed passed in is correctly constructed.

Valiates the packet to check if it is a valid packet targeted for the CAN bus.

Parameters
[in]packetThe packet to be validated
Returns
Whether the packet is valid CAN bus packet or not
Return values
trueThe packet is valid
falseThe packet is invalid

◆ 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: