Compare commits

..

2 Commits

Author SHA1 Message Date
c57205059e Prvni funkcni verze 2018-12-11 08:29:06 +01:00
5d3c79fe91 Prvni odevzdani - netestovano!!! 2018-12-11 08:21:23 +01:00
6 changed files with 193 additions and 0 deletions

34
.gitignore vendored Normal file
View File

@ -0,0 +1,34 @@
# ---> C++
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app

20
keywords.txt Normal file
View File

@ -0,0 +1,20 @@
#######################################
# Syntax Coloring Map
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
#######################################
# Methods and Functions (KEYWORD2)
#######################################
#######################################
# Instances (KEYWORD2)
#######################################
#######################################
# Constants (LITERAL1)
#######################################

22
library.json Normal file
View File

@ -0,0 +1,22 @@
{
"name":"encipheredEEPROMStrings",
"description":"Store and retrieve EEPROM strings",
"keywords":"eeprom,storage",
"authors":
{
"name": "Pavel Brychta",
"maintainer": true
},
"repository":
{
"type": "git",
"url": "http://git.xpablo.cz/xPablo.cz/encipheredEEPROMStrings.git"
},
"version": "1.0",
"license": "MIT",
"frameworks": "arduino",
"platforms": ["espressif8266","espressif32"],
"build": {
"libCompatMode": 2
}
}

9
library.properties Normal file
View File

@ -0,0 +1,9 @@
name=encipheredEEPROMStrings
version=1.0
author=Pavel Brychta
maintainer=Pavel Brychta
sentence=Store and retrieve EEPROM strings
paragraph=Store and retrieve EEPROM strings
category=Other
url=http://git.xpablo.cz/xPablo.cz/encipheredEEPROMStrings
architectures=esp8266,esp32

View File

@ -0,0 +1,82 @@
#include "encipheredEEPROMStrings.h"
#include <EEPROM.h>
#if defined(ESP8266)
extern "C" {
#include "user_interface.h"
}
#define ESP_getChipId() (ESP.getChipId())
#else
#include <esp_wifi.h>
#define ESP_getChipId() ((uint32_t)ESP.getEfuseMac())
#endif
String EES_readString(unsigned int start, size_t maxlen)
{
uint8_t key[4];
unsigned int enciphidx = 0;
String result;
unsigned int top = EEPROM.read(start);
unsigned int i;
result.reserve(maxlen);
uint32_t cid = ESP_getChipId();
uint32_t *pkey = (uint32_t *)&key[0];
*pkey = cid;
if ((top > 0) && (top < (maxlen - 2)))
{
uint8_t b;
for (i = start + 1; i < + start + top + 1; ++i)
{
b = EEPROM.read(i);
b ^= key[enciphidx];
++enciphidx;
enciphidx %= sizeof(key);
result.concat(char(b));
}
b = EEPROM.read(i) ^ key[enciphidx];
if (b != 0)
{
result = F(""); // spatna ukoncovaci nula - neplatny retezec
}
}
return result;
}
bool EES_storeString(unsigned int start, size_t maxlen, String &string)
{
uint8_t key[4];
unsigned int enciphidx = 0;
unsigned int si = 0;
unsigned int top;
char c;
bool result = false; // retezec nebyl ulozeny cely (nevesel s do bufferu)
unsigned int i;
if (string.length() > maxlen - 2)
top = maxlen - 2;
else
{
result = true; // retezec se do urceneho mista vejde
top = string.length();
}
uint32_t cid = ESP_getChipId();
uint32_t *pkey = (uint32_t *)&key[0];
*pkey = cid;
EEPROM.write(start, (uint8_t)top); // ulozime delku retezce (pouzite pr kontrolu pri vycitani)
for (i = start + 1; i < start + top + 1; ++i)
{
c = string[si];
c ^= key[enciphidx];
++enciphidx;
enciphidx %= sizeof(key);
EEPROM.write(i, c);
++si;
}
c = 0 ^ key[enciphidx];
EEPROM.write(i, c); // ukoncovaci a kontrolni nula
return result;
}

View File

@ -0,0 +1,26 @@
/* Knihovna pro ukladani a cteni retezcu do/z EEPROM.
* Retezce jsou ulozeny jednoduse sifrovane pomoci XOR sifry.
* @author Pavel Brychta http://www.xpabo.cz
*/
#include <Arduino.h>
/**
* @brief Cteni sifrovanych retezcu z EEPROM
*
* @param[in] start Pocatecni adresa retezce v EEPROM
* @param[in] maxlen Maximalni delka retezce
*
* @return Vycteny a desifrovany retezec
*/
String EES_readString(unsigned int start, size_t maxlen);
/**
* @brief Zapis retezcu do EEPROM
*
* @param[in] start Pocatecni adresa retezce v EEPROM
* @param[in] maxlen Maximalni delka retezce
* @param string Ukladany retezec
*
* @return Priznak, zda se zapis podaril
*/
bool EES_storeString(unsigned int start, size_t maxlen, String &string);