File transmission method and device based on CAN protocol and storage medium

By using custom multi-byte write operations and preset encapsulation formats in the CAN protocol for file transmission, the coordination problem of the CAN protocol between different physical layer media and MCU is solved, and efficient data transmission and file breakpoint transmission is achieved.

CN119814774APending Publication Date: 2025-04-11SHENZHEN POWEROAK NEWENER CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510286453.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-12
Publication Date
2025-04-11

AI Technical Summary

Technical Problem

Existing CAN protocols are difficult to efficiently coordinate with other IoT communication protocols between different physical layer media and MCUs, especially in terms of data transmission delay and throughput.

Method used

The file transfer method based on the CAN protocol is adopted, and the file index and content data blocks are encapsulated into different data blocks through custom multi-byte write operations, and transmitted through a preset encapsulation format, supporting file breakpoint continuous transmission, improving data transmission efficiency.

Benefits of technology

It realizes efficient coordination between CAN protocol and other IoT communication protocols between different physical layer media and MCUs, improves data transmission efficiency, and supports file breakpoint continuous transmission.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119814774A_ABST
    Figure CN119814774A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of CAN communication, in particular to a file transmission method and device based on a CAN protocol and a storage medium. The file transmission method based on the CAN protocol comprises the steps that an upper computer encapsulates a target file index into a file reading data block according to a first encapsulation format, sends the file reading data block to a lower computer through a self-defined multi-byte write operation, and then receives a file content data block sent by the lower computer through the multi-byte write operation, and analyzing the file content data block based on the second packaging format to obtain the target file content. According to the method provided by the invention, file breakpoint resume can be supported, and the data transmission efficiency is greatly improved, so that the CAN protocol can efficiently cooperate with other Internet of Things communication protocols between different physical layer media and MCUs based on the same data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of CAN communication technology, and in particular to a file transmission method, device and storage medium based on the CAN protocol. Background Art

[0002] In the existing IoT communication network, there are various physical transmission media, such as Ethernet (wired, wireless, WIFI, 2 / 3 / 4 / 5G cellular network), serial communication (UART / RS232 / RS485), CAN (Controller Area Network), etc. Equivalent to the OSI (Open System Interconnect) communication data model, different physical transmission media correspond to different application layer communication protocols. In the prior art, Ethernet and serial communication often use the standard modbus communication protocol, and the standard application layer protocols commonly used by the CAN bus include CANopen, SAE J1939, etc. Each standard is only applicable to the limited range of each specific physical layer, and there is no good compatibility for cross-physical layer data transmission. In addition, for historical record data stored on the device side, the CAN protocol generally adopts a simple and immediate question-and-answer interaction protocol (that is, the upper computer sends a message to query the specified object, and the lower computer immediately returns a valid content message based on the object index). This method cannot properly handle the actual delay of local data reading and the maximum response delay of protocol transmission.

[0003] In order to simplify and unify data communication in IoT embedded systems, there is an urgent need for a data transmission method that enables the CAN protocol to efficiently collaborate (such as latency and throughput) with other IoT communication protocols based on the same data on different physical layer media and MCUs (Microcontroller Units). Summary of the invention

[0004] The embodiments of the present application provide a file transmission method, device and storage medium based on the CAN protocol, which solve the problem that the traditional CAN protocol cannot efficiently collaborate with other IoT communication protocols based on the same data between different physical layer media and MCUs.

[0005] In a first aspect, an embodiment of the present application provides a file transmission method based on the CAN protocol, which is applied to a host computer, and the method includes: Encapsulating the target file index into a file read data block according to a preset first encapsulation format, and sending the file read data block to the lower computer through a custom multi-byte write operation; Receiving a file content data block sent by the lower computer through the multi-byte write operation, parsing the file content data block based on a preset second encapsulation format to obtain target file content; The sending of the file read data block to the lower computer through a customized multi-byte write operation comprises: The file read data block is encapsulated into a write data block start frame and at least one data load frame according to the CAN protocol data frame format, and the write data block start frame and the at least one data load frame are sent to the lower computer in sequence, and then the data response frame encapsulated in the CAN protocol data frame format returned by the lower computer is received.

