Data processing method, device, electronic device and computer readable storage medium
By using the same custom protocol library for data interaction between devices, the problem of inconvenient data interaction between devices is solved, achieving convenient data processing and reducing maintenance costs.
Patent Information
- Application Number
- CN202410772764.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-17
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2044-06-17
AI Technical Summary
In the existing technology, devices that establish near-field connections need to develop and maintain different custom protocol libraries, which results in inconvenient data interaction and high development and maintenance costs.
By using the same custom protocol library for data interaction, the framing and deframing processes between devices are inverse processes. Only one protocol library needs to be developed and maintained, which simplifies the data processing process and improves framing and decoding through modular design. Frame efficiency.
It realizes the convenience of data interaction between devices, shortens the development cycle and maintenance costs, and improves the update efficiency and data transmission reliability.
Smart Images

Figure CN118337877B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communications, and in particular, to a data processing method, device, electronic device, and computer-readable storage medium. Background Art
[0002] With the continuous development of communication technology, more and more devices can exchange data through near-field connection. In the process of data exchange, devices with near-field connection can use custom protocols to process data sent by the other end. That is, the custom protocol library compiled based on the custom protocol contains the code to implement the custom protocol, so the device can process the data sent by the other end based on the custom protocol library.
[0003] In related technologies, devices that establish near-field connections usually use different custom protocol libraries to process data. For example, the devices can agree on the specific meaning represented by a specific string, and then develop a corresponding custom protocol library. In this way, each device can use its own custom protocol library to parse the meaning represented by the specific string sent by the other end, and then frame it according to the meaning represented by the data to be sent to achieve data interaction between the two ends. However, this requires the development and maintenance of different custom protocol libraries, which is not convenient for data interaction between the two ends. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a data processing method, device, electronic device and computer-readable storage medium to facilitate data interaction between devices with near-field connections.
[0005] In the first aspect, an embodiment of the present application provides a data processing method, which is applied to a device with a near-field connection. The method includes: if a data block to be sent is detected, the data block to be sent is framed using a custom protocol library to obtain a data frame to be sent; if a data frame sent by the opposite end based on the near-field connection is received, the received data frame is deframed using the custom protocol library; wherein the custom protocol library includes a deframe code for performing custom deframe processing on the received data frame, and a framing code for performing custom framing processing on the data block to be sent. In this way, when two devices with a near-field connection are performing data interaction, the deframe process of one of them and the framing process of the opposite end are inverse processes. Therefore, the custom protocol library used by the two devices with a near-field connection can be the same. Then, only the custom protocol library needs to be developed and maintained to implement the above data processing method, so that data interaction can be facilitated at both ends. Further, since the time period for developing a custom protocol library is long, compared with the solution that requires the development and maintenance of two custom protocol libraries, the development and maintenance of the custom protocol library used in this implementation can greatly shorten the development cycle and reduce maintenance costs.
[0006] Optionally, the custom protocol library includes a first framing module and a second framing module; and the use of the custom protocol library to perform framing processing on the data block to be sent to obtain the data frame to be sent includes: using the second framing module of the custom protocol library to assemble the command data block that provides the command information to be sent in the data block to be sent; using the first framing module of the custom protocol library to assemble the non-command data block in the data block to be sent; using the custom protocol library according to the non-command data block and the command data block, to obtain the data frame to be sent. In this way, the first framing module and the second framing module in the custom protocol library can be used for framing processing, so that the command data block and the non-command data block can be assembled respectively. In this way, each module performs its own duties, which is convenient for improving framing efficiency.
[0007] Optionally, the command data block includes a main sub-command data block; the main command data block in the main sub-command data block provides the main category information to which the command information to be sent belongs; the sub-command data block in the main sub-command data block provides the sub-category information to which the command information to be sent belongs; and the use of the second framing module of the custom protocol library to assemble the command data block that provides the command information to be sent in the data block to be sent includes: using the second framing module of the custom protocol library to assemble the main sub-command data block according to the main category and sub-category to which the command information to be sent belongs. In this way, the second framing module can be used to realize the assembly of the main sub-command data block. In this way, when similar functions of the control device or the controlled device need to be updated in the future, only the corresponding main sub-command related code can be updated, which greatly improves the update efficiency.
[0008] Optionally, the use of the first framing module of the custom protocol library to assemble the non-command data block in the data block to be sent includes: using the first framing module of the custom protocol library to add a version data block providing version information on the basis of the main and sub-command data blocks. In this way, the version data block can be added to the data block to be sent, so as to provide the version information of the custom protocol library currently used by the device, so as to be able to assemble the corresponding version of the data frame to be sent, and realize normal communication with the opposite end.
[0009] Optionally, the use of the first framing module of the custom protocol library to assemble the non-command data blocks in the data blocks to be sent also includes: using the first framing module of the custom protocol library to add a check data block, a type data block and an identity data block on the basis of the main and sub-command data blocks and the version data block; wherein the check data block is used to provide the check information of the data frame to be sent; the type data block is used to provide the type information of the data frame to be sent; and the identity data block is used to provide the identity information of the data frame to be sent. In this way, the first framing module can be used to add the type data block to determine the response status. And, the identity data block and the check data block are added so that each data frame to be sent has unique identity information and corresponding check information, thereby achieving accurate transmission.
[0010] Optionally, the data block to be sent includes a response data block to be sent, and the custom protocol library includes a first de-framing module and a second de-framing module; and the de-framing of the received data frame using the custom protocol library to obtain the response data block to be sent includes: using the first de-framing module of the custom protocol library to parse the non-command data frame in the received data frame to obtain a non-command data block; using the second de-framing module of the custom protocol library to parse the command data frame providing the received command information in the received data frame to obtain a command data block; and the method also includes: using the custom protocol library to obtain the response data block to be sent according to the non-command data block and / or the command data block. In this way, the first de-framing module and the second de-framing module in the custom protocol library can be used for de-framing, so that the command data block and the non-command data block can be parsed out respectively. In this way, each module performs its own duties, which is convenient for improving de-framing efficiency.
[0011] Optionally, the command data block includes a main sub-command data block; the main command data block in the main sub-command data block provides the main category information to which the received command information belongs; the sub-command data block in the main sub-command data block provides the sub-category information to which the received command information belongs; and the second de-framing module of the custom protocol library is used to parse the command data frame providing the received command information in the received data frame to obtain the command data block, including: using the second de-framing module of the custom protocol library to parse the main sub-command data frame in the received data frame to obtain the main sub-command data block; and the use of the custom protocol library to obtain the response data block to be sent according to the non-command data block and / or the command data block, including: using the second de-framing module of the custom protocol library to call the application layer interface so that the application layer returns the response data block to be sent according to the main sub-command data block. In this way, the second de-framing module can be used to parse the main sub-command data frame. In this way, when similar functions of the control device or the controlled device need to be updated later, only the corresponding main sub-command related code can be updated, which greatly improves the update efficiency.
[0012] Optionally, the use of the first de-framing module of the custom protocol library to parse the non-command data frame in the received data frame to obtain the non-command data block includes: using the first de-framing module of the custom protocol library to parse the version data frame providing version information in the received data frame to obtain the version data block; and using the custom protocol library to obtain the response data block to be sent according to the non-command data block and / or the command data block includes: using the first de-framing module of the custom protocol library to obtain the response data block representing the failure of data processing according to the version data block when the version information does not meet the version requirements. In this way, when the version information in the received data frame does not meet the version requirements, the information of the failure of data processing can be directly fed back, thereby eliminating the need to perform subsequent steps and improving the efficiency of data interaction.
[0013] Optionally, the use of the first deframing module of the custom protocol library to parse the non-command data frame in the received data frame to obtain a non-command data block includes: using the first deframing module of the custom protocol library to parse the type data frame providing type information in the received data frame to obtain a type data block; and when the type data block indicates that the received data frame belongs to the response data frame type, parsing the identity data frame providing identity information in the received data frame to obtain an identity data block; determining a processing strategy for the sent data frame information corresponding to the identity information provided by the identity data block; and verifying the accuracy of the received data frame according to a preset verification rule; if the verification result indicates that the received data frame is transmitted accurately, transmitting the unparsed main and sub-command data frames in the received data frame to the second deframing module; and using the custom protocol library to obtain the response data block to be sent according to the non-command data block and / or the command data block, includes: when the verification result indicates that the received data frame is transmitted incorrectly, using the first deframing module of the custom protocol library to obtain a response data block indicating data processing failure according to the verification result. In this way, the first de-framing module can be used to parse out relevant data blocks, thereby realizing data interaction with the opposite end based on the type information, identity information, and verification information, thereby improving data interaction efficiency.
[0014] Optionally, the method further includes: using the custom protocol library to resend the data frame to be sent when the data frame to be sent is not successfully sent within a preset time length; and discarding the data frame to be sent when the number of retransmissions exceeds a preset number threshold. In this way, the data frame to be sent is sent through the retransmission mechanism to improve the transmission reliability of the data frame.
[0015] In the second aspect, an embodiment of the present application provides a data processing device, which is applied to a device that establishes a near-field connection, and the device includes: a framing module, which is used to, if a data block to be sent is detected, use a custom protocol library to perform framing processing on the data block to be sent to obtain a data frame to be sent; a deframing module, which is used to, if a data frame sent by the opposite end based on the near-field connection is received, use the custom protocol library to perform deframing processing on the received data frame; wherein the custom protocol library includes a deframing code for performing custom deframing processing on the received data frame, and a framing code for performing custom framing processing on the data block to be sent. In this way, data processing can be realized by only developing and maintaining the custom protocol library, thereby facilitating data interaction between the two ends. Furthermore, the development cycle can be greatly shortened and maintenance costs can be reduced.
[0016] In a third aspect, an embodiment of the present application provides an electronic device, including a processor and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps in the method provided in the first aspect are executed. The electronic device is a control device or a controlled device.
[0017] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps in the method provided in the first aspect are performed.
[0018] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program or instructions, and when the computer program or instructions are executed by a processor, the method described in the first aspect is performed.
[0019] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the embodiments of the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0021] Figure 1 A flowchart of a data processing method provided in an embodiment of the present application;
[0022] Figure 2A schematic diagram of the structure of a custom protocol library provided in an embodiment of the present application;
[0023] Figure 3 A schematic diagram of data frame transmission provided in an embodiment of the present application;
[0024] Figure 4 A structural block diagram of a data processing device provided in an embodiment of the present application;
[0025] Figure 5 A schematic diagram of the structure of an electronic device for executing a data processing method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0026] The technical solutions 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 only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0027] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.
[0028] It should be noted that the embodiments in this application or the technical features in the embodiments may be combined if there is no conflict.
[0029] In the related art, different custom protocol libraries are usually used to process data between devices that have established near-field connections. This requires the development and maintenance of different custom protocol libraries, which is inconvenient for data interaction between the two ends. In order to solve this problem, the present application provides a data processing method, device, electronic device, and computer-readable storage medium. Furthermore, the devices interact with each other through the same custom protocol. In this way, the custom protocol library used by the two is the same, and then only the custom protocol library needs to be developed and maintained to implement the above data processing method, thereby facilitating data interaction between the two ends.
[0030] The defects existing in the solutions in the above-mentioned related technologies are the results obtained by the inventor after practice and careful research. Therefore, the discovery process of the above-mentioned problems and the solutions proposed in the embodiments of the present invention below for the above-mentioned problems should all be the contributions made by the inventor to the present invention during the process of the present invention.
[0031] In some application scenarios, a data processing method provided by the present application can be applied to devices with near-field connections. The above-mentioned devices with near-field connections may include control devices and controlled devices with near-field connections. The above-mentioned control devices may include, for example, devices such as mobile phones, tablets or desktop computers that can actually send control instructions. The above-mentioned controlled devices may include, for example, cameras, smart home devices, smart bracelets and other devices that can actually connect to the control device in the near field and can interact with data. Thus, the control device and the controlled device can interact with data based on the near-field connection to realize the control function of the control device on the controlled device. Furthermore, the data transmitted between the two may include, for example, their own device data, connectable wifi data, collected data (such as temperature, humidity) and other data.
[0032] The above-mentioned near field connection may include, for example, a Bluetooth connection, a ZigBee connection, etc.
[0033] Please refer to Figure 1 , which shows a flow chart of a data processing method provided by an embodiment of the present application. Figure 1 As shown, the data processing method includes the following steps 101 to 102.
[0034] Step 101: If a data block to be sent is detected, a custom protocol library is used to perform framing processing on the data block to be sent to obtain a data frame to be sent; the custom protocol library includes a framing code for performing custom framing processing on the data block to be sent.
[0035] The data blocks to be sent are data blocks to be sent to the other end through the near field connection. They may include only the response data blocks to be sent, or only the non-response data blocks to be sent, or both the response data blocks to be sent and the non-response data blocks to be sent.
[0036] The non-response data block is a data block obtained when the control device does not receive a data frame sent by the other end. For example, it can be a data block generated based on the instruction command of the operator without receiving a data frame. Or, it can be a data block for providing identity information actively sent by the controlled device when the Bluetooth connection is successful.
[0037] The above-mentioned response data block is a data block obtained by performing response processing on the data frame based on the application layer after receiving the data frame sent by the opposite end.
[0038] Thus, when a data block to be sent is detected, the data block to be sent can be input into the custom protocol library so that the custom protocol library can perform framing processing on it based on the internal framing code. Here, the so-called framing processing is to assemble the data block to be sent into a data frame to be sent.
[0039] In some application scenarios, the above framing code is also the code written according to the custom framing logic, which can be used to assemble a version data block providing version information, or to assemble an identity data block providing identity information, etc.
[0040] Then, the assembled data frame to be sent can be sent to the other end through the near field connection.
[0041] In some application scenarios, the custom protocol library may include code for calling related conversion interfaces, so that after obtaining the data frame to be sent, the custom protocol library can call the related conversion interface to convert the data frame to be sent into a bit stream form, so as to send it to the other end through a near field connection.
[0042] It should be noted that after the bit stream is transmitted to the other end based on the near field connection, the other end may also call a related conversion interface to convert it into a data frame to obtain a corresponding received data frame.
[0043] Furthermore, if the data processing method is applied to a control device, then the opposite end is the controlled device. If the data processing method is applied to a controlled device, then the opposite end is the control device.
[0044] Step 102: If a data frame sent by the opposite end based on the near field connection is received, the received data frame is deframed using the custom protocol library; the custom protocol library includes a deframe code for performing custom deframe processing on the received data frame.
[0045] The above-mentioned received data frame is also the data frame received by the local end, which can be assembled by the opposite end based on the custom protocol library.
[0046] Furthermore, if a data frame sent by the other end is received, the received data frame can be input into the custom protocol library so that the custom protocol library can perform de-framing processing on it based on the internal de-framing code. Here, the so-called de-framing processing is to parse the received data frame and restore the original data block. The above data block may include, for example, a message segment, a datagram, etc.
[0047] In some application scenarios, the above deframing code is also the code written according to the custom deframing logic. For example, it can be used to parse the version information frame providing version information in the received data frame to obtain the version data block; or to parse the identity data frame providing identity information in the received data frame to obtain the identity data block, etc.
[0048] After the custom protocol library completes deframing of the received data frame, it can call a preset application layer interface to use the application layer to obtain a response data block that responds to the received data frame.
[0049] In some application scenarios, the application layer of the control device may, for example, display information obtained based on the deframing result, so that the operator can issue relevant response instructions to obtain a response data block.
[0050] In other application scenarios, the application layer of the controlled device can directly process the de-framing result according to preset rules to obtain a response data block. For example, when the temperature information requested by the received data frame is not found, a response data block indicating that no relevant information is found is generated.
[0051] In this implementation, when two devices that have established a near-field connection are interacting with each other, the deframing process of one of them and the framing process of the other end are inverse processes. Therefore, the custom protocol library used by the two devices that have established a near-field connection can be the same. Then, it is only necessary to develop and maintain the custom protocol library to implement the above-mentioned data processing method, thereby facilitating data interaction between the two ends. Furthermore, since the time period for developing a custom protocol library is relatively long, compared to the solution that requires the development and maintenance of two custom protocol libraries, the development and maintenance of the custom protocol library used in this implementation can significantly shorten the development cycle and reduce maintenance costs.
[0052] It should be noted that the custom protocol corresponding to the custom protocol library may include a multi-layer structure or a single-layer structure. Among them, if the custom protocol includes a multi-layer structure, each layer of the structure can be used to implement different functions; if the custom protocol includes only a layer of structure, the layer of structure can be used to implement all functions. Furthermore, since the deframing process and the framing process are inverse processes to each other, the same layer of structure can also be used to implement the deframing process and the framing process of the same type of data frames. The same type of data frames here may include, for example, command data frames and non-command data frames. For example, the same layer of structure can be used to implement the deframing process and the framing process of the command data frame, and another layer of structure can be used to implement the deframing process and the framing process of the non-command data frame.
[0053] In some application scenarios, the custom protocol may include a first layer L1 and a second layer L2. The L1 layer may be used to parse non-command data frames in received data frames; the L2 layer may be used to parse command data frames in received data frames. The non-command data frames are data frames that do not provide command information, which may include, for example, version data frames that provide version information, identity data frames that provide identity information, etc. The command data frames are data frames that provide command information, which may include, for example, command data frames that provide requests to obtain temperature information, command data frames that request to obtain humidity information, etc.
[0054] In these application scenarios, the L1 layer can be defined as shown in the following table:
[0055] Table 1
[0056]
[0057] Table 2
[0058]
[0059] From Table 1 above, we can see that the L1 layer defines that a packet can occupy (8-128) bytes, its header can occupy 8 bytes, and its payload can occupy (0-120) bytes.
[0060] From the above Table 2, it can be seen that the L1 layer also defines the usage of the 8 bytes occupied by its header. That is, its header includes 8 bits of Magic byte (magic byte, used to place a specific 8 bits value at the beginning of the data frame to help identify and verify whether the data frame can apply the custom protocol. For example, the valid value 0xAB can be used to indicate that the custom protocol can be used), 2 bits of Reserve (reserved bit, convenient for later updating of the custom protocol library, which is located at the 6th to 7th bit), 1 bit of Err flag (error flag bit, used to provide information whether there is an error in the data frame transmission process, which is located at the 5th bit), 1 bit of Ack flag (type flag bit, which is used to provide type information of the data frame, which is located at the 4th bit), 4 bits of Version (version information bit, which is used to provide version information, which is located at the 0th to 3rd bit), 16 bits of Payload length (data length of the payload), 16 bits of CRC16 (16-bit cyclic redundancy check code), and 16 bits of Sequence id (identification code).
[0061] Furthermore, the L2 layer may be defined as shown in the following table:
[0062] Table 3
[0063]
[0064] Table 4
[0065]
[0066] Table 5
[0067]
[0068] Table 6
[0069]
[0070] From Table 3 above, we can see that the L2 layer defines that a packet can occupy (2-120) bytes, its header can occupy 2 bytes, and its payload can occupy (0-118) bytes.
[0071] From the above Table 4, it can be seen that the L2 layer also defines the usage of the 2 bytes occupied by its header. That is, its header includes 8 bits of Command ID (command word flag, used to identify a specific operation command or request) and 8 bits of Reserve (reserved bit).
[0072] From the above Table 5, it can be seen that the L2 layer also defines the occupancy of its payload, which may include, for example, 1 byte Key (subcommand flag), 2 byte Key header (subcommand header), N byte Key value (subcommand payload), etc.
[0073] From the above Table 6, it can be seen that the L2 layer also defines the usage of the bytes occupied by the Key header. That is, it can include 7 bits of Reserve (reserved bits, which are located from bit 9 to bit 15) and 9 bits of Key value length (data length corresponding to the subcommand, which are located from bit 0 to bit 8).
[0074] Therefore, the custom protocol library can perform framing or deframing according to the definitions of the L1 layer and the L2 layer.
[0075] It should be noted that the custom protocol defines the occupancy of data during the transmission process, so the custom protocol library represents the data at the bit level for processing, which can reduce the amount of communication data compared to the method of representing the data in character encoding form for processing.
[0076] See also Figure 2 , which shows a schematic diagram of the structure of the custom protocol library divided based on the custom protocols including the above L1 layer and L2 layer. Figure 2 As shown, the custom protocol library includes a first framing module and a second framing module; the first framing module may include, for example, a framing code for implementing the L1 layer in the custom protocol, and the second framing module may include, for example, a framing code for implementing the L2 layer in the custom protocol.
[0077] In this way, the process of performing framing processing on the data block to be sent by using the custom protocol library in the above step 101 to obtain the data frame to be sent includes the following sub-steps:
[0078] Sub-step 1011, using the second frame module of the custom protocol library, assembling a command data block providing command information to be sent in the data block to be sent;
[0079] Sub-step 1012, assembling the non-command data blocks in the data blocks to be sent by using the first framing module of the custom protocol library;
[0080] Sub-step 1013, using the custom protocol library to obtain the data frame to be sent according to the non-command data block and the command data block.
[0081] In some application scenarios, after the application layer determines the data block to be sent, it can call a preset sending interface (such as a preset XRSBLE_L2_SendData interface) to transmit the unassembled data block to be sent to the second frame assembly module.
[0082] Then, the second framing module may first identify the command data block from the data blocks to be sent, and then frame the command data block according to the definitions shown in Tables 3 to 6. In these application scenarios, the second framing module may, for example, call a preset sending interface (e.g., a preset XRSBLE_L1_SendData interface) to transmit the unassembled non-command data block to the first framing module.
[0083] Furthermore, after receiving the unassembled non-command data blocks, the first framing module may frame the non-command data blocks according to the definition information shown in Tables 1 and 2, so as to obtain data frames to be sent.
[0084] In this implementation, the first framing module and the second framing module in the custom protocol library can be used for framing processing, so that the command data block and the non-command data block can be assembled respectively. In this way, each module performs its own function, which is convenient for improving framing efficiency.
[0085] In some optional implementations, the command data block includes a main sub-command data block; the main command data block in the main sub-command data block provides the main category information to which the command information to be sent belongs; the sub-command data block in the main sub-command data block provides the sub-category information to which the command information to be sent belongs. The above main categories may include, for example, acquisition categories, setting categories, etc. Among them, the acquisition category may include sub-categories such as acquisition of temperature information and acquisition of humidity information; the setting category may include, for example, sub-categories such as setting WiFi password and setting user name.
[0086] In this way, the above-mentioned sub-step 1011 uses the second framing module of the custom protocol library to assemble the command data block that provides the command information to be sent in the data block to be sent, including: using the second framing module of the custom protocol library to assemble the main-sub-command data blocks according to the main category and sub-category to which the command information to be sent belongs.
[0087] For example, if the command information to be sent is used to obtain temperature information, the second frame module can assemble the main-sub-command data block according to the acquisition category (main category) to which the command information to be sent belongs and the acquired temperature information (subcategory) to which it belongs.
[0088] In this implementation, the second group of frame modules can be used to realize the assembly of the main and sub-command data blocks. In this way, when similar functions of the control device or the controlled device need to be updated in the future, only the corresponding main and sub-command related codes can be updated, which greatly improves the update efficiency. For example, if you want to obtain humidity information on the basis of obtaining temperature information, you can add a sub-category code for obtaining humidity information under the acquisition category. In addition, if you want to add a setting category, you can add the setting category as the main category.
[0089] In some application scenarios, since the custom protocol library can be updated, the control device and the controlled device may not be updated synchronously, or the same version of the custom protocol library cannot be used at the same time. In other words, the custom protocol library used by the two is not the same version of the custom protocol library. Therefore, a version data block can be added to the data frame to be sent to provide the version information of the custom protocol library currently used by the control device or the controlled device, so that the other end can determine whether deframing can be achieved.
[0090] Therefore, in some optional implementations, the use of the first framing module of the custom protocol library in the above step 1012 to assemble the non-command data block in the data block to be sent includes: using the first framing module of the custom protocol library to add a version data block that provides version information on the basis of the main sub-command data block.
[0091] That is, the second frame module has assembled the main and sub-command data blocks, and the first frame module can continue to assemble the non-command data blocks. Further, the non-command data blocks include the above-mentioned version data blocks, which can be assembled according to the Version defined in Table 2.
[0092] In this implementation, a version data block can be added to the data block to be sent, thereby providing the version information of the custom protocol library currently used by the device, so as to assemble the corresponding version of the data frame to be sent and achieve normal communication with the other end.
[0093] In some optional implementations, the above-mentioned step 1012 of using the first framing module of the custom protocol library to assemble the non-command data blocks in the data blocks to be sent also includes: using the first framing module of the custom protocol library to add a check data block, a type data block and an identity data block on the basis of the main sub-command data blocks and the version data block; wherein the check data block is used to provide check information of the data frame to be sent; the type data block is used to provide type information of the data frame to be sent; and the identity data block is used to provide identity information of the data frame to be sent.
[0094] The above-mentioned identity information may include, for example, an identity identification code, which may be assembled by, for example, a Sequenceid as defined in Table 2.
[0095] The above-mentioned verification data block is a data block used by the other end to verify whether the data frame to be sent is transmitted accurately, and it can provide verification information. For example, it can be assembled by CRC16 and majic byte as defined in Table 2.
[0096] The above-mentioned type information can provide information on whether the data frame to be sent belongs to a non-response data frame or a response data frame. Among them, the response data frame is assembled by the response data block, and the non-response data frame is assembled by the non-response data block. In this way, the response situation can be known according to the type information. For example, if the control device receives that the data frame M sent by the controlled device is a non-response data frame (for example, when assembled according to the definition information in Table 2, the Ack flag is set to 0), it can send the corresponding response data frame m to the controlled device (for example, when assembled according to the definition information in Table 2, the Ack flag is set to 1). After receiving the response data frame m, the controlled device can determine that the sent data frame M has been processed by the control device, and then the relevant information of the data frame M can be destroyed; if the response data frame m is not received, the data frame M can be retransmitted.
[0097] In this implementation, the first frame module can be used to add a type data block to determine the response status, and to add an identity data block and a check data block so that each data frame to be sent has unique identity information and corresponding check information, thereby achieving accurate transmission.
[0098] In some optional implementations, the method further includes: using the custom protocol library to resend the data frame to be sent when the data frame to be sent is not successfully sent within a preset time length; and discarding the data frame to be sent when the number of retransmissions exceeds a preset number threshold.
[0099] In some application scenarios, the custom protocol library can implement the retransmission process by calling the retransmission interface, for example. For example, after obtaining the data frame to be sent, the first frame module can call the retransmission interface to send it, and can determine whether it is successfully sent within the preset time length. If it is not successfully sent, the retransmission interface can be called again to resend the data frame to be sent. Then the number of times the retransmission interface is called can be counted, and if the number of calls exceeds the preset number threshold, the data frame to be sent can be discarded.
[0100] In this implementation, the data frame to be sent may be sent through a retransmission mechanism to improve the transmission reliability of the data frame.
[0101] Please continue reading Figure 2 As shown in the structural diagram, the custom protocol library includes a first deframing module and a second deframing module. The first deframing module may include, for example, a deframing code for implementing the L1 layer in the custom protocol, and the second deframing module may include, for example, a deframing code for implementing the L2 layer in the custom protocol.
[0102] In this way, the de-framing process of the received data frame by using the custom protocol library described in the above step 102 includes the following sub-steps:
[0103] Sub-step 1021, using the first de-framing module of the custom protocol library, parsing the non-command data frame in the received data frame to obtain a non-command data block;
[0104] Sub-step 1022, using the second de-framing module of the custom protocol library, parsing the command data frame providing the received command information in the received data frame to obtain a command data block;
[0105] In this way, the method further comprises step 103: using the custom protocol library to obtain the response data block to be sent according to the non-command data block and / or the command data block.
[0106] In some application scenarios, after the custom protocol library receives the data frame sent by the other end, the first de-framing module can parse the non-command data frame in the received data frame through the definition information shown in Tables 1 and 2 to obtain the non-command data block. Here, for example, after the Bluetooth library receives the bit stream sent by the other end, it can transmit it to the first de-framing module through a preset interface (such as a preset XRSBLE_L1_RecvProcess interface).
[0107] Then, the first de-framing module may call a preset interface (e.g., a preset XRSBLE_L2_RecvProcess interface) to transmit the unparsed command data frame to the second de-framing module, so that the second de-framing module may parse the command data frame in the received data frame through the definition information shown in Tables 3 to 6, thereby obtaining a command data block. Thus, the response data block to be sent may be obtained based on the non-command data block and the command data block.
[0108] In this implementation, the first de-framing module and the second de-framing module in the custom protocol library can be used to perform de-framing processing, so that the command data block and the non-command data block can be parsed respectively. In this way, each module performs its own function, which is convenient for improving de-framing efficiency.
[0109] In some optional implementations, the command data block includes a main sub-command data block; the main command data block in the main sub-command data block provides main category information to which the received command information belongs; and the sub-command data block in the main sub-command data block provides sub-category information to which the received command information belongs.
[0110] Thus, the above sub-step 1022, using the second de-framing module of the custom protocol library to parse the command data frame providing the received command information in the received data frame to obtain the command data block, includes: using the second de-framing module of the custom protocol library to parse the main sub-command data frame in the received data frame to obtain the main sub-command data block;
[0111] For example, if the received data frame is used to obtain temperature information, the second deframing module can parse and obtain the main-sub-command data block according to the acquisition category (main category) to which the received command information belongs and the acquired temperature information (subcategory) to which it belongs.
[0112] In this way, the above-mentioned step 103 uses the custom protocol library to obtain the response data block to be sent according to the non-command data block and / or the command data block, including: using the second deframing module of the custom protocol library to call the application layer interface so that the application layer returns the response data block to be sent according to the main sub-command data block.
[0113] In this implementation, the second de-framing module can be used to parse the master and sub-command data frames. In this way, when similar functions of the control device or the controlled device need to be updated later, only the corresponding master and sub-command related codes can be updated, which greatly improves the update efficiency.
[0114] In some optional implementations, the above sub-step 1021 uses the first deframing module of the custom protocol library to parse the non-command data frame in the received data frame to obtain a non-command data block, including: using the first deframing module of the custom protocol library to parse the version data frame that provides version information in the received data frame to obtain a version data block.
[0115] In some application scenarios, the version data block is assembled by the first framing module using the Version defined in Table 2. Therefore, the first deframing module can also perform deframing using the Version.
[0116] In this way, the above-mentioned step 103 described in using the custom protocol library to obtain the response data block to be sent according to the non-command data block and / or the command data block includes: using the first deframing module of the custom protocol library to obtain a response data block representing data processing failure according to the version data block when the version information does not meet the version requirements.
[0117] In some application scenarios, a higher version of a custom protocol library may include the de-framing code in a lower version of a custom protocol library. Therefore, it can implement the data frames assembled by the lower version of the custom protocol library at the other end. For example, a custom protocol library with version number 3.0 can de-frame data frames assembled by custom protocol libraries with version numbers 1.0, 2.0, and 3.0, but cannot de-frame data frames assembled by a custom protocol library with version number 4.0.
[0118] Therefore, the first deframing module can first determine whether the version information in the received data frame meets the version requirements. If not, the response data block of the data processing failure can be directly fed back to the other end. For example, if the version number in the received data frame is 4.0, the custom protocol library with the version number of 3.0 on this end cannot perform deframing on the received data frame. Therefore, its version information does not meet the version requirements, and there is no need to transmit the unparsed command data frame to the second deframing module, but directly feed back the response data block of the data processing failure to the other end. Here, the response data frame can be assembled by the first framing module according to the definition information shown in Table 2, for example, it can be assembled into an "error ACK packet, where ACK flag is 1 and ERRflag is 1".
[0119] In this implementation, when the version information in the received data frame does not meet the version requirement, information indicating that data processing has failed can be directly fed back, thereby eliminating the need to execute subsequent steps and improving data interaction efficiency.
[0120] In some optional implementations, the above sub-step 1021 uses the first deframing module of the custom protocol library to parse the non-command data frame in the received data frame to obtain a non-command data block, including: using the first deframing module of the custom protocol library to parse the type data frame that provides type information in the received data frame to obtain a type data block.
[0121] Thus, when the type data block indicates that the received data frame belongs to the type of the response data frame, the identity data frame providing identity information in the received data frame is parsed to obtain the identity data block; and a processing strategy for the sent data frame information corresponding to the identity information provided by the identity data block is determined;
[0122] For example, if the type data block parsed by the control device indicates that the received data frame belongs to a response data frame and the response is successful (for example, the value of the Ack flag is 1), the identity data block can be further parsed, so that the relevant information of the sent data frame corresponding to the response data frame can be found in the multiple data frames that have been sent, and the relevant information of the sent data frame can be destroyed.
[0123] In addition, if the type data block indicates that the received data frame belongs to the non-response data frame type, for example, the received data frame can be deframed to parse out its identity data block, so that a response data frame indicating that the data frame has been successfully received can be returned to the other end.
[0124] Then, the accuracy of the received data frame can be checked according to a preset check rule; if the check result indicates that the received data frame is transmitted accurately, the unparsed master and sub-command data frames in the received data frame are transmitted to the second de-framing module;
[0125] The preset verification rule may be, for example, a magic byte rule or a CRC16 rule as defined in Table 2. Thus, if the verification passes, it can be determined that the received data frame is transmitted accurately.
[0126] In this way, the step 103 described above of using the custom protocol library to obtain the response data block to be sent according to the non-command data block and / or the command data block includes: using the first deframing module of the custom protocol library to obtain the response data block indicating data processing failure according to the verification result when the verification result indicates that the received data frame has a transmission error. For example, the first framing module can be used to frame the response data block according to the definition information shown in Table 2.
[0127] In this implementation, the first de-framing module can be used to parse out relevant data blocks, so as to achieve data interaction with the other end based on type information, identity information, and verification information, thereby improving data interaction efficiency.
[0128] It should be noted that after completing an interaction, the relevant destruction interface (such as the preset XRSBLE_L2_UnInit interface) can be called to destroy the relevant interaction resources. The interaction resources here may include, for example, memory resources, thread resources, etc., to improve resource utilization.
[0129] It should be noted that although the custom protocol library used by the two devices that establish a near-field connection may be the same, due to the differences in the devices, the two may use different interfaces to implement corresponding functions. For example, interface X is used in the control device to receive data transmitted by the other end based on Bluetooth, and interface Y is used in the controlled device to receive data transmitted by the other end based on Bluetooth. The implementation logic of interface X and interface Y is the same. Furthermore, when the control device or the controlled device installs the custom protocol library, it can perform initialization operations based on its own situation (that is, initialize the custom protocol). For example, the control device sets the interface for receiving data transmitted by the other end based on Bluetooth to interface X, and the controlled device sets the interface for receiving data transmitted by the other end based on Bluetooth to interface Y.
[0130] For further information, see Figure 3 , which shows a schematic diagram of data frame transmission between an application layer, a near field connection layer (the Bluetooth library in the figure) and a custom protocol layer in a device with a near field connection provided by an embodiment of the present application. Figure 3 As shown, the application layer can turn on Bluetooth and initialize the custom protocol to obtain a custom protocol library suitable for use on this end. Then, the application layer can generate the command information to be sent, and transmit it to the custom protocol layer for framing processing, and then the custom protocol layer transmits the data frame to be sent obtained by framing to the Bluetooth library to send the data frame to the other end through the Bluetooth library. In addition, after the Bluetooth library receives the data frame, it can be transmitted to the custom protocol layer, and the custom protocol layer de-frames it to obtain the received command information, and then transmits the received command information to the application layer. After the interaction is over, the application layer can turn off Bluetooth, and can reopen it when data frame transmission is required next time, and can reverse initialize the custom protocol layer to destroy the current transmission resources. For the de-framing or framing processing here, please refer to the relevant content above, which will not be repeated here.
[0131] In addition, those skilled in the art will appreciate that, in the above method of a specific embodiment, the order in which the steps are written does not imply a strict order of execution and does not constitute any limitation on the implementation process. The specific order of execution of the steps should be determined by their function and possible internal logic.
[0132] Please refer to Figure 4 , which shows a structural block diagram of a data processing device provided in an embodiment of the present application. The data processing device may be a module, program segment or code on an electronic device. It should be understood that the device is similar to the above Figure 1 The method embodiment corresponds to and can be executed Figure 1 The method embodiment involves various steps.
[0133] Optionally, the above-mentioned data processing device is applied to a device with a near field connection, and the device includes a framing module 401 and a deframing module 402. The framing module 401 is used to, if a data block to be sent is detected, perform framing processing on the data block to be sent using a custom protocol library to obtain a data frame to be sent; the deframing module 402 is used to, if a data frame sent by the opposite end based on the near field connection is received, perform deframing processing on the received data frame using the custom protocol library; wherein the custom protocol library includes a deframing code for performing a custom deframing processing on the received data frame, and a framing code for performing a custom framing processing on the data block to be sent.
[0134] Optionally, the custom protocol library includes a first framing module and a second framing module; and the framing module 401 is further used to: use the second framing module of the custom protocol library to assemble the command data block that provides the command information to be sent in the data block to be sent; use the first framing module of the custom protocol library to assemble the non-command data block in the data block to be sent; use the custom protocol library to obtain the data frame to be sent based on the non-command data block and the command data block.
[0135] Optionally, the command data block includes a main sub-command data block; the main command data block in the main sub-command data block provides the main category information to which the command information to be sent belongs; the sub-command data block in the main sub-command data block provides the sub-category information to which the command information to be sent belongs; and the framing module 401 is further used to: utilize the second framing module of the custom protocol library to assemble the main sub-command data block according to the main category and sub-category to which the command information to be sent belongs.
[0136] Optionally, the framing module 401 is further used to: use the first framing module of the custom protocol library to add a version data block providing version information based on the main sub-command data block.
[0137] Optionally, the framing module 401 is further used to: use the first framing module of the custom protocol library to add a check data block, a type data block and an identity data block based on the main sub-command data block and the version data block; wherein the check data block is used to provide check information of the data frame to be sent; the type data block is used to provide type information of the data frame to be sent; and the identity data block is used to provide identity information of the data frame to be sent.
[0138] Optionally, the data block to be sent includes a response data block to be sent, and the custom protocol library includes a first deframing module and a second deframing module; and the deframing module 402 is further used to: use the first deframing module of the custom protocol library to parse the non-command data frame in the received data frame to obtain a non-command data block; use the second deframing module of the custom protocol library to parse the command data frame providing the received command information in the received data frame to obtain a command data block; and the device also includes a response module, and the above-mentioned response module is used to: use the custom protocol library to obtain the response data block to be sent according to the non-command data block and / or the command data block.
[0139] Optionally, the command data block includes a main sub-command data block; the main command data block in the main sub-command data block provides the main category information to which the received command information belongs; the sub-command data block in the main sub-command data block provides the sub-category information to which the received command information belongs; and the deframing module 402 is further used to: use the second deframing module of the custom protocol library to parse the main sub-command data frame in the received data frame to obtain the main sub-command data block; use the second deframing module of the custom protocol library to call the application layer interface so that the application layer returns the response data block to be sent according to the main sub-command data block.
[0140] Optionally, the deframing module 402 is further used to: use the first deframing module of the custom protocol library to parse the version data frame providing version information in the received data frame to obtain a version data block; and use the first deframing module of the custom protocol library to obtain a response data block representing data processing failure based on the version data block when the version information does not meet the version requirements.
[0141] Optionally, the deframing module 402 is further used to: utilize the first deframing module of the custom protocol library to parse the type data frame providing type information in the received data frame to obtain a type data block; and when the type data block indicates that the received data frame belongs to the response data frame type, parse the identity data frame providing identity information in the received data frame to obtain an identity data block; determine the processing strategy for the sent data frame information corresponding to the identity information provided by the identity data block; and verify the accuracy of the received data frame according to preset verification rules; if the verification result indicates that the received data frame is transmitted accurately, the unparsed main and sub-command data frames in the received data frame are transmitted to the second deframing module; and when the verification result of the first deframing module of the custom protocol library indicates that the received data frame is transmitted incorrectly, obtain a response data block indicating data processing failure according to the verification result.
[0142] Optionally, the device also includes a retransmission module, which is used to: use the custom protocol library to resend the data frame to be sent when the data frame to be sent is not successfully sent within a preset time length; and discard the data frame to be sent when the number of retransmissions exceeds a preset number threshold.
[0143] It should be noted that those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0144] Please refer to Figure 5 , Figure 5 A structural diagram of an electronic device for executing a data processing method provided in an embodiment of the present application, the electronic device may include: at least one processor 501, such as a CPU, at least one communication interface 502, at least one memory 503 and at least one communication bus 504. Among them, the communication bus 504 is used to realize direct connection and communication between these components. Among them, the communication interface 502 of the device in the embodiment of the present application is used to communicate signaling or data with other node devices. The memory 503 can be a high-speed RAM memory or a non-volatile memory (non-volatile memory), such as at least one disk storage. The memory 503 can optionally be at least one storage device located away from the aforementioned processor. Computer-readable instructions are stored in the memory 503. When the computer-readable instructions are executed by the processor 501, the electronic device can execute the above-mentioned Figure 1 The method process is shown.
[0145] Understandably, Figure 5 The structure shown is for illustration only, and the electronic device may also include Figure 5More or fewer components as shown, or with Figure 5 Different configurations are shown. Figure 5 Each component shown in the figure can be implemented by hardware, software or a combination thereof.
[0146] The present application embodiment provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the following can be performed: Figure 1 The method process in the method embodiment shown is executed by the electronic device.
[0147] An embodiment of the present application provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the methods provided by the above-mentioned method embodiments. For example, the method may include: if a data block to be sent is detected, the data block to be sent is framed using a custom protocol library to obtain a data frame to be sent; if a data frame sent by the opposite end based on a near field connection is received, the received data frame is deframed using the custom protocol library.
[0148] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0149] In addition, the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0150] Furthermore, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0151] In this document, relational terms such as first and second, etc. are used merely to distinguish one entity or operation from another entity or operation, but do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0152] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A data processing method, It is characterized in that Applied to a device having a near field connection, the method comprises: If a data block to be sent is detected, the data block to be sent is framed using a custom protocol library to obtain a data frame to be sent; If a data frame sent by the opposite end based on the near field connection is received, the received data frame is deframed using the custom protocol library; The custom protocol library includes a deframing code for performing a custom deframing process on the received data frame, and a framing code for performing a custom framing process on the data block to be sent; The custom protocol library includes a first framing module, a second framing module, a first deframing module and a second deframing module; wherein the first framing module is used to implement the framing code of the L1 layer in the custom protocol, and the second framing module is used to implement the framing code of the L2 layer in the custom protocol; the first deframing module is used to implement the deframing code of the L1 layer in the custom protocol, and the second deframing module is used to implement the deframing code of the L2 layer in the custom protocol; the L1 layer and the L2 layer respectively define the occupancy of data during transmission, and the occupancy represents the number of bytes occupied by the data packet, the data packet header, and the payload, respectively.
2. The method according to claim 1, It is characterized in that The step of performing framing processing on the data block to be sent by using a custom protocol library to obtain a data frame to be sent includes: Using the second frame module of the custom protocol library, assembling a command data block providing command information to be sent in the data block to be sent; Using the first frame module of the custom protocol library, assembling the non-command data blocks in the data blocks to be sent; The data frame to be sent is obtained according to the non-command data block and the command data block by utilizing the custom protocol library.
3. The method according to claim 2, It is characterized in that The command data block includes a main sub-command data block; the main command data block in the main sub-command data block provides the main category information to which the command information to be sent belongs; the sub-command data block in the main sub-command data block provides the sub-category information to which the command information to be sent belongs; as well as The step of utilizing the second frame module of the custom protocol library to assemble a command data block providing command information to be sent in the data block to be sent includes: The second frame module of the custom protocol library is utilized to assemble the main and sub-command data blocks according to the main category and sub-category to which the command information to be sent belongs.
4. The method according to claim 3, It is characterized in that The step of utilizing the first frame module of the custom protocol library to assemble the non-command data block in the data block to be sent includes: The first frame module of the custom protocol library is used to add a version data block providing version information based on the main sub-command data block.
5. The method according to claim 4, It is characterized in that The step of assembling the non-command data block in the data block to be sent by using the first frame module of the custom protocol library further includes: The first group of frame modules of the custom protocol library are used to add a check data block, a type data block and an identity data block on the basis of the main sub-command data block and the version data block; wherein the check data block is used to provide check information of the data frame to be sent; the type data block is used to provide type information of the data frame to be sent; and the identity data block is used to provide identity information of the data frame to be sent.
6. The method according to any one of claims 1 to 5, It is characterized in that The data blocks to be sent include response data blocks to be sent; as well as The step of performing de-framing processing on the received data frame by using the custom protocol library includes: Utilizing the first de-framing module of the custom protocol library, parsing the non-command data frame in the received data frame to obtain a non-command data block; Using the second de-framing module of the custom protocol library, parsing the command data frame providing the received command information in the received data frame to obtain a command data block; and The method further comprises: The response data block to be sent is obtained according to the non-command data block and / or the command data block by utilizing the custom protocol library.
7. The method according to claim 6, It is characterized in that The command data block includes a main sub-command data block; the main command data block in the main sub-command data block provides the main category information to which the received command information belongs; the sub-command data block in the main sub-command data block provides the sub-category information to which the received command information belongs; as well as The second de-framing module of the custom protocol library is used to parse the command data frame providing the received command information in the received data frame to obtain the command data block, including: Utilizing the second de-framing module of the custom protocol library, parsing the main sub-command data frame in the received data frame to obtain a main sub-command data block; and The step of obtaining the response data block to be sent according to the non-command data block and / or the command data block by using the custom protocol library includes: The second de-framing module of the custom protocol library is used to call the application layer interface, so that the application layer returns the response data block to be sent according to the main sub-command data block.
8. The method according to claim 6, It is characterized in that The first de-framing module of the custom protocol library is used to parse the non-command data frame in the received data frame to obtain the non-command data block, including: Using the first de-framing module of the custom protocol library, parsing the version data frame providing version information in the received data frame to obtain a version data block; and The step of obtaining the response data block to be sent according to the non-command data block and / or the command data block by using the custom protocol library includes: When the version information does not meet the version requirement, the first deframing module of the custom protocol library is used to obtain a response data block indicating data processing failure according to the version data block.
9. The method according to claim 6, It is characterized in that The first de-framing module of the custom protocol library is used to parse the non-command data frame in the received data frame to obtain the non-command data block, including: Utilizing the first de-framing module of the custom protocol library, parsing the category data frame providing category information in the received data frame to obtain a category data block; and When the type data block indicates that the received data frame belongs to the type of the response data frame, parsing the identity data frame providing identity information in the received data frame to obtain the identity data block; determining a processing strategy for the sent data frame information corresponding to the identity information provided by the identity data block; and Verifying the accuracy of the received data frame according to a preset verification rule; if the verification result indicates that the received data frame is transmitted accurately, transmitting the unparsed master and sub-command data frames in the received data frame to the second de-framing module; and The step of obtaining the response data block to be sent according to the non-command data block and / or the command data block by using the custom protocol library includes: When the check result of the first deframing module of the custom protocol library indicates that the received data frame has a transmission error, a response data block indicating that data processing has failed is obtained according to the check result.
10. The method according to any one of claims 1 to 5 or 7 to 9, It is characterized in that The method further comprises: Resending the data frame to be sent by using the custom protocol library when the data frame to be sent is not successfully sent within a preset time length; and When the number of retransmissions exceeds a preset number threshold, the data frame to be sent is discarded.
11. A data processing device, It is characterized in that Applicable to a device for establishing a near field connection, the device comprises: A framing module, for, if a data block to be sent is detected, performing framing processing on the data block to be sent by using a custom protocol library to obtain a data frame to be sent; A deframing module, configured to, if a data frame sent by a peer based on a near field connection is received, perform deframing processing on the received data frame using the custom protocol library; The custom protocol library includes a deframing code for performing a custom deframing process on the received data frame, and a framing code for performing a custom framing process on the data block to be sent; The custom protocol library includes a first framing module, a second framing module, a first deframing module and a second deframing module; wherein the first framing module is used to implement the framing code of the L1 layer in the custom protocol, and the second framing module is used to implement the framing code of the L2 layer in the custom protocol; the first deframing module is used to implement the deframing code of the L1 layer in the custom protocol, and the second deframing module is used to implement the deframing code of the L2 layer in the custom protocol; the L1 layer and the L2 layer respectively define the occupancy of data during transmission, and the occupancy represents the number of bytes occupied by the data packet, the data packet header, and the payload, respectively.
12. An electronic device, It is characterized in that The method comprises a processor and a memory, wherein the memory stores computer-readable instructions. When the computer-readable instructions are executed by the processor, the method according to any one of claims 1 to 10 is executed.
13. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 10 is executed.
14. A computer program product comprising a computer program or instructions, It is characterized in that When the computer program or instruction is executed by a processor, the method according to any one of claims 1 to 10 is performed.
