The content of the invention
The technical problems to be solved by the invention are to provide a kind of multitask application program based on GPRS monitor terminals
Implementation method, to meet high reliability request of the severe application environment such as photovoltaic plant, wind power plant to GPRS monitor terminals.
In order to solve the above technical problems, present invention employs following technical scheme:
A kind of implementation method of the multitask application program based on GPRS monitor terminals, the multitask application program are based on
Multitask design mode realizes that multitask includes:Begin a task with, Modem serial ports receives task, GPRS scheduler tasks, data solution
Analyse convert task, GPRS link establishments and keep task, system monitoring alarming assignment, device data acquisition storage upload task;
Begin a task with:Start GPRS wireless communication modules first, then detect embedded microcontroller and serial ports is locally configured
The instruction into configuration status whether is received, if being not detected by the instruction in setting time, is normally started into system
State, otherwise into systematic parameter configuration state;
Modem serial ports receives task:Modem serial ports receives task and is mainly responsible for periodically inquiry and GPRS wireless communication modules
Whether data that GPRS wireless communication module send are had in the serial ports buffering area for the embedded microcontroller being connected, if so, then
Take out and be sent into Modem and receive data-message queue;
GPRS scheduler tasks:GPRS scheduler tasks complete the reception of GPRS wireless communication modules data, short message, and
The transmission of GPRS data, short message;
Data parse convert task:Data parsing convert task is periodically inquired about following flag bit and located accordingly successively
Reason:Data accepted flag position is inquired about, if the flag bit is true, the data received are parsed;Inquire about data and send mark
Will position, if the flag bit is true, structure sends packet and passes to GPRS scheduler tasks and transmitted wirelessly;
System monitoring alarming assignment:System monitoring alarming assignment is completed to system mode and the equipment real time data collected
Exception monitoring, by the running status of periodic detection system, so as to find system exception in time, and detecting anomalous event
When set alert flag bit accordingly, and set sends the flag bit of system exception alarm packet, is changed so that data parse
Task is inquired about, built and transmission system alarm packet to GPRS scheduler tasks are transmitted wirelessly;
Device data acquisition stores upload task:Device data acquisition storage upload task is periodically completed to the real-time number of equipment
According to collection, storage, and set equipment real time data uploads flag bit, so that data parsing convert task is inquired about, built
And transmission equipment real time data bag to GPRS scheduler tasks are transmitted wirelessly;
GPRS link establishments and holding task:GPRS link establishments and keep task complete GPRS communication links foundation and
Maintain, the task employ state machine realization, the state machine by " GPRS Modem initialization " state, " establish GPRS PPP company
Connect " state, " establishing GPRS TCP/UDP connections " state, " login remote server " state, " detection GPRS PPP connection shapes
State " state, " detection GPRS TCP/UDP connection status " state, " GPRS Modem hardware resets " state, " GPRS Modem
Upper electricity again " state and " software systems warm reset " state are formed.
Further, described to begin a task with systematic parameter configuration state, user can be by configuring serial ports to system
Send configuration instructs, and system carries out instructing parsing and parameter modification, storage after configuration-direct is received;User can also lead to
Cross instruction and check newest system parameter values, after the configuration completion instruction that user sends is received, system enters normal start
State, after software systems enter normal activation state, multi-tasks Software house dog is initialized first, then creates the letter of correlation
Number amount, message mailbox and message queue, then create that Modem serial ports receives task, GPRS scheduler tasks, data parsing conversion are appointed
Business, GPRS link establishments and holding task, system monitoring alarming assignment, device data acquisition storage upload task, finally start
Task hangs up itself;Afterwards, operating system begins to carry out Modem serial ports reception task, GPRS scheduler tasks, data parsing
Convert task, GPRS link establishments and holding task, system monitoring alarming assignment, the tune of device data acquisition storage upload task
Degree.
Further, the GPRS scheduler tasks periodically inquire about Modem and receive in data-message queue whether have message, if
Have, then take out the message and parsed, if message content is TCP/UDP data or short message, carries out corresponding data and carry
The simultaneously corresponding flag bit of set is taken, if message content is AT repeat-back data, is delivered the data to by message mailbox
GPRS link establishments and holding task are handled;GPRS scheduler tasks are also periodically inquired about Modem and sent in data-message queue
Whether message is had, if so, then take out the message, and whether unimpeded, if unimpeded, carry out the wireless hair of data if detecting GPRS links
Send, otherwise, add up sending times and the wait that is delayed, repeating transmission.If sending times more than 3 times, abandon the wireless transmission of the data;
In addition, GPRS scheduler tasks, which periodically inquire about short message, sends flag bit, if the flag bit is true, the transmission of short message is carried out.
Further, the inquiry of the data parsing convert task and implementation procedure are as follows:
If a, there are new TCP/UDP data, parsed accordingly, if the TCP/UDP data are grasped for Server remote
Order, then build corresponding acknowledgement frame according to predefined stipulations, and the acknowledgement frame is added into Modem and sends data-message team
Row, GPRS scheduler tasks are waited to be transmitted wirelessly;If the TCP/UDP data are server acknowledgement frame, set is marked accordingly
Will position;
If b, there is new remote operation short message, parsed, and response short message is built simultaneously according to predefined stipulations
Set short message sends flag bit, and wait GPRS scheduler tasks are inquired about and the wireless transmission of short message;
C, when network connection is normal, logon data bag, heartbeat data packets, equipment real time data bag, ALM are carried out
Packet, equipment alarm packet etc. send the detection of flag bit, if it is true that certain packet, which sends flag bit, according to predetermined
Adopted stipulations build the packet, and are sent to message queue to be sent, wait GPRS scheduler tasks to be transmitted wirelessly.
Further, the system monitoring alarming assignment is additionally included in when detecting new equipment real time data, to it
Carry out abnormality detection, it is similar with the processing of system exception, when detecting equipment real time data anomalous event set accuse accordingly
Alert flag bit, and set sends the flag bit of unit exception alarm packet, is inquired about so that data parse convert task, structure
Build and transmission equipment alarm packet to GPRS scheduler tasks are transmitted wirelessly.
Compared with the prior art, the invention has the advantages that:The advantage of this multitask application programming is:
Compared with the single task software system design for not using operating system, it on the one hand need not carry out function scheduling and set
Meter, so as to reduce the complexity of software system design, reduces design deviation to greatest extent;On the other hand, as a result of more
Business design, when the software systems of GPRS monitor terminals meet with outside strong jamming, some task for only resulting in software systems is different
Often, without triggering all task abnormities, so as to enhance the reliability of software systems.
Multitask design can easily carry out expanding of system function and system upgrade, if necessary on original function basis
Upper increase One function, it is only necessary to be individually for the Functional Design and realize a task, without carrying out big to existing software systems
Change.
The efficiency and real-time of system can also be improved using the multitask design based on embedded OS.
Embodiment
A kind of high reliability GPRS monitor terminals of the present invention are described further below in conjunction with accompanying drawing.
As shown in figure 1, a kind of high reliability GPRS monitor terminals that this example is related to, its hardware circuit includes insertion and declined
Controller, GPRS wireless communication modules, power module, GPRS power management modules, memory module, input/output module, hardware
House dog and indicator lamp;Wherein, GPRS wireless communication modules are connected by serial ports with embedded microcontroller, GPRS power supply pipes
Reason module is connected by universal I/O port with embedded microcontroller, and power module is electric with embedded microcontroller, GPRS respectively
Source control module is connected, embedded microcontroller also with memory module, input/output module, hardware watchdog and indicator lamp phase
Connection, embedded microcontroller is by controlling GPRS power management modules to open or stop the confession to GPRS wireless communication modules
Electricity.
As shown in Fig. 2 the input of GPRS power management module circuits is GPRS_PWR_DOWNn, with embedded microcontroller
The universal I/O port of device is connected, and output end VCC_GPRS, is connected with the power input of GPRS wireless communication modules.It is embedded
The controller that declines controls the output level of the universal I/O port of embedded microcontroller according to the control instruction of software systems, and then controls
The level of the input of GPRS power management modules circuit processed.When GPRS power management modules circuit input end is low level,
GPRS power management module circuit output end VCC_GPRS voltages are zero, i.e., now cut off the power supply to GPRS wireless communication modules
Supply;When GPRS power management modules circuit input end is high level, GPRS power management module circuit output ends VCC_
GPRS voltages are 3.8V, i.e., the power supply for now providing GPRS wireless communication modules 3.8V is supplied.It is real by above-mentioned controlling mechanism
The upper electric operation again of software instruction control GPRS wireless communication modules is showed, so as to ensure that GPRS monitor terminals can after suspension
Normal operating conditions is returned to, is reliably connected to network.
As shown in figure 3, on GPRS monitor terminals after electricity, software systems automatic start simultaneously enters Main functions, in Main letters
In number, the peripheral hardwares such as serial ports, indicator lamp, memory module are initialized first, then control GPRS power management modules wireless to GPRS
It is electric in communication module, embedded OS is then initialized, and create and begin a task with, finally start multi-task scheduling.
In beginning a task with, start GPRS wireless communication modules first, then detect embedded microcontroller and string is locally configured
Whether mouth receives the instruction into configuration status, if being not detected by the instruction in setting time, is normally opened into system
Dynamic state, otherwise into systematic parameter configuration state.Under systematic parameter configuration state, user can be by configuring serial ports to being
Send configuration of uniting instruction, system carry out instructing parsing and parameter modification, storage after configuration-direct is received.User can also
Newest system parameter values are checked by instruction.After the configuration completion instruction that user sends is received, system, which enters, normally to be opened
Dynamic state.After software systems enter normal activation state, multi-tasks Software house dog is initialized first, then creates correlation
Semaphore, message mailbox and message queue, then create Modem serial ports and receive task, GPRS scheduler tasks, data parsing conversion
Task, GPRS link establishments and holding task, system monitoring alarming assignment, device data acquisition storage upload task, are finally opened
Beginning task hangs up itself.Afterwards, operating system begins to carry out Modem serial ports reception task, GPRS scheduler tasks, data solution
Analyse convert task, GPRS link establishments and keep task, system monitoring alarming assignment, device data acquisition to store upload task
Scheduling.
Modem serial ports, which receives task, to be mainly responsible for periodically inquiring about the embedded micro-control being connected with GPRS wireless communication modules
Whether data that GPRS wireless communication module send are had in the serial ports buffering area of device processed, if so, then taking out and being sent into Modem receptions
Data-message queue.
GPRS scheduler tasks complete the reception of GPRS wireless communication modules data, short message, and GPRS data, short message
Transmission.GPRS scheduler tasks periodically inquire about Modem and receive in data-message queue whether have message, disappear if so, then taking out this
Cease and parsed, if message content is TCP/UDP data or short message, carries out corresponding data extraction and set is corresponding
Flag bit, if message content is AT repeat-back data, by message mailbox deliver the data to GPRS link establishments and
Holding task is handled.GPRS scheduler tasks also periodically inquire about Modem and send in data-message queue whether have message, if
Have, then take out the message, and detect whether GPRS links are unimpeded, if unimpeded, the wireless transmission of progress data is otherwise, accumulative
Sending times and the wait that is delayed, repeating transmission.If sending times more than 3 times, abandon the wireless transmission of the data.In addition, GPRS is adjusted
Degree task periodically inquires about short message and sends flag bit, if the flag bit is true, carries out the transmission of short message.
Data parsing convert task periodically carries out the inquiry of following flag bit successively, and performs corresponding action:
(1)If there are new TCP/UDP data, parsed accordingly.If the TCP/UDP data are grasped for Server remote
Order(Such as remote inquiry, setting command), then corresponding acknowledgement frame is built according to predefined stipulations, and the acknowledgement frame is added
Enter Modem and send data-message queue, wait GPRS scheduler tasks to be transmitted wirelessly;If the TCP/UDP data are server
Acknowledgement frame(Such as log in acknowledgement frame, heartbeat packet acknowledgement frame), then the corresponding flag bit of set.
(2)If there is new remote operation short message, parsed, and response short message is built simultaneously according to predefined stipulations
Set short message sends flag bit, and wait GPRS scheduler tasks are inquired about and the wireless transmission of short message.
(3)When network connection is normal, logon data bag, heartbeat data packets, equipment real time data bag, ALM are carried out
Packet, equipment alarm packet etc. send the detection of flag bit, if it is true that certain packet, which sends flag bit, according to predetermined
Adopted stipulations build the packet, and are sent to message queue to be sent, wait GPRS scheduler tasks to be transmitted wirelessly.
System monitoring alarming assignment completes the exception monitoring to system mode and the equipment real time data collected, by fixed
When detecting system running status, so as to finding system exception in time, and set alerts accordingly when detecting anomalous event
Flag bit, and set sends the flag bit of system exception alarm packet, is inquired about, built so that data parse convert task
And transmission system alarm packet to GPRS scheduler tasks are transmitted wirelessly.In addition, system monitoring alarming assignment is detecting
When having new equipment real time data, abnormality detection is carried out to it, it is similar with the processing of system exception, detecting that equipment counts in real time
Flag bit is alerted accordingly according to set during anomalous event, and set sends the flag bit of unit exception alarm packet, to count
Inquired about, built according to parsing convert task and transmission equipment alarm packet to GPRS scheduler tasks are transmitted wirelessly.
Device data acquisition stores upload task:Device data acquisition storage upload task is periodically completed to the real-time number of equipment
According to collection, storage and upload.
GPRS link establishments and holding task:GPRS link establishments and keep task complete GPRS communication links foundation and
Maintain, the task employ state machine realization, the state machine by " GPRS Modem initialization " state, " establish GPRS PPP company
Connect " state, " establishing GPRS TCP/UDP connections " state, " login remote server " state, " detection GPRS PPP connection shapes
State " state, " detection GPRS TCP/UDP connection status " state, " GPRS Modem hardware resets " state, " GPRS Modem
Upper electricity again " state and " software systems warm reset " state are formed.
As shown in figure 4, the State Transferring mechanism of the state machine of the GPRS link establishments and holding task is as follows:
A, into " GPRS Modem initialization " state, GPRS Modem initialization is carried out in this case, is being initialized
Each Modem AT command operatings when, employ " deterministic Modem AT command operatings mechanism ";If at the beginning of Modem
Beginning chemical conversion work(then enters " establishing GPRS PPP connections " state, if initialization failure, enters " GPRS Modem hardware resets "
State;
B, under " establishing GPRS PPP connections " state, trial is instructed to establish PPP companies by sending AT to GPRS Modem
Connect, if establishing successful connection, enter " establishing GPRS TCP/UDP connections " state, if PPP connections are established in continuous 3 trials
Failure, then enter " GPRS Modem hardware resets " state;
C, under " establishing GPRS TCP/UDP connections " state, attempt and specify according to the configuration selection of systematic parameter
Service-Port establishes TCP connections or UDP connections, if establishing successful connection, enters " login remote server " state, if even
Continue 3 trials and establish TCP/UDP connection failures, then enter " GPRS Modem hardware resets " state;
D, under " login remote server " state, the long-range of server is carried out using " reliable to log in GPRS network mechanism "
Register;Set sends the flag bit of logon data bag to server, waits pending data parsing convert task detect simultaneously structure
Build, transmit logon data bag to GPRS scheduler tasks and transmitted wirelessly, and the logon data bag feedback of waiting for server, if
The logon data bag feedback of server is received in the stand-by period specified, then illustrates the success of login service device, into " detection
GPRS PPP connection status " state, otherwise illustrate that login service device fails, if continuous 3 login service devices fail, enter
" GPRS Modem hardware resets " state;
E, under " detection GPRS PPP connection status " state, realize " terminal real-time online testing mechanism ".By fixed
Phase sends the state of AT command detection GPRS PPP connections to GPRS Modem, if GPRS PPP connections are normal, enters " detection
GPRS TCP/UDP connection status " state, if detecting for continuous 3 times, GPRS PPP connections disconnect, and enter and " establish GPRS PPP
Connection " state, re-establishes GPRS PPP connections;Periodic detection GPRS PPP connection status why is needed, is due to GPRS
The network condition of network in itself can cause GPRS wireless monitor nodes to go offline, in order to ensure GPRS wireless monitors node and service
The proper communication of device, GPRS wireless monitor nodes have to know when to go offline from GPRS network, so as to re-establish PPP in time
Connection and TCP/UDP connections.
F, under " detection GPRS TCP/UDP connection status " state, TCP/UDP links are realized using " heartbeat mechanism "
Connection status detects.By periodically sending heartbeat data packets to server to detect the state of GPRS TCP/UDP connections, if
GPRS TCP/UDP connections are normal, then enter " detection GPRS PPP connection status " state, if continuous 3 times detect GPRS
TCP/UDP connections disconnect, then enter " establishing GPRS TCP/UDP connections " state, re-establish GPRS TCP/UDP connections.Its
In, it is similar with sending logon data bag to the implementation of server transmission heartbeat data packets, sent by set to server
The flag bit of heartbeat data packets, wait pending data parsing convert task to be detected and built, transmit heartbeat data packets to GPRS tune
Degree task is transmitted wirelessly, and the heartbeat data packets feedback of waiting for server, if receiving clothes within the specified stand-by period
The heartbeat data packets feedback of business device, then illustrate that TCP/UDP connections are normal, otherwise it is assumed that TCP/UDP connections disconnect.
G, under " GPRS Modem hardware resets " state, the action of GPRS Modem hardware resets, and accumulative GPRS are performed
The number of Modem hardware resets, if the number of GPRS Modem hardware resets more than 3 times, enter " GPRS Modem again on
Electricity " state, otherwise enters " GPRS Modem initialization " state;
H, under " GPRS Modem again upper electricity " state, GPRS Modem shutdown, power-off, upper electricity, start behaviour are performed successively
Make, and add up GPRS Modem upper electric numbers again, if above the number of electricity more than 3 times, enters " software system to GPRS Modem again
System warm reset " state, otherwise enters " GPRS Modem initialization " state;
I, under " software systems warm reset " state, software systems warm reset action is performed, restarts software systems, Jin Er
After establishing GPRS link establishments and holding task, into " GPRS Modem initialization " state.
The Modem AT command operating mechanism is the response time instructed for GPRS wireless communication modules to different AT
It is inconsistent, using timeout mechanism, i.e., the different stand-by period is set according to each AT orders different response time, if specify
Interior acquisition return value then terminates to wait, overtime then terminate to wait automatically, the reliability of guarantee Modem AT command operatings.
The reliable GPRS network mechanism that logs in is logged in using timeout mechanism, i.e., when monitor node logs in, if waiting
Log in feedback time-out, then it is assumed that login failure, after multiple login failure, then reset GPRS wireless communication modules again.
The heartbeat mechanism is that the timing of GPRS monitor terminals sends heartbeat packet to background server, if not received in the keep-alive time
Fed back to heartbeat packet, then it is assumed that link has disconnected, and disconnects existing connection automatically and re-establishes link;Exist always although GPRS has
The characteristics of line, but when GPRS online no data transmission for a long time, data service rank can be lowered automatically, using heartbeat machine
I.e. when system is transmitted without valid data for a long time, monitor node is sent system according to certain time interval to server
One frame invalid data, so as to keep data transmission service to be in higher priority level, maintain GPRS data link.
The terminal real-time online testing mechanism is by being periodically detected GPRS PPP connection status, can detect in time
Whether node goes offline from GPRS network, is performed if going offline and attempts the operation of dial-up connection again, so as to ensure that monitor node is real-time
Online;Gone offline because the unstability of GPRS network in itself may result in GPRS wireless monitor nodes, in order to ensure monitoring section
The proper communication of point and server, monitor node have to know when to go offline from GPRS network, and then re-establish PPP connections
And TCP/UDP connections.
" the GPRS Modem hardware resets ", " GPRS Modem are again upper electric ", " software systems warm reset " three kinds of shapes
State constitutes GPRS link establishments and keeps triple Restart mechanisms of task;Ensure that monitor node can recover after going offline with after
The connection of platform server, so as to realize the reliable networking of GPRS wireless monitor nodes.
As shown in figure 5, GPRS Modem initialization flow is as follows:
(1)AT instruction testings are carried out to GPRS Modem first, Modem AT instruction echo work(is closed if being successfully tested
Can, then carry out SIM card test;Terminate GPRS Modem initialization if continuous 3 test crash, and return to initialization failure
Information.
(2)GPRS signal quality testings are carried out if SIM card is successfully tested;If continuous 3 SIM card test crash, are tied
Beam GPRS Modem are initialized, and return to initialization failure information.
(3)If GPRS signal qualitys well if carry out GPRS Modem network registries;If GPRS signals are unavailable, terminate
GPRS Modem are initialized, and return to initialization failure information.
(4)If the success of GPRS Modem network registries, carries out short message(SMS)Relevant parameter initializes;If continuous 3 times
GPRS Modem network registries fail, then terminate GPRS Modem initialization, and return to initialization failure information.
(5)If short message(SMS)Relevant parameter initializes successfully, then reads GPRS Modem information, terminates GPRS
Modem is initialized, and returns to initialization successful information;If short message(SMS)Relevant parameter initialization failure, then terminate GPRS
Modem is initialized, and returns to initialization failure information.
The number of various tests or operation in above initialization procedure is not limited to 3 times, can be according to the applied field of reality
Conjunction is adjusted.
As shown in fig. 6, the multitask application program realizes multi-tasks Software house dog, the multi-tasks Software house dog
Fed dog subprogram by the software watchdog subprogram of each task, and multi-tasks Software house dog and formed;Each task is soft
Part watchdog program is mainly responsible for the initialization of the task software watchdog, and updates the task software in major cycle and guard the gate
The counter of dog;Multi-tasks Software house dog feeds the software that dog subprogram then checks each task in each system clock cycle
Whether house dog has timed out, as long as the software watchdog time-out of some task, just answering by the complete paired systems of hardware watchdog
Position.
Wherein, the software watchdog subprogram of each task mainly includes the assignment and counter of the initial value of timer
Renewal, specifically:It is required for initializing the software watchdog of the task in each task section start, including by software watchdog
The initial value of timer is entered as the timeout value of the task, and opens the software watchdog of the task.In addition, in each task
The counter of the task software watchdog will be updated in major cycle.
Multi-tasks Software house dog feeds dog subprogram and is located at system clock beat Hook Function, in each system clock cycle
It is interior to be called once.Multi-tasks Software house dog feeds dog subroutine flow and is described as follows:
After feeding dog subprogram into multi-tasks Software house dog, " stopping feeding hardware watchdog flag bit " is first checked for whether
It is true, if true, then directly terminate multi-tasks Software house dog and feed dog subprogram;If it is not true, successively to each
The software watchdog state of business is checked that step is as follows:Check whether the task software watchdog counter has updated, if
Renewal, then the value for resetting the task software watchdog timer is the timeout value of the task, and continues next task
Software watchdog status checkout;If not updating, the value of the task software watchdog timer is subtracted 1 first, then judging should
Whether the value of task software watchdog timer is zero, is zero and illustrates that the task software watchdog timer has timed out, set
" stopping feeding hardware watchdog flag bit " is true, directly terminates multi-tasks Software house dog and feeds dog subprogram, is not zero, continues
Carry out the software watchdog status checkout of next task.It is sequentially completed according to above-mentioned steps to each task software watchdog
Status checkout, the step of feeding hardware watchdog is then performed, finally terminate multi-tasks Software house dog and feed dog subprogram.
As shown in fig. 7, housing using it is interior it is it is outer under shell structure, material is aluminium alloy;Using close between upper-lower casing
Strip of paper used for sealing is sealed, and sealing strip is silastic material, is installed in the groove in upper shell;Upper-lower casing is connected using screw thread
Connect and compress the sealing strip between upper-lower casing, reach the effect of sealing;Connector selects PG7 Waterproof connector of cable, installation position
Put and be arranged in housing both sides;Hardware circuit board, which is connected through a screw thread, to be fixed in lower house.
The description of understanding for embodiment is only to understand the present invention for help, rather than for limiting this hair
Bright.Those skilled in the art can carry out some changes and change using the thought of the present invention, as long as its technological means does not have
There are the thought and main points for departing from the present invention, still within protection scope of the present invention.