Apollo  6.0
Open source self driving car software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bcan.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2017 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 #pragma once
18 
19 #include <sys/ioctl.h>
20 #include <sys/types.h>
21 #include <cstdint>
22 #include <cstdlib>
23 
24 /* bcan_msg_t and bcan_err_code definitions. */
25 // #include "linux/bcan_defs.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #define BCAN_MAX_TX_MSG 256
33 #define BCAN_MAX_RX_MSG 256
34 
35 // Channel states
36 #define BCAN_DEV_UNINIT -1
37 #define BCAN_DEV_OPEN (1 << 0)
38 #define BCAN_DEV_CLOSE (1 << 1)
39 #define BCAN_DEV_BAUD_SET (1 << 2)
40 #define BCAN_DEV_NORMAL (1 << 3)
41 #define BCAN_DEV_LOOPBACK (1 << 4)
42 #define BCAN_DEV_CONFIG (1 << 5)
43 #define BCAN_DEV_START (1 << 6)
44 #define BCAN_DEV_STOP (1 << 7)
45 #define BCAN_DEV_ACTIVE (1 << 8)
46 #define BCAN_DEV_RECVD (1 << 9)
47 
48 typedef uint64_t bcan_hdl_t;
49 
56 };
57 
58 /* Returns bcan library version. */
59 const char *bcan_get_libversion(void);
60 
61 /* Returns detailed bcan library build info. */
62 const char *bcan_bld_info(void);
63 
64 /* Returns brief bcan library build info. */
65 const char *bcan_bld_info_short(void);
66 
67 /* Returns error message corresponding to the given error code. */
68 const char *bcan_get_err_msg(int err_code);
69 
70 int bcan_open(uint32_t dev_index, uint32_t flags, uint64_t tx_to,
71  uint64_t rx_to, bcan_hdl_t *hdl);
72 int bcan_close(bcan_hdl_t hdl);
73 int bcan_start(bcan_hdl_t hdl);
74 int bcan_stop(bcan_hdl_t hdl);
75 
76 int bcan_set_loopback(bcan_hdl_t hdl);
77 int bcan_unset_loopback(bcan_hdl_t hdl);
78 int bcan_set_baudrate(bcan_hdl_t hdl, uint32_t rate);
79 int bcan_get_baudrate(bcan_hdl_t hdl, uint32_t *rate);
80 int bcan_recv(bcan_hdl_t hdl, bcan_msg_t *buf, uint32_t num_msg);
81 int bcan_send(bcan_hdl_t hdl, bcan_msg_t *buf, uint32_t num_msg);
82 int bcan_send_hi_pri(bcan_hdl_t hdl, bcan_msg_t *buf);
83 int bcan_get_status(bcan_hdl_t hdl);
84 int bcan_get_err_counter(bcan_hdl_t hdl, uint8_t *rx_err, uint8_t *tx_err);
85 
86 /* The following APIs are not implemented yet. { */
87 int bcan_id_add(bcan_hdl_t hdl, uint32_t id_start, uint32_t id_end);
88 int bcan_id_add_all(bcan_hdl_t hdl);
89 int bcan_id_remove(bcan_hdl_t hdl, uint32_t id_start, uint32_t id_end);
90 int bcan_id_remove_all(bcan_hdl_t hdl);
91 /* } Not implemented. */
92 
93 #ifdef __cplusplus
94 }
95 #endif
int bcan_recv(bcan_hdl_t hdl, bcan_msg_t *buf, uint32_t num_msg)
const char * bcan_get_libversion(void)
int bcan_set_loopback(bcan_hdl_t hdl)
int bcan_send_hi_pri(bcan_hdl_t hdl, bcan_msg_t *buf)
const char * bcan_bld_info_short(void)
Definition: bcan.h:55
Definition: bcan.h:54
int bcan_id_remove_all(bcan_hdl_t hdl)
int bcan_id_add_all(bcan_hdl_t hdl)
int bcan_stop(bcan_hdl_t hdl)
int bcan_send(bcan_hdl_t hdl, bcan_msg_t *buf, uint32_t num_msg)
int bcan_unset_loopback(bcan_hdl_t hdl)
Definition: bcan.h:52
int bcan_set_baudrate(bcan_hdl_t hdl, uint32_t rate)
bcan_baudrate_val
Definition: bcan.h:50
int bcan_id_remove(bcan_hdl_t hdl, uint32_t id_start, uint32_t id_end)
int bcan_get_baudrate(bcan_hdl_t hdl, uint32_t *rate)
uint64_t bcan_hdl_t
Definition: bcan.h:48
Definition: bcan.h:51
int bcan_id_add(bcan_hdl_t hdl, uint32_t id_start, uint32_t id_end)
int bcan_get_err_counter(bcan_hdl_t hdl, uint8_t *rx_err, uint8_t *tx_err)
const char * bcan_get_err_msg(int err_code)
int bcan_open(uint32_t dev_index, uint32_t flags, uint64_t tx_to, uint64_t rx_to, bcan_hdl_t *hdl)
int bcan_get_status(bcan_hdl_t hdl)
Definition: bcan_defs.h:28
Definition: bcan.h:53
int bcan_close(bcan_hdl_t hdl)
int bcan_start(bcan_hdl_t hdl)
const char * bcan_bld_info(void)