[1.1.5] Add support for alert button

Rename Panicclient to AlarmItem and Botclient to PositionItem, also use all dates in UTC
functions.js is now responsible for timecalculations, so that the utc times are changed to the local browser time
nav.js is now map.js so its more clear what it did
Server.cs has now a function that gives the utc server time for timecorrection
This commit is contained in:
BlubbFish 2019-03-31 12:57:59 +02:00
parent 4444b97d3b
commit 4ad9814a84
11 changed files with 126 additions and 86 deletions

View File

@ -46,9 +46,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Model\Marker.cs" /> <Compile Include="Model\Marker.cs" />
<Compile Include="Model\Panicclient.cs" /> <Compile Include="Model\AlarmItem.cs" />
<Compile Include="Server.cs" /> <Compile Include="Server.cs" />
<Compile Include="Model\Botclient.cs" /> <Compile Include="Model\PositionItem.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
@ -115,6 +115,9 @@
<Content Include="resources\icons\marker\thw\einheiten\27-92.png"> <Content Include="resources\icons\marker\thw\einheiten\27-92.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="resources\js\functions.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="resources\js\leaflet\images\layers-2x.png" /> <Content Include="resources\js\leaflet\images\layers-2x.png" />
<Content Include="resources\js\leaflet\images\layers.png" /> <Content Include="resources\js\leaflet\images\layers.png" />
<Content Include="resources\js\leaflet\images\marker-icon-2x.png" /> <Content Include="resources\js\leaflet\images\marker-icon-2x.png" />
@ -134,7 +137,7 @@
<Content Include="resources\js\menu.js"> <Content Include="resources\js\menu.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="resources\js\nav.js"> <Content Include="resources\js\map.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="resources\js\marker.js"> <Content Include="resources\js\marker.js">

View File

