From c5f834b2bc10d0c39226b6c48534b8d4e3ff782f Mon Sep 17 00:00:00 2001 From: Hideaki Tai Date: Thu, 4 Jan 2024 16:37:34 +0900 Subject: [PATCH] feat: add ArtTrigger --- Artnet/ArtTrigger.h | 69 +++++++++++++++++++++++++++++++++++++++++++-- Artnet/Sender.h | 20 +++++++++++++ README.md | 9 +++++- 3 files changed, 94 insertions(+), 4 deletions(-) diff --git a/Artnet/ArtTrigger.h b/Artnet/ArtTrigger.h index 45fc466..353081e 100644 --- a/Artnet/ArtTrigger.h +++ b/Artnet/ArtTrigger.h @@ -1,9 +1,72 @@ #pragma once -#ifndef ARTNET_ARTPOLLREPLY_H -#define ARTNET_ARTPOLLREPLY_H +#ifndef ARTNET_ART_TRIGGER_H +#define ARTNET_ART_TRIGGER_H + +#include "Common.h" +#include +#include namespace art_net { +namespace art_trigger { + +enum Index : uint16_t { + ID = 0, + OP_CODE_L = 8, + OP_CODE_H = 9, + PROTOCOL_VER_H = 10, + PROTOCOL_VER_L = 11, + FILTER_1 = 12, + FILTER_2 = 13, + OEM_H = 14, + OEM_L = 15, + KEY = 16, + SUB_KEY = 17, + PAYLOAD = 18 +}; + +class ArtTrigger { + uint16_t oem {0xFFFF}; + uint8_t key {0xFF}; + uint8_t subkey {0xFF}; + +public: + void set_oem(uint16_t oem_) + { + oem = oem_; + } + + void set_key(uint8_t key_) + { + key = key_; + } + + void set_subkey(uint8_t subkey_) + { + subkey = subkey_; + } + + void set_header(uint8_t *packet) + { + for (size_t i = 0; i < ID_LENGTH; i++) packet[i] = static_cast(ARTNET_ID[i]); + packet[OP_CODE_L] = (static_cast(OpCode::Trigger) >> 0) & 0x00FF; + packet[OP_CODE_H] = (static_cast(OpCode::Trigger) >> 8) & 0x00FF; + packet[PROTOCOL_VER_H] = (PROTOCOL_VER >> 8) & 0x00FF; + packet[PROTOCOL_VER_L] = (PROTOCOL_VER >> 0) & 0x00FF; + packet[FILTER_1] = 0; + packet[FILTER_2] = 0; + packet[OEM_H] = (oem >> 8) & 0x00FF; + packet[OEM_L] = (oem >> 0) & 0x00FF; + packet[KEY] = key; + packet[SUB_KEY] = subkey; + } + + void set_payload(uint8_t *packet, const uint8_t* const payload, uint16_t size) + { + memcpy(packet, payload, size); + } +}; +} // namespace art_trigger } // namespace art_net -#endif // ARTNET_ARTPOLLREPLY_H +#endif // ARTNET_ART_TRIGGER_H diff --git a/Artnet/Sender.h b/Artnet/Sender.h index c8e1c01..69acea6 100644 --- a/Artnet/Sender.h +++ b/Artnet/Sender.h @@ -4,6 +4,7 @@ #include "Common.h" #include "ArtDmx.h" +#include "ArtTrigger.h" namespace art_net { @@ -11,6 +12,7 @@ template class Sender_ { Array packet; artdmx::ArtDmx artdmx_ctx; + art_trigger::ArtTrigger art_trigger_ctx; IntervalMap intervals; S* stream; @@ -80,6 +82,24 @@ class Sender_ { return artdmx_ctx.sequence(); } + // ArtTrigger + void set_oem(uint16_t oem) { + art_trigger_ctx.set_oem(oem); + } + void set_key(uint8_t key) { + art_trigger_ctx.set_key(key); + } + void set_oem(uint8_t subkey) { + art_trigger_ctx.set_subkey(subkey); + } + void set_payload(const uint8_t* const payload, uint16_t size) { + art_trigger_ctx.set_payload(packet.data(), payload, size); + } + void trigger(const String& ip) { + art_trigger_ctx.set_header(packet.data()); + send_raw(ip, DEFAULT_PORT, packet.data(), packet.size()); + } + protected: void attach(S& s) { stream = &s; diff --git a/README.md b/README.md index 973f3be..bc2837b 100644 --- a/README.md +++ b/README.md @@ -263,9 +263,16 @@ void send(const String& ip, const uint32_t universe_, const uint8_t* const data, void send(const String& ip, const uint8_t net_, const uint8_t subnet_, const uint8_t universe_, const uint8_t* const data, const uint16_t size); // send arbitrary packet to the target void send_raw(const String& ip, uint16_t port, const uint8_t* const data, size_t size); -// others +// ArtDmx void physical(const uint8_t i); uint8_t sequence() const; +// ArtTrigger +void set_oem(uint16_t oem); +void set_key(uint8_t key); +void set_oem(uint8_t subkey); +void set_payload(const uint8_t* const payload, uint16_t size); +// send ArtTrigger based on the config above +void trigger(const String& ip); ``` ### ArtnetReceiver