Changeset 52 in pacpussensors for trunk/Sick/SickLDMRSSensor.cpp
- Timestamp:
- Jun 16, 2014, 4:04:34 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Sick/SickLDMRSSensor.cpp
r42 r52 320 320 } 321 321 322 LOG_TRACE("(Packet reconstitution) Message complete ! "); 322 323 // we have a complete message available that we can add to the list 323 324 MessageLDMRS msg; 324 325 325 326 // we copy the bytes in the body message 326 char* messageData = (char*)malloc(msgSize); 327 memcpy(messageData, pendingBytes.data.c_str() + index, msgSize); 328 329 msg.body = messageData; 327 // char* messageData = (char*)malloc(msgSize); 328 // if(messageData == NULL){ 329 // LOG_FATAL("(Packet reconstitution) Malloc FAILED. Packet lost."); 330 // return; 331 // } 332 memcpy(msg.body, pendingBytes.data.c_str() + index, msgSize); 333 334 // msg->body = messageData; 330 335 331 336 // we set the timestamp of the message … … 358 363 359 364 int index = 24 + 44; // data header + scan header 360 ScanPoint* scanPoints = (ScanPoint*) malloc(sizeof(ScanPoint) * msg.hScan.numPoints); 361 int position = 0; 362 365 366 if(sizeof(ScanPoint) * msg.hScan.numPoints > BODY_MAX_SIZE){ 367 LOG_FATAL("Size of the message is too long !"); 368 return 0; 369 } 370 371 ScanPoint scanPoints[msg.hScan.numPoints]; 372 373 // replace memory with structured data 363 374 for (int i = 0; i < msg.hScan.numPoints; ++i) { 364 ((ScanPoint*)(scanPoints + position))->layerEcho = *((uchar*)(msg.body + index)); 365 ((ScanPoint*)(scanPoints + position))->flags = *((uchar*)(msg.body + index + 1)); 366 ((ScanPoint*)(scanPoints + position))->angle = *((u_int16_t*)(msg.body + index + 2)); 367 ((ScanPoint*)(scanPoints + position))->distance = *((u_int16_t*)(msg.body + index + 4)); 368 ((ScanPoint*)(scanPoints + position))->echoPulseWidth = *((u_int16_t*)(msg.body + index + 6)); 369 index += 10; 370 position += sizeof(ScanPoint); 371 } 372 373 // raw data (message) no longer needed, free memory and replace with structured data 374 free(msg.body); 375 msg.body = (char*) scanPoints; 375 scanPoints[i].layerEcho = *((uchar*)(msg.body + index)); 376 scanPoints[i].flags = *((uchar*)(msg.body + index + 1)); 377 scanPoints[i].angle = *((u_int16_t*)(msg.body + index + 2)); 378 scanPoints[i].distance = *((u_int16_t*)(msg.body + index + 4)); 379 scanPoints[i].echoPulseWidth = *((u_int16_t*)(msg.body + index + 6)); 380 } 381 382 memcpy(msg.body, scanPoints, sizeof(ScanPoint) * msg.hScan.numPoints); 376 383 } 377 384 else if (msg.hData.dataType == SICKLDMRS_OBJECTDATA_TYPE){ 378 385 LOG_TRACE("(Process Message) Object Data Type!"); 379 386 380 381 382 387 // TODO 383 384 // raw message no longer needed, free memory 385 free(msg.body); 386 // msg.body = (char*) scanObjects; 387 } 388 else // irrelevant data type 389 free(msg.body); // free raw data 388 } 389 else {// irrelevant data type 390 // TODO 391 } 392 390 393 391 394 return msg.hData.dataType; … … 405 408 // entry.timerange = msg.timerange; 406 409 410 LOG_TRACE("Writing into DBT + UTC files.."); 411 407 412 // write DBT 408 413 try { … … 421 426 dataFile_.write(reinterpret_cast<char*>(&(utcMagicWord)), sizeof(int32_t)); 422 427 428 LOG_TRACE("Writing done !"); 429 423 430 } 424 431 … … 446 453 while ( !msgList.empty() ) 447 454 { 455 LOG_TRACE("Message waiting"); 448 456 // get the first (the eldest) message and process it 449 457 MessageLDMRS msgToProcess = msgList.front(); 450 458 unsigned long type = processMessage(msgToProcess); 459 LOG_TRACE("Message processed !"); 451 460 452 461 if (type == SICKLDMRS_SCANDATA_TYPE) … … 480 489 481 490 // removes the processed item of the list 491 // free(msgList.front().body); 482 492 msgList.pop_front(); 483 493 }
Note:
See TracChangeset
for help on using the changeset viewer.