ProDevelopTeam#MasterRace / Mbed 2 deprecated ArtnetDMX

Dependencies:   mbed DMX TextLCD mbed-rtos

Committer:
Ayrton_L
Date:
Fri Mar 18 00:44:33 2016 +0000
Revision:
28:4b327f1cb9cb
Parent:
27:1bd34c90e0a9
DMX Update;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ayrton_L 15:b0efafcfbb03 1 #ifndef ARTNET_H
Ayrton_L 15:b0efafcfbb03 2 #define ARTNET_H
Ayrton_L 15:b0efafcfbb03 3
Ayrton_L 15:b0efafcfbb03 4 #include "mbed.h"
Ayrton_L 15:b0efafcfbb03 5 #include "EthernetInterface.h"
Ayrton_L 27:1bd34c90e0a9 6
Ayrton_L 27:1bd34c90e0a9 7 Ethernet eth;
Ayrton_L 15:b0efafcfbb03 8
Ayrton_L 22:b4af2cbd3148 9 using namespace std;
Ayrton_L 22:b4af2cbd3148 10
Ayrton_L 27:1bd34c90e0a9 11 class ArtNet
Ayrton_L 27:1bd34c90e0a9 12 {
Ayrton_L 27:1bd34c90e0a9 13 public:
Ayrton_L 27:1bd34c90e0a9 14 ArtNet();
Ayrton_L 27:1bd34c90e0a9 15 ~ArtNet();
Ayrton_L 27:1bd34c90e0a9 16
Ayrton_L 27:1bd34c90e0a9 17 void V_ArtNet();
Ayrton_L 27:1bd34c90e0a9 18 uint32_t I32_CheckHeader(char C_Header[7]);
Ayrton_L 27:1bd34c90e0a9 19 uint32_t I32_Universes[2];
Ayrton_L 27:1bd34c90e0a9 20
Ayrton_L 27:1bd34c90e0a9 21 private:
Ayrton_L 27:1bd34c90e0a9 22 char C_Buf[572];
Ayrton_L 27:1bd34c90e0a9 23 char C_ID[8];
Ayrton_L 27:1bd34c90e0a9 24 uint16_t I16_OPCode;
Ayrton_L 27:1bd34c90e0a9 25 uint16_t I16_ProtocolVersie;
Ayrton_L 27:1bd34c90e0a9 26 uint16_t I16_Universe;
Ayrton_L 27:1bd34c90e0a9 27 uint8_t I8_Values[2][511];
Ayrton_L 27:1bd34c90e0a9 28 };
Ayrton_L 15:b0efafcfbb03 29
Ayrton_L 27:1bd34c90e0a9 30 ArtNet::ArtNet()
Ayrton_L 27:1bd34c90e0a9 31 {
Ayrton_L 27:1bd34c90e0a9 32 char C_Buf[572] = {""};
Ayrton_L 27:1bd34c90e0a9 33
Ayrton_L 27:1bd34c90e0a9 34 uint16_t I16_OPCode = 0x5000;
Ayrton_L 27:1bd34c90e0a9 35 uint16_t I16_ProtocolVersie = 14;
Ayrton_L 27:1bd34c90e0a9 36 uint16_t I16_Universe = 0;
Ayrton_L 28:4b327f1cb9cb 37 uint32_t I32_Universes[2] = {0};
Ayrton_L 27:1bd34c90e0a9 38 uint8_t I8_Values[2][511];
Ayrton_L 27:1bd34c90e0a9 39 }
Ayrton_L 15:b0efafcfbb03 40
Ayrton_L 27:1bd34c90e0a9 41 ArtNet::~ArtNet()
Ayrton_L 27:1bd34c90e0a9 42 {
Ayrton_L 27:1bd34c90e0a9 43
Ayrton_L 27:1bd34c90e0a9 44 }
Ayrton_L 15:b0efafcfbb03 45
Ayrton_L 27:1bd34c90e0a9 46 void ArtNet::V_ArtNet()
Ayrton_L 15:b0efafcfbb03 47 {
Ayrton_L 27:1bd34c90e0a9 48 while(1) {
Ayrton_L 27:1bd34c90e0a9 49 int size = eth.receive();
Ayrton_L 27:1bd34c90e0a9 50 if(size > 0) {
Ayrton_L 27:1bd34c90e0a9 51 eth.read(C_Buf, size);
Ayrton_L 28:4b327f1cb9cb 52 if(C_Buf[34] == 0x19 and C_Buf[35] == 0x36 and C_Buf[36] == 0x19 and C_Buf[37] == 0x36) //Poort checken (6465 = 0x1936 // deel van udp protocol
Ayrton_L 27:1bd34c90e0a9 53 {
Ayrton_L 27:1bd34c90e0a9 54 char C_ID[7];
Ayrton_L 27:1bd34c90e0a9 55 memcpy(C_ID, &C_Buf[42], 7);
Ayrton_L 28:4b327f1cb9cb 56 if(ArtNet::I32_CheckHeader(C_ID) == 0) //Art-Net Header checken
Ayrton_L 27:1bd34c90e0a9 57 {
Ayrton_L 28:4b327f1cb9cb 58 if(C_Buf[50] == 0x00 and C_Buf[51]== 0x50) //OPcode checken
Ayrton_L 27:1bd34c90e0a9 59 {
Ayrton_L 28:4b327f1cb9cb 60 if(C_Buf[52] == 0x00 and C_Buf[53]== 0x0E) //Protocol Versie (14) checken
Ayrton_L 27:1bd34c90e0a9 61 {
Ayrton_L 28:4b327f1cb9cb 62 // 56/57 = universe
Ayrton_L 28:4b327f1cb9cb 63 I16_Universe = C_Buf[56];
Ayrton_L 28:4b327f1cb9cb 64 I16_Universe = I16_Universe << 8;
Ayrton_L 28:4b327f1cb9cb 65 I16_Universe = I16_Universe & 0xFF00;
Ayrton_L 28:4b327f1cb9cb 66 I16_Universe = I16_Universe + C_Buf[57];
Ayrton_L 27:1bd34c90e0a9 67
Ayrton_L 28:4b327f1cb9cb 68 if(I16_Universe == I32_Universes[0])
Ayrton_L 28:4b327f1cb9cb 69 {
Ayrton_L 28:4b327f1cb9cb 70 }
Ayrton_L 28:4b327f1cb9cb 71 else if(I16_Universe == I32_Universes[1])
Ayrton_L 28:4b327f1cb9cb 72 {
Ayrton_L 28:4b327f1cb9cb 73 }
Ayrton_L 28:4b327f1cb9cb 74 else if(I16_Universe == I32_Universes[2])
Ayrton_L 28:4b327f1cb9cb 75 {
Ayrton_L 28:4b327f1cb9cb 76 }
Ayrton_L 27:1bd34c90e0a9 77 }
Ayrton_L 27:1bd34c90e0a9 78 }
Ayrton_L 27:1bd34c90e0a9 79 }
Ayrton_L 27:1bd34c90e0a9 80 }
Ayrton_L 27:1bd34c90e0a9 81 }
Ayrton_L 27:1bd34c90e0a9 82
Ayrton_L 27:1bd34c90e0a9 83 wait(1);
Ayrton_L 27:1bd34c90e0a9 84 }
Ayrton_L 27:1bd34c90e0a9 85 }
Ayrton_L 27:1bd34c90e0a9 86
Ayrton_L 27:1bd34c90e0a9 87 uint32_t ArtNet::I32_CheckHeader(char C_Header[6])
Ayrton_L 27:1bd34c90e0a9 88 {
Ayrton_L 27:1bd34c90e0a9 89 if(C_Header[0] == 'A')
Ayrton_L 27:1bd34c90e0a9 90 {
Ayrton_L 27:1bd34c90e0a9 91 if(C_Header[1] == 'r')
Ayrton_L 22:b4af2cbd3148 92 {
Ayrton_L 27:1bd34c90e0a9 93 if(C_Header[2] == 't')
Ayrton_L 22:b4af2cbd3148 94 {
Ayrton_L 27:1bd34c90e0a9 95 if(C_Header[3] == '-')
Ayrton_L 27:1bd34c90e0a9 96 {
Ayrton_L 27:1bd34c90e0a9 97 if(C_Header[4] == 'N')
Ayrton_L 27:1bd34c90e0a9 98 {
Ayrton_L 27:1bd34c90e0a9 99 if(C_Header[5] == 'e')
Ayrton_L 27:1bd34c90e0a9 100 {
Ayrton_L 27:1bd34c90e0a9 101 if(C_Header[6] == 't')
Ayrton_L 27:1bd34c90e0a9 102 {
Ayrton_L 27:1bd34c90e0a9 103 return 0;
Ayrton_L 27:1bd34c90e0a9 104 }
Ayrton_L 27:1bd34c90e0a9 105 else
Ayrton_L 27:1bd34c90e0a9 106 {
Ayrton_L 27:1bd34c90e0a9 107 return 1;
Ayrton_L 27:1bd34c90e0a9 108 }
Ayrton_L 27:1bd34c90e0a9 109 }
Ayrton_L 27:1bd34c90e0a9 110 else
Ayrton_L 27:1bd34c90e0a9 111 {
Ayrton_L 27:1bd34c90e0a9 112 return 1;
Ayrton_L 27:1bd34c90e0a9 113 }
Ayrton_L 27:1bd34c90e0a9 114 }
Ayrton_L 27:1bd34c90e0a9 115 else
Ayrton_L 27:1bd34c90e0a9 116 {
Ayrton_L 27:1bd34c90e0a9 117 return 1;
Ayrton_L 27:1bd34c90e0a9 118 }
Ayrton_L 27:1bd34c90e0a9 119 }
Ayrton_L 27:1bd34c90e0a9 120 else
Ayrton_L 27:1bd34c90e0a9 121 {
Ayrton_L 27:1bd34c90e0a9 122 return 1;
Ayrton_L 27:1bd34c90e0a9 123 }
Ayrton_L 22:b4af2cbd3148 124 }
Ayrton_L 27:1bd34c90e0a9 125 else
Ayrton_L 27:1bd34c90e0a9 126 {
Ayrton_L 27:1bd34c90e0a9 127 return 1;
Ayrton_L 27:1bd34c90e0a9 128 }
Ayrton_L 27:1bd34c90e0a9 129 }
Ayrton_L 27:1bd34c90e0a9 130 else
Ayrton_L 27:1bd34c90e0a9 131 {
Ayrton_L 27:1bd34c90e0a9 132 return 1;
Ayrton_L 27:1bd34c90e0a9 133 }
Ayrton_L 16:3cc108681a53 134 }
Ayrton_L 27:1bd34c90e0a9 135 else
Ayrton_L 27:1bd34c90e0a9 136 {
Ayrton_L 27:1bd34c90e0a9 137 return 1;
Ayrton_L 27:1bd34c90e0a9 138 }
Ayrton_L 15:b0efafcfbb03 139 }
Ayrton_L 15:b0efafcfbb03 140
Ayrton_L 15:b0efafcfbb03 141
Ayrton_L 15:b0efafcfbb03 142 #endif
Ayrton_L 15:b0efafcfbb03 143