Compare commits

...

3 Commits

3 changed files with 68 additions and 50 deletions

View File

@ -303,7 +303,18 @@ struct SharedMem
// download of device controller and json files // download of device controller and json files
struct DCDownload { struct DCDownload {
char m_filename[512]; enum class FILE_INDEX {
DC_BINARY = 0, DC2C_CASH = 1, DC2C_CONF = 2, DC2C_SERIAL=3,
DC2C_PRINT_01, DC2C_PRINT_02, DC2C_PRINT_03, DC2C_PRINT_04,
DC2C_PRINT_05, DC2C_PRINT_06, DC2C_PRINT_07, DC2C_PRINT_08,
DC2C_PRINT_09, DC2C_PRINT_10, DC2C_PRINT_11, DC2C_PRINT_12,
DC2C_PRINT_13, DC2C_PRINT_14, DC2C_PRINT_15, DC2C_PRINT_16,
DC2C_PRINT_17, DC2C_PRINT_18, DC2C_PRINT_19, DC2C_PRINT_20,
DC2C_PRINT_21, DC2C_PRINT_22, DC2C_PRINT_23, DC2C_PRINT_24,
DC2C_PRINT_25, DC2C_PRINT_26, DC2C_PRINT_27, DC2C_PRINT_28,
DC2C_PRINT_29, DC2C_PRINT_30, DC2C_PRINT_31, DC2C_PRINT_32
};
char m_filename[(int)FILE_INDEX::DC2C_PRINT_32][512];
std::atomic_ushort m_totalBlocks; std::atomic_ushort m_totalBlocks;
std::atomic_ushort m_currentblockNumber; std::atomic_ushort m_currentblockNumber;
std::atomic_bool m_requested{false}; std::atomic_bool m_requested{false};

View File

@ -99,57 +99,63 @@ DownloadThread::~DownloadThread() {
// bootloader is really not running anymore. // bootloader is really not running anymore.
*/ */
void DownloadThread::run() { void DownloadThread::run() {
// download thread running in ca-master sends the dc-file down to firmware // download thread running in ca-master sends the dc-file down to firmware
#if 0 // TODO: send the json files as well
Update::DownloadResult Update::dc_downloadBinary(QByteArray const &b) const {
int const nBlocks = (((b.size())%64)==0) ? (b.size()/64) : (b.size()/64)+1;
// fill lst block of data to be sent with 0xFF
QByteArray ba = b.leftJustified(nBlocks*64, (char)(0xFF));
qInfo() << "total number of bytes to send to dc" << ba.size();
qInfo() << "total number of blocks to send to dc" << nBlocks;
int bNum = 0;
DownloadResult res = DownloadResult::OK;
fprintf(stderr, "\n64-byte block %04d ", bNum);
while (res != DownloadResult::ERROR && bNum < nBlocks) {
if ((res = sendNextAddress(bNum)) != DownloadResult::ERROR) {
if ((res = sendNextDataBlock(ba, bNum)) != DownloadResult::ERROR) {
bNum += 1;
fprintf(stderr, ".");
if ((bNum % 80) == 0) {
fprintf(stderr, "\n64-byte block %04d ", bNum);
}
}
}
}
fprintf(stderr, "\nlast 64-byte block %04d\n", bNum);
int const rest = ba.size() % 64;
int const offset = ba.size() - rest;
char const *startAddress = ba.constData() + offset;
if (rest > 0) {
// SHOULD NEVER HAPPEN !!!
uint8_t local[66];
memset(local, 0xFF, sizeof(local));
memcpy(local, startAddress, rest);
qCritical() << "ERROR SEND REMAINING" << rest << "BYTES";
m_hw->bl_sendDataBlock(64, local);
}
m_hw->bl_sendLastBlock();
qInfo() << "last result" << (int)sendStatus(m_hw->bl_wasSendingDataOK());
return res;
}
#endif
m_hw->dcDownloadRequestAck(); m_hw->dcDownloadRequestAck();
qCritical() << QDateTime::currentDateTime().toString(Qt::ISODate) + "DOWNLOAD THREAD STARTED"; qCritical() << "DownloadThread::run(): DOWNLOAD THREAD STARTED";
// load binary device controller file into memory
QByteArray ba = loadBinaryDCFile(m_hw->dcDownloadFileName());
if (ba.size() > 0) {
uint16_t const totalBlocks = (((ba.size())%64)==0) ? (ba.size()/64) : (ba.size()/64)+1;
m_hw->dcDownloadSetTotalBlockNumber(totalBlocks);
// fill last block of data to be sent with 0xFF
ba = ba.leftJustified(totalBlocks*64, (char)(0xFF));
resetDeviceController();
if (startBootloader()) {
qCritical() << "DownloadThread::run(): TOTAL NUMBER OF BYTES TO SEND TO DC" << ba.size();
qCritical() << "DownloadThread::run(): TOTAL NUMBER OF BLOCKS" << totalBlocks;
int currentBlock = 0;
DownloadResult res = DownloadResult::OK;
qCritical() << "64-byte block " << currentBlock;
while (res != DownloadResult::ERROR && currentBlock < totalBlocks) {
if ((res = sendNextAddress(currentBlock)) != DownloadResult::ERROR) {
if ((res = sendNextDataBlock(ba, currentBlock)) != DownloadResult::ERROR) {
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
currentBlock += 1;
}
}
}
qCritical() << "DownloadThread::run(): last 64-byte block %04d" << currentBlock;
int const rest = ba.size() % 64;
int const offset = ba.size() - rest;
char const *startAddress = ba.constData() + offset;
if (rest > 0) {
// SHOULD NEVER HAPPEN !!!
uint8_t local[66];
memset(local, 0xFF, sizeof(local));
memcpy(local, startAddress, rest);
qCritical() << "DownloadThread::run(): ERROR SEND REMAINING" << rest << "BYTES";
m_hw->bl_sendDataBlock(64, local);
} else {
m_hw->bl_sendLastBlock();
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
}
qCritical() << "DownloadThread::run(): last result" << (int)sendStatus(m_hw->bl_wasSendingDataOK());
}
stopBootloader(); // there is no harm in stopping the bootloader even
} // if it was not started at all
#if 0
// test code: // test code:
uint16_t const totalBlocks = 100; uint16_t const totalBlocks = 100;
m_hw->dcDownloadSetTotalBlockNumber(totalBlocks); m_hw->dcDownloadSetTotalBlockNumber(totalBlocks);
@ -158,6 +164,7 @@ void DownloadThread::run() {
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock); m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
QThread::msleep(100); QThread::msleep(100);
} }
#endif
m_hw->dcDownloadSetRunning(false); m_hw->dcDownloadSetRunning(false);
m_hw->dcDownloadSetFinished(true); m_hw->dcDownloadSetFinished(true);

View File

@ -4387,7 +4387,7 @@ bool hwapi::dcDownloadRequest(QString const &dcFileToDownload) const {
return false; return false;
} }
char *fNameBuffer = data->m_downLoadDC.m_filename; char *fNameBuffer = data->m_downLoadDC.m_filename[(int)SharedMem::DCDownload::FILE_INDEX::DC_BINARY];
size_t const size = sizeof(data->m_downLoadDC.m_filename); size_t const size = sizeof(data->m_downLoadDC.m_filename);
std::memset(fNameBuffer, 0x00, size); std::memset(fNameBuffer, 0x00, size);
@ -4575,7 +4575,7 @@ bool hwapi::dcDownloadReportFinished() {
QString hwapi::dcDownloadFileName() const { QString hwapi::dcDownloadFileName() const {
SharedMem const *data = SharedMem::getDataConst(); SharedMem const *data = SharedMem::getDataConst();
return data ? data->m_downLoadDC.m_filename : ""; return data ? data->m_downLoadDC.m_filename[(int)SharedMem::DCDownload::FILE_INDEX::DC_BINARY] : "";
} }
bool hwapi::dcDownloadSetRequested(bool requested) { bool hwapi::dcDownloadSetRequested(bool requested) {