int Ersky9xInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t variant, uint8_t version) { EEPROMWarnings.clear(); efile->EeFsCreate(eeprom, EESIZE_SKY9X, BOARD_SKY9X); Ersky9xGeneral ersky9xGeneral(radioData.generalSettings); int sz = efile->writeRlc2(FILE_GENERAL, FILE_TYP_GENERAL, (uint8_t*)&ersky9xGeneral, sizeof(Ersky9xGeneral)); if(sz != sizeof(Ersky9xGeneral)) { return 0; } for (int i=0; i<getMaxModels(); i++) { if (!radioData.models[i].isempty()) { Ersky9xModelData_v11 ersky9xModel(radioData.models[i]); applyStickModeToModel(ersky9xModel, radioData.generalSettings.stickMode+1); sz = efile->writeRlc2(FILE_MODEL(i), FILE_TYP_MODEL, (uint8_t*)&ersky9xModel, sizeof(Ersky9xModelData_v11)); if(sz != sizeof(Ersky9xModelData_v11)) { return 0; } } } if (!EEPROMWarnings.isEmpty()) QMessageBox::warning(NULL, QObject::tr("Warning"), QObject::tr("EEPROM saved with these warnings:") + "\n- " + EEPROMWarnings.remove(EEPROMWarnings.length()-1, 1).replace("\n", "\n- ")); return EESIZE_SKY9X; }
bool OpenTxEepromInterface::loadModel(ModelData &model, uint8_t *data, int index, unsigned int stickMode) { T _model; if (!data) { // load from EEPROM efile->openRd(FILE_MODEL(index)); int sz = efile->readRlc2((uint8_t*)&_model, sizeof(T)); if (sz) { model = _model; if (sz < (int)sizeof(T)) { std::cout << " size(" << model.name << ") " << sz << " < " << (int)sizeof(T) << " "; } if (stickMode) { applyStickModeToModel(model, stickMode); } } else { model.clear(); } } else { // load from SD Backup, size is stored in index if ((unsigned int)index < sizeof(T)) return false; memcpy((uint8_t*)&_model, data, sizeof(T)); model = _model; } return true; }
void Gruvin9xInterface::loadModel(ModelData &model, unsigned int stickMode, int version) { T _model; if ((version == 2 && efile->readRlc2((uint8_t*)&_model, sizeof(T))) || (version == 1 && efile->readRlc1((uint8_t*)&_model, sizeof(T)))) { model = _model; if (stickMode) { applyStickModeToModel(model, stickMode); } } else { model.clear(); } }
bool Ersky9xInterface::loadModelDataXML(QDomDocument * qdoc, ModelData *model, int modelNum, int stickMode) { T ersky9xModel; memset(&ersky9xModel, 0, sizeof(ersky9xModel)); //look for MODEL_DATA with modelNum attribute. //if modelNum = -1 then just pick the first one QDomNodeList ndl = qdoc->elementsByTagName("MODEL_DATA"); //cycle through nodes to find correct model number QDomNode k = ndl.at(0); if (modelNum>=0) { while(!k.isNull()) { int a = k.toElement().attribute("number").toInt(); if(a==modelNum) break; k = k.nextSibling(); } } if (k.isNull()) // couldn't find return false; //load cdata into tgen QDomNode n = k.toElement().elementsByTagName("Data").at(0).firstChild();// get all children in Data while (!n.isNull()) { if (n.isCDATASection()) { QString ds = n.toCDATASection().data(); QByteArray ba = QByteArray::fromBase64(ds.toAscii()); const char * data = ba.data(); memcpy(&ersky9xModel, data, std::min(ba.size(), (int)sizeof(ersky9xModel))); break; } n = n.nextSibling(); } applyStickModeToModel(ersky9xModel, stickMode); *model = ersky9xModel; return true; }
bool Er9xInterface::loadxml(RadioData &radioData, QDomDocument &doc) { std::cout << "trying er9x xml import... "; Er9xGeneral er9xGeneral; memset(&er9xGeneral,0,sizeof(er9xGeneral)); if(!loadGeneralDataXML(&doc, &er9xGeneral)) { return false; } else { radioData.generalSettings=er9xGeneral; std::cout << "version " << (unsigned int)er9xGeneral.myVers << " "; } for(int i=0; i<getMaxModels(); i++) { Er9xModelData er9xModel; memset(&er9xModel,0,sizeof(er9xModel)); if(loadModelDataXML(&doc, &er9xModel, i)) { applyStickModeToModel(er9xModel, radioData.generalSettings.stickMode+1); radioData.models[i] = er9xModel; } } std::cout << "ok\n"; return true; }
bool Ersky9xInterface::load(RadioData &radioData, uint8_t *eeprom, int size) { std::cout << "trying ersky9x import... "; if (size != EESIZE_SKY9X) { std::cout << "wrong size\n"; return false; } if (!efile->EeFsOpen(eeprom, size, BOARD_SKY9X)) { std::cout << "wrong file system\n"; return false; } efile->openRd(FILE_GENERAL); Ersky9xGeneral ersky9xGeneral; if (efile->readRlc2((uint8_t*)&ersky9xGeneral, 1) != 1) { std::cout << "no\n"; return false; } std::cout << "version " << (unsigned int)ersky9xGeneral.myVers << " "; switch(ersky9xGeneral.myVers) { case 10: break; case 11: break; default: std::cout << "not ersky9x\n"; return false; } efile->openRd(FILE_GENERAL); if (!efile->readRlc2((uint8_t*)&ersky9xGeneral, sizeof(Ersky9xGeneral))) { std::cout << "ko\n"; return false; } radioData.generalSettings = ersky9xGeneral; for (int i=0; i<getMaxModels(); i++) { uint8_t buffer[4096]; uint size; memset(buffer,0,sizeof(buffer)); efile->openRd(FILE_MODEL(i)); // if (!efile->readRlc2((uint8_t*)&ersky9xModel, sizeof(Ersky9xModelData))) { size=efile->readRlc2(buffer, 4096); if (!size) { radioData.models[i].clear(); } else { if (size<720) { Ersky9xModelData_v10 ersky9xModel; memcpy(&ersky9xModel, buffer, sizeof(ersky9xModel)); applyStickModeToModel(ersky9xModel, radioData.generalSettings.stickMode+1); radioData.models[i] = ersky9xModel; } else { Ersky9xModelData_v11 ersky9xModel; memcpy(&ersky9xModel, buffer, sizeof(ersky9xModel)); applyStickModeToModel(ersky9xModel, radioData.generalSettings.stickMode+1); radioData.models[i] = ersky9xModel; } } } std::cout << "ok\n"; return true; }
bool Er9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) { std::cout << "trying er9x import... "; if (size != getEEpromSize()) { std::cout << "wrong size\n"; return false; } if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_STOCK)) { std::cout << "wrong file system\n"; return false; } efile->openRd(FILE_GENERAL); Er9xGeneral er9xGeneral; if (efile->readRlc1((uint8_t*)&er9xGeneral, 1) != 1) { std::cout << "no\n"; return false; } std::cout << "version " << (unsigned int)er9xGeneral.myVers << " "; switch(er9xGeneral.myVers) { case 3: std::cout << "(old gruvin9x) "; case 4: // case 5: case 6: case 7: case 8: case 9: case 10: break; default: std::cout << "not er9x\n"; return false; } efile->openRd(FILE_GENERAL); if (!efile->readRlc1((uint8_t*)&er9xGeneral, sizeof(Er9xGeneral))) { std::cout << "ko\n"; return false; } radioData.generalSettings = er9xGeneral; for (int i=0; i<getMaxModels(); i++) { Er9xModelData er9xModel; efile->openRd(FILE_MODEL(i)); if (!efile->readRlc1((uint8_t*)&er9xModel, sizeof(Er9xModelData))) { radioData.models[i].clear(); } else { applyStickModeToModel(er9xModel, radioData.generalSettings.stickMode+1); radioData.models[i] = er9xModel; } } std::cout << "ok\n"; return true; }