[0006] Optionally, the data segments of the write data block start frame and the data response frame include data block type, data start position, data length and load data verification information, and the data segment of the data load frame includes data block type, data packet number field and load data.

[0007] Optionally, the data block encapsulated in the first encapsulation format includes index information, data offset information and a continuous write flag, and the data block encapsulated in the second encapsulation format includes data classification, total data, current data transmission length, data offset information and current load data.

[0008] Optionally, the method further includes: Encapsulating the query directory index into a file query data block according to the first encapsulation format, and sending the file query data block to the lower computer through the multi-byte write operation; The index content data block sent by the lower computer through the multi-byte write operation is received, and the index content data block is parsed based on the second encapsulation format to obtain target index content.

[0009] In a second aspect, an embodiment of the present application provides a file transmission method based on the CAN protocol, which is applied to a lower computer, and the method includes: Receiving a file read data block sent by a host computer through a customized multi-byte write operation, parsing the file read data block based on a preset first encapsulation format, and obtaining a target file index; Determine the target file content corresponding to the target file index according to the target file index, encapsulate the target file content into a file content data block according to a preset second encapsulation format, and send the file content data block to the host computer through the multi-byte write operation; The sending of the file content data block to the host computer through the multi-byte write operation comprises: The file content data block is encapsulated into a write data block start frame and at least one data load frame according to the data frame format of the CAN protocol, and the write data block start frame and the at least one data load frame are sent to the host computer in sequence, and then the data response frame encapsulated in the CAN protocol data frame format returned by the host computer is received.

[0010] Optionally, the data block encapsulated in the first encapsulation format includes index information, data offset information and a continuous write flag, and the data block encapsulated in the second encapsulation format includes data classification, total data, current data transmission length, data offset information and current load data.

[0011] Optionally, the method further includes: Receiving a file query data block sent by the host computer through the multi-byte write operation, parsing the file query data block based on the first encapsulation format, and obtaining a query directory index; The target index content corresponding to the query directory index is determined according to the query directory index, the target index content is encapsulated into an index content data block according to the second encapsulation format, and the index content data block is sent to the host computer through the multi-byte write operation.

[0012] Optionally, the data after parsing the file read data block based on the first encapsulation format includes a target file index, data offset information and a continuous write flag, and when the continuous write flag is yes, determining the target file content corresponding to the target file index according to the target file index, encapsulating the target file content into a file content data block according to a preset second encapsulation format, and sending the file content data block to the host computer through the multi-byte write operation includes: Determine the target file content according to the target file index and the data offset information; The target file content is encapsulated into M file content data blocks according to the second encapsulation format, and each of the file content data blocks is sent to the host computer in sequence through M multi-byte write operations, where M is an integer greater than or equal to 1.

[0013] In a third aspect, an embodiment of the present application provides an electronic device, comprising: at least one processor and a memory communicatively connected to the at least one processor, the memory storing instructions executable by the at least one processor, the instructions being executed by the at least one processor so that the at least one processor can execute any of the methods described above.

[0014] In a fourth aspect, an embodiment of the present application provides a computer storage medium, which stores instructions or programs. When the instructions or programs are executed by at least one processor, the at least one processor executes any one of the methods described above.

