AT command parameter dynamic coding and decoding method and system based on prefix identifier
By using a dynamic encoding and decoding method based on prefix identifiers, the flexibility and compatibility issues of AT command parameter processing in existing technologies are resolved, achieving efficient and reliable AT command parameter transmission and ensuring encoding and decoding consistency and accuracy across devices and scenarios.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- WUHAN MENGXIN TECH CO LTD
- Filing Date
- 2025-12-16
- Publication Date
- 2026-05-01
AI Technical Summary
Existing technologies for processing AT command parameters suffer from several drawbacks. Fixed encoding methods increase data transmission overhead and lack flexibility, while character escaping methods are logically complex and have poor compatibility. These technologies cannot efficiently and reliably solve the problem of transmitting non-printable ASCII characters, thus affecting communication stability and versatility.
A dynamic encoding and decoding method based on prefix identifiers is adopted. Special character sets and encoding algorithms are predefined, and a unique prefix identifier is configured for each encoding algorithm. The method determines whether special characters are contained by character traversal analysis. Only parameters containing special characters are encoded and the prefix identifier is concatenated. Plaintext parameters are directly output and finally assembled according to AT command syntax.
By reducing unnecessary processing overhead, shortening command transmission length, avoiding misinterpretation at the receiving end, and balancing transmission efficiency and reliability, dynamic and flexible encoding and decoding of AT command parameters has been achieved, improving the consistency and accuracy of encoding and decoding across devices and scenarios.
Smart Images

