including tftp based shell and sockets from different project
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @file countDown.hpp
|
||||
* @author Gustice
|
||||
* @brief Classes for typical index manipulation
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
class CountDown {
|
||||
public:
|
||||
CountDown(unsigned max) : Max(max) {}
|
||||
|
||||
void Tick() {
|
||||
_cnt++;
|
||||
if (_cnt >= Max) {
|
||||
_cnt = 0;
|
||||
_pFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool GetVolatileFlag() {
|
||||
if (!_pFlag)
|
||||
return false;
|
||||
|
||||
// Reset _pFlag in any case, so it only be consumed once
|
||||
// hence volatile
|
||||
_pFlag = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
const unsigned Max;
|
||||
unsigned _cnt;
|
||||
bool _pFlag;
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @file portBase.hpp
|
||||
* @author Gustice
|
||||
* @brief Base-class for all hardware ports
|
||||
*
|
||||
* @copyright Copyright (c) 2024
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
class PortBase { // Forbid Copy and Move assignments
|
||||
public:
|
||||
PortBase(/* args */) {};
|
||||
PortBase(const PortBase &other) = delete;
|
||||
PortBase &operator=(const PortBase &other) = delete;
|
||||
};
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* @file rotatingIndex.hpp
|
||||
* @author Gustice
|
||||
* @brief Classes for typical index manipulation
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* @brief Index with automatic revolution back to start position
|
||||
* @details Useful for Buffer-Pointer, or similar tasks
|
||||
*/
|
||||
class RotatingIndex {
|
||||
public:
|
||||
/// @brief Value at witch the index rotates back to beginning
|
||||
const uint16_t MaxIndex;
|
||||
|
||||
/// @brief Constructor for rotating index
|
||||
/// @brief output index will be set to 0 if incremented value reaches Maximum
|
||||
/// @param max Maximum index for overflow-condition
|
||||
RotatingIndex(uint16_t max) : MaxIndex(max) { _index = 0; }
|
||||
|
||||
/// @brief Get the current index and inkrement index afterwards
|
||||
/// @return uint16_t current index
|
||||
uint16_t getIndexAndIncrement(void) {
|
||||
auto retVal = _index;
|
||||
_index++;
|
||||
if (_index >= MaxIndex) {
|
||||
_index = 0;
|
||||
}
|
||||
return retVal;
|
||||
};
|
||||
|
||||
/// @brief Get the current index without incrementing the index
|
||||
/// @return uint16_t current index
|
||||
uint16_t getIndex(void) { return _index; }
|
||||
|
||||
/// @brief Check if next get will lead to overflow condition
|
||||
bool peekRevolution(void) {
|
||||
if (MaxIndex == 0)
|
||||
return true;
|
||||
|
||||
if (_index >= MaxIndex - 1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// @brief Reset Index to 0
|
||||
void resetIndex(void) { _index = 0; }
|
||||
|
||||
private:
|
||||
/// Current Index
|
||||
uint16_t _index;
|
||||
};
|
||||
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @file utils.hpp
|
||||
* @author Gustice
|
||||
* @brief Template
|
||||
*
|
||||
* @copyright Copyright (c) 2024
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* @brief Simple exception
|
||||
*/
|
||||
class CoreException : public std::exception {
|
||||
char const *Text;
|
||||
|
||||
public:
|
||||
/// @brief Constructor with simple pointer to text
|
||||
CoreException(char const *text) : Text(text) {
|
||||
}
|
||||
|
||||
/// @brief error message getter
|
||||
char const *what() const throw() override { return Text; }
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Common interface for character streams
|
||||
*/
|
||||
class CharStream {
|
||||
public:
|
||||
/// @brief Read method
|
||||
/// @return string
|
||||
virtual std::string read() = 0;
|
||||
|
||||
/// @brief Write character
|
||||
/// @param c character to write
|
||||
virtual void write(char c) = 0;
|
||||
|
||||
/// @brief Write string
|
||||
/// @param str string to write
|
||||
virtual void write(std::string str) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Common interface
|
||||
*/
|
||||
class ByteStream {
|
||||
/// @brief Read method
|
||||
/// @return series of bytes
|
||||
virtual std::vector<uint8_t> read() = 0;
|
||||
|
||||
/// @brief write single byte
|
||||
/// @param b byte to write
|
||||
virtual void write(uint8_t b) = 0;
|
||||
|
||||
/// @brief write series of bytes
|
||||
/// @param data series to write
|
||||
virtual void write(std::vector<uint8_t> data) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Base for constructs that allow only one concurrently active instance
|
||||
*
|
||||
* @tparam T
|
||||
* @note needs a `T * T::SingleActive<T>::active{};` definition in source
|
||||
*/
|
||||
template <typename T>
|
||||
class SingleActive {
|
||||
static bool active;
|
||||
|
||||
public:
|
||||
/// @brief Constructor, memorizes if already on instance was successfully build
|
||||
SingleActive() {
|
||||
if (active) {
|
||||
throw "Instance already active";
|
||||
}
|
||||
assert(active == false && "Constructor my only be run if no instance active");
|
||||
active = true;
|
||||
}
|
||||
|
||||
/// @brief Destructor, clears memory of existing instance
|
||||
~SingleActive() {
|
||||
assert(active == true && "Destructor my only be run on active instance");
|
||||
active = false;
|
||||
}
|
||||
|
||||
// Disable move and assignment
|
||||
SingleActive(SingleActive &other) = delete;
|
||||
void operator=(const SingleActive &) = delete;
|
||||
};
|
||||
Reference in New Issue
Block a user