[0015] In an embodiment of the present application, a file transmission method based on the CAN protocol is provided, wherein the upper computer encapsulates the target file index into a file reading data block according to a first encapsulation format, and sends it to the lower computer through a custom multi-byte write operation, and then receives the file content data block sent by the lower computer through the multi-byte write operation, and parses the file content data block based on the second encapsulation format to obtain the target file content. The method of the present application uses the file concept to summarize various types of data, establishes a mapping relationship between files and file indexes, and when performing file transmission, encapsulates the files and file indexes into data blocks using different encapsulation formats, and transmits them through a custom multi-byte write operation method, which not only supports file breakpoint continuation, but also greatly improves the data transmission efficiency, so that the CAN protocol can be efficiently coordinated with other Internet of Things communication protocols based on the same data between different physical layer media and MCUs. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 A topological structure diagram of a CAN bus is shown as an example; Figure 2 The following is an exemplary diagram showing a frame structure of a CAN protocol data frame; Figure 3 A schematic diagram of the hardware structure of an electronic device is exemplarily shown; Figure 4 The flowchart of the file transmission method based on the CAN protocol applied to the host computer is exemplified; Figure 5 The flowchart of the file transmission method based on the CAN protocol applied to the lower computer is exemplified; Figure 6 The structure diagram of the first packaging format is exemplarily shown; Figure 7 The structure diagram of the second packaging format is exemplarily shown; Figure 8 The structure diagram of the write data block start frame, the data load frame and the data response frame is exemplarily shown; Fig. 9 The following is a schematic diagram showing the entire process of file transmission based on the CAN protocol. DETAILED DESCRIPTION

[0017] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0018] Please refer to Figure 1 , Figure 1 The topological structure diagram of a CAN bus is shown as an example. Figure 1 As shown, the CAN bus includes two lines, CAN_H and CAN_L, and nodes 1 to N are connected to the CAN bus through a CAN controller and a CAN transceiver, respectively. In the CAN protocol, the types of frames are mainly divided into data frames, remote frames, error frames, and overload frames. Among them, data frames are used to send data, remote frames are used to request data, error frames are used to indicate that an error has occurred, and overload frames are used to indicate that the node cannot receive data. The file transfer method based on the CAN protocol in this application is to transfer data blocks from a sending node to a receiving node through data frames.

[0019] Please refer to Figure 2 , Figure 2 The frame structure diagram of the CAN protocol data frame is shown as an example. The data frame includes a standard frame and an extended frame. Each data frame may specifically include seven parts: frame start, arbitration segment, control segment, data segment, CRC segment, ACK segment and frame end segment. Among them, the arbitration segment is used to determine the transmission priority, including the data frame ID. The data segment contains the actual transmitted data, and a maximum of 8 bytes of data can be transmitted. When the data frame is transmitted on the CAN bus, each CAN node uses an acceptance filter to compare whether the data frame ID on the bus is consistent with the ID of the node. If they are consistent, the CAN controller allows the received information to be stored in the corresponding register. Through acceptance filtering technology, without the need for special scheduling, the CAN bus can realize data transmission in various ways such as one-to-one, one-to-many and global broadcast.

[0020] Please refer to Figure 3 , Figure 3 The hardware structure diagram of the electronic device is shown as an example. The electronic device can be Figure 1 Any node device in Figure 3 As shown, the electronic device 100 includes a processor 10, a memory 20 and a communication interface 30, and the processor 10, the memory 20 and the communication interface 30 are connected through a line. Figure 3 In the illustrated embodiment, the processor 10, the memory 20 and the communication interface 30 are communicatively connected to each other via a bus.

[0021] The memory 20 is used to store software programs, computer executable program instructions, etc. The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and application programs required for at least one function; the data storage area may store data created according to the use of the electronic device, etc.

[0022] The memory 20 may be a read-only memory (ROM), or other types of static storage devices that can store static information and instructions, or a random access memory (RAM), or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), and the specifics are not limited here.

[0023] Exemplarily, the memory 20 may be a double data rate synchronous dynamic random access memory DDR SDRAM (DDR for short). The memory 20 may exist independently but be connected to the processor 10. Optionally, the memory 20 may also be integrated with the processor 10. For example, integrated into one or more chips.

[0024] In some embodiments, the memory 20 may include a memory remotely located relative to the processor 10, and these remote memories may be connected to the electronic device via a network. Examples of the above network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0025] The processor 10 uses various interfaces and lines to connect various parts of the entire electronic device 100, and performs various functions of the electronic device and processes data by running or executing software programs stored in the memory 20 and calling data stored in the memory 20, such as implementing the method described in any embodiment of the present application.

