Skip to content

Commit 051f257

Browse files
committed
Test CANBridge link
1 parent f487192 commit 051f257

37 files changed

+3363
-47
lines changed

CANBridge/candlelib/candle.h

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
/*
2+
3+
Copyright (c) 2016 Hubert Denkmair <hubert@denkmair.de>
4+
5+
This file is part of the candle windows API.
6+
7+
This library is free software: you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation, either
10+
version 3 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library. If not, see <http://www.gnu.org/licenses/>.
19+
20+
*/
21+
22+
#pragma once
23+
#include <stdint.h>
24+
#include <stdbool.h>
25+
26+
#ifdef USING_WINDOWS_ERR_DECODE
27+
#include <windows.h>
28+
#endif
29+
30+
// Use overlapped IO on TX as well as RX
31+
// #define USING_OVERLAPPED_IO_ON_TX
32+
33+
#ifdef __cplusplus
34+
extern "C" {
35+
#endif
36+
37+
typedef void* candle_list_handle;
38+
typedef void* candle_handle;
39+
40+
typedef enum {
41+
CANDLE_DEVSTATE_AVAIL,
42+
CANDLE_DEVSTATE_INUSE
43+
} candle_devstate_t;
44+
45+
typedef enum {
46+
CANDLE_FRAMETYPE_UNKNOWN,
47+
CANDLE_FRAMETYPE_RECEIVE,
48+
CANDLE_FRAMETYPE_ECHO,
49+
CANDLE_FRAMETYPE_ERROR,
50+
CANDLE_FRAMETYPE_TIMESTAMP_OVFL
51+
} candle_frametype_t;
52+
53+
typedef enum {
54+
CANDLE_MODE_NORMAL = 0x00,
55+
CANDLE_MODE_LISTEN_ONLY = 0x01,
56+
CANDLE_MODE_LOOP_BACK = 0x02,
57+
CANDLE_MODE_TRIPLE_SAMPLE = 0x04,
58+
CANDLE_MODE_ONE_SHOT = 0x08,
59+
CANDLE_MODE_HW_TIMESTAMP = 0x10,
60+
CANDLE_MODE_PAD_PKTS_TO_MAX_PKT_SIZE = 0x80
61+
} candle_device_mode_flags_t;
62+
63+
typedef enum {
64+
CANDLE_FEATURE_NORMAL = 0x00,
65+
CANDLE_FEATURE_LISTEN_ONLY = 0x01,
66+
CANDLE_FEATURE_LOOP_BACK = 0x02,
67+
CANDLE_FEATURE_TRIPLE_SAMPLE = 0x04,
68+
CANDLE_FEATURE_ONE_SHOT = 0x08,
69+
CANDLE_FEATURE_HW_TIMESTAMP = 0x10,
70+
CANDLE_FEATURE_IDENTIFY = 0x20,
71+
CANDLE_FEATURE_USER_ID = 0x40,
72+
CANDLE_FEATURE_PAD_PKTS_TO_MAX_PKT_SIZE = 0x80
73+
} candle_feature_t;
74+
75+
typedef enum {
76+
CANDLE_ERR_OK = 0,
77+
CANDLE_ERR_CREATE_FILE = 1,
78+
CANDLE_ERR_WINUSB_INITIALIZE = 2,
79+
CANDLE_ERR_QUERY_INTERFACE = 3,
80+
CANDLE_ERR_QUERY_PIPE = 4,
81+
CANDLE_ERR_PARSE_IF_DESCR = 5,
82+
CANDLE_ERR_SET_HOST_FORMAT = 6,
83+
CANDLE_ERR_GET_DEVICE_INFO = 7,
84+
CANDLE_ERR_GET_BITTIMING_CONST = 8,
85+
CANDLE_ERR_PREPARE_READ = 9,
86+
CANDLE_ERR_SET_DEVICE_MODE = 10,
87+
CANDLE_ERR_SET_BITTIMING = 11,
88+
CANDLE_ERR_BITRATE_FCLK = 12,
89+
CANDLE_ERR_BITRATE_UNSUPPORTED = 13,
90+
CANDLE_ERR_SEND_FRAME = 14,
91+
CANDLE_ERR_READ_TIMEOUT = 15,
92+
CANDLE_ERR_READ_WAIT = 16,
93+
CANDLE_ERR_READ_RESULT = 17,
94+
CANDLE_ERR_READ_SIZE = 18,
95+
CANDLE_ERR_SETUPDI_IF_DETAILS = 19,
96+
CANDLE_ERR_SETUPDI_IF_DETAILS2 = 20,
97+
CANDLE_ERR_MALLOC = 21,
98+
CANDLE_ERR_PATH_LEN = 22,
99+
CANDLE_ERR_CLSID = 23,
100+
CANDLE_ERR_GET_DEVICES = 24,
101+
CANDLE_ERR_SETUPDI_IF_ENUM = 25,
102+
CANDLE_ERR_SET_TIMESTAMP_MODE = 26,
103+
CANDLE_ERR_DEV_OUT_OF_RANGE = 27,
104+
CANDLE_ERR_GET_TIMESTAMP = 28,
105+
CANDLE_ERR_SET_PIPE_RAW_IO = 29,
106+
CANDLE_ERR_DEVICE_FEATURE_UNAVAILABLE = 30,
107+
CANDLE_ERR_WRITE_WAIT = 31,
108+
CANDLE_ERR_WRITE_TIMEOUT_PRE = 32,
109+
CANDLE_ERR_WRITE_TIMEOUT = 33,
110+
CANDLE_ERR_WRITE_RESULT = 34,
111+
CANDLE_ERR_WRITE_SIZE = 35,
112+
} candle_err_t;
113+
114+
#pragma pack(push,1)
115+
116+
typedef struct {
117+
uint32_t echo_id;
118+
uint32_t can_id;
119+
uint8_t can_dlc;
120+
uint8_t channel;
121+
uint8_t flags;
122+
uint8_t reserved;
123+
uint8_t data[8];
124+
uint32_t timestamp_us;
125+
} candle_frame_t;
126+
127+
typedef struct {
128+
uint32_t feature;
129+
uint32_t fclk_can;
130+
uint32_t tseg1_min;
131+
uint32_t tseg1_max;
132+
uint32_t tseg2_min;
133+
uint32_t tseg2_max;
134+
uint32_t sjw_max;
135+
uint32_t brp_min;
136+
uint32_t brp_max;
137+
uint32_t brp_inc;
138+
} candle_capability_t;
139+
140+
typedef struct {
141+
uint32_t prop_seg;
142+
uint32_t phase_seg1;
143+
uint32_t phase_seg2;
144+
uint32_t sjw;
145+
uint32_t brp;
146+
} candle_bittiming_t;
147+
148+
#pragma pack(pop)
149+
150+
// Static Lib
151+
#define DLL
152+
#define __stdcall
153+
154+
DLL bool __stdcall candle_list_scan(candle_list_handle *list);
155+
DLL bool __stdcall candle_list_free(candle_list_handle list);
156+
DLL bool __stdcall candle_list_length(candle_list_handle list, uint8_t *len);
157+
158+
DLL bool __stdcall candle_dev_get(candle_list_handle list, uint8_t dev_num, candle_handle *hdev);
159+
DLL bool __stdcall candle_dev_get_state(candle_handle hdev, candle_devstate_t *state);
160+
DLL wchar_t * __stdcall candle_dev_get_path(candle_handle hdev);
161+
DLL char * __stdcall candle_dev_get_name(candle_handle hdev);
162+
DLL bool __stdcall candle_dev_open(candle_handle hdev);
163+
DLL bool __stdcall candle_dev_get_timestamp_us(candle_handle hdev, uint32_t *timestamp_us);
164+
DLL bool __stdcall candle_dev_close(candle_handle hdev);
165+
DLL bool __stdcall candle_dev_free(candle_handle hdev);
166+
167+
DLL bool __stdcall candle_channel_count(candle_handle hdev, uint8_t *num_channels);
168+
DLL bool __stdcall candle_channel_get_capabilities(candle_handle hdev, uint8_t ch, candle_capability_t *cap);
169+
DLL bool __stdcall candle_channel_set_timing(candle_handle hdev, uint8_t ch, candle_bittiming_t *data);
170+
DLL bool __stdcall candle_channel_set_bitrate(candle_handle hdev, uint8_t ch, uint32_t bitrate);
171+
DLL bool __stdcall candle_channel_start(candle_handle hdev, uint8_t ch, candle_device_mode_flags_t device_mode_flags);
172+
DLL bool __stdcall candle_channel_stop(candle_handle hdev, uint8_t ch);
173+
174+
DLL bool __stdcall candle_frame_send(candle_handle hdev, uint8_t ch, candle_frame_t *frame,bool wait_send,uint32_t timeout_ms);
175+
DLL bool __stdcall candle_frame_read(candle_handle hdev, candle_frame_t *frame, uint32_t timeout_ms);
176+
177+
DLL candle_frametype_t __stdcall candle_frame_type(candle_frame_t *frame);
178+
DLL uint32_t __stdcall candle_frame_id(candle_frame_t *frame);
179+
DLL bool __stdcall candle_frame_is_extended_id(candle_frame_t *frame);
180+
DLL bool __stdcall candle_frame_is_rtr(candle_frame_t *frame);
181+
DLL uint8_t __stdcall candle_frame_dlc(candle_frame_t *frame);
182+
DLL uint8_t * __stdcall candle_frame_data(candle_frame_t *frame);
183+
DLL uint32_t __stdcall candle_frame_timestamp_us(candle_frame_t *frame);
184+
185+
DLL candle_err_t __stdcall candle_dev_last_error(candle_handle hdev);
186+
DLL const char * __stdcall candle_error_text(candle_err_t errnum);
187+
#ifdef USING_WINDOWS_ERR_DECODE
188+
DLL DWORD __stdcall candle_dev_last_windows_error(candle_handle hdev);
189+
DLL void __stdcall candle_windows_error_text(DWORD errnum, wchar_t* buffer, size_t buflen);
190+
#else
191+
#define DWORD int
192+
//int GetLastError() {return 0;}
193+
#endif
194+
195+
// This is a convenience function to initialize a single device and start a channel on it
196+
DLL candle_err_t __stdcall candle_init_single_device(uint8_t device_num, uint8_t device_channel, uint32_t bitrate, candle_device_mode_flags_t device_mode_flags, candle_list_handle *plist, candle_handle *phdev);
197+
198+
#ifdef __cplusplus
199+
}
200+
#endif