Figure CN121967544A_ABST
Abstract
Description
A method and system for dynamic encoding and decoding of AT command parameters based on prefix identifiers Technical Field
[0001] This invention relates to the field of communication technology, and in particular to a method and system for dynamic encoding and decoding of AT command parameters based on prefix identifiers. Background Technology
[0002] In the field of communication technology, AT commands, as a core control protocol between devices such as embedded systems and mobile communication modules, are widely used in the command interaction of modems and mobile devices. They typically rely on characters such as commas, equal signs, and carriage returns as separators for parameter parsing and command execution. However, in practical applications, when the parameter values of AT commands themselves contain special characters, parsing errors can easily occur, and this problem has become a common hidden danger affecting the reliability of device communication.
[0003] To address the aforementioned issues, existing technologies primarily employ two solutions: one is a fixed encoding method, which uniformly uses Base64 or similar encoding for all parameters or parameters of specific types, avoiding the influence of special characters through encoding conversion; the other is a character escaping method, which uses escape characters to mark and convert special characters in the parameters, enabling the parser to distinguish between delimiters and characters within the parameters. Both methods can alleviate parsing problems caused by special characters in certain scenarios and have become the mainstream processing methods in the industry.
[0004] However, the aforementioned existing technologies have significant common defects: the fixed encoding method lacks flexibility and uniformly processes simple parameters that do not require encoding, which not only increases the overhead of data transmission and command length, but also reduces the intuitiveness of user interaction; the character escaping method has complex implementation logic and lacks a unified standard for escaping rules, resulting in poor compatibility between devices from different manufacturers. At the same time, neither method can efficiently and reliably solve the problem of transmitting non-printable ASCII characters, and it is also difficult to avoid ambiguity and misjudgment in the parsing process, ultimately affecting the stability and universality of AT command communication. Summary of the Invention
[0005] This invention provides a method and system for dynamic encoding and decoding of AT command parameters based on prefix identifiers. This method can reduce unnecessary processing overhead and shorten the command transmission length. At the same time, the prefix identifier clearly indicates the encoding method, avoiding misinterpretation by the receiving end. It balances transmission efficiency and reliability, and realizes dynamic and flexible encoding and decoding of AT command parameters.
[0006] To achieve the above objectives, embodiments of the present invention employ the following technical solutions: Firstly, a dynamic encoding and decoding method for AT command parameters based on prefix identifiers is provided. The method includes an encoding process, comprising: predefining a special character set and an encoding algorithm; configuring a unique corresponding prefix identifier for each encoding algorithm, the prefix identifier being a string used to indicate the encoding method; performing character traversal analysis on each parameter of the AT command to be sent to determine whether it contains any character from the predefined special character set; if not, directly outputting the parameter as a plaintext parameter; if it contains, encoding the parameter according to the encoding algorithm corresponding to the parameter, and concatenating the corresponding prefix identifier before the encoded data to form an encoded parameter; assembling all plaintext parameters and encoded parameters according to the AT command syntax to generate a target command string and sending it.
[0007] The beneficial effects of this invention are as follows: The method provided by this invention performs character traversal analysis on the AT command parameters to be sent by predefining a special character set, encoding algorithm, and unique prefix identifier. Only parameters containing special characters are encoded and concatenated with the prefix identifier; parameters without special characters are output directly in plaintext. Finally, the parameters are assembled and sent according to the AT command syntax. This design breaks through the limitation of existing fixed encoding methods that uniformly encode all parameters. By "encoding on demand," unnecessary processing overhead is reduced, and the command transmission length is shortened. At the same time, the prefix identifier clearly indicates the encoding method, avoiding misinterpretation at the receiving end. It balances transmission efficiency and reliability, and realizes dynamic and flexible encoding and decoding of AT command parameters.
[0008] In one possible implementation of the first aspect, the predefined special character set includes AT command syntax separators, control characters, non-printable ASCII characters, leading and trailing whitespace characters, and all defined prefix identifier strings.
[0009] The method provided by this invention explicitly predefines a special character set that includes AT command syntax separators, control characters, non-printable ASCII characters, leading and trailing whitespace characters, and all prefix identifier strings, comprehensively covering character types that may cause parsing ambiguity or transmission difficulties in AT command interaction. By precisely defining the range of special characters to be encoded, it avoids encoding / decoding failures caused by character omissions, prevents over-encoding from increasing the system burden, ensures the accuracy of encoding triggering, and provides a clear judgment basis for the reliable execution of subsequent dynamic encoding / decoding.
[0010] In one possible implementation of the first aspect, the AT command syntax separators include commas, semicolons, and equal signs; the control characters include carriage returns and newlines; the non-printable ASCII characters are characters with ASCII values less than 32 or greater than 126; and the leading and trailing whitespace characters include spaces and tabs.
[0011] The method provided by this invention refines the specific types of various characters in a predefined special character set, clarifying the specific meanings of syntax separators, control characters, non-printable ASCII characters, and whitespace characters, especially defining the ASCII value range of non-printable ASCII characters. This refined definition makes the judgment criteria for special characters uniform and quantifiable, avoiding misunderstandings of special characters in different devices or scenarios, improving the universality and operability of the method, and ensuring consistency of encoding and decoding across devices and scenarios.
[0012] In one possible implementation of the first aspect, the encoding algorithm includes at least one of Hex encoding, Base32 encoding, and Base64 encoding; the prefix identifier corresponds one-to-one with the encoding algorithm, and the prefix identifier is a string of fixed length, wherein the prefix identifier uses a colon as a separator from the encoded data.
[0013] The method provided by this invention limits the encoding algorithm to at least one of Hex, Base32, and Base64, with a one-to-one correspondence between the prefix identifier and the encoding algorithm, a fixed length, and a colon as the separator. Support for multiple encoding algorithms meets the needs of different parameter characteristics and transmission scenarios, improving the flexibility of the method. Furthermore, the fixed-length prefix identifier and colon separator design allows the receiving end to quickly identify and extract the encoding identifier and encoded data, simplifying the parsing logic, improving decoding efficiency, and avoiding confusion between the identifier and data, thus ensuring the accuracy of encoding and decoding.
[0014] In one possible implementation of the first aspect, encoding the parameters according to the encoding algorithm corresponding to the parameters includes: determining the algorithm selection mode of the AT command to be sent, the algorithm selection mode including a preset fixed algorithm mode or a dynamically adapted algorithm mode; when the algorithm selection mode is the preset fixed algorithm mode, then calling a preset encoding algorithm to encode the parameters containing special characters; when the algorithm selection mode is the dynamically adapted algorithm mode, then analyzing the parameter characteristics, the parameter characteristics including the type of special characters, the length of the parameter data, and the transmission scenario; when the parameter contains multiple non-printable ASCII characters, determining Hex encoding as the target encoding algorithm; when the length of the parameter data is greater than a preset length threshold, determining Base64 encoding as the target encoding algorithm; when the transmission scenario is a compatibility scenario, determining Base32 encoding as the target encoding algorithm; and calling the target encoding algorithm to encode the parameters containing special characters.
[0015] Specifically, the preset encoding algorithm can be flexibly configured by the user according to the user's actual usage scenario, or it can be the default encoding algorithm. This embodiment of the invention does not impose any special restrictions on this.
[0016] The method provided by this invention selects the encoding algorithm through two modes: a preset fixed algorithm and a dynamic adaptation algorithm. In the dynamic adaptation mode, the optimal algorithm is precisely matched according to the special character type of the parameter, the data length, and the transmission scenario. When the parameter contains multiple non-printable ASCII characters, Hex encoding is selected; for long parameters, Base64 encoding is selected; and for compatibility scenarios, Base32 encoding is selected. This targeted algorithm selection method not only ensures the encoding effect but also further optimizes the transmission efficiency and compatibility, enabling the method to flexibly adapt to diverse parameters and application scenarios.
[0017] In one possible implementation of the first aspect, the prefix identifier is further configured with a unique corresponding decoding algorithm, and the prefix identifier is a string used to indicate the decoding method.
[0018] The method provided by this invention configures a unique corresponding decoding algorithm for a prefix identifier, enabling the prefix identifier to simultaneously indicate both the encoding and decoding methods. This design establishes a strong correlation between encoding and decoding. The receiving end does not need to store additional encoding algorithm information; it can directly determine the corresponding decoding algorithm simply by recognizing the prefix identifier. This simplifies the decoding process, avoids parsing failures caused by mismatch between encoding and decoding algorithms, reduces system storage overhead, and improves the collaborative reliability and execution efficiency of encoding and decoding.
[0019] In one possible implementation of the first aspect, the method further includes a decoding process, which includes: receiving a target command string; splitting the target command string according to an AT command syntax delimiter; extracting the command name and the corresponding parameter string list; traversing each parameter string and checking whether it begins with the prefix identifier; if the parameter string begins with the prefix identifier, extracting the encoded data after the prefix identifier; decoding the encoded data according to the decoding algorithm uniquely corresponding to the prefix identifier to restore the original parameters; if the parameter string does not begin with the prefix identifier, directly including the parameter string as plaintext parameters in the original parameter list; summarizing all restored original parameters and plaintext parameters to form a complete original parameter list, which is used to execute the corresponding AT command.
[0020] The method provided by this invention achieves complete closed-loop adaptation with the encoding process through the following steps during decoding: splitting the target command string, traversing the parameter string and checking prefix identifiers, selectively decoding or directly using plaintext parameters, and summarizing the original parameter list. It accurately decodes and restores parameters with prefix identifiers, while parameters without identifiers are directly used as plaintext. This ensures reliable parsing of parameters with special characters and compatibility with standard AT command syntax. It eliminates the need to modify the existing system's parsing logic for simple plaintext parameters, achieving backward compatibility. Simultaneously, it makes the entire encoding and decoding process coherent and efficient, guaranteeing the normal execution of AT commands.
[0021] Secondly, this invention provides a dynamic encoding and decoding system for AT command parameters based on prefix identifiers. The system includes: an identifier configuration module, used to predefine special character sets and encoding algorithms, and configure a unique corresponding prefix identifier for each encoding algorithm, wherein the prefix identifier is a string used to indicate the encoding method; a parameter analysis module, used to perform character traversal analysis on each parameter of the AT command to be sent, and determine whether it contains any character from the predefined special character set; an encoding module, used to directly output the parameter as a plaintext parameter if it does not contain any character; the encoding module is also used to encode the parameter according to the encoding algorithm corresponding to the parameter if it does contain any character, and to concatenate the corresponding prefix identifier before the encoded data to form an encoded parameter; and to assemble all plaintext parameters and encoded parameters according to the AT command syntax to generate a target command string and send it.
[0022] In one possible implementation of the second aspect, the prefix identifier is further configured with a unique corresponding decoding algorithm, and the prefix identifier is a string used to indicate the decoding method. The system further includes: a parameter analysis module, configured to receive a target command string, split the target command string according to AT command syntax delimiters, extract the command name and the corresponding parameter string list; traverse each parameter string and check whether it begins with the prefix identifier; a decoding module, configured to, if the parameter string begins with the prefix identifier, extract the encoded data after the prefix identifier, decode the encoded data according to the unique decoding algorithm corresponding to the prefix identifier, and restore the original parameters; the decoding module is further configured to, if the parameter string does not begin with the prefix identifier, directly include the parameter string as plaintext parameters in the original parameter list; and a command execution module, configured to summarize all restored original parameters and plaintext parameters to form a complete original parameter list, which is used to execute the corresponding AT command.
[0023] Thirdly, an electronic device is provided, the electronic device including a memory and one or more processors; the memory is coupled to the processors; wherein the memory stores computer program code, the computer program code including computer instructions, which, when executed by the processor, cause the electronic device to perform the method as described in any implementation of the first aspect.
[0024] Fourthly, a computer-readable storage medium is provided, including computer instructions that, when executed on an electronic device, cause the electronic device to perform a method as described in any implementation of the first aspect.
[0025] Fifthly, a computer program product is provided that, when run on a computer, causes the computer to perform the method in any implementation of the first aspect.
[0026] Understandably, the beneficial effects achieved by the system of the second aspect, the electronic device of the third aspect, the computer-readable storage medium of the fourth aspect, and the computer program product of the fifth aspect provided above can be referred to with reference to the beneficial effects of the first aspect and any of its possible design embodiments, which will not be repeated here. Attached Figure Description
[0027] Figure 1 is a schematic diagram of an electronic device provided in an embodiment of the present invention; Figure 2 is a flowchart of a dynamic encoding and decoding method for AT command parameters based on prefix identifiers provided in an embodiment of the present invention; Figure 3 is a flowchart of another dynamic encoding and decoding method for AT command parameters based on prefix identifiers provided in an embodiment of the present invention; Figure 4 is a flowchart of a dynamic encoding method for AT command parameters based on prefix identifiers provided in an embodiment of the present invention; Figure 5 is a flowchart of yet another dynamic decoding method for AT command parameters based on prefix identifiers provided in an embodiment of the present invention; Figure 6 is a schematic diagram of an encoding and decoding system provided in an embodiment of the present invention. Detailed Implementation
[0028] The technical solutions of the embodiments of the present invention will be described below with reference to the accompanying drawings. In the description of the present invention, unless otherwise stated, " / " indicates that the objects before and after are in an "or" relationship. For example, A / B can represent A or B. The "or" in the present invention is merely a description of the relationship between the related objects, indicating that three relationships can exist. For example, A or B can represent: A alone, A and B simultaneously, and B alone. A and B can be singular or plural. Furthermore, in the description of the present invention, unless otherwise stated, "multiple" refers to two or more. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items.
[0029] Furthermore, to facilitate a clear description of the technical solutions of the embodiments of the present invention, the terms "first" and "second" are used in the embodiments of the present invention to distinguish identical or similar items with essentially the same function and effect. Those skilled in the art will understand that the terms "first" and "second" do not limit the quantity or execution order, and that the terms "first" and "second" are not necessarily different.
[0030] In this embodiment of the invention, the terms "exemplary" or "for example" are used to indicate that something is an example, illustration, or description. Any embodiment or design described as "exemplary" or "for example" in this embodiment of the invention should not be construed as superior or more advantageous than other embodiments or designs. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner for ease of understanding.
[0031] In the field of communication technology, AT commands, as a core control protocol between devices such as embedded systems and mobile communication modules, are widely used in the command interaction of modems and mobile devices. They typically rely on characters such as commas, equal signs, and carriage returns as separators for parameter parsing and command execution. However, in practical applications, when the parameter values of AT commands themselves contain special characters, parsing errors can easily occur, and this problem has become a common hidden danger affecting the reliability of device communication.
[0032] To address the aforementioned issues, existing technologies primarily employ two solutions: one is a fixed encoding method, which uniformly uses Base64 or similar encoding for all parameters or parameters of specific types, avoiding the influence of special characters through encoding conversion; the other is a character escaping method, which uses escape characters to mark and convert special characters in the parameters, enabling the parser to distinguish between delimiters and characters within the parameters. Both methods can alleviate parsing problems caused by special characters in certain scenarios and have become the mainstream processing methods in the industry.
[0033] However, the aforementioned existing technologies have significant common defects: the fixed encoding method lacks flexibility and uniformly processes simple parameters that do not require encoding, which not only increases the overhead of data transmission and command length, but also reduces the intuitiveness of user interaction; the character escaping method has complex implementation logic and lacks a unified standard for escaping rules, resulting in poor compatibility between devices from different manufacturers. At the same time, neither method can efficiently and reliably solve the problem of transmitting non-printable ASCII characters, and it is also difficult to avoid ambiguity and misjudgment in the parsing process, ultimately affecting the stability and universality of AT command communication.
[0034] In view of this, embodiments of the present invention provide a dynamic encoding and decoding method and system for AT command parameters based on prefix identifiers. The method includes an encoding process, which includes: predefining a special character set and an encoding algorithm; configuring a unique corresponding prefix identifier for each encoding algorithm, wherein the prefix identifier is a string used to indicate the encoding method; performing character traversal analysis on each parameter of the AT command to be sent to determine whether it contains any character in the predefined special character set; if it does not contain any character, the parameter is directly output as a plaintext parameter; if it does contain any character, the parameter is encoded according to the encoding algorithm corresponding to the parameter, and the corresponding prefix identifier is concatenated before the encoded data to form an encoded parameter; assembling all plaintext parameters and encoded parameters according to the AT command syntax to generate a target command string and sending it.
[0035] The method provided by this invention performs character traversal analysis on the AT command parameters to be sent by predefining a special character set, encoding algorithm, and unique prefix identifier. Only parameters containing special characters are encoded and appended with the prefix identifier; parameters without special characters are output directly in plaintext. Finally, the parameters are assembled and sent according to the AT command syntax. This design overcomes the limitation of existing fixed encoding methods that uniformly encode all parameters. By "encoding on demand," it reduces unnecessary processing overhead and shortens the command transmission length. At the same time, the prefix identifier clearly indicates the encoding method, avoiding misinterpretation at the receiving end. It balances transmission efficiency and reliability, realizing dynamic and flexible encoding and decoding of AT command parameters.
[0036] In some embodiments, the AT command parameter dynamic encoding and decoding method based on prefix identifier provided in this embodiment of the invention can be executed by an AT command parameter dynamic encoding and decoding system 100 based on prefix identifier (hereinafter referred to as encoding and decoding system 100).
[0037] As an example, the encoding / decoding system 100 can be any electronic device 200 with data processing capabilities, such as a general-purpose computer, personal computer, laptop computer, switch, or tablet computer. The specific implementation of the encoding / decoding system 100 is not limited here.
[0038] Figure 1 shows a schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present invention. The electronic device 200 includes a processor 210, a memory 220, and a communication interface 230.
[0039] Processor 210 may include one or more processing cores. Processor 210 connects to various parts within electronic device 200 using various interfaces and lines, and performs various functions and processes data of electronic device 200 by running or executing instructions, programs, code sets, or instruction sets stored in memory 220, and by calling data stored in memory 220. Optionally, processor 210 may be implemented using at least one of the following hardware forms: Central Processing Unit (CPU), Graphics Processing Unit (GPU), Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA).
[0040] The memory 220 may include random access memory (RAI) or read-only memory (ROI). Optionally, the memory 220 may include non-transitory computer-readable storage ledger. The memory 220 may be used to store instructions, programs, code, code sets, or instruction sets. The memory 220 may include a stored program area. The stored program area may store instructions for implementing an operating system, instructions for implementing at least one function, instructions for implementing the various method embodiments described above, etc.
[0041] Communication interface 230 is used to communicate with other devices, equipment or communication networks, such as data storage devices, image processing devices or Ethernet, wireless access network (RAN), wireless local area network (WLAN), etc.
[0042] In terms of physical implementation, the aforementioned devices (such as processor 210, memory 220, and communication interface 230) can each be devices within the same device (such as a laptop computer). Alternatively, at least two of these devices can be located within the same device, i.e., as different devices within the same device, similar to the deployment of devices or components in a distributed system.
[0043] It is understood that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device 200. In other embodiments of the present invention, the electronic device 200 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0044] The following description, in conjunction with the accompanying drawings, illustrates a dynamic encoding and decoding method for AT command parameters based on prefix identifiers provided by an embodiment of the present invention.
[0045] Figure 2 is a flowchart of a dynamic encoding and decoding method for AT command parameters based on prefix identifiers provided by an embodiment of the present invention. Optionally, this method can be executed by the electronic device 200 shown in Figure 1. The method includes an encoding process and a decoding process. The encoding process may include the following steps: S11, predefining a special character set and encoding algorithm, configuring a unique corresponding prefix identifier for each encoding algorithm, wherein the prefix identifier is a string used to indicate the encoding method; in one possible implementation, the predefined special character set includes AT command syntax separators, control characters, non-printable ASCII characters, leading and trailing whitespace characters, and all defined prefix identifier strings; wherein, the AT command syntax separators include commas, semicolons, and equal signs; the control characters include carriage returns and newlines; the non-printable ASCII characters are characters with ASCII values less than 32 or greater than 126; the leading and trailing whitespace characters include spaces and tabs.
[0046] The method provided by this invention explicitly predefines a special character set that includes AT command syntax separators, control characters, non-printable ASCII characters, leading and trailing whitespace characters, and all prefix identifier strings, comprehensively covering character types that may cause parsing ambiguity or transmission difficulties in AT command interaction. By precisely defining the range of special characters to be encoded, it avoids encoding / decoding failures caused by character omissions and prevents over-encoding from increasing the system burden, ensuring the accuracy of encoding triggering and providing a clear judgment basis for the reliable execution of subsequent dynamic encoding / decoding. Furthermore, the method provided by this invention refines the specific types of various characters in the predefined special character set, clarifying the specific meanings of syntax separators, control characters, non-printable ASCII characters, and whitespace characters, especially defining the ASCII value range of non-printable ASCII characters. This refined definition makes the judgment criteria for special characters uniform and quantifiable, avoiding misunderstandings of special characters in different devices or scenarios, improving the universality and operability of the method, and ensuring consistency of encoding / decoding across devices and scenarios.
[0047] In some embodiments, the encoding algorithm includes at least one of Hex encoding, Base32 encoding, and Base64 encoding; the prefix identifier corresponds one-to-one with the encoding algorithm, and the prefix identifier is a string of fixed length, with a colon as the separator between the prefix identifier and the encoded data.
[0048] Specifically, the length of the prefix identifier is uniformly 6 characters, but it can also be flexibly set according to the actual use scenario. This embodiment of the invention does not impose any special restrictions on the length of the prefix identifier.
[0049] In one example, the encoding method includes, but is not limited to: Hex, Base32, Base64. The prefix identifier includes, but is not limited to: bh1eX6:, ba3sE2:, ba6sE4:.
[0050] Furthermore, bh1eX6 corresponds to Hex encoding, ba3sE2 corresponds to Base32 encoding, and ba6sE4 corresponds to Base64 encoding.
[0051] When the parameters in the AT command are "123,456", the encoding example corresponding to bh1eX6 is bh1eX6:3132332C343536; the encoding example corresponding to ba3sE2 is ba3sE2:GEZDGLBUGU3A====; and the encoding example corresponding to ba6sE4 is ba6sE4:MTIzLDQ1Ng==.
[0052] The method provided by this invention limits the encoding algorithm to at least one of Hex, Base32, and Base64, with a one-to-one correspondence between the prefix identifier and the encoding algorithm, a fixed length, and a colon as the separator. Support for multiple encoding algorithms meets the needs of different parameter characteristics and transmission scenarios, improving the flexibility of the method. Furthermore, the fixed-length prefix identifier and colon separator design allows the receiving end to quickly identify and extract the encoding identifier and encoded data, simplifying the parsing logic, improving decoding efficiency, and avoiding confusion between the identifier and data, thus ensuring the accuracy of encoding and decoding.
[0053] S12. Perform character traversal analysis on each parameter of the AT command to be sent to determine whether it contains any character in the predefined special character set; S13. If it does not contain any character, output the parameter directly as a plaintext parameter; S14. If it contains any character, encode the parameter according to the encoding algorithm corresponding to the parameter, and concatenate the corresponding prefix identifier before the encoded data to form an encoded parameter.
[0054] In some embodiments, encoding the parameters according to the encoding algorithm corresponding to the parameters includes: determining the algorithm selection mode of the AT command to be sent, wherein the algorithm selection mode includes a preset fixed algorithm mode or a dynamically adapted algorithm mode; when the algorithm selection mode is the preset fixed algorithm mode, then calling a preset encoding algorithm to encode the parameters containing special characters; when the algorithm selection mode is the dynamically adapted algorithm mode, then analyzing the parameter characteristics, wherein the parameter characteristics include the type of special characters, the length of the parameter data, and the transmission scenario; when the parameter contains multiple non-printable ASCII characters, determining Hex encoding as the target encoding algorithm; when the length of the parameter data is greater than a preset length threshold, determining Base64 encoding as the target encoding algorithm; when the transmission scenario is a compatibility scenario, determining Base32 encoding as the target encoding algorithm; and calling the target encoding algorithm to encode the parameters containing special characters.
[0055] In one example, the preset length threshold is 100 bytes.
[0056] Specifically, compatibility scenarios refer to application scenarios in which AT command interaction needs to be adapted to different manufacturers' equipment, older hardware versions, low-bandwidth transmission links, or traditional parsing systems. The core requirement is to ensure that the encoded and decoded commands can be correctly recognized and parsed by various receiving ends, avoiding communication failures caused by protocol differences, hardware limitations, or different parsing logic.
[0057] It should be understood that when the parameters contain multiple non-printable ASCII characters, the parameter data length is greater than the preset length threshold, and the transmission scenario is a compatibility scenario, Hex encoding is determined as the target encoding algorithm.
[0058] The method provided by this invention selects the encoding algorithm through two modes: a preset fixed algorithm and a dynamic adaptation algorithm. In the dynamic adaptation mode, the optimal algorithm is precisely matched according to the special character type of the parameter, the data length, and the transmission scenario. When the parameter contains multiple non-printable ASCII characters, Hex encoding is selected; for long parameters, Base64 encoding is selected; and for compatibility scenarios, Base32 encoding is selected. This targeted algorithm selection method not only ensures the encoding effect but also further optimizes the transmission efficiency and compatibility, enabling the method to flexibly adapt to diverse parameters and application scenarios.
[0059] S15. Assemble all plaintext parameters and encoded parameters according to the AT command syntax, generate the target command string, and send it.
[0060] As shown in S1-S5, the method provided by this invention performs character traversal analysis on the AT command parameters to be sent by predefining a special character set, encoding algorithm, and unique prefix identifier. Only parameters containing special characters are encoded and appended with the prefix identifier; parameters without special characters are output directly in plaintext. Finally, the parameters are assembled and sent according to the AT command syntax. This design breaks through the limitation of existing fixed encoding methods that uniformly encode all parameters. By "encoding on demand," it reduces unnecessary processing overhead and shortens the command transmission length. At the same time, the prefix identifier clearly indicates the encoding method, avoiding misinterpretation at the receiving end. It balances transmission efficiency and reliability, realizing dynamic and flexible encoding and decoding of AT command parameters.
[0061] In some embodiments, the prefix identifier is further configured with a unique corresponding decoding algorithm, and the prefix identifier is a string used to indicate the decoding method.
[0062] The method provided by this invention configures a unique corresponding decoding algorithm for a prefix identifier, enabling the prefix identifier to simultaneously indicate both the encoding and decoding methods. This design establishes a strong correlation between encoding and decoding. The receiving end does not need to store additional encoding algorithm information; it can directly determine the corresponding decoding algorithm simply by recognizing the prefix identifier. This simplifies the decoding process, avoids parsing failures caused by mismatch between encoding and decoding algorithms, reduces system storage overhead, and improves the collaborative reliability and execution efficiency of encoding and decoding.
[0063] This invention can also be understood as follows: The method provided by this invention only encodes parameters containing special characters, avoiding unnecessary processing overhead for simple parameters, shortening command length, and improving transmission efficiency. Furthermore, by defining different prefix identifiers, it can easily support multiple encoding algorithms (such as Hex, Base32, Base64, and even future new encoding methods), making the system highly adaptable. On the other hand, the explicit prefix identifiers provided by this invention avoid guessing and misinterpretation at the receiving end, ensuring the accuracy and reliability of data transmission, especially suitable for transmitting parameters containing arbitrary binary data or complex text. Meanwhile, for parameters that do not contain special characters, they are transmitted as is, fully compatible with standard AT command syntax, without requiring modification to the parsing logic for such simple parameters in existing systems. Finally, when the method provided by this invention does not contain special characters, the interaction is as convenient and simple as standard AT commands.
[0064] Further, referring to Figure 3, the decoding process includes: S21, receiving the target command string, splitting the target command string according to the AT command syntax delimiter, and extracting the command name and the corresponding parameter string list; S22, traversing each parameter string and checking whether it starts with the prefix identifier; S23, if the parameter string starts with the prefix identifier, then extracting the encoded data after the prefix identifier, decoding the encoded data according to the decoding algorithm uniquely corresponding to the prefix identifier, and restoring the original parameters; S24, if the parameter string does not start with the prefix identifier, then directly including the parameter string as plaintext parameters in the original parameter list; S25, summarizing all restored original parameters and plaintext parameters to form a complete original parameter list, which is used to execute the corresponding AT command.
[0065] It should be noted that in the process of summarizing all restored original parameters and plaintext parameters, the summarization order follows the original command parameter order, but other orders can also be used. This embodiment of the invention does not impose any special restrictions on this.
[0066] The method provided by this invention achieves complete closed-loop adaptation with the encoding process through the following steps during decoding: splitting the target command string, traversing the parameter string and checking prefix identifiers, selectively decoding or directly using plaintext parameters, and summarizing the original parameter list. It accurately decodes and restores parameters with prefix identifiers, while parameters without identifiers are directly used as plaintext. This ensures reliable parsing of parameters with special characters and compatibility with standard AT command syntax. It eliminates the need to modify the existing system's parsing logic for simple plaintext parameters, achieving backward compatibility. Simultaneously, it makes the entire encoding and decoding process coherent and efficient, guaranteeing the normal execution of AT commands.
[0067] To facilitate understanding of this solution, the encoding and decoding processes of the method provided in this embodiment of the invention will be explained below with reference to an example.
[0068] In one example, referring to Figure 4, the encoding process provided by the embodiment of the present invention includes the following steps: start the encoding process, traverse each parameter in the AT command, determine whether the parameter contains special characters, if not, use it directly as plaintext, if so, select an encoding algorithm, such as Hex encoding, encode the parameter, and concatenate a prefix (prefix identifier) for the encoded data to generate the encoded parameter, assemble all parameters (plaintext / encoded) according to the AT command syntax, send the AT command string, and the process ends.
[0069] Furthermore, the encoding process provided in this embodiment of the invention includes the following steps: The AT command to be sent is: AT+ACOUNT="admin","123,456". Wherein, the first parameter "admin" does not contain special characters, and the second parameter "123,456" contains the special character comma (,). Analyzing parameter 1: "admin". It is found that it does not contain special characters. admin is directly used as the plaintext parameter for output. Analyzing parameter 2: "123,456". It is found that it contains the special character comma (,). Hex encoding is selected (corresponding to the prefix bh1eX6:). The encoding yields 3132332C343536. After concatenating the prefix, it becomes: bh1eX6:3132332C343536. The final command sent is: AT+ACOUNT=admin,bh1eX6:3132332C343536\r\n In another example, see Figure 5. The decoding process provided by this embodiment of the invention includes the following steps: start the decoding process, receive and parse the AT command to obtain the parameter string list, traverse each parameter string, check if it starts with a known prefix identifier. If not, use it directly as plaintext. If so, identify the prefix identifier, select the corresponding decoding algorithm, decode, restore the original parameters, obtain the original parameter list, execute the AT command, and the process ends.
[0070] Specifically, for the decoding process, the method provided in this embodiment of the invention includes: The receiving end receives the command: AT+ACOUNT=admin,bh1eX6:3132332C343536\r\n. Parameter 1 is identified as "admin". Since there is no prefix, it is used directly. Parameter 2 is identified as "bh1eX6:3132332C343536". Starting with "bh1eX6:", Hex decoding is performed to obtain the original parameters: 123,456. The system uses the decoded parameters "admin" and "123,456" to execute the AT+ACOUNT command.
[0071] Optionally, for the above parameter "123,456", different encoding algorithms can be used according to the actual use scenario. For example, using Base64 encoding, the encoding after concatenating the prefix is: ba6sE4:MTIzLDQ1Ng==. The receiving end can restore the data by recognizing the ba6sE4: prefix and calling the Base64 decoder.
[0072] The foregoing mainly describes the solutions of the embodiments of the present invention from a methodological perspective. It is understood that, in order to achieve the above-mentioned functions, the encoding / decoding system 100 includes at least one of the hardware structures and software modules corresponding to the execution of each function. Those skilled in the art should readily recognize that, in conjunction with the units and algorithm steps of the various examples described in the embodiments disclosed herein, the embodiments of the present invention can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the embodiments of the present invention.
[0073] In this embodiment of the invention, the encoding / decoding system 100 can be divided into functional units according to the above method example. For example, the encoding / decoding system 100 can be divided into functional units corresponding to various functions, or two or more functions can be integrated into one processing unit. The integrated unit can be implemented in hardware or as a software functional unit. It should be noted that the unit division in this embodiment of the invention is illustrative and only represents one logical functional division; other division methods may be used in actual implementation.
[0074] For example, Figure 6 shows a schematic diagram of the hardware structure of an encoding / decoding system provided in an embodiment of the present invention. The encoding / decoding system 100 includes: an identifier configuration module 110, used to predefine special character sets and encoding algorithms, and configure a unique corresponding prefix identifier for each encoding algorithm, wherein the prefix identifier is a string used to indicate the encoding method; a parameter analysis module 120, used to perform character traversal analysis on each parameter of the AT command to be sent, and determine whether it contains any character in the predefined special character set; an encoding module 130, used to output the parameter directly as a plaintext parameter if it does not contain any character; the encoding module 130 is also used to encode the parameter according to the encoding algorithm corresponding to the parameter if it does contain any character, and to concatenate the corresponding prefix identifier before the encoded data to form an encoded parameter; and to assemble all plaintext parameters and encoded parameters according to the AT command syntax to generate a target command string and send it.
[0075] Optionally, the prefix identifier is also configured with a unique corresponding decoding algorithm, and the prefix identifier is a string used to indicate the decoding method. The encoding and decoding system 100 further includes: the parameter analysis module 120, which is further used to receive the target command string, split the target command string according to the AT command syntax delimiter, extract the command name and the corresponding parameter string list; traverse each parameter string and check whether it starts with the prefix identifier; the decoding module 140, which is used to extract the encoded data after the prefix identifier if the parameter string starts with the prefix identifier, decode the encoded data according to the unique decoding algorithm corresponding to the prefix identifier, and restore the original parameters; the decoding module 150, which is also used to directly include the parameter string as plaintext parameters in the original parameter list if the parameter string does not start with the prefix identifier; and the command execution module 150, which is used to summarize all the restored original parameters and plaintext parameters to form a complete original parameter list, which is used to execute the corresponding AT command.
[0076] It should be understood that specific descriptions of the above-mentioned optional methods can be found in the foregoing method embodiments, and will not be repeated here. Furthermore, explanations of any of the above-provided encoding / decoding systems 100 and descriptions of their beneficial effects can be found in the corresponding method embodiments, and will not be repeated here.
[0077] This invention also provides a computer-readable storage medium storing at least one computer instruction, which is loaded and executed by a processor to implement the methods of the various embodiments described above. Explanations of the relevant content and descriptions of the beneficial effects of any of the computer-readable storage media provided above can be found in the corresponding embodiments described above, and will not be repeated here.
[0078] This invention also provides a chip. This chip integrates a control circuit for implementing the functions of the above-described encoding / decoding system 100 and one or more ports. Optionally, the functions supported by this chip are as described above and will not be repeated here.
[0079] Those skilled in the art will understand that the program for implementing all or part of the steps of the above embodiments, which can be executed by a program instructing related hardware, can be stored in a computer-readable storage medium. The storage medium mentioned above can be a read-only memory, a random access memory, etc. The processing unit or processor mentioned above can be a central processing unit, a general-purpose processor, an application-specific integrated circuit (ASIC), a microprocessor (DSP), a field-programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof.
[0080] This invention also provides a computer program product containing instructions that, when executed on a computer, cause the computer to perform any of the methods described in the above embodiments. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of this invention is generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, computer instructions may be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., SSD), etc.
[0081] It should be noted that the devices for storing computer instructions or computer programs provided in the embodiments of the present invention, such as, but not limited to, the aforementioned memory, computer-readable storage medium, and communication chip, are all non-transitory. Those skilled in the art should recognize that the functions described in the embodiments of the present invention in one or more of the above examples can be implemented using hardware, software, firmware, or any combination thereof. When implemented using software, these functions can be stored in a computer-readable storage medium or transmitted as one or more instructions or code on a computer-readable storage medium. Computer-readable storage media include computer storage media and communication media, wherein communication media include any medium that facilitates the transmission of computer programs from one place to another. Storage media can be any available medium accessible to general-purpose or special-purpose computers.
[0082] Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of the present invention.
Claims
1. A dynamic encoding and decoding method for AT command parameters based on prefix identifiers, characterized in that, The method includes an encoding process, which includes: predefining a special character set and an encoding algorithm; configuring a unique prefix identifier for each encoding algorithm, wherein the prefix identifier is a string used to indicate the encoding method; performing character traversal analysis on each parameter of the AT command to be sent to determine whether it contains any character from the predefined special character set; if it does not contain any character, the parameter is directly output as a plaintext parameter; if it does contain any character, the parameter is encoded according to the encoding algorithm corresponding to the parameter, and the corresponding prefix identifier is concatenated before the encoded data to form an encoded parameter; assembling all plaintext parameters and encoded parameters according to the AT command syntax to generate a target command string and sending it.
2. The dynamic encoding and decoding method for AT command parameters based on prefix identifiers according to claim 1, characterized in that, The predefined special character set includes AT command syntax separators, control characters, non-printable ASCII characters, leading and trailing whitespace characters, and all defined prefix identifier strings.
3. The dynamic encoding and decoding method for AT command parameters based on prefix identifiers according to claim 2, characterized in that, The AT command syntax separators include commas, semicolons, and equal signs; the control characters include carriage returns and newlines; the non-printable ASCII characters are characters with ASCII values less than 32 or greater than 126; the leading and trailing whitespace characters include spaces and tabs.
4. The dynamic encoding and decoding method for AT command parameters based on prefix identifiers according to claim 1, characterized in that, The encoding algorithm includes at least one of Hex encoding, Base32 encoding, and Base64 encoding; the prefix identifier corresponds one-to-one with the encoding algorithm, and the prefix identifier is a string of fixed length, with a colon as the separator between the prefix identifier and the encoded data.
5. The dynamic encoding and decoding method for AT command parameters based on prefix identifiers according to claim 1, characterized in that, The step of encoding the parameters according to the corresponding encoding algorithm includes: determining the algorithm selection mode of the AT command to be sent, wherein the algorithm selection mode includes a preset fixed algorithm mode or a dynamically adapted algorithm mode; when the algorithm selection mode is the preset fixed algorithm mode, then calling the preset encoding algorithm to encode the parameters containing special characters; when the algorithm selection mode is the dynamically adapted algorithm mode, then analyzing the parameter characteristics, wherein the parameter characteristics include the type of special characters, the length of the parameter data, and the transmission scenario; when the parameter contains multiple non-printable ASCII characters, determining Hex encoding as the target encoding algorithm; when the length of the parameter data is greater than a preset length threshold, determining Base64 encoding as the target encoding algorithm; when the transmission scenario is a compatibility scenario, determining Base32 encoding as the target encoding algorithm; and calling the target encoding algorithm to encode the parameters containing special characters.
6. The dynamic encoding and decoding method for AT command parameters based on prefix identifiers according to claim 1, characterized in that, The prefix identifier is also configured with a unique corresponding decoding algorithm, and the prefix identifier is a string used to indicate the decoding method.
7. The dynamic encoding and decoding method for AT command parameters based on prefix identifiers according to claim 6, characterized in that, The method further includes a decoding process, which includes: receiving a target command string; splitting the target command string according to the AT command syntax delimiter; extracting the command name and the corresponding parameter string list; traversing each parameter string and checking whether it starts with the prefix identifier; if the parameter string starts with the prefix identifier, extracting the encoded data after the prefix identifier, decoding the encoded data according to the unique decoding algorithm corresponding to the prefix identifier, and restoring the original parameters; if the parameter string does not start with the prefix identifier, directly including the parameter string as a plaintext parameter in the original parameter list; summarizing all the restored original parameters and plaintext parameters to form a complete original parameter list, which is used to execute the corresponding AT command.
8. A dynamic encoding and decoding system for AT command parameters based on prefix identifiers, characterized in that, The system includes: an identifier configuration module, used to predefine special character sets and encoding algorithms, and configure a unique corresponding prefix identifier for each encoding algorithm, wherein the prefix identifier is a string used to indicate the encoding method; a parameter analysis module, used to perform character traversal analysis on each parameter of the AT command to be sent, and determine whether it contains any character in the predefined special character set; an encoding module, used to output the parameter directly as a plaintext parameter if it does not contain any character; the encoding module is also used to encode the parameter according to the encoding algorithm corresponding to the parameter if it does contain any character, and to concatenate the corresponding prefix identifier before the encoded data to form an encoded parameter; and to assemble all plaintext parameters and encoded parameters according to the AT command syntax to generate a target command string and send it.
9. The AT command parameter dynamic encoding and decoding system based on prefix identifier according to claim 8, characterized in that, The prefix identifier is also configured with a unique corresponding decoding algorithm, and the prefix identifier is a string used to indicate the decoding method; the system also includes: a parameter analysis module, which is further configured to receive a target command string, split the target command string according to the AT command syntax delimiter, extract the command name and the corresponding parameter string list; traverse each parameter string and check whether it starts with the prefix identifier; a decoding module, which is configured to, if the parameter string starts with the prefix identifier, extract the encoded data after the prefix identifier, decode the encoded data according to the unique decoding algorithm corresponding to the prefix identifier, and restore the original parameters; the decoding module is further configured to, if the parameter string does not start with the prefix identifier, directly include the parameter string as plaintext parameters in the original parameter list; and a command execution module, which is configured to summarize all restored original parameters and plaintext parameters to form a complete original parameter list, which is used to execute the corresponding AT command.
10. An electronic device, characterized in that, include: processor; A memory for storing processor-executable instructions; wherein the processor is configured to execute the instructions to implement the prefix-identifier-based dynamic encoding and decoding method for AT command parameters as described in any one of claims 1-7.
Citation Information
Cited By
A data transmission method, device and equipment for smart meters and a medium
CN122160438A