bool eeDuplicateModel(uint8_t id) { uint8_t i; for( i=id+1; i<MAX_MODELS; i++) { if(! EFile::exists(FILE_MODEL(i))) break; } if(i==MAX_MODELS) return false; //no free space in directory left theFile.openRd(FILE_MODEL(id)); theFile2.create(FILE_MODEL(i),FILE_TYP_MODEL,600); uint8_t buf[15]; uint8_t l; while((l=theFile.read(buf,15))) { theFile2.write(buf,l); // if(theFile.write_errno()==ERR_TMO) // { // //wait for 10ms and try again // uint16_t tgtime = get_tmr10ms() + 100; // while (!=tgtime); // theFile2.write(buf,l); // } wdt_reset(); } theFile2.closeTrunc(); //todo error handling return true; }
void EEPFILE::eeLoadModelName(uint8_t id,char*buf,uint8_t len) { if(id<MAX_MODELS) { //eeprom_read_block(buf,(void*)modelEeOfs(id),sizeof(g_model.name)); memset(buf,' ',len); *buf='0'+(id+1)/10; buf++; *buf='0'+(id+1)%10; buf++; *buf=':'; buf++;buf++; if(!eeModelExists(id)) // make sure we don't add junk { *buf=0; //terminate str return; } theFile->openRd(FILE_MODEL(id)); uint16_t res = theFile->readRlc((uint8_t*)buf,sizeof(ModelData().name)); if(res == sizeof(ModelData().name) ) { //buf+=len-5; for(int i=0; i<(len-4); i++) { if(*buf==0) *buf=' '; buf++; } *buf=0;buf--; uint16_t sz=theFile->size(FILE_MODEL(id)); while(sz){ --buf; *buf='0'+sz%10; sz/=10;} } } }
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; }
static void project_root_added (AnjutaPlugin *plugin, const gchar *name, const GValue *value, gpointer user_data) { AnjutaFileManager* file_manager; GtkTreeModelSort *tree_model; FileModel *file_model; const gchar *root_uri; file_manager = (AnjutaFileManager*) plugin; tree_model = GTK_TREE_MODEL_SORT ( gtk_tree_view_get_model (GTK_TREE_VIEW (file_manager->fv))); file_model = FILE_MODEL (gtk_tree_model_sort_get_model (tree_model)); root_uri = g_value_get_string (value); if (root_uri) { g_object_set (G_OBJECT(file_manager->fv), "base_uri", root_uri, NULL); file_model_set_ivcs (file_model, get_vcs_plugin (file_manager, root_uri)); file_view_refresh (file_manager->fv); file_manager->have_project = TRUE; } else { file_model_set_ivcs(file_model, NULL); file_manager_set_default_uri (file_manager); file_view_refresh (file_manager->fv); } }
void eeLoadModel(uint8_t id) { if(id<MAX_MODELS) { theFile.openRlc(FILE_MODEL(id)); uint16_t sz = theFile.readRlc((uint8_t*)&g_model, sizeof(g_model)); #ifdef SIMU if (sz > 0 && sz != sizeof(g_model)) { printf("Model data read=%d bytes vs %d bytes\n", sz, (int)sizeof(ModelData)); } #endif if (sz < 730/*sizeof(last compatible eeprom)*/) { modelDefault(id); eeCheck(true); } resetTimer1(); resetTimer2(); resetProto(); #ifdef TELEMLOGS initTelemLog(); #endif } }
bool OpenTxEepromInterface::loadModelVariant(unsigned int index, ModelData &model, uint8_t *data, unsigned int version, unsigned int variant) { T open9xModel(model, board, version, variant); if (!data) { // load from EEPROM QByteArray eepromData(sizeof(model), 0); // ModelData should be always bigger than the EEPROM struct efile->openRd(FILE_MODEL(index)); int numbytes = efile->readRlc2((uint8_t *)eepromData.data(), eepromData.size()); if (numbytes) { open9xModel.Import(eepromData); // open9xModel.Dump(); model.used = true; } else { model.clear(); } } else { // load from SD Backup, size is stored in index QByteArray eepromData((char *)data, index); open9xModel.Import(eepromData); } return true; }
static gboolean file_view_query_tooltip (GtkWidget* widget, gint x, gint y, gboolean keyboard, GtkTooltip* tooltip) { AnjutaFileView* view = ANJUTA_FILE_VIEW (widget); AnjutaFileViewPrivate* priv = ANJUTA_FILE_VIEW_GET_PRIVATE (view); GtkTreeModel* model_sort; GtkTreeModel* file_model = GTK_TREE_MODEL (priv->model); GtkTreePath* path; GtkTreeIter iter; GtkTreeIter real_iter; gchar* filename; gboolean result = TRUE; GdkRectangle visible_rect, column_rect; GdkScreen *screen = gdk_screen_get_default (); PangoContext *context; PangoLayout *layout; gint width, height; if (!gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (view), &x, &y, keyboard, &model_sort, &path, &iter)) return FALSE; gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (model_sort), &real_iter, &iter); filename = file_model_get_filename (FILE_MODEL (file_model), &real_iter); context = gdk_pango_context_get_for_screen (screen); layout = pango_layout_new (context); pango_layout_set_text (layout, filename, -1); pango_layout_get_pixel_size (layout, &width, &height); gtk_tree_view_get_visible_rect (GTK_TREE_VIEW (view), &visible_rect); gtk_tree_view_get_cell_area (GTK_TREE_VIEW (view), path, gtk_tree_view_get_column (GTK_TREE_VIEW (view), 0), &column_rect); if (column_rect.x + width > visible_rect.x + visible_rect.width || column_rect.x < visible_rect.x) { gtk_tooltip_set_text (tooltip, filename); gtk_tree_view_set_tooltip_row (GTK_TREE_VIEW (view), tooltip, path); } else { result = FALSE; } g_free (filename); gtk_tree_path_free (path); g_object_unref (layout); g_object_unref (context); return result; }
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; }
uint16_t EeFsGetFree() { int32_t ret = freeBlocks * (BS-sizeof(blkid_t)); ret += eeFs.files[FILE_TMP].size; ret -= eeFs.files[FILE_MODEL(g_eeGeneral.currModel)].size; return (ret > 0 ? ret : 0); }
bool OpenTxEepromInterface::saveModel(unsigned int index, ModelData &model, unsigned int version, unsigned int variant) { T open9xModel(model, board, version, variant); // open9xModel.Dump(); QByteArray eeprom; open9xModel.Export(eeprom); int sz = efile->writeRlc2(FILE_MODEL(index), FILE_TYP_MODEL, (const uint8_t*)eeprom.constData(), eeprom.size()); return (sz == eeprom.size()); }
static void file_view_selection_changed (GtkTreeSelection* selection, AnjutaFileView* view) { AnjutaFileViewPrivate* priv = ANJUTA_FILE_VIEW_GET_PRIVATE (view); GtkTreeModel* file_model = GTK_TREE_MODEL(priv->model); GtkTreeIter selected; GtkTreeModel* model = gtk_tree_view_get_model (GTK_TREE_VIEW(view)); if (priv->current_selection) { GtkTreeIter iter; GtkTreePath* path = gtk_tree_row_reference_get_path (priv->current_selection); if (path && gtk_tree_model_get_iter (file_model, &iter, path)) { gchar* filename; gtk_tree_model_get (file_model, &iter, COLUMN_FILENAME, &filename, -1); gtk_tree_store_set (GTK_TREE_STORE (file_model), &iter, COLUMN_DISPLAY, filename, -1); g_free(filename); gtk_tree_path_free(path); } gtk_tree_row_reference_free(priv->current_selection); priv->current_selection = NULL; } if (gtk_tree_selection_get_selected (selection, &model, &selected)) { GtkTreeIter real_selection; GtkTreePath* path; GFile* file; gtk_tree_model_sort_convert_iter_to_child_iter(GTK_TREE_MODEL_SORT(model), &real_selection, &selected); path = gtk_tree_model_get_path(file_model, &real_selection); priv->current_selection = gtk_tree_row_reference_new (file_model, path); gtk_tree_path_free(path); file_view_show_extended_data (view, &real_selection); file = file_model_get_file(FILE_MODEL(file_model), &real_selection); g_signal_emit_by_name (G_OBJECT (view), "current-file-changed", file, NULL); g_object_unref (file); } else { g_signal_emit_by_name (G_OBJECT (view), "current-file-changed", NULL, NULL); } /* The pending selection is now either done or if the user changed the * selection before it was finished we cancel it. */ g_clear_object (&priv->pending_selected_file); DEBUG_PRINT ("%s", "selection_changed"); }
int8_t eeFindEmptyModel(uint8_t id, bool down) { int8_t i = id; for (;;) { i = (MAX_MODELS + (down ? i+1 : i-1)) % MAX_MODELS; if (!EFile::exists(FILE_MODEL(i))) break; if (i == id) return -1; // no free space in directory left } return i; }
uint16_t eeLoadModelName(uint8_t id, char *name) { memset(name, 0, sizeof(g_model.name)); if (id<MAX_MODELS) { theFile.openRlc(FILE_MODEL(id)); if (theFile.readRlc((uint8_t*)name, sizeof(g_model.name)) == sizeof(g_model.name)) { return theFile.size(); } } return 0; }
bool eeDuplicateModel(uint8_t id) { uint8_t i; for( i=id+1; i<MAX_MODELS; i++) { if(! EFile::exists(FILE_MODEL(i))) break; } if(i==MAX_MODELS) return false; //no free space in directory left theFile.openRd(FILE_MODEL(id)); theFile2.create(FILE_MODEL(i),FILE_TYP_MODEL,200); uint8_t buf[15]; uint8_t l; while((l=theFile.read(buf,15))) { theFile2.write(buf,l); wdt_reset(); } theFile2.closeTrunc(); //todo error handling return true; }
int EEPFILE::getModel(ModelData* model, uint8_t id) { int sz = 0; memset(model, 0, sizeof(ModelData)); if(id<MAX_MODELS) { theFile->openRd(FILE_MODEL(id)); sz = theFile->readRlc((uint8_t*)model, sizeof(ModelData)); } return sz; }
bool EEPFILE::putModel(ModelData* model, uint8_t id) { int sz = 0; if(id<MAX_MODELS) { sz = theFile->writeRlc(FILE_MODEL(id), FILE_TYP_MODEL, (uint8_t*)model, sizeof(ModelData)); // sz = theFile->writeRlc(FILE_TMP, FILE_TYP_MODEL, (uint8_t*)model, sizeof(ModelData)); // if(sz == sizeof(ModelData)) // theFile->swap(FILE_MODEL(id),FILE_TMP); // do not need temp file, writeRlc should write the actual file } return (sz == sizeof(ModelData)); }
void eeCheck(bool immediately) { if (immediately) { eeFlush(); } if (s_eeDirtyMsk & EE_GENERAL) { s_eeDirtyMsk -= EE_GENERAL; theFile.writeRlc(FILE_GENERAL, FILE_TYP_GENERAL, (uint8_t*)&g_eeGeneral, sizeof(EEGeneral), immediately); if (!immediately) return; } if (s_eeDirtyMsk & EE_MODEL) { s_eeDirtyMsk = 0; theFile.writeRlc(FILE_MODEL(g_eeGeneral.currModel), FILE_TYP_MODEL, (uint8_t*)&g_model, sizeof(g_model), immediately); } }
uint16_t EeFsGetFree() { #if defined(CPUARM) int32_t ret = freeBlocks * (BS-sizeof(blkid_t)); #else int16_t ret = 0; blkid_t i = eeFs.freeList; while (i) { ret += BS-sizeof(blkid_t); i = EeFsGetLink(i); } #endif ret += eeFs.files[FILE_TMP].size; ret -= eeFs.files[FILE_MODEL(g_eeGeneral.currModel)].size; return (ret > 0 ? ret : 0); }
void eeLoadModelName(uint8_t id,char*buf,uint8_t len) { if(id<MAX_MODELS) { //eeprom_read_block(buf,(void*)modelEeOfs(id),sizeof(g_model.name)); theFile.openRd(FILE_MODEL(id)); memset(buf,' ',len); if(theFile.readRlc2((uint8_t*)buf,sizeof(g_model.name)+1) == (sizeof(g_model.name)+1) ) { uint8_t vers = buf[sizeof(g_model.name)]; uint16_t sz = theFile.size(); buf[sizeof(g_model.name)]=' '; buf+=len; *--buf='0'+vers%10; vers/=10; *--buf='0'+vers%10; *--buf='V'; --buf; while(sz){ --buf; *buf='0'+sz%10; sz/=10;} } } }
void eeCheck(bool immediately) { if(!s_eeDirtyMsk) return; if( !immediately && ((g_tmr10ms - s_eeDirtyTime10ms) < WRITE_DELAY_10MS)) return; if(s_eeDirtyMsk & EE_GENERAL){ s_eeDirtyMsk &= ~EE_GENERAL; //not int safe if(theFile.writeRlc2(FILE_TMP, FILE_TYP_GENERAL, (uint8_t*)&g_eeGeneral, sizeof(g_eeGeneral),20) == sizeof(g_eeGeneral)) { EFile::swap(FILE_GENERAL,FILE_TMP); }else{ if(theFile.write_errno()==ERR_TMO){ s_eeDirtyMsk |= EE_GENERAL; //try again s_eeDirtyTime10ms = g_tmr10ms - WRITE_DELAY_10MS; printf("writing aborted GENERAL\n"); }else{ alert(PSTR("EEPROM overflow")); } } //first finish GENERAL, then MODEL !!avoid Toggle effect } else if(s_eeDirtyMsk & EE_MODEL){ s_eeDirtyMsk &= ~EE_MODEL;//not int safe g_model.mdVers = MDVERS_TOP; if(theFile.writeRlc2(FILE_TMP, FILE_TYP_MODEL, (uint8_t*)&g_model, sizeof(g_model),20) == sizeof(g_model)) { EFile::swap(FILE_MODEL(g_eeGeneral.currModel),FILE_TMP); }else{ if(theFile.write_errno()==ERR_TMO){ s_eeDirtyMsk |= EE_MODEL; //try again s_eeDirtyTime10ms = g_tmr10ms - WRITE_DELAY_10MS; printf("writing aborted MODEL\n"); }else{ alert(PSTR("EEPROM overflow")); } } } beepStore(); }
void eeLoadModelName(uint8_t id,char*buf,uint8_t len) { if(id<MAX_MODELS) { //eeprom_read_block(buf,(void*)modelEeOfs(id),sizeof(g_model.name)); theFile.openRd(FILE_MODEL(id)); memset(buf,' ',len); if(theFile.readRlc((uint8_t*)buf,sizeof(g_model.name)) == sizeof(g_model.name) ) { uint16_t sz=theFile.size(); buf+=len; while(sz) { div_t qr ; qr = div( sz, 10 ) ; --buf; *buf='0'+qr.rem; sz = qr.quot; } } } }
void modelDefaultWrite(uint8_t id) { memset(&g_model, 0, sizeof(ModelData)); setNameP(g_model.name,PSTR(STR_MODEL)); // strncpy_P(g_model.name,PSTR(STR_MODEL), 10); div_t qr ; qr = div( id+1, 10 ) ; g_model.name[5]='0'+qr.quot; g_model.name[6]='0'+qr.rem; #ifdef VERSION3 g_model.modelVersion = 3 ; #else g_model.modelVersion = 2 ; #endif g_model.trimInc = 2 ; #ifdef NO_TEMPLATES applyTemplate(); //default 4 channel template #else applyTemplate(0); //default 4 channel template #endif theFile.writeRlc(FILE_MODEL(id),FILE_TYP_MODEL,(uint8_t*)&g_model,sizeof(g_model),200); }
void eeReadAll() { if(!EeFsOpen() || EeFsck() < 0 || !eeLoadGeneral() ) { #ifdef SIM printf("bad eeprom contents\n"); #else alert(PSTR("Bad EEprom Data")); #endif EeFsFormat(); generalDefault(); theFile.writeRlc2(FILE_GENERAL,FILE_TYP_GENERAL,(uint8_t*)&g_eeGeneral, sizeof(g_eeGeneral),200); modelDefault(0); theFile.writeRlc2(FILE_MODEL(0),FILE_TYP_MODEL,(uint8_t*)&g_model, sizeof(g_model),200); } eeLoadModel(g_eeGeneral.currModel); }
void eeReadAll() { if(!EeFsOpen() || EeFsck() < 0 || !eeLoadGeneral() ) { alert(PSTR("Bad EEprom Data"), true); message(PSTR("EEPROM Formatting")); EeFsFormat(); //alert(PSTR("format ok")); generalDefault(); //alert(PSTR("default ok")); theFile.writeRlc(FILE_GENERAL, FILE_TYP_GENERAL,(uint8_t*)&g_eeGeneral,sizeof(EEGeneral), true); modelDefault(0); //alert(PSTR("modef ok")); theFile.writeRlc(FILE_MODEL(0), FILE_TYP_MODEL, (uint8_t*)&g_model, sizeof(g_model), true); //alert(PSTR("modwrite ok")); } eeLoadModel(g_eeGeneral.currModel); }
bool eeModelExists(uint8_t id) { return EFile::exists(FILE_MODEL(id)); }
uint8_t Translate() { if (g_eeGeneral.myVers == 0) { if (theFile.readRlc1((uint8_t*)&g_eeGeneral, 1) != 1) return 0; theFile.openRlc(FILE_GENERAL); } if (g_eeGeneral.myVers == EEPROM_VER_r584 || (g_eeGeneral.myVers >= EEPROM_ER9X_MIN && g_eeGeneral.myVers <= EEPROM_ER9X_MAX)) { alert(g_eeGeneral.myVers == EEPROM_VER_r584 ? PSTR("EEprom Data v3") : PSTR("EEprom Data Er9x"), true); message(PSTR("EEPROM Converting")); theFile.readRlc1((uint8_t*)&g_eeGeneral, sizeof(g_eeGeneral)); memset(&g_eeGeneral.frskyRssiAlarms, 0, sizeof(g_eeGeneral.frskyRssiAlarms)); if (g_eeGeneral.myVers == EEPROM_VER_r584) { // previous version had only 6 custom switches, OFF and ON values have to be shifted 6 if (g_eeGeneral.lightSw == MAX_SWITCH-6) g_eeGeneral.lightSw += 6; if (g_eeGeneral.lightSw == -MAX_SWITCH+6) g_eeGeneral.lightSw -= 6; } else { g_eeGeneral.inactivityTimer += 10; } g_eeGeneral.view = 0; // will not translate the view index EEPROM_V3::EEGeneral *old = (EEPROM_V3::EEGeneral *)&g_eeGeneral; g_eeGeneral.disableMemoryWarning = old->disableMemoryWarning; g_eeGeneral.switchWarning = old->disableSwitchWarning ? 0 : -1; for (uint8_t i=0; i<4; i++) { g_eeGeneral.trainer.mix[i].srcChn = old->trainer.mix[i].srcChn; g_eeGeneral.trainer.mix[i].mode = old->trainer.mix[i].mode; g_eeGeneral.trainer.mix[i].studWeight = old->trainer.mix[i].studWeight * 13 / 4; } for (uint8_t id=0; id<MAX_MODELS; id++) { theFile.openRlc(FILE_MODEL(id)); uint16_t sz = theFile.readRlc1((uint8_t*)&g_model, sizeof(EEPROM_V4::ModelData)); if(sz > 0) { EEPROM_V4::ModelData *v4 = (EEPROM_V4::ModelData *)&g_model; EEPROM_V3::ModelData *v3 = (EEPROM_V3::ModelData *)&g_model; SwashRingData swashR; swashR.invertELE = v4->swashInvertELE; swashR.invertAIL = v4->swashInvertAIL; swashR.invertCOL = v4->swashInvertCOL; swashR.type = v4->swashType; swashR.collectiveSource = v4->swashCollectiveSource; swashR.value = v4->swashRingValue; int8_t trims[4]; memcpy(&trims[0], &v3->trim[0], 4); int8_t trimSw = v3->trimSw; for (uint8_t i=0; i<10; i++) g_model.name[i] = char2idx(g_model.name[i]); g_model.timer1.mode = v3->tmrMode; g_model.timer1.dir = v3->tmrDir; g_model.timer1.val = v3->tmrVal; g_model.protocol = v3->protocol; g_model.ppmNCH = v3->ppmNCH; g_model.thrTrim = v3->thrTrim; g_model.trimInc = v3->trimInc; g_model.pulsePol = v3->pulsePol; if (g_eeGeneral.myVers == EEPROM_VER_r584) g_model.extendedLimits = 0; else g_model.extendedLimits = v4->extendedLimits; g_model.extendedTrims = 0; g_model.spare2 = 0; g_model.ppmDelay = v3->ppmDelay; g_model.beepANACenter = v3->beepANACenter; g_model.timer2.mode = 0; g_model.timer2.dir = 0; g_model.timer2.val = 0; for (uint8_t i=0; i<MAX_MIXERS; i++) { memmove(&g_model.mixData[i], &v3->mixData[i], sizeof(MixData)); // MixData size changed! g_model.mixData[i].mixWarn = g_model.mixData[i].phase; g_model.mixData[i].phase = 0; if (g_eeGeneral.myVers == EEPROM_VER_r584 && g_model.mixData[i].srcRaw > MIX_FULL) { g_model.mixData[i].srcRaw += 3; /* because of [CYC1:CYC3] inserted after MIX_FULL */ } } assert((char *)&g_model.limitData[0] < (char *)&v3->limitData[0]); memmove(&g_model.limitData[0], &v3->limitData[0], sizeof(LimitData)*NUM_CHNOUT); assert((char *)&g_model.expoData[0] < (char *)v3->expoData); EEPROM_V4::ExpoData expo4[4]; memcpy(&expo4[0], &v4->expoData[0], sizeof(expo4)); memset(&g_model.expoData[0], 0, sizeof(expo4)); // expos conversion uint8_t e = 0; for (uint8_t ch = 0; ch < 4 && e < MAX_EXPOS; ch++) { for (uint8_t dr = 0, pos = 0; dr < 3 && e < MAX_EXPOS; dr++, pos++) { if ((dr == 0 && !expo4[ch].drSw1) || (dr == 1 && !expo4[ch].drSw2)) dr = 2; if (dr == 2 && !expo4[ch].expo[0][0][0] && !expo4[ch].expo[0][0][1] && !expo4[ch].expo[0][1][0] && !expo4[ch].expo[0][1][1]) break; g_model.expoData[e].swtch = (dr == 0 ? -expo4[ch].drSw1 : (dr == 1 ? -expo4[ch].drSw2 : 0)); g_model.expoData[e].chn = ch; g_model.expoData[e].expo = expo4[ch].expo[pos][0][0]; g_model.expoData[e].weight = 100 + expo4[ch].expo[pos][1][0]; if (expo4[ch].expo[pos][0][0] == expo4[ch].expo[pos][0][1] && expo4[ch].expo[pos][1][0] == expo4[ch].expo[pos][1][1]) { g_model.expoData[e++].mode = 3; } else { g_model.expoData[e].mode = 2; if (e < MAX_EXPOS - 1) { g_model.expoData[e + 1].swtch = g_model.expoData[e].swtch; g_model.expoData[++e].chn = ch; g_model.expoData[e].mode = 1; g_model.expoData[e].expo = expo4[ch].expo[pos][0][1]; g_model.expoData[e++].weight = 100 + expo4[ch].expo[pos][1][1]; } } } } assert((char *)&g_model.curves5[0][0] < (char *)&v3->curves5[0][0]); memmove(&g_model.curves5[0][0], &v3->curves5[0][0], 5*MAX_CURVE5); assert((char *)&g_model.curves9[0][0] < (char *)&v3->curves9[0][0]); memmove(&g_model.curves9[0][0], &v3->curves9[0][0], 9*MAX_CURVE9); if (g_eeGeneral.myVers == EEPROM_VER_r584) { memmove(&g_model.customSw[0], &v3->customSw[0], sizeof(CustomSwData)*6); memset(&g_model.customSw[6], 0, sizeof(CustomSwData)*6); memset(&g_model.safetySw[0], 0, sizeof(SafetySwData)*NUM_CHNOUT + sizeof(SwashRingData) + sizeof(FrSkyData)); } else { assert((char *)&g_model.customSw[0] < (char *)&v4->customSw[0]); memmove(&g_model.customSw[0], &v4->customSw[0], sizeof(CustomSwData)*12); assert((char *)&g_model.safetySw[0] < (char *)&v4->safetySw[0]); memmove(&g_model.safetySw[0], &v4->safetySw[0], sizeof(SafetySwData)*NUM_CHNOUT); memcpy(&g_model.swashR, &swashR, sizeof(SwashRingData)); for (uint8_t i=0; i<2; i++) { // TODO this conversion is bad // assert(&g_model.frsky.channels[i].ratio < &v4->frsky.channels[i].ratio); g_model.frsky.channels[i].ratio = v4->frsky.channels[i].ratio; g_model.frsky.channels[i].type = v4->frsky.channels[i].type; // g_model.frsky.channels[i].offset = 0; g_model.frsky.channels[i].alarms_value[0] = v4->frsky.channels[i].alarms_value[0]; g_model.frsky.channels[i].alarms_value[1] = v4->frsky.channels[i].alarms_value[1]; g_model.frsky.channels[i].alarms_level = v4->frsky.channels[i].alarms_level; g_model.frsky.channels[i].alarms_greater = v4->frsky.channels[i].alarms_greater; g_model.frsky.channels[i].barMin = 0; g_model.frsky.channels[i].barMax = 0; } } memset(&g_model.phaseData[0], 0, sizeof(g_model.phaseData)); memset(&g_model.funcSw[0], 0, sizeof(g_model.funcSw)); if (trimSw) { g_model.funcSw[0].swtch = trimSw; g_model.funcSw[0].func = FUNC_INSTANT_TRIM; } for (uint8_t i=0; i<NUM_STICKS; i++) setTrimValue(0, i, trims[i]); g_model.ppmFrameLength = 0; theFile.writeRlc(FILE_MODEL(id), FILE_TYP_MODEL, (uint8_t*)&g_model, sizeof(g_model), 200); } } g_eeGeneral.myVers = EEPROM_VER; theFile.writeRlc(FILE_GENERAL, FILE_TYP_GENERAL, (uint8_t*)&g_eeGeneral, sizeof(EEGeneral), 200); return sizeof(EEGeneral); } return 0; }
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; }
unsigned long Gruvin9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) { std::cout << "trying " << getName() << " import... "; std::bitset<NUM_ERRORS> errors; if (size != this->getEEpromSize()) { std::cout << "wrong size\n"; errors.set(WRONG_SIZE); return errors.to_ulong(); } if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_STOCK)) { std::cout << "wrong file system\n"; errors.set(WRONG_FILE_SYSTEM); return errors.to_ulong(); } efile->openRd(FILE_GENERAL); uint8_t version; if (efile->readRlc2(&version, 1) != 1) { std::cout << "no\n"; errors.set(UNKNOWN_ERROR); return errors.to_ulong(); } if (version == 0) { efile->openRd(FILE_GENERAL); if (efile->readRlc1(&version, 1) != 1) { std::cout << "no\n"; errors.set(UNKNOWN_ERROR); return errors.to_ulong(); } } std::cout << "version " << (unsigned int)version << " "; switch(version) { case 5: case 100: case 101: case 102: case 103: case 104: case 105: // subtrims(16bits) + function switches added case 106: // trims(10bits), no subtrims break; default: std::cout << "not gruvin9x\n"; errors.set(NOT_GRUVIN9X); return errors.to_ulong(); } efile->openRd(FILE_GENERAL); if (version == 5) { if (!loadGeneral<Gruvin9xGeneral_v103>(radioData.generalSettings, 1)) { errors.set(UNKNOWN_ERROR); return errors.to_ulong(); } } else if (version < 104) { if (!loadGeneral<Gruvin9xGeneral_v103>(radioData.generalSettings)) { errors.set(UNKNOWN_ERROR); return errors.to_ulong(); } } else if (version <= 106) { if (!loadGeneral<Gruvin9xGeneral_v104>(radioData.generalSettings)) { errors.set(UNKNOWN_ERROR); return errors.to_ulong(); } } else { std::cout << "ko\n"; errors.set(UNKNOWN_ERROR); return errors.to_ulong(); } for (int i=0; i<getMaxModels(); i++) { efile->openRd(FILE_MODEL(i)); if (version == 5) { loadModel<Gruvin9xModelData_v102>(radioData.models[i], radioData.generalSettings.stickMode+1, 1); } else if (version < 103) { loadModel<Gruvin9xModelData_v102>(radioData.models[i], radioData.generalSettings.stickMode+1); } else if (version == 103) { loadModel<Gruvin9xModelData_v103>(radioData.models[i], radioData.generalSettings.stickMode+1); } else if (version == 105) { loadModel<Gruvin9xModelData_v105>(radioData.models[i], radioData.generalSettings.stickMode+1); } else if (version == 106) { loadModel<Gruvin9xModelData_v106>(radioData.models[i], radioData.generalSettings.stickMode+1); } else { std::cout << "ko\n"; errors.set(UNKNOWN_ERROR); return errors.to_ulong(); } } std::cout << "ok\n"; errors.set(NO_ERROR); return errors.to_ulong(); }
void eeLoadModel(uint8_t id) { if(id>=MAX_MODELS) return; //paranoia theFile.openRd(FILE_MODEL(id)); uint16_t sz = 0; if(theFile.readRlc2((uint8_t*)&g_model,sizeof(g_model.name)+1) == (sizeof(g_model.name)+1)){ theFile.openRd(FILE_MODEL(id)); if(g_model.mdVers < MDVERS192){ sz = theFile.readRlc1((uint8_t*)&g_model, sizeof(g_model)); }else{ sz = theFile.readRlc2((uint8_t*)&g_model, sizeof(g_model)); } } // #if 0 // if( sz == sizeof(ModelData_r0) ){ // printf("converting model data t0 r84\n"); // char* pSrc = ((char*)&g_model) + sizeof(ModelData_r0); //Pointers behind the end // char* pDst = ((char*)&g_model) + sizeof(ModelData_r84); // ModelData_r84 *model84 = (ModelData_r84*)&g_model; // #define sizeof84(memb) sizeof(((ModelData_r84*)0)->memb) // fullCopy(sizeof84(trimData)+sizeof84(curves9)+sizeof84(curves5)); // // partCopy(sizeof84(mixData), sizeof(MixData_r0)*20); // // for(uint8_t i=0; i<DIM(model84->expoData); i++){ // partCopy(sizeof(ExpoData_r84), sizeof(ExpoData_r0)); // } // sz = sizeof(ModelData_r84); // model84->mdVers = MDVERS84; // } // #endif if( sz == sizeof(ModelData_r84) && g_model.mdVers == MDVERS84) { printf("converting model data from r84 to r143\n"); ModelData_r84 *model84 = (ModelData_r84*)&g_model; ModelData_r143 *model143 = (ModelData_r143*)&g_model; for(int8_t i=3; i>=0; i--){ int16_t val = trimExp2(model84->trimData[i].trim) + model84->trimData[i].trimDef_lt133; model143->trimData[i].itrim = trimRevert2(val); model143->trimData[i].tmode = 0; } memmove(&model143->curves5, &model84->curves5, sizeof(model84->curves5)+sizeof(model84->curves9)); memset(model143->curves3, 0, sizeof(model143->curves3)); model143->curves3[0][2] = 100; model143->curves3[2][0] = 100; model143->curves3[2][2] = 100; model143->curves3[1][0] = -100; sz = sizeof(ModelData_r143); model84->mdVers = MDVERS143; } if( sz == sizeof(ModelData_r143) && g_model.mdVers == MDVERS143) { printf("converting model data from r143 to r167\n"); ModelData_r143 *model143 = (ModelData_r143*)&g_model; ModelData_r167 *model167 = (ModelData_r167*)&g_model; for(int8_t i=0; i<NUM_CHNOUT; i++){ int8_t v = model143->limitData[i].min-100; model167->limitData[i].min = add7Bit(val2idx50_150(v),40); model167->limitData[i].scale = 0; v = model143->limitData[i].max+100; model167->limitData[i].max = add7Bit(val2idx50_150(v),-40); model167->limitData[i].binSwtch = 0; } model143->mdVers = MDVERS167; } if( sz == sizeof(ModelData_r167) && g_model.mdVers == MDVERS167) { printf("converting model data from r167 to r171\n"); ModelData_r167 *model167 = (ModelData_r167*)&g_model; ModelData_r171 *model171 = (ModelData_r171*)&g_model; ExpoData_r84 *hlpExp = (ExpoData_r84*) ((char*)&model171->expoTab +sizeof(model171->expoTab) -sizeof(model167->expoData)); // old:20B new:45B // move old to end // clr unused start 25B // interpret old to new <= 3*8=24B // clr old at end 20B // memmove(hlpExp, &model167->expoData, sizeof(ModelData_r167)-offsetof(ModelData_r167,expoData)); memset(model171->expoTab, 0, sizeof(model171->expoTab) -sizeof(model167->expoData)); for(int8_t i=0,j=0; i<4; i++){ if(hlpExp[i].expNorm || hlpExp[i].expNormWeight){ model171->expoTab[j].drSw = hlpExp[i].drSw ? -hlpExp[i].drSw : 0; model171->expoTab[j].chn = convertMode(i); model171->expoTab[j].mode3 = EM_BOTH; model171->expoTab[j].exp5 = val2idx15_100(hlpExp[i].expNorm); model171->expoTab[j].weight6 =val2idx30_100(hlpExp[i].expNormWeight+100); j++; } if(hlpExp[i].drSw && (hlpExp[i].expDr || hlpExp[i].expSwWeight)){ model171->expoTab[j].drSw = hlpExp[i].drSw; model171->expoTab[j].chn = convertMode(i); model171->expoTab[j].mode3 = EM_BOTH; model171->expoTab[j].exp5 = val2idx15_100(hlpExp[i].expDr); model171->expoTab[j].weight6 =val2idx30_100(hlpExp[i].expSwWeight+100); j++; } } memset(hlpExp, 0, sizeof(model167->expoData)); sz = sizeof(ModelData_r171); for(uint8_t i=0;i<MAX_MIXERS;i++){ MixData_r0 &md = model171->mixData[i]; if(md.destCh==0) break; md.srcRaw = convertMode(md.srcRaw-1)+1; } if(g_eeGeneral.stickMode & 1) memswap(&model171->trimData[1], &model171->trimData[2],sizeof(model171->trimData[1])); if(g_eeGeneral.stickMode & 2) memswap(&model171->trimData[0], &model171->trimData[3],sizeof(model171->trimData[0])); model167->mdVers = MDVERS171; } if( sz == sizeof(ModelData_r171) && g_model.mdVers == MDVERS171) { printf("converting model data from r171 to r192\n"); ModelData_r171 *model171 = (ModelData_r171*)&g_model; ModelData_r192 *model192 = (ModelData_r192*)&g_model; memmove(&model192->curves3, &model171->curves3, sizeof(ModelData_r171)-offsetof(ModelData_r171,curves3)); for(uint8_t i=MAX_MIXERS;i>0;){i--; MixData_r0 &md0 = model171->mixData[i]; MixData_r192 &md192 = model192->mixData[i]; uint8_t dc=md0.destCh; if(dc==0){ memset(&md192,0,5); continue; } memmove(&md192.weight,&md0.weight,3); // 0 1 2 3 4 5 6 7 8 9 uint8_t sr=md0.srcRaw; //0 RUD ELE THR AIL P1 P2 P3 MAX FUL X1-4 memset(&md192,0,2); md192.destCh =dc; if(sr>4){ if(sr<=9) md192.switchMode=1; //P1-3, FUL I=-1 if(sr==8) md192.switchMode=2; //MAX I=0 if(sr==9) sr=8; //FUL->MAX if(sr>9) sr+=8;//space for ch1-ch8 if(sr>7) sr+=3;//space for p1-3 } md192.srcRaw =sr-1; //now start with 0 if(md192.weight<0 && md192.curve){ md192.weight = -md192.weight; md192.curveNeg = 1; } } sz = sizeof(ModelData_r192); model171->mdVers = MDVERS192; } if( sz == sizeof(ModelData_r192) && g_model.mdVers == MDVERS192) { printf("converting model data from r192 to r204\n"); ModelData_r192 *model192 = (ModelData_r192*)&g_model; ModelData_r204 *model204 = (ModelData_r204*)&g_model; memmove(&model204->trimData,&model192->trimData,sizeof(model192->trimData)); memset(model204->switchTab,0,sizeof(model204->switchTab)); model204->trimData[0].tmode=0; model204->trimData[1].tmode=0; model204->trimData[2].tmode=0; model204->trimData[3].tmode=0; sz = sizeof(ModelData_r204); model204->mdVers = MDVERS204; } if( sz == sizeof(ModelData_TOP) && g_model.mdVers == MDVERS_TOP) { return; } printf("bad model%d data using default\n",id+1); modelDefault(id); }