[0026] The processor 10 may be a Field Programmable Gate Array (FPGA), a Digital Signal Processor (DSP), a Central Processing Unit (CPU), etc.

[0027] The processor 10 may be a single-core processor or a multi-core processor. For example, the processor 10 may be composed of multiple FPGAs or multiple DSPs. In addition, the processor 10 may refer to one or more devices, circuits and / or processing cores for processing data (e.g., computer program instructions). The processor 10 may be a separate semiconductor chip or may be integrated into a semiconductor chip together with other circuits. For example, the processor 10 may form a system-on-a-chip (SoC) with other circuits (e.g., codec circuits, hardware acceleration circuits, or various buses and interface circuits), or may be integrated into an application-specific integrated circuit (ASIC) as a built-in processor of the ASIC. The ASIC with the integrated processor may be packaged separately or may be packaged together with other circuits.

[0028] The communication interface 30 may use a transceiver or other transceiver to implement communication between the electronic device and other devices or a communication network.

[0029] The data between IoT devices generally include real-time data, historical data, configuration parameters, etc. Conventional transmission methods are based on limited specific signal quantity requirements, and the data point table (or register) is gradually expanded based on the requirements in a toothpaste-squeezing manner, and the table length is infinitely increased by spreading the cake. The application layer data on different physical layers is only the association of peer data point tables, and it is impossible to achieve efficient collaboration (such as delay and throughput) of the same data between different physical layer media and MCUs. In order to solve the above problems, this application adopts the concept of files to summarize various types of data, establish a mapping relationship between files and file indexes, and encapsulate files and file indexes into data blocks using different encapsulation formats when performing file transmission, and transmit them through a custom multi-byte write operation method, which not only supports file breakpoint resumption, but also greatly improves the data transmission efficiency, so that the CAN protocol can be based on the same data with other IoT communication protocols to perform efficient collaboration between different physical layer media and MCUs.

[0030] The files in this application are formed by combining some data with interrelated contents and meanings in a preset format according to the requirements of the demander. For example, in the field of energy storage systems, various types of record files can be formed according to the data content that different demanders (such as customers, operation and maintenance engineers, and R&D engineers) need to view, such as fault records, operation records, historical power generation, equipment replacement records, etc.

[0031] Files have attributes such as file name, folder, file directory, file content, and file length. A file directory has different folders and folder levels, and a folder can have different files and subordinate folders. Directories and file names are used to distinguish the meanings of different files. A file may have different file lengths and file contents based on specific needs.

[0032] In order to adapt to data transmission of various sizes, this application adopts a data block-based transmission method. When the file to be transmitted is large, the file can be split into multiple data blocks for transmission, and the data offset is used to specify the data block to be transmitted each time, thereby realizing the breakpoint resume function.

[0033] Furthermore, based on the usage scenario of file transfer, the data block types are divided into two types: index type and content type. Among them, the index type data block mainly includes the directory and the file name, and is encapsulated in the first encapsulation format to indicate the directory to be queried or the target file to be read. The content type data block mainly includes the target index content or the target file content, and is encapsulated in the second encapsulation format to feedback the queried target index content or the read target file content to the requesting party. For example, the file reading data block and the file query data block below are index type data blocks, and the index content data block and the file content data block are content type data blocks.

[0034] The following describes the implementation process of the file transfer method based on the CAN protocol in detail from the perspectives of the requester (i.e., the upper computer below) and the provider (i.e., the lower computer below).

[0035] Please refer to Figure 4 , Figure 4 The flowchart of the file transmission method based on the CAN protocol applied to the host computer is exemplified, including: Step S401: encapsulate the target file index into a file read data block according to a preset first encapsulation format, and send the file read data block to a lower computer through a user-defined multi-byte write operation.

