void CEeprom::ReadFrom(uint8_t * Buffer, int32_t line) { int32_t i; if (!m_File.IsOpen()) { LoadEeprom(); } for (i = 0; i < 8; i++) { Buffer[i] = m_EEPROM[line * 8 + i]; } }
void CEeprom::ReadFrom(BYTE * Buffer, int line) { int i; if (m_hFile == NULL) { LoadEeprom(); } for (i=0; i < 8; i++) { Buffer[i] = m_EEPROM[line*8+i]; } }
void CEeprom::WriteTo(BYTE * Buffer, int line) { DWORD dwWritten; int i; if (m_hFile == NULL) { LoadEeprom(); } for (i=0;i<8;i++) { m_EEPROM[line*8+i]=Buffer[i]; } SetFilePointer(m_hFile,line*8,NULL,FILE_BEGIN); WriteFile( m_hFile,Buffer,8,&dwWritten,NULL ); FlushFileBuffers(m_hFile); }
void CEeprom::WriteTo(uint8_t * Buffer, int32_t line) { if (m_ReadOnly) { return; } int32_t i; if (!m_File.IsOpen()) { LoadEeprom(); } for (i = 0; i < 8; i++) { m_EEPROM[line * 8 + i] = Buffer[i]; } m_File.Seek(line * 8, CFile::begin); m_File.Write(Buffer, 8); }
bool MdiChild::loadFile(const QString &fileName, bool resetCurrentFile) { QFile file(fileName); if (!file.exists()) { QMessageBox::critical(this, tr("Error"), tr("Unable to find file %1!").arg(fileName)); return false; } int fileType = getFileType(fileName); #if 0 if (fileType==FILE_TYPE_XML) { if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { //reading HEX TEXT file QMessageBox::critical(this, tr("Error"), tr("Error opening file %1:\n%2.") .arg(fileName) .arg(file.errorString())); return false; } QTextStream inputStream(&file); XmlInterface(inputStream).load(radioData); } else #endif if (fileType==FILE_TYPE_HEX || fileType==FILE_TYPE_EEPE) { //read HEX file if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { //reading HEX TEXT file QMessageBox::critical(this, tr("Error"), tr("Error opening file %1:\n%2.") .arg(fileName) .arg(file.errorString())); return false; } QDomDocument doc(ER9X_EEPROM_FILE_TYPE); bool xmlOK = doc.setContent(&file); if(xmlOK) { if (LoadEepromXml(radioData, doc)){ ui->modelsList->refreshList(); if(resetCurrentFile) setCurrentFile(fileName); return true; } } file.reset(); QTextStream inputStream(&file); if (fileType==FILE_TYPE_EEPE) { // read EEPE file header QString hline = inputStream.readLine(); if (hline!=EEPE_EEPROM_FILE_HEADER) { file.close(); return false; } } uint8_t eeprom[EESIZE_RLC_MAX]; int eeprom_size = HexInterface(inputStream).load(eeprom, EESIZE_RLC_MAX); if (!eeprom_size) { QMessageBox::critical(this, tr("Error"), tr("Invalid EEPROM File %1") .arg(fileName)); file.close(); return false; } file.close(); if (!LoadEeprom(radioData, eeprom, eeprom_size)) { QMessageBox::critical(this, tr("Error"), tr("Invalid EEPROM File %1") .arg(fileName)); return false; } ui->modelsList->refreshList(); if(resetCurrentFile) setCurrentFile(fileName); return true; } else if (fileType==FILE_TYPE_BIN) { //read binary int eeprom_size = file.size(); if (!file.open(QFile::ReadOnly)) { //reading binary file - TODO HEX support QMessageBox::critical(this, tr("Error"), tr("Error opening file %1:\n%2.") .arg(fileName) .arg(file.errorString())); return false; } uint8_t *eeprom = (uint8_t *)malloc(eeprom_size); memset(eeprom, 0, eeprom_size); long result = file.read((char*)eeprom, eeprom_size); file.close(); if (result != eeprom_size) { QMessageBox::critical(this, tr("Error"), tr("Error reading file %1:\n%2.") .arg(fileName) .arg(file.errorString())); return false; } if (!LoadEeprom(radioData, eeprom, eeprom_size) && !LoadBackup(radioData, eeprom, eeprom_size, 0)) { QMessageBox::critical(this, tr("Error"), tr("Invalid binary EEPROM File %1") .arg(fileName)); return false; } ui->modelsList->refreshList(); if(resetCurrentFile) setCurrentFile(fileName); free(eeprom); return true; } return false; }
bool burnDialog::checkeEprom(QString fileName) { if (fileName.isEmpty()) { return false; } QFile file(fileName); if (!file.exists()) { QMessageBox::critical(this, tr("Error"), tr("Unable to find file %1!").arg(fileName)); return false; } burnraw=false; int fileType = getFileType(fileName); if (fileType==FILE_TYPE_XML) { if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { //reading HEX TEXT file QMessageBox::critical(this, tr("Error"),tr("Error opening file %1:\n%2.").arg(fileName).arg(file.errorString())); return false; } QTextStream inputStream(&file); XmlInterface(inputStream).load(radioData); } else if (fileType==FILE_TYPE_HEX || fileType==FILE_TYPE_EEPE) { //read HEX file if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { //reading HEX TEXT file QMessageBox::critical(this, tr("Error"),tr("Error opening file %1:\n%2.").arg(fileName).arg(file.errorString())); return false; } QDomDocument doc(ER9X_EEPROM_FILE_TYPE); bool xmlOK = doc.setContent(&file); if(xmlOK) { if (!LoadEepromXml(radioData, doc)){ return false; } } file.reset(); QTextStream inputStream(&file); if (fileType==FILE_TYPE_EEPE) { // read EEPE file header QString hline = inputStream.readLine(); if (hline!=EEPE_EEPROM_FILE_HEADER) { file.close(); return false; } } uint8_t eeprom[EESIZE_RLC_MAX]; int eeprom_size = HexInterface(inputStream).load(eeprom, EESIZE_RLC_MAX); if (!eeprom_size) { int res = QMessageBox::question(this, "Companion",tr("Invalid binary Models and Settings File %1, Proceed anyway ?").arg(fileName),QMessageBox::Yes | QMessageBox::No); if (res == QMessageBox::No) { return false; } burnraw=true; ui->FWFileName->setText(fileName); return true; } file.close(); if (!LoadEeprom(radioData, eeprom, eeprom_size)) { int res = QMessageBox::question(this, "Companion",tr("Invalid binary Models and Settings File %1, Proceed anyway ?").arg(fileName),QMessageBox::Yes | QMessageBox::No); if (res == QMessageBox::No) { return false; } burnraw=true; ui->FWFileName->setText(fileName); return true; } } else if (fileType==FILE_TYPE_BIN) { //read binary int eeprom_size = file.size(); if (!file.open(QFile::ReadOnly)) { //reading binary file - TODO HEX support QMessageBox::critical(this, tr("Error"),tr("Error opening file %1:\n%2.").arg(fileName).arg(file.errorString())); return false; } uint8_t *eeprom = (uint8_t *)malloc(eeprom_size); memset(eeprom, 0, eeprom_size); long result = file.read((char*)eeprom, eeprom_size); file.close(); if (result != eeprom_size) { QMessageBox::critical(this, tr("Error"),tr("Error reading file %1:\n%2.").arg(fileName).arg(file.errorString())); return false; } if (!LoadEeprom(radioData, eeprom, eeprom_size)) { int res = QMessageBox::question(this, "Companion",tr("Invalid binary Models and Settings File %1, Proceed anyway ?").arg(fileName),QMessageBox::Yes | QMessageBox::No); if (res == QMessageBox::No) { return false; } burnraw=true; } } ui->FWFileName->setText(fileName); return true; }
bool MdiChild::loadFile(const QString &fileName, bool resetCurrentFile) { QFile file(fileName); if (!file.exists()) { QMessageBox::critical(this, tr("Error"), tr("Unable to find file %1!").arg(fileName)); return false; } int fileType = getFileType(fileName); #if 0 if (fileType==FILE_TYPE_XML) { if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { //reading HEX TEXT file QMessageBox::critical(this, tr("Error"), tr("Error opening file %1:\n%2.") .arg(fileName) .arg(file.errorString())); return false; } QTextStream inputStream(&file); XmlInterface(inputStream).load(radioData); } else #endif if (fileType==FILE_TYPE_HEX || fileType==FILE_TYPE_EEPE) { //read HEX file if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { //reading HEX TEXT file QMessageBox::critical(this, tr("Error"), tr("Error opening file %1:\n%2.") .arg(fileName) .arg(file.errorString())); return false; } QDomDocument doc(ER9X_EEPROM_FILE_TYPE); bool xmlOK = doc.setContent(&file); if(xmlOK) { std::bitset<NUM_ERRORS> errors((unsigned long long)LoadEepromXml(radioData, doc)); if (errors.test(NO_ERROR)) { ui->modelsList->refreshList(); if(resetCurrentFile) setCurrentFile(fileName); return true; } } file.reset(); QTextStream inputStream(&file); if (fileType==FILE_TYPE_EEPE) { // read EEPE file header QString hline = inputStream.readLine(); if (hline!=EEPE_EEPROM_FILE_HEADER) { file.close(); return false; } } QByteArray eeprom(EESIZE_MAX, 0); int eeprom_size = HexInterface(inputStream).load((uint8_t *)eeprom.data(), EESIZE_MAX); if (!eeprom_size) { QMessageBox::critical(this, tr("Error"), tr("Invalid EEPROM File %1") .arg(fileName)); file.close(); return false; } file.close(); std::bitset<NUM_ERRORS> errors((unsigned long long)LoadEeprom(radioData, (uint8_t *)eeprom.data(), eeprom_size)); if (!errors.test(NO_ERROR)) { ShowEepromErrors(this, tr("Error"), tr("Invalid EEPROM File %1").arg(fileName), errors.to_ulong()); return false; } if (errors.test(HAS_WARNINGS)) { ShowEepromWarnings(this, tr("Warning"), errors.to_ulong()); } ui->modelsList->refreshList(); if(resetCurrentFile) setCurrentFile(fileName); return true; } else if (fileType==FILE_TYPE_BIN) { //read binary int eeprom_size = file.size(); if (!file.open(QFile::ReadOnly)) { //reading binary file - TODO HEX support QMessageBox::critical(this, tr("Error"), tr("Error opening file %1:\n%2.") .arg(fileName) .arg(file.errorString())); return false; } uint8_t *eeprom = (uint8_t *)malloc(eeprom_size); memset(eeprom, 0, eeprom_size); long result = file.read((char*)eeprom, eeprom_size); file.close(); if (result != eeprom_size) { QMessageBox::critical(this, tr("Error"), tr("Error reading file %1:\n%2.") .arg(fileName) .arg(file.errorString())); return false; } std::bitset<NUM_ERRORS> errorsEeprom((unsigned long long)LoadEeprom(radioData, eeprom, eeprom_size)); if (!errorsEeprom.test(NO_ERROR)) { std::bitset<NUM_ERRORS> errorsBackup((unsigned long long)LoadBackup(radioData, eeprom, eeprom_size, 0)); if (!errorsBackup.test(NO_ERROR)) { ShowEepromErrors(this, tr("Error"), tr("Invalid binary EEPROM File %1").arg(fileName), (errorsEeprom | errorsBackup).to_ulong()); return false; } if (errorsBackup.test(HAS_WARNINGS)) { ShowEepromWarnings(this, tr("Warning"), errorsBackup.to_ulong()); } } else if (errorsEeprom.test(HAS_WARNINGS)) { ShowEepromWarnings(this, tr("Warning"), errorsEeprom.to_ulong()); } ui->modelsList->refreshList(); if(resetCurrentFile) setCurrentFile(fileName); free(eeprom); return true; } return false; }