namespace cleanups
This commit is contained in:
parent
04d103a427
commit
104d5526bc
|
@ -35,14 +35,14 @@ address_type::address_type(uint8_t val) {
|
|||
width = (address_length)(val & 0b11);
|
||||
}
|
||||
|
||||
range::range(PDU::stream_ptr stream, data_type t, address_length l) {
|
||||
range::range(stream_ptr stream, data_type t, address_length l) {
|
||||
address = read(stream, l);
|
||||
if (t == SINGLE) return;
|
||||
incriment = read(stream, l);
|
||||
count = read(stream, l);
|
||||
}
|
||||
|
||||
uint32_t range::read(PDU::stream_ptr stream, address_length length) {
|
||||
uint32_t range::read(stream_ptr stream, address_length length) {
|
||||
switch (length) {
|
||||
case ONE:
|
||||
return stream->read8();
|
||||
|
@ -56,8 +56,8 @@ uint32_t range::read(PDU::stream_ptr stream, address_length length) {
|
|||
}
|
||||
|
||||
|
||||
Pdu::Pdu(PDU::stream_ptr stream)
|
||||
: ACN::PDU::Pdu(stream, 1) // vectors are 1 octet
|
||||
Pdu::Pdu(stream_ptr stream)
|
||||
: PDU::Pdu(stream, 1) // vectors are 1 octet
|
||||
{
|
||||
if (stream->fail()) return;
|
||||
if (!buffer_->good()) return;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "pdu.h"
|
||||
|
||||
|
@ -31,6 +32,13 @@
|
|||
namespace ACN {
|
||||
namespace DMP {
|
||||
|
||||
using std::uint8_t;
|
||||
using std::uint32_t;
|
||||
using std::vector;
|
||||
using std::pair;
|
||||
using std::shared_ptr;
|
||||
using PDU::stream_ptr;
|
||||
|
||||
// 5.1.4 Address and Data Types
|
||||
enum data_type {
|
||||
SINGLE = 0b00, // 0
|
||||
|
@ -61,14 +69,14 @@ struct range {
|
|||
uint32_t incriment;
|
||||
uint32_t count;
|
||||
range() {};
|
||||
range(PDU::stream_ptr, data_type, address_length);
|
||||
range(stream_ptr, data_type, address_length);
|
||||
private:
|
||||
uint32_t read(PDU::stream_ptr, address_length);
|
||||
uint32_t read(stream_ptr, address_length);
|
||||
};
|
||||
|
||||
typedef std::pair<range, std::vector<uint8_t>> set_property;
|
||||
typedef pair<range, vector<uint8_t>> set_property;
|
||||
struct dmp_set_data : PDU::pdu_data {
|
||||
std::vector<set_property> properties;
|
||||
vector<set_property> properties;
|
||||
};
|
||||
|
||||
// 7 Response Messages
|
||||
|
@ -101,10 +109,10 @@ static const uint8_t SUBSCRIBE_REJECT = 13;
|
|||
static const uint8_t SYNC_EVENT = 17;
|
||||
|
||||
class Pdu
|
||||
: public ACN::PDU::Pdu
|
||||
: public PDU::Pdu
|
||||
{
|
||||
public:
|
||||
Pdu(PDU::stream_ptr);
|
||||
Pdu(stream_ptr);
|
||||
private:
|
||||
void readSetData();
|
||||
};
|
||||
|
|
|
@ -133,7 +133,7 @@ pdu_flags::pdu_flags(uint8_t val) {
|
|||
|
||||
uint8_t pdu_stream::read8() {
|
||||
uint8_t ret = 0;
|
||||
if (available() < sizeof(ret)) {
|
||||
if (available() < (int)sizeof(ret)) {
|
||||
setstate(rdstate() | std::ios_base::failbit);
|
||||
return 0;
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ uint8_t pdu_stream::read8() {
|
|||
|
||||
uint16_t pdu_stream::read16() {
|
||||
uint16_t ret = 0;
|
||||
if (available() < sizeof(ret)) {
|
||||
if (available() < (int)sizeof(ret)) {
|
||||
setstate(rdstate() | std::ios_base::failbit);
|
||||
return 0;
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ uint16_t pdu_stream::read16() {
|
|||
|
||||
uint32_t pdu_stream::read32() {
|
||||
uint32_t ret = 0;
|
||||
if (available() < sizeof(ret)) {
|
||||
if (available() < (int)sizeof(ret)) {
|
||||
setstate(rdstate() | std::ios_base::failbit);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,15 @@
|
|||
namespace ACN {
|
||||
namespace PDU {
|
||||
|
||||
using std::uint8_t;
|
||||
using std::uint16_t;
|
||||
using std::uint32_t;
|
||||
using std::vector;
|
||||
using std::shared_ptr;
|
||||
using std::basic_streambuf;
|
||||
using std::streamsize;
|
||||
using std::basic_istream;
|
||||
|
||||
// 2.4.1. Flags
|
||||
// Flags is a 4-bit field containing flags L, V, H and D which declare how the PDU is packed.
|
||||
struct pdu_flags {
|
||||
|
@ -43,10 +52,10 @@ struct pdu_flags {
|
|||
|
||||
class pdu_stream;
|
||||
class Pdu;
|
||||
typedef std::shared_ptr<pdu_stream> stream_ptr;
|
||||
typedef std::shared_ptr<Pdu> pdu_ptr;
|
||||
typedef std::vector<pdu_ptr> pdu_block;
|
||||
typedef std::shared_ptr<pdu_block> block_ptr;
|
||||
typedef shared_ptr<pdu_stream> stream_ptr;
|
||||
typedef shared_ptr<Pdu> pdu_ptr;
|
||||
typedef vector<pdu_ptr> pdu_block;
|
||||
typedef shared_ptr<pdu_block> block_ptr;
|
||||
|
||||
// MAYBE: remove virtuals?
|
||||
// Arduino doen't enable RTTI for run-time polymorphism.
|
||||
|
@ -58,7 +67,7 @@ struct pdu_data { virtual ~pdu_data() {} };
|
|||
Memory buffer of uint8_t data.
|
||||
*/
|
||||
class pdu_buffer
|
||||
: public std::basic_streambuf<uint8_t>
|
||||
: public basic_streambuf<uint8_t>
|
||||
{
|
||||
public:
|
||||
pdu_buffer(uint8_t * p, size_t l) { setg(p, p, p + l); };
|
||||
|
@ -68,17 +77,17 @@ public:
|
|||
Input stream of nested PDU
|
||||
*/
|
||||
class pdu_stream
|
||||
: public std::basic_istream<uint8_t>
|
||||
: public basic_istream<uint8_t>
|
||||
{
|
||||
public:
|
||||
pdu_stream(uint8_t * p, size_t l)
|
||||
: std::basic_istream<uint8_t>(&_buffer)
|
||||
: basic_istream<uint8_t>(&_buffer)
|
||||
, _buffer(p, l) { rdbuf(&_buffer); }
|
||||
std::streamsize available() { return _buffer.in_avail(); }
|
||||
uint8_t * data() { return _buffer.cur_ptr(); };
|
||||
uint8_t read8 ();
|
||||
uint16_t read16();
|
||||
uint32_t read32();
|
||||
streamsize available() { return _buffer.in_avail(); }
|
||||
uint8_t * data() { return _buffer.cur_ptr(); };
|
||||
uint8_t read8 ();
|
||||
uint16_t read16();
|
||||
uint32_t read32();
|
||||
private:
|
||||
pdu_buffer _buffer;
|
||||
};
|
||||
|
@ -114,12 +123,12 @@ public:
|
|||
void setInherit(pdu_ptr pdu) {inherit_ = pdu;}
|
||||
|
||||
protected:
|
||||
pdu_flags flags_;
|
||||
uint32_t length_;
|
||||
uint32_t vector_;
|
||||
pdu_ptr parent_;
|
||||
pdu_ptr inherit_;
|
||||
stream_ptr buffer_;
|
||||
pdu_flags flags_;
|
||||
uint32_t length_;
|
||||
uint32_t vector_;
|
||||
pdu_ptr parent_;
|
||||
pdu_ptr inherit_;
|
||||
stream_ptr buffer_;
|
||||
|
||||
// private setters
|
||||
void setHeader (pdu_header * h) {header_ = h;}
|
||||
|
@ -141,9 +150,8 @@ private:
|
|||
@return std::shared_ptr<std::vector<std::shared_ptr<T>>> A block of PDU
|
||||
*/
|
||||
template<typename T>
|
||||
std::shared_ptr<std::vector<std::shared_ptr<T>>> readBlock(stream_ptr buffer) {
|
||||
auto block = std::shared_ptr<std::vector<std::shared_ptr<T>>>
|
||||
(new std::vector<std::shared_ptr<T>>);
|
||||
shared_ptr<vector<shared_ptr<T>>> readBlock(stream_ptr buffer) {
|
||||
auto block = shared_ptr<vector<shared_ptr<T>>>(new vector<shared_ptr<T>>);
|
||||
while(buffer->good()) {
|
||||
std::shared_ptr<T> pdu(new T(buffer));
|
||||
if (buffer->fail()) // stream failed during pdu constructor
|
||||
|
|
|
@ -33,6 +33,10 @@ namespace ACN {
|
|||
namespace RLP {
|
||||
namespace UDP {
|
||||
|
||||
using std::uint8_t;
|
||||
using std::uint16_t;
|
||||
using PDU::stream_ptr;
|
||||
|
||||
// The ACN Packet Identifier shall be the text string
|
||||
// “ASC-E1.17\0\0\0” encoded in [ASCII].
|
||||
static constexpr uint8_t ACN_PACKET_IDENTIFIER[] = { 0x41, 0x53, 0x43, 0x2d, 0x45, 0x31, 0x2e, 0x31, 0x37, 0x00, 0x00, 0x00 };
|
||||
|
@ -46,7 +50,7 @@ struct preamble_t {
|
|||
uint16_t length;
|
||||
uint16_t postamble_size;
|
||||
uint8_t acn_id[12];
|
||||
preamble_t(PDU::stream_ptr);
|
||||
preamble_t(stream_ptr);
|
||||
operator bool();
|
||||
};
|
||||
|
||||
|
|
|
@ -24,17 +24,20 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include "pdu.h"
|
||||
|
||||
namespace ACN {
|
||||
namespace RLP {
|
||||
|
||||
using PDU::stream_ptr;
|
||||
|
||||
// 2.6.1.2.2. Header Field in Root Layer PDUs
|
||||
// The Header field in Root Layer PDUs shall contain the CID of the component
|
||||
// that generated the PDU (the Source CID).
|
||||
struct rlp_header : PDU::pdu_header {
|
||||
uint8_t cid[16];
|
||||
rlp_header(PDU::stream_ptr);
|
||||
rlp_header(stream_ptr);
|
||||
};
|
||||
|
||||
class Pdu
|
||||
|
|
|
@ -31,6 +31,9 @@ namespace ACN {
|
|||
namespace SDT {
|
||||
namespace UDP {
|
||||
|
||||
using std::uint8_t;
|
||||
using std::uint16_t;
|
||||
|
||||
// Table 1. IPv4 Address Specification
|
||||
struct acn_sdt_udp_ipv4_addr_t {
|
||||
ip_addr_spec_t type; // SDT_ADDR_IPV4
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
namespace ACN {
|
||||
namespace SDT {
|
||||
|
||||
using std::uint32_t;
|
||||
|
||||
// 7.1 Protocol Code
|
||||
static const uint32_t SDT_PROTOCOL_ID = 1; // PDU protocol value
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
|
||||
namespace SACN {
|
||||
namespace DATA {
|
||||
using namespace ACN;
|
||||
|
||||
frame_header::frame_header(PDU::stream_ptr stream) {
|
||||
stream->read(source_name, 64);
|
||||
|
@ -40,7 +39,7 @@ frame_header::frame_header(PDU::stream_ptr stream) {
|
|||
}
|
||||
|
||||
Pdu::Pdu(PDU::stream_ptr stream)
|
||||
: ACN::PDU::Pdu(stream, 4) // vectors are 4 octets
|
||||
: PDU::Pdu(stream, 4) // vectors are 4 octets
|
||||
{
|
||||
if (stream->fail()) return;
|
||||
if (!buffer_->good()) return;
|
||||
|
|
|
@ -27,7 +27,10 @@
|
|||
|
||||
namespace SACN {
|
||||
namespace DATA {
|
||||
using namespace ACN;
|
||||
|
||||
using std::uint8_t;
|
||||
using std::uint16_t;
|
||||
using PDU::stream_ptr;
|
||||
|
||||
// Table 6-1: E1.31 Data Packet Framing Layer
|
||||
struct frame_header : PDU::pdu_header {
|
||||
|
@ -37,7 +40,7 @@ struct frame_header : PDU::pdu_header {
|
|||
uint8_t sequence_number;
|
||||
uint8_t options;
|
||||
uint16_t universe;
|
||||
frame_header(PDU::stream_ptr);
|
||||
frame_header(stream_ptr);
|
||||
};
|
||||
|
||||
// 6.2.6 E1.31 Data Packet: Options
|
||||
|
|
|
@ -26,9 +26,12 @@
|
|||
#include "sacn.h"
|
||||
|
||||
namespace SACN {
|
||||
namespace EXTENDED {
|
||||
using namespace ACN;
|
||||
|
||||
namespace EXTENDED {
|
||||
using std::uint8_t;
|
||||
using std::uint16_t;
|
||||
|
||||
// 6.3 E1.31 Synchronization Packet Framing Layer
|
||||
struct frame_sync_header : PDU::pdu_header {
|
||||
uint8_t sequence_number;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <esp_log.h>
|
||||
static const char* TAG = "EspReceiver";
|
||||
|
||||
using namespace SACN;
|
||||
namespace SACN {
|
||||
|
||||
EspReceiver::EspReceiver()
|
||||
: Receiver()
|
||||
|
@ -53,3 +53,5 @@ void EspReceiver::udpHandler(AsyncUDPPacket udp) {
|
|||
PDU::stream_ptr packet(new PDU::pdu_stream(udp.data(), udp.available()));
|
||||
packetHandler(packet); // from base class, SACN::Receiver
|
||||
}
|
||||
|
||||
} // SACN
|
||||
|
|
|
@ -49,13 +49,9 @@ namespace SACN {
|
|||
String(universe & 0xff, HEX));
|
||||
return address;
|
||||
};
|
||||
} // SACN
|
||||
|
||||
|
||||
using namespace SACN;
|
||||
|
||||
class EspReceiver
|
||||
: public Receiver
|
||||
: public SACN::Receiver
|
||||
{
|
||||
public:
|
||||
EspReceiver();
|
||||
|
@ -66,3 +62,5 @@ class EspReceiver
|
|||
void udpHandler(AsyncUDPPacket); // UDP packet parser callback
|
||||
|
||||
};
|
||||
|
||||
} // SACN
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include "data.h"
|
||||
|
||||
namespace SACN {
|
||||
using namespace ACN;
|
||||
|
||||
void Receiver::subscribe(const uint16_t universe) {
|
||||
if (universes_.count(universe))
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include <unordered_map>
|
||||
|
||||
namespace SACN {
|
||||
using namespace ACN;
|
||||
|
||||
class Receiver
|
||||
{
|
||||
|
|
|
@ -28,7 +28,11 @@
|
|||
|
||||
// E1.31 Lightweight streaming protocol for transport of DMX512 using ACN
|
||||
namespace SACN {
|
||||
|
||||
using namespace ACN;
|
||||
using std::uint8_t;
|
||||
using std::uint16_t;
|
||||
using std::uint32_t;
|
||||
|
||||
// Appendix A: Defined Parameters (Normative)
|
||||
static const uint32_t VECTOR_ROOT_E131_DATA = 0x00000004;
|
||||
|
|
|
@ -25,30 +25,29 @@
|
|||
#include "universe.h"
|
||||
|
||||
namespace SACN {
|
||||
using namespace ACN;
|
||||
|
||||
Universe::Universe()
|
||||
: DMX::Universe()
|
||||
{
|
||||
}
|
||||
|
||||
void Universe::set(PDU::pdu_ptr pdu) {
|
||||
void Universe::set(pdu_ptr pdu) {
|
||||
// 7.3 Address Type and Data Type
|
||||
// Sources shall set the DMP Layer's Address Type and Data Type to 0xa1.
|
||||
// Receivers shall discard the packet if the received value is not 0xa1.
|
||||
if (!pdu->header())
|
||||
return;
|
||||
auto type = (DMP::address_type*)pdu->header();
|
||||
auto type = (ACN::DMP::address_type*)pdu->header();
|
||||
if (!type->z_reserved) return; // needs to be true, but why?
|
||||
if (type->relative) return;
|
||||
if (type->type != DMP::ARRAY) return;
|
||||
if (type->type != ACN::DMP::ARRAY) return;
|
||||
if (type->x_reserved != 0) return;
|
||||
if (type->width != DMP::TWO) return;
|
||||
if (type->width != ACN::DMP::TWO) return;
|
||||
|
||||
// only act on the first property pair in the data
|
||||
if (!pdu->data())
|
||||
return;
|
||||
auto data = (DMP::dmp_set_data*)pdu->data();
|
||||
auto data = (ACN::DMP::dmp_set_data*)pdu->data();
|
||||
auto prop = data->properties.front();
|
||||
auto pr = prop.first;
|
||||
|
||||
|
|
|
@ -27,14 +27,14 @@
|
|||
#include "../dmx/universe.h"
|
||||
|
||||
namespace SACN {
|
||||
using namespace ACN;
|
||||
using ACN::PDU::pdu_ptr;
|
||||
|
||||
class Universe
|
||||
: public DMX::Universe
|
||||
{
|
||||
public:
|
||||
Universe();
|
||||
void set(PDU::pdu_ptr);
|
||||
void set(pdu_ptr);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -46,8 +46,8 @@ static const char* TAG = "WiFlash";
|
|||
//// device objects
|
||||
EspStrobe *strobe;
|
||||
NeoPixelBus<NeoGrbwFeature, Neo800KbpsMethod> *strip;
|
||||
EspReceiver *e131 = new EspReceiver();
|
||||
AsyncWebServer *httpd = new AsyncWebServer(80);
|
||||
auto *e131 = new SACN::EspReceiver();
|
||||
auto *httpd = new AsyncWebServer(80);
|
||||
|
||||
|
||||
//// Global button variables
|
||||
|
|
Loading…
Reference in New Issue