Summary of the invention
The technical problem to be solved in the present invention is that multi-channel A T receives the defective that data are mixed mutually, and a kind of AT instruction processing unit and method thereof that AT replys the reliability of data that receive that increase is provided for after overcoming in the prior art multi-channel A T instruction and sending.
The present invention solves above-mentioned technical problem by following technical proposals:
A kind of AT instruction processing unit, its characteristics are that it comprises:
Sending module is used to send the AT instruction, and any one has only an AT instruction to be sent out constantly;
Receiver module is used for receiving and parsing AT instruction, and triggers the task of different application layers according to the different situations that receive character; Simultaneously, receiver module has also been realized a kind of data receive method of the timeout mechanism based on μ COS-II.
Application processing module is used for the parsing of AT instruction short message content, carries out corresponding operation according to the different content of note.
Preferably, this device is the device based on real-time multi-task operating system.
Preferably, this real-time multi-task operating system is μ COS-II.
Preferably, described AT instruction comprises: GPRS and tcp state query statement, send and the short message reading instruction, and send the tcp data instruction.
Another technical scheme of the present invention is: a kind of AT command processing method of described device, and its characteristics are that it may further comprise the steps:
S1, sending module sends the AT instruction, and any one has only an AT instruction to be sent out constantly;
S2, receiver module receives and resolve the AT instruction, and triggers the task of different application layers according to the different situations that receive character;
S3, application processing module resolves the short message content in the AT instruction, carries out corresponding operation according to the different content of note.
Preferably, step S1In, after sending module sends data, have only wait for predetermined timeout interval after, just send next bar data, to guarantee the end of wireless module transmission data.
Preferably, described AT instruction comprises: GPRS and tcp state query statement, send and the short message reading instruction, and send the tcp data instruction.
Preferably, step S2In, the process that receives the AT instruction adopts the mode of character reception one by one, after hardware based interruption has determined data, utilizes semaphore to notify receiver module.
Preferably, step S2In, receiver module triggers the task of different application layers by semaphore and mailbox.
Preferably, step S3In the operation carried out comprise: according to the switch of short message content control LED, multichannel inquiry and the control of LED on the development board.
Positive progressive effect of the present invention is: the present invention takes the mode of character reception one by one to receive data, the main Data Receiving of using based on the timeout mechanism of μ COS-II, and this method is different from traditional data receive mode.The present invention effectively reduces the losing probability that AT replys data, increases to receive the reliability that AT replys data.Further, realized under μ COS-II that AT instructs separating fully of transmission and data parsing.Reduced receiving the possibility that the AT director data mixes in the data, reduced the complexity of resolving the AT instruction.Instruction sends based on AT, and the principle that data parsing and application Processing tasks are separated is added for simultaneously follow-up application and having been stayed convenience.
Embodiment
Provide preferred embodiment of the present invention below in conjunction with accompanying drawing, to describe technical scheme of the present invention in detail.
As everyone knows, when carrying out the exploitation of wireless module, need utilize between MCU or single-chip microcomputer and the wireless module to communicate.The present invention just is based on a kind of exploitation on this framework, and that the MCU in the present embodiment adopts is ARM.As shown in Figure 1, AT instruction processing unit 1 of the present invention comprises: sending module 11, be used to send the AT instruction, and any one has only constantly an AT instruction to be sent out; Receiver module 12 is used for receiving and parsing AT instruction, and triggers the task of different application layers according to the different situations that receive character; Application processing module 13 is used for the parsing of AT instruction short message content, carries out corresponding operation according to the different content of note.Wherein, described AT instruction can be GPRS and tcp state query statement, sends and the short message reading instruction, sends the tcp data instruction.In the present embodiment, adopted μ COS-II as real time operating system, those skilled in the art also can adopt the operating system of other types certainly, and it has the real-time that most real time operating systems have, the task property seized, it has littler EMS memory occupation simultaneously.In specific implementation, each task of aforesaid module respective operations system sends such as all AT and all to be placed on task A and task B is responsible for the data processing that all receive, and resolves this task that all is placed on.Task C is an application task, and it is used for handling the relevant task of note.Task B comes control task C by semaphore and mailbox, and follow-up application can realize that follow-up task is unified communicates by letter with task B by the form of adding independent task.
Fig. 2 is the AT command processing method of device of the present invention, and it may further comprise the steps:
Step 101, sending module send the AT instruction, and any one has only an AT instruction to be sent out constantly.Wherein, because of employing in the present embodiment is μ COS-II operating system, the waiting-timeout mechanism that provides by μ COS-II operating system, after having guaranteed the transmission data, (this overtime time can be definite through test after having only wait timeout, and can guarantee the reception fully of data), judge that according to this opposite end (being the data that wireless module is issued ARM) sends the end of data; After this, sending module just can send next bar data.Taked in the present embodiment to send data, received data, sent the principle of data again.Wherein, the mutual exclusion of overtime reception data and AT order is sent as key technology means of the present invention place.
Step 102, receiver module receive and resolve the AT instruction, and trigger the task of different application layers according to the different situations that receive character;
Step 103, application processing module are resolved the short message content in the AT instruction, carry out corresponding operation according to the different content of note.
Above-mentionedsteps 102~103 specific implementation in practice is the state of the art, is not inventive point of the present invention place.
As shown in Figure 3, in concrete design, need to send multiple AT instruction: as GPRS and tcp state query statement, send and the short message reading instruction, send tcp data instruction or the like according to multiple different situation.The present embodiment unification is put into these instructions among the task A of having limit priority, and the mutual exclusion of the state flag bit that constantly changes in using by each guarantees that any one has only an AT instruction just to be sent out among the task A constantly.The strategy of Shi Xianing also is based on former experiments like this, and the AT instruction of high amount of traffic amount mixes under the situation about sending, and there is the situation of mixing in the data that receive, and it is more difficult resolving under these circumstances and receiving data.
The processing unification from the data of wireless module that receives is placed among the task B of time high priority, and the mode that the process of reception adopts character one by one to receive adopts the interruption receive mode of serial ports.In case after hardware based interruption has determined data, utilize semaphore to notify task B, after a period of time did not receive data, system is overtime to be returned, and began to send next bar AT instruction.Simultaneously in task B, trigger the task of different application layers according to the various situation that receives character by semaphore and mailbox, in the design of present embodiment task C.Such as: the ARM development board receives character ">" expression from wireless module can send data, receives " CMT " expression and has received new note or the like.Simultaneously, send order, for this class AT command analysis, judge unified being placed among the task B especially if added new AT.
Task C mainly is responsible for the parsing of short message content in the design, carries out corresponding operating according to the different content of note.For example control switch of LED or the like according to short message content.Simultaneously, in interruption, can also realize regularly,, send data to the TCP server on this basis in the mid-or clear corresponding marker bit of interrupt handling routine.The idiographic flow that each task among Fig. 3 is switched is:
Step 201, task A hangs up self by mailbox, and notice task B, and an AT instruction is sent out, and prepares to accept data.
Step 202, the data that task B handle receives send to task C with the form of mailbox, hang up itself with semaphore simultaneously.
Step 203, task C is with the form notice task B of semaphore, and data are finished dealing with.Hang-up task C, the switching of finishing the work of notice kernel.
Step 204, task B notice task A, data finish receiving, and request sends next bar AT instruction, and the notice kernel carries out task and switches.Self-defining title when scheming Chinese and English phrase for programming is only for giving an example.
A kind of new data receive method that Fig. 4 proposes for the present invention.In the reception of the serial ports interrupt handling routine of ARM development board is interrupted, send semaphore to system.In receiver function, use the timeout mechanism of μ COS-II, after after having surpassed certain clock cycle, still not receiving character from wireless module, the serial ports hardware FIFO of ARM development board still is empty words simultaneously, hang up the reception task so and (in system of the present invention, will move other task of limit priority A this time; Send next bar AT instruction).Before not using said method, in traditional technology, after many places or a plurality of local transmission AT instruction, last the corresponding reception data of AT instruction often instruct corresponding reception data mixing to be in the same place with a back AT; At this moment resolving the data that wireless module provides is comparison difficulties, and the loss of data phenomenon often occurs.After using this new data receive method, test result shows that compare additive method, this method has increased substantially the Data Receiving reliability, has reduced the probability of obliterated data.As figure, idiographic flow is as follows:
Step 301, operating system initialization.
Step 302, multitask environment is created.
Step 303, the Target Board initialization.
Step 304 after μ COS-II system wait is overtime, does not also receive character and then hangs up reception task (task A will move).
After step 305, wireless module receive a character, send semaphore.
Wherein, self-defining title when scheming Chinese and English phrase for programming is only for giving an example.
Those skilled in the art can realize the real-time detection of GPRS and tcp state when test is of the present invention, and the BEEP prompting is arranged; Realize multichannel inquiry and the control of note to the LED on the ARM development board; Realize regularly reporting of led state to PC end TCP server.
The process of concrete test is as follows, and 1, the development board of serial ports of ARM development board and wireless module is coupled together; 2, another serial ports and the PC of ARM development board are coupled together, open PC and go up the serial ports receiving tool, in order to monitor GPRS state and tcp state; 3, wireless module is by the led state on the note control ARM development board.During inquiry, message reply.4, regularly report led state to the TCP server on the PC.
Can realize the function that the present invention is whole by test, with stylish AT analytic method and framework, clear layer has reduced the parsing complexity of data, has avoided the situation of the AT data mixing that receives that can occur usually.Stayed convenience for simultaneously the interpolation of new function.
Though more than described the specific embodiment of the present invention, it will be understood by those of skill in the art that these only illustrate.Protection scope of the present invention is limited by appended claims.Those skilled in the art can make numerous variations or modification to these execution modes under the prerequisite that does not deviate from principle of the present invention and essence, but these changes and modification all fall into protection scope of the present invention.