Summary of the invention
In order to solve above-mentioned technical problem, it is an object of the invention to provide a kind of enhancement mode CAN data re-transmitting method and device, it can reduce the resources occupation rate of bus, promotes bus capacity and reduces the congestion level that data send, to the abnormal detection of bus much sooner.
The technical solution adopted in the present invention is a kind of enhancement mode CAN data re-transmitting method on the one hand, comprises the following steps:
S1, judging whether data send successfully, if sending successfully, then continuing to judge whether data send successfully, otherwise perform step S2 to carry out retransmitting judgement;
S2, according to data send failed reason carry out retransmit judgement and make different process.
Further, described step S2 includes:
S21, determine whether significant data, if being significant data, then performing step S22, otherwise performing step S1;
S22, judge that data send whether failed reason is ACK mistake, if it is, the number of statistics ACK mistake number according to ACK mistake make respective handling, otherwise execution step S23;
S23, judge that data send whether failed reason is arbitrate failure or error in data, if it is, add up sending times and carry out data re-transmitting; Otherwise, step S24 is performed;
S24, carry out different abnormality processing.
Further, in described step S23 add up sending times and carry out data retransmit include:
S231, statistics sending times;
S232, judge that sending times is whether more than retransmitting higher limit, if sending times is more than retransmitting higher limit, then performs step S24, otherwise performs step S233;
S233, retransmission data.
Further, described step S22 adds up the number of ACK mistake and makes respective handling according to the number of ACK mistake and include:
S221, statistics ACK mistake number;
S222, judge that the number of ACK mistake is whether more than the higher limit of ACK mistake, if the number of ACK mistake is more than the higher limit of ACK mistake, then performs step S24, otherwise performs step S1.
Further, described step S24 includes:
S241, determine whether the number higher limit more than ACK mistake of ACK mistake, if it is, alarm output: ACK mistake, from equipment nonreply, otherwise perform step S242;
S242, determine whether sending times more than retransmit higher limit, if it is, alarm output: bus error, bus busy, otherwise perform step S243;
S243, alarm output: unknown communication mistake.
Technical scheme is a kind of enhancement mode CAN data re-transmitting device on the other hand, including:
First module, is used for judging whether data send successfully, if data send successfully, then continues to judge whether data send successfully, otherwise carries out retransmitting judgement;
Second module, carries out retransmitting judgement and making different process for sending failed reason according to data.
Further, described send failed reason according to data and carry out retransmitting judgement and making different process and specifically include:
First, it is determined that whether be significant data, if being significant data, then proceed data and send failure cause judgement, otherwise return and judge whether data send successfully;
Next, it is determined that data send whether failed reason is ACK mistake, if it is, the number of statistics ACK mistake the number according to ACK mistake make respective handling, otherwise proceed data and send failure cause judgement;
Finally, it is judged that data send whether failed reason is arbitration failure or error in data, if it is, add up sending times and carry out data re-transmitting; Otherwise, different abnormality processing is carried out.
Further, described statistics sending times and carry out data re-transmitting particularly as follows:
First, statistics sending times;
Next, it is determined that whether sending times is more than retransmitting higher limit, if sending times is more than retransmitting higher limit, then carry out different abnormality processing, otherwise retransmission data.
Further, the number of described statistics ACK mistake number according to ACK mistake make respective handling particularly as follows:
First, the number of ACK mistake is added up;
Next, it is determined that whether the number of ACK mistake is more than the higher limit of ACK mistake, if the number of ACK mistake is more than the higher limit of ACK mistake, then carries out different abnormality processing, otherwise judge whether data send successfully.
Further, carry out different abnormality processing described in particularly as follows:
Determine whether the number higher limit more than ACK mistake of ACK mistake, if, alarm output: ACK mistake, from equipment nonreply, otherwise determine whether sending times more than retransmitting higher limit, if it is, alarm output: bus error, bus busy, otherwise alerts output: unknown communication mistake.
The invention has the beneficial effects as follows: the enhancement mode CAN data re-transmitting method of the present invention, judge by different pieces of information is sent failed reason, then different disposal is made, reduce the resources occupation rate of bus, improve bus capacity and reduce the congestion level that data send, to the abnormal detection of bus much sooner.
Another of the present invention provides the benefit that: the enhancement mode CAN data re-transmitting device of the present invention can be effectively improved the resource utilization of CAN, reduces the congestion level that data send.
Detailed description of the invention
It should be noted that when not conflicting, the embodiment in the application and the feature in embodiment can be mutually combined.
A kind of enhancement mode CAN data re-transmitting method, with reference to Fig. 1, comprises the following steps:
S1, judging whether data send successfully, if sending successfully, then continuing to judge whether data send successfully, otherwise perform step S2 to carry out retransmitting judgement;
S2, according to data send failed reason carry out retransmit judgement and make different process.
Being further used as preferred embodiment, with reference to Fig. 2, described step S2 includes:
S21, determine whether significant data, if being significant data, then performing step S22, otherwise performing step S1;
S22, judge that data send whether failed reason is ACK mistake, if it is, the number of statistics ACK mistake number according to ACK mistake make respective handling, otherwise execution step S23;
S23, judge that data send whether failed reason is arbitrate failure or error in data, if it is, add up sending times and carry out data re-transmitting; Otherwise, step S24 is performed;
S24, carry out different abnormality processing.
It is further used as preferred embodiment, described step S22 adds up the number of ACK mistake and makes respective handling according to the number of ACK mistake and include:
S221, statistics ACK mistake number;
S222, judge that the number of ACK mistake is whether more than the higher limit of ACK mistake, if the number of ACK mistake is more than the higher limit of ACK mistake, then performs step S24, otherwise performs step S1.
Be further used as preferred embodiment, in described step S23 add up sending times and carry out data retransmit include:
S231, statistics sending times;
S232, judge that sending times is whether more than retransmitting higher limit, if sending times is more than retransmitting higher limit, then performs step S24, otherwise performs step S233;
S233, retransmission data.
Being further used as preferred embodiment, described step S24 includes:
S241, determine whether the number higher limit more than ACK mistake of ACK mistake, if it is, alarm output: ACK mistake, from equipment nonreply, otherwise perform step S242;
S242, determine whether sending times more than retransmit higher limit, if it is, alarm output: bus error, bus busy, otherwise perform step S243;
S243, alarm output: unknown communication mistake.
When utilizing CAN to carry out data transmission unsuccessfully, first determine whether whether the data transmitted are significant data, if not significant data, then return and judge whether data send successfully; Otherwise, continue to determine whether.
Then, judge that significant data sends failed reason, if it is ACK mistake that significant data sends failed reason, then it represents that data send successfully, receiving terminal does not receive, or transmitting terminal is not set up with receiving terminal and is connected, and can retransmit, can directly judge reception failure, the number of statistics ACK mistake, when the number of ACK mistake is more than default ACK upper error limit value, carry out alarm output: ACK mistake, from equipment nonreply; If significant data sends failed reason for arbitration failure or error in data, it is arbitrate unsuccessfully that significant data sends failed reason, represents that data do not send, and failure is unrelated with receiving terminal; It is error in data that significant data sends failed reason, then it represents that data occur abnormal in transmission process. Now, first add up the number of times of repeating transmission, then carry out data re-transmitting judgement. If the number of times retransmitted is more than default repeating transmission higher limit, then it represents that after carrying out repeatedly repeating transmission, still can not being normally sent completely, communication line fault or CAN are very busy, then alert output: bus error, bus busy. If significant data sends failed reason and is in addition to other reason beyond above-mentioned reason, then alert output: unknown communication mistake.
Flow chart with reference to the specific embodiment that Fig. 3, Fig. 3 are a kind of enhancement mode CAN data re-transmitting method. First, CAN is initialized; Deng pending data, then continue waiting for without data, until when having data to need to send, data to be sent being sent into transmission mailbox and is transmitted; Obtain and send mark, the information such as described mark comprises transmission result, type of error; According to the mark obtained, it may be judged whether sending successfully, if sending successfully, then continuing waiting for the data that the next one to send, otherwise carry out fault processing, namely carry out retransmitting judgement; Judge not send whether successful data are significant data, if not significant data, then do not process, return to waiting for data, otherwise retransmit judgement further; Judge that data send whether failed reason is ACK mistake, if being ACK mistake, then carry out errors number record, when the errors number of ACK is more than 3 times, judge from equipment fault or communication line fault, then alert output: ACK mistake, from equipment nonreply, otherwise judge that data send whether failed reason is arbitration mistake or error in data, if arbitration failure or error in data, then retransmit and add up sending times, when sending times is more than 3 times, alarm output: bus error, bus busy; If not arbitration failure or error in data, then alert output: unknown communication mistake.
A kind of enhancement mode CAN data re-transmitting device, including:
First module, is used for judging whether data send successfully, if data send successfully, then continues to judge whether data send successfully, otherwise carries out retransmitting judgement;
Second module, carries out retransmitting judgement and making different process for sending failed reason according to data.
It is further used as preferred embodiment, described send failed reason according to data and carry out retransmitting judgement and making different process and specifically include:
First, it is determined that whether be significant data, if being significant data, then proceed data and send failure cause judgement, otherwise return and judge whether data send successfully;
Next, it is determined that data send whether failed reason is ACK mistake, if it is, the number of statistics ACK mistake the number according to ACK mistake make respective handling, otherwise proceed data and send failure cause judgement;
Finally, it is judged that data send whether failed reason is arbitration failure or error in data, if it is, add up sending times and carry out data re-transmitting; Otherwise, different abnormality processing is carried out.
Be further used as preferred embodiment, the number of described statistics ACK mistake number according to ACK mistake make respective handling particularly as follows:
First, the number of ACK mistake is added up;
Next, it is determined that whether the number of ACK mistake is more than the higher limit of ACK mistake, if the number of ACK mistake is more than the higher limit of ACK mistake, then carries out different abnormality processing, otherwise judge whether data send successfully.
Be further used as preferred embodiment, described statistics sending times and carry out data re-transmitting particularly as follows:
First, statistics sending times;
Next, it is determined that whether sending times is more than retransmitting higher limit, if sending times is more than retransmitting higher limit, then carry out different abnormality processing, otherwise retransmission data.
Be further used as preferred embodiment, described in carry out different abnormality processing particularly as follows:
Determine whether the number higher limit more than ACK mistake of ACK mistake, if, alarm output: ACK mistake, from equipment nonreply, otherwise determine whether sending times more than retransmitting higher limit, if it is, alarm output: bus error, bus busy, otherwise alerts output: unknown communication mistake.
Described enhancement mode CAN data re-transmitting device can be effectively improved the resource utilization of CAN, reduces the congestion level that data send.
It is above the preferably enforcement of the present invention has been illustrated, but the invention is not limited to described embodiment, those of ordinary skill in the art also can make all equivalent variations or replacement under the premise without prejudice to spirit of the present invention, and these equivalent deformation or replacement are all contained in the application claim limited range.