From bdd78832f9e7e5f9727050cbb2adb5c0b1804fe9 Mon Sep 17 00:00:00 2001 From: Philip Schell Date: Fri, 8 Mar 2019 15:13:31 +0100 Subject: [PATCH] Extend of #1 --- Lora-Map/Googlelocation.cs | 14 +++---- Lora-Map/Model/Botclient.cs | 32 +++++++++------ Lora-Map/resources/index.html | 17 +------- Lora-Map/resources/js/nav.js | 75 +++++++++++++++++++++++++++++++++-- 4 files changed, 97 insertions(+), 41 deletions(-) diff --git a/Lora-Map/Googlelocation.cs b/Lora-Map/Googlelocation.cs index ebee39b..37002b7 100644 --- a/Lora-Map/Googlelocation.cs +++ b/Lora-Map/Googlelocation.cs @@ -36,18 +36,14 @@ namespace Fraunhofer.Fit.IoT.LoraMap { && d.ContainsKey("Name") && d["Name"].IsString) { String name = (String)d["Name"]; Botclient b = new Botclient(d); - if (b.Fix || b.Longitude != 0 || b.Latitude != 0) { - if (this.locations.ContainsKey(name)) { - this.locations[name] = b; - } else { - this.locations.Add(name,b); - } - Console.WriteLine("Koodinate erhalten!"); + if (this.locations.ContainsKey(name)) { + this.locations[name] = b; } else { - Console.WriteLine("Daten erhalten! (Kein Fix)"); + this.locations.Add(name, b); } + Console.WriteLine("Koordinate erhalten!"); } - } catch(Exception ex) { + } catch (Exception ex) { Helper.WriteError(ex.Message); } } diff --git a/Lora-Map/Model/Botclient.cs b/Lora-Map/Model/Botclient.cs index 8c768f1..fd1bee5 100644 --- a/Lora-Map/Model/Botclient.cs +++ b/Lora-Map/Model/Botclient.cs @@ -13,37 +13,44 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model { if (json.ContainsKey("Rssi") && json["Rssi"].IsDouble) { this.Rssi = (Double)json["Rssi"]; } - if(json.ContainsKey("Snr") && json["Snr"].IsDouble) { + if (json.ContainsKey("Snr") && json["Snr"].IsDouble) { this.Snr = (Double)json["Snr"]; } if (json.ContainsKey("Receivedtime") && json["Receivedtime"].IsString) { - if (DateTime.TryParse((String)json["Receivedtime"], DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeLocal, out DateTime updatetime)) { + if (DateTime.TryParse((String)json["Receivedtime"], DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out DateTime updatetime)) { this.Upatedtime = updatetime; } } - if(json.ContainsKey("BatteryLevel") && json["BatteryLevel"].IsDouble) { - this.Battery = Math.Round((Double)json["BatteryLevel"],2); + if (json.ContainsKey("BatteryLevel") && json["BatteryLevel"].IsDouble) { + this.Battery = Math.Round((Double)json["BatteryLevel"], 2); + if(this.Battery < 3) { + this.Batterysimple = 0; + } else if(this.Battery < 3.5) { + this.Batterysimple = 1; + } else { + this.Batterysimple = 2; + } } - if(json.ContainsKey("Gps") && json["Gps"].IsObject) { - if(json["Gps"].ContainsKey("Latitude") && json["Gps"]["Latitude"].IsDouble) { + if (json.ContainsKey("Gps") && json["Gps"].IsObject) { + if (json["Gps"].ContainsKey("Latitude") && json["Gps"]["Latitude"].IsDouble) { this.Latitude = (Double)json["Gps"]["Latitude"]; } - if(json["Gps"].ContainsKey("Longitude") && json["Gps"]["Longitude"].IsDouble) { + if (json["Gps"].ContainsKey("Longitude") && json["Gps"]["Longitude"].IsDouble) { this.Longitude = (Double)json["Gps"]["Longitude"]; } - if(json["Gps"].ContainsKey("Fix") && json["Gps"]["Fix"].IsBoolean) { + if (json["Gps"].ContainsKey("Fix") && json["Gps"]["Fix"].IsBoolean) { this.Fix = (Boolean)json["Gps"]["Fix"]; } - if(json["Gps"].ContainsKey("LastLatitude") && json["Gps"]["LastLatitude"].IsDouble && !this.Fix) { + if (json["Gps"].ContainsKey("LastLatitude") && json["Gps"]["LastLatitude"].IsDouble && !this.Fix) { this.Latitude = (Double)json["Gps"]["LastLatitude"]; } - if(json["Gps"].ContainsKey("LastLongitude") && json["Gps"]["LastLongitude"].IsDouble && !this.Fix) { + if (json["Gps"].ContainsKey("LastLongitude") && json["Gps"]["LastLongitude"].IsDouble && !this.Fix) { this.Longitude = (Double)json["Gps"]["LastLongitude"]; } - if(json["Gps"].ContainsKey("Hdop") && json["Gps"]["Hdop"].IsDouble) { + if (json["Gps"].ContainsKey("Hdop") && json["Gps"]["Hdop"].IsDouble) { this.Hdop = (Double)json["Gps"]["Hdop"]; } - if(json["Gps"].ContainsKey("Height") && json["Gps"]["Height"].IsDouble) { + if (json["Gps"].ContainsKey("Height") && json["Gps"]["Height"].IsDouble) { this.Height = (Double)json["Gps"]["Height"]; } } @@ -56,6 +63,7 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model { public Double Longitude { get; private set; } public Double Hdop { get; private set; } public Double Battery { get; private set; } + public Int32 Batterysimple { get; private set; } public Boolean Fix { get; private set; } public Double Height { get; private set; } diff --git a/Lora-Map/resources/index.html b/Lora-Map/resources/index.html index 9fc4b91..1ef9998 100644 --- a/Lora-Map/resources/index.html +++ b/Lora-Map/resources/index.html @@ -14,22 +14,7 @@
vx.x.x
-
-
- - -
- A - -
-
- GPS-Empfang -
-
- Letzter Datenempfang: vor 10 s -
-
-
+
diff --git a/Lora-Map/resources/js/nav.js b/Lora-Map/resources/js/nav.js index 334f023..dd52428 100644 --- a/Lora-Map/resources/js/nav.js +++ b/Lora-Map/resources/js/nav.js @@ -24,16 +24,83 @@ function parsedata() { for (var key in items) { if (items.hasOwnProperty(key)) { var markeritem = items[key]; - if (!markers.hasOwnProperty(key)) { - markers[key] = L.marker([markeritem['Latitude'], markeritem['Longitude']]).addTo(mymap); - } else { - markers[key].setLatLng([markeritem['Latitude'], markeritem['Longitude']]); + if (markeritem['Latitude'] != 0 || markeritem['Longitude'] != 0) { + if (!markers.hasOwnProperty(key)) { + markers[key] = L.marker([markeritem['Latitude'], markeritem['Longitude']]).addTo(mymap); + } else { + markers[key].setLatLng([markeritem['Latitude'], markeritem['Longitude']]); + } } } } + parseStatus(items); } } +function parseStatus(items) { + document.getElementById("pannels_pos").innerHTML = ""; + for (var name in items) { + if (items.hasOwnProperty(name)) { + var markeritem = items[name]; + var divItem = document.createElement("div"); + divItem.className = "item"; + var spanColor = document.createElement("span"); + spanColor.className = "color"; + if (markeritem["Batterysimple"] == 0) { + spanColor.style.backgroundColor = "red"; + } else if (markeritem["Batterysimple"] == 1) { + spanColor.style.backgroundColor = "yellow"; + } else if (markeritem["Batterysimple"] == 2) { + spanColor.style.backgroundColor = "green"; + } + divItem.appendChild(spanColor); + var spanIcon = document.createElement("span"); + spanIcon.className = "icon"; + divItem.appendChild(spanIcon); + var divLine1 = document.createElement("div"); + divLine1.className = "line1"; + var spanName = document.createElement("span"); + spanName.className = "name"; + spanName.innerText = name; + divLine1.appendChild(spanName); + var spanAkku = document.createElement("span"); + spanAkku.className = "akku"; + divLine1.appendChild(spanAkku); + divItem.appendChild(divLine1); + var divLine2 = document.createElement("div"); + divLine2.className = "line2"; + if (markeritem["Fix"]) { + divLine2.style.color = "green"; + divLine2.innerText = "GPS-Empfang"; + } else { + divLine2.style.color = "red"; + divLine2.innerText = "kein GPS-Empfang"; + } + divItem.appendChild(divLine2); + var divLine3 = document.createElement("div"); + divLine3.className = "line3"; + divLine3.innerText = "Letzter Datenempfang: vor " + timeDiffToText(markeritem["Upatedtime"]); + divItem.appendChild(divLine3); + document.getElementById("pannels_pos").appendChild(divItem); + } + } +} + +function timeDiffToText(time) { + var diff = Date.now() - Date.parse(time); + diff = Math.round(diff / 1000); + if (diff < 60) { + return diff + " s"; + } + if (diff < (60 * 60)) { + return Math.floor(diff / 60) + " m"; + } + if (diff < (60 * 60 * 24)) { + return Math.floor(diff / (60 * 60)) + " h"; + } + return Math.floor(diff / (60 * 60 * 24)) + " d"; +} + var visiblePanel = null; function showHidePanel(name) { if (visiblePanel == null) {