feat(UML-1462): Добавлены функции приема и передачи вектора

This commit is contained in:
algin 2023-07-20 12:48:59 +03:00
parent 0f0b83702c
commit 4cfbcac957

View File

@ -15,6 +15,7 @@
#include "free_rtos/ethernet/eth_types.h"
#include <vector>
#include <iterator>
#include <cstdint>
namespace free_rtos {
@ -31,14 +32,56 @@ public:
int32_t read_async(uint8_t * p_data, uint32_t len);
template<class T, class Allocator>
int32_t read_async(std::vector<T, Allocator>& data, uint32_t len = 65535)
{
if (len == 0) {
return 0;
}
if (buff_.empty()) {
return 0;
}
return get_data(data, len);
}
int32_t write(uint32_t ip_dst_be, uint8_t * p_data, uint32_t len);
template<class T, class Allocator>
int32_t write(uint32_t ip_dst_be, std::vector<T, Allocator>& data)
{
return write(ip_dst_be, data.data(), data.size() * sizeof(T));
}
void clear(); ///<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
private:
void put_data(uint32_t src_ip, uint8_t * p_data, uint32_t len);
int32_t get_data(uint8_t * p_data, uint32_t len);
template<class T, class Allocator>
int32_t get_data(std::vector<T, Allocator>& data, uint32_t len)
{
uint32_t size = buff_.size();
if (size > len) {
size = len;
}
{
LockGuard lock(rx_mut_);
auto item_begin = buff_.begin();
auto item_end = item_begin + size;
std::copy(item_begin, item_end, std::back_inserter(data));
buff_.erase(item_begin, item_end);
}
return size;
}
private:
const uint32_t max_buf_size = 0x100000; // 1Mb