The port of Art-Net protocol parser natcl/Artnet to openFrameworks and mbed. https://github.com/hideakitai/ofxArtnetProtocol

Revision:
0:1abf45d17b99
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Artnet.cpp	Fri Mar 25 07:39:22 2016 +0000
@@ -0,0 +1,91 @@
+/*The MIT License (MIT)
+
+Copyright (c) 2014 Nathanaël Lécaudé
+https://github.com/natcl/Artnet, http://forum.pjrc.com/threads/24688-Artnet-to-OctoWS2811
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include <Artnet.h>
+
+Artnet::Artnet() {}
+
+void Artnet::begin(const char* ip, const char* mask, const char* gateway)
+{
+    eth.init(ip, mask, gateway);
+    eth.connect();
+    printf("\nServer IP Address is %s\n", eth.getIPAddress());
+
+    server.bind(ART_NET_PORT);
+}
+
+uint16_t Artnet::read()
+{
+  int packetSize = server.receiveFrom(client, (char*)artnetPacket, (int)MAX_BUFFER_ARTNET);
+
+  if (packetSize <= MAX_BUFFER_ARTNET && packetSize > 0)
+  {
+    //   Udp.read(artnetPacket, MAX_BUFFER_ARTNET);
+
+      // Check that packetID is "Art-Net" else ignore
+      for (size_t i = 0 ; i < 9 ; i++)
+      {
+        if (artnetPacket[i] != ART_NET_ID[i])
+          return 0;
+      }
+
+      opcode = artnetPacket[8] | artnetPacket[9] << 8;
+
+      if (opcode == ART_DMX)
+      {
+        sequence = artnetPacket[12];
+        incomingUniverse = artnetPacket[14] | artnetPacket[15] << 8;
+        dmxDataLength = artnetPacket[17] | artnetPacket[16] << 8;
+//        dmxDataLength = artnetPacket[16] | artnetPacket[17] << 8;
+
+        if (artDmxCallback) (*artDmxCallback)(incomingUniverse, dmxDataLength, sequence, artnetPacket + ART_DMX_START);
+        return ART_DMX;
+      }
+      if (opcode == ART_POLL)
+      {
+        return ART_POLL;
+      }
+  }
+  else
+  {
+    return 0;
+  }
+}
+
+void Artnet::printPacketHeader()
+{
+  printf("\npacket size = %d", packetSize);
+  printf("\nopcode = %2x", opcode);
+  printf("\nuniverse number = %d", incomingUniverse);
+  printf("\ndata length = %d", dmxDataLength);
+  printf("\nsequence n0. = %d", sequence);
+}
+
+void Artnet::printPacketContent()
+{
+  for (uint16_t i = ART_DMX_START ; i < dmxDataLength ; i++){
+    printf("%d  ", artnetPacket[i]);
+  }
+  printf("\n\n");
+}