gatewayTransportSend

This commit is contained in:
Dmitry Borisenko
2022-12-01 02:10:06 +01:00
parent 2c61580157
commit cb50965c3b
293 changed files with 67232 additions and 3 deletions

View File

@@ -0,0 +1,209 @@
/*
Copyright (c) 2014 Arduino. All right reserved.
This library is free software; you can redistribute it and / or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110 - 1301 USA
*/
#include "extEEPROM.h"
extEEPROM myEEPROM(kbits_256, 1, 64, 0x57);
void setup(void)
{
SerialUSB.begin(115200);
while (!SerialUSB) {
;
}
byte i2cStat = myEEPROM.begin(myEEPROM.twiClock100kHz);
if ( i2cStat != 0 ) {
SerialUSB.println(F("I2C Problem"));
}
SerialUSB.println(
F("EEPROM Memory commands: read:(a)(l)(r) , write:(a)(d)(w), next read data (n)"));
SerialUSB.println(F("- Commands TO PRESS:"));
SerialUSB.println(F("\t a : memory address to read / write"));
SerialUSB.println(F("\t d : data to write"));
SerialUSB.println(F("\t l : data to write"));
SerialUSB.println(F("\t r : read command"));
SerialUSB.println(F("\t w : write command"));
}
unsigned long address = 0;
const unsigned int maxDataSize = 1024; //0x8000; // 32 k bytes (32768 = 0x8000) = 256 kbits
byte data[maxDataSize] = {'p', 'i', 'p', 'p', 'o'};
unsigned int dataSize = 5;
void eprom_read_write(bool write)
{
byte i2cStat = 0;
if (write) {
i2cStat = myEEPROM.write(address, data, dataSize);
} else {
memset(data, 0, maxDataSize);
i2cStat = myEEPROM.read(address, data, dataSize);
}
if ( i2cStat != 0 ) {
//there was a problem
SerialUSB.print(F("I2C Problem: "));
if ( i2cStat == EEPROM_ADDR_ERR) {
SerialUSB.println(F("Wrong address"));
} else {
SerialUSB.print(F("I2C error: "));
SerialUSB.print(i2cStat);
SerialUSB.println(F(""));
}
}
}
void parse(char inChar)
{
const char addr_len = 5;
char addr_char[addr_len] = "";
const char data_len = 3;
char data_char[data_len] = "";
char size_char[data_len] = "";
char inc = 0, i = 0, j = 0;
switch (inChar) {
case 'a':
SerialUSB.print(F("Insert Address as 4 Hex chars (without '0x'): "));
while (i < 4) {
while (SerialUSB.available() <= 0)
;
inc = SerialUSB.read();
if (inc == 'q') {
return;
}
addr_char[i] = inc;
++i;
}
address = (unsigned long)strtol(addr_char, NULL, 16);
SerialUSB.println(address);
break;
case 'd':
SerialUSB.print(F("Insert Hex data sequence (without '0x'), return to enter: "));
memset(data, 0, maxDataSize);
while (true) {
while (SerialUSB.available() <= 0)
;
inc = SerialUSB.read();
if (inc == 'q') {
return;
}
if (inc == '\r' || inc == '\n') {
break;
}
if (inc >= 'a' && inc <= 'f') {
data[j] += inc - 'a' + 10;
} else if (inc >= 'A' && inc <= 'F') {
data[j] += inc - 'A' + 10;
} else if (inc >= '0' && inc <= '9') {
data[j] += inc - '0';
} else {
return;
}
if (i % 2) {
j++;
} else {
data[j] = data[j] << 4;
}
i++;
}
dataSize = j;
SerialUSB.println(dataSize);
SerialUSB.println(F(""));
break;
case 'l':
SerialUSB.print(F("Insert data len as 2 Hex chars (without '0x'): "));
while (i < 2) {
while (SerialUSB.available() <= 0)
;
inc = SerialUSB.read();
if (inc == 'q') {
return;
}
size_char[i] = inc;
++i;
if (inc == '\n') {
return;
}
}
dataSize = (unsigned int)strtol(size_char, NULL, 16);
SerialUSB.println(dataSize);
break;
case 'n':
address += dataSize;
/* FALLTHROUGH */
case 'r':
SerialUSB.print(F("reading address: "));
SerialUSB.println(address, HEX);
eprom_read_write(false);
for (i = 0; i < dataSize ; ++i) {
SerialUSB.print(data[i], HEX);
SerialUSB.print(F(" "));
}
SerialUSB.println();
break;
case 'w':
SerialUSB.print(F("writing at address: "));
SerialUSB.print(address, HEX);
SerialUSB.print(F(", len: "));
SerialUSB.println(address, dataSize);
for (i = 0; i < dataSize ; ++i) {
SerialUSB.print(data[i], HEX);
SerialUSB.print(F(" "));
}
eprom_read_write(true);
SerialUSB.println();
break;
case 'T':
SerialUSB.println(F("Memory test: writing and verifying the whole memory"));
break;
default:
break;
}
}
void loop(void)
{
if (SerialUSB.available() > 0) {
char inChar = SerialUSB.read();
SerialUSB.print(inChar);
parse(inChar);
}
delay(10);
}

