Text analysis method and device for embedded equipment, equipment and medium
By using text-form files to define abstract syntax and keyword code tables in embedded devices, ASCII-encoded text content files are generated, and appropriate communication protocols are selected through the adaptive transmission mechanism, the transmission and parsing problems of embedded devices under resource constraints are solved, and efficient and secure configuration parameter processing is achieved.
Patent Information
- Application Number
- CN202510521757.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-24
- Publication Date
- 2025-07-29
AI Technical Summary
When transmitting and parsing editable parameter text, existing embedded devices face problems such as high resource usage, poor flexibility and insufficient security. Especially when RAM or ROM space is limited and communication bandwidth is limited, traditional JSON or XML formats have problems such as low efficiency and poor security.
Use text-form files to define abstract syntax and keyword code tables, generate ASCII-encoded text content files, and select appropriate communication protocols through an adaptive transmission mechanism to realize the organization, encoding, transmission and parsing of configuration parameters, avoid relying on large-scale parsing libraries, and improve system flexibility and security.
It effectively reduces the ROM usage and computing burden of embedded devices, improves data organization and transmission efficiency, enhances transmission security, supports multiple operating modes, and improves system flexibility and versatility.
Smart Images

Figure HDA0005374177060000011 
Figure HDA0005374177060000021 
Figure HDA0005374177060000031
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of text parsing of embedded devices, and in particular to a text parsing method, device, equipment and medium for embedded devices. Background Art
[0002] Currently, for some embedded products, due to limited RAM or ROM space and bandwidth limitations of communication methods such as BLE and serial ports, in scenarios where editable parameter texts need to be transmitted and parsed, there are two common methods: One is to use JSON or XML format files. This method has a general structure but is relatively complex and requires the introduction of third-party parsing libraries such as cJSON and TinyXML. These libraries usually occupy more than dozens of KB of ROM space during operation and are not suitable for resource-constrained embedded systems. Moreover, they are in plain text structure during transmission, and parameter information is easily parsed and intercepted. The other is that the host computer pre-parses the parameter content, encapsulates it into a data packet with a fixed format, and transmits it to the lower computer through a custom protocol. The lower computer parses the parameters according to the position offset. Although this method saves resources, the protocol format is fixed, the flexibility is poor, and parameter changes require synchronous updates of the communication protocol and firmware, resulting in weak generality and scalability. Summary of the Invention
[0003] In order to improve transmission adaptability, the present application provides a text parsing method, device, equipment and medium for embedded devices.
[0004] The first above-mentioned object of the present application is achieved by the following technical solutions: A text parsing method for an embedded device, the text parsing method for the embedded device includes: Obtain a text-formatted file; Organize device configuration parameter data according to the abstract syntax and keyword code table in the text-formatted file to generate a text content file; Perform ASCII encoding on the text content file to obtain an encoded text content file, and transmit the encoded text content file to the embedded device; In the embedded device, receive the encoded text content file, and parse the encoded text content file according to the abstract syntax and the keyword code table in the text-formatted file to obtain device configuration parameters; Control the working state of the embedded device according to the device configuration parameters.
[0005] By adopting the above technical solutions, it is possible to complete the organization, encoding, transmission, and parsing of configuration parameters without relying on traditional JSON or XML parsing libraries, effectively reducing the ROM occupancy and computing burden of embedded devices; by defining the abstract syntax and keyword code table in a text-form file, the parameter structure is clearer, the format is more unified, and it is convenient for standardization processing; the generated text content file adopts a compact tag structure, reducing redundant information and improving the efficiency of data organization and transmission; through ASCII encoding and binary encapsulation methods, it adapts to communication methods with limited bandwidth such as BLE and serial ports, and to a certain extent avoids the direct reading of parameters during transmission, enhancing transmission security; the device side does not need to load large library files through rule parsing, and the resource usage is more friendly; automatically adjusting the device working state according to the configuration parameters can support multiple operating modes, enhancing the flexibility and versatility of the system.
[0006] In a preferred example, the present application can be further configured as follows: organizing the device configuration parameter data according to the abstract syntax and keyword code table in the text-form file to generate a text content file, including: Determining the format requirements of the device configuration parameters according to the abstract syntax to obtain the format specification of the device configuration parameters; Selecting corresponding keywords and unit codes for the device configuration parameters according to the keyword code table to obtain the encoding rule of the device configuration parameters; Organizing and converting the device configuration parameter data based on the format specification and the encoding rule to obtain device configuration text content that conforms to the specification; Integrating and formatting multiple device configuration parameters according to the device configuration text content to generate the text content file.
[0007] By adopting the above technical solutions, the device configuration parameters can have a clear format specification and encoding structure at the generation stage, avoiding the problems of ambiguous parameter semantics and field interpretation relying on manual maintenance in traditional texts; through the unified format definition of the abstract syntax, the structural composition of the parameter tags is clarified, which is helpful for subsequent automatic recognition and program parsing; through the keyword code table method, information such as parameter names and units is encoded and solidified, reducing redundant text and improving the expression efficiency; in the process of organizing and converting parameter data, combining the format specification and the encoding rule can generate text content with a rigorous structure and concise expression, which is convenient for generalization in different systems or platforms; splicing multiple configuration parameters into a text content file according to the unified syntax not only improves the consistency of data collation and transmission, but also lays a good foundation for subsequent encoding and embedded parsing.
[0008] In a preferred example, this application can be further configured as follows: encoding the text content file in ASCII to obtain an encoded text content file, including: Converting each character in the text content file one by one according to the ASCII encoding standard to obtain the corresponding ASCII code value; Converting the ASCII code value into an 8-bit binary code, and concatenating all the 8-bit binary codes in a preset character order to obtain a continuous binary data stream; Writing the continuous binary data stream into a target file, and after successful writing, encapsulating the target file according to a predetermined format to obtain the encoded text content file.
[0009] By adopting the above technical solution, the structured text content file can be converted into a binary data stream encoded by characters, effectively reducing the character parsing complexity and text redundancy during data transmission, and improving the encoding consistency and transmission adaptability; through character-by-character ASCII encoding and 8-bit binary format concatenation, the controllability of the transmission format and the general compatibility of the device side are ensured; at the same time, after encoding, the target file is structurally encapsulated, so that the generated text content has clear data boundaries and structure identifiers, facilitating integrity verification and content recognition during subsequent parsing, and improving the overall data security and parsing efficiency of the system.
[0010] In a preferred example, this application can be further configured as follows: transmitting the encoded text content file to an embedded device, including: Obtaining network status information; According to the network status information, dynamically selecting a transmission protocol through an adaptive transmission mechanism to obtain the selected transmission protocol; Based on the selected transmission protocol, transmitting the encoded text content file to the embedded device.
[0011] By adopting the above technical solution, it is possible to dynamically sense the communication status according to the current network environment and select the most suitable transmission protocol, enabling the system to achieve effective data transmission under different bandwidth, latency or stability conditions; by selecting protocol types such as TCP, UDP or DCCP through the adaptive transmission mechanism, the transmission efficiency can be ensured while taking into account the transmission stability and reliability; combining the selected protocol to transmit the encoded text content file to the embedded device effectively improves the data adaptation ability and transmission success rate of the system in a complex network environment.
[0012] In a preferred example, this application can be further configured as follows: according to the network status information, dynamically selecting a transmission protocol through an adaptive transmission mechanism to obtain the selected transmission protocol, including: According to the network condition information, evaluate the current network environment through an adaptive transmission mechanism, and calculate the adaptability of different transmission protocols; If the network bandwidth is large and the latency is small, select the TCP protocol; if the network latency is large or the packet loss rate is high, select the UDP protocol; if the network stability is poor, select the DCCP protocol.
[0013] By adopting the above technical solution, it is possible to quantitatively evaluate key indicators such as signal strength, bandwidth, latency, and packet loss rate based on the current network condition information, and combine a preset protocol matching mechanism to perform adaptability scoring on various communication protocols such as TCP, UDP, and DCCP, so as to dynamically select the transmission method that best matches the current network environment, improving the stability, flexibility, and efficiency of data transmission, and is particularly suitable for embedded application scenarios with large network state fluctuations or limited communication conditions.
[0014] In a preferred example of the present application, it can be further configured that: in the embedded device, receive the encoded text content file, and according to the abstract syntax and the keyword code table in the text form file, parse the encoded text content file to obtain device configuration parameters, including: The embedded device performs integrity and validity verification on the encoded text content file; After the verification passes, according to the abstract syntax in the text form file, extract the metadata of the device configuration parameters, and according to the keyword code table, parse the attributes of the device configuration parameters; Based on the metadata and the attributes, integrate the extracted device configuration item information, and convert and map the device configuration item information in a predetermined format to obtain the device configuration parameters.
[0015] By adopting the above technical solution, the embedded device can perform integrity and validity verification on the text content file after receiving it, ensuring that the transmitted data has not been tampered with or damaged, and improving the reliability of data processing; after the verification passes, it can accurately extract the metadata of the device configuration parameters according to the abstract syntax structure, and parse the parameter attributes in combination with the keyword code table, effectively realizing the accurate identification of information such as parameter names, types, and units; on this basis, integrate the extracted configuration item information and convert it into a recognizable internal configuration structure in a predetermined format, enabling the device to quickly complete parameter loading and support subsequent operation control operations, improving the parsing efficiency and system stability.
[0016] In a preferred example of the present application, it can be further configured that: according to the device configuration parameters, control the working state of the embedded device, including: Determine the working mode of the embedded device according to the working mode parameter in the device configuration parameters; Based on the root working mode, adjust the working parameters of the embedded device.
[0017] By adopting the above technical solution, it is possible to automatically identify the working mode that the current embedded device should be in according to the working mode parameter in the device configuration parameters, avoiding the configuration risks and inconveniences brought by manual setting or hard-coded mode switching; after identifying the specific mode, combined with the working parameters corresponding to this mode, it is possible to automatically adjust the control logic, output behavior or functional state of the embedded device, so that the device operating state corresponds precisely to the configuration requirements, thereby improving the operation flexibility, adaptability and configuration efficiency of the system.
[0018] The second inventive object of the present application is achieved by the following technical solution: A text parsing device for an embedded device, the text parsing device for the embedded device includes: A text acquisition module, configured to acquire a text-form file; A configuration data organization module, configured to organize device configuration parameter data according to the abstract syntax and keyword code table in the text-form file, and generate a text content file; An ASCII encoding and transmission module, configured to perform ASCII encoding on the text content file to obtain an encoded text content file, and transmit the encoded text content file to the embedded device; A device configuration parsing module, configured to receive the encoded text content file in the embedded device, and parse the encoded text content file according to the abstract syntax and the keyword code table in the text-form file to obtain device configuration parameters; A working state control module, configured to control the working state of the embedded device according to the device configuration parameters.
[0019] By adopting the above technical solutions, it is possible to complete the organization, encoding, transmission, and parsing of configuration parameters without relying on traditional JSON or XML parsing libraries, effectively reducing the ROM occupancy and computing burden of embedded devices; by defining the abstract syntax and keyword code table in a text-form file, the parameter structure is made clearer, the format is more unified, and it is convenient for standardization processing; the generated text content file adopts a compact tag structure, reducing redundant information and improving the efficiency of data organization and transmission; through ASCII encoding and binary encapsulation methods, it adapts to communication methods with limited bandwidth such as BLE and serial ports, and to a certain extent avoids direct reading of parameters during transmission, enhancing transmission security; the device side does not need to load large library files through rule parsing, and the resource usage is more friendly; automatically adjusting the device working state according to the configuration parameters can support multiple operating modes, improving the flexibility and versatility of the system.
[0020] The above object three of the present application is achieved by the following technical solutions: A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the text parsing method of the above embedded device are implemented.
[0021] The above object four of the present application is achieved by the following technical solutions: A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the text parsing method of the above embedded device are implemented.
[0022] In summary, the present application includes at least one of the following beneficial technical effects: 1. It is possible to complete the organization, encoding, transmission, and parsing of configuration parameters without relying on traditional JSON or XML parsing libraries, effectively reducing the ROM occupancy and computing burden of embedded devices; by defining the abstract syntax and keyword code table in a text-form file, the parameter structure is made clearer, the format is more unified, and it is convenient for standardization processing; the generated text content file adopts a compact tag structure, reducing redundant information and improving the efficiency of data organization and transmission; through ASCII encoding and binary encapsulation methods, it adapts to communication methods with limited bandwidth such as BLE and serial ports, and to a certain extent avoids direct reading of parameters during transmission, enhancing transmission security; the device side does not need to load large library files through rule parsing, and the resource usage is more friendly; automatically adjusting the device working state according to the configuration parameters can support multiple operating modes, improving the flexibility and versatility of the system; 2. The embedded device can verify the integrity and validity of the received text content file after receiving it, ensuring that the transmitted data has not been tampered with or damaged, and improving the reliability of data processing. After the verification passes, it can accurately extract the metadata of the device configuration parameters according to the abstract syntax structure, and parse the parameter attributes in combination with the keyword code table, effectively realizing the accurate identification of information such as parameter names, types, and units. On this basis, the extracted configuration item information is uniformly integrated and converted into a recognizable internal configuration structure in a predetermined format, enabling the device to quickly complete parameter loading and support subsequent operation control operations, improving the parsing efficiency and system stability. 3. It can automatically identify the working mode that the current embedded device should be in according to the working mode parameter in the device configuration parameters, avoiding the configuration risks and inconveniences brought by manual setting or hard-coded mode switching. After identifying the specific mode, combined with the working parameters corresponding to this mode, it can realize the automatic adjustment of the control logic, output behavior, or functional state of the embedded device, making the device operation state accurately correspond to the configuration requirements, thereby improving the operation flexibility, adaptability, and configuration efficiency of the system. Description of the Drawings
[0023] Figure 1 is a flowchart of a text parsing method for an embedded device in an embodiment of the present application; Figure 2 is an implementation flowchart of step S20 in the text parsing method for an embedded device in an embodiment of the present application; Figure 3 is an implementation flowchart of step S30 in the text parsing method for an embedded device in an embodiment of the present application; Figure 4 is another implementation flowchart of step S30 in the text parsing method for an embedded device in an embodiment of the present application; Figure 5 is an implementation flowchart of step S302 in the text parsing method for an embedded device in an embodiment of the present application; Figure 6 is an implementation flowchart of step S40 in the text parsing method for an embedded device in an embodiment of the present application; Figure 7 is an implementation flowchart of step S50 in the text parsing method for an embedded device in an embodiment of the present application; Figure 8 is a principle block diagram of a text parsing device for an embedded device in an embodiment of the present application; Figure 9 is a schematic diagram of the device in an embodiment of the present application. Detailed Description of the Embodiment
[0024] The following further describes the present application in detail with reference to the accompanying drawings.
[0025] In one embodiment, as Figure 1 shown, the present application discloses a text parsing method for an embedded device, specifically including the following steps: S10: Obtain a text-formatted file.
[0026] Specifically, call the embedded file access interface to read the content of the text-formatted file from a specified path in the EEPROM or Flash. After obtaining the path permission by mounting the file system, perform the file handle opening operation. Use the byte-order reading method to load the file data content into the cache array segment by segment, with the length of each read not exceeding the set block size to avoid cache overflow. The cache structure can adopt a linear queue to support sequential access. If the text-formatted file is stored in a compressed format, first judge the compression header identification bit and call the corresponding decompression logic according to the compression algorithm type for block decoding. During the decompression process, locate the compressed segment through a circular offset pointer and restore the original character stream one by one. After decompression, uniformly convert it to the standard ASCII encoding according to the character encoding method, and finally store all the text-formatted content in the byte buffer array to obtain the text-formatted file.
[0027] S20: Organize the device configuration parameter data according to the abstract syntax and keyword code table in the text-formatted file, and generate a text content file.
[0028] Specifically, extract the abstract syntax format by reading the character sequence enclosed by the markup symbols in the text-formatted file. When parsing the abstract syntax, first search for angle brackets and their internal structures in character order, and extract the keyword position, data type identification bit, length description field, and unit placeholder according to the label parsing order. After completing the abstract syntax parsing, match the preset device configuration parameters to the corresponding keyword coding fields item by item according to the mapping relationship in the keyword code table. Each parameter value is converted and padded with zeros according to its type information to meet the length requirements in the abstract syntax. The unit field inserts the unit code obtained by looking up the table into the corresponding position. All parameter labels are combined and spliced according to the arrangement order set in the abstract syntax, and written into the buffer area in the form of a one-dimensional character array in ASCII character rules in sequence. Finally, splice the complete text content structure to obtain a text content file that meets the text syntax requirements.
[0029] S30: Perform ASCII encoding on the text content file to obtain an encoded text content file, and transmit the encoded text content file to the embedded device.
[0030] Specifically, by traversing the organized character stream data in the text content file byte by byte, each character is converted into the corresponding decimal encoding value according to the ASCII code table. During the conversion process, the character transcoding function is called to compare and match the character values, and the matched decimal code values are written into the new encoding buffer. Each write operation advances sequentially to the buffer address in byte mode until all characters are encoded. No line breaks or paragraph symbols are inserted into the encoded character sequence to maintain the data stream continuity. After the encoding is completed, the communication interface is called to initialize the transmission channel, and the current communication protocol is set according to the receiving protocol parameters provided by the device end. If the communication interface is a serial port, the baud rate, parity mode, and data bits are configured. If it is a BLE connection, the service channel and transmission characteristic values are configured. After the initialization is completed, the content of the encoded buffer is sent to the input buffer of the target embedded device in byte order to obtain the complete transmission result of the encoded text content file at the device end.
[0031] S40: In the embedded device, receive the encoded text content file, and according to the abstract syntax and the keyword code table in the text form file, parse the encoded text content file to obtain device configuration parameters.
[0032] Specifically, the incoming encoded content data is obtained in byte order through the device end receiving buffer. After the reception is completed, the byte stream is restored to ASCII characters one by one. By traversing the character stream, each parameter label segment wrapped in angle brackets is extracted. The parameter code, data length field, data type field, and data value segment are parsed in the order of the characters' positions within the label. The data length field is converted from hexadecimal to decimal value to determine the number of bytes of the data value. The data type field determines the parsing method of the current data by looking up the table according to the preset type rules. The data value segment performs byte splicing and radix conversion operations according to the obtained type and length to get the specific value. When parsing each parameter label, the corresponding parameter name is matched by keyword number by looking up the keyword code table in the text form file. If the number does not exist in the code table, the current label is skipped and the next segment is continued to be parsed until all labels are parsed. The parsed parameter names, corresponding values, and unit identifiers are combined into structured configuration data items to obtain the complete device configuration parameters.
[0033] S50: Control the working state of the embedded device according to the device configuration parameters.
[0034] Specifically, after parsing all device configuration parameters, each parameter is classified according to the preset configuration type and written into the corresponding register mapping address. For the working mode parameters, the current mode number is located by looking up the enumeration value mapping table, and the corresponding mode selection bit in the control register is set. For analog parameters such as voltage, current, and frequency, type conversion is performed according to the values in the parsing results and written into the input channels of the analog output control module or the PWM control module. If the parameter involves multi-channel control, the status configuration values under the corresponding channel numbers are updated in the specified control structure in sequence. If there is a parameter dependency relationship, the application priority order is dynamically selected by judging the dependency trigger conditions. The completion of all configurations is judged by the configuration completion flag bit. Finally, according to the start control logic, a trigger command is executed to update the current operating state of the device to obtain the device working state controlled by the configuration parameters.
[0035] In one embodiment, as Figure 2 shown, in step S20, that is, according to the abstract syntax and keyword code table in the text form file, organizing the device configuration parameter data to generate a text content file, including: S201: According to the abstract syntax, determine the format requirements of the device configuration parameters to obtain the format specification of the device configuration parameters.
[0036] Specifically, by scanning the abstract syntax expression defined in the text form file character by character, identifying and extracting the syntax structure symbols and their arrangement order therein, identifying the label boundary symbols such as angle brackets, square brackets, and parentheses through a state machine or a regular expression-based parser, locating the positional relationships of the keyword field, length field, data type field, and unit field in the label, establishing a field correspondence mapping table according to the symbol combination logic in the abstract syntax, clarifying the data format corresponding to each type of field and its byte representation requirements, recording the position and whether it is a default flag if a field allows selection, converting the length mark specified in the syntax to a fixed byte length value if the field is fixed-length, and further confirming the length bits through the type identifier if it is variable-length. Through the above field sequence relationship and data restriction rules, a complete syntax matching model is constructed, and finally a unified format field specification table is formed to describe the structural requirements that each type of device configuration parameter should meet to obtain the format specification of the device configuration parameters.
[0037] S202: According to the keyword code table, select the corresponding keywords and unit codes for the device configuration parameters to obtain the encoding rule of the device configuration parameters.
[0038] Specifically, by scanning the keyword code table defined in the text-formatted file, the number value and unit identifier corresponding to each keyword are extracted using character matching. By traversing the device configuration parameter list, the name of each parameter is compared one by one with the keyword field in the code table. When the names match exactly, the coding number corresponding to the keyword is recorded and used as the keyword code of the current parameter. At the same time, the physical quantity type to which the current parameter belongs, such as voltage, current, frequency, etc., is retrieved, and the unit identifier code corresponding to its unit field is found in the code table and associated for storage. If the parameter involves a custom unit, the extended unit table is searched to determine its coding value. All coding fields are arranged in the order of keyword first and unit second to construct a structured coding template for the parameter. During the subsequent generation process of the text content file, the parameter values can be directly filled into this template according to this template to form a complete label, thereby completing the unique identification method of the parameter in text expression to obtain the coding rule of the device configuration parameter.
[0039] S203: Based on the format specification and the coding rule, organize and transform the device configuration parameter data to obtain device configuration text content that conforms to the specification.
[0040] Specifically, determine the overall structural framework of the parameter label according to the parsed format specification, including the arrangement order of the keyword position, data length field, data type field, and unit field. Then, according to the coding rule, map the name of each device configuration parameter to the corresponding keyword code, and convert the unit information into the unit code and fill it into the specified field position. For the value of each parameter, first determine its numerical expression format, such as integer, unsigned integer, or hexadecimal representation, according to the data type field. If it is a decimal input, the numerical value is converted to the corresponding base and aligned to the specified byte length through the type conversion logic, and the insufficient part is filled with zeros, and the high-order zeros are filled with leading zeros. During the splicing process of all fields, they are nested in the structure wrapped by angle brackets according to the syntax requirements to form a complete label. Multiple parameter labels are arranged in order and appended to the same character buffer area. Each time a parameter is processed, a label string that conforms to the format specification is generated. Finally, all the labels are combined into a continuous parameter configuration content to obtain device configuration text content that conforms to the specification.
[0041] S204: According to the device configuration text content, integrate and format multiple device configuration parameters to generate the text content file.
[0042] Specifically, each piece of configuration text content is read in sequence according to the arrangement relationship of device configuration parameters in the function call sequence. Each generated tag string is appended to a unified buffer in a predetermined order. The buffer uses a sequential write method and is arranged continuously by bytes to maintain the integrity of the data structure. No delimiter is inserted between each tag to avoid introducing offsets due to invalid characters. If there are parameter dependencies or associated sequence requirements, the parameter tags with triggering relationships are written first and the write sequence numbers are recorded. After all parameter tags are written, all characters in the buffer are output as a character array in the original encoding method, and the character write interface is called to write the character array into the target path file in the file system. The write operation uses a single-channel sequential write mode to avoid position offset problems caused by concurrent writes. After the write is completed, the end-of-file marker is confirmed and the file handle is closed to obtain a complete structured text content file.
[0043] In one embodiment, as Figure 3 shown, in step S30, that is, performing ASCII encoding on the text content file to obtain an encoded text content file, including: S301: Each character in the text content file is converted one by one according to the standard of the ASCII encoding to obtain the corresponding ASCII code value.
[0044] Specifically, all character data in the text content file is traversed in character order. The character values are extracted one by one by calling the character reading function, and the decimal encoding value corresponding to the current character is searched in the locally established standard ASCII code mapping table. A matching operation is performed each time a character is extracted. The matching process is realized by comparing the character value with the index position in the ASCII code table through table lookup. When the corresponding encoding is found, the encoding value is written into the encoding cache array. The encoding cache is organized in the original order of the characters without reverse order or compression processing. Special symbols such as line break characters, space characters, and angle brackets in the characters are directly encoded according to the standard ASCII values without skipping or replacement. If an illegal character is encountered during the processing, the character is skipped and the next valid character is encoded until the entire character encoding conversion process is completed after the traversal to obtain the complete ASCII code value.
[0045] S302: The ASCII code value is converted into an 8-bit binary encoding, and all the 8-bit binary encodings are concatenated in a preset character order to obtain a continuous binary data stream.
[0046] Specifically, after obtaining the ASCII code values, each decimal ASCII code value in the encoding cache array is traversed in sequence. By calling the integer-to-binary function, each code value is converted into the corresponding 8-bit binary string. During the conversion process, the digit length of the current code value is judged. If it is less than 8 bits, zeros are filled in front of its high bits until the 8-bit format requirement is met. The zero-padding logic adopts the leading-zero filling method to avoid data meaning deviation. After the conversion is completed, each 8-bit binary result is appended to the binary concatenation buffer in the original order of the characters. The concatenation operation controls the writing position through a displacement pointer. Each time a group is written, the pointer is advanced 8-bit positions backward. After all the data is concatenated, a binary code stream continuously combined in the order of character arrangement is obtained. During the entire concatenation process, no interval bits are introduced, no segment symbols are used, and the complete original character logical order is retained to obtain a continuous binary data stream.
[0047] S303: Write the continuous binary data stream into the target file. After the writing is successful, encapsulate the target file according to a predetermined format to obtain the encoded text content file.
[0048] Specifically, the target file under the specified path can be created or opened through a file writing interface. Before writing, initialize the file handle and set it to the binary writing mode. Subsequently, the continuous binary data stream is taken out byte by byte from the concatenation buffer and written into the target file in a sequential writing manner. Set the writing buffer size during the writing process to ensure that the data block of each operation is within the tolerable range of the device. If an exception occurs during the writing, perform a rollback operation to reset the writing pointer to the previous successful position and continue writing. After all the data is written, perform a file closing operation and reposition the file header position. Write the header identification field, including the version number, data length, and check bit field, at the starting position of the file according to the predetermined encapsulation format. Then append a terminator or check tail code at the end of the file. The encapsulation format determines the field length and position according to the current device communication protocol, without compression or encryption processing. After the encapsulation is completed, the file is stored as the encoded text content file under the target path to obtain the final output result.
[0049] In one embodiment, as Figure 4 shown, in step S30, that is, transmitting the encoded text content file to the embedded device includes: S304: Obtain network status information.
[0050] Specifically, the network connection information of the current device is obtained by calling the status detection function in the network interface management module. During the status detection process, it first checks whether the network module is in an active state, then queries the current connection type including Wi-Fi, cellular network, or Bluetooth, and collects the corresponding signal strength, bandwidth rate, connection stability, and current packet loss rate. The signal strength is obtained by reading the RSSI value of the module, the bandwidth rate is calculated from the statistical result of the data throughput within a fixed time window, the packet loss rate is calculated by comparing the number of sent and received data packets to calculate the error ratio, and the connection stability can be statistically analyzed by the number of disconnections and reconnections within a set time period. Finally, the above-collected parameters are summarized and organized into a network status information structure and stored in the status cache for subsequent transmission policy judgment.
[0051] S305: According to the network condition information, dynamically select a transmission protocol through an adaptive transmission mechanism to obtain the selected transmission protocol.
[0052] Specifically, extract each index value from the network status information structure stored in the status cache as an adaptive judgment condition, compare each index threshold according to the preset protocol selection rules, and calculate the current network adaptation score. If the signal strength is higher than the set upper limit and the packet loss rate is lower than the minimum tolerance range, set the scoring weight to favor the TCP protocol. If frequent bandwidth changes or packet loss phenomena are detected, the score favors the UDP protocol. If there are multiple disconnection and reconnection records within a certain time window, increase the adaptation score for the DCCP protocol. Finally, sort all the protocol score results and select the transmission protocol with the highest score as the target protocol for the current file transmission and record the protocol type for subsequent interface calls.
[0053] S306: Based on the selected transmission protocol, transfer the encoded text content file to the embedded device.
[0054] Specifically, initialize the corresponding communication module according to the target protocol type determined in the previous step. If it is the TCP protocol, establish a stable connection channel based on the handshake process and confirm the receiving end port listening state. If it is the UDP protocol, directly configure the target IP and port for data sending preparation without establishing a connection. If it is the DCCP protocol, call the connection initialization process that supports congestion control to complete the transmission path configuration. After the protocol initialization, read the data in blocks from the encoded text content file, and the length of each read data is dynamically adjusted according to the transmission unit of the protocol. Send each segment of the read data in sequence through the data sending interface and monitor the sending status code feedback in real time. During the entire transmission process, adjust the transmission rate or retransmission strategy according to network changes until all content is sent and a receive confirmation response is received, then close the transmission channel to complete the sending process.
[0055] In one embodiment, as Figure 5 shown, in step S305, that is, according to the network condition information, dynamically select a transmission protocol through an adaptive transmission mechanism to obtain the selected transmission protocol, including: S3051: According to the network condition information, evaluate the current network environment through an adaptive transmission mechanism, and calculate the adaptability of different transmission protocols.
[0056] Specifically, extract indicators such as signal strength, current bandwidth, average delay, packet loss rate, and connection interruption frequency from the network status information structure in sequence. Establish a set of evaluation parameter weight models for each transmission protocol. Set a scoring formula for each indicator in the model and perform weighted operations in combination with empirical weight factors. The signal strength is converted into a score through the RSSI value and then multiplied by the channel stability coefficient. The bandwidth score is obtained from the ratio of the data throughput per unit time to the maximum bandwidth. The delay score is converted into a reverse score according to the difference between the average response time and the set threshold. The packet loss rate score obtains the weight coefficient based on the contrast between the error code ratio and the reliability requirement. The connection interruption frequency is used to evaluate the long-term transmission stability and directly affects the protocol switching priority. Finally, sum up the weights of all the above indicators to form an adaptability score table for each protocol for subsequent sorting and selection.
[0057] S3052: If the network bandwidth is large and the delay is small, select the TCP protocol. If the network delay is large or the packet loss rate is high, select the UDP protocol. If the network stability is poor, select the DCCP protocol.
[0058] Specifically, after calculating the adaptability scores of each transmission protocol, make a conditional judgment in combination with the real-time state parameters of the current network. If the current bandwidth score exceeds the set threshold and the delay score is in the excellent value range, it meets the stable transmission condition of the TCP protocol. Mark the TCP protocol as the first choice and send it back to the protocol management module for configuration. If it is detected that the delay score is in the low score range or the packet loss score is negatively offset and the stability score is higher than the reliable transmission bottom line, it is judged that the current environment is more suitable for the connectionless UDP protocol and make the corresponding identification. If the bandwidth and delay scores do not have the advantage of protocol selection and the stability score is lower than the set threshold, write the DCCP protocol as a candidate protocol to the first place of the priority list through the connection fluctuation record. Finally, switch the corresponding communication interface according to the identification result of the selected protocol to complete the protocol layer initialization preparation.
[0059] In one embodiment, as Figure 6 shown, in step S40, that is, in the embedded device, receive the encoded text content file, and parse the encoded text content file according to the abstract syntax and the keyword code table in the text form file to obtain device configuration parameters, including: S401: The embedded device verifies the integrity and validity of the encoded text content file.
[0060] Specifically, after the embedded device receives the encoded text content file, it first reads the version number field and the checksum field in the file header. By comparing the version number, it determines whether the current parsing module supports this version format. If it does not support, the parsing process is aborted. Subsequently, it reads all the content of the file body and performs an integrity check based on the pre-set checksum algorithm before transmission. The check method can use CRC-16 or a custom XOR check method to perform cyclic calculations on each segment of data, and compares the calculation result with the checksum at the end of the file to determine whether an error occurred during data transmission. If an abnormal or missing byte sequence is detected, the error location is recorded and the processing is terminated. If the check passes, it continues to perform a syntax check on the content structure to verify whether all tags conform to the nested structure, field order, and length legality in the abstract syntax. After all checks are correct, the current content is marked as valid to complete the integrity and validity verification.
[0061] S402: If the verification passes, according to the abstract syntax in the text form file, extract the metadata of the device configuration parameters, and parse the attributes of the device configuration parameters according to the keyword code table.
[0062] Specifically, scan the character stream tag by tag from the decoded text content file according to the tag structure defined in the abstract syntax, identify each tag block wrapped in angle brackets, and extract the keyword number, data length mark, type identification bit, and unit code according to the field position. The field extraction process uses character offsets for positioning and intercepts the values within the corresponding range as a preliminary metadata set. The keyword number in the metadata is used for matching operations in the keyword code table. If the match is successful, the corresponding parameter name, supported data types, and unit type list are returned. If the data length field does not match the parameter definition, it is marked as an illegal parameter and the current tag is skipped to continue processing the next segment. The type identification bit is used to define the data parsing method, for example, to distinguish between integer type, floating-point type, or array type. The unit code is matched to the corresponding physical quantity unit. Finally, a metadata structure containing the original field information and parameter semantic information is extracted for subsequent mapping and integration. S403: Based on the metadata and the attributes, integrate the extracted device configuration item information, convert and map the device configuration item information according to a predetermined format to obtain the device configuration parameters.
[0063] Specifically, after the metadata structure extraction is completed, all the parsed parameter field information is sorted and integrated according to the preset parameter list order. During the integration process, the parameter name represented by the keyword is used as the main index item, and the corresponding data value field is subjected to a format conversion operation according to the data type. If it is an integer data, it is concatenated in byte order and then converted to decimal representation. If it is a floating-point type, a floating-point parsing function is called for binary-to-floating-point processing. The unit field is converted to the standard unit name through a mapping table and bound to the value. Each group of configuration items after integration is organized in the form of "parameter name: value + unit". All configuration items are combined into a structured parameter list or a key-value pair array. If the device supports the structure configuration method, the parameter array is written into the corresponding structure field of the device runtime configuration table, and finally a complete parameter object set including name, value, and unit is formed to obtain the device configuration parameters.
[0064] In one embodiment, as Figure 7 shown, in step S50, that is, according to the device configuration parameters, controlling the working state of the embedded device includes: S501: Determine the working mode of the embedded device according to the working mode parameter in the device configuration parameters.
[0065] Specifically, in the device configuration parameter set, the parameter item representing the working mode is extracted according to the preset key name or index field, the value of the parameter item is read and matched and judged according to the parameter definition file or the enumeration mapping table. During the matching process, the value is compared with the defined mode numbers one by one to confirm the current belonging mode number. If the parameter is multi-bit encoded, the valid bit field is extracted through bit shift operation and then decoded and judged. If the mode parameter supports the extended type, after the multi-field combination, the complete mode encoding is generated by regular splicing and then compared. After the mode matching is completed, the current mode number is written into the main control register or the status variable according to the predefined working mode identifier in the device operation control table, and at the same time, the current running state is reset to switch to the selected working mode.
[0066] S502: Based on the root working mode, adjust the working parameters of the embedded device.
[0067] Specifically, after determining the current working mode number, load the corresponding parameter item list for this mode from the mode configuration mapping table, and sequentially search for the actual values corresponding to each item in the list in the device configuration parameter set. Perform format verification and conversion on the found parameter values according to their types. After the conversion is completed, write them into the corresponding function module register or control interface through the parameter mapping relationship. For example, when the working mode is the voltage control mode, write the voltage parameter value into the analog output channel control register after processing it through the voltage conversion function. When the working mode is the frequency drive mode, write the frequency parameter into the timer configuration area after obtaining the control bit map through clock division calculation. If some parameters are not enabled in the current mode, skip the writing process and clear the corresponding configuration area. After all the parameters are written, set the update flag bit and trigger the mode activation instruction to complete the adjustment of the operating parameters of the embedded device in the current mode.
[0068] It should be understood that the magnitudes of the sequence numbers of the steps in the above embodiments do not imply the order of execution. The order of execution of each process should be determined by its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
[0069] In one embodiment, a text parsing device for an embedded device is provided. The text parsing device for the embedded device corresponds one-to-one with the text parsing method of the embedded device in the above embodiment. As Figure 8 shown, the text parsing device for the embedded device includes a text acquisition module, a configuration data organization module, an ASCII encoding and transmission module, a device configuration parsing module, and a working state control module. The detailed description of each function module is as follows: The text acquisition module is used to acquire text-formatted files; The configuration data organization module is used to organize device configuration parameter data according to the abstract syntax and keyword code table in the text-formatted file, and generate a text content file; The ASCII encoding and transmission module is used to perform ASCII encoding on the text content file to obtain an encoded text content file, and transmit the encoded text content file to the embedded device; The device configuration parsing module is used to receive the encoded text content file in the embedded device, and parse the encoded text content file according to the abstract syntax and the keyword code table in the text-formatted file to obtain device configuration parameters; The working state control module is used to control the working state of the embedded device according to the device configuration parameters.
[0070] Optionally, the configuration data organization module includes: A format specification generation sub-module, configured to determine the format requirements of the device configuration parameters according to the abstract syntax, and obtain the format specification of the device configuration parameters; A parameter coding rule generation sub-module, configured to select corresponding keywords and unit codes for the device configuration parameters according to the keyword code table, and obtain the coding rule of the device configuration parameters; A parameter conversion and organization sub-module, configured to organize and convert the device configuration parameter data based on the format specification and the coding rule, and obtain the device configuration text content that conforms to the specification; A text content file generation sub-module, configured to integrate and format multiple device configuration parameters according to the device configuration text content, and generate the text content file.
[0071] Optionally, the ASCII encoding and transmission module includes: An ASCII encoding sub-module, configured to convert each character in the text content file one by one according to the standard of the ASCII encoding, and convert it into the corresponding ASCII code value; A binary splicing sub-module, configured to convert the ASCII code value into an 8-bit binary encoding, and splice all the 8-bit binary encodings in a preset character order to obtain a continuous binary data stream; An encoded file encapsulation sub-module, configured to write the continuous binary data stream into a target file, and after successful writing, encapsulate the target file according to a predetermined format to obtain the encoded text content file.
[0072] Optionally, the ASCII encoding and transmission module further includes: A network status acquisition sub-module, configured to acquire network status information.
[0073] An adaptive protocol selection sub-module, configured to dynamically select a transmission protocol through an adaptive transmission mechanism according to the network status information, and obtain the selected transmission protocol; A data transmission sub-module, configured to transmit the encoded text content file to the embedded device based on the selected transmission protocol.
[0074] Optionally, the adaptive protocol selection sub-module includes: A network environment evaluation unit, configured to evaluate the current network environment through an adaptive transmission mechanism according to the network status information, and calculate the adaptability of different transmission protocols; A protocol decision-making unit, configured to select the TCP protocol if the network bandwidth is large and the delay is small, select the UDP protocol if the network delay is large or the packet loss rate is high, and select the DCCP protocol if the network stability is poor.
[0075] Optionally, the device configuration parsing module includes: A content verification module, configured to verify the integrity and validity of the encoded text content file by the embedded device; A parameter information extraction module, configured to, after passing the verification, extract metadata of the device configuration parameters according to the abstract syntax in the text form file, and parse attributes of the device configuration parameters according to the keyword code table; A configuration parameter mapping module, configured to integrate the extracted device configuration item information based on the metadata and the attributes, convert and map the device configuration item information in a predetermined format to obtain the device configuration parameters.
[0076] Optionally, the working state control module includes: A working mode recognition sub-module, configured to determine the working mode of the embedded device according to the working mode parameter in the device configuration parameters; An operating parameter adjustment sub-module, configured to adjust the operating parameters of the embedded device based on the root working mode.
[0077] For the specific limitations on the text parsing device of the embedded device, reference may be made to the limitations on the text parsing method of the embedded device in the foregoing, which will not be elaborated herein. Each module in the foregoing text parsing device of the embedded device may be implemented in whole or in part by software, hardware, and their combination. The foregoing modules may be embedded in or independent of a processor in a computer device in the form of hardware, or may be stored in a memory in a computer device in the form of software, so as to be called by the processor to execute the operations corresponding to the foregoing modules.
[0078] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as Figure 9 shown. The computer device includes a processor, a memory, a network interface, and a database connected through a system bus. Wherein, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. The computer program, when executed by the processor, implements a text parsing method for an embedded device.
[0079] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the following steps are implemented: Obtain a text form file; Organize the device configuration parameter data according to the abstract syntax and keyword code table in the text form file, and generate a text content file; Perform ASCII encoding on the text content file to obtain the encoded text content file, and transfer the encoded text content file to the embedded device; In the embedded device, receive the encoded text content file, and parse the encoded text content file according to the abstract syntax and keyword code table in the text form file to obtain the device configuration parameters; Control the working state of the embedded device according to the device configuration parameters.
[0080] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented: Obtain the text form file; Organize the device configuration parameter data according to the abstract syntax and keyword code table in the text form file, and generate a text content file; Perform ASCII encoding on the text content file to obtain the encoded text content file, and transfer the encoded text content file to the embedded device; In the embedded device, receive the encoded text content file, and parse the encoded text content file according to the abstract syntax and keyword code table in the text form file to obtain the device configuration parameters; Control the working state of the embedded device according to the device configuration parameters.
[0081] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, storage, database, or other medium used in the embodiments provided in the present application can include non-volatile and / or volatile memories. Non-volatile memories can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memories can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and Rambus dynamic RAM (RDRAM), etc.
[0082] Those skilled in the art can clearly understand that for the convenience and brevity of description, only the above division of each functional unit and module is used as an example. In actual applications, the above functions can be allocated to different functional units and modules according to needs, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above.
[0083] The above embodiments are only used to illustrate the technical solutions of the present application, not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A text parsing method for an embedded device, characterized in that, The text parsing method of the embedded device includes: Obtain a text-formatted file; Organize device configuration parameter data according to the abstract syntax and keyword code table in the text-formatted file to generate a text content file; Perform ASCII encoding on the text content file to obtain an encoded text content file, and transmit the encoded text content file to the embedded device; In the embedded device, receive the encoded text content file, and parse the encoded text content file according to the abstract syntax and the keyword code table in the text-formatted file to obtain device configuration parameters; Control the working state of the embedded device according to the device configuration parameters.
2. The text parsing method of the embedded device according to claim 1, wherein The organizing device configuration parameter data according to the abstract syntax and keyword code table in the text-formatted file to generate a text content file includes: Determine the format requirements of the device configuration parameters according to the abstract syntax to obtain the format specification of the device configuration parameters; Select corresponding keywords and unit codes for the device configuration parameters according to the keyword code table to obtain the encoding rule of the device configuration parameters; Organize and convert the device configuration parameter data based on the format specification and the encoding rule to obtain a device configuration text content that meets the specification; Integrate and format multiple device configuration parameters according to the device configuration text content to generate the text content file.
3. The text parsing method of the embedded device according to claim 1, characterized in that The performing ASCII encoding on the text content file to obtain an encoded text content file includes: Convert each character in the text content file one by one according to the standard of the ASCII encoding to convert it into the corresponding ASCII code value; Convert the ASCII code value into an 8-bit binary encoding, and splice all the 8-bit binary encodings in a preset character order to obtain a continuous binary data stream; Write the continuous binary data stream into a target file, and after successful writing, encapsulate the target file according to a predetermined format to obtain the encoded text content file.
4. The text parsing method of the embedded device according to claim 1, characterized in that, The transmitting the encoded text content file to the embedded device includes: Obtain network status information; Dynamically select a transmission protocol through an adaptive transmission mechanism according to the network status information to obtain a selected transmission protocol; Transmit the encoded text content file to the embedded device based on the selected transmission protocol.
5. The text parsing method of the embedded device according to claim 4, characterized in that The dynamically selecting a transmission protocol through an adaptive transmission mechanism according to the network status information to obtain a selected transmission protocol includes: Evaluate the current network environment through an adaptive transmission mechanism according to the network status information, and calculate the adaptability of different transmission protocols; If the network bandwidth is large and the latency is small, select the TCP protocol; if the network latency is large or the packet loss rate is high, select the UDP protocol; if the network stability is poor, select the DCCP protocol.
6. The text parsing method of the embedded device according to claim 1, characterized in that, In the embedded device, receive the encoded text content file, and parse the encoded text content file according to the abstract syntax and the keyword code table in the text form file to obtain device configuration parameters, including: The embedded device performs integrity and validity verification on the encoded text content file; After passing the verification, extract the metadata of the device configuration parameters according to the abstract syntax in the text form file, and parse the attributes of the device configuration parameters according to the keyword code table; Based on the metadata and the attributes, integrate the extracted device configuration item information, and convert and map the device configuration item information in a predetermined format to obtain the device configuration parameters.
7. The text parsing method of the embedded device according to claim 1, characterized in that, According to the device configuration parameters, control the working state of the embedded device, including: Determine the working mode of the embedded device according to the working mode parameter in the device configuration parameters; Based on the root working mode, adjust the working parameters of the embedded device.
8. A text parsing device for an embedded device, characterized in that The text parsing device of the embedded device includes: A text acquisition module for acquiring a text form file; A configuration data organization module for organizing device configuration parameter data according to the abstract syntax and keyword code table in the text form file to generate a text content file; An ASCII encoding and transmission module for performing ASCII encoding on the text content file to obtain an encoded text content file, and transmitting the encoded text content file to the embedded device; A device configuration parsing module for receiving the encoded text content file in the embedded device and parsing the encoded text content file according to the abstract syntax and the keyword code table in the text form file to obtain device configuration parameters; A working state control module for controlling the working state of the embedded device according to the device configuration parameters.
9. An embedded device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the text parsing method of the embedded device according to any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the steps of the text parsing method of the embedded device according to any one of claims 1 to 7.