mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-31 04:19:15 +03:00
first
This commit is contained in:
18
lib/ArduinoStreamUtils/extras/test/cores/avr/Arduino.h
Normal file
18
lib/ArduinoStreamUtils/extras/test/cores/avr/Arduino.h
Normal file
@@ -0,0 +1,18 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Client.h>
|
||||
#include <Print.h>
|
||||
#include <Stream.h>
|
||||
#include <WString.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
inline unsigned long millis() {
|
||||
return static_cast<unsigned long>(time(NULL));
|
||||
}
|
||||
|
||||
inline void yield() {}
|
||||
22
lib/ArduinoStreamUtils/extras/test/cores/avr/CMakeLists.txt
Normal file
22
lib/ArduinoStreamUtils/extras/test/cores/avr/CMakeLists.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
# StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
# Copyright Benoit Blanchon 2019-2021
|
||||
# MIT License
|
||||
|
||||
add_library(AvrCore
|
||||
Client.h
|
||||
EEPROM.cpp
|
||||
EEPROM.h
|
||||
Print.h
|
||||
Stream.h
|
||||
WString.h
|
||||
)
|
||||
|
||||
target_include_directories(AvrCore
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_compile_definitions(AvrCore
|
||||
PUBLIC
|
||||
ARDUINO_ARCH_AVR
|
||||
)
|
||||
27
lib/ArduinoStreamUtils/extras/test/cores/avr/Client.h
Normal file
27
lib/ArduinoStreamUtils/extras/test/cores/avr/Client.h
Normal file
@@ -0,0 +1,27 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Stream.h"
|
||||
#include "WString.h"
|
||||
|
||||
using IPAddress = String;
|
||||
|
||||
struct Client : Stream {
|
||||
virtual int connect(IPAddress ip, uint16_t port) = 0;
|
||||
virtual int connect(const char *host, uint16_t port) = 0;
|
||||
virtual uint8_t connected() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual operator bool() = 0;
|
||||
|
||||
// Already in Stream
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
virtual size_t write(const uint8_t *buf, size_t size) = 0;
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
|
||||
// Curiously not in Stream
|
||||
virtual int read(uint8_t *buf, size_t size) = 0;
|
||||
};
|
||||
12
lib/ArduinoStreamUtils/extras/test/cores/avr/EEPROM.cpp
Normal file
12
lib/ArduinoStreamUtils/extras/test/cores/avr/EEPROM.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "EEPROM.h"
|
||||
|
||||
EEPROMClass EEPROM;
|
||||
static uint8_t data[512];
|
||||
|
||||
uint8_t EEPROMClass::read(int address) {
|
||||
return data[address];
|
||||
}
|
||||
|
||||
void EEPROMClass::update(int address, uint8_t value) {
|
||||
data[address] = value;
|
||||
}
|
||||
12
lib/ArduinoStreamUtils/extras/test/cores/avr/EEPROM.h
Normal file
12
lib/ArduinoStreamUtils/extras/test/cores/avr/EEPROM.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class EEPROMClass {
|
||||
public:
|
||||
uint8_t read(int);
|
||||
void update(int, uint8_t);
|
||||
// void write(int, uint8_t); <- it exists but we want to use update() instead
|
||||
};
|
||||
|
||||
extern EEPROMClass EEPROM;
|
||||
42
lib/ArduinoStreamUtils/extras/test/cores/avr/Print.h
Normal file
42
lib/ArduinoStreamUtils/extras/test/cores/avr/Print.h
Normal file
@@ -0,0 +1,42 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstring>
|
||||
|
||||
#include <WString.h>
|
||||
|
||||
struct Print {
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||
virtual size_t write(uint8_t data) = 0;
|
||||
virtual void flush() {}
|
||||
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
size_t print(const String &s) {
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t print(const char *s) {
|
||||
return write(s, std::strlen(s));
|
||||
}
|
||||
|
||||
size_t println() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t print(const T &value) {
|
||||
return print(String(value));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t println(const T &value) {
|
||||
return print(value);
|
||||
}
|
||||
};
|
||||
41
lib/ArduinoStreamUtils/extras/test/cores/avr/Stream.h
Normal file
41
lib/ArduinoStreamUtils/extras/test/cores/avr/Stream.h
Normal file
@@ -0,0 +1,41 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Print.h"
|
||||
|
||||
struct Stream : Print {
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
|
||||
size_t readBytes(char *buffer, size_t length) {
|
||||
size_t count = 0;
|
||||
while (count < length) {
|
||||
int c = timedRead();
|
||||
if (c < 0)
|
||||
break;
|
||||
*buffer++ = (char)c;
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
String readString() {
|
||||
String result;
|
||||
int c;
|
||||
while ((c = timedRead()) >= 0) {
|
||||
result += static_cast<char>(c);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void setTimeout(unsigned long) {}
|
||||
|
||||
protected:
|
||||
int timedRead() {
|
||||
return read();
|
||||
}
|
||||
};
|
||||
43
lib/ArduinoStreamUtils/extras/test/cores/avr/WString.h
Normal file
43
lib/ArduinoStreamUtils/extras/test/cores/avr/WString.h
Normal file
@@ -0,0 +1,43 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class String : private std::string {
|
||||
public:
|
||||
String() {}
|
||||
String(const String& s) : std::string(s) {}
|
||||
String(String&& s) : std::string(std::move(s)) {}
|
||||
String(const char* s) : std::string(s) {}
|
||||
String(int n) : std::string(std::to_string(n)) {}
|
||||
|
||||
String& operator=(const String& rhs) {
|
||||
std::string::operator=(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
using std::string::c_str;
|
||||
using std::string::length;
|
||||
using std::string::operator+=;
|
||||
using std::string::operator[];
|
||||
|
||||
void remove(unsigned int index, unsigned int count) {
|
||||
erase(begin() + index, begin() + index + count);
|
||||
}
|
||||
|
||||
void toCharArray(char* buf, unsigned int bufsize,
|
||||
unsigned int index = 0) const {
|
||||
copy(buf, bufsize, index);
|
||||
}
|
||||
|
||||
friend bool operator==(const String& lhs, const char* rhs) {
|
||||
return static_cast<const std::string&>(lhs) == rhs;
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& lhs, const String& rhs) {
|
||||
return lhs << static_cast<const std::string&>(rhs);
|
||||
}
|
||||
};
|
||||
18
lib/ArduinoStreamUtils/extras/test/cores/esp32/Arduino.h
Normal file
18
lib/ArduinoStreamUtils/extras/test/cores/esp32/Arduino.h
Normal file
@@ -0,0 +1,18 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Client.h>
|
||||
#include <Print.h>
|
||||
#include <Stream.h>
|
||||
#include <WString.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
inline unsigned long millis() {
|
||||
return static_cast<unsigned long>(time(NULL));
|
||||
}
|
||||
|
||||
inline void yield() {}
|
||||
@@ -0,0 +1,22 @@
|
||||
# StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
# Copyright Benoit Blanchon 2019-2021
|
||||
# MIT License
|
||||
|
||||
add_library(Esp32Core
|
||||
Client.h
|
||||
EEPROM.cpp
|
||||
EEPROM.h
|
||||
Print.h
|
||||
Stream.h
|
||||
WString.h
|
||||
)
|
||||
|
||||
target_include_directories(Esp32Core
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_compile_definitions(Esp32Core
|
||||
PUBLIC
|
||||
ARDUINO_ARCH_ESP32
|
||||
)
|
||||
26
lib/ArduinoStreamUtils/extras/test/cores/esp32/Client.h
Normal file
26
lib/ArduinoStreamUtils/extras/test/cores/esp32/Client.h
Normal file
@@ -0,0 +1,26 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Stream.h"
|
||||
#include "WString.h"
|
||||
|
||||
using IPAddress = String;
|
||||
|
||||
class Client : public Stream {
|
||||
public:
|
||||
virtual int connect(IPAddress ip, uint16_t port) = 0;
|
||||
virtual int connect(const char *host, uint16_t port) = 0;
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
virtual size_t write(const uint8_t *buf, size_t size) = 0;
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int read(uint8_t *buf, size_t size) = 0;
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual uint8_t connected() = 0;
|
||||
virtual operator bool() = 0;
|
||||
};
|
||||
20
lib/ArduinoStreamUtils/extras/test/cores/esp32/EEPROM.cpp
Normal file
20
lib/ArduinoStreamUtils/extras/test/cores/esp32/EEPROM.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "EEPROM.h"
|
||||
|
||||
#include <string.h> // memcpy
|
||||
|
||||
EEPROMClass EEPROM;
|
||||
static uint8_t commitedData[512];
|
||||
static uint8_t pendingData[512];
|
||||
|
||||
uint8_t EEPROMClass::read(int address) {
|
||||
return commitedData[address];
|
||||
}
|
||||
|
||||
void EEPROMClass::write(int address, uint8_t value) {
|
||||
pendingData[address] = value;
|
||||
}
|
||||
|
||||
bool EEPROMClass::commit() {
|
||||
memcpy(commitedData, pendingData, 512);
|
||||
return true;
|
||||
}
|
||||
12
lib/ArduinoStreamUtils/extras/test/cores/esp32/EEPROM.h
Normal file
12
lib/ArduinoStreamUtils/extras/test/cores/esp32/EEPROM.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class EEPROMClass {
|
||||
public:
|
||||
uint8_t read(int);
|
||||
void write(int, uint8_t);
|
||||
bool commit();
|
||||
};
|
||||
|
||||
extern EEPROMClass EEPROM;
|
||||
42
lib/ArduinoStreamUtils/extras/test/cores/esp32/Print.h
Normal file
42
lib/ArduinoStreamUtils/extras/test/cores/esp32/Print.h
Normal file
@@ -0,0 +1,42 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <WString.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstring>
|
||||
|
||||
struct Print {
|
||||
virtual ~Print() {}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||
virtual size_t write(uint8_t data) = 0;
|
||||
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
size_t print(const String &s) {
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t print(const char *s) {
|
||||
return write(s, std::strlen(s));
|
||||
}
|
||||
|
||||
size_t println() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t print(const T &value) {
|
||||
return print(String(value));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t println(const T &value) {
|
||||
return print(value);
|
||||
}
|
||||
};
|
||||
48
lib/ArduinoStreamUtils/extras/test/cores/esp32/Stream.h
Normal file
48
lib/ArduinoStreamUtils/extras/test/cores/esp32/Stream.h
Normal file
@@ -0,0 +1,48 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Print.h"
|
||||
|
||||
struct Stream : Print {
|
||||
virtual ~Stream() {}
|
||||
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0;
|
||||
|
||||
virtual size_t readBytes(char *buffer, size_t length) {
|
||||
size_t count = 0;
|
||||
while (count < length) {
|
||||
int c = timedRead();
|
||||
if (c < 0)
|
||||
break;
|
||||
*buffer++ = (char)c;
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
virtual size_t readBytes(uint8_t *buffer, size_t length) {
|
||||
return readBytes((char *)buffer, length);
|
||||
}
|
||||
|
||||
virtual String readString() {
|
||||
String result;
|
||||
int c;
|
||||
while ((c = timedRead()) >= 0) {
|
||||
result += c;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void setTimeout(unsigned long) {}
|
||||
|
||||
protected:
|
||||
int timedRead() {
|
||||
return read();
|
||||
}
|
||||
};
|
||||
5
lib/ArduinoStreamUtils/extras/test/cores/esp32/WString.h
Normal file
5
lib/ArduinoStreamUtils/extras/test/cores/esp32/WString.h
Normal file
@@ -0,0 +1,5 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#include "../avr/WString.h"
|
||||
18
lib/ArduinoStreamUtils/extras/test/cores/esp8266/Arduino.h
Normal file
18
lib/ArduinoStreamUtils/extras/test/cores/esp8266/Arduino.h
Normal file
@@ -0,0 +1,18 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Client.h>
|
||||
#include <Print.h>
|
||||
#include <Stream.h>
|
||||
#include <WString.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
inline unsigned long millis() {
|
||||
return static_cast<unsigned long>(time(NULL));
|
||||
}
|
||||
|
||||
inline void yield() {}
|
||||
@@ -0,0 +1,22 @@
|
||||
# StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
# Copyright Benoit Blanchon 2019-2021
|
||||
# MIT License
|
||||
|
||||
add_library(Esp8266Core
|
||||
Client.h
|
||||
EEPROM.cpp
|
||||
EEPROM.h
|
||||
Print.h
|
||||
Stream.h
|
||||
WString.h
|
||||
)
|
||||
|
||||
target_include_directories(Esp8266Core
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_compile_definitions(Esp8266Core
|
||||
PUBLIC
|
||||
ARDUINO_ARCH_ESP8266
|
||||
)
|
||||
26
lib/ArduinoStreamUtils/extras/test/cores/esp8266/Client.h
Normal file
26
lib/ArduinoStreamUtils/extras/test/cores/esp8266/Client.h
Normal file
@@ -0,0 +1,26 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Stream.h"
|
||||
#include "WString.h"
|
||||
|
||||
using IPAddress = String;
|
||||
|
||||
class Client : public Stream {
|
||||
public:
|
||||
virtual int connect(IPAddress ip, uint16_t port) = 0;
|
||||
virtual int connect(const char *host, uint16_t port) = 0;
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
virtual size_t write(const uint8_t *buf, size_t size) = 0;
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int read(uint8_t *buf, size_t size) = 0;
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual uint8_t connected() = 0;
|
||||
virtual operator bool() = 0;
|
||||
};
|
||||
19
lib/ArduinoStreamUtils/extras/test/cores/esp8266/EEPROM.cpp
Normal file
19
lib/ArduinoStreamUtils/extras/test/cores/esp8266/EEPROM.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "EEPROM.h"
|
||||
|
||||
#include <string.h> // memcpy
|
||||
|
||||
EEPROMClass EEPROM;
|
||||
static uint8_t commitedData[512];
|
||||
static uint8_t pendingData[512];
|
||||
|
||||
uint8_t EEPROMClass::read(int address) {
|
||||
return commitedData[address];
|
||||
}
|
||||
|
||||
void EEPROMClass::write(int address, uint8_t value) {
|
||||
pendingData[address] = value;
|
||||
}
|
||||
|
||||
void EEPROMClass::commit() {
|
||||
memcpy(commitedData, pendingData, 512);
|
||||
}
|
||||
12
lib/ArduinoStreamUtils/extras/test/cores/esp8266/EEPROM.h
Normal file
12
lib/ArduinoStreamUtils/extras/test/cores/esp8266/EEPROM.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class EEPROMClass {
|
||||
public:
|
||||
uint8_t read(int);
|
||||
void write(int, uint8_t);
|
||||
void commit();
|
||||
};
|
||||
|
||||
extern EEPROMClass EEPROM;
|
||||
43
lib/ArduinoStreamUtils/extras/test/cores/esp8266/Print.h
Normal file
43
lib/ArduinoStreamUtils/extras/test/cores/esp8266/Print.h
Normal file
@@ -0,0 +1,43 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <WString.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstring>
|
||||
|
||||
struct Print {
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||
virtual size_t write(uint8_t data) = 0;
|
||||
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
size_t print(const String &s) {
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t print(const char *s) {
|
||||
return write(s, std::strlen(s));
|
||||
}
|
||||
|
||||
size_t println() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t print(const T &value) {
|
||||
return print(String(value));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t println(const T &value) {
|
||||
return print(value);
|
||||
}
|
||||
|
||||
virtual void flush() {}
|
||||
};
|
||||
45
lib/ArduinoStreamUtils/extras/test/cores/esp8266/Stream.h
Normal file
45
lib/ArduinoStreamUtils/extras/test/cores/esp8266/Stream.h
Normal file
@@ -0,0 +1,45 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Print.h"
|
||||
|
||||
struct Stream : Print {
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
|
||||
virtual size_t readBytes(char *buffer, size_t length) {
|
||||
size_t count = 0;
|
||||
while (count < length) {
|
||||
int c = timedRead();
|
||||
if (c < 0)
|
||||
break;
|
||||
*buffer++ = (char)c;
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
virtual size_t readBytes(uint8_t *buffer, size_t length) {
|
||||
return readBytes((char *)buffer, length);
|
||||
}
|
||||
|
||||
virtual String readString() {
|
||||
String result;
|
||||
int c;
|
||||
while ((c = timedRead()) >= 0) {
|
||||
result += c;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void setTimeout(unsigned long) {}
|
||||
|
||||
protected:
|
||||
int timedRead() {
|
||||
return read();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#include "../avr/WString.h"
|
||||
18
lib/ArduinoStreamUtils/extras/test/cores/nrf52/Arduino.h
Normal file
18
lib/ArduinoStreamUtils/extras/test/cores/nrf52/Arduino.h
Normal file
@@ -0,0 +1,18 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Client.h>
|
||||
#include <Print.h>
|
||||
#include <Stream.h>
|
||||
#include <WString.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
inline unsigned long millis() {
|
||||
return static_cast<unsigned long>(time(NULL));
|
||||
}
|
||||
|
||||
inline void yield() {}
|
||||
@@ -0,0 +1,15 @@
|
||||
# StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
# Copyright Benoit Blanchon 2019-2021
|
||||
# MIT License
|
||||
|
||||
add_library(Nrf52Core INTERFACE)
|
||||
|
||||
target_include_directories(Nrf52Core
|
||||
INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_compile_definitions(Nrf52Core
|
||||
INTERFACE
|
||||
ARDUINO_ARCH_NRF52
|
||||
)
|
||||
26
lib/ArduinoStreamUtils/extras/test/cores/nrf52/Client.h
Normal file
26
lib/ArduinoStreamUtils/extras/test/cores/nrf52/Client.h
Normal file
@@ -0,0 +1,26 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Stream.h"
|
||||
#include "WString.h"
|
||||
|
||||
using IPAddress = String;
|
||||
|
||||
class Client : public Stream {
|
||||
public:
|
||||
virtual int connect(IPAddress ip, uint16_t port) = 0;
|
||||
virtual int connect(const char *host, uint16_t port) = 0;
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
virtual size_t write(const uint8_t *buf, size_t size) = 0;
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int read(uint8_t *buf, size_t size) = 0;
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual uint8_t connected() = 0;
|
||||
virtual operator bool() = 0;
|
||||
};
|
||||
45
lib/ArduinoStreamUtils/extras/test/cores/nrf52/Print.h
Normal file
45
lib/ArduinoStreamUtils/extras/test/cores/nrf52/Print.h
Normal file
@@ -0,0 +1,45 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <WString.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstring>
|
||||
|
||||
struct Print {
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||
virtual size_t write(uint8_t data) = 0;
|
||||
|
||||
virtual int availableForWrite() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
size_t print(const String &s) {
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t print(const char *s) {
|
||||
return write(s, std::strlen(s));
|
||||
}
|
||||
|
||||
size_t println() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t print(const T &value) {
|
||||
return print(String(value));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t println(const T &value) {
|
||||
return print(value);
|
||||
}
|
||||
};
|
||||
45
lib/ArduinoStreamUtils/extras/test/cores/nrf52/Stream.h
Normal file
45
lib/ArduinoStreamUtils/extras/test/cores/nrf52/Stream.h
Normal file
@@ -0,0 +1,45 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Print.h"
|
||||
|
||||
struct Stream : Print {
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() {}
|
||||
|
||||
size_t readBytes(char *buffer, size_t length) {
|
||||
size_t count = 0;
|
||||
while (count < length) {
|
||||
int c = timedRead();
|
||||
if (c < 0)
|
||||
break;
|
||||
*buffer++ = (char)c;
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
size_t readBytes(uint8_t *buffer, size_t length) {
|
||||
return readBytes((char *)buffer, length);
|
||||
}
|
||||
|
||||
String readString() {
|
||||
String result;
|
||||
int c;
|
||||
while ((c = timedRead()) >= 0)
|
||||
result += c;
|
||||
return result;
|
||||
}
|
||||
|
||||
void setTimeout(unsigned long) {}
|
||||
|
||||
protected:
|
||||
int timedRead() {
|
||||
return read();
|
||||
}
|
||||
};
|
||||
5
lib/ArduinoStreamUtils/extras/test/cores/nrf52/WString.h
Normal file
5
lib/ArduinoStreamUtils/extras/test/cores/nrf52/WString.h
Normal file
@@ -0,0 +1,5 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#include "../avr/WString.h"
|
||||
18
lib/ArduinoStreamUtils/extras/test/cores/samd/Arduino.h
Normal file
18
lib/ArduinoStreamUtils/extras/test/cores/samd/Arduino.h
Normal file
@@ -0,0 +1,18 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Client.h>
|
||||
#include <Print.h>
|
||||
#include <Stream.h>
|
||||
#include <WString.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
inline unsigned long millis() {
|
||||
return static_cast<unsigned long>(time(NULL));
|
||||
}
|
||||
|
||||
inline void yield() {}
|
||||
15
lib/ArduinoStreamUtils/extras/test/cores/samd/CMakeLists.txt
Normal file
15
lib/ArduinoStreamUtils/extras/test/cores/samd/CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
# StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
# Copyright Benoit Blanchon 2019-2021
|
||||
# MIT License
|
||||
|
||||
add_library(SamdCore INTERFACE)
|
||||
|
||||
target_include_directories(SamdCore
|
||||
INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_compile_definitions(SamdCore
|
||||
INTERFACE
|
||||
ARDUINO_ARCH_SAMD
|
||||
)
|
||||
26
lib/ArduinoStreamUtils/extras/test/cores/samd/Client.h
Normal file
26
lib/ArduinoStreamUtils/extras/test/cores/samd/Client.h
Normal file
@@ -0,0 +1,26 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Stream.h"
|
||||
#include "WString.h"
|
||||
|
||||
using IPAddress = String;
|
||||
|
||||
class Client : public Stream {
|
||||
public:
|
||||
virtual int connect(IPAddress ip, uint16_t port) = 0;
|
||||
virtual int connect(const char *host, uint16_t port) = 0;
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
virtual size_t write(const uint8_t *buf, size_t size) = 0;
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int read(uint8_t *buf, size_t size) = 0;
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual uint8_t connected() = 0;
|
||||
virtual operator bool() = 0;
|
||||
};
|
||||
46
lib/ArduinoStreamUtils/extras/test/cores/samd/Print.h
Normal file
46
lib/ArduinoStreamUtils/extras/test/cores/samd/Print.h
Normal file
@@ -0,0 +1,46 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <WString.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstring>
|
||||
|
||||
struct Print {
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||
virtual size_t write(uint8_t data) = 0;
|
||||
virtual void flush() {}
|
||||
|
||||
virtual int availableForWrite() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
size_t print(const String &s) {
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t print(const char *s) {
|
||||
return write(s, std::strlen(s));
|
||||
}
|
||||
|
||||
size_t println() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t print(const T &value) {
|
||||
return print(String(value));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t println(const T &value) {
|
||||
return print(value);
|
||||
}
|
||||
};
|
||||
44
lib/ArduinoStreamUtils/extras/test/cores/samd/Stream.h
Normal file
44
lib/ArduinoStreamUtils/extras/test/cores/samd/Stream.h
Normal file
@@ -0,0 +1,44 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Print.h"
|
||||
|
||||
struct Stream : Print {
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
|
||||
size_t readBytes(char *buffer, size_t length) {
|
||||
size_t count = 0;
|
||||
while (count < length) {
|
||||
int c = timedRead();
|
||||
if (c < 0)
|
||||
break;
|
||||
*buffer++ = (char)c;
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
size_t readBytes(uint8_t *buffer, size_t length) {
|
||||
return readBytes((char *)buffer, length);
|
||||
}
|
||||
|
||||
String readString() {
|
||||
String result;
|
||||
int c;
|
||||
while ((c = timedRead()) >= 0)
|
||||
result += c;
|
||||
return result;
|
||||
}
|
||||
|
||||
void setTimeout(unsigned long) {}
|
||||
|
||||
protected:
|
||||
int timedRead() {
|
||||
return read();
|
||||
}
|
||||
};
|
||||
5
lib/ArduinoStreamUtils/extras/test/cores/samd/WString.h
Normal file
5
lib/ArduinoStreamUtils/extras/test/cores/samd/WString.h
Normal file
@@ -0,0 +1,5 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#include "../avr/WString.h"
|
||||
18
lib/ArduinoStreamUtils/extras/test/cores/stm32/Arduino.h
Normal file
18
lib/ArduinoStreamUtils/extras/test/cores/stm32/Arduino.h
Normal file
@@ -0,0 +1,18 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Client.h>
|
||||
#include <Print.h>
|
||||
#include <Stream.h>
|
||||
#include <WString.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
inline unsigned long millis() {
|
||||
return static_cast<unsigned long>(time(NULL));
|
||||
}
|
||||
|
||||
inline void yield() {}
|
||||
@@ -0,0 +1,22 @@
|
||||
# StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
# Copyright Benoit Blanchon 2019-2021
|
||||
# MIT License
|
||||
|
||||
add_library(Stm32Core
|
||||
Client.h
|
||||
EEPROM.cpp
|
||||
EEPROM.h
|
||||
Print.h
|
||||
Stream.h
|
||||
WString.h
|
||||
)
|
||||
|
||||
target_include_directories(Stm32Core
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_compile_definitions(Stm32Core
|
||||
PUBLIC
|
||||
ARDUINO_ARCH_STM32
|
||||
)
|
||||
28
lib/ArduinoStreamUtils/extras/test/cores/stm32/Client.h
Normal file
28
lib/ArduinoStreamUtils/extras/test/cores/stm32/Client.h
Normal file
@@ -0,0 +1,28 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Stream.h"
|
||||
#include "WString.h"
|
||||
|
||||
using IPAddress = String;
|
||||
|
||||
struct Client : Stream {
|
||||
// Print
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
virtual size_t write(const uint8_t *buf, size_t size) = 0;
|
||||
|
||||
// Stream
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual void flush() = 0;
|
||||
|
||||
virtual int connect(IPAddress ip, uint16_t port) = 0;
|
||||
virtual int connect(const char *host, uint16_t port) = 0;
|
||||
virtual uint8_t connected() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual operator bool() = 0;
|
||||
virtual int read(uint8_t *buf, size_t size) = 0;
|
||||
};
|
||||
12
lib/ArduinoStreamUtils/extras/test/cores/stm32/EEPROM.cpp
Normal file
12
lib/ArduinoStreamUtils/extras/test/cores/stm32/EEPROM.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "EEPROM.h"
|
||||
|
||||
EEPROMClass EEPROM;
|
||||
static uint8_t data[512];
|
||||
|
||||
uint8_t EEPROMClass::read(int address) {
|
||||
return data[address];
|
||||
}
|
||||
|
||||
void EEPROMClass::write(int address, uint8_t value) {
|
||||
data[address] = value;
|
||||
}
|
||||
11
lib/ArduinoStreamUtils/extras/test/cores/stm32/EEPROM.h
Normal file
11
lib/ArduinoStreamUtils/extras/test/cores/stm32/EEPROM.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class EEPROMClass {
|
||||
public:
|
||||
uint8_t read(int);
|
||||
void write(int, uint8_t);
|
||||
};
|
||||
|
||||
extern EEPROMClass EEPROM;
|
||||
41
lib/ArduinoStreamUtils/extras/test/cores/stm32/Print.h
Normal file
41
lib/ArduinoStreamUtils/extras/test/cores/stm32/Print.h
Normal file
@@ -0,0 +1,41 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstring>
|
||||
|
||||
#include <WString.h>
|
||||
|
||||
struct Print {
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||
virtual size_t write(uint8_t data) = 0;
|
||||
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
size_t print(const String &s) {
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t print(const char *s) {
|
||||
return write(s, std::strlen(s));
|
||||
}
|
||||
|
||||
size_t println() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t print(const T &value) {
|
||||
return print(String(value));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t println(const T &value) {
|
||||
return print(value);
|
||||
}
|
||||
};
|
||||
42
lib/ArduinoStreamUtils/extras/test/cores/stm32/Stream.h
Normal file
42
lib/ArduinoStreamUtils/extras/test/cores/stm32/Stream.h
Normal file
@@ -0,0 +1,42 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Print.h"
|
||||
|
||||
struct Stream : Print {
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0;
|
||||
|
||||
virtual size_t readBytes(char *buffer, size_t length) {
|
||||
size_t count = 0;
|
||||
while (count < length) {
|
||||
int c = timedRead();
|
||||
if (c < 0)
|
||||
break;
|
||||
*buffer++ = (char)c;
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
String readString() {
|
||||
String result;
|
||||
int c;
|
||||
while ((c = timedRead()) >= 0) {
|
||||
result += static_cast<char>(c);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void setTimeout(unsigned long) {}
|
||||
|
||||
protected:
|
||||
int timedRead() {
|
||||
return read();
|
||||
}
|
||||
};
|
||||
43
lib/ArduinoStreamUtils/extras/test/cores/stm32/WString.h
Normal file
43
lib/ArduinoStreamUtils/extras/test/cores/stm32/WString.h
Normal file
@@ -0,0 +1,43 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class String : private std::string {
|
||||
public:
|
||||
String() {}
|
||||
String(const String& s) : std::string(s) {}
|
||||
String(String&& s) : std::string(std::move(s)) {}
|
||||
String(const char* s) : std::string(s) {}
|
||||
String(int n) : std::string(std::to_string(n)) {}
|
||||
|
||||
String& operator=(const String& rhs) {
|
||||
std::string::operator=(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
using std::string::c_str;
|
||||
using std::string::length;
|
||||
using std::string::operator+=;
|
||||
using std::string::operator[];
|
||||
|
||||
void remove(unsigned int index, unsigned int count) {
|
||||
erase(begin() + index, begin() + index + count);
|
||||
}
|
||||
|
||||
void toCharArray(char* buf, unsigned int bufsize,
|
||||
unsigned int index = 0) const {
|
||||
copy(buf, bufsize, index);
|
||||
}
|
||||
|
||||
friend bool operator==(const String& lhs, const char* rhs) {
|
||||
return static_cast<const std::string&>(lhs) == rhs;
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& lhs, const String& rhs) {
|
||||
return lhs << static_cast<const std::string&>(rhs);
|
||||
}
|
||||
};
|
||||
18
lib/ArduinoStreamUtils/extras/test/cores/teensy/Arduino.h
Normal file
18
lib/ArduinoStreamUtils/extras/test/cores/teensy/Arduino.h
Normal file
@@ -0,0 +1,18 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Client.h>
|
||||
#include <Print.h>
|
||||
#include <Stream.h>
|
||||
#include <WString.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
inline unsigned long millis() {
|
||||
return static_cast<unsigned long>(time(NULL));
|
||||
}
|
||||
|
||||
inline void yield() {}
|
||||
@@ -0,0 +1,22 @@
|
||||
# StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
# Copyright Benoit Blanchon 2019-2021
|
||||
# MIT License
|
||||
|
||||
add_library(TeensyCore
|
||||
Client.h
|
||||
EEPROM.cpp
|
||||
EEPROM.h
|
||||
Print.h
|
||||
Stream.h
|
||||
WString.h
|
||||
)
|
||||
|
||||
target_include_directories(TeensyCore
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_compile_definitions(TeensyCore
|
||||
PUBLIC
|
||||
CORE_TEENSY
|
||||
)
|
||||
31
lib/ArduinoStreamUtils/extras/test/cores/teensy/Client.h
Normal file
31
lib/ArduinoStreamUtils/extras/test/cores/teensy/Client.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Stream.h"
|
||||
#include "WString.h"
|
||||
|
||||
using IPAddress = String;
|
||||
|
||||
struct Client : Stream {
|
||||
virtual int connect(IPAddress ip, uint16_t port) = 0;
|
||||
virtual int connect(const char *host, uint16_t port) = 0;
|
||||
virtual uint8_t connected() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual operator bool() = 0;
|
||||
|
||||
// Already in Print
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
virtual size_t write(const uint8_t *buf, size_t size) = 0;
|
||||
virtual void flush() = 0;
|
||||
|
||||
// Already in Stream
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
|
||||
// Curiously not in Stream
|
||||
virtual int read(uint8_t *buf, size_t size) = 0;
|
||||
};
|
||||
12
lib/ArduinoStreamUtils/extras/test/cores/teensy/EEPROM.cpp
Normal file
12
lib/ArduinoStreamUtils/extras/test/cores/teensy/EEPROM.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "EEPROM.h"
|
||||
|
||||
EEPROMClass EEPROM;
|
||||
static uint8_t data[512];
|
||||
|
||||
uint8_t EEPROMClass::read(int address) {
|
||||
return data[address];
|
||||
}
|
||||
|
||||
void EEPROMClass::update(int address, uint8_t value) {
|
||||
data[address] = value;
|
||||
}
|
||||
12
lib/ArduinoStreamUtils/extras/test/cores/teensy/EEPROM.h
Normal file
12
lib/ArduinoStreamUtils/extras/test/cores/teensy/EEPROM.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class EEPROMClass {
|
||||
public:
|
||||
uint8_t read(int);
|
||||
void update(int, uint8_t);
|
||||
// void write(int, uint8_t); <- it exists but we want to use update() instead
|
||||
};
|
||||
|
||||
extern EEPROMClass EEPROM;
|
||||
46
lib/ArduinoStreamUtils/extras/test/cores/teensy/Print.h
Normal file
46
lib/ArduinoStreamUtils/extras/test/cores/teensy/Print.h
Normal file
@@ -0,0 +1,46 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <WString.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstring>
|
||||
|
||||
struct Print {
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||
virtual size_t write(uint8_t data) = 0;
|
||||
virtual void flush() {}
|
||||
|
||||
virtual int availableForWrite() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
size_t print(const String &s) {
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t print(const char *s) {
|
||||
return write(s, std::strlen(s));
|
||||
}
|
||||
|
||||
size_t println() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t print(const T &value) {
|
||||
return print(String(value));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t println(const T &value) {
|
||||
return print(value);
|
||||
}
|
||||
};
|
||||
42
lib/ArduinoStreamUtils/extras/test/cores/teensy/Stream.h
Normal file
42
lib/ArduinoStreamUtils/extras/test/cores/teensy/Stream.h
Normal file
@@ -0,0 +1,42 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Print.h"
|
||||
|
||||
struct Stream : Print {
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0;
|
||||
|
||||
size_t readBytes(char *buffer, size_t length) {
|
||||
size_t count = 0;
|
||||
while (count < length) {
|
||||
int c = timedRead();
|
||||
if (c < 0)
|
||||
break;
|
||||
*buffer++ = (char)c;
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
String readString() {
|
||||
String result;
|
||||
int c;
|
||||
while ((c = timedRead()) >= 0) {
|
||||
result += static_cast<char>(c);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void setTimeout(unsigned long) {}
|
||||
|
||||
private:
|
||||
int timedRead() {
|
||||
return read();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../avr/WString.h"
|
||||
Reference in New Issue
Block a user