[0036] Specifically, the target file index includes the directory and file name of the target file. In one embodiment, the data block encapsulated in the first encapsulation format includes index information, data offset information and a continuous write flag. The index information includes directory and file name information. In one embodiment, the directory and file name information are represented by an ASCII string.

[0037] Please refer to Figure 6 , Figure 6 The structure diagram of the first packaging format is exemplarily shown. Figure 6As shown, in the first encapsulation format, of the 10 bytes occupied by the index information field, the 1st to 2nd bytes represent the directory, and the 3rd to 10th bytes represent the file name. Assuming that the 1st byte is ' / ' and the 2nd byte is the secondary directory name, 61 secondary directories under the root directory can be represented: '1'~'9', 'A'~'Z', 'a'~'z'. For example, " / Z012345678" represents the "012345678" file under the secondary directory 'Z'. The directory and file name are up to 10 bytes long, and if the length is insufficient, it is supplemented with '\0'. When all 10 bytes are '\0', it means reading the root directory; when the secondary directory is not '\0' and the file name is all '\0', it means reading the file and folder information under the secondary directory (i.e. the target index content); when the secondary directory is '\0' and the file name is not '\0', it means reading the target file under the root directory (i.e. the target file content); when both the secondary directory and the file name are not '\0', it means reading the target file under the secondary directory (i.e. the target file content). The upper computer notifies the lower computer to perform corresponding operations by filling different contents in the index information field.

[0038] The data offset field occupies 4 bytes and contains the read offset position of the target file or target index. The continuous write flag field occupies 2 bytes and is used to indicate whether the lower computer can split the target file content or target index content into multiple data blocks for transmission. Specifically, when the continuous write flag is 1, it means that the target file content or target index content is supported to be split into multiple data blocks for transmission. When the continuous write flag is 0, it means that the target file content or target index content is not supported to be split into multiple data blocks for transmission.

[0039] The message transmission protocols based on the Internet of Things mainly include the CAN protocol and the Modbus protocol. In the traditional CAN protocol, a data frame can only transmit 8 bytes of payload data, which cannot adapt to the transmission of data blocks with variable data sizes. Hereby, this application customizes a multi-byte write operation method to realize the transmission of data blocks, which can simplify and unify data communication in the embedded system of the Internet of Things.

[0040] Specifically, sending a data block to a target device through a customized multi-byte write operation includes: encapsulating the data block into a write data block start frame and at least one data load frame according to the CAN protocol data frame format, and sending the write data block start frame and at least one data load frame to the target device in sequence, and then receiving a data response frame encapsulated in the CAN protocol data frame format returned by the target device.

[0041] Please refer to Figure 8 , Figure 8 The structure diagram of the write data block start frame, the data load frame and the data response frame is shown as an example. Figure 8As shown in the figure, the write data block start frame, data load frame and data response frame have different data frame IDs respectively, and the Data0~Data8 bytes correspond to the data segment in the data frame of the CAN protocol. The data segment of the write data block start frame includes the data block type, data start position, data length and load data verification information, which is used to inform the target device of the write position of the data block in the original file or content, the size of the data block and the verification data of the data block. The data segment of the data load frame includes the data block type, data packet number and load data, which is used to carry the load data. The data segment of the data response frame includes the data block type, data start position, data length and load data verification information, which is used to confirm whether the target device has accurately received the data block.

[0042] Step S402: receiving a file content data block sent by the lower computer through a multi-byte write operation, parsing the file content data block based on a preset second encapsulation format, and obtaining target file content.

[0043] After the lower computer receives the file reading data block, it parses the target file index carried in the file reading data block based on the first encapsulation format, determines the corresponding target file according to the target file index, encapsulates the target file content into a file content data block according to the second encapsulation format, and sends it to the upper computer through a multi-byte write operation.

