//Description: Reads an unsigned long value from the specified address of EEPROM // Assumes that the value is stored in Big Endian format. unsigned long eepromReadLong(unsigned int uiAddress){ unsigned long tempValue=0; tempValue = eepromReadInt(uiAddress); //Read the first 2 bytes of data tempValue = tempValue << 16; //Shift the first two bytes of data into the upper section of the temp Value. tempValue |= eepromReadInt(uiAddress + 2); //Get the second 2 bytes of data and put them in the lower half of the temp value. return tempValue; }
uint8_t loadSettings(STORAGE& storage, EncoderChannel& channel, int& addr) { channel.average = eepromReadInt(storage, addr); addr += 2; channel.minValue = eepromReadInt(storage, addr); addr += 2; channel.maxValue = eepromReadInt(storage, addr); addr += 2; return 0; }
void Settings::load() { if ( EEPROM.read ( checkNumAdr ) != 0 && EEPROM.read ( checkNumAdr ) != checkNum ) { Serial.println ( "" ); Serial.println ( "[E] ERROR: Checknum mismatch! Current checknum=" + ( String ) checkNum + "; stored checknum=" + ( String ) EEPROM.read ( checkNumAdr ) ); Serial.println ( "" ); reset (); return ; } else { Serial.println ( "" ); Serial.println ( "[+] Current checknum=" + ( String ) checkNum + "; stored checknum=" + ( String ) EEPROM.read ( checkNumAdr ) ); Serial.println ( "" ); } ssidLen = EEPROM.read ( ssidLenAdr ); passwordLen = EEPROM.read ( passwordLenAdr ); if ( ssidLen < 1 || ssidLen > 32 || passwordLen < 8 && passwordLen != 0 || passwordLen > 32 ) { reset (); return ; } ssid = ""; password = ""; for ( int i = 0; i < ssidLen; i++ ) { ssid += ( char ) EEPROM.read ( ssidAdr + i ); } for ( int i = 0; i < passwordLen; i++ ) { password += ( char ) EEPROM.read ( passwordAdr + i ); } ssidHidden = ( bool ) EEPROM.read ( ssidHiddenAdr ); wifiClient = ( bool ) EEPROM.read ( wifiClientAdr ); ssidClientLen = EEPROM.read ( ssidClientLenAdr ); for ( int i = 0; i < ssidClientLen; i++ ) { ssidClient += ( char ) EEPROM.read ( ssidClientAdr + i ); } passwordClientLen = EEPROM.read ( passwordClientLenAdr ); for ( int i = 0; i < passwordClientLen; i++ ) { passwordClient += ( char ) EEPROM.read ( passwordClientAdr + i ); } hostnameLen = EEPROM.read ( hostnameLenAdr ); for ( int i = 0; i < hostnameLen; i++ ) { hostname += ( char ) EEPROM.read ( hostnameAdr + i ); } if ( ( int ) EEPROM.read ( apChannelAdr ) >= 1 && ( int ) EEPROM.read ( apChannelAdr ) <= 14 ) { apChannel = ( int ) EEPROM.read ( apChannelAdr ); } else { apChannel = 1; } for ( int i = 0; i < 6; i++ ) macAP.setAt ( ( uint8_t ) EEPROM.read ( macAPAdr + i ), i ); if ( !macAP.valid () ) { macAP.set ( defaultMacAP ); } isMacAPRand = ( bool ) EEPROM.read ( isMacAPRandAdr ); apScanHidden = ( bool ) EEPROM.read ( apScanHiddenAdr ); deauthReason = EEPROM.read ( deauthReasonAdr ); attackTimeout = eepromReadInt ( attackTimeoutAdr ); attackPacketRate = EEPROM.read ( attackPacketRateAdr ); clientScanTime = EEPROM.read ( clientScanTimeAdr ); useLed = ( bool ) EEPROM.read ( useLedAdr ); channelHop = ( bool ) EEPROM.read ( channelHopAdr ); multiAPs = ( bool ) EEPROM.read ( multiAPsAdr ); multiAttacks = ( bool ) EEPROM.read ( multiAttacksAdr ); macInterval = eepromReadInt ( macIntervalAdr ); beaconInterval = ( bool ) EEPROM.read ( beaconIntervalAdr ); setLedPin ( ( int ) EEPROM.read ( ledPinAdr ) ); isSettingsLoaded = 1; darkMode = ( bool ) EEPROM.read ( darkModeAdr ); cache = ( bool ) EEPROM.read ( cacheAdr ); serverCache = ( int ) EEPROM.read ( serverCacheAdr ); newUser = ( bool ) EEPROM.read ( newUserAdr ); detectorChannel = ( int ) EEPROM.read ( detectorChannelAdr ); detectorAllChannels = ( bool ) EEPROM.read ( detectorAllChannelsAdr ); alertPin = ( int ) EEPROM.read ( alertPinAdr ); invertAlertPin = ( bool ) EEPROM.read ( invertAlertPinAdr ); detectorScanTime = ( int ) EEPROM.read ( detectorScanTimeAdr ); pinNamesLen = EEPROM.read ( pinNamesLenAdr ); pinNames = ""; for ( int i = 0; i < pinNamesLen; i++ ) { pinNames += ( char ) EEPROM.read ( pinNamesAdr + i ); } }
void deviceEepromHandleRawData(char commandHeader, InputStream* inputStream, OutputStream* outputStream) { _deviceEepromCheckInitialized(); if (commandHeader == COMMAND_RELOAD_EEPROM) { ackCommand(outputStream, EEPROM_DEVICE_HEADER, COMMAND_RELOAD_EEPROM); eeprom_->eepromLoad(eeprom_); } else if (commandHeader == COMMAND_DUMP_TO_FILE_EEPROM) { ackCommand(outputStream, EEPROM_DEVICE_HEADER, COMMAND_DUMP_TO_FILE_EEPROM); eeprom_->eepromDump(eeprom_); } else if (commandHeader == COMMAND_DUMP_TO_LOG_OUTPUT_STREAM_EEPROM) { ackCommand(outputStream, EEPROM_DEVICE_HEADER, COMMAND_DUMP_TO_LOG_OUTPUT_STREAM_EEPROM); OutputStream* debugOutputStream = getInfoOutputStreamLogger(); dumpEepromToOutputStream(eeprom_, debugOutputStream, 0, eeprom_->maxIndex); } else if (commandHeader == COMMAND_DUMP_PARTIAL_CONTENT_TO_LOG_OUTPUT_STREAM_EEPROM) { ackCommand(outputStream, EEPROM_DEVICE_HEADER, COMMAND_DUMP_PARTIAL_CONTENT_TO_LOG_OUTPUT_STREAM_EEPROM); unsigned long startAddress = readHex4(inputStream); checkIsSeparator(inputStream); unsigned long length = readHex4(inputStream); OutputStream* debugOutputStream = getInfoOutputStreamLogger(); dumpEepromToOutputStream(eeprom_, debugOutputStream, startAddress, startAddress + length); } else if (commandHeader == COMMAND_CLEAR_EEPROM) { ackCommand(outputStream, EEPROM_DEVICE_HEADER, COMMAND_CLEAR_EEPROM); unsigned long startAddress = readHex4(inputStream); checkIsSeparator(inputStream); unsigned long endAddress = readHex4(inputStream); clearEeprom(eeprom_, startAddress, endAddress); } else if (commandHeader == COMMAND_READ_BYTE_EEPROM) { ackCommand(outputStream, EEPROM_DEVICE_HEADER, COMMAND_READ_BYTE_EEPROM); unsigned long address = readHex4(inputStream); char value = eeprom_->eepromReadChar(eeprom_, address); appendHex2(outputStream, value); } else if (commandHeader == COMMAND_READ_INT_EEPROM) { ackCommand(outputStream, EEPROM_DEVICE_HEADER, COMMAND_READ_INT_EEPROM); unsigned long address = readHex4(inputStream); int value = eepromReadInt(eeprom_, address); appendHex4(outputStream, value); } else if (commandHeader == COMMAND_WRITE_BYTE_EEPROM) { ackCommand(outputStream, EEPROM_DEVICE_HEADER, COMMAND_WRITE_BYTE_EEPROM); unsigned long address = readHex4(inputStream); checkIsSeparator(inputStream); char data = readHex2(inputStream); eeprom_->eepromWriteChar(eeprom_, address, data); } else if (commandHeader == COMMAND_WRITE_INT_EEPROM) { ackCommand(outputStream, EEPROM_DEVICE_HEADER, COMMAND_WRITE_INT_EEPROM); unsigned long address = readHex4(inputStream); checkIsSeparator(inputStream); int data = readHex4(inputStream); eepromWriteInt(eeprom_, address, data); } else if (commandHeader == COMMAND_READ_BLOCK_EEPROM) { ackCommand(outputStream, EEPROM_DEVICE_HEADER, COMMAND_READ_BLOCK_EEPROM); unsigned long address = readHex4(inputStream); int index; for (index = 0; index < EEPROM_DEVICE_READ_BLOCK_LENGTH; index++) { char value = eeprom_->eepromReadChar(eeprom_, address + index); if (index > 0) { appendSeparator(outputStream); } appendHex2(outputStream, value); } } else if (commandHeader == COMMAND_WRITE_BLOCK_EEPROM) { ackCommand(outputStream, EEPROM_DEVICE_HEADER, COMMAND_WRITE_BLOCK_EEPROM); unsigned long address = readHex4(inputStream); char data; int index; for (index = 0; index < EEPROM_DEVICE_WRITE_BLOCK_LENGTH; index++) { checkIsSeparator(inputStream); data = readHex2(inputStream); eeprom_->eepromWriteChar(eeprom_, address + index, data); } } else if (commandHeader == COMMAND_INTENSIVE_TEST) { ackCommand(outputStream, EEPROM_DEVICE_HEADER, COMMAND_INTENSIVE_TEST); unsigned long address = readHex4(inputStream); checkIsSeparator(inputStream); unsigned long length = readHex4(inputStream); unsigned int errorCount = 0; unsigned int index; // Writes for (index = 0; index < length; index++) { unsigned char value = (unsigned char) index; eeprom_->eepromWriteChar(eeprom_, address + index, value); } // Reads for (index = 0; index < length; index++) { unsigned char value = (unsigned char) eeprom_->eepromReadChar(eeprom_, address + index); if (value != (unsigned char)index) { if (errorCount < 255) { errorCount++; } } } appendHex4(outputStream, errorCount); } }