log file from microchip tool tokens: 0 = timestamp 1 = Transmission direction 2 = ID 3 = Data byte length 4-x = The data bytes */
| 2447 | 4-x = The data bytes |
| 2448 | */ |
| 2449 | bool FrameFileIO::loadMicrochipFile(QString filename, QVector<CANFrame>* frames) |
| 2450 | { |
| 2451 | QFile *inFile = new QFile(filename); |
| 2452 | CANFrame thisFrame; |
| 2453 | QByteArray line; |
| 2454 | bool inComment = false; |
| 2455 | long long timeStamp; |
| 2456 | int lineCounter = 0; |
| 2457 | bool foundErrors = false; |
| 2458 | thisFrame.remote = false; |
| 2459 | |
| 2460 | if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text)) |
| 2461 | { |
| 2462 | delete inFile; |
| 2463 | return false; |
| 2464 | } |
| 2465 | |
| 2466 | //line = inFile->readLine(); //read out the header first and discard it. |
| 2467 | |
| 2468 | while (!inFile->atEnd()) { |
| 2469 | lineCounter++; |
| 2470 | if (lineCounter > 100) |
| 2471 | { |
| 2472 | qApp->processEvents(); |
| 2473 | lineCounter = 0; |
| 2474 | } |
| 2475 | |
| 2476 | line = inFile->readLine(); |
| 2477 | if (line.length() > 2) |
| 2478 | { |
| 2479 | if (line.startsWith("//")) |
| 2480 | { |
| 2481 | inComment = !inComment; |
| 2482 | } |
| 2483 | else |
| 2484 | { |
| 2485 | if (!inComment) |
| 2486 | { |
| 2487 | QList<QByteArray> tokens = line.split(';'); |
| 2488 | if (tokens.length() >= 4) |
| 2489 | { |
| 2490 | timeStamp = tokens[0].toInt() * 1000; |
| 2491 | thisFrame.timestamp = timeStamp; |
| 2492 | if (tokens[1].at(0) == 'R') thisFrame.isReceived = true; |
| 2493 | else thisFrame.isReceived = false; |
| 2494 | thisFrame.remote = false; |
| 2495 | thisFrame.ID = Utility::ParseStringToNum(tokens[2]); |
| 2496 | if (thisFrame.ID <= 0x7FF) thisFrame.extended = false; |
| 2497 | else thisFrame.extended = true; |
| 2498 | thisFrame.bus = 0; |
| 2499 | thisFrame.len = tokens[3].toUInt(); |
| 2500 | if (thisFrame.len > 8) thisFrame.len = 8; |
| 2501 | if (thisFrame.len + 4 > (unsigned int) tokens.length()) thisFrame.len = tokens.length() - 4; |
| 2502 | for (unsigned int d = 0; d < thisFrame.len; d++) thisFrame.data[d] = (unsigned char)Utility::ParseStringToNum(tokens[4 + d]); |
| 2503 | frames->append(thisFrame); |
| 2504 | } |
| 2505 | else foundErrors = true; |
| 2506 | } |