candleLight, CANable, CANnectivity and cantact adapters speak gs_usb. On Linux and macOS the kernel driver exposes them as SocketCAN interfaces, so SavvyCAN already reached them through Qt SerialBus. Windows has no such driver, which left those adapters unusable there. Add a GSUSBConnection that talks to the hardware directly over WinUSB: - one connection per physical device, one SavvyCAN bus per CAN channel - CAN FD including BRS, plus RTR, extended IDs and error frames - known good bit timings for 16/48/80/160/170 MHz device clocks, with a generic solver for clocks the tables do not cover - hardware timestamps, unwrapped across the 32 bit rollover and anchored to the host clock so they line up with the rest of SavvyCAN gs_usb multiplexes every channel over a single USB bulk IN endpoint, so a single reader thread drains it and hands frames to the connection thread in batches, coalescing the wakeups. That keeps one producer on the lock free queue, which the tx echo path already writes to. Device scans skip adapters that a live connection holds. candle_dev_open() shares the file handle and queues read URBs immediately, so probing a device in use would consume frames the open connection is waiting for. connections/candle_api is an unmodified copy of the candle Windows API, LGPL 3.0 rather than MIT and only compiled into Windows builds. See its README for provenance. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XZnuZJ7zc3e8hk6C8bGDZN
102 lines
2.3 KiB
C
102 lines
2.3 KiB
C
/*
|
|
|
|
Copyright (c) 2016 Hubert Denkmair <hubert@denkmair.de>
|
|
Copyright (c) 2026 Schildkroet
|
|
|
|
This file is part of the candle windows API.
|
|
|
|
This library is free software: you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation, either
|
|
version 3 of the License, or (at your option) any later version.
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
#ifndef _WIN32_WINNT
|
|
#define _WIN32_WINNT 0x0600
|
|
#endif
|
|
|
|
#include <windows.h>
|
|
#include <winbase.h>
|
|
#include <winusb.h>
|
|
#include <setupapi.h>
|
|
#include <devguid.h>
|
|
#include <regstr.h>
|
|
|
|
#undef __CRT__NO_INLINE
|
|
#include <strsafe.h>
|
|
#define __CRT__NO_INLINE
|
|
|
|
#include "candle.h"
|
|
|
|
#define CANDLE_MAX_DEVICES 32
|
|
#define CANDLE_URB_COUNT 30
|
|
|
|
#pragma pack(push,1)
|
|
|
|
typedef struct {
|
|
uint32_t byte_order;
|
|
} candle_host_config_t;
|
|
|
|
typedef struct {
|
|
uint8_t reserved1;
|
|
uint8_t reserved2;
|
|
uint8_t reserved3;
|
|
uint8_t icount;
|
|
uint32_t sw_version;
|
|
uint32_t hw_version;
|
|
} candle_device_config_t;
|
|
|
|
typedef struct {
|
|
uint32_t mode;
|
|
uint32_t flags;
|
|
} candle_device_mode_t;
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
typedef struct {
|
|
OVERLAPPED ovl;
|
|
bool pending;
|
|
uint8_t buf[512];
|
|
} canlde_rx_urb;
|
|
|
|
typedef struct {
|
|
wchar_t path[256];
|
|
candle_devstate_t state;
|
|
candle_err_t last_error;
|
|
|
|
HANDLE deviceHandle;
|
|
WINUSB_INTERFACE_HANDLE winUSBHandle;
|
|
UCHAR interfaceNumber;
|
|
UCHAR bulkInPipe;
|
|
UCHAR bulkOutPipe;
|
|
HANDLE txEvent; /* pre-allocated event for timed overlapped writes */
|
|
|
|
candle_device_config_t dconf;
|
|
candle_capability_t bt_const;
|
|
/* Per-channel capabilities: index 0..dconf.icount, maximum 8 channels */
|
|
candle_capability_t ch_caps[8];
|
|
canlde_rx_urb rxurbs[CANDLE_URB_COUNT];
|
|
HANDLE rxevents[CANDLE_URB_COUNT];
|
|
} candle_device_t;
|
|
|
|
typedef struct {
|
|
uint8_t num_devices;
|
|
candle_err_t last_error;
|
|
candle_device_t dev[CANDLE_MAX_DEVICES];
|
|
} candle_list_t;
|
|
|