ProDevelopTeam#MasterRace / Mbed 2 deprecated ArtnetDMX

Dependencies:   mbed DMX TextLCD mbed-rtos

Revision:
27:1bd34c90e0a9
Parent:
23:2ed8390eaf32
Child:
28:4b327f1cb9cb
--- a/ArtNet.h	Thu Mar 17 13:35:50 2016 +0000
+++ b/ArtNet.h	Thu Mar 17 17:11:18 2016 +0000
@@ -3,52 +3,124 @@
 
 #include "mbed.h"
 #include "EthernetInterface.h"
-#include "string"
+
+Ethernet eth;
 
 using namespace std;
 
-#define ArtNetID "Art-Net"
-#define ArtNetOPCode 0x5000
-#define ArtNetPV 14
-#define ArtNetPoort 6454
+class ArtNet
+{
+    public:
+        ArtNet();
+        ~ArtNet();
+        
+        void V_ArtNet();
+        uint32_t I32_CheckHeader(char C_Header[7]);
+        uint32_t I32_Universes[2];
+        
+    private:
+        char C_Buf[572];
+        char C_ID[8];
+        uint16_t I16_OPCode;
+        uint16_t I16_ProtocolVersie;
+        uint16_t I16_Universe;
+        uint8_t I8_Values[2][511];
+};
 
-static const char*          mbedIp       = "2.0.0.100";  //IP
-static const char*          mbedMask     = "255.0.0.0";  // Mask
-static const char*          mbedGateway  = "2.0.0.1";    //Gateway 
+ArtNet::ArtNet()
+{
+    char C_Buf[572] = {""};
+    
+    uint16_t I16_OPCode = 0x5000;
+    uint16_t I16_ProtocolVersie = 14;
+    uint16_t I16_Universe = 0;
+    uint8_t I8_Values[2][511];
+}
 
-void V_ArtNet();
+ArtNet::~ArtNet()
+{
+    
+}
 
-void V_ArtNet()
+void ArtNet::V_ArtNet() 
 {
-    EthernetInterface eth;
-    eth.init(mbedIp, mbedMask, mbedGateway);
-    eth.connect();
-    UDPSocket ArtNetSocket;
-    ArtNetSocket.bind(ArtNetPoort);
-    uint8_t I8_Values[512] = {0};
-    Endpoint Client;
-    char buffer[600];
-    //uint8_t I8_Channels[512][3];
-    
-   while (true) 
-   {
-        int n = ArtNetSocket.receiveFrom(Client, buffer, sizeof(buffer));
-        buffer[n] = '\0';
-        
-        string S_DataString(buffer);
-        if (S_DataString.find("Art-Net") != string::npos) 
+    while(1) {
+        int size = eth.receive();   
+        if(size > 0) {
+            eth.read(C_Buf, size);
+             if(C_Buf[34] == 0x19 and C_Buf[35] == 0x36 and C_Buf[36] == 0x19 and C_Buf[37] == 0x36)
+            {
+                char C_ID[7];
+                memcpy(C_ID, &C_Buf[42], 7);
+                if(ArtNet::I32_CheckHeader(C_ID) == 0)
+                {
+                    if(C_Buf[50] == 0x00 and C_Buf[51]== 0x50)
+                    {
+                        if(C_Buf[52] == 0x00 and C_Buf[53]== 0x0E)
+                        {
+                            
+                        } 
+                    }   
+                }
+            }
+        }
+ 
+        wait(1);
+    }
+}
+
+uint32_t ArtNet::I32_CheckHeader(char C_Header[6])
+{
+    if(C_Header[0] == 'A')
+    {
+        if(C_Header[1] == 'r')
         {
-            size_t pos = S_DataString.find("Art-Net")+ 8;
-            string S_Data = S_DataString.substr(pos);
-            uint32_t I32_Universe =  S_Data[12] |  S_Data[13] << 8;
-            int i = 0;
-            for ( i =0; i <512; i++)
+            if(C_Header[2] == 't')
             {
-                I8_Values[i] = S_Data[i+17];
+                if(C_Header[3] == '-')
+                {
+                    if(C_Header[4] == 'N')
+                    {
+                        if(C_Header[5] == 'e')
+                        {
+                            if(C_Header[6] == 't')
+                            {
+                                return 0;
+                            }
+                            else
+                            {
+                                return 1;
+                            }  
+                        }
+                        else
+                        {
+                            return 1;
+                        }  
+                    }
+                    else
+                    {
+                        return 1;
+                    }  
+                }
+                else
+                {
+                    return 1;
+                }     
             }
-        } 
+            else
+            {
+                return 1;
+            }  
+        }
+        else
+        {
+            return 1;
+        }    
     }
-        
+    else
+    {
+        return 1;
+    }
 }