NAP
artnetlistener.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // External Includes
8 #include <cstdint>
9 #include <nap/numeric.h>
10 #include <asio/io_service.hpp>
11 #include <asio/error_code.hpp>
12 #include <asio/ip/udp.hpp>
13 
14 
15 namespace nap
16 {
17  namespace artnet
18  {
19  inline constexpr const char* protocolID = "Art-Net";
20  inline constexpr uint16 opCode = 0x5000;
21  inline constexpr uint16 minProtVer = 14;
22  inline constexpr uint16 dataLength = 512;
23  inline constexpr uint16 headerLength = 18;
24  }
25 
26  class ArtNetReceiver;
27 
31  class ArtNetListener final
32  {
33  public:
34  ArtNetListener(ArtNetReceiver& receiver, asio::io_service& ioService, const std::string& ip, uint16 port);
35 
36  private:
37  void startReceive();
38  void handleReceive(const asio::error_code& error, std::size_t size);
39 
40  // Buffer size is known at compile time
41  using ArtNetBuffer = std::array<uint8, artnet::headerLength + artnet::dataLength>;
42 
43  ArtNetReceiver& mReceiver; // The Art-Net Receiver that holds the message queue
44  asio::ip::udp::socket mSocket; // The UDP socket that is used to receive data
45  ArtNetBuffer mBuffer; // The buffer used for receiving ArtDmx packets
46  };
47 }
nap::artnet::protocolID
constexpr const char * protocolID
Protocol identifier.
Definition: artnetlistener.h:19
nap::artnet::dataLength
constexpr uint16 dataLength
Length of Art-Net buffer in bytes.
Definition: artnetlistener.h:22
nap::ArtNetListener
Definition: artnetlistener.h:31
nap::artnet::headerLength
constexpr uint16 headerLength
Length of Art-Net header in bytes.
Definition: artnetlistener.h:23
nap
Definition: templateapp.h:17
nap::uint16
uint16_t uint16
Definition: numeric.h:18
nap::artnet::opCode
constexpr uint16 opCode
Packet type identifier.
Definition: artnetlistener.h:20
nap::artnet::minProtVer
constexpr uint16 minProtVer
Min allowed Art-Net protocol version.
Definition: artnetlistener.h:21
nap::ArtNetListener::ArtNetListener
ArtNetListener(ArtNetReceiver &receiver, asio::io_service &ioService, const std::string &ip, uint16 port)
nap::ArtNetReceiver
Definition: artnetreceiver.h:29