AT command processing method, device and equipment
Through the combination solution of consumer threads, producer threads, parser threads and global state machine, the problem of low AT command processing efficiency is solved, real-time and reliability between the master control and the module is achieved.
Patent Information
- Application Number
- CN202211338610.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-28
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2042-10-28
AI Technical Summary
In the prior art, AT command processing efficiency is low, and the processing progress of subsequent messages will be affected when the current message is not processed or abnormal.
The combination of consumer threads, producer threads, parser threads and global state machine is adopted to process AT commands through blocking mode and non-blocking mode, and to use message queues and synchronization locking mechanisms to ensure the timeliness and reliability of message processing.
It improves the efficiency of AT command processing, ensures real-time and reliability between the master and module, and improves the timeliness of message processing.
Smart Images

Figure CN115695592B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to an AT command processing method, apparatus, and device. Background Art
[0002] Embedded WiFi modules are low-power, low-cost IoT communication solutions designed to quickly connect embedded devices to the internet. Communication between the host controller and the WiFi module typically occurs via UART (Uni-Asynchronous Receiver / Transmitter) or SPI (Serial Peripheral Interface). The host controller sends AT commands to the module, which responds with AT responses indicating command success. AT commands can be used to manipulate the WiFi module to complete a range of tasks, including obtaining AT firmware version information, connecting to WiFi, establishing TCP (Transmission Control Protocol) connections, and sending / receiving TCP data.
[0003] Therefore, there is an urgent need to provide a more reliable AT command processing solution. Summary of the Invention
[0004] The object of the present invention is to provide an AT command processing method, apparatus and device, so as to solve the problem of low message processing efficiency in the prior art.
[0005] In order to achieve the above object, the present invention provides the following technical solutions:
[0006] In a first aspect, the present invention provides an AT command processing method, which is applied to an AT command processing system, wherein the AT command processing system includes a consumer thread, a producer thread, a parser thread, and a global state machine; the method includes:
[0007] Obtaining an AT command sent by a user; and determining a communication mode of the AT command processing system; the communication mode includes a blocking mode and a non-blocking mode;
[0008] The producer thread allocates message resources based on the communication mode and puts the messages contained in the message resources into a message queue;
[0009] The consumer thread takes out the corresponding message from the message queue and processes it, waiting for the synchronization lock of the global state machine;
[0010] The parser thread receives and parses the response from the module to determine the sending status of the retrieved message;
[0011] The synchronization lock of the global state machine is released based on the sending status, and the next response of the module is waited for.
[0012] In a second aspect, the present invention provides an AT command processing device, which is applied to an AT command processing system. The AT command processing system includes a consumer thread, a producer thread, a parser thread, and a global state machine. The device includes:
[0013] The communication mode acquisition module is used to acquire the AT command sent by the user and determine the communication mode of the AT command processing system; the communication mode includes blocking mode and non-blocking mode;
[0014] A message resource allocation module, configured for the producer thread to allocate message resources based on the communication mode and place messages contained in the message resources into a message queue;
[0015] A message processing module, configured for the consumer thread to retrieve the corresponding message from the message queue and process it, waiting for the synchronization lock of the global state machine;
[0016] A parsing module, configured for the parser thread to receive and parse the response sent by the module and determine the sending status of the retrieved message;
[0017] The synchronization lock releasing module is used to release the synchronization lock of the global state machine based on the sending state and wait for the next module response.
[0018] In a third aspect, the present invention provides an AT command processing device, the AT command processing device being applied to an AT command processing system, the AT command processing system including a consumer thread, a producer thread, a parser thread, and a global state machine; the device including:
[0019] A communication unit / communication interface, configured to obtain AT commands sent by a user and determine a communication mode of the AT command processing system; the communication modes include a blocking mode and a non-blocking mode;
[0020] a processing unit / processor, configured for the producer thread to allocate message resources based on the communication mode and place messages contained in the message resources into a message queue;
[0021] The consumer thread takes out the corresponding message from the message queue and processes it, waiting for the synchronization lock of the global state machine;
[0022] The parser thread receives and parses the response from the module to determine the sending status of the retrieved message;
[0023] The synchronization lock of the global state machine is released based on the sending status, and the next response of the module is waited for.
[0024] In a fourth aspect, the present invention provides a computer storage medium, wherein the computer storage medium stores instructions, and when the instructions are executed, the above-mentioned AT command processing method is implemented.
[0025] Compared to the prior art, the present invention provides an AT command processing method, apparatus, and device. The method includes: obtaining an AT command sent by a user; and determining the communication mode of the AT command processing system; the communication mode includes a blocking mode and a non-blocking mode; the producer thread allocates message resources based on the communication mode and places the message contained in the message resources into a message queue; the consumer thread retrieves the corresponding message from the message queue and processes it, waiting for the synchronization lock of the global state machine; the parser thread receives and parses the response sent by the module, determining the sending status of the retrieved message; based on the sending status, the synchronization lock of the global state machine is released, and the next response from the module is waited for. The method of this solution is applicable to both blocking and non-blocking communication modes. During the message processing process, the message is processed and parsed based on the consumer thread, producer thread, parser thread, and global state machine, ensuring the timeliness of message processing and improving message processing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0027] Figure 1 A schematic flow chart of an AT command processing method provided by the present invention;
[0028] Figure 2 A schematic diagram of blocking mode communication provided by the present invention;
[0029] Figure 3 A schematic diagram of non-blocking mode communication provided by the present invention;
[0030] Figure 4 A schematic diagram of the operation of the global state machine in the AT command processing method provided by the present invention;
[0031] Figure 5 A schematic diagram of the parser's parsing process in the AT command processing method provided by the present invention;
[0032] Figure 6 A schematic structural diagram of an AT command processing device provided by the present invention;
[0033] Figure 7 This is a structural diagram of an AT command processing device provided by the present invention. DETAILED DESCRIPTION
[0034] To facilitate a clear description of the technical solutions of the embodiments of the present invention, the words "first" and "second" are used in the embodiments of the present invention to distinguish between identical or similar items with substantially the same functions and effects. For example, the first threshold and the second threshold are merely used to distinguish between different thresholds and do not limit their order. Those skilled in the art will understand that the words "first" and "second" do not limit the quantity or execution order, and the words "first" and "second" do not necessarily mean different.
[0035] It should be noted that, in the present invention, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in the present invention should not be construed as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.
[0036] In the present invention, "at least one" refers to one or more, and "more" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: the existence of A alone, the existence of A and B at the same time, and the existence of B alone, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b or c can represent: a, b, c, the combination of a and b, the combination of a and c, the combination of b and c, or the combination of a, b and c, where a, b, c can be single or multiple.
[0037] In the prior art, during the message processing process, if the current message is not processed completely or an exception occurs and the message cannot be processed, the current message will be suspended, thereby affecting the processing progress of subsequent messages. Therefore, it is urgent to provide a solution that can speed up the message processing efficiency.
[0038] To this end, the present invention provides an AT command processing solution.
[0039] Next, the solutions provided in the embodiments of this specification are described with reference to the accompanying drawings:
[0040] The AT command processing method provided in this solution is applied to the AT command processing system, wherein the AT command processing system includes a consumer thread, a producer thread, a parser thread, and a global state machine. This solution mainly involves message interaction between the main control and the module.
[0041] Based on RTOS (real-time operating system), the functions of the following roles in the AT command processing system are:
[0042] Consumer thread: This thread obtains messages from the message queue for processing.
[0043] Producer thread: This thread puts messages into the message queue.
[0044] Parser thread: This thread receives and parses the response from the WiFi module.
[0045] Global state machine: indicates the type of command currently being processed, holds a reference to the message, and holds the global synchronization lock for the consumer thread and parsing.
[0046] The system also includes an OS interface and a customizable AT command type and parsing interface. The OS interface is responsible for managing threads, message queues, and mutex locks.
[0047] The specific implementation of the AT command processing method applied to the above system is combined Figure 1 To explain:
[0048] Figure 1 A flow chart of an AT command processing method provided by the present invention is shown as follows: Figure 1 As shown, the process may include the following steps:
[0049] Step 110: Acquire the AT command sent by the user; and determine the communication mode of the AT command processing system; the communication mode includes a blocking mode and a non-blocking mode.
[0050] AT stands for Attention. The AT command set is sent from the Terminal Equipment (TE) or Data Terminal Equipment (DTE) to the Terminal Adapter (TA) or Data Circuit Terminal Equipment (DCE). Through the TA, the TE sends AT commands to control the functions of the Mobile Station (MS) and interact with GSM network services. Users can use AT commands to control calls, text messages, phone books, data services, faxes, and other aspects.
[0051] Blocking mode means that the current thread will be suspended before the call result is returned, and the thread will enter a non-executable state. In this state, the CPU will not allocate time slices to the thread, that is, the thread will be suspended. The function will not return until the result is obtained.
[0052] Non-blocking mode means that the function will not block the current thread but will return immediately until the result is not available immediately.
[0053] Step 120: The producer thread allocates message resources based on the communication mode, and puts the message contained in the message resources into a message queue.
[0054] The producer thread allocates message resources and puts the message into the message queue, waiting for subsequent transmission.
[0055] Step 130: The consumer thread takes out the corresponding message from the message queue and processes it, waiting for the synchronization lock of the global state machine.
[0056] Step 140: The parser thread receives and parses the response from the module to determine the sending status of the retrieved message.
[0057] In this solution, the main control and the WiFi module can also communicate via UART (Asynchronous Receiver / Transmitter) or SPI (Serial Peripheral Interface): the main control sends AT commands to the module, and the module replies with an AT response indicating whether the command was successful. AT commands can operate the WiFi module to complete a series of transactions, including obtaining AT firmware version information, connecting to WiFi, establishing a TCP (Transmission Control Protocol) connection, and sending / receiving TCP data. The parser thread can receive and parse the response from the WiFi module, and after parsing is complete, determine the message delivery status. In this solution, the message to be sent is retrieved from the message queue according to the pre-set settings, and the success or failure of the transmission can be determined based on the transmission status.
[0058] Step 150: Release the synchronization lock of the global state machine based on the sending status, and wait for the next module response.
[0059] Figure 1 The method acquires an AT command sent by a user and determines the communication mode of the AT command processing system; the communication modes include blocking mode and non-blocking mode. The producer thread allocates message resources based on the communication mode and places the messages contained in the message resources into a message queue. The consumer thread retrieves the corresponding message from the message queue and processes it, waiting for the synchronization lock of the global state machine. The parser thread receives and parses the response from the WiFi module, determining the send status of the retrieved message. Based on the send status, the global state machine synchronization lock is released and the next response from the WiFi module is awaited. The method of this solution is applicable to both blocking and non-blocking communication modes. During message processing, the consumer thread, producer thread, parser thread, and global state machine are used to process and parse the message, ensuring timely message processing and improving message processing efficiency.
[0060] based on Figure 1 The present specification also provides some specific implementation methods of the method, which are described below.
[0061] Next, we will explain the message processing in blocking mode and non-blocking mode respectively:
[0062] Blocking mode communication can be combined with Figure 2 To explain: Figure 2 This is a schematic diagram of the blocking mode communication provided by the present invention. Figure 2 As shown, the relevant subjects include users, producer threads, consumer threads, and resolver threads. The specific operation process is as follows:
[0063] The user initiates an AT command to the producer thread to allocate message resources, put the message into the message queue, and wait for the message's mutex lock (blocking_time).
[0064] The consumer thread takes the message from the message queue, sets the message reference of the state machine, processes the message, and waits for the synchronization lock of the global state machine.
[0065] The parser thread receives the response from the Wi-Fi module and parses it. After parsing, it sets the message status (successful or failed) based on the message reference in the state machine. It then releases the synchronization lock of the global state machine and waits for the next response from the Wi-Fi module.
[0066] The consumer thread continues to execute, sets the message reference of the global state machine to null, releases the message mutex, and waits for the next message to be retrieved.
[0067] The producer thread continues executing, obtaining the message status (success / failure). If the mutex lock cannot be released within the blocking_time period, the producer thread sets the return status to timeout. Finally, the producer thread releases the message resources, completing the process.
[0068] Non-blocking communication can be combined with Figure 3 To explain: Figure 3 This is a schematic diagram of non-blocking mode communication provided by the present invention. Figure 3 As shown, the relevant subjects include users, producer threads, consumer threads, and resolver threads. The specific operation process is as follows:
[0069] The producer thread allocates message resources, sets the message type, puts the message into the message queue, and is done.
[0070] The consumer thread takes the message from the message queue, sets the message reference of the state machine, processes the message, and waits for the synchronization lock of the global state machine.
[0071] The parser thread receives the response from the Wi-Fi module and parses it. After parsing, it sets the message status (successful or failed) based on the message reference in the state machine. It then releases the synchronization lock of the global state machine and waits for the next response from the Wi-Fi module.
[0072] The consumer thread continues to execute, obtains the status of the message (success / failure), calls the message callback function to notify the producer thread; sets the message reference of the global state machine to null, releases the message resources, and waits for the next message to be retrieved.
[0073] Optionally, before the parser thread receives and parses the response from the module and determines the sending status of the retrieved message, it may further include:
[0074] Setting a message reference for the global state machine;
[0075] The parser thread receives and parses the response from the module to determine the delivery status of the retrieved message, specifically including:
[0076] The sending state of the message is set according to the message reference of the global state machine; the sending state includes sending success or sending failure.
[0077] Optionally, the global state machine workflow can be combined with Figure 4 Provide explanation. Figure 4 The working diagram of the global state machine in the AT command processing method provided by the present invention is as follows. Figure 4 As shown, after receiving the start command, the message reference of the global state machine is empty. After the consumer thread takes out the message, the message is referenced, the consumer thread waits for the synchronization lock, the synchronization lock is locked, the parser thread releases the synchronization lock, and after the synchronization lock is released, the consumer thread sets the message reference of the state machine to empty.
[0078] Furthermore, the external interface of the resolver can be: resolver_parse_received(data, len). Where data is the received AT response and len is the length of the response. The resolver's parsing process can be combined with Figure 5 Provide explanation. Figure 5 Schematic diagram of the parser parsing process in the AT command processing method provided by the present invention. Figure 5 As shown, before the parser thread receives and parses the response from the module, it may also include:
[0079] The parser thread obtains the currently received message;
[0080] Determine whether the currently received message is TCP data and obtain the judgment result;
[0081] If the judgment result indicates that the currently received message is TCP data, the currently received message is added to the TCP buffer, and the user reception callback function is called after the reception is completed;
[0082] If the judgment result indicates that the currently received message is not TCP data, the data is added to the receiving buffer.
[0083] The parser thread receives and parses the response from the module, which may include:
[0084] When the parser thread receives a specific instruction, it obtains the message reference and message type corresponding to the currently received message from the global state machine;
[0085] Setting the status of the message according to the keyword in the specific instruction;
[0086] Parsing the message in the buffer according to the message type, obtaining and saving the parsing result; the parsing result includes at least the IP address and the port number;
[0087] Reset the receive buffer and then release the state machine synchronization lock.
[0088] The specific instruction may be "\r\n", and the keyword may be, for example, "OK", "ERROR", "ready", etc. The receiving result may include information such as fd, IP address, port number, etc.
[0089] The technical solution provided by the present invention is applicable to both blocking and non-blocking communication modes. During message processing, messages are parsed based on consumer threads, producer threads, parser threads, and a global state machine, ensuring timely message processing and improving message processing efficiency. This further enhances the real-time performance, reliability, and programmability of the communication between the main control and modules.
[0090] Based on the same idea, the present invention also provides an AT command processing device, which is applied to an AT command processing system. The AT command processing system includes a consumer thread, a producer thread, a parser thread, and a global state machine. Figure 6 This is a schematic diagram of the structure of an AT command processing device provided by the present invention. Figure 6 As shown, the device may include:
[0091] The communication mode acquisition module 610 is used to acquire the AT command sent by the user and determine the communication mode of the AT command processing system; the communication mode includes a blocking mode and a non-blocking mode;
[0092] A message resource allocation module 620 is configured for the producer thread to allocate message resources based on the communication mode and place messages contained in the message resources into a message queue;
[0093] A message processing module 630 is used for the consumer thread to retrieve the corresponding message from the message queue and process it, waiting for the synchronization lock of the global state machine;
[0094] Parsing module 640, used for the parser thread to receive and parse the response sent by the module to determine the sending status of the retrieved message;
[0095] The synchronization lock releasing module 650 is configured to release the synchronization lock of the global state machine based on the sending state and wait for the next module response.
[0096] based on Figure 6 The device may further include some specific implementation units:
[0097] Optionally, when the communication mode is a blocking mode, the apparatus may further include:
[0098] The mutual exclusion lock waiting module is used to wait for the mutual exclusion lock of the message contained in the message resource.
[0099] Optionally, the device may further include:
[0100] A mutex lock release module is used for the consumer thread to continue executing, set the message reference of the global state machine to null, release the mutex lock, and wait for the next message to be retrieved;
[0101] A message resource release module is used for the producer thread to continue executing. Based on the sending status, the producer thread releases the message resource; if the mutex lock cannot be released within the blocking time, the producer thread sets the return status to timeout.
[0102] Optionally, when the communication mode is a non-blocking mode, the apparatus may further include:
[0103] The consumer thread execution module is used for the consumer thread to continue executing, and based on the sending status, calls the message callback function to notify the producer thread; sets the message reference of the state machine to empty, releases the message resource, and waits for the next message to be retrieved.
[0104] Optionally, the device may further include:
[0105] The currently received information acquisition module is used by the parser thread to obtain the currently received message;
[0106] A judgment module is used to judge whether the currently received message is TCP data and obtain a judgment result;
[0107] A TCP data buffer module is used to add the currently received message to the TCP buffer if the judgment result indicates that the currently received message is TCP data, and call the user reception callback function after the reception is completed;
[0108] The data caching module is used to add the data into the receiving buffer if the judgment result indicates that the currently received message is not TCP data.
[0109] Optionally, the parsing module 640 may specifically include:
[0110] A message reference and message type receiving unit, configured to obtain a message reference and a message type corresponding to a currently received message from the global state machine when the parser thread receives a specific instruction;
[0111] A message status setting unit, configured to set the status of a message according to a keyword in the specific instruction;
[0112] A parsing unit, which parses the message in the buffer according to the message type, obtains and saves the parsing result; the parsing result includes at least an IP address and a port number;
[0113] The buffer reset unit is used to reset the receiving buffer.
[0114] Optionally, the device may further include:
[0115] A message reference setting module, used to set the message reference of the global state machine;
[0116] The analysis module 640 may specifically include:
[0117] The sending state setting unit is used to set the sending state of the message according to the message reference of the global state machine; the sending state includes sending success or sending failure.
[0118] Based on the same idea, the embodiments of this specification also provide an AT command processing device. Figure 7 This is a schematic diagram of the structure of an AT command processing device provided by the present invention. It may include:
[0119] A communication unit / communication interface, configured to obtain AT commands sent by a user and determine a communication mode of the AT command processing system; the communication modes include a blocking mode and a non-blocking mode;
[0120] a processing unit / processor, configured for the producer thread to allocate message resources based on the communication mode and place messages contained in the message resources into a message queue;
[0121] The consumer thread takes out the corresponding message from the message queue and processes it, waiting for the synchronization lock of the global state machine;
[0122] The parser thread receives and parses the response from the module to determine the sending status of the retrieved message;
[0123] The synchronization lock of the global state machine is released based on the sending status, and the next response of the module is waited for.
[0124] like Figure 7 As shown, the terminal device may further include a communication line. The communication line may include a path for transmitting messages between the components. The memory may be a read-only memory (ROM) or other types of static storage devices that can store static messages and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store messages and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compact disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory may exist independently and be connected to the processor via a communication line. The memory may also be integrated with the processor.
[0125] Optionally, the computer-executable instructions in the embodiment of the present invention may also be referred to as application program codes, which is not specifically limited in the embodiment of the present invention.
[0126] In a specific implementation, as an embodiment, Figure 7 As shown, the processor may include one or more CPUs, such as Figure 7 CPU0 and CPU1 in.
[0127] In a specific implementation, as an embodiment, Figure 7 As shown, the terminal device may include multiple processors, such as Figure 7 Each of these processors can be a single-core processor or a multi-core processor.
[0128] Based on the same idea, the embodiments of this specification also provide a computer storage medium corresponding to the above embodiments. The computer storage medium stores instructions, and when the instructions are executed, the method in the above embodiments is implemented.
[0129] The above mainly introduces the solution provided by the embodiment of the present invention from the perspective of the interaction between the various modules. It can be understood that, in order to realize the above functions, each module includes a hardware structure and / or software unit corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present invention can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present invention.
[0130] The embodiments of the present invention can be divided into functional modules according to the above-mentioned method examples. For example, each functional module can be divided according to each function, or two or more functions can be integrated into a single processing module. The above-mentioned integrated modules can be implemented in the form of hardware or software functional modules. It should be noted that the division of modules in the embodiments of the present invention is illustrative and is only a logical functional division. In actual implementation, other division methods may be used.
[0131] The processor in this specification may also function as a memory. The memory is used to store computer-executable instructions for implementing the solutions of the present invention, and the processor controls the execution of the instructions. The processor is used to execute the computer-executable instructions stored in the memory, thereby implementing the methods provided in the embodiments of the present invention.
[0132] The memory may be a read-only memory (ROM) or other type of static storage device that can store static information and instructions, a random access memory (RAM) or other type of dynamic storage device that can store information and instructions, an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, an optical disc storage (including compact discs, laser discs, optical discs, digital versatile discs, Blu-ray discs, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory may exist independently and be connected to the processor via a communication line. The memory may also be integrated with the processor.
[0133] Optionally, the computer-executable instructions in the embodiment of the present invention may also be referred to as application program codes, which is not specifically limited in the embodiment of the present invention.
[0134] The methods disclosed in the above embodiments of the present invention can be applied to or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by hardware integrated logic circuits in the processor or by software instructions. The above processor may be a general-purpose processor, a digital signal processor (DSP), an ASIC, a field-programmable gate array (FPGA), or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component. The methods, steps, and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in conjunction with the embodiments of the present invention can be directly implemented and executed by a hardware decoding processor or by a combination of hardware and software modules in the decoding processor. The software modules can be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. The storage medium is located in a memory, and the processor reads the information in the memory and, in conjunction with its hardware, completes the steps of the above method.
[0135] In one possible implementation, a computer-readable storage medium is provided. The computer-readable storage medium stores instructions. When the instructions are executed, the method in the above embodiment is implemented.
[0136] In the above embodiments, all or part of the embodiments may be implemented using software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments may be implemented in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer programs or instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present invention are performed in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, a terminal, a user device, or other programmable device. The computer program or instructions may be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another. For example, the computer program or instructions may be transferred from one website, computer, server, or data center to another website, computer, server, or data center via wired or wireless means. The computer-readable storage medium may be any available medium that can be accessed by 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, such as a floppy disk, hard disk, or magnetic tape; an optical medium, such as a digital video disc (DVD); or a semiconductor medium, such as a solid-state drive (SSD).
[0137] Although the present invention is described herein in conjunction with various embodiments, in the process of implementing the claimed invention, those skilled in the art can understand and implement other variations of the disclosed embodiments by reviewing the drawings, the disclosure, and the appended claims. In the claims, the word "comprising" does not exclude other components or steps, and "a" or "an" does not exclude multiple situations. A single processor or other unit can implement several functions listed in the claims. Certain measures are recorded in different dependent claims, but this does not mean that these measures cannot be combined to produce good results.
[0138] Although the present invention has been described with reference to specific features and embodiments thereof, it will be apparent that various modifications and combinations may be made thereto without departing from the spirit and scope of the invention. Accordingly, this specification and drawings are merely illustrative of the invention as defined by the appended claims and are deemed to cover any and all modifications, variations, combinations or equivalents within the scope of the invention. It will be apparent that various modifications and variations may be made to the present invention by those skilled in the art without departing from the spirit and scope of the invention. Thus, the present invention is intended to include such modifications and variations as fall within the scope of the claims of the present invention and their equivalents.
Claims
1. A method for processing an AT command, characterized in that: The AT command processing method is applied to an AT command processing system, wherein the AT command processing system includes a consumer thread, a producer thread, a parser thread, and a global state machine; the method includes: Obtain AT commands sent by the user; and determine the communication mode of the AT command processing system; the communication mode includes blocking mode and non-blocking mode, and completes the information exchange between the main control and the WiFi module based on RTOS; The producer thread allocates message resources based on the communication mode and puts the messages contained in the message resources into a message queue; The consumer thread takes the corresponding message from the message queue and processes it, waiting for the synchronization lock of the global state machine; The parser thread receives and parses the response from the module to determine the sending status of the retrieved message; Release the synchronization lock of the global state machine based on the sending status, and wait for the next module response; When the communication mode is blocking mode, the user initiates an AT command to the producer thread to allocate message resources, put the message into the message queue, and wait for the mutex lock of the message contained in the message resource; the consumer thread continues to execute, sets the message reference of the global state machine to null, releases the mutex lock, and waits for the next message to be retrieved; the producer thread continues to execute, and based on the sending status, the producer thread releases the message resource; if the mutex lock cannot be released within the blocking time, the producer thread sets the return status to timeout; When the communication mode is non-blocking mode, the consumer thread continues to execute, and based on the sending status, calls the message callback function to notify the producer thread; sets the message reference of the state machine to null, releases the message resource, and waits for the next message to be retrieved.
2. The method according to claim 1, characterized in that Before the parser thread receives and parses the response from the module, it also includes: The parser thread obtains the currently received message; Determine whether the currently received message is TCP data and obtain the judgment result; If the judgment result indicates that the currently received message is TCP data, the currently received message is added to the TCP buffer, and the user reception callback function is called after the reception is completed; If the judgment result indicates that the currently received message is not TCP data, the data is added to the receiving buffer.
3. The method according to claim 2, characterized in that The parser thread receives the response from the module and parses it, specifically including: When the parser thread receives a specific instruction, it obtains the message reference and message type corresponding to the currently received message from the global state machine; the specific instruction includes " "; Setting the status of the message according to the keyword in the specific instruction; Parsing the message in the buffer according to the message type, obtaining and saving the parsing result; the parsing result includes at least the IP address and the port number; Reset the receive buffer.
4. The method according to claim 1, wherein The parser thread receives and parses the response from the module, and before determining the sending status of the retrieved message, it also includes: Setting a message reference for the global state machine; The parser thread receives and parses the response from the module to determine the delivery status of the retrieved message, specifically including: The sending state of the message is set according to the message reference of the global state machine; the sending state includes sending success or sending failure.
5. An AT command processing device, characterized in that: The AT command processing device is applied to an AT command processing system, which includes a consumer thread, a producer thread, a parser thread, and a global state machine; the device includes: The communication mode acquisition module is used to acquire the AT command sent by the user and determine the communication mode of the AT command processing system; the communication mode includes blocking mode and non-blocking mode; A message resource allocation module, configured for the producer thread to allocate message resources based on the communication mode and place messages contained in the message resources into a message queue; A message processing module, configured for the consumer thread to retrieve the corresponding message from the message queue and process it, waiting for the synchronization lock of the global state machine; A parsing module, configured for the parser thread to receive and parse the response sent by the module and determine the sending status of the retrieved message; A synchronization lock releasing module, configured to release the synchronization lock of the global state machine based on the sending state and wait for a response from the next module; When the communication mode is the blocking mode, the AT command processing device further includes: A mutex waiting module, configured to wait for a mutex lock of a message contained in the message resource; A mutex lock release module is used for the consumer thread to continue executing, set the message reference of the global state machine to null, release the mutex lock, and wait for the next message to be retrieved; A message resource release module is configured to allow the producer thread to continue executing and release the message resource based on the sending status; if the mutex cannot be released within the blocking time, the producer thread sets the return status to timeout; When the communication mode is a non-blocking mode, the AT command processing device further includes: The consumer thread execution module is used for the consumer thread to continue executing, and based on the sending status, calls the message callback function to notify the producer thread; sets the message reference of the state machine to empty, releases the message resource, and waits for the next message to be retrieved.
6. An AT command processing device, characterized in that: The AT command processing device is applied to an AT command processing system, which includes a consumer thread, a producer thread, a parser thread, and a global state machine; the device includes: A communication unit / communication interface, configured to obtain AT commands sent by a user and determine a communication mode of the AT command processing system; the communication modes include a blocking mode and a non-blocking mode; a processing unit / processor for allocating message resources to the producer thread based on the communication mode and placing messages contained in the message resources into a message queue; The consumer thread takes the corresponding message from the message queue and processes it, waiting for the synchronization lock of the global state machine; The parser thread receives and parses the response from the module to determine the sending status of the retrieved message; Release the synchronization lock of the global state machine based on the sending status, and wait for the next module response; When the communication mode is blocking mode, the user initiates an AT command to the producer thread to allocate message resources, put the message into the message queue, and wait for the mutex lock of the message contained in the message resource; the consumer thread continues to execute, sets the message reference of the global state machine to null, releases the mutex lock, and waits for the next message to be retrieved; the producer thread continues to execute, and based on the sending status, the producer thread releases the message resource; if the mutex lock cannot be released within the blocking time, the producer thread sets the return status to timeout; When the communication mode is non-blocking mode, the consumer thread continues to execute, and based on the sending status, calls the message callback function to notify the producer thread; sets the message reference of the state machine to null, releases the message resource, and waits for the next message to be retrieved.
7. A computer storage medium, characterized in that The computer storage medium stores instructions, and when the instructions are executed, the AT command processing method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Internet of Things water meter communication process control method and system
CN114125588A