浏览代码

httpd alpha version - release

Sebastien 5 年之前
父节点
当前提交
168c15ce02
共有 4 个文件被更改,包括 64 次插入52 次删除
  1. 1 1
      components/esp-dsp
  2. 2 2
      components/services/messaging.c
  3. 60 48
      components/wifi-manager/code.js
  4. 1 1
      components/wifi-manager/index.html

+ 1 - 1
components/esp-dsp

@@ -1 +1 @@
-Subproject commit de39220fb482eeaee4db5707358bf6b97b34fe59
+Subproject commit 8b082c1071497d49346ee6ed55351470c1cb4264

+ 2 - 2
components/services/messaging.c

@@ -128,7 +128,7 @@ cJSON *  messaging_retrieve_messages(RingbufHandle_t buf_handle){
 	size_t item_size;
     UBaseType_t uxItemsWaiting;
     vRingbufferGetInfo(buf_handle, NULL, NULL, NULL, NULL, &uxItemsWaiting);
-	if(uxItemsWaiting>0){
+	for(int i = 0;i<uxItemsWaiting;i++){
 		message = (single_message_t *)xRingbufferReceive(buf_handle, &item_size, pdMS_TO_TICKS(50));
 		//Check received data
 		if (message== NULL) {
@@ -179,7 +179,7 @@ esp_err_t messaging_post_to_queue(messaging_handle_t subscriber_handle, single_m
 	}
 	vRingbufferGetInfo(subscriber->buf_handle,NULL,NULL,NULL,NULL,&uxItemsWaiting);
 	if(uxItemsWaiting>=subscriber->max_count){
-		ESP_LOGW(tag,"messaged dropped for %s",str_or_unknown(subscriber->subscriber_name));
+		ESP_LOGD(tag,"messaged dropped for %s",str_or_unknown(subscriber->subscriber_name));
 		single_message_t * dummy = (single_message_t *)xRingbufferReceive(subscriber->buf_handle, &item_size, pdMS_TO_TICKS(50));
 		if (dummy== NULL) {
 			ESP_LOGE(tag,"receive from buffer failed");

+ 60 - 48
components/wifi-manager/code.js

@@ -211,7 +211,7 @@ $(document).ready(function(){
         }
 
 
-        showMessage('please wait for the ESP32 to reboot', 'WARNING');
+        showMessage('please wait for the ESP32 to reboot', 'MESSAGING_WARNING');
         $.ajax({
             url: '/config.json',
             dataType: 'text',
@@ -224,7 +224,7 @@ $(document).ready(function(){
             error: function (xhr, ajaxOptions, thrownError) {
                 console.log(xhr.status);
                 console.log(thrownError);
-                if (thrownError != '') showMessage(thrownError, 'ERROR');
+                if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
             },
             complete: function(response) {
                 //var returnedResponse = JSON.parse(response.responseText);
@@ -241,7 +241,7 @@ $(document).ready(function(){
                     error: function (xhr, ajaxOptions, thrownError) {
                         console.log(xhr.status);
                         console.log(thrownError);
-                        if (thrownError != '') showMessage(thrownError, 'ERROR');
+                        if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
                     },
                     complete: function(response) {
                     	console.log('reboot call completed');
@@ -273,7 +273,7 @@ $(document).ready(function(){
             error: function (xhr, ajaxOptions, thrownError) {
                 console.log(xhr.status);
                 console.log(thrownError);
-                if (thrownError != '') showMessage(thrownError, 'ERROR');
+                if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
             }
         });
         console.log('sent config JSON with headers:', autoexec1);
@@ -306,7 +306,7 @@ $(document).ready(function(){
             error: function (xhr, ajaxOptions, thrownError) {
                 console.log(xhr.status);
                 console.log(thrownError);
-                if (thrownError != '') showMessage(thrownError, 'ERROR');
+                if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
             }
         });
         console.log('sent config JSON with headers:', JSON.stringify(headers));
@@ -361,7 +361,7 @@ $(document).ready(function(){
             error: function (xhr, ajaxOptions, thrownError) {
                 console.log(xhr.status);
                 console.log(thrownError);
-                if (thrownError != '') showMessage(thrownError, 'ERROR');
+                if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
             }
         });
         console.log('sent config JSON with headers:', JSON.stringify(headers));
@@ -378,11 +378,11 @@ $(document).ready(function(){
             xhttp.onreadystatechange = function() {
                 if (xhttp.readyState == 4) {
                     if (xhttp.status == 200) {
-                    	showMessage(xhttp.responseText, 'INFO')
+                    	showMessage(xhttp.responseText, 'MESSAGING_INFO')
                     } else if (xhttp.status == 0) {
-                    	showMessage("Upload connection was closed abruptly!", 'ERROR');
+                    	showMessage("Upload connection was closed abruptly!", 'MESSAGING_ERROR');
                     } else {
-                    	showMessage(xhttp.status + " Error!\n" + xhttp.responseText, 'ERROR');
+                    	showMessage(xhttp.status + " Error!\n" + xhttp.responseText, 'MESSAGING_ERROR');
                     }
                 }
             };
@@ -414,7 +414,7 @@ $(document).ready(function(){
             error: function (xhr, ajaxOptions, thrownError) {
                 console.log(xhr.status);
                 console.log(thrownError);
-                if (thrownError != '') showMessage(thrownError, 'ERROR');
+                if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
             }
         });
         enableStatusTimer = true;
@@ -597,7 +597,7 @@ function performConnect(conntype){
         error: function (xhr, ajaxOptions, thrownError) {
             console.log(xhr.status);
             console.log(thrownError);
-            if (thrownError != '') showMessage(thrownError, 'ERROR');
+            if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
         }
     });
 
@@ -645,18 +645,44 @@ function refreshAPHTML(data){
 
     $( "#wifi-list" ).html(h)
 }
+
 function getMessages() {
-    $.getJSON("/messages.json", function(data) {
-        data.forEach(function(msg) {
-        	message: "{"ota_dsc":"Erasing flash complete","ota_pct":0}"
-        });
-        
-    })
-    .fail(function(xhr, ajaxOptions, thrownError) {
-        console.log(xhr.status);
-        console.log(thrownError);
-        if (thrownError != '') showMessage(thrownError, 'ERROR');
-    });
+	   $.getJSON("/messages.json", function(data) {
+	        data.forEach(function(msg) {
+				var msg_age = msg["current_time"] - msg["sent_time"];
+	        	switch (msg["class"]) {
+	        		case "MESSAGING_CLASS_OTA":
+	        			//message: "{"ota_dsc":"Erasing flash complete","ota_pct":0}"
+	        			var ota_data = JSON.parse(msg["message"]);
+	        			if (ota_data.hasOwnProperty('ota_pct') && ota_data['ota_pct'] != 0){
+	        	            otapct = ota_data['ota_pct'];
+	        	            $('.progress-bar').css('width', otapct+'%').attr('aria-valuenow', otapct);
+	        	            $('.progress-bar').html(otapct+'%');
+	        	        }
+	        	        if (ota_data.hasOwnProperty('ota_dsc') && ota_data['ota_dsc'] != ''){
+	        	            otadsc = ota_data['ota_dsc'];
+	        	            $("span#flash-status").html(otadsc);
+	        	            if (otadsc.match(/Error:/) || otapct > 95) {
+	        	                blockFlashButton = false;
+	        	                enableStatusTimer = true;
+	        	            }
+	        	        }        			
+	        			break;
+	        		case "MESSAGING_CLASS_SYSTEM":
+	        			showMessage(msg["message"], msg["type"],msg_age);
+	        			lastMsg = msg;
+	        			break;
+				default:
+					break;
+				}	
+	        });
+	        
+	    })
+	    .fail(function(xhr, ajaxOptions, thrownError) {
+	        console.log(xhr.status);
+	        console.log(thrownError);
+	        if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
+	    });
 }
 function checkStatus(){
     RepeatCheckStatusInterval();
@@ -780,29 +806,10 @@ function checkStatus(){
             ver = data['version'];
             $("span#foot-fw").html("fw: <strong>"+ver+"</strong>, mode: <strong>"+pname+"</strong>");
         }
-        if (data.hasOwnProperty('ota_pct') && data['ota_pct'] != 0){
-            otapct = data['ota_pct'];
-            $('.progress-bar').css('width', otapct+'%').attr('aria-valuenow', otapct);
-            $('.progress-bar').html(otapct+'%');
-        }
-        if (data.hasOwnProperty('ota_dsc') && data['ota_dsc'] != ''){
-            otadsc = data['ota_dsc'];
-            $("span#flash-status").html(otadsc);
-            if (otadsc.match(/Error:/) || otapct > 95) {
-                blockFlashButton = false;
-                enableStatusTimer = true;
-            }
-        } else {
+         else {
             $("span#flash-status").html('');
         }
-        if (data.hasOwnProperty('message') && data['message'] != ''){
-            var msg = data['message'].text;
-            var severity = data['message'].severity;
-            if (msg != lastMsg) {
-                showMessage(msg, severity);
-                lastMsg = msg;
-            }
-        }
+       
         if (data.hasOwnProperty('Voltage')) {
             var voltage = data['Voltage'];
             var layer;
@@ -832,7 +839,7 @@ function checkStatus(){
     .fail(function(xhr, ajaxOptions, thrownError) {
         console.log(xhr.status);
         console.log(thrownError);
-        if (thrownError != '') showMessage(thrownError, 'ERROR');
+        if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
         blockAjax = false;
     });
 }
@@ -888,20 +895,25 @@ function getConfig() {
     .fail(function(xhr, ajaxOptions, thrownError) {
         console.log(xhr.status);
         console.log(thrownError);
-        if (thrownError != '') showMessage(thrownError, 'ERROR');
+        if (thrownError != '') showMessage(thrownError, 'MESSAGING_ERROR');
         blockAjax = false;
     });
 }
 
 
-function showMessage(message, severity) {
-    if (severity == 'INFO') {
+function showMessage(message, severity, age=0) {
+	
+	if (severity == 'MESSAGING_INFO') {
         $('#message').css('background', '#6af');
-    } else if (severity == 'WARNING') {
+    } else if (severity == 'MESSAGING_WARNING') {
         $('#message').css('background', '#ff0');
+    } else if (severity == 'MESSAGING_ERROR' ) {
+        $('#message').css('background', '#f00');
     } else {
         $('#message').css('background', '#f00');
     }
+    	
+    	
     $('#message').html(message);
     $("#content").fadeTo("slow", 0.3, function() {
         $("#message").show(500).delay(5000).hide(500, function() {

+ 1 - 1
components/wifi-manager/index.html

@@ -17,7 +17,7 @@
         <script src="/res/test/bootstrap.min.js"></script> <!-- TODO delete -->
 
         <script src="/res/code.js"></script>
-        <script src="code.js"></script> <!-- TODO delete -->
+
 
 
         <title>esp32-wifi-manager</title>