Lumiverse  2.5
A framework for creating lighting control applications
KiNetInterface.h
Go to the documentation of this file.
1 
4 #ifndef _KINETINTERFACE_H_
5 #define _KINETINTERFACE_H_
6 
7 #pragma once
8 #include "LumiverseCoreConfig.h"
9 
10 #ifdef USE_KINET
11 
12 #ifdef _WIN32
13 #include <WinSock2.h>
14 #include <ws2tcpip.h>
15 #pragma comment (lib, "Ws2_32.lib")
16 #else
17 #include <sys/socket.h>
18 #include <netdb.h>
19 #include <unistd.h>
20 #endif
21 
22 #include "DMXInterface.h"
23 #include "../lib/libjson/libjson.h"
24 #include "Logger.h"
25 #include <string>
26 #include <sstream>
27 #include <iostream>
28 #include <math.h>
29 #include <fcntl.h>
30 
31 namespace Lumiverse {
36  enum KinetProtocolType {
37  OLD,
38  NEW
39  };
40 
47  class KiNetInterface : public DMXInterface
48  {
49  public:
58  KiNetInterface(string id, string host, int port = 6038, enum KinetProtocolType protocolType = KinetProtocolType::OLD);
59 
60  ~KiNetInterface();
61 
62  virtual void init();
63 
64  virtual void sendDMX(unsigned char* data, unsigned int universe);
65 
66  virtual void closeInt();
67 
68  virtual void reset();
69 
70  virtual JSONNode toJSON();
71 
72  virtual string getInterfaceType() { return "KiNetInterface"; }
73 
74  string getIP() { return m_host; }
75  void setIP(string ip) { m_host = ip; }
76 
77  int getPort() { return m_port; }
78  void setPort(int port) { m_port = port; }
79 
80  size_t getHeaderSize() const { return m_headerSize; }
81  size_t getDataSize() const { return m_dataSize; }
82  size_t getNumChannels() const { return m_numChannels; }
83  size_t getPacketSize() const { return m_headerSize + m_dataSize; }
84  size_t getBufferSize() const { return getPacketSize() * m_numChannels; }
85  const unsigned char* getHeaderBytes() const { return m_headerBytes; }
86 
87  private:
88  string m_host;
89  int m_port;
90  bool m_connected;
91  int m_socket;
92 
93  unsigned char* m_buffer;
94 
95  // Protocol header
96  const unsigned char* m_headerBytes;
97  size_t m_headerSize;
98  size_t m_dataSize;
99  size_t m_numChannels;
100  KinetProtocolType m_type;
101  };
102 }
103 
104 #endif
105 
106 #endif
void init(const char *jsonPatchStr, const char *filename)
Initializes data structures.
Definition: Dumiverse.cpp:29
Contains functions for logging information to console or file.
Base class describing how DMX Interfaces should act.
Contains all core Lumiverse functions and variables.
Definition: Device.cpp:2