Summary of the invention
Technical problem to be solved by this invention is, provides a kind of cycle for low-frequency serial bus and aperiodic to mix communication means and system, to solve the problem of the data collision and the wasting of resources etc. that cause when periodically packet and aperiodicity message mix transmitting-receiving.
The present invention solves the problems of the technologies described above adopted technical scheme and is to provide a kind of cycle for low-frequency serial bus and aperiodic mixes communication means, and the method comprising the steps of:
S1, client serially-transmitted data message, wherein, periodically packet each cycle sends once, and aperiodicity message sends when there is emergency situations;
Whether S2, judgement now send described data message and can clash, if meeting, then described data message are put into buffer memory Buffer and keep in;
If S3 can not, then will send described data message;
The transmission order of client described in S4, received server-side, is set to 0 by flag bit Flag;
S5, receive described data message, described Flag is set to 1, and empties buffer memory RespBuffer;
S6, resolve described data message, if described data message is correct, then it is verified, if described data message is wrong, then described type of error is updated in ErrCode;
S7, judge sub-type of message, if described periodically packet, then update server data, if described aperiodicity message, then write in described RespBuffer, and flag bit bRespReceived are set to 1.
Preferably, in step S2, when universal serial bus is idle, judges whether there is temporary data message in described buffer memory Buffer, if having, then send described data message, and empty described buffer memory Buffer.
Preferably, in step S4, when described flag bit Flag is set to 0, start timing, if timing exceedes the time threshold T of setting, not receiving described data message yet or calibration mistake occurs, is then time-out error, stops receiving, and upgrades described ErrCode.
Preferably, in step S7, described server end judges sub-type of message according to Resp value, if Resp=0X0F, is then described periodically packet, if Resp ≠ 0X0F, is then aperiodicity message.
Preferably, when the flag bit bRespReceived value of described RespBuffer is 1, described server end need reply the aperiodicity message in described RespBuffer.
On the other hand, the invention provides a kind of cycle for low-frequency serial bus and aperiodic mixes communication system, it is characterized in that, described system comprises client and server end, wherein,
Described client is used for serial and sends periodically packet and aperiodicity message, and described client comprises the first judging unit, buffer memory Buffer unit, transmitting element and detecting unit;
Described server end is for receiving described periodically packet and aperiodicity message, and respective handling is carried out to it, described server end comprises receiving element, resolution unit, error handling unit, calibration unit, the second judging unit, data updating unit and buffer memory RespBuffer unit.
Preferably, the unit in described client:
Described first judging unit, now sends described periodically packet for judgement or whether aperiodicity message can clash, if meeting, is then kept in described buffer memory Buffer unit, if can not, then send it to described transmitting element;
Described buffer memory Buffer unit, the described periodically packet sent for temporary described first judging unit or aperiodic message;
Described transmitting element, for send described periodically packet or aperiodic message;
Described detecting unit, for when universal serial bus is idle, to detect in described buffer memory Buffer unit whether temporary have described periodically packet or aperiodic message, if having, then send, and empty described buffer memory Buffer unit.
Preferably, the unit in described server end:
Described receiving element, for receive transmission order and described periodically packet that described client sends or aperiodic message, when receiving described transmission order, flag bit Flag is set to 0, when described message finishes receiving, described flag bit Flag is set to 1;
Described resolution unit, for resolve described periodically packet or aperiodic message, if described message is correct, then sends it to described calibration unit, if described message is wrong, then type of error be updated to error handling unit;
Described error handling unit, for recording the mistake receiving described periodically packet or produce in message process aperiodic;
Described calibration unit, for periodically packet described in calibration or aperiodic message;
Described second judging unit, for judging the type of sub-message, if described periodically packet, is then sent to described data updating unit, if described aperiodicity message, is then sent to described buffer memory RespBuffer unit;
Described data updating unit, for upgrading the data of described server end according to described periodically packet;
Described buffer memory RespBuffer unit, for aperiodicity message described in buffer memory.
Preferably, described receiving element also comprises timing unit, when described flag bit Flag is 0, start timing, if overtime threshold value T does not receive described message or described message calibration mistake yet, be then time-out error, stop receiving, and described time-out error is sent to described error handling unit upgrades; When described Flag is 1, empty described buffer memory RespBuffer unit.
Preferably, described second judging unit judges the type of sub-message according to Resp value, if Resp=0X0F, is then described periodically packet; If Resp ≠ 0X0F, be then aperiodicity message, write described buffer memory RespBuffer unit, and the flag bit bRespReced in described buffer memory RespBuffer unit is set to 1.
Embodiment
Following examples only for technical scheme of the present invention is clearly described, and can not limit the scope of the invention with this.Specification subsequent descriptions is for implementing better embodiment of the present invention, and right described description is to illustrate for the purpose of rule of the present invention, and is not used to limit scope of the present invention.Protection scope of the present invention is when being as the criterion depending on the claims person of defining.
Below in conjunction with the drawings and specific embodiments, the present invention is described in further details.
As depicted in figs. 1 and 2, be a preferred embodiment of the present invention, the cycle and the aperiodic that disclose low-frequency serial bus mix communication means, and wherein, Fig. 1 discloses the method that periodically packet sends, and the method comprising the steps of:
S101, when client serial send periodically packet time, judge that whether universal serial bus idle;
If S102 has the aperiodicity message sent, then periodically packet is put into buffer memory Buffer and keep in;
If S103 is idle, then send;
S104, to be sent completely, to judge in buffer memory Buffer whether temporaryly have aperiodicity message;
If S105 has, then send the message in buffer memory Buffer, and empty buffer memory Buffer.
Further, Fig. 2 discloses the method that aperiodicity message sends, and the method comprising the steps of:
S201, when client serial send aperiodicity message time, judge that whether universal serial bus idle;
If S202 has the periodically packet sent, then aperiodicity message is put into buffer memory Buffer and keep in;
If S203 is idle, then send;
S204, to be sent completely, to judge in buffer memory Buffer whether temporaryly have periodically packet;
If S205 has, then send the message in buffer memory Buffer, and empty buffer memory Buffer.
In the present embodiment, data message is divided into periodically packet and aperiodicity message, wherein periodically packet is accumulated to by timing and starts cycle time to send, aperiodicity message starts when breaking in a burst to send, when sending periodically packet, if there is aperiodicity message to take universal serial bus, then for preventing conflict, periodically packet is temporarily stored in buffer memory Buffer, after aperiodicity message is sent completely, message in buffer memory Buffer is sent, vice versa, like this, both the conflict that serially-transmitted data message may cause had been solved, simultaneously, again because do not need to divide the time sent datagram at every turn, can immediately send temporary message, solve as sending the problems such as the wasting of resources that message causes in time.
As shown in Figure 3, disclose the method for received server-side data message, the method comprising the steps of:
The transmission order of S301, received server-side client, is set to 0 by flag bit Flag, and receives message;
S302, flag bit Flag are designated as 0, start timing, judge whether the timing cumulative time exceedes the time threshold of setting;
Finish receiving in S303, time threshold, Flag value is set to 1, and empty buffer memory RespBuffer;
Do not finish receiving in S304, time thresholding, as time-out error, be updated in ErrCode;
S305, analytic message, and judge that whether message is correct;
S306, message error, be then updated to mistake in ErrCode.
In the present embodiment, control confirmation message by flag bit Flag whether to finish receiving, if finish receiving, then Flag becomes 1 from 0, if message does not receive or receives mistake, being then updated in ErrCode by corresponding mistake, can the message that receives of Deterministic service device termination be all correctly available, and the mistake and the type of error that dock time receiving message have corresponding record, and reversibility is strong.
As shown in Figure 4, disclose the method for the message that server-side processes receives, the method comprising the steps of:
S301, calibration message;
S302, judge sub-type of message, Resp=0X0F according to Resp value in message, sub-message is cycle temper message, Resp ≠ 0X0F, aperiodicity message during sub-message;
If S303 message is periodically packet, then according to message update server data;
If S304 message is non-periodically packet, then message is write RespBuffer, flag bit bRespReceived is set to 1.
In the present embodiment, when emergency situations occurs, client sends aperiodicity message, and server end is write in RespBuffer, and flag bit bRespReceived is set to 1, and waiting for server end is replied; Periodically packet is that periodic data is uploaded, server end only needs to carry out corresponding data and upgrades, without the need to response, the different types of data message of simple differentiation, makes respective handling to different message, accelerates message processing speed, raise the efficiency, and server can be replied for the corresponding command response message, need not check one by one, reduce the wasting of resources.
One of ordinary skill in the art will appreciate that, the all or part of step realized in above-described embodiment method is that the hardware that can carry out instruction relevant by program has come, described program can be stored in computer read/write memory medium, this program is when performing, comprise each step of above-described embodiment method, and described storage medium can be: ROM/RAM, magnetic disc, CD, storage card etc.Therefore, relevant technical staff in the field will be understood that corresponding with method of the present invention, the present invention also comprises a kind of cycle of low-frequency serial bus simultaneously and aperiodic mixes communication system, see Fig. 4, with said method step correspondingly, this system comprises client and server end, wherein
Client comprises the first judging unit, buffer memory Buffer unit, transmitting element and detecting unit;
Server end comprises receiving element, resolution unit, error handling unit, calibration unit, the second judging unit, data updating unit and buffer memory RespBuffer unit.
In the present embodiment, client sends message by serial mode to server end, client sends message in order by the first judging unit, buffer memory Buffer unit, transmitting element and detecting unit, avoid the problem of serial line interface message collisions, server end receives by receiving element, resolution unit, error handling unit the message that client sends, guarantee the correctness of message, complete the process to dissimilar message by the second judging unit, data updating unit and buffer memory RespBuffer unit, improve the efficiency of server-side processes message.
Further, the unit in client:
First judging unit, for judging whether the message sent, if having, then keeps in message to buffer memory Buffer unit, if do not have, then message is sent to transmitting element;
Buffer memory Buffer unit, for storing the message that the first judging unit sends;
Transmitting element, for sending message;
Detecting unit, after being sent completely at the message sent, whether have message, if having, then send message, and empty buffer memory Buffer unit if detecting in buffer memory Buffer unit to keep in.
In the present embodiment, client judges whether to need the message sent to keep in by the first judging unit, during unit free to be sent, by detecting unit determination buffer memory message, transmitting element sends, when ensure that transmitting element is busy, the message that need send is ranked, and can not cause conflict and block up, and when transmitting element is idle, again can the message of dispatcher queue in time, improve transmitting efficiency.
Further, the unit in server end:
Receiving element, for receiving the transmission order and message that client sends, when receive send order time, flag bit Flag is set to 0, when message finishes receiving, flag bit Flag is set to 1;
Resolution unit, for analytic message, if message is correct, is then sent to calibration unit by message, if message is wrong, then type of error is updated to error handling unit;
Error handling unit, for recording the mistake receiving and produce in message process;
Calibration unit, for calibration message;
Second judging unit, for judging the type of sub-message, if periodically packet, is then sent to data updating unit, if command response message, is then sent to buffer memory RespBuffer unit;
Data updating unit, for the data according to periodically packet update server end;
Buffer memory RespBuffer unit, for buffer memory aperiodicity message.
Further, receiving element also comprises timing unit, when flag bit Flag is 0, starting timing, if overtime threshold value T does not receive message or message calibration mistake yet, is then time-out error, stop receiving message, and time-out error is sent to error handling unit upgrades; When Flag is 1, empty buffer memory RespBuffer unit.
Further, the second judging unit judges the type of message according to the Resp value of message, if Resp value is 0X0F, then message is periodically packet; If Resp value is not 0X0F, then message is aperiodicity message, is write buffer memory RespBuffer unit, and the flag bit bRespReced in buffer memory RespBuffer unit is set to 1.
In the present embodiment, by flag bit Flag, server end judges that whether receiving element is complete and receives message, and to guarantee the correctness of message, meanwhile, the mistake of error handling unit misregistration message and error condition, make the reception of message have trackability; In addition, server end is judged type of message by the second judging unit, and respectively different process is carried out to periodically packet and aperiodicity message by data updating unit and buffer memory RespBuffer unit, message is made to be easier to classification, treatment effeciency is higher, and special process is no longer needed to periodic data, saving resource.
Compared with prior art, the cycle and the aperiodic that the invention provides a kind of low-frequency serial bus mix communication means and system, by using buffer control client to the transmission of message, preventing serial mode from mixing when sending periodically packet and aperiodicity message and producing conflict; Control by flag bit the integrality receiving message, message is resolved, ensure correctness and the availability of message; In addition, by judging type of message, message being carried out classification process, saving the processing time, raise the efficiency, meanwhile, prevent the waste of resource.
It should be noted that; the foregoing is only preferred embodiment of the present invention; not thereby limit scope of patent protection of the present invention, the present invention can also carry out the improvement of materials and structures to the structure of above-mentioned various parts, or adopts technically equivalent ones to replace.Therefore the equivalent structure change that all utilizations specification of the present invention and diagramatic content are done, or directly or indirectly apply to other correlative technology fields and be all in like manner all contained in the scope that the present invention contains.