CANBridge/candlelib/candle_ctrl_req.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
3+
Copyright (c) 2016 Hubert Denkmair <hubert@denkmair.de>
4+
5+
This file is part of the candle windows API.
6+
7+
This library is free software: you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation, either
10+
version 3 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library. If not, see <http://www.gnu.org/licenses/>.
19+
20+
*/
21+
22+
#pragma once
23+
24+
#include "candle_defs.h"
25+
26+
enum {
27+
CANDLE_DEVMODE_RESET = 0,
28+
CANDLE_DEVMODE_START = 1
29+
};
30+
31+
bool candle_ctrl_set_host_format(candle_device_t *dev);
32+
bool candle_ctrl_set_timestamp_mode(candle_device_t *dev, bool enable_timestamps);
33+
bool candle_ctrl_set_device_mode(candle_device_t *dev, uint8_t channel, uint32_t mode,candle_device_mode_flags_t device_mode_flags );
34+
bool candle_ctrl_get_config(candle_device_t *dev, candle_device_config_t *dconf);
35+
bool candle_ctrl_get_capability(candle_device_t *dev, uint8_t channel, candle_capability_t *data);
36+
bool candle_ctrl_set_bittiming(candle_device_t *dev, uint8_t channel, candle_bittiming_t *data);
37+
bool candle_ctrl_get_timestamp(candle_device_t *dev, uint32_t *current_timestamp);
38+
bool candle_ctrl_set_user_id(candle_device_t *dev, uint8_t channel, uint32_t id);
39+
bool candle_ctrl_get_user_id(candle_device_t *dev, uint32_t *id);
40+