View File

@@ -0,0 +1,176 @@
//Test extEEPROM library.
//Writes the EEPROM full of 32-bit integers and reads them back to verify.
//Wire a button from digital pin 6 to ground, this is used as a start button
//so the sketch doesn't do unnecessary EEPROM writes every time it's reset.
//Jack Christensen 09Jul2014
//Paolo Paolucci 17Mar2016 (fix 28Jun2017)
#include <extEEPROM.h> //https://github.com/PaoloP74/extEEPROM
//One 24LC256 EEPROMs on the bus
const uint32_t totalKBytes = 32; //for read and write test functions
extEEPROM eep(kbits_256, 1, 64); //device size, number of devices, page size
const uint8_t btnStart = 6; //start button
void setup(void)
{
pinMode(btnStart, INPUT_PULLUP);
Serial.begin(115200);
uint8_t eepStatus = eep.begin(eep.twiClock400kHz); //go fast!
if (eepStatus) {
Serial.print(F("extEEPROM.begin() failed, status = "));
Serial.println(eepStatus);
while (1);
}
Serial.println(F("Press button to start..."));
while (digitalRead(btnStart) == HIGH) {
delay(10); //wait for button push
}
uint8_t chunkSize =
64; //this can be changed, but must be a multiple of 4 since we're writing 32-bit integers
// eeErase(chunkSize, 0, totalKBytes * 1024 - 1);
eeWrite(chunkSize);
eeRead(chunkSize);
dump(0, 32); //the first 32 bytes
dump(32256, 64); //the last 64 bytes
//dump(32512, 64); //across the device boundary
//dump(65520, 16); //the last 16 bytes
}
void loop(void)
{
}
//write test data (32-bit integers) to eeprom, "chunk" bytes at a time
void eeWrite(uint8_t chunk)
{
chunk &= 0xFC; //force chunk to be a multiple of 4
uint8_t data[chunk];
uint32_t val = 0;
Serial.println(F("Writing..."));
uint32_t msStart = millis();
for (uint32_t addr = 0; addr < totalKBytes * 1024; addr += chunk) {
if ( (addr & 0xFFF) == 0 ) {
Serial.println(addr);
}
for (uint8_t c = 0; c < chunk; c += 4) {
data[c + 0] = val >> 24;
data[c + 1] = val >> 16;
data[c + 2] = val >> 8;
data[c + 3] = val;
++val;
}
eep.write(addr, data, chunk);
}
uint32_t msLapse = millis() - msStart;
Serial.print(F("Write lapse: "));
Serial.print(msLapse);
Serial.println(F(" ms"));
}
//read test data (32-bit integers) from eeprom, "chunk" bytes at a time
void eeRead(uint8_t chunk)
{
chunk &= 0xFC; //force chunk to be a multiple of 4
uint8_t data[chunk];
uint32_t val = 0, testVal;
Serial.println(F("Reading..."));
uint32_t msStart = millis();
for (uint32_t addr = 0; addr < totalKBytes * 1024; addr += chunk) {
if ( (addr & 0xFFF) == 0 ) {
Serial.println(addr);
}
eep.read(addr, data, chunk);
for (uint8_t c = 0; c < chunk; c += 4) {
testVal = ((uint32_t)data[c + 0] << 24) + ((uint32_t)data[c + 1] << 16) + ((
uint32_t)data[c + 2] << 8) + (uint32_t)data[c + 3];
if (testVal != val) {
Serial.print(F("Error @ addr "));
Serial.print(addr + c);
Serial.print(F(" Expected "));
Serial.print(val);
Serial.print(F(" Read "));
Serial.print(testVal);
Serial.print(F(" 0x"));
Serial.println(testVal, HEX);
}
++val;
}
}
uint32_t msLapse = millis() - msStart;
Serial.print(F("Last value: "));
Serial.print(val);
Serial.print(F(" Read lapse: "));
Serial.print(msLapse);
Serial.println(F(" ms"));
}
//write 0xFF to eeprom, "chunk" bytes at a time
void eeErase(uint8_t chunk, uint32_t startAddr, uint32_t endAddr)
{
chunk &= 0xFC; //force chunk to be a multiple of 4
uint8_t data[chunk];
Serial.println(F("Erasing..."));
for (int i = 0; i < chunk; i++) {
data[i] = 0xFF;
}
uint32_t msStart = millis();
for (uint32_t a = startAddr; a <= endAddr; a += chunk) {
if ( (a & 0xFFF) == 0 ) {
Serial.println(a);
}
eep.write(a, data, chunk);
}
uint32_t msLapse = millis() - msStart;
Serial.print(F("Erase lapse: "));
Serial.print(msLapse);
Serial.print(F(" ms"));
}
//dump eeprom contents, 16 bytes at a time.
//always dumps a multiple of 16 bytes.
void dump(uint32_t startAddr, uint32_t nBytes)
{
Serial.print(F("EEPROM DUMP 0x"));
Serial.print(startAddr, HEX);
Serial.print(F(" 0x"));
Serial.print(nBytes, HEX);
Serial.print(F(" "));
Serial.print(startAddr);
Serial.print(F(" "));
Serial.println(nBytes);
uint32_t nRows = (nBytes + 15) >> 4;
uint8_t d[16];
for (uint32_t r = 0; r < nRows; r++) {
uint32_t a = startAddr + 16 * r;
eep.read(a, d, 16);
Serial.print(F("0x"));
if ( a < 16 * 16 * 16 ) {
Serial.print(F("0"));
}
if ( a < 16 * 16 ) {
Serial.print(F("0"));
}
if ( a < 16 ) {
Serial.print(F("0"));
}
Serial.print(a, HEX);
Serial.print(F(" "));
for ( int c = 0; c < 16; c++ ) {
if ( d[c] < 16 ) {
Serial.print(F("0"));
Serial.print(d[c], HEX);
Serial.print( c == 7 ? " " : " ");
}
}
Serial.println(F(""));
}
}

