mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 03:49:13 +03:00
first
This commit is contained in:
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);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user