feat(protocan): добавь общий ABI для GUI
This commit is contained in:
74
c/protocan-transport/include/pcan_abi.h
Normal file
74
c/protocan-transport/include/pcan_abi.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* @file pcan_abi.h
|
||||
* @brief Stable C ABI for desktop, Android and other foreign runtimes.
|
||||
*
|
||||
* The firmware-facing API remains allocation free. This header exposes
|
||||
* scalar arguments and explicitly sized buffers so ctypes/JNI/Swift can use
|
||||
* the same C99 implementation without reproducing the wire protocol.
|
||||
*/
|
||||
#ifndef PCAN_ABI_H
|
||||
#define PCAN_ABI_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(_WIN32) && defined(PCAN_ABI_BUILD_DLL)
|
||||
# define PCAN_ABI_API __declspec(dllexport)
|
||||
#elif defined(_WIN32) && defined(PCAN_ABI_USE_DLL)
|
||||
# define PCAN_ABI_API __declspec(dllimport)
|
||||
#elif defined(__GNUC__) && (__GNUC__ >= 4)
|
||||
# define PCAN_ABI_API __attribute__((visibility("default")))
|
||||
#else
|
||||
# define PCAN_ABI_API
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PCAN_ABI_VERSION 1U
|
||||
|
||||
typedef struct {
|
||||
uint32_t can_id;
|
||||
uint8_t sequence;
|
||||
uint8_t flags;
|
||||
uint8_t dlc;
|
||||
uint8_t data[8];
|
||||
} pcan_abi_frame_t;
|
||||
|
||||
PCAN_ABI_API uint32_t pcan_abi_version(void);
|
||||
|
||||
PCAN_ABI_API uint32_t pcan_abi_id_pack(uint8_t priority, uint8_t route,
|
||||
uint8_t device_type, uint8_t device_id,
|
||||
uint8_t message_type, uint16_t body);
|
||||
|
||||
PCAN_ABI_API void pcan_abi_id_unpack(uint32_t raw, uint8_t *priority,
|
||||
uint8_t *route, uint8_t *device_type,
|
||||
uint8_t *device_id, uint8_t *message_type,
|
||||
uint16_t *body);
|
||||
|
||||
PCAN_ABI_API uint16_t pcan_abi_crc16(const uint8_t *data, size_t size);
|
||||
|
||||
PCAN_ABI_API size_t pcan_abi_frame_encode(uint8_t sequence, uint8_t flags,
|
||||
uint32_t can_id,
|
||||
const uint8_t *data, uint8_t dlc,
|
||||
uint8_t *output,
|
||||
size_t output_size);
|
||||
|
||||
/* The caller owns parser_storage; no allocation is performed by the core. */
|
||||
PCAN_ABI_API size_t pcan_abi_parser_size(void);
|
||||
PCAN_ABI_API int pcan_abi_parser_init(void *parser_storage,
|
||||
size_t storage_size);
|
||||
PCAN_ABI_API int pcan_abi_parser_push(void *parser_storage, uint8_t byte,
|
||||
pcan_abi_frame_t *output);
|
||||
PCAN_ABI_API int pcan_abi_parser_stats(const void *parser_storage,
|
||||
uint32_t *frames,
|
||||
uint32_t *crc_errors,
|
||||
uint32_t *bad_length,
|
||||
uint32_t *stray_bytes);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* PCAN_ABI_H */
|
||||
Reference in New Issue
Block a user