Kaynağa Gözat

adding admin login functionality

* there is a 'MAGIC_DRIVER_NAME' in the common header that `diu_minder` will look
  for and send a 'ok admin' message (instead of 'ok driver') on successful admin
  login
* the UI looks for 'ok admin' to pass control to the diagnostic screen, where one
  option is the equipment number
clementinecomputing 5 yıl önce
ebeveyn
işleme
6c3c34b1e5
2 değiştirilmiş dosya ile 26 ekleme ve 7 silme
  1. 13 1
      busunit/DIUv2/diu_main.c
  2. 13 6
      busunit/DIUv2/html/js/diu_ui-ORG.js

+ 13 - 1
busunit/DIUv2/diu_main.c

@@ -54,7 +54,7 @@
 
 #define _SLEN LINE_BUFFER_SIZE
 
-#define DIU_MINDER_VERSION "2.1.10"
+#define DIU_MINDER_VERSION "2.1.11"
 
 static const char *s_http_port = "60535";
 static struct mg_serve_http_opts s_http_server_opts;
@@ -914,6 +914,7 @@ static void ui_handle_driver_login(struct mg_connection *nc, struct http_message
 
   char msg_fail[] = "fail driver_login";
   char msg_success[] = "ok driver";
+  char msg_success_admin[] = "ok admin";
 
   ret = mg_get_http_var(&(hm->body), "driver", s_driver, _SLEN);
   if (ret<=0) { mg_http_send_error(nc, 404, NULL); return; }
@@ -930,6 +931,17 @@ static void ui_handle_driver_login(struct mg_connection *nc, struct http_message
     return;
   }
 
+  // If we have an admin login, indicate a successful login and give a message
+  // to the UI indicating it's an 'admin' login
+  //
+  if (!strcmp(my_driver_status.driver_name, MAGIC_DRIVER_NAME)) {
+    mg_printf(nc, "HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n%s",
+        (unsigned long)strlen(msg_success_admin), msg_success_admin);
+    return;
+  }
+
+  // Otherwise a normal driver login
+  //
   mg_printf(nc, "HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n%s",
       (unsigned long)strlen(msg_success), msg_success);
 }

+ 13 - 6
busunit/DIUv2/html/js/diu_ui-ORG.js

@@ -149,10 +149,6 @@ function _api_request(action, param, cb_ok, cb_fail, cb_neterr) {
   req.onerror = function() { console.log("network error"); };
 
   try {
-
-    //DEBUG
-    console.log("req, varstr:", varstr);
-
     req.open("POST", url, true);
     req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
     req.send(varstr);
@@ -457,11 +453,22 @@ function _verify_driver() {
   return;
 }
 
-function _verify_driver_ok() {
-  console.log("driver ok");
+function _verify_driver_ok(dat) {
+  console.log("driver ok:", dat);
 
   _clear_ui_watchdog();
 
+  var tok = dat.split(" ");
+
+  // If we have an admin login...
+  //
+  if ( (tok.length >= 2) &&
+       ((tok[1] == "admin") ||
+        (tok[1] == "AdminMode")) ) {
+    _switch_ui("ui_diagnostic");
+    return;
+  }
+
   _switch_ui("ui_paddle");
 }