View File

@@ -0,0 +1,233 @@
//Test extEEPROM library.
//Writes the EEPROM full of 32-bit integers and reads them back to verify.
//Wire a button from digital pin 6 to ground, this is used as a start button
//so the sketch doesn't do unnecessary EEPROM writes every time it's reset.
//Jack Christensen 09Jul2014
//Paolo Paolucci 17Mar2016 (fix 28Jun2017)
//Mik 03Jan2017 (configured Library to use the Wire1 as I2C channel)
#include <extEEPROM.h> //https://github.com/PaoloP74/extEEPROM
//One 24LC256 EEPROMs on the bus
const uint32_t totalKBytes = 32; //for read and write test functions
extEEPROM eep(kbits_256, 1, 64, 0x57); //device size, number of devices, page size
const uint8_t btnStart = 6; //start button
void setup(void)
{
uint8_t eepStatus;
pinMode(btnStart, INPUT_PULLUP);
Serial.begin(115200);
while (!SerialUSB) {}
bool channelInsert = false;
Serial.println(F("Select the number of Wire channel use the eeprom"));
Serial.println(F("0 = Wire"));
Serial.println(F("1 = Wire1"));
Serial.println(F("...."));
Serial.println(F("x = WIRE_INTERFACES_COUNT"));
do {
if (Serial.available()) {
char I2Cchannel = Serial.read();
// only number that are less than WIRE_INTERFACES_COUNT are allowed
if ((I2Cchannel > '0') && (I2Cchannel < ('0' + WIRE_INTERFACES_COUNT))) {
channelInsert = true;
}
switch ((I2Cchannel - '0')) {
case 0:
Serial.println(F("Using the default Wire interface"));
eepStatus = eep.begin(eep.twiClock400kHz); //go fast!
break;
case 1:
Serial.println(F("Using the Wire1 interface"));
eepStatus = eep.begin(eep.twiClock400kHz, &Wire1); //go fast!
break;
/*
Uncomment till the number of WIRE_INTERFACES_COUNT of your Arduino board
case 2:
Serial.println(F("Using the Wire2 interface"));
eepStatus = eep.begin(eep.twiClock400kHz, &Wire2); //go fast!
break;
case 3:
Serial.println(F("Using the Wire3 interface"));
eepStatus = eep.begin(eep.twiClock400kHz, &Wire3); //go fast!
break;
case 4:
Serial.println(F("Using the Wire4 interface"));
eepStatus = eep.begin(eep.twiClock400kHz, &Wire4); //go fast!
break;
case 5:
Serial.println(F("Using the Wire5 interface"));
eepStatus = eep.begin(eep.twiClock400kHz, &Wire5); //go fast!
break;*/
default:
Serial.println(F("A wrong channel has been inserted (Arduino manage max 5)"));
break;
}
}
} while (!channelInsert);
if (eepStatus) {
Serial.print(F("extEEPROM.begin() failed, status = "));
Serial.println(eepStatus);
while (1);
}
Serial.println(F("Started !!"));
uint8_t chunkSize =
64; //this can be changed, but must be a multiple of 4 since we're writing 32-bit integers
// eeErase(chunkSize, 0, totalKBytes * 1024 - 1);
eeWrite(chunkSize);
eeRead(chunkSize);
dump(0, 32); //the first 32 bytes
dump(32256, 64); //the last 64 bytes
//dump(32512, 64); //across the device boundary
//dump(65520, 16); //the last 16 bytes
}
void loop(void)
{
}
//write test data (32-bit integers) to eeprom, "chunk" bytes at a time
void eeWrite(uint8_t chunk)
{
chunk &= 0xFC; //force chunk to be a multiple of 4
uint8_t data[chunk];
uint32_t val = 0;
Serial.println(F("Writing..."));
uint32_t msStart = millis();
for (uint32_t addr = 0; addr < totalKBytes * 1024; addr += chunk) {
if ( (addr & 0xFFF) == 0 ) {
Serial.println(addr);
}
for (uint8_t c = 0; c < chunk; c += 4) {
data[c + 0] = val >> 24;
data[c + 1] = val >> 16;
data[c + 2] = val >> 8;
data[c + 3] = val;
++val;
}
eep.write(addr, data, chunk);
}
uint32_t msLapse = millis() - msStart;
Serial.print(F("Write lapse: "));
Serial.print(msLapse);
Serial.println(F(" ms"));
}
//read test data (32-bit integers) from eeprom, "chunk" bytes at a time
void eeRead(uint8_t chunk)
{
chunk &= 0xFC; //force chunk to be a multiple of 4
uint8_t data[chunk];
uint32_t val = 0, testVal;
Serial.println(F("Reading..."));
uint32_t msStart = millis();
for (uint32_t addr = 0; addr < totalKBytes * 1024; addr += chunk) {
if ( (addr & 0xFFF) == 0 ) {
Serial.println(addr);
}
eep.read(addr, data, chunk);
for (uint8_t c = 0; c < chunk; c += 4) {
testVal = ((uint32_t)data[c + 0] << 24) + ((uint32_t)data[c + 1] << 16) + ((
uint32_t)data[c + 2] << 8) + (uint32_t)data[c + 3];
if (testVal != val) {
Serial.print(F("Error @ addr "));
Serial.print(addr + c);
Serial.print(F(" Expected "));
Serial.print(val);
Serial.print(F(" Read "));
Serial.print(testVal);
Serial.print(F(" 0x"));
Serial.println(testVal, HEX);
}
++val;
}
}
uint32_t msLapse = millis() - msStart;
Serial.print(F("Last value: "));
Serial.print(val);
Serial.print(F(" Read lapse: "));
Serial.print(msLapse);
Serial.println(F(" ms"));
}
//write 0xFF to eeprom, "chunk" bytes at a time
void eeErase(uint8_t chunk, uint32_t startAddr, uint32_t endAddr)
{
chunk &= 0xFC; //force chunk to be a multiple of 4
uint8_t data[chunk];
Serial.println(F("Erasing..."));
for (int i = 0; i < chunk; i++) {
data[i] = 0xFF;
}
uint32_t msStart = millis();
for (uint32_t a = startAddr; a <= endAddr; a += chunk) {
if ( (a & 0xFFF) == 0 ) {
Serial.println(a);
}
eep.write(a, data, chunk);
}
uint32_t msLapse = millis() - msStart;
Serial.print(F("Erase lapse: "));
Serial.print(msLapse);
Serial.print(F(" ms"));
}
//dump eeprom contents, 16 bytes at a time.
//always dumps a multiple of 16 bytes.
void dump(uint32_t startAddr, uint32_t nBytes)
{
Serial.print(F("EEPROM DUMP 0x"));
Serial.print(startAddr, HEX);
Serial.print(F(" 0x"));
Serial.print(nBytes, HEX);
Serial.print(F(" "));
Serial.print(startAddr);
Serial.print(F(" "));
Serial.println(nBytes);
uint32_t nRows = (nBytes + 15) >> 4;
uint8_t d[16];
for (uint32_t r = 0; r < nRows; r++) {
uint32_t a = startAddr + 16 * r;
eep.read(a, d, 16);
Serial.print(F("0x"));
if ( a < 16 * 16 * 16 ) {
Serial.print(F("0"));
}
if ( a < 16 * 16 ) {
Serial.print(F("0"));
}
if ( a < 16 ) {
Serial.print(F("0"));
}
Serial.print(a, HEX);
Serial.print(F(" "));
for ( int c = 0; c < 16; c++ ) {
if ( d[c] < 16 ) {
Serial.print(F("0"));
Serial.print(d[c], HEX);
Serial.print( c == 7 ? " " : " ");
}
}
Serial.println(F(""));
}
}