@@ -167,9 +167,9 @@ bool transportSend(const uint8_t to, const void* data, const uint8_t len, const
167
167
uint8_t buff[8 ];
168
168
uint8_t j=0 ;
169
169
// memcpy(buff,datap[i*8+j],partlen);
170
- Serial.print (" partLen: " );
170
+ Serial.print (" send partLen: " );
171
171
Serial.println (partLen);
172
- Serial.print (" data: " );
172
+ Serial.print (" send data: " );
173
173
for (j = 0 ; j < partLen; j++) {
174
174
buff[j]=datap[i*8 +j];
175
175
Serial.print (buff[j]);
@@ -178,18 +178,19 @@ Serial.print("data: ");
178
178
179
179
180
180
Serial.println (" ." );
181
- Serial.print (" CAN len: " );
181
+
182
+ Serial.print (" send CAN len: " );
182
183
Serial.println (len);
183
- Serial.print (" CAN noOfFrames: " );
184
+ Serial.print (" send CAN noOfFrames: " );
184
185
Serial.println (noOfFrames);
185
- Serial.print (" CAN id: " );
186
+ Serial.print (" send CAN id: " );
186
187
Serial.println (canId);
187
188
byte sndStat = CAN0.sendMsgBuf (canId, partLen, buff);
188
189
if (sndStat == CAN_OK) {
189
- Serial.print (" packet sent\n " );
190
+ Serial.print (" send packet sent\n " );
190
191
return true ;
191
192
} else {
192
- Serial.print (" packet send error\n " );
193
+ Serial.print (" send packet send error\n " );
193
194
return false ;
194
195
}
195
196
}
@@ -198,26 +199,25 @@ bool transportDataAvailable(void)
198
199
{
199
200
if (!hwDigitalRead (CAN0_INT)) // If CAN0_INT pin is low, read receive buffer
200
201
{
201
- Serial.print (" Read message\n " );
202
202
CAN0.readMsgBuf (&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
203
+ Serial.print (" READ CAN id: " );
203
204
Serial.println (rxId);
204
205
long unsigned int from=(rxId & 0x000000FF );
205
- Serial.print (" from: " );
206
+ Serial.print (" READ CAN from: " );
206
207
Serial.println (from);
207
208
long unsigned int to=(rxId & 0x0000FF00 )>>8 ;
208
- Serial.print (" to: " );
209
+ Serial.print (" READ CAN to: " );
209
210
Serial.println (to);
210
211
long unsigned int currentPart=(rxId & 0x000F0000 )>>16 ;
211
- Serial.print (" currentPart: " );
212
+ Serial.print (" READ CAN currentPart: " );
212
213
Serial.println (currentPart);
213
214
long unsigned int totalPartCount=(rxId & 0x00F00000 )>>20 ;
214
- Serial.print (" totalPartCount: " );
215
+ Serial.print (" READ CAN totalPartCount: " );
215
216
Serial.println (totalPartCount);
216
217
long unsigned int messageId=(rxId & 0x07000000 )>>24 ;
217
- Serial.print (" messageId: " );
218
+ Serial.print (" READ CAN messageId: " );
218
219
Serial.println (messageId);
219
220
uint8_t slot;
220
- // TODO should start from 0;
221
221
if (currentPart==0 ){
222
222
slot=_findCanPacketSlot ();
223
223
packets[slot].locked =true ;
@@ -226,24 +226,21 @@ bool transportDataAvailable(void)
226
226
}
227
227
if (slot!=bufSize) {
228
228
memcpy (packets[slot].data + packets[slot].len , rxBuf, len);
229
- Serial.println (" packets start" );
230
- Serial.println (packets[slot].data [0 ]);
231
- Serial.println (packets[slot].data [1 ]);
232
- Serial.println (packets[slot].data [2 ]);
233
- Serial.println (packets[slot].data [3 ]);
234
- Serial.println (packets[slot].data [4 ]);
235
- Serial.println (packets[slot].data [5 ]);
236
- Serial.println (packets[slot].data [6 ]);
237
- Serial.println (" packets end" );
238
229
packets[slot].lastReceivedPart ++;
239
230
packets[slot].len += len;
240
- Serial.print (" SLOT: " );
231
+ Serial.println (" READ CAN data: " );
232
+ for (uint8_t k=0 ;k<packets[slot].len ;k++){
233
+ Serial.print (packets[slot].data [k]);
234
+ Serial.print (" , " );
235
+ }
236
+ Serial.println (" " );
237
+ Serial.print (" READ CAN SLOT: " );
241
238
Serial.println (slot);
242
- Serial.print (" lastReceivedPart: " );
239
+ Serial.print (" READ CAN lastReceivedPart: " );
243
240
Serial.println (packets[slot].lastReceivedPart );
244
241
if (packets[slot].lastReceivedPart == totalPartCount) {
245
242
packets[slot].ready = true ;
246
- Serial.print (" packet received\n " );
243
+ Serial.print (" READ CAN packet received\n " );
247
244
return true ;
248
245
}
249
246
}
0 commit comments