Compare commits

..

No commits in common. "4cc964e8c29416a27af5ef25648378650f923833" and "47f09067ea9ab272dde34c01c17b19aa7f4255d1" have entirely different histories.

3 changed files with 46 additions and 64 deletions

View File

@ -303,18 +303,7 @@ struct SharedMem
// download of device controller and json files // download of device controller and json files
struct DCDownload { struct DCDownload {
enum class FILE_INDEX { char m_filename[512];
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,63 +99,57 @@ 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
// TODO: send the json files as well #if 0
Update::DownloadResult Update::dc_downloadBinary(QByteArray const &b) const {
int const nBlocks = (((b.size())%64)==0) ? (b.size()/64) : (b.size()/64)+1;
m_hw->dcDownloadRequestAck(); // fill lst block of data to be sent with 0xFF
QByteArray ba = b.leftJustified(nBlocks*64, (char)(0xFF));
qCritical() << "DownloadThread::run(): DOWNLOAD THREAD STARTED"; qInfo() << "total number of bytes to send to dc" << ba.size();
qInfo() << "total number of blocks to send to dc" << nBlocks;
// load binary device controller file into memory int bNum = 0;
QByteArray ba = loadBinaryDCFile(m_hw->dcDownloadFileName()); DownloadResult res = DownloadResult::OK;
if (ba.size() > 0) { fprintf(stderr, "\n64-byte block %04d ", bNum);
uint16_t const totalBlocks = (((ba.size())%64)==0) ? (ba.size()/64) : (ba.size()/64)+1; while (res != DownloadResult::ERROR && bNum < nBlocks) {
m_hw->dcDownloadSetTotalBlockNumber(totalBlocks); if ((res = sendNextAddress(bNum)) != DownloadResult::ERROR) {
if ((res = sendNextDataBlock(ba, bNum)) != DownloadResult::ERROR) {
// fill last block of data to be sent with 0xFF bNum += 1;
ba = ba.leftJustified(totalBlocks*64, (char)(0xFF)); fprintf(stderr, ".");
if ((bNum % 80) == 0) {
resetDeviceController(); fprintf(stderr, "\n64-byte block %04d ", bNum);
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 fprintf(stderr, "\nlast 64-byte block %04d\n", bNum);
} // if it was not started at all
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();
qCritical() << QDateTime::currentDateTime().toString(Qt::ISODate) + "DOWNLOAD THREAD STARTED";
#if 0
// test code: // test code:
uint16_t const totalBlocks = 100; uint16_t const totalBlocks = 100;
m_hw->dcDownloadSetTotalBlockNumber(totalBlocks); m_hw->dcDownloadSetTotalBlockNumber(totalBlocks);
@ -164,7 +158,6 @@ 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[(int)SharedMem::DCDownload::FILE_INDEX::DC_BINARY]; char *fNameBuffer = data->m_downLoadDC.m_filename;
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[(int)SharedMem::DCDownload::FILE_INDEX::DC_BINARY] : ""; return data ? data->m_downLoadDC.m_filename : "";
} }
bool hwapi::dcDownloadSetRequested(bool requested) { bool hwapi::dcDownloadSetRequested(bool requested) {