Ver código fonte

response with device ID instead of mac addr

Chris Mullins 8 anos atrás
pai
commit
82382f499b
2 arquivos alterados com 27 adições e 19 exclusões
  1. 13 5
      lib/Udp/V6MiLightUdpServer.cpp
  2. 14 14
      lib/Udp/V6MiLightUdpServer.h

+ 13 - 5
lib/Udp/V6MiLightUdpServer.cpp

@@ -60,7 +60,7 @@ uint8_t V6MiLightUdpServer::SEARCH_RESPONSE[] = {
   0x01,
   0x17, 0x63,  // this is 5987 in hex. specifying a different value seems to
                // cause client to connect on a different port for some commands
-  0x00, 0x00, 0x05, 0x00, 0x09, 0x78, 
+  0x00, 0x00, 0x05, 0x00, 0x09, 0x78,
   0x6C, 0x69, 0x6E, 0x6B, 0x5F, 0x64,
   0x65, 0x76, 0x07, 0x5B, 0xCD, 0x15
 };
@@ -133,7 +133,7 @@ void V6MiLightUdpServer::handleSearch() {
   const size_t packetLen = size(SEARCH_RESPONSE);
   uint8_t response[packetLen];
   memcpy(response, SEARCH_RESPONSE, packetLen);
-  WiFi.macAddress(response + 6);
+  writeMacAddr(response + 6);
 
   socket.beginPacket(socket.remoteIP(), socket.remotePort());
   socket.write(response, packetLen);
@@ -146,7 +146,8 @@ void V6MiLightUdpServer::handleStartSession() {
   uint16_t sessionId = beginSession();
 
   memcpy(response, START_SESSION_RESPONSE, len);
-  WiFi.macAddress(response + 7);
+  writeMacAddr(response + 7);
+
   response[19] = sessionId >> 8;
   response[20] = sessionId & 0xFF;
 
@@ -184,7 +185,7 @@ bool V6MiLightUdpServer::handleOpenCommand(uint16_t sessionId) {
   size_t len = size(OPEN_COMMAND_RESPONSE);
   uint8_t response[len];
   memcpy(response, OPEN_COMMAND_RESPONSE, len);
-  WiFi.macAddress(response + 5);
+  writeMacAddr(response + 5);
 
   return sendResponse(sessionId, response, len);
 }
@@ -242,7 +243,8 @@ void V6MiLightUdpServer::handleCommand(
 void V6MiLightUdpServer::handleHeartbeat(uint16_t sessionId) {
   char header[] = { 0xD8, 0x00, 0x00, 0x00, 0x07 };
   memcpy(responseBuffer, header, size(header));
-  WiFi.macAddress(responseBuffer+5);
+  writeMacAddr(responseBuffer + 5);
+  
   responseBuffer[11] = 0;
 
   sendResponse(sessionId, responseBuffer, 12);
@@ -280,3 +282,9 @@ void V6MiLightUdpServer::handlePacket(uint8_t* packet, size_t packetSize) {
     Serial.println(F("Unhandled V6 packet"));
   }
 }
+
+void V6MiLightUdpServer::writeMacAddr(uint8_t* packet) {
+  memset(packet, 0, 6);
+  packet[4] = deviceId >> 8;
+  packet[5] = deviceId;
+}

+ 14 - 14
lib/Udp/V6MiLightUdpServer.h

@@ -12,7 +12,7 @@
 #define V6_MAX_SESSIONS 10
 
 #ifndef _V6_MILIGHT_UDP_SERVER
-#define _V6_MILIGHT_UDP_SERVER 
+#define _V6_MILIGHT_UDP_SERVER
 
 struct V6Session {
   V6Session(IPAddress ipAddr, uint16_t port, uint16_t sessionId)
@@ -21,7 +21,7 @@ struct V6Session {
       sessionId(sessionId),
       next(NULL)
   { }
-  
+
   IPAddress ipAddr;
   uint16_t port;
   uint16_t sessionId;
@@ -36,21 +36,21 @@ public:
       numSessions(0),
       firstSession(NULL)
   { }
-  
+
   ~V6MiLightUdpServer();
-  
+
   // Should return size of the response packet
   virtual void handlePacket(uint8_t* packet, size_t packetSize);
-  
+
   template <typename T>
   static T readInt(uint8_t* packet);
-  
+
   template <typename T>
   static uint8_t* writeInt(const T& value, uint8_t* packet);
-    
+
 protected:
   static V6CommandDemuxer COMMAND_DEMUXER PROGMEM;
-  
+
   static uint8_t START_SESSION_COMMAND[] PROGMEM;
   static uint8_t START_SESSION_RESPONSE[] PROGMEM;
   static uint8_t COMMAND_HEADER[] PROGMEM;
@@ -58,21 +58,21 @@ protected:
   static uint8_t LOCAL_SEARCH_COMMAND[] PROGMEM;
   static uint8_t HEARTBEAT_HEADER[] PROGMEM;
   static uint8_t HEARTBEAT_HEADER2[] PROGMEM;
-  
+
   static uint8_t SEARCH_COMMAND[] PROGMEM;
   static uint8_t SEARCH_RESPONSE[] PROGMEM;
-  
+
   static uint8_t OPEN_COMMAND_RESPONSE[] PROGMEM;
-  
+
   V6Session* firstSession;
   size_t numSessions;
   uint16_t sessionId;
-  
+
   uint16_t beginSession();
   bool sendResponse(uint16_t sessionId, uint8_t* responseBuffer, size_t responseSize);
-  
   bool matchesPacket(uint8_t* packet1, size_t packet1Len, uint8_t* packet2, size_t packet2Len);
-  
+  void writeMacAddr(uint8_t* packet);
+
   void handleSearch();
   void handleStartSession();
   bool handleOpenCommand(uint16_t sessionId);