void Eeprom::writeEeprom(const EepromLocation& location, const Value& val) { //get the type and location from the EepromLocation object ValueType type = location.valueType(); uint16 eepromLoc = location.location(); //determine which writeEeprom function to call, based on the valueType switch(type) { case valueType_uint16: writeEeprom(eepromLoc, val.as_uint16()); break; case valueType_float: writeEeprom_float(eepromLoc, val.as_float()); break; case valueType_uint32: writeEeprom_uint32(eepromLoc, val.as_uint32()); break; case valueType_int16: writeEeprom_int16(eepromLoc, val.as_int16()); break; default: assert(false); //we are trying to write a value with an invalid type? writeEeprom(eepromLoc, val.as_uint16()); //just default to uint16 } }
void Eeprom::writeEeprom_float(uint16 location, float value) { //Note: floats in EEPROM for Wireless devices are in Little Endian uint8 b1, b2, b3, b4; //split the float into its 4 bytes (in little endian) Utils::split_float(value, b1, b2, b3, b4, Utils::littleEndian); //write the first eeprom location writeEeprom(location, Utils::make_uint16(b1, b2)); //write the second eeprom location writeEeprom(location + 2, Utils::make_uint16(b3, b4)); //TODO: possibly throw a custom exception if this throws? We wrote the msw but not the lsw }
void Eeprom::writeEeprom_uint32(uint16 location, uint32 value) { uint8 low = 0; uint8 b2 = 0; uint8 b3 = 0; uint8 high = 0; //split the uint32 into 2 parts Utils::split_uint32(value, low, b2, b3, high); //try to write the msw writeEeprom(location, Utils::make_uint16(low, b2)); //try to write the lsw writeEeprom(location + 2, Utils::make_uint16(b3, high)); //TODO: possibly throw a custom exception if this throws? We wrote the msw but not the lsw }
void WirelessNode_Impl::resetRadio() { static const uint16 RESET_RADIO = 0x02; //cycle the radio on the node by writing a 2 to the CYCLE_POWER location writeEeprom(NodeEepromMap::CYCLE_POWER, Value::UINT16(RESET_RADIO)); Utils::threadSleep(200); }
struct I2C_module* configCompass() { // initialize I2C0 for compass struct I2C_module* Compass; volatile WORD test = 0; BYTE dat[3]; Compass = I2C_masterModule(0,'b',0x0C); dat[0] = 0x4F; I2C_enableModule(Compass, ENABLE); #ifndef COMMS_DISCONNECTED I2C_sendDataBytes(Compass,0x42, dat, 1); writeEeprom(Compass, 0x06, 0x0F); // set compass to average 16 times writeEeprom(Compass, 0x08, 0x72); // set to continuous mode, 20HZ, Periodic set/reset #endif return Compass; }
void WirelessNode_Impl::changeFrequency(WirelessTypes::Frequency frequency) { //make sure the frequency is within the correct range, change if not Utils::checkBounds_min(frequency, WirelessTypes::freq_11); Utils::checkBounds_max(frequency, WirelessTypes::freq_26); //write the new frequency to the node writeEeprom(NodeEepromMap::FREQUENCY, Value::UINT16(static_cast<uint16>(frequency))); //reset the radio on the node to commit the change resetRadio(); }
void clearSettings() { memset(&herp,0,sizeof(herp)); herp.ver=VER; memcpy_P(herp.welcome,PSTR("Welcome"),7); herp.viv_count=1; memcpy_P(&herp.vivs[0].name,PSTR("VIV #1"),6); herp.vivs[0].temp.target=28.9; herp.vivs[0].temp.hi=(byte)((32.0f-herp.vivs[0].temp.target)*10); herp.vivs[0].temp.lo=(byte)abs((26.5f-herp.vivs[0].temp.target)*10); herp.vivs[0].relay_pin=3; herp.flags|=(TEMP_F << TEMP_FLAG); writeEeprom(); didReset=true; }
void WirelessNode_Impl::cyclePower() { static const uint16 RESET_NODE = 0x01; //cycle the power on the node by writing a 1 to the CYCLE_POWER location writeEeprom(NodeEepromMap::CYCLE_POWER, Value::UINT16(RESET_NODE)); Utils::threadSleep(250); //attempt to ping the node a few times to see if its back online bool pingSuccess = false; uint8 retries = 0; while(!pingSuccess && retries <= 15) { pingSuccess = ping().success(); retries++; } }
void programPage(uint16_t address) { uint16_t length = (getch() << 8) | getch(); // It is weird that makeWord does not work here uint8_t memtype = getch(); switch (memtype) { case 'F': writeFlash(address, length); break; case 'E': writeEeprom(address, length); break; default: Serial.write(STK_FAILED); break; } }
void Eeprom::writeEeprom_int16(uint16 location, int16 value) { writeEeprom(location, static_cast<uint16>(value)); }
void FlashFirmwareDialog::startFlash(const QString &filename) { bool backup = g.backupOnFlash(); close(); ProgressDialog progressDialog(this, tr("Write Firmware to Radio"), CompanionIcon("write_flash.png")); // check hardware compatibility if requested if (g.checkHardwareCompatibility()) { QString tempFirmware = generateProcessUniqueTempFileName("flash-check.bin"); if (!readFirmware(tempFirmware, progressDialog.progress())) { QMessageBox::warning(this, tr("Firmware check failed"), tr("Could not check firmware from radio")); return; } FirmwareInterface previousFirmware(tempFirmware); qunlink(tempFirmware); FirmwareInterface newFirmware(filename); qDebug() << "startFlash: checking firmware compatibility between " << tempFirmware << "and" << filename; if (!newFirmware.isHardwareCompatible(previousFirmware)) { QMessageBox::warning(this, tr("Firmware check failed"), tr("New firmware is not compatible with the one currently installed!")); if (isTempFileName(filename)) { qDebug() << "startFlash: removing temporary file" << filename; qunlink(filename); } return; } } // backup if requested bool result = true; QString backupFilename; QString backupPath; if (backup) { backupPath = g.profile[g.id()].pBackupDir(); if (backupPath.isEmpty()) { backupPath=g.backupDir(); } backupFilename = backupPath + "/backup-" + QDateTime().currentDateTime().toString("yyyy-MM-dd-HHmmss") + ".bin"; result = readEeprom(backupFilename, progressDialog.progress()); sleep(2); } // flash result = (result && writeFirmware(filename, progressDialog.progress())); // restore if backup requested if (backup && result) { sleep(2); QString restoreFilename = generateProcessUniqueTempFileName("restore.bin"); if (!convertEEprom(backupFilename, restoreFilename, filename)) { QMessageBox::warning(this, tr("Conversion failed"), tr("Cannot convert Models and Settings for use with this firmware, original data will be used")); restoreFilename = backupFilename; } if (!writeEeprom(restoreFilename, progressDialog.progress())) { QMessageBox::warning(this, tr("Restore failed"), tr("Could not restore Models and Settings to Radio. The models and settings data file can be found at: %1").arg(backupFilename)); } } progressDialog.progress()->setInfo(tr("Flashing done")); progressDialog.exec(); if (isTempFileName(filename)) { qDebug() << "startFlash: removing temporary file" << filename; qunlink(filename); } }
//************************************************************************ void EEPROMClass::write(unsigned int address, uint8_t value) { writeEeprom((uint32_t)address, (uint8_t)value); }