Skip to content

Commit

Permalink
feat: add ArtTrigger
Browse files Browse the repository at this point in the history
  • Loading branch information
hideakitai committed Jan 4, 2024
1 parent b6f191e commit c5f834b
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 4 deletions.
69 changes: 66 additions & 3 deletions Artnet/ArtTrigger.h
Original file line number Diff line number Diff line change
@@ -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 <stdint.h>
#include <stddef.h>

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<uint8_t>(ARTNET_ID[i]);
packet[OP_CODE_L] = (static_cast<uint16_t>(OpCode::Trigger) >> 0) & 0x00FF;
packet[OP_CODE_H] = (static_cast<uint16_t>(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
20 changes: 20 additions & 0 deletions Artnet/Sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

#include "Common.h"
#include "ArtDmx.h"
#include "ArtTrigger.h"

namespace art_net {

template <typename S>
class Sender_ {
Array<PACKET_SIZE> packet;
artdmx::ArtDmx artdmx_ctx;
art_trigger::ArtTrigger art_trigger_ctx;

IntervalMap intervals;
S* stream;
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c5f834b

Please sign in to comment.