[0044] Please refer to Figure 7 , Figure 7 The structure diagram of the second packaging format is exemplarily shown. Figure 7 As shown, in the second encapsulation format, the data classification field occupies 2 bytes, which are used to indicate the data category of the current load data. Among them, 0 indicates that the current load data is the target index content, and 1 indicates that the current load data is the target file content. The total data field occupies 4 bytes. When the data classification is 0, it indicates the total number of bytes of the target index content. When the data classification is 1, it indicates the total number of bytes of the target file content. The current data transmission length field occupies 2 bytes, indicating the number of bytes of the target index content or target file content transmitted this time. The data offset information field occupies 4 bytes, indicating the data offset of the current load data in the target index content or target file content. The current load data field is used to indicate the valid data uploaded. If the maximum length of a single load is 128 bytes, when a 200-byte target file content is transmitted, the target file content can be split into two data blocks. The data offset information field corresponding to the first data block is 0, and the data offset information field corresponding to the second data block is 128.

[0045] In one embodiment, the file content data block is parsed based on the preset second encapsulation format to obtain data classification, total data, current data transmission length, data offset information and current load data. When the target file content to be transmitted is large, the method of the present application supports encapsulating the target file content into several file content data blocks and transmitting them to the host computer in sequence. Specifically, if the continuous write flag carried by the file read data block is yes, then continue to receive other first content data frames based on the target file sent by the lower computer until all target file contents are received. When the target file content is fully received, the target file content received multiple times is spliced ​​into a complete file according to the data offset information. Further, the upper computer can parse out the corresponding signal information according to the target file content encoding rules pre-agreed with the lower computer. For example, the target file is formed by sorting the current signal, voltage signal, electric quantity signal, etc. in sequence, and the upper computer can parse out the value of the current signal, the value of the voltage signal and the value of the electric quantity signal according to the rule.

[0046] In one embodiment, the upper computer can also send a query directory index to the lower computer to obtain the file or folder information under the query directory index. Specifically, the CAN protocol-based file transmission method applied to the upper computer also includes: encapsulating the query directory index into a file query data block according to the first encapsulation format, and sending the file query data block to the lower computer through a multi-byte write operation; receiving the index content data block sent by the lower computer through a multi-byte write operation, parsing the index content data block based on the second encapsulation format, and obtaining the target index content. Among them, the query directory index includes query directory information (please refer to the previous description for details), and the target index content includes the file or folder information of the preset level under the query directory. For example, if the preset level is level 2, the target index content includes the files and folders under the query directory, as well as the file and folder information under the query directory folder.

[0047] Please refer to Figure 5 , Figure 5 The flowchart of the file transmission method based on the CAN protocol applied to the lower computer is exemplarily shown, including: Step S501: receiving a file read data block sent by a host computer through a user-defined multi-byte write operation, parsing the file read data block based on a preset first encapsulation format, and obtaining a target file index.

[0048] Step S502, determining the target file content corresponding to the target file index, encapsulating the target file content into a file content data block according to a preset second encapsulation format, and sending the file content data block to the host computer through a multi-byte write operation.

[0049] In one embodiment, when the target file content to be transmitted is large, the method of the present application supports encapsulating the target file content into several file content data blocks and then transmitting them in sequence. Specifically, the lower computer parses the file reading data block based on the first encapsulation format, and can parse out the target file index, data offset information and continuous write flag. When the continuous write flag is yes, the lower computer determines the target file content according to the target file index and data offset information, splits the target file content according to the size of the target file content, the maximum load length of a single transmission, the current network transmission environment and the processing power of the current device, and encapsulates the target file content into M file content data blocks according to the second encapsulation format, and then sends each file content data block to the upper computer in sequence through M multi-byte write operations. Wherein, M is an integer greater than or equal to 1. When the continuous write flag is no, if the size of the target file content does not exceed the maximum load length of a single transmission, all the target file contents are packaged into a data block and sent to the upper computer, and if the size of the target file content exceeds the maximum load length of a single transmission, the target file content of the maximum load length of a single transmission is packaged into a data block and sent to the upper computer.

