Summary of the invention
In order to solve the above-mentioned technical problem, the object of the present invention is to provide a kind of enhanced CAN bus data re-transmitting methods
And device, the resources occupation rate of bus can be reduced, bus capacity is promoted and reduces the congestion level that data are sent, to total
The detection of line exception is much sooner.
On the one hand the technical solution adopted in the present invention is a kind of enhanced CAN bus data re-transmitting method, including following
Step:
S1, judge whether data send success, if sent successfully, continue to judge whether data send success, otherwise
Step S2 is executed to carry out repeating transmission judgement;
S2, it carries out retransmitting judgement according to the reason of data transmission failure and makes different processing.
Further, the step S2 includes:
S21, judge whether it is significant data, if it is significant data, then follow the steps S22, it is no to then follow the steps S1;
S22, judge whether the reason of data send failure is ACK mistake, if it is, the number of statistics ACK mistake is simultaneously
Respective handling is made according to the number of ACK mistake, it is no to then follow the steps S23;
S23, judge whether the reason of data send failure is arbitration failure or error in data, if it is, statistics weight
Hair number simultaneously carries out data re-transmitting;Otherwise, step S24 is executed;
S24, different abnormality processings is carried out.
Further, sending times are counted in the step S23 and carry out data repeating transmission includes:
S231, statistics sending times;
S232, judge whether sending times are greater than repeating transmission upper limit value, if sending times, which are greater than, retransmits upper limit value, execute
Step S24, it is no to then follow the steps S233;
S233, retransmission data.
Further, the number of ACK mistake is counted in the step S22 and corresponding position is made according to the number of ACK mistake
Reason includes:
S221, the number for counting ACK mistake;
S222, judge whether the number of ACK mistake is greater than the upper limit value of ACK mistake, if the number of ACK mistake is greater than
The upper limit value of ACK mistake thens follow the steps S24, no to then follow the steps S1.
Further, the step S24 includes:
S241, the number for judging whether it is ACK mistake are greater than the upper limit value of ACK mistake, if so, alarm output: ACK is wrong
Accidentally, unresponsive from equipment, it is no to then follow the steps S242;
S242, sending times are judged whether it is greater than upper limit value is retransmitted, if it is, alarm output: bus error, bus
It is busy, it is no to then follow the steps S243;
S243, alarm output: unknown communication mistake.
On the other hand technical solution of the present invention is a kind of enhanced CAN bus data re-transmitting device, comprising:
First module, if data are sent successfully, continues whether to judge data for judging whether data send success
It sends successfully, otherwise carries out repeating transmission judgement;
Second module, for carrying out retransmitting judgement according to the reason of data transmission failure and making different processing.
Further, described the reason of sending failure according to data, retransmit judgement and make different processing specifically wrapping
It includes:
First, it is determined that whether being significant data, if it is significant data, continues data transmission failure cause and sentence
It is disconnected, it otherwise returns and judges whether data send success;
Next, it is determined that data send whether the reason of failure is ACK mistake, if it is, the number of statistics ACK mistake is simultaneously
Respective handling is made according to the number of ACK mistake, otherwise continues data and sends failure cause judgement;
Finally, judging whether the reason of data send failure is arbitration failure or error in data, if it is, statistics weight
Hair number simultaneously carries out data re-transmitting;Otherwise, different abnormality processings is carried out.
Further, the statistics sending times and data re-transmitting is carried out specifically:
Firstly, statistics sending times;
Next, it is determined that whether sending times are greater than repeating transmission upper limit value, if sending times, which are greater than, retransmits upper limit value, carry out
Different abnormality processings, otherwise retransmission data.
Further, it is described statistics ACK mistake number and respective handling is made according to the number of ACK mistake specifically:
Firstly, the number of statistics ACK mistake;
Next, it is determined that whether the number of ACK mistake is greater than the upper limit value of ACK mistake, if the number of ACK mistake is greater than
The upper limit value of ACK mistake, then carry out different abnormality processings, otherwise judges whether data send success.
It is further, described to carry out different abnormality processings specifically:
The number for judging whether it is ACK mistake is greater than the upper limit value of ACK mistake, if so, alarm output: ACK mistake, from
Equipment is unresponsive, otherwise judges whether it is sending times and is greater than repeating transmission upper limit value, if it is, alarm output: bus error, always
Line is busy, otherwise alarm output: unknown communication mistake.
The beneficial effects of the present invention are: enhanced CAN bus data re-transmitting method of the invention, by sending out different data
The reason of sending unsuccessfully is judged, different disposal is then made, and reduces the resources occupation rate of bus, improve bus capacity with
And reduce the congestion level that data are sent, much sooner to the detection of bus exception.
Another beneficial effect of the present invention is: enhanced CAN bus data re-transmitting device of the invention can be mentioned effectively
The resource utilization of high CAN bus reduces the congestion level that data are sent.
Specific embodiment
It should be noted that in the absence of conflict, the features in the embodiments and the embodiments of the present application can phase
Mutually combination.
A kind of enhanced CAN bus data re-transmitting method, with reference to Fig. 1, comprising the following steps:
S1, judge whether data send success, if sent successfully, continue to judge whether data send success, otherwise
Step S2 is executed to carry out repeating transmission judgement;
S2, it carries out retransmitting judgement according to the reason of data transmission failure and makes different processing.
It is further used as preferred embodiment, with reference to Fig. 2, the step S2 includes:
S21, judge whether it is significant data, if it is significant data, then follow the steps S22, it is no to then follow the steps S1;
S22, judge whether the reason of data send failure is ACK mistake, if it is, the number of statistics ACK mistake is simultaneously
Respective handling is made according to the number of ACK mistake, it is no to then follow the steps S23;
S23, judge whether the reason of data send failure is arbitration failure or error in data, if it is, statistics weight
Hair number simultaneously carries out data re-transmitting;Otherwise, step S24 is executed;
S24, different abnormality processings is carried out.
It is further used as preferred embodiment, the number of ACK mistake is counted in the step S22 and according to ACK mistake
Number make respective handling and include:
S221, the number for counting ACK mistake;
S222, judge whether the number of ACK mistake is greater than the upper limit value of ACK mistake, if the number of ACK mistake is greater than
The upper limit value of ACK mistake thens follow the steps S24, no to then follow the steps S1.
It is further used as preferred embodiment, sending times are counted in the step S23 and carry out data repeating transmission includes:
S231, statistics sending times;
S232, judge whether sending times are greater than repeating transmission upper limit value, if sending times, which are greater than, retransmits upper limit value, execute
Step S24, it is no to then follow the steps S233;
S233, retransmission data.
It is further used as preferred embodiment, the step S24 includes:
S241, the number for judging whether it is ACK mistake are greater than the upper limit value of ACK mistake, if so, alarm output: ACK is wrong
Accidentally, unresponsive from equipment, it is no to then follow the steps S242;
S242, sending times are judged whether it is greater than upper limit value is retransmitted, if it is, alarm output: bus error, bus
It is busy, it is no to then follow the steps S243;
S243, alarm output: unknown communication mistake.
When carrying out data transmission unsuccessfully using CAN bus, first determine whether transmitted data are significant data, such as
Fruit is not significant data, then returns and judge whether data send success;Otherwise, continue to do further judgement.
Next, it is determined that significant data sends the reason of failure, if significant data is ACK mistake the reason of sending failure,
Then indicate that data are sent successfully, receiving end does not receive or transmitting terminal does not establish connection with receiving end, can not have to retransmit, can be straight
Judgement reception failure is connect, the number of ACK mistake is counted, when the number of ACK mistake is greater than preset ACK upper error limit value, into
Row alarm output: ACK mistake, it is unresponsive from equipment;If significant data sends the reason of failure as arbitration failure or data
The reason of mistake, significant data sends failure is arbitration failure, indicates that data are not sent, failure is unrelated with receiving end;Important number
It is error in data according to the reason of sending failure, then it represents that data occur abnormal in transmission process.At this point, time that first statistics is retransmitted
Number, then carry out data re-transmitting judgement.If the number retransmitted is greater than preset repeating transmission upper limit value, then it represents that repeatedly retransmitted
Afterwards, it still cannot normally be sent completely, communication line failure or CAN bus are very busy, then alarm output: bus error, always
Line is busy.If significant data send failure the reason of be other than above-mentioned reason other the reason of, alarm output: unknown
Communication mistake.
With reference to Fig. 3, Fig. 3 is a kind of flow chart of a specific embodiment of enhanced CAN bus data re-transmitting method.It is first
First, CAN is initialized;Equal pending datas, continue waiting for if without data, will be to be sent when having data to need to send
Data are sent into transmission mailbox and are sent;It obtains and sends mark, the mark is comprising sending as a result, the information such as type of error;Root
According to the mark of acquisition, judge whether to send successfully, successfully continues waiting for next data to be sent if sent, otherwise
Error handle is carried out, that is, carries out repeating transmission judgement;Judge whether not sent successful data are significant data, if not important number
According to, then be not processed, return to waiting for data, otherwise carry out further retransmit judgement;Whether judge the reason of data send failure
Errors number record is carried out if it is ACK mistake for ACK mistake, when the errors number of ACK is more than 3 times, is judged from setting
Standby failure or communication line failure, then alarm output: ACK mistake, it is unresponsive from equipment, otherwise judge that data are sent and fails
Whether reason is to arbitrate mistake or error in data, if it is arbitration failure or error in data, then retransmits and count sending times, when
When sending times are more than 3 times, alarm output: bus error, bus busy;If not arbitration failure or error in data, then accuse
Alert output: unknown communication mistake.
A kind of enhanced CAN bus data re-transmitting device, comprising:
First module, if data are sent successfully, continues whether to judge data for judging whether data send success
It sends successfully, otherwise carries out repeating transmission judgement;
Second module, for carrying out retransmitting judgement according to the reason of data transmission failure and making different processing.
It is further used as preferred embodiment, described the reason of sending failure according to data carries out retransmitting judgement and make
Different processing specifically include:
First, it is determined that whether being significant data, if it is significant data, continues data transmission failure cause and sentence
It is disconnected, it otherwise returns and judges whether data send success;
Next, it is determined that data send whether the reason of failure is ACK mistake, if it is, the number of statistics ACK mistake is simultaneously
Respective handling is made according to the number of ACK mistake, otherwise continues data and sends failure cause judgement;
Finally, judging whether the reason of data send failure is arbitration failure or error in data, if it is, statistics weight
Hair number simultaneously carries out data re-transmitting;Otherwise, different abnormality processings is carried out.
It is further used as preferred embodiment, the number of the statistics ACK mistake is simultaneously made according to the number of ACK mistake
Respective handling specifically:
Firstly, the number of statistics ACK mistake;
Next, it is determined that whether the number of ACK mistake is greater than the upper limit value of ACK mistake, if the number of ACK mistake is greater than
The upper limit value of ACK mistake, then carry out different abnormality processings, otherwise judges whether data send success.
It is further used as preferred embodiment, the statistics sending times simultaneously carry out data re-transmitting specifically:
Firstly, statistics sending times;
Next, it is determined that whether sending times are greater than repeating transmission upper limit value, if sending times, which are greater than, retransmits upper limit value, carry out
Different abnormality processings, otherwise retransmission data.
It is further used as preferred embodiment, it is described to carry out different abnormality processings specifically:
The number for judging whether it is ACK mistake is greater than the upper limit value of ACK mistake, if so, alarm output: ACK mistake, from
Equipment is unresponsive, otherwise judges whether it is sending times and is greater than repeating transmission upper limit value, if it is, alarm output: bus error, always
Line is busy, otherwise alarm output: unknown communication mistake.
The enhanced CAN bus data re-transmitting device can effectively improve the resource utilization of CAN bus, reduce number
According to the congestion level of transmission.
It is to be illustrated to preferable implementation of the invention, but the invention is not limited to the implementation above
Example, those skilled in the art can also make various equivalent variations on the premise of without prejudice to spirit of the invention or replace
It changes, these equivalent deformations or replacement are all included in the scope defined by the claims of the present application.