Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

remove magic number (CAN data position) and fix fault in process_rece…

…ived_data function
  • Loading branch information...
commit bce2a5cf2ca6d957d255afba6127aa9418ffbf22 1 parent cb5835e
Hartmut Behrens authored January 16, 2013
2  c2e_can.c
@@ -40,7 +40,7 @@ static void write_to_ringbuf(tCANMsgObject *can_object, uint32_t id)
40 40
     unsigned char frame[CAN_FRAME_SIZE];
41 41
     uint32_to_uchar(&frame[0], can_object->ulMsgID);                                  // convert ID to char so that it is suitable to sending over UDP
42 42
 
43  
-    memcpy(&frame[4], &(can_object->pucMsgData[id*8]), 8 );                         // copy CAN data into frame
  43
+    memcpy(&frame[CAN_DATA_POS], &(can_object->pucMsgData[id*8]), 8 );                         // copy CAN data into frame
44 44
     frame[EXT_FLAG_POS] = (can_object->ulFlags & MSG_OBJ_EXTENDED_ID) ? 1 : 0;        // flag to indicate whether CAN message is using extended ID's
45 45
     frame[RTR_FLAG_POS] = (can_object->ulFlags & MSG_OBJ_REMOTE_FRAME) ? 1 : 0;       // flag to indicate whether CAN frame transmission was requested by remote node
46 46
     RingBufWrite(&g_can_ringbuf, &frame[0], CAN_FRAME_SIZE);
8  c2e_udp.c
@@ -132,18 +132,16 @@ void UDP_send_msg(unsigned char *message, uint32_t size, struct ip_addr *ip_addr
132 132
     udp_remove(pcb);
133 133
 }
134 134
 
135  
-static void process_CAN_data(unsigned char *data, uint32_t size)
  135
+static void process_received_data(unsigned char *data, uint32_t size)
136 136
 {
137 137
     uint32_t position = 0;
138 138
     while (position < size)                                         // more than one CAN frame might be embedded
139 139
     {
140  
-        unsigned char CAN_data[8];
141 140
         uint32_t CAN_id = uchar_to_uint32(&data[CAN_ID_POS]);
142  
-        memcpy(&CAN_data,&data[0],8);
143 141
         uint32_t ext_id_flag = data[EXT_FLAG_POS];                  // CAN extended ID flag
144 142
         uint32_t remote_tx_flag = data[RTR_FLAG_POS];
145 143
         position += CAN_FRAME_SIZE;
146  
-        CAN_transmit(&CAN_data[0], 8, CAN_id, ext_id_flag, remote_tx_flag);
  144
+        CAN_transmit(&data[CAN_DATA_POS], 8, CAN_id, ext_id_flag, remote_tx_flag);
147 145
         udp_rx_count += 1;
148 146
         update_count += 1;
149 147
     }
@@ -168,7 +166,7 @@ void UDP_receive(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr
168 166
     if ( message_starts_with(data, C2E_DATA_ID) )           // received a message with CAN data, so send it out on the CAN i/f
169 167
     {
170 168
         uint32_t id_size = sizeof(C2E_DATA_ID);
171  
-        process_CAN_data(&data[id_size], (p->len - id_size) );
  169
+        process_received_data(&data[id_size], (p->len - id_size) );
172 170
     }
173 171
     if ( message_starts_with(data, C2E_BROADCAST_ID) )      // found a gateway, so add the IP address to the list of known gateways
174 172
     {
3  config.h
@@ -23,7 +23,8 @@ typedef struct
23 23
 #define CAN_FIFO_SIZE   (8 * 8)             // size of FIFO buffers allocated to the CAN controller - 8 messages can each hold a max of 8 bytes
24 24
 #define CAN_BITRATE 1000000                 // set CAN bitrate to 1Mbps
25 25
 #define MAX_CAN_GATEWAYS 4 					// number of CAN gateways to keep track of
26  
-#define CAN_ID_POS 0 						// position of CAN message ID  in CAN frame
  26
+#define CAN_ID_POS 0 						// position of CAN message ID in CAN frame
  27
+#define CAN_DATA_POS 4 						// position of CAN data in CAN frame
27 28
 #define EXT_FLAG_POS 12                     // position of CAN extended ID flag in CAN frame
28 29
 #define RTR_FLAG_POS 13                     // position of CAN remote transmission flag in CAN frame
29 30
 #define TRIGGER_THRESHOLD 1                 // number of received CAN frames required to trigger a UDP send

0 notes on commit bce2a5c

Please sign in to comment.
Something went wrong with that request. Please try again.