@ -3,26 +3,26 @@ using System.Globalization;
using LitJson; using LitJson;
namespace Fraunhofer.Fit.IoT.LoraMap.Model { namespace Fraunhofer.Fit.IoT.LoraMap.Model {
class Panicclient { class AlarmItem {
public Double Rssi { get; private set; } public Double Rssi { get; private set; }
public Double Snr { get; private set; } public Double Snr { get; private set; }
public DateTime Upatedtime { get; private set; } public DateTime Lorarecievedtime { get; private set; }
public DateTime Recievedtime { get; private set; }
public Double Latitude { get; private set; } public Double Latitude { get; private set; }
public Double Longitude { get; private set; } public Double Longitude { get; private set; }
public Double Hdop { get; private set; } public Double Hdop { get; private set; }
public Boolean Fix { get; private set; } public Boolean Fix { get; private set; }
public Double Height { get; private set; } public Double Height { get; private set; }
public DateTime Triggerdtime { get; private set; }
public Panicclient(JsonData json) => this.Update(json); public AlarmItem(JsonData json) => this.Update(json);
public void Update(JsonData json) { public void Update(JsonData json) {
this.Triggerdtime = DateTime.Now;
this.Rssi = (Double)json["Rssi"]; this.Rssi = (Double)json["Rssi"];
this.Snr = (Double)json["Snr"]; this.Snr = (Double)json["Snr"];
if(DateTime.TryParse((String)json["Receivedtime"], DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out DateTime updatetime)) { if(DateTime.TryParse((String)json["Receivedtime"], DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out DateTime updatetime)) {
this.Upatedtime = updatetime; this.Lorarecievedtime = updatetime.ToUniversalTime();
} }
this.Recievedtime = DateTime.UtcNow;
this.Latitude = (Double)json["Gps"]["Latitude"]; this.Latitude = (Double)json["Gps"]["Latitude"];
this.Longitude = (Double)json["Gps"]["Longitude"]; this.Longitude = (Double)json["Gps"]["Longitude"];
this.Fix = (Boolean)json["Gps"]["Fix"]; this.Fix = (Boolean)json["Gps"]["Fix"];

View File

@ -3,13 +3,15 @@ using System.Globalization;
using LitJson; using LitJson;
namespace Fraunhofer.Fit.IoT.LoraMap.Model { namespace Fraunhofer.Fit.IoT.LoraMap.Model {
class Botclient { class PositionItem {
public Double Rssi { get; private set; } public Double Rssi { get; private set; }
public Double Snr { get; private set; } public Double Snr { get; private set; }
public DateTime Upatedtime { get; private set; } public DateTime Lorarecievedtime { get; private set; }
public DateTime Recievedtime { get; private set; }
public Double Latitude { get; private set; } public Double Latitude { get; private set; }
public Double Longitude { get; private set; } public Double Longitude { get; private set; }
public Double Hdop { get; private set; } public Double Hdop { get; private set; }
public DateTime Lastgpspostime { get; private set; }
public Double Battery { get; private set; } public Double Battery { get; private set; }
public Int32 Batterysimple { get; private set; } public Int32 Batterysimple { get; private set; }
public Boolean Fix { get; private set; } public Boolean Fix { get; private set; }
@ -17,7 +19,7 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model {
public String Name { get; private set; } public String Name { get; private set; }
public String Icon { get; private set; } public String Icon { get; private set; }
public Botclient(JsonData json, JsonData marker) { public PositionItem(JsonData json, JsonData marker) {
this.Update(json); this.Update(json);
String id = GetId(json); String id = GetId(json);
if(marker.ContainsKey(id)) { if(marker.ContainsKey(id)) {
@ -48,6 +50,7 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model {
&& json["Gps"].ContainsKey("Longitude") && json["Gps"]["Longitude"].IsDouble && json["Gps"].ContainsKey("Longitude") && json["Gps"]["Longitude"].IsDouble
&& json["Gps"].ContainsKey("LastLatitude") && json["Gps"]["LastLatitude"].IsDouble && json["Gps"].ContainsKey("LastLatitude") && json["Gps"]["LastLatitude"].IsDouble
&& json["Gps"].ContainsKey("LastLongitude") && json["Gps"]["LastLongitude"].IsDouble && json["Gps"].ContainsKey("LastLongitude") && json["Gps"]["LastLongitude"].IsDouble
&& json["Gps"].ContainsKey("LastLongitude") && json["Gps"]["LastGPSPos"].IsString
&& json["Gps"].ContainsKey("Hdop") && json["Gps"]["Hdop"].IsDouble && json["Gps"].ContainsKey("Hdop") && json["Gps"]["Hdop"].IsDouble
&& json["Gps"].ContainsKey("Fix") && json["Gps"]["Fix"].IsBoolean && json["Gps"].ContainsKey("Fix") && json["Gps"]["Fix"].IsBoolean
&& json["Gps"].ContainsKey("Height") && json["Gps"]["Height"].IsDouble && json["Gps"].ContainsKey("Height") && json["Gps"]["Height"].IsDouble
@ -58,8 +61,9 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model {
this.Rssi = (Double)json["Rssi"]; this.Rssi = (Double)json["Rssi"];
this.Snr = (Double)json["Snr"]; this.Snr = (Double)json["Snr"];
if(DateTime.TryParse((String)json["Receivedtime"], DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out DateTime updatetime)) { if(DateTime.TryParse((String)json["Receivedtime"], DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out DateTime updatetime)) {
this.Upatedtime = updatetime; this.Lorarecievedtime = updatetime.ToUniversalTime();
} }
this.Recievedtime = DateTime.UtcNow;
this.Battery = Math.Round((Double)json["BatteryLevel"], 2); this.Battery = Math.Round((Double)json["BatteryLevel"], 2);
if(this.Battery < 3) { if(this.Battery < 3) {
this.Batterysimple = 0; this.Batterysimple = 0;
@ -79,6 +83,9 @@ namespace Fraunhofer.Fit.IoT.LoraMap.Model {
this.Latitude = (Double)json["Gps"]["LastLatitude"]; this.Latitude = (Double)json["Gps"]["LastLatitude"];
this.Longitude = (Double)json["Gps"]["LastLongitude"]; this.Longitude = (Double)json["Gps"]["LastLongitude"];
} }
if(DateTime.TryParse((String)json["Gps"]["LastGPSPos"], DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out DateTime lastgpstime)) {
this.Lastgpspostime = lastgpstime.ToUniversalTime();
}
this.Hdop = (Double)json["Gps"]["Hdop"]; this.Hdop = (Double)json["Gps"]["Hdop"];
this.Height = (Double)json["Gps"]["Height"]; this.Height = (Double)json["Gps"]["Height"];
} }

View File

@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Fraunhofer FIT")] [assembly: AssemblyCompany("Fraunhofer FIT")]
[assembly: AssemblyProduct("Lora-Map")] [assembly: AssemblyProduct("Lora-Map")]
[assembly: AssemblyCopyright("Copyright © 2018 - 10.03.2019")] [assembly: AssemblyCopyright("Copyright © 2018 - 30.03.2019")]
[assembly: AssemblyTrademark("Fraunhofer FIT, BlubbFish")] [assembly: AssemblyTrademark("Fraunhofer FIT, BlubbFish")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("de-DE")] [assembly: NeutralResourcesLanguage("de-DE")]
@ -33,12 +33,13 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// übernehmen, indem Sie "*" eingeben: // übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.4")] [assembly: AssemblyVersion("1.1.5")]
[assembly: AssemblyFileVersion("1.1.4")] [assembly: AssemblyFileVersion("1.1.5")]
/* /*
* 1.1.1 Add Debian package config * 1.1.1 Add Debian package config
* 1.1.2 #2 Show versions number in Site * 1.1.2 #2 Show versions number in Site
* 1.1.3 #1 Click on icon and show details * 1.1.3 #1 Click on icon and show details
* 1.1.4 #3 Create icons for devices * 1.1.4 #3 Create icons for devices
* 1.1.5 Add support for alert button
*/ */

View File

@ -13,8 +13,8 @@ using LitJson;
namespace Fraunhofer.Fit.IoT.LoraMap { namespace Fraunhofer.Fit.IoT.LoraMap {
class Server : Webserver class Server : Webserver
{ {
private readonly SortedDictionary<String, Botclient> locations = new SortedDictionary<String, Botclient>(); private readonly SortedDictionary<String, PositionItem> positions = new SortedDictionary<String, PositionItem>();
private readonly SortedDictionary<String, Panicclient> panics = new SortedDictionary<String, Panicclient>(); private readonly SortedDictionary<String, AlarmItem> alarms = new SortedDictionary<String, AlarmItem>();
private readonly JsonData marker; private readonly JsonData marker;
private readonly Dictionary<String, Marker> markertable = new Dictionary<String, Marker>(); private readonly Dictionary<String, Marker> markertable = new Dictionary<String, Marker>();
@ -23,20 +23,20 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
protected override void Backend_MessageIncomming(Object sender, BackendEvent e) { protected override void Backend_MessageIncomming(Object sender, BackendEvent e) {
try { try {
JsonData d = JsonMapper.ToObject(e.Message); JsonData d = JsonMapper.ToObject(e.Message);
if (Botclient.CheckJson(d) && ((String)e.From).Contains("lora/data")) { if (PositionItem.CheckJson(d) && ((String)e.From).Contains("lora/data")) {
String name = Botclient.GetId(d); String name = PositionItem.GetId(d);
if (this.locations.ContainsKey(name)) { if (this.positions.ContainsKey(name)) {
this.locations[name].Update(d); this.positions[name].Update(d);
} else { } else {
this.locations.Add(name, new Botclient(d, this.marker)); this.positions.Add(name, new PositionItem(d, this.marker));
} }
Console.WriteLine("Koordinate erhalten!"); Console.WriteLine("Koordinate erhalten!");
} else if(Panicclient.CheckJson(d) && ((String)e.From).Contains("lora/panic")) { } else if(AlarmItem.CheckJson(d) && ((String)e.From).Contains("lora/panic")) {
String name = Panicclient.GetId(d); String name = AlarmItem.GetId(d);
if(this.panics.ContainsKey(name)) { if(this.alarms.ContainsKey(name)) {
this.panics[name].Update(d); this.alarms[name].Update(d);
} else { } else {
this.panics.Add(name, new Panicclient(d)); this.alarms.Add(name, new AlarmItem(d));
} }
Console.WriteLine("PANIC erhalten!"); Console.WriteLine("PANIC erhalten!");
} }
@ -48,10 +48,10 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
protected override void SendResponse(HttpListenerContext cont) { protected override void SendResponse(HttpListenerContext cont) {
try { try {
if (cont.Request.Url.PathAndQuery.StartsWith("/loc")) { if (cont.Request.Url.PathAndQuery.StartsWith("/loc")) {
this.SendJsonResponse(this.locations, cont); this.SendJsonResponse(this.positions, cont);
return; return;
} else if(cont.Request.Url.PathAndQuery.StartsWith("/panic")) { } else if(cont.Request.Url.PathAndQuery.StartsWith("/panic")) {
this.SendJsonResponse(this.panics, cont); this.SendJsonResponse(this.alarms, cont);
return; return;
} else if (cont.Request.Url.PathAndQuery.StartsWith("/icons/marker/Marker.svg") && cont.Request.Url.PathAndQuery.Contains("?")) { } else if (cont.Request.Url.PathAndQuery.StartsWith("/icons/marker/Marker.svg") && cont.Request.Url.PathAndQuery.Contains("?")) {
String hash = cont.Request.Url.PathAndQuery.Substring(cont.Request.Url.PathAndQuery.IndexOf('?') + 1); String hash = cont.Request.Url.PathAndQuery.Substring(cont.Request.Url.PathAndQuery.IndexOf('?') + 1);
@ -64,6 +64,9 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
cont.Response.OutputStream.Write(buf, 0, buf.Length); cont.Response.OutputStream.Write(buf, 0, buf.Length);
Console.WriteLine("200 - " + cont.Request.Url.PathAndQuery); Console.WriteLine("200 - " + cont.Request.Url.PathAndQuery);
return; return;
} else if(cont.Request.Url.PathAndQuery.StartsWith("/currenttime")) {
this.SendJsonResponse(new Dictionary<String, DateTime>() { { "utc", DateTime.UtcNow } }, cont);
return;
} }
} catch (Exception e) { } catch (Exception e) {
Helper.WriteError("500 - " + e.Message); Helper.WriteError("500 - " + e.Message);

View File

@ -1,2 +1,2 @@
[js/nav.js] [js/map.js]
start_location=50.7, 7.2 start_location=50.7, 7.2

View File

@ -35,7 +35,8 @@
</div> </div>
</div> </div>
<script type="text/javascript" src="js/leaflet/leaflet.js"></script> <script type="text/javascript" src="js/leaflet/leaflet.js"></script>
<script type="text/javascript" src="js/nav.js"></script> <script type="text/javascript" src="js/functions.js"></script>
<script type="text/javascript" src="js/map.js"></script>
<script type="text/javascript" src="js/menu.js"></script> <script type="text/javascript" src="js/menu.js"></script>
<script type="text/javascript" src="js/marker.js"></script> <script type="text/javascript" src="js/marker.js"></script>
</body> </body>

View File

@ -0,0 +1,43 @@
setInterval(timecorrectionrunner, 60000);
timecorrectionrunner();
function timecorrectionrunner() {
var timecorrection = new XMLHttpRequest();
timecorrection.onreadystatechange = parseAjaxTimecorrection;
timecorrection.open("GET", "http://{%REQUEST_URL_HOST%}:8080/currenttime", true);
timecorrection.send();
}
var timeOffset = 0;
function parseAjaxTimecorrection() {
if (this.readyState === 4 && this.status === 200) {
utcobject = JSON.parse(this.responseText);
if (utcobject.hasOwnProperty("utc")) {
timeOffset = Date.now() - Date.parse(utcobject["utc"]);
}
}
}
function timeCalculation(timestr, type) {
if (type === "diffraw" || type === "difftext") {
var diff = Math.round((Date.now() - Date.parse(timestr) - timeOffset) / 1000);
if (type === "diffraw") {
return diff;
}
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";
} else if (type === "str") {
var date = new Date(Date.parse(timestr) + timeOffset);
var str = date.toLocaleString();
return str;
}
}

View File

@ -19,24 +19,24 @@ function parseAjaxLoc() {
serverLocation = JSON.parse(this.responseText); serverLocation = JSON.parse(this.responseText);
for (var key in serverLocation) { for (var key in serverLocation) {
if (serverLocation.hasOwnProperty(key)) { if (serverLocation.hasOwnProperty(key)) {
var markeritem = serverLocation[key]; var positionItem = serverLocation[key];
if (markeritem['Latitude'] !== 0 || markeritem['Longitude'] !== 0) { if (positionItem['Latitude'] !== 0 || positionItem['Longitude'] !== 0) {
if (!markers.hasOwnProperty(key)) { if (!markers.hasOwnProperty(key)) {
var marker = null; var marker = null;
if (markeritem['Icon'] === null) { if (positionItem['Icon'] === null) {
marker = L.marker([markeritem['Latitude'], markeritem['Longitude']], { 'title': markeritem['Name'] }); marker = L.marker([positionItem['Latitude'], positionItem['Longitude']], { 'title': positionItem['Name'] });
} else { } else {
var myIcon = L.divIcon({ var myIcon = L.divIcon({
className: 'pos-marker', className: 'pos-marker',
iconSize: [56, 80], iconSize: [56, 80],
iconAnchor: [0, 80], iconAnchor: [0, 80],
html: '<object data="'+markeritem['Icon']+'" type="image/svg+xml" style="height:80px; width:56px;"></object>' html: '<object data="'+positionItem['Icon']+'" type="image/svg+xml" style="height:80px; width:56px;"></object>'
}); });
marker = L.marker([markeritem['Latitude'], markeritem['Longitude']], { 'title': markeritem['Name'], 'icon': myIcon }); marker = L.marker([positionItem['Latitude'], positionItem['Longitude']], { 'title': positionItem['Name'], 'icon': myIcon });
} }
markers[key] = marker.addTo(mymap).on("click", showMarkerInfo, key); markers[key] = marker.addTo(mymap).on("click", showMarkerInfo, key);
} else { } else {
markers[key].setLatLng([markeritem['Latitude'], markeritem['Longitude']]); markers[key].setLatLng([positionItem['Latitude'], positionItem['Longitude']]);
} }
} }
} }
@ -51,13 +51,13 @@ function parseAjaxPanic() {
var panics = JSON.parse(this.responseText); var panics = JSON.parse(this.responseText);
for (var id in panics) { for (var id in panics) {
if (panics.hasOwnProperty(id)) { if (panics.hasOwnProperty(id)) {
var panicitem = panics[id]; var alertItem = panics[id];
if (markers.hasOwnProperty(id)) { if (markers.hasOwnProperty(id)) {
var marker = markers[id]; var marker = markers[id];
if (timeDiffRaw(panicitem["Triggerdtime"]) <= 10 && marker._icon.className.indexOf(" marker-alert") === -1) { if (timeCalculation(alertItem["Recievedtime"], "diffraw") <= 10 && marker._icon.className.indexOf(" marker-alert") === -1) {
marker._icon.className += " marker-alert"; marker._icon.className += " marker-alert";
showMarkerInfoPerId(id); showMarkerInfoPerId(id);
} else if (timeDiffRaw(panicitem["Triggerdtime"]) > 10 && marker._icon.className.indexOf(" marker-alert") !== -1) { } else if (timeCalculation(alertItem["Recievedtime"], "diffraw") > 10 && marker._icon.className.indexOf(" marker-alert") !== -1) {
marker._icon.className = marker._icon.className.replace(" marker-alert", ""); marker._icon.className = marker._icon.className.replace(" marker-alert", "");
} }
} }

View File

@ -39,19 +39,20 @@ function showMarkerInfoMenu() {
function updateDeviceStatus() { function updateDeviceStatus() {
document.getElementById("pannels_info").innerHTML = ""; document.getElementById("pannels_info").innerHTML = "";
if (serverLocation.hasOwnProperty(statusToDevice)) { if (serverLocation.hasOwnProperty(statusToDevice)) {
var markeritem = serverLocation[statusToDevice]; var positionItem = serverLocation[statusToDevice];
var html = "<div class=\"name\">Name: <span class=\"bold\">" + markeritem["Name"] + "</span></div>"; var html = "<div class=\"name\">Name: <span class=\"bold\">" + positionItem["Name"] + "</span></div>";
html += "<div class=\"batt\"><span class=\"bold\">Batterie:</span> " + markeritem["Battery"] + "V <img src=\"icons/akku/" + markeritem["Batterysimple"] + "-4.png\"></div>"; html += "<div class=\"batt\"><span class=\"bold\">Batterie:</span> " + positionItem["Battery"] + "V <img src=\"icons/akku/" + positionItem["Batterysimple"] + "-4.png\"></div>";
if (markeritem["Fix"]) { if (positionItem["Fix"]) {
html += "<div class=\"gps\" style=\"color: green;\">GPS-Empfang</div>"; html += "<div class=\"gps\" style=\"color: green;\">GPS-Empfang</div>";
} else { } else {
html += "<div class=\"gps\" style=\"color: red;\">kein GPS-Empfang</div>"; html += "<div class=\"gps\" style=\"color: red;\">kein GPS-Empfang</div>";
} }
html += "<div class=\"coord\">" + markeritem["Latitude"].toFixed(7) + ", " + markeritem["Longitude"].toFixed(7) + "</div>"; html += "<div class=\"coord\">" + positionItem["Latitude"].toFixed(7) + ", " + positionItem["Longitude"].toFixed(7) + "</div>";
html += "<div class=\"height\"><span class=\"bold\">Höhe:</span> " + markeritem["Height"].toFixed(1) + " m</div>"; html += "<div class=\"lastgps\"><span class=\"bold\">Letzter Wert:</span> Vor: " + timeCalculation(positionItem["Lastgpspostime"], "difftext") + "</div>";
html += "<div class=\"hdop\"><span class=\"bold\">HDOP:</span> " + markeritem["Hdop"].toFixed(1) + "</div>"; html += "<div class=\"height\"><span class=\"bold\">Höhe:</span> " + positionItem["Height"].toFixed(1) + " m</div>";
html += "<div class=\"update\"><span class=\"bold\">Update:</span> " + markeritem["Upatedtime"] + "<br><span class=\"bold\">Vor:</span> " + timeDiffToText(markeritem["Upatedtime"]) + "</div>"; html += "<div class=\"hdop\"><span class=\"bold\">HDOP:</span> " + positionItem["Hdop"].toFixed(1) + "</div>";
html += "<div><span class=\"bold\">RSSI:</span> " + markeritem["Rssi"] + ", <span class=\"bold\">SNR:</span> " + markeritem["Snr"] + "</div>"; html += "<div class=\"update\"><span class=\"bold\">Update:</span> " + timeCalculation(positionItem["Recievedtime"], "str") + "<br><span class=\"bold\">Vor:</span> " + timeCalculation(positionItem["Recievedtime"], "difftext") + "</div>";
html += "<div><span class=\"bold\">RSSI:</span> " + positionItem["Rssi"] + ", <span class=\"bold\">SNR:</span> " + positionItem["Snr"] + "</div>";
document.getElementById("pannels_info").innerHTML = html; document.getElementById("pannels_info").innerHTML = html;
} }
} }
@ -61,71 +62,52 @@ var overviewStatus = new Array();
function updateStatus() { function updateStatus() {
for (var id in serverLocation) { for (var id in serverLocation) {
if (serverLocation.hasOwnProperty(id)) { if (serverLocation.hasOwnProperty(id)) {
var markeritem = serverLocation[id]; var positionItem = serverLocation[id];
if (typeof overviewStatus[id] === "undefined") { if (typeof overviewStatus[id] === "undefined") {
overviewStatus[id] = createOverviewElement(markeritem, id); overviewStatus[id] = createOverviewElement(positionItem, id);
document.getElementById("pannels_pos").appendChild(overviewStatus[id]); document.getElementById("pannels_pos").appendChild(overviewStatus[id]);
} }
updateOverviewElement(markeritem, id); updateOverviewElement(positionItem, id);
} }
} }
} }
function updateOverviewElement(markeritem, id) { function updateOverviewElement(positionItem, id) {
if (markeritem["Batterysimple"] === 0) { if (positionItem["Batterysimple"] === 0) {
document.getElementById("overview-color-id-" + id).style.backgroundColor = "red"; document.getElementById("overview-color-id-" + id).style.backgroundColor = "red";
} else if (markeritem["Batterysimple"] === 1 || markeritem["Batterysimple"] === 2) { } else if (positionItem["Batterysimple"] === 1 || positionItem["Batterysimple"] === 2) {
document.getElementById("overview-color-id-" + id).style.backgroundColor = "yellow"; document.getElementById("overview-color-id-" + id).style.backgroundColor = "yellow";
} else if (markeritem["Batterysimple"] === 3 || markeritem["Batterysimple"] === 4) { } else if (positionItem["Batterysimple"] === 3 || positionItem["Batterysimple"] === 4) {
document.getElementById("overview-color-id-" + id).style.backgroundColor = "green"; document.getElementById("overview-color-id-" + id).style.backgroundColor = "green";
} }
document.getElementById("overview-name-id-" + id).innerText = markeritem["Name"]; document.getElementById("overview-name-id-" + id).innerText = positionItem["Name"];
document.getElementById("overview-akkuimg-id-" + id).src = "icons/akku/" + markeritem["Batterysimple"] + "-4.png"; document.getElementById("overview-akkuimg-id-" + id).src = "icons/akku/" + positionItem["Batterysimple"] + "-4.png";
if (markeritem["Fix"]) { if (positionItem["Fix"]) {
document.getElementById("overview-gps-id-" + id).innerText = "GPS-Empfang"; document.getElementById("overview-gps-id-" + id).innerText = "GPS-Empfang";
document.getElementById("overview-gps-id-" + id).style.color = "green"; document.getElementById("overview-gps-id-" + id).style.color = "green";
} else { } else {
document.getElementById("overview-gps-id-" + id).innerText = "kein GPS-Empfang"; document.getElementById("overview-gps-id-" + id).innerText = "kein GPS-Empfang";
document.getElementById("overview-gps-id-" + id).style.color = "red"; document.getElementById("overview-gps-id-" + id).style.color = "red";
} }
document.getElementById("overview-update-id-" + id).innerText = "Letzter Datenempfang: vor " + timeDiffToText(markeritem["Upatedtime"]); document.getElementById("overview-update-id-" + id).innerText = "Letzter Datenempfang: vor " + timeCalculation(positionItem["Recievedtime"], "difftext");
} }
function createOverviewElement(markeritem, id) { function createOverviewElement(positionItem, id) {
var divItem = document.createElement("div"); var divItem = document.createElement("div");
divItem.className = "item"; divItem.className = "item";
divItem.onclick = showMarkerInfoMenu; divItem.onclick = showMarkerInfoMenu;
divItem.setAttribute("rel", id); divItem.setAttribute("rel", id);
divItem.innerHTML = "<span class=\"color\" id=\"overview-color-id-" + id + "\"></span>"; divItem.innerHTML = "<span class=\"color\" id=\"overview-color-id-" + id + "\"></span>";
if (markeritem['Icon'] !== null) { if (positionItem['Icon'] !== null) {
divItem.innerHTML += "<span class=\"icon\"><object data=\"" + markeritem['Icon'] + "&marker-bg=hidden" + "\" type=\"image/svg+xml\"></object></span>"; divItem.innerHTML += "<span class=\"icon\"><object data=\"" + positionItem['Icon'] + "&marker-bg=hidden" + "\" type=\"image/svg+xml\"></object></span>";
} else { } else {
divItem.innerHTML += "<span class=\"icon\"><img src=\"icons/marker/map-marker.png\"></span>"; divItem.innerHTML += "<span class=\"icon\"><img src=\"icons/marker/map-marker.png\"></span>";
} }
divItem.innerHTML += "<div class=\"line1\">" + divItem.innerHTML += "<div class=\"line1\">" +
"<span class=\"name\" id=\"overview-name-id-" + id + "\"></span>" + "<span class=\"name\" id=\"overview-name-id-" + id + "\"></span>" +
"<span class=\"akku\"><img id=\"overview-akkuimg-id-" + id + "\" src=\"icons/akku/" + markeritem["Batterysimple"] + "-4.png\"></span>" + "<span class=\"akku\"><img id=\"overview-akkuimg-id-" + id + "\" src=\"icons/akku/" + positionItem["Batterysimple"] + "-4.png\"></span>" +
"</div>"; "</div>";
divItem.innerHTML += "<div class=\"line2\" style=\"color: red;\" id=\"overview-gps-id-" + id + "\">kein GPS-Empfang</div>"; divItem.innerHTML += "<div class=\"line2\" style=\"color: red;\" id=\"overview-gps-id-" + id + "\">kein GPS-Empfang</div>";
divItem.innerHTML += "<div class=\"line3\" id=\"overview-update-id-" + id + "\">Letzter Datenempfang: vor " + timeDiffToText(markeritem["Upatedtime"]) + "</div>"; divItem.innerHTML += "<div class=\"line3\" id=\"overview-update-id-" + id + "\">Letzter Datenempfang: vor " + timeCalculation(positionItem["Recievedtime"], "difftext") + "</div>";
return divItem; return 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";
}
function timeDiffRaw(time) {
return (Date.now() - Date.parse(time)) / 1000;
} }