Cross-platform CAN communication system based on Qt
By using a Qt-based cross-platform CAN communication system, cross-platform adaptation of CAN communication modules is achieved, development efficiency is improved, and high performance and security are enhanced. This solves the problems of high difficulty in cross-platform adaptation, low development efficiency, performance and thread safety risks, and poor scalability in existing technologies. It is suitable for industrial control, automotive electronics, and smart devices.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-05
- Publication Date
- 2026-03-10
AI Technical Summary
Existing CAN communication modules suffer from problems such as difficulty in cross-platform adaptation, low development efficiency, performance and thread safety risks, and poor scalability.
A cross-platform CAN communication system based on Qt is adopted. Through layered design, modular architecture and configuration definition differentiation, the CAN communication function is decoupled, reused and adapted to cross platforms. It includes CAN communication device, CAN extended frame parsing module, CAN extended frame generation module and CAN communication management module. The modules work together to provide a unified management interface and optimization algorithm.
It achieves cross-platform compatibility, running on Windows and Linux systems without code modification, improving development efficiency, enhancing code reusability, ensuring high performance and thread safety, supporting personalized needs, and reducing maintenance costs.
Smart Images

Figure CN121644705A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of CAN (Controller Area Network) communication technology, specifically to a cross-platform CAN communication system based on Qt. Background Technology
[0002] CAN communication, due to its high reliability, real-time performance, and anti-interference capabilities, has been widely used in automotive electronics, industrial automation, and smart instruments. With the diversification of development scenarios, developers are placing higher demands on the cross-platform adaptability, development efficiency, and code reusability of CAN communication modules. However, existing technologies suffer from the following significant drawbacks: Cross-platform adaptation is challenging. Existing CAN communication modules often rely on the underlying drivers or interfaces of specific operating systems. For example, SocketCAN is commonly used in Linux systems (an implementation of the CAN communication protocol in Linux, which uses network stack and other technologies to implement the CAN device driver as a network interface), while Windows systems rely on other open-source or self-developed CAN communication drivers. Developers need to write differentiated code for different operating systems, which not only increases the workload but also easily leads to compatibility issues due to system differences, making it impossible to achieve "develop once, deploy on multiple platforms".
[0003] Development efficiency is low. Traditional CAN communication development requires implementing basic functions such as device initialization, protocol parsing, and data sending / receiving one by one. Moreover, code is difficult to reuse directly between different projects, and developers need to repeatedly write similar code, which prolongs the project cycle.
[0004] Performance and thread safety risks exist. Some CAN communication modules do not consider data contention issues in multi-threaded scenarios. When multiple threads send or receive CAN data simultaneously, problems such as data loss and frame corruption are likely to occur. At the same time, there is a lack of reasonable allocation of communication bandwidth and scheduling mechanism for data priority, and an over-reliance on bus arbitration mechanism. In high-concurrency scenarios, communication delays or data congestion are likely to occur, affecting system reliability.
[0005] Poor scalability. Existing modules often couple CAN device drivers, data parsing, and frame generation together. If new CAN devices or custom data parsing rules need to be adapted, the core code must be modified, which compromises the stability of the original architecture, increases maintenance costs, and makes it difficult to meet the personalized development needs of different industries and scenarios.
[0006] In summary, existing CAN communication modules suffer from technical problems such as difficulty in cross-platform adaptation, low development efficiency, performance and thread safety risks, and poor scalability. Summary of the Invention
[0007] This application provides a cross-platform CAN communication system based on Qt, which can solve the technical problems of high difficulty in cross-platform adaptation, low development efficiency, performance and thread safety risks, and poor scalability in the prior art.
[0008] This application provides a cross-platform CAN communication system based on Qt, the system comprising: CAN communication devices are used to drive and adapt CAN hardware devices, providing a unified and defined device interface. The CAN extended frame parsing module is used to convert received CAN extended frames into data structures that developers can directly use. The CAN extended frame generation module is used to convert developer-defined data structures into CAN extended frames. The CAN communication management module is used to: coordinate the entire CAN communication process and provide a unified management interface and optimization algorithm; Each module works collaboratively through Qt's signal and slot mechanism and interface abstraction, achieving an efficient development model of "loading modules - configuring protocols - direct use".
[0009] In one implementation, both the CAN extended frame parsing module and the CAN extended frame generation module support defining the mapping relationship between extended frames and data segments through configuration files.
[0010] In one implementation, the CAN communication management module includes a device registration and management submodule, which is used to: support automatic loading of default CAN devices in Linux and Windows systems, support custom device extensions, support device status monitoring, and detect the connection status, communication rate, and error codes of registered devices in real time.
[0011] In one implementation, the CAN communication management module includes a parsing tool and a transmission interface registration submodule, used to: support developers in registering custom CAN tools to achieve automatic conversion of "CAN extended frame → data structure".
[0012] In one embodiment, the CAN communication management module includes a message transmission management submodule, used to: support the configuration of transmission parameters, including: message retransmission count, periodic transmission period, and extended inter-frame transmission time interval; support transmission queue scheduling: adopting a "priority queue + time slice scheduling" mechanism to sort the messages to be sent according to priority, with high-priority messages scheduled first.
[0013] In one implementation, the CAN communication management module includes a data caching and acquisition submodule, which is used to: store both the structured data parsed by the receiving end and the original CAN frame in the cache based on the "CAN frame ID + timestamp" caching mechanism; automatically eliminate cached data according to timestamp; and support dynamic configuration of cache capacity and cache time.
[0014] In one implementation, the CAN communication management module includes an algorithm scheduling submodule, used for: performance optimization by employing a priority scheduling algorithm combining "static priority + dynamic adjustment" and a bandwidth reservation algorithm based on a "demand pre-allocation + dynamic reuse" mechanism.
[0015] In one implementation, the CAN communication management module includes a thread safety protection submodule, used to: control read and write operations of shared resources through mutex locks or read-write locks; provide a multi-threaded separation design so that the receiving thread, parsing thread, and sending thread run independently, and realize data transfer between threads through the Qt signal and slot mechanism.
[0016] In one implementation, the CAN communication management module includes an anomaly detection and fault tolerance submodule, used to: capture CAN bus bit errors and arbitration loss errors in real time, and trigger configurable fault tolerance strategies.
[0017] In one implementation, the CAN communication management module includes a log and debugging assistance submodule, used for: hierarchical log output, supporting custom log content: frame transmission and reception timing stamps, raw data bytes, parsing results, and error codes.
[0018] The beneficial effects of the technical solutions provided in this application include: This application's embodiments, through layered design, modular architecture, and differentiated configuration definitions, achieve decoupling, reuse, and cross-platform adaptation of CAN communication functions. The Qt-based cross-platform CAN communication system includes: a CAN communication device, a CAN extended frame parsing module, a CAN extended frame generation module, and a CAN communication management module. These modules work collaboratively to achieve an efficient development model of "loading modules - configuring protocols - direct use," achieving the following effects: (1) Achieve cross-platform adaptation: It can run on Windows and Linux systems without modifying the code, reducing the cross-platform adaptation cost for developers; (2) Improve development efficiency: Provide a "plug and play" modular design. Developers only need to load the module and configure the communication protocol to complete the development of CAN communication function, reducing repetitive coding work; (3) Enhance code reusability: Through base class abstraction and interface standardization, functions such as device driver, data parsing, and frame generation can be reused in different projects, reducing maintenance costs; (4) Ensure high performance and thread safety: Improve communication real-time performance through priority scheduling and bandwidth reservation algorithms, and avoid data competition through thread synchronization mechanism to ensure stable operation of the module in high concurrency scenarios; (5) Enhance scalability: Supports custom CAN devices, parsing rules and transmission logic to meet the personalized needs of different industry scenarios and reduce the technical threshold for function expansion.
[0019] Therefore, the embodiments of this application are geared towards generalization needs, effectively improving cross-platform adaptability and development efficiency, realizing "plug-and-play" modules, and possessing high performance, high reliability, and high scalability to meet personalized needs. Overall, they achieve the effect of cost reduction and efficiency improvement, and can meet the development needs of cross-platform, high performance, and high reliability CAN communication. They are suitable for scenarios requiring CAN communication, such as industrial control, automotive electronics, and smart devices. In particular, they provide developers with efficient, reusable, and thread-safe CAN communication development modules, which can be adapted to both Windows and Linux operating systems. They belong to the intersection of embedded communication and cross-platform software development technologies. Attached Figure Description
[0020] Figure 1 This is a schematic diagram of the overall architecture of the cross-platform CAN communication system based on Qt, as described in this application embodiment.
[0021] Figure 2 This is a schematic diagram illustrating the specific functions of the CAN communication management module in the embodiments of this application.
[0022] Figure 3 This is a schematic diagram of the data flow of the CAN communication management module in an embodiment of this application. Detailed Implementation
[0023] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.
[0024] First, some of the technical terms used in this application will be explained to help those skilled in the art understand this application.
[0025] Qt: Qt is a cross-platform C++ application framework widely used for developing applications with graphical user interfaces (GUIs). It can also be used to develop non-GUI programs, such as console tools and servers. Qt not only provides a rich set of interface components but also supports various functionalities such as networking, databases, and multithreading.
[0026] The Qt framework includes a series of modular C++ class libraries and development tools, enabling developers to create applications that are highly readable and maintainable.
[0027] Qt's core components include: Qt Core: Provides the core classes for non-GUI functionalities such as signals and slots, event handling, and time and date processing. Qt's signals and slots mechanism is a high-level event handling mechanism that allows communication between objects. When an object's state changes, it emits a signal, which other objects can respond to through slot functions. This mechanism reduces coupling between objects and makes the code more modular.
[0028] Qt GUI: Provides basic graphics components such as windows, dialog boxes, and controls, as well as OpenGL integration.
[0029] Qt Widgets: Provides a set of components for creating classic desktop-style user interfaces.
[0030] Qt Quick: A high-level framework for creating dynamic user interfaces, using the QML language for interface design.
[0031] Qt Network: Provides classes for network programming, supporting protocols such as TCP / IP and UDP.
[0032] Qt SQL: Provides classes for database integration, supporting multiple database systems.
[0033] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0034] Reference Figure 1 , Figure 1 This is a schematic diagram of the overall architecture of the Qt-based cross-platform CAN communication system in this application embodiment. Figure 1As shown, this application embodiment provides a cross-platform CAN communication system based on Qt. The system includes: a CAN communication device, a CAN extended frame parsing module, a CAN extended frame generation module, and a CAN communication management module. Based on the cross-platform characteristics of the Qt framework (supporting low-level interface calls for Windows and Linux systems) and object-oriented principles, this application embodiment designs four core functions: "device, management, parsing, and generation," as follows: Figure 1 As shown.
[0035] The CAN communication device (hardware adaptation layer) is responsible for driver adaptation of CAN hardware devices. It acts as a bridge between the CAN communication management module and the CAN communication hardware devices. Under Linux, it encapsulates the SocketCAN interface and also adapts to devices such as TinyCAN (a CAN bus communication solution provided as a plugin under the Qt framework in Linux) and PCAN (a CAN bus communication solution provided as a plugin under the Qt framework in Linux). Simultaneously, it provides a unified and defined device interface, offering users customized solutions through standardized interfaces and ensuring that the CAN communication management module can call different devices in a unified manner.
[0036] The CAN extended frame parsing module (protocol parsing layer) is responsible for converting the received CAN extended frames into data structures that developers can directly use, supporting a dual mode of "code extension + configuration file".
[0037] The CAN extended frame generation module (message generation layer) is responsible for converting the data structures defined by the developers into extended frames that conform to the CAN2.0B standard.
[0038] Both the CAN extended frame parsing module and the CAN extended frame generation module support defining the mapping relationship between extended frames and data segments through configuration files.
[0039] The CAN communication management module (core scheduling layer) serves as the "central hub" of the system, responsible for coordinating the entire CAN communication process and providing a unified management interface and optimization algorithms.
[0040] The cross-platform CAN communication system based on Qt adopts a "layered decoupling + interface standardization" architecture. Each module works together through Qt's signal slot mechanism and interface abstraction, realizing an efficient development model of "loading modules - configuring protocols - direct use".
[0041] Figure 2 This is a schematic diagram illustrating the specific functions of the CAN communication management module in the embodiments of this application.
[0042] See Figure 2 As shown, the CAN communication management module specifically includes the following sub-modules: (1) Device registration and management submodule, used to: support automatic loading of default CAN devices in Linux and Windows systems, support custom device extension, support device status monitoring, and detect the connection status (online / offline), communication rate (baud rate), and error code (such as bus error, frame loss) of registered devices in real time.
[0043] (2) Parsing tool and sending interface registration submodule, used to: support developers to register custom CAN tools and realize the automatic conversion of "CAN extended frame → data structure".
[0044] (3) Message sending management submodule, used for: It supports flexible transmission parameter configuration, allowing you to specify the number of times a message is repeatedly transmitted (1~N times), the periodic transmission period (1ms~1h, with an accuracy of ±0.1ms), and the extended inter-frame transmission time interval (10us~100ms) to meet the real-time requirements of different scenarios. Supports send queue scheduling: It adopts a "priority queue + time slice scheduling" mechanism to sort the messages to be sent according to their priority, and schedules high-priority messages first, while avoiding a single message from occupying too much bus resources.
[0045] (4) Data caching and acquisition submodule, used for: a caching mechanism based on "CAN frame ID + timestamp", where the structured data parsed by the receiving end and the original CAN frame are both stored in the cache, the cached data is automatically eliminated according to the timestamp, and the cache capacity and cache time are dynamically configured.
[0046] (5) Algorithm scheduling submodule, used for: using a priority scheduling algorithm that combines "static priority + dynamic adjustment" and a bandwidth reservation algorithm based on the "demand pre-allocation + dynamic reuse" mechanism to optimize performance.
[0047] (6) Thread safety protection submodule, used to: control the read and write operations of shared resources such as device list, cached data, and sending queue through mutex locks or read-write locks, realize the protection of shared resources and avoid multi-threaded data competition; provide multi-threaded separation design so that the receiving thread, parsing thread and sending thread run independently, and realize the data transfer between threads through Qt signal and slot mechanism to avoid communication delay caused by single-thread blocking.
[0048] (7) Anomaly detection and fault tolerance submodule, used to: capture CAN bus bit errors and arbitration loss errors in real time and trigger configurable fault tolerance strategies.
[0049] (8) Log and debugging assistance submodule, used for: hierarchical output of logs, supporting custom log content: frame transmission and reception time stamp, raw data bytes, parsing results, error codes.
[0050] The following sections will provide detailed explanations using CAN communication devices, CAN extended frame parsing modules, CAN extended frame generation modules, and CAN communication management modules as examples.
[0051] Example 1: CAN Communication Device The CAN communication device in this application embodiment provides a multi-system default device driver and a custom device extension interface. It provides a multi-system default device, and the currently supported systems specifically include Linux system and Windows system.
[0052] The default communication devices in the Linux system include: SocketCAN, which encapsulates the PF_CAN protocol family (a network protocol family in the Linux kernel specifically designed for CAN bus communication) through Qt, supporting CAN_RAW and CAN_BCM (two commonly used socket types in the PF_CAN protocol family) modes to achieve frame transmission and reception; TinyCAN / PCAN, which encapsulates the device driver interface through plugins provided by Qt, uniformly adapting to the interface specification of BaseCanBusDevice (the abstract base class name of all CAN communication devices in the system of this application embodiment, for developers to inherit and develop quickly).
[0053] The default communication device in Windows systems provides a communication device based on open-source drivers. It calls the DLL file of the communication driver through Qt's "dynamic library loading" (QLibrary), encapsulates functions such as device initialization, frame sending / receiving, and device shutdown, adapts to the BaseCanBusDevice interface, and supports plug and play.
[0054] Developers can customize communication devices: The base class defines a pure virtual interface and generic methods to ensure compatibility with custom devices. Developers can inherit from the abstract base class `BaseCanBusDevice` and implement the unified interfaces defined in the base class (initialization interface, frame sending interface, frame receiving interface, and device shutdown interface) to connect to the management module without modifying other code.
[0055] Example 2: CAN Extended Frame Parsing Module The CAN extended frame parsing module converts CAN extended frames into data structures and provides differentiated configuration services. The base class of the CAN extended frame parsing utility class provides a unified interface, allowing developers to define subclasses and develop according to customized communication protocols. It also provides configuration files to determine differentiated services and define parsing rules, which are implemented together through the built-in parsing configuration class of the CAN extended frame parsing module.
[0056] The current configuration file supports JSON and XML files, and specifically includes extended frame ID, data length, total number of packets, meaning of each byte of extended frame ID, and meaning of each data segment after concatenation.
[0057] Example 3: CAN Extended Frame Generation Module The CAN extended frame generation module converts data structures into CAN extended frames and provides differentiated configuration services. The base class of the CAN extended frame generation module provides a unified interface, allowing developers to define subclasses and develop data structure-to-segment and-to-extended-frame functions according to customized communication protocols. A configuration file determines the differentiated services and defines parsing rules, which are implemented together through the built-in parsing configuration class of the CAN extended frame parsing module.
[0058] The current configuration file supports JSON and XML files, and specifically includes extended frame ID, data length, total number of packets, meaning of each byte of extended frame ID, serialization rules for each data structure member variable, and the position of serialized variables in the data segment.
[0059] Example 4: CAN Communication Management Module The CAN communication management module is the core scheduling hub of the cross-platform CAN communication system based on Qt in this embodiment. It implements global scheduling through a singleton pattern and provides functions such as device registration and management, CAN extended frame parsing module registration, CAN extended frame generation module registration, message transmission management (transmission request handling), data caching and acquisition, algorithm scheduling (performance optimization), thread safety assurance, exception capture and repair (exception detection and fault tolerance), logging and debugging assistance, etc. Figure 2 , Figure 3 As shown.
[0060] The specific functions of each submodule in the CAN communication management module are explained in detail below.
[0061] (1) Equipment registration and management submodule, used for: Provides a default device registration service, which automatically detects the current operating system and registers the default CAN device during module initialization. In Linux systems, SocketCAN (preferred, supports multiple channels), tinyCAN (compatible with older devices), and pcan (industrial-grade devices) are loaded sequentially. Developers can also specify the default device through configuration files. In Windows systems, CAN devices based on open-source drivers are loaded, and the installed driver version is automatically identified and adapted, supporting CAN communication drivers available on the market such as USB-CAN-2 and USB-CAN-2E.
[0062] It provides custom device registration, allowing developers to inherit the abstract base class BaseCanBusDevice and implement the unified interface defined by the base class (initialization interface, frame sending interface, frame receiving interface, and device shutdown interface). Registration is completed by calling the registration interface of the management module, and the module automatically includes the custom device in the unified management, supporting dynamic device switching.
[0063] It provides anomaly detection and fault tolerance mechanisms, captures CAN bus errors such as bit errors, arbitration loss, and CRC errors in real time, and triggers configurable fault tolerance strategies, including automatic device reconnection, switching to other CAN interfaces, and degraded operation. It also supports extended frame transmission timeout retry function.
[0064] (2) The parsing tool and sending interface registration submodule is used for: It supports the registration of CAN extended frame parsing tool classes. The frame ID set and CAN communication device number are used as the filtering conditions for each parsing tool class. When an extended data frame with a given frame ID is received from a specified CAN communication device, the corresponding extended frame parsing tool is called to perform the work of converting data segments into data structures.
[0065] It supports the registration of CAN extended frame generation tools, enabling the CAN communication management module to receive the transmission request from the generation tool after generating the target extended frame and perform the transmission request processing function.
[0066] (3) Message sending management submodule, used for: It provides a send request handling function, supports fine-grained send control, and the input parameters include: extended frame set, inter-frame send time interval, number of repeated sends of extended frame group, and inter-send time interval between extended frame groups. It manages periodic sending through Qt timers and handles batch send tasks through a thread pool (QThreadPool) to ensure that the send process does not block threads and avoids bus congestion caused by sending a large number of frames in a short period of time.
[0067] (4) Data caching and retrieval submodule, used for: Efficient caching is achieved using a hash table where the key is the CAN frame ID and the value is the cached item. Each data cache item contains a data structure, a receive timestamp, and the cache status.
[0068] It provides a cache write function, which automatically updates the cache according to the frame ID after receiving and splicing CAN frames; if the ID does not exist, a new cache entry is added; if it exists, the old data is overwritten and the timestamp is updated.
[0069] It provides a cache read function, which can retrieve the corresponding cached data by inputting the frame ID, and returns whether the data has timed out (custom timeout is allowed).
[0070] It provides a cache cleanup function, starts an independent background thread, periodically scans the cache, deletes timed-out data, and avoids memory leaks.
[0071] (6) Algorithm scheduling submodule, used for: Priority scheduling and bandwidth reservation algorithms are provided to optimize performance.
[0072] The priority scheduling algorithm provides a priority division service, dividing CAN frames into 5 levels (P0~P4) according to "urgency level - service type". P0 is the highest priority (such as equipment fault alarm frames) and P4 is the lowest priority (such as periodic status reporting frames). Priority can be determined by the frame ID prefix (the high 3 bits of the frame ID indicate the priority) or by the extended frame priority of a specified frame ID determined by the configuration file.
[0073] It provides scheduling implementation services and adopts a hybrid scheduling mechanism of "priority preemption + time slice round-robin". High-priority frames (P0~P1) directly preempt the transmission resources, while low-priority frames (P2~P4) are sent in a time slice round-robin manner to avoid low-priority frames being blocked for a long time. At the same time, it uses Qt's wait condition component to realize dynamic wake-up of the transmission queue, reducing CPU usage.
[0074] The bandwidth reservation algorithm provides bus bandwidth allocation services. During module initialization, developers can reserve fixed bandwidth for extended frames corresponding to critical devices or service types through configuration files, and the remaining bandwidth can be dynamically allocated to other services.
[0075] Provides monitoring and adjustment services, and provides real-time statistics on bus occupancy for each frame ID.
[0076] If a service exceeds the reserved bus bandwidth, "bandwidth throttling" is triggered (suspending the transmission of non-urgent frames for that service).
[0077] If the reserved bandwidth is idle, it will be automatically allocated to other services to ensure maximum bus bandwidth utilization.
[0078] Combined with priority allocation services, conflict resolution services are provided. When multiple critical services simultaneously trigger bus bandwidth requirements, idle bus bandwidth is allocated according to service priority, with higher priority services taking the lead.
[0079] (6) Thread safety protection submodule, used for: The CAN communication module uses Qt's thread synchronization mechanism to protect critical resources (device operation, transmission queue, data buffer) within the module.
[0080] During device operation, a mutex lock is added to the initialization, sending extended frame, and receiving extended frame methods of BaseCanBusDevice to ensure that the same device is operated by only one thread at a time.
[0081] In the send queue, enqueue (enqueue()) and dequeue (dequeue()) operations are automatically locked / unlocked using the mutual exclusion mechanism provided by the Qt framework to prevent multiple threads from modifying the queue simultaneously.
[0082] In the data cache, the write and read operations of the data cache are implemented through the read-write lock of the Qt framework to achieve "multiple reads and single writes", which improves the efficiency of concurrent reads and avoids data competition during writes.
[0083] In inter-thread communication, threads within a module (such as sending threads, receiving threads, and cache cleanup threads) communicate through Qt's signal and slot mechanism to ensure the safety of data transfer between threads and avoid direct memory sharing.
[0084] (7) Anomaly detection and fault tolerance submodule, used to: capture CAN bus bit errors and arbitration loss errors in real time and trigger configurable fault tolerance strategies.
[0085] (8) Log and Debugging Auxiliary Submodule, used to: support hierarchical output of logs, including debug, information, warning and error levels, support custom log content, and currently support extended frame transmission and reception timing stamps, raw data bytes, parsing results, error code details and other information.
[0086] This application's embodiments, through layered design, modular architecture, and differentiated configuration definitions, achieve decoupling, reuse, and cross-platform adaptation of CAN communication functions. The Qt-based cross-platform CAN communication system includes: a CAN communication device, a CAN extended frame parsing module, a CAN extended frame generation module, and a CAN communication management module. These modules work collaboratively to achieve an efficient development model of "loading modules - configuring protocols - direct use," achieving the following effects: (1) Achieve cross-platform adaptation: It can run on Windows and Linux systems without modifying the code, reducing the cross-platform adaptation cost for developers; (2) Improve development efficiency: Provide a "plug and play" modular design. Developers only need to load the module and configure the communication protocol to complete the development of CAN communication function, reducing repetitive coding work; (3) Enhance code reusability: Through base class abstraction and interface standardization, functions such as device driver, data parsing, and frame generation can be reused in different projects, reducing maintenance costs; (4) Ensure high performance and thread safety: Improve communication real-time performance through priority scheduling and bandwidth reservation algorithms, and avoid data competition through thread synchronization mechanism to ensure stable operation of the module in high concurrency scenarios; (5) Enhance scalability: Supports custom CAN devices, parsing rules and transmission logic to meet the personalized needs of different industry scenarios and reduce the technical threshold for function expansion.
[0087] Therefore, the embodiments of this application are geared towards generalization needs, effectively improving cross-platform adaptability and development efficiency, realizing "plug-and-play" modules, and possessing high performance, high reliability, and high scalability to meet personalized needs. Overall, they achieve the effect of cost reduction and efficiency improvement, and can meet the development needs of cross-platform, high performance, and high reliability CAN communication. They are suitable for scenarios requiring CAN communication, such as industrial control, automotive electronics, and smart devices. In particular, they provide developers with efficient, reusable, and thread-safe CAN communication development modules, which can be adapted to both Windows and Linux operating systems. They belong to the intersection of embedded communication and cross-platform software development technologies.
[0088] The communication interface in this application includes input / output (I / O) interfaces, physical interfaces, and logical interfaces for interconnecting devices within the Qt-based cross-platform CAN communication system, as well as interfaces for interconnecting the Qt-based cross-platform CAN communication system with other devices (such as other computing devices or user equipment). The physical interface can be an Ethernet interface, fiber optic interface, ATM interface, etc.; the user equipment can be a display screen, keyboard, etc.
[0089] Memory can be various types of storage media, such as random access memory (RAM), read-only memory (ROM), non-volatile RAM (NVRAM), flash memory, optical storage, hard disk, programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), etc.
[0090] It should be noted that the sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0091] The terms "comprising" and "having," and any variations thereof, in the specification, claims, and accompanying drawings of this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to such process, method, product, or apparatus. The terms "first," "second," and "third," etc., are used to distinguish different objects, etc., and do not indicate a sequence, nor do they limit "first," "second," and "third" to different types.
[0092] In the description of the embodiments of this application, terms such as "exemplary," "for example," or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design that is described as "exemplary," "for example," or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design options. Specifically, the use of terms such as "exemplary," "for example," or "for example" is intended to present the relevant concepts in a specific manner.
[0093] In the description of the embodiments of this application, unless otherwise stated, " / " means "or". For example, A / B can mean A or B. The "and / or" in the text is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist simultaneously, and B exists alone. In addition, in the description of the embodiments of this application, "multiple" means two or more.
[0094] In some processes described in the embodiments of this application, multiple operations or steps are included in a specific order. However, it should be understood that these operations or steps may not be executed in the order they appear in the embodiments of this application, or they may be executed in parallel. The sequence number of the operation is only used to distinguish different operations, and the sequence number itself does not represent any execution order. In addition, these processes may include more or fewer operations, and these operations or steps may be executed sequentially or in parallel, and these operations or steps may be combined.
[0095] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device to execute the methods described in the various embodiments of this application.
[0096] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
Claims
1. A Qt-based cross-platform CAN communication system, characterized in that, The system comprises: a CAN communication device for driving an adaptive CAN hardware device and providing a uniformly defined device interface; a CAN extended frame analysis module for converting a received CAN extended frame into a data structure directly used by a developer; a CAN extended frame generation module for converting a data structure defined by the developer into a CAN extended frame; a CAN communication management module for overall planning of a CAN communication process, providing a uniform management interface and an optimization algorithm; The modules work cooperatively through a signal-slot mechanism of Qt and interface abstraction to realize an efficient development mode of "loading module- configuring protocol- direct use".
2. The Qt-based cross-platform CAN communication system of claim 1, wherein, The CAN extended frame analysis module and the CAN extended frame generation module support definition of a mapping relationship between an extended frame and a data segment through a configuration file.
3. The Qt-based cross-platform CAN communication system of claim 1, wherein, The CAN communication management module comprises a device registration and management submodule for supporting automatic loading of a default CAN device of Linux and Windows systems, supporting custom device extension, supporting device state monitoring, and real-time detection of a connection state, a communication rate, and an error code of a registered device.
4. The Qt-based cross-platform CAN communication system of claim 1, wherein, The CAN communication management module comprises an analysis tool and a sending interface registration submodule for supporting registration of a custom CAN tool by the developer and realizing automatic conversion of "CAN extended frame- data structure".
5. The Qt-based cross-platform CAN communication system of claim 1, wherein, The CAN communication management module comprises a message sending management submodule for supporting configuration of sending parameters, including a message repeated sending number, a periodic sending period, and an extended frame interval, and supporting sending queue scheduling by using a "priority queue + time slice scheduling" mechanism to sort the to-be-sent messages according to priorities and schedule high-priority messages preferentially.
6. The Qt-based cross-platform CAN communication system of claim 1, wherein, The CAN communication management module comprises a data buffering and acquisition submodule for buffering structured data and original CAN frames after analysis by a receiving end based on a "CAN frame ID + time stamp" buffering mechanism, automatically eliminating buffered data according to time stamps, and supporting dynamic configuration of a buffer capacity and a buffer time.
7. The Qt-based cross-platform CAN communication system of claim 1, wherein, The CAN communication management module comprises an algorithm scheduling submodule for using a "static priority + dynamic adjustment" combined priority scheduling algorithm and a bandwidth reservation algorithm based on a "demand pre-allocation + dynamic multiplexing" mechanism to perform performance optimization.
8. The Qt-based cross-platform CAN communication system of claim 1, wherein, The CAN communication management module comprises a thread safety guarantee submodule for controlling read-write operations of shared resources through a mutex or a read-write lock, providing a multi-thread separation design to make a receiving thread, an analysis thread, and a sending thread run independently, and realizing data transmission between threads through a Qt signal-slot mechanism.
9. The Qt-based cross-platform CAN communication system of claim 1, wherein, The CAN communication management module comprises an exception detection and fault tolerance submodule for real-time capture of CAN bus bit errors and arbitration loss errors and triggering of a configurable fault tolerance strategy.
10. The Qt-based cross-platform CAN communication system of claim 1, wherein, The CAN communication management module comprises a log and debugging auxiliary submodule for hierarchical output of logs and support of custom log content, including a frame receiving and sending time stamp, data original bytes, analysis results, and error codes.
Citation Information
Patent Citations
Client universal system based on UDS protocol communication
CN110798464A
Equipment monitoring platform based on data stream
CN114003022A
Cross-platform multi-CAN port communication drive implementation system and implementation method
CN115604220A