[0050] For example, after the lower computer parses the file read data block, it obtains the target file index as " / z123.txt0", the offset information is 0, and the continuous write flag is 1. According to the target file index, it can be determined that the target file is the "123.txt" file in the secondary directory "z" folder. If the size of the "123.txt" file is 200 bytes and the maximum load length of a single transmission is 128 bytes, the "123.txt" file can be split into two parts and then encapsulated into two file content data blocks. Among them, the current load data of the first file content data block starts from the starting data of the "123.txt" file and has a length of 128 bytes; the current load data of the second file content data block starts from the 128th byte of the "123.txt" file and has a length of 72 bytes. It can be understood that the length of the current load data in the first file content data block can be less than 128 bytes.

[0051] In one embodiment, the lower computer can also obtain the query directory index sent by the upper computer, and return the file or folder information under the query directory index to the upper computer. Specifically, the file transmission method based on the CAN protocol applied to the lower computer also includes: receiving the file query data block sent by the upper computer through a multi-byte write operation, parsing the file query data block based on the first encapsulation format, and obtaining the query directory index; determining the corresponding target index content according to the query directory index, encapsulating the target index content into an index content data block according to the second encapsulation format, and sending the index content data block to the upper computer through a multi-byte write operation. It can be understood that when the target index content data is large, it can also be split and encapsulated into several index content data blocks, and each index content data block is sent to the upper computer in turn through a multi-byte write operation.

[0052] Please refer to Fig. 9 , Fig. 9 The following is a schematic diagram of the entire process of file transmission based on the CAN protocol. Specifically, the entire process of file transmission includes the following four steps: Step 901: The upper computer sends the query directory index to the lower computer through a multi-byte write operation.

[0053] Step 902: The lower computer sends the target index content to the upper computer through a multi-byte write operation.

[0054] Step 903: The upper computer sends the target file index to the lower computer through a multi-byte write operation.

[0055] Step 904: The lower computer sends the target file content to the upper computer through a multi-byte write operation.

[0056] Among them, the amount of data transmitted in step 901 to step 903 is relatively small, and all data transmission can be completed through one data block. In step 904, the target file content transmitted is divided into multiple data blocks for transmission. The transmission of each data block is realized through a write data block start frame, at least one data load frame and a data response frame.

[0057] The file transmission method based on the CAN protocol provided by the embodiment of the present application is that the upper computer encapsulates the target file index into a file reading data block according to the first encapsulation format, and sends it to the lower computer through a customized multi-byte write operation, and then receives the file content data block sent by the lower computer through the multi-byte write operation, and parses the file content data block based on the second encapsulation format to obtain the target file content. The method of the present application adopts the file concept to summarize various types of data, establishes a mapping relationship between files and file indexes, and when performing file transmission, encapsulates the files and file indexes into data blocks using different encapsulation formats, and transmits them through a customized multi-byte write operation method, which not only supports file breakpoint continuation, but also greatly improves the data transmission efficiency, so that the CAN protocol can be efficiently coordinated with other Internet of Things communication protocols based on the same data between different physical layer media and MCUs.

[0058] According to an embodiment of the present application, a computer-readable storage medium is provided, the type of which is as described above, and the computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the processor executes the steps of the above-mentioned file transfer method based on the CAN protocol.

[0059] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Under the concept of the present application, the technical features in the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other changes in different aspects of the present application as described above, which are not provided in detail for the sake of simplicity. Although the present application has been described in detail with reference to the aforementioned embodiments, a person of ordinary skill in the art should understand that the technical solutions described in the aforementioned embodiments can still be modified, or some of the technical features can be replaced by equivalents. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A file transmission method based on CAN protocol, characterized in that: Applied to a host computer, the method includes: Encapsulating the target file index into a file read data block according to a preset first encapsulation format, and sending the file read data block to the lower computer through a custom multi-byte write operation; Receiving a file content data block sent by the lower computer through the multi-byte write operation, parsing the file content data block based on a preset second encapsulation format to obtain target file content; The sending of the file read data block to the lower computer through a customized multi-byte write operation comprises: The file read data block is encapsulated into a write data block start frame and at least one data load frame according to the CAN protocol data frame format, and the write data block start frame and the at least one data load frame are sent to the lower computer in sequence, and then the data response frame encapsulated in the CAN protocol data frame format returned by the lower computer is received.

