VLCB SDK
An opinionated SDK for VLCB protocol
Loading...
Searching...
No Matches
iface_can.c
Go to the documentation of this file.
1#include <stdbool.h>
2#include <stddef.h>
3#include <string.h>
4
5#include "iface_vlcb.h"
6#include "vlcb/net/adapter.h"
7#include "vlcb/net/iface.h"
9#include "vlcb/platform/log.h"
10
13 VlcbOpCode opc = *payload[0];
14 // TODO: should we validate opcodes?
15 // {
16 // int err = vlcb_defs_OpcodeFromByte(*payload[0], &opc);
17 // if (err != 0) {
18 // VLCBLOG_ERROR("invalid opcode, dropping packet");
19 // return;
20 // }
21 // }
22
23 VlcbNetPacket vlcb_pkt;
24 {
26 err = vlcb_net_pkt_New(opc, pkt->payload_len,
27 (VlcbNetPayload *)(payload + 1), &vlcb_pkt);
30 return;
31 }
32 }
33
34 ProcessVlcbPacket(iface, &vlcb_pkt);
35}
36
38 const VlcbNetPacket *const packet) {
39 VlcbNetAdptPkt adpt_pkt;
40
41 adpt_pkt.medium = VLCB_MEDIUM_CAN;
42 adpt_pkt.meta.can.is_rtr = false;
43 adpt_pkt.payload_len = 1 + packet->payload_len;
44
45 if (packet->payload_len) {
46 memcpy(&adpt_pkt.payload + 1, packet->payload, packet->payload_len);
47 }
48
49 VlcbNetAdptErr err = _INTERFACE_PTR_CALL(iface->adpt, SendPkt, &adpt_pkt);
50
51 return err;
52}
VlcbNetAdptErr
Definition adapter.h:39
uint8_t VlcbNetAdptPayload[8]
Definition adapter.h:11
@ VLCB_MEDIUM_CAN
Definition addr.h:6
VlcbNetAdptErr DispatchCanPacket(VlcbNetIface *const iface, const VlcbNetPacket *const packet)
Definition iface_can.c:37
void ProcessCanPacket(VlcbNetIface *const iface, VlcbNetAdptPkt *pkt)
Definition iface_can.c:11
void ProcessVlcbPacket(VlcbNetIface *const iface, VlcbNetPacket *const packet)
Definition iface_vlcb.c:9
#define _INTERFACE_PTR_CALL(o, m,...)
Definition interface.h:28
#define VLCBLOG_ERROR(msg)
Definition log.h:31
VlcbNetAdptPktMeta meta
Definition adapter.h:30
VlcbNetMedium medium
Definition adapter.h:28
uint8_t payload_len
Definition adapter.h:31
VlcbNetAdptPayload payload
Definition adapter.h:32
IVlcbNetAdpt *const adpt
Definition iface.h:11
VlcbNetPayload payload
Definition vlcb.h:37
uint8_t payload_len
Definition vlcb.h:36
VlcbNetAdptCanPktMeta can
Definition adapter.h:17
uint8_t VlcbNetPayload[7]
Definition vlcb.h:17
vlcb_error vlcb_net_pkt_ConstructErrToStr(VlcbNetPacketConstructErr err)
Definition vlcb.c:15
VlcbNetPacketConstructErr vlcb_net_pkt_New(VlcbOpCode opc, uint8_t payload_len, const VlcbNetPayload *const payload, VlcbNetPacket *const packet)
Definition vlcb.c:35
VlcbNetPacketConstructErr
Definition vlcb.h:40
@ VLCB_NET_PKT_CONSTRUCT_ERR_OK
Definition vlcb.h:41
VlcbOpCode
Definition vlcb_defs.h:493