Exemple #1
0
void str2zchar(char *dest, const char *src, int size)
{
  memset(dest, 0, size);
  for (int c=0; c<size && src[c]; c++) {
    dest[c] = char2idx(src[c]);
  }
}
Exemple #2
0
static inline void
init_idxtab(struct fastfind_info *info)
{
	int i;

	for (i = 0; i < FF_MAX_CHARS; i++)
		info->idxtab[i] = char2idx((unsigned char) i, info);
}
Exemple #3
0
static void validateName( char *name, uint8_t size )
{
	for(uint8_t i=0; i<size;i++) // makes sure name is valid
  {
//		uint8_t idx = char2idx(name[i]);
		name[i] = idx2char(char2idx(name[i])) ;
	}
}
Exemple #4
0
struct fastfind_index *
fastfind_index(struct fastfind_index *index, enum fastfind_flags flags)
{
	struct fastfind_key_value *p;
	struct fastfind_info *info;

	assert(index && index->reset && index->next);
	if_assert_failed goto return_error;

	info = init_fastfind(index, flags);
	if (!info) goto return_error;

	/* First search min, max, count and uniq_chars. */
	index->reset();

	while ((p = index->next())) {
		int key_len = strlen(p->key);
		int i;

		assert(key_len > 0 && key_len <= FF_MAX_KEYLEN);
		if_assert_failed goto return_error;

		if (key_len < info->min_key_len)
			info->min_key_len = key_len;

		if (key_len > info->max_key_len)
			info->max_key_len = key_len;

		for (i = 0; i < key_len; i++) {
			/* ifcase() test should be moved outside loops but
			 * remember we call this routine only once per list.
			 * So I go for code readability vs performance here.
			 * --Zas */
			int k = ifcase(p->key[i]);

			assert(k < FF_MAX_CHARS);
			if_assert_failed goto return_error;

			if (char2idx(k, info) == -1) {
				assert(info->uniq_chars_count < FF_MAX_CHARS);
				if_assert_failed goto return_error;

				info->uniq_chars[info->uniq_chars_count++] = k;
			}
		}

		info->count++;
	}
void setEEPROMZString(char *dst, const char *src, int size)
{
  for (int i=size-1; i>=0; i--)
    dst[i] = char2idx(src[i]);
}
Exemple #6
0
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;
}
void statAlphaTbl(char *s, int *tbl) {
    for (; *s; s++) {
        tbl[char2idx(*s)]++;
    }
}