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

Committer:
hideakitai
Date:
Fri Mar 25 07:39:22 2016 +0000
Revision:
0:1abf45d17b99
first  commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hideakitai 0:1abf45d17b99 1 /*The MIT License (MIT)
hideakitai 0:1abf45d17b99 2
hideakitai 0:1abf45d17b99 3 Copyright (c) 2014 Nathanaël Lécaudé
hideakitai 0:1abf45d17b99 4 https://github.com/natcl/Artnet, http://forum.pjrc.com/threads/24688-Artnet-to-OctoWS2811
hideakitai 0:1abf45d17b99 5
hideakitai 0:1abf45d17b99 6 Permission is hereby granted, free of charge, to any person obtaining a copy
hideakitai 0:1abf45d17b99 7 of this software and associated documentation files (the "Software"), to deal
hideakitai 0:1abf45d17b99 8 in the Software without restriction, including without limitation the rights
hideakitai 0:1abf45d17b99 9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hideakitai 0:1abf45d17b99 10 copies of the Software, and to permit persons to whom the Software is
hideakitai 0:1abf45d17b99 11 furnished to do so, subject to the following conditions:
hideakitai 0:1abf45d17b99 12
hideakitai 0:1abf45d17b99 13 The above copyright notice and this permission notice shall be included in
hideakitai 0:1abf45d17b99 14 all copies or substantial portions of the Software.
hideakitai 0:1abf45d17b99 15
hideakitai 0:1abf45d17b99 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hideakitai 0:1abf45d17b99 17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hideakitai 0:1abf45d17b99 18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hideakitai 0:1abf45d17b99 19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hideakitai 0:1abf45d17b99 20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hideakitai 0:1abf45d17b99 21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hideakitai 0:1abf45d17b99 22 THE SOFTWARE.
hideakitai 0:1abf45d17b99 23 */
hideakitai 0:1abf45d17b99 24
hideakitai 0:1abf45d17b99 25 #ifndef ARTNET_H
hideakitai 0:1abf45d17b99 26 #define ARTNET_H
hideakitai 0:1abf45d17b99 27
hideakitai 0:1abf45d17b99 28 // #include <Arduino.h>
hideakitai 0:1abf45d17b99 29 // #include <Ethernet.h>
hideakitai 0:1abf45d17b99 30 // #include <EthernetUdp.h>
hideakitai 0:1abf45d17b99 31 #include <mbed.h>
hideakitai 0:1abf45d17b99 32 #include <EthernetInterface.h>
hideakitai 0:1abf45d17b99 33
hideakitai 0:1abf45d17b99 34 // UDP specific
hideakitai 0:1abf45d17b99 35 #define ART_NET_PORT 6454
hideakitai 0:1abf45d17b99 36 // Opcodes
hideakitai 0:1abf45d17b99 37 #define ART_POLL 0x2000
hideakitai 0:1abf45d17b99 38 #define ART_DMX 0x5000
hideakitai 0:1abf45d17b99 39 // Buffers
hideakitai 0:1abf45d17b99 40 #define MAX_BUFFER_ARTNET 530
hideakitai 0:1abf45d17b99 41 // Packet
hideakitai 0:1abf45d17b99 42 #define ART_NET_ID "Art-Net\0"
hideakitai 0:1abf45d17b99 43 #define ART_DMX_START 18
hideakitai 0:1abf45d17b99 44
hideakitai 0:1abf45d17b99 45 class Artnet
hideakitai 0:1abf45d17b99 46 {
hideakitai 0:1abf45d17b99 47 public:
hideakitai 0:1abf45d17b99 48 Artnet();
hideakitai 0:1abf45d17b99 49
hideakitai 0:1abf45d17b99 50 void begin(const char* ip, const char* mask, const char* gateway);
hideakitai 0:1abf45d17b99 51 uint16_t read();
hideakitai 0:1abf45d17b99 52 void printPacketHeader();
hideakitai 0:1abf45d17b99 53 void printPacketContent();
hideakitai 0:1abf45d17b99 54
hideakitai 0:1abf45d17b99 55 // Return a pointer to the start of the DMX data
hideakitai 0:1abf45d17b99 56 inline uint8_t* getDmxFrame(void)
hideakitai 0:1abf45d17b99 57 {
hideakitai 0:1abf45d17b99 58 return artnetPacket + ART_DMX_START;
hideakitai 0:1abf45d17b99 59 }
hideakitai 0:1abf45d17b99 60
hideakitai 0:1abf45d17b99 61 inline uint16_t getOpcode(void)
hideakitai 0:1abf45d17b99 62 {
hideakitai 0:1abf45d17b99 63 return opcode;
hideakitai 0:1abf45d17b99 64 }
hideakitai 0:1abf45d17b99 65
hideakitai 0:1abf45d17b99 66 inline uint8_t getSequence(void)
hideakitai 0:1abf45d17b99 67 {
hideakitai 0:1abf45d17b99 68 return sequence;
hideakitai 0:1abf45d17b99 69 }
hideakitai 0:1abf45d17b99 70
hideakitai 0:1abf45d17b99 71 inline uint16_t getUniverse(void)
hideakitai 0:1abf45d17b99 72 {
hideakitai 0:1abf45d17b99 73 return incomingUniverse;
hideakitai 0:1abf45d17b99 74 }
hideakitai 0:1abf45d17b99 75
hideakitai 0:1abf45d17b99 76 inline uint16_t getLength(void)
hideakitai 0:1abf45d17b99 77 {
hideakitai 0:1abf45d17b99 78 return dmxDataLength;
hideakitai 0:1abf45d17b99 79 }
hideakitai 0:1abf45d17b99 80
hideakitai 0:1abf45d17b99 81 inline void setArtDmxCallback(void (*fptr)(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data))
hideakitai 0:1abf45d17b99 82 {
hideakitai 0:1abf45d17b99 83 artDmxCallback = fptr;
hideakitai 0:1abf45d17b99 84 }
hideakitai 0:1abf45d17b99 85
hideakitai 0:1abf45d17b99 86 private:
hideakitai 0:1abf45d17b99 87 // EthernetUDP Udp;
hideakitai 0:1abf45d17b99 88 EthernetInterface eth;
hideakitai 0:1abf45d17b99 89 UDPSocket server;
hideakitai 0:1abf45d17b99 90 Endpoint client;
hideakitai 0:1abf45d17b99 91
hideakitai 0:1abf45d17b99 92 uint8_t artnetPacket[MAX_BUFFER_ARTNET];
hideakitai 0:1abf45d17b99 93 uint16_t packetSize;
hideakitai 0:1abf45d17b99 94 uint16_t opcode;
hideakitai 0:1abf45d17b99 95 uint8_t sequence;
hideakitai 0:1abf45d17b99 96 uint16_t incomingUniverse;
hideakitai 0:1abf45d17b99 97 uint16_t dmxDataLength;
hideakitai 0:1abf45d17b99 98 void (*artDmxCallback)(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data);
hideakitai 0:1abf45d17b99 99 };
hideakitai 0:1abf45d17b99 100
hideakitai 0:1abf45d17b99 101 #endif