diff --git a/Artnet.h b/Artnet.h index 857efd6..268c4f2 100644 --- a/Artnet.h +++ b/Artnet.h @@ -162,17 +162,21 @@ namespace arduino uint8_t operator[] (const size_t i) const { return buffer[i]; } uint8_t& operator[] (const size_t i) { return buffer[i]; } }; + typedef void (*CallbackType)(uint8_t* data, uint16_t size); + struct Map { uint32_t universe; CallbackType func; }; + using CallbackMap = arx::vector; +#else + template + using Array = std::array; + using CallbackType = std::function; + struct Map { uint32_t universe; CallbackType func; }; + using CallbackMap = std::vector; #endif template class Sender_ { -#ifdef ARTNET_DISABLE_STL Array packet; -#else - std::array packet; -#endif - const char* ip; uint16_t port {DEFAULT_PORT}; uint8_t target_net {0}; @@ -281,19 +285,7 @@ namespace arduino template class Receiver_ { -#ifdef ARTNET_DISABLE_STL - typedef void (*CallbackType)(uint8_t* data, uint16_t size); - struct Map { uint32_t universe; CallbackType func; }; - arx::vector v; - using CallbackMap = arx::vector; Array packet; -#else - using CallbackType = std::function; - struct Map { uint32_t universe; CallbackType func; }; - using CallbackMap = std::vector; - std::array packet; -#endif - IPAddress remote_ip; uint16_t remote_port; CallbackMap callbacks; @@ -315,7 +307,7 @@ namespace arduino { if (opcode(d) == OPC(OpCode::Dmx)) { - // TODO: std::move... + memmove(packet.data(), d, size); memcpy(packet.data(), d, size); remote_ip = stream->S::remoteIP(); remote_port = (uint16_t)stream->S::remotePort(); diff --git a/RingBuffer.h b/RingBuffer.h deleted file mode 100644 index ca64206..0000000 --- a/RingBuffer.h +++ /dev/null @@ -1,122 +0,0 @@ -#pragma once - -#ifndef RINGBUFFER_H -#define RINGBUFFER_H - -template -class RingBuffer -{ -public: - - inline size_t capacity() const { return SIZE; }; - inline size_t size() const { return (tail_ - head_); }; - inline const T* data() const { return &(queue_[head_]); } - inline T* data() { return &(queue_[head_]); } - inline bool empty() const { return tail_ == head_; }; - inline void clear() { head_ = 0; tail_ = 0; }; - inline void pop() - { - if (size() == 0) return; - if (size() == 1) clear(); - else head_++; - }; - inline void pop_back() - { - if (size() == 0) return; - if (size() == 1) clear(); - else tail_--; - }; - inline void push(const T& data) - { - queue_[(tail_++) % SIZE] = data; - if (size() > SIZE) head_++; - }; - inline void push(T&& data) - { - queue_[(tail_++) % SIZE] = data; - if (size() > SIZE) head_++; - }; - inline void push_back(const T& data) - { - queue_[(tail_++) % SIZE] = data; - if (size() > SIZE) head_++; - }; - inline void push_back(T&& data) - { - queue_[(tail_++) % SIZE] = data; - if (size() > SIZE) head_++; - }; - - inline const T& front() const // throw(Exception) - { - // if(empty()) throw Exception(); - return *(queue_ + head_ % SIZE); - }; - inline T& front() // throw(Exception) - { - // if(empty()) throw Exception(); - return *(queue_ + head_ % SIZE); - }; - - inline const T& back() const // throw(Exception) - { - // if(empty()) throw Exception(); - return *(queue_ + (SIZE + tail_ - 1) % SIZE); - } - inline T& back() // throw(Exception) - { - // if(empty()) throw Exception(); - return *(queue_ + (SIZE + tail_ - 1) % SIZE); - } - - inline const T& operator[] (uint8_t index) const - { - return *(queue_ + (head_ + index) % SIZE); - } - inline T& operator[] (uint8_t index) - { - return *(queue_ + (head_ + index) % SIZE); - } - - inline const T* begin() const { return &(queue_[head_]); } - inline T* begin() { return &(queue_[head_]); } - inline const T* end() const { return &(queue_[tail_]); } - inline T* end() { return &(queue_[tail_]); } - - inline T* erase(T* p) - { - if (p == end()) return p; - for (T* pos = p + 1; pos != end(); ++pos) - *(pos - 1) = *pos; - --tail_; - return p; - } - - inline void resize(size_t sz) - { - size_t s = size(); - if (sz > size()) - { - for (size_t i = 0; i < sz - s; ++i) push(T()); - } - else if (sz < size()) - { - for (size_t i = 0; i < s - sz; ++i) pop(); - } - } - - inline void assign(const T* const first, const T* const end) - { - clear(); - const char* p = first; - while (p != end) push(*p++); - } - -private: - - T queue_[SIZE]; - volatile size_t head_ {0}; - volatile size_t tail_ {0}; -}; - -#endif // RINGBUFFER_H