AutoConnectCredential offset supported

pull/8/head
Hieromon Ikasamo 7 years ago
parent 1cbaa69877
commit 3a310a2c30
  1. 12
      .gitignore
  2. 11
      src/AutoConnectCredentail.cpp
  3. 2
      src/AutoConnectCredentail.h

12
.gitignore vendored

@ -1,2 +1,12 @@
# Files generated by build
/site
.vs/
__vm/
debug/
img/
*.tmp
*.TMP
*.sln
*.vcxproj
*.vcxproj.filters
.pioenvs
.piolibdeps

@ -11,7 +11,7 @@
#include "AutoConnectCredentail.h"
#define AC_IDENTIFIER "AC_CREDT"
#define AC_HEADERSIZE ((int)(AC_IDENTIFIER_OFFSET + sizeof(AC_IDENTIFIER) - 1 + sizeof(uint8_t) + sizeof(uint16_t)))
#define AC_HEADERSIZE ((int)(_offset + sizeof(AC_IDENTIFIER) - 1 + sizeof(uint8_t) + sizeof(uint16_t)))
/**
* AutoConnectCredential constructor takes the available count of saved
@ -33,15 +33,22 @@
* Free area are filled with FF, which is reused as an area for insertion.
*/
AutoConnectCredential::AutoConnectCredential() {
AutoConnectCredential(AC_IDENTIFIER_OFFSET);
}
AutoConnectCredential::AutoConnectCredential(uint16_t offset) {
char id_c[sizeof(AC_IDENTIFIER) - 1];
uint8_t c;
// Save offset for the credential area.
_offset = offset;
EEPROM.begin(AC_HEADERSIZE);
// Validate the save area of the EEPROM.
// If it is a valid area, retrieve the stored number of entries,
// if the identifier is not saved, initialize the EEPROM area.
for (c = AC_IDENTIFIER_OFFSET; c < AC_IDENTIFIER_OFFSET + sizeof(id_c); c++) {
for (c = _offset; c < _offset + sizeof(id_c); c++) {
id_c[c] = static_cast<char>(EEPROM.read(c));
}
if (!strncmp(id_c, AC_IDENTIFIER, sizeof(id_c))) {

@ -31,6 +31,7 @@ extern "C" {
class AutoConnectCredential {
public:
AutoConnectCredential();
AutoConnectCredential(uint16_t offset);
~AutoConnectCredential();
uint8_t entries() { return _entries; }
bool del(const char* ssid);
@ -44,6 +45,7 @@ class AutoConnectCredential {
uint16_t _containSize; /**< Container size */
int _dp; /**< The current address in EEPROM */
int _ep; /**< The current entry address in EEPROM */
uint16_t _offset; /**< The offset for the saved area of credentials in EEPROM. */
};
#endif // _AUTOCONNECTCREDENTAIL_H_

Loading…
Cancel
Save