Преглед на файлове

don't sniff for particular type in UI

Chris Mullins преди 8 години
родител
ревизия
ae8a43fd11
променени са 2 файла, в които са добавени 29 реда и са изтрити 27 реда
  1. 4 20
      data/web/index.html
  2. 25 7
      lib/WebServer/MiLightHttpServer.cpp

+ 4 - 20
data/web/index.html

@@ -31,6 +31,7 @@
     .error-info:before { content: '('; }
     .error-info:after { content: ')'; }
     .header-btn { margin: 20px; }
+    #sniffed-traffic { max-height: 50em; overflow-y: auto; }
     .btn-secondary {
       background-color: #fff;
       border: 1px solid #ccc;
@@ -213,10 +214,8 @@
     var sniffRequest;
     var sniffing = false;
     var getTraffic = function() {
-      var sniffType = $('#sniff-type input:checked').data('value');
-
-      sniffRequest = $.get('/gateway_traffic/' + sniffType, function(data) {
-        $('#sniffed-traffic').html(data + $('#sniffed-traffic').html());
+      sniffRequest = $.get('/gateway_traffic', function(data) {
+        $('#sniffed-traffic').prepend('<pre>' + data + '</pre>');
         getTraffic();
       });
     };
@@ -1012,24 +1011,9 @@
       <div class="col-sm-12">
         <button type="button" id="sniff" class="btn btn-primary">Start Sniffing</button>
 
-        <div class="btn-group" id="sniff-type" data-toggle="buttons">
-          <label class="btn btn-secondary active">
-            <input type="radio" name="options" autocomplete="off" data-value="rgbw" checked> RGBW
-          </label>
-          <label class="btn btn-secondary">
-            <input type="radio" name="options" autocomplete="off" data-value="cct"> CCT
-          </label>
-          <label class="btn btn-secondary">
-            <input type="radio" name="options" autocomplete="off" data-value="rgb_cct"> RGB+CCT
-          </label>
-          <label class="btn btn-secondary">
-            <input type="radio" name="options" autocomplete="off" data-value="rgb"> RGB
-          </label>
-        </div>
-
         <div> &nbsp; </div>
 
-        <pre id="sniffed-traffic"></pre>
+        <div id="sniffed-traffic"></div>
       </div>
     </div>
 

+ 25 - 7
lib/WebServer/MiLightHttpServer.cpp

@@ -16,7 +16,10 @@ void MiLightHttpServer::begin() {
   server.on("/settings", HTTP_PUT, [this]() { handleUpdateSettings(); });
   server.on("/settings", HTTP_POST, [this]() { server.send_P(200, TEXT_PLAIN, PSTR("success. rebooting")); ESP.restart(); }, handleUpdateFile(SETTINGS_FILE));
   server.on("/radio_configs", HTTP_GET, [this]() { handleGetRadioConfigs(); });
+
+  server.on("/gateway_traffic", HTTP_GET, [this]() { handleListenGateway(NULL); });
   server.onPattern("/gateway_traffic/:type", HTTP_GET, [this](const UrlTokenBindings* b) { handleListenGateway(b); });
+
   server.onPattern("/gateways/:device_id/:type/:group_id", HTTP_ANY, [this](const UrlTokenBindings* b) { handleUpdateGroup(b); });
   server.onPattern("/raw_commands/:type", HTTP_ANY, [this](const UrlTokenBindings* b) { handleSendRaw(b); });
   server.onPattern("/download_update/:component", HTTP_GET, [this](const UrlTokenBindings* b) { handleDownloadUpdate(b); });
@@ -293,9 +296,14 @@ void MiLightHttpServer::handleUpdateSettings() {
 
 void MiLightHttpServer::handleListenGateway(const UrlTokenBindings* bindings) {
   bool available = false;
-  MiLightRadioConfig* config = MiLightRadioConfig::fromString(bindings->get("type"));
-
-  if (config == NULL) {
+  bool listenAll = bindings == NULL;
+  uint8_t configIx = 0;
+  MiLightRadioConfig* currentConfig =
+    listenAll
+      ? MiLightRadioConfig::ALL_CONFIGS[0]
+      : MiLightRadioConfig::fromString(bindings->get("type"));
+
+  if (currentConfig == NULL && bindings != NULL) {
     String body = "Unknown device type: ";
     body += bindings->get("type");
 
@@ -303,13 +311,18 @@ void MiLightHttpServer::handleListenGateway(const UrlTokenBindings* bindings) {
     return;
   }
 
-  milightClient->prepare(*config, 0, 0);
-
   while (!available) {
     if (!server.clientConnected()) {
       return;
     }
 
+    if (listenAll) {
+      currentConfig = MiLightRadioConfig::ALL_CONFIGS[
+        configIx++ % MiLightRadioConfig::NUM_CONFIGS
+      ];
+    }
+    milightClient->prepare(*currentConfig, 0, 0);
+
     if (milightClient->available()) {
       available = true;
     }
@@ -317,13 +330,18 @@ void MiLightHttpServer::handleListenGateway(const UrlTokenBindings* bindings) {
     yield();
   }
 
-  uint8_t packet[config->getPacketLength()];
+  uint8_t packet[currentConfig->getPacketLength()];
   milightClient->read(packet);
 
   char response[200];
   char* responseBuffer = response;
 
-  responseBuffer += sprintf_P(responseBuffer, PSTR("\nPacket received (%d bytes):\n"), sizeof(packet));
+  responseBuffer += sprintf_P(
+    responseBuffer,
+    PSTR("\n%s packet received (%d bytes):\n"),
+    currentConfig->name,
+    sizeof(packet)
+  );
   milightClient->formatPacket(packet, responseBuffer);
 
   server.send(200, TEXT_PLAIN, response);