CANBridge/candlelib/candle_defs.h

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
3+
Copyright (c) 2016 Hubert Denkmair <hubert@denkmair.de>
4+
5+
This file is part of the candle windows API.
6+
7+
This library is free software: you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation, either
10+
version 3 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library. If not, see <http://www.gnu.org/licenses/>.
19+
20+
*/
21+
22+
#pragma once
23+
24+
// Ignore windows library warnings
25+
#pragma warning(push, 0)
26+
27+
#include <stdint.h>
28+
#include <windows.h>
29+
#include <winbase.h>
30+
#include <winusb.h>
31+
#include <setupapi.h>
32+
#include <devguid.h>
33+
#include <regstr.h>
34+
35+
#undef __CRT__NO_INLINE
36+
#include <strsafe.h>
37+
#define __CRT__NO_INLINE
38+
39+
#pragma warning(pop)
40+
41+
#include "candle.h"
42+
43+
#define CANDLE_MAX_DEVICES 32
44+
#define CANDLE_URB_COUNT 30
45+
46+
#pragma pack(push,1)
47+
48+
typedef struct {
49+
uint32_t byte_order;
50+
} candle_host_config_t;
51+
52+
typedef struct {
53+
uint8_t reserved1;
54+
uint8_t reserved2;
55+
uint8_t reserved3;
56+
uint8_t icount;
57+
uint32_t sw_version;
58+
uint32_t hw_version;
59+
} candle_device_config_t;
60+
61+
typedef struct {
62+
uint32_t mode;
63+
uint32_t flags;
64+
} candle_device_mode_t;
65+
66+
#pragma pack(pop)
67+
68+
69+
typedef struct {
70+
OVERLAPPED ovl;
71+
uint8_t buf[64]; // Set this to max packet size for full speed usb. We may use less
72+
uint32_t send_size;
73+
} candle_tx_rx_urb;
74+
75+
typedef struct {
76+
wchar_t path[256];
77+
char name[256];
78+
candle_devstate_t state;
79+
candle_err_t last_error;
80+
DWORD windows_last_error;
81+
82+
HANDLE deviceHandle;
83+
WINUSB_INTERFACE_HANDLE winUSBHandle;
84+
UCHAR interfaceNumber;
85+
86+
UCHAR bulkInPipe;
87+
WINUSB_PIPE_INFORMATION bulkInPipeInfo;
88+
89+
UCHAR bulkOutPipe;
90+
WINUSB_PIPE_INFORMATION bulkOutPipeInfo;
91+
92+
candle_device_config_t dconf;
93+
candle_capability_t bt_const;
94+
95+
#ifdef USING_OVERLAPPED_IO_ON_TX
96+
candle_tx_rx_urb txurbs[CANDLE_URB_COUNT];
97+
HANDLE txevents[CANDLE_URB_COUNT];
98+
uint32_t txurbs_in_use;
99+
#endif
100+
101+
candle_tx_rx_urb rxurbs[CANDLE_URB_COUNT];
102+
HANDLE rxevents[CANDLE_URB_COUNT];
103+
104+
candle_device_mode_flags_t device_mode_flags;
105+
} candle_device_t;
106+
107+
typedef struct {
108+
uint8_t num_devices;
109+
candle_err_t last_error;
110+
candle_device_t dev[CANDLE_MAX_DEVICES];
111+
} candle_list_t;

CANBridge/candlelib/ch_9.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
3+
Copyright (c) 2016 Hubert Denkmair <hubert@denkmair.de>
4+
5+
This file is part of the candle windows API.
6+
7+
This library is free software: you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation, either
10+
version 3 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library. If not, see <http://www.gnu.org/licenses/>.
19+
20+
*/
21+
22+
#pragma once
23+
24+
#define USB_DIR_OUT 0 /* to device */
25+
#define USB_DIR_IN 0x80 /* to host */
26+
27+
#define USB_TYPE_MASK (0x03 << 5)
28+
#define USB_TYPE_STANDARD (0x00 << 5)
29+
#define USB_TYPE_CLASS (0x01 << 5)
30+
#define USB_TYPE_VENDOR (0x02 << 5)
31+
#define USB_TYPE_RESERVED (0x03 << 5)
32+
33+
#define USB_RECIP_MASK 0x1f
34+
#define USB_RECIP_DEVICE 0x00
35+
#define USB_RECIP_INTERFACE 0x01
36+
#define USB_RECIP_ENDPOINT 0x02
37+
#define USB_RECIP_OTHER 0x03
File renamed without changes.

0 commit comments

Comments
 (0)