1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
From 10327a700491ba7412ce1296cb709b4d3303326f Mon Sep 17 00:00:00 2001
From: Petr Nechaev <petr.nechaev@cogentembedded.com>
Date: Wed, 29 Jul 2015 17:58:49 +0300
Subject: [PATCH 4/9] cansocketbcm: Fix reading of frames in case of RX_TIMEOUT
If bcms.hdr.nframes==0 we must not read any frames.
Also, frame size can vary with the number of messages.
---
plugins/common/cansocketbcm.cpp | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/plugins/common/cansocketbcm.cpp b/plugins/common/cansocketbcm.cpp
index d923ce3..7ee663c 100644
--- a/plugins/common/cansocketbcm.cpp
+++ b/plugins/common/cansocketbcm.cpp
@@ -145,7 +145,7 @@ int CANSocketBCM::waitData(unsigned int timeout)
/**
* BCM header with one message.
- * @note hdr.nframes must always be 0 or 1.
+ * @note As a result, hdr.nframes must always be 0 or 1.
*/
struct __attribute__ ((__packed__)) bcm_msg_one{
struct bcm_msg_head hdr;
@@ -190,7 +190,7 @@ CANSocket::CANSocketReadSuccess CANSocketBCM::readMessage(CANFrameInfo& message)
switch (bcms.hdr.opcode)
{
case RX_CHANGED:
- if (bcms.hdr.nframes >= 1 && nbytes == sizeof(bcms))
+ if (bcms.hdr.nframes >= 1 && nbytes == sizeof(bcm_msg_head) + bcms.hdr.nframes*sizeof(can_frame))
{
if (bcms.hdr.nframes > 1)
{
@@ -211,10 +211,24 @@ CANSocket::CANSocketReadSuccess CANSocketBCM::readMessage(CANFrameInfo& message)
return CANSocket::CANSocketReadSuccess::READING_FAILED;
}
case RX_TIMEOUT:
- memcpy(&message.frame, &bcms.frames[0], sizeof(bcms.frames[0]));
- message.frame.can_id = bcms.hdr.can_id; //doubtful. Do we need to override this?
- message.status = CANFrameInfo::CANMessageStatus::TIMEOUT;
- return CANSocket::CANSocketReadSuccess::READING_SUCCEEDED;
+ if (bcms.hdr.nframes >= 0 && nbytes == sizeof(bcm_msg_head) + bcms.hdr.nframes*sizeof(can_frame))
+ {
+ if (bcms.hdr.nframes > 0)
+ {
+ memcpy(&message.frame, &bcms.frames[0], sizeof(bcms.frames[0]));
+ }
+ message.frame.can_id = bcms.hdr.can_id; //doubtful. Do we need to override this?
+ message.status = CANFrameInfo::CANMessageStatus::TIMEOUT;
+ return CANSocket::CANSocketReadSuccess::READING_SUCCEEDED;
+ }
+ else
+ {
+ LOG_ERROR("Unexpected data from the socket"
+ << " " << bcms.hdr.opcode
+ << " " << bcms.hdr.nframes
+ << " " << nbytes);
+ return CANSocket::CANSocketReadSuccess::READING_FAILED;
+ }
case TX_EXPIRED:
// do nothing
--
1.9.1
|