2. The method according to claim 1, characterized in that: The data segments of the write data block start frame and the data response frame include data block type, data start position, data length and load data verification information, and the data segment of the data load frame includes data block type, data packet number field and load data.

3. The method according to claim 1, characterized in that The data block encapsulated in the first encapsulation format includes index information, data offset information and a continuous write flag, and the data block encapsulated in the second encapsulation format includes data classification, total data, current data transmission length, data offset information and current load data.

4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Encapsulating the query directory index into a file query data block according to the first encapsulation format, and sending the file query data block to the lower computer through the multi-byte write operation; The index content data block sent by the lower computer through the multi-byte write operation is received, and the index content data block is parsed based on the second encapsulation format to obtain target index content.

5. A file transmission method based on CAN protocol, characterized in that: Applied to a lower computer, the method includes: Receiving a file read data block sent by a host computer through a customized multi-byte write operation, parsing the file read data block based on a preset first encapsulation format, and obtaining a target file index; Determine the target file content corresponding to the target file index according to the target file index, encapsulate the target file content into a file content data block according to a preset second encapsulation format, and send the file content data block to the host computer through the multi-byte write operation; The sending of the file content data block to the host computer through the multi-byte write operation comprises: The file content data block is encapsulated into a write data block start frame and at least one data load frame according to the data frame format of the CAN protocol, and the write data block start frame and the at least one data load frame are sent to the host computer in sequence, and then the data response frame encapsulated in the CAN protocol data frame format returned by the host computer is received.

6. The method according to claim 5, characterized in that The data block encapsulated in the first encapsulation format includes index information, data offset information and a continuous write flag, and the data block encapsulated in the second encapsulation format includes data classification, total data, current data transmission length, data offset information and current load data.

7. The method according to claim 5 or 6, characterized in that: The method further comprises: Receiving a file query data block sent by the host computer through the multi-byte write operation, parsing the file query data block based on the first encapsulation format, and obtaining a query directory index; The target index content corresponding to the query directory index is determined according to the query directory index, the target index content is encapsulated into an index content data block according to the second encapsulation format, and the index content data block is sent to the host computer through the multi-byte write operation.

8. The method according to claim 6, characterized in that The data after parsing the file read data block based on the first encapsulation format includes a target file index, data offset information and a continuous write flag, and when the continuous write flag is yes, determining the target file content corresponding to the target file index according to the target file index, encapsulating the target file content into a file content data block according to a preset second encapsulation format, and sending the file content data block to the host computer through the multi-byte write operation includes: Determine the target file content according to the target file index and the data offset information; The target file content is encapsulated into M file content data blocks according to the second encapsulation format, and each of the file content data blocks is sent to the host computer in sequence through M multi-byte write operations, where M is an integer greater than or equal to 1.

9. An electronic device, characterized in that: The electronic device includes at least one processor and a memory communicatively connected to the at least one processor, the memory storing instructions executable by the at least one processor, the instructions being executed by the at least one processor so that the at least one processor can execute the method as described in any one of claims 1 to 8.

10. A computer storage medium, characterized in that: The computer storage medium stores instructions or programs, and when the instructions or programs are executed by at least one processor, the at least one processor is caused to perform the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Software burning method and device

    CN109976767A

  • Method and device for transmitting CAN (Controller Area Network) message of electric vehicle

    CN114422289A

  • File transmission method and device based on communication protocol of multifunctional electric energy meter

    CN117221310A

  • Electro-hydraulic valve upgrading method and system based on CAN network, medium and equipment

    CN118642739A

  • CAN protocol analysis method, system, device and medium

    CN118677970A