Skip to content

Commit

Permalink
Merge pull request #722 from esaulenka/fix/FirmwareUpdater
Browse files Browse the repository at this point in the history
Fix FirmwareUpdater
  • Loading branch information
collin80 authored Jan 26, 2024
2 parents b33608b + 9e1d10b commit e7fe84a
Showing 1 changed file with 40 additions and 43 deletions.
83 changes: 40 additions & 43 deletions firmwareuploaderwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,38 +133,38 @@ void FirmwareUploaderWindow::timerElapsed()

void FirmwareUploaderWindow::sendFirmwareChunk()
{
CANFrame *output = new CANFrame;
CANFrame output;
int firmwareLocation = currentSendingPosition * 4;
int xorByte = 0;
output->setExtendedFrameFormat(false);
output.setExtendedFrameFormat(false);
QByteArray bytes(7,0);
output->bus = bus;
output->setFrameId(baseAddress + 0x16);
output->payload()[0] = currentSendingPosition & 0xFF;
output->payload()[1] = (currentSendingPosition >> 8) & 0xFF;
output->payload()[2] = firmwareData[firmwareLocation++];
output->payload()[3] = firmwareData[firmwareLocation++];
output->payload()[4] = firmwareData[firmwareLocation++];
output->payload()[5] = firmwareData[firmwareLocation++];
for (int i = 0; i < 6; i++) xorByte = xorByte ^ static_cast<unsigned char>(output->payload()[i]);
output->payload()[6] = xorByte;
output->setPayload(bytes);
CANConManager::getInstance()->sendFrame(*output);
output.bus = bus;
output.setFrameId(baseAddress + 0x16);
bytes[0] = currentSendingPosition & 0xFF;
bytes[1] = (currentSendingPosition >> 8) & 0xFF;
bytes[2] = firmwareData[firmwareLocation++];
bytes[3] = firmwareData[firmwareLocation++];
bytes[4] = firmwareData[firmwareLocation++];
bytes[5] = firmwareData[firmwareLocation++];
for (int i = 0; i < 6; i++) xorByte ^= static_cast<unsigned char>(bytes[i]);
bytes[6] = xorByte;
output.setPayload(bytes);
CANConManager::getInstance()->sendFrame(output);
timer->start();
}

void FirmwareUploaderWindow::sendFirmwareEnding()
{
CANFrame *output = new CANFrame;
output->setExtendedFrameFormat(false);
output->bus = bus;
CANFrame output;
output.setExtendedFrameFormat(false);
output.bus = bus;
QByteArray bytes(4,0);
output->setFrameId(baseAddress + 0x30);
output->payload()[3] = 0xC0;
output->payload()[2] = 0xDE;
output->payload()[1] = 0xFA;
output->payload()[0] = 0xDE;
output->setPayload(bytes);
output.setFrameId(baseAddress + 0x30);
bytes[3] = (char)0xC0;
bytes[2] = (char)0xDE;
bytes[1] = (char)0xFA;
bytes[0] = (char)0xDE;
output.setPayload(bytes);
//sendCANFrame(output, bus);
}

Expand All @@ -182,23 +182,23 @@ void FirmwareUploaderWindow::handleStartStopTransfer()
qDebug() << "Base address: " + QString::number(baseAddress);
CANConManager::getInstance()->addTargettedFrame(bus, baseAddress + 0x10, 0x7FF, this);
CANConManager::getInstance()->addTargettedFrame(bus, baseAddress + 0x20, 0x7FF, this);
CANFrame *output = new CANFrame;
output->setExtendedFrameFormat(false);
CANFrame output;
output.setExtendedFrameFormat(false);
QByteArray bytes(8,0);
output->bus = bus;
output->setFrameId(baseAddress);
output->setFrameType(QCanBusFrame::DataFrame);

bytes[0] = 0xEF;
bytes[1] = 0xBE;
bytes[2] = 0xAD;
bytes[3] = 0xDE;
output.bus = bus;
output.setFrameId(baseAddress);
output.setFrameType(QCanBusFrame::DataFrame);

bytes[0] = (char)0xEF;
bytes[1] = (char)0xBE;
bytes[2] = (char)0xAD;
bytes[3] = (char)0xDE;
bytes[4] = token & 0xFF;
bytes[5] = (token >> 8) & 0xFF;
bytes[6] = (token >> 16) & 0xFF;
bytes[7] = (token >> 24) & 0xFF;
output->setPayload(bytes);
CANConManager::getInstance()->sendFrame(*output);
output.setPayload(bytes);
CANConManager::getInstance()->sendFrame(output);
}
else //stop anything in process
{
Expand All @@ -209,7 +209,6 @@ void FirmwareUploaderWindow::handleStartStopTransfer()

void FirmwareUploaderWindow::handleLoadFile()
{
QString filename;
QFileDialog dialog;

QStringList filters;
Expand All @@ -221,7 +220,7 @@ void FirmwareUploaderWindow::handleLoadFile()

if (dialog.exec() == QDialog::Accepted)
{
filename = dialog.selectedFiles()[0];
QString filename = dialog.selectedFiles().constFirst();

loadBinaryFile(filename);
}
Expand All @@ -232,22 +231,20 @@ void FirmwareUploaderWindow::loadBinaryFile(QString filename)

if (transferInProgress) handleStartStopTransfer();

QFile *inFile = new QFile(filename);
QFile inFile(filename);

if (!inFile->open(QIODevice::ReadOnly))
if (!inFile.open(QIODevice::ReadOnly))
{
delete inFile;
return;
}

firmwareData = inFile->readAll();
firmwareData = inFile.readAll();

currentSendingPosition = 0;
firmwareSize = firmwareData.length();

updateProgress();

inFile->close();
delete inFile;
inFile.close();
}

0 comments on commit e7fe84a

Please sign in to comment.