mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 10:19:29 +02:00
Use rollover count at the time of the event, not the current value to
produce correct dates. Use 64-bit integers for timestamp to ease arithmetic.
This commit is contained in:
parent
dbf2def0e2
commit
001d254cd3
4 changed files with 36 additions and 33 deletions
|
@ -1,4 +1,5 @@
|
|||
#include "events_html.h"
|
||||
#include <limits>
|
||||
#include "../../datalayer/datalayer.h"
|
||||
|
||||
const char EVENTS_HTML_START[] = R"=====(
|
||||
|
@ -10,7 +11,9 @@ const char EVENTS_HTML_END[] = R"=====(
|
|||
button:hover { background-color: #3A4A52; }</style>
|
||||
<button onclick="askClear()">Clear all events</button>
|
||||
<button onclick="home()">Back to main page</button>
|
||||
<style>.event:nth-child(even){background-color:#455a64}.event:nth-child(odd){background-color:#394b52}</style><script>function showEvent(){document.querySelectorAll(".event").forEach(function(e){var n=e.querySelector(".sec-ago");n&&(n.innerText=new Date(Date.now()-(4294967296*+n.innerText.split(";")[0]+ +n.innerText.split(";")[1])).toLocaleString())})}function askClear(){window.confirm("Are you sure you want to clear all events?")&&(window.location.href="/clearevents")}function home(){window.location.href="/"}window.onload=function(){showEvent()}</script>
|
||||
<style>.event:nth-child(even){background-color:#455a64}.event:nth-child(odd){background-color:#394b52}</style>
|
||||
<script>function showEvent(){document.querySelectorAll(".event").forEach(function(e){var n=e.querySelector(".sec-ago");n&&(n.innerText=new Date(Number(BigInt(Date.now()) - BigInt(n.innerText))).toLocaleString())})}function askClear(){window.confirm("Are you sure you want to clear all events?")&&(window.location.href="/clearevents")}function home(){window.location.href="/"}window.onload=function(){showEvent()}
|
||||
</script>
|
||||
)=====";
|
||||
|
||||
static std::vector<EventData> order_events;
|
||||
|
@ -34,12 +37,15 @@ String events_processor(const String& var) {
|
|||
}
|
||||
// Sort events by timestamp
|
||||
std::sort(order_events.begin(), order_events.end(), compareEventsByTimestampDesc);
|
||||
unsigned long timestamp_now = millis();
|
||||
uint64_t current_timestamp =
|
||||
(uint64_t)datalayer.system.status.millisrolloverCount * (uint64_t)std::numeric_limits<uint32_t>::max() +
|
||||
(uint64_t)millis();
|
||||
|
||||
// Generate HTML and debug output
|
||||
for (const auto& event : order_events) {
|
||||
EVENTS_ENUM_TYPE event_handle = event.event_handle;
|
||||
event_pointer = event.event_pointer;
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
logging.println("Showing Event: " + String(get_event_enum_string(event_handle)) +
|
||||
" count: " + String(event_pointer->occurences) + " seconds: " + String(event_pointer->timestamp) +
|
||||
|
@ -49,8 +55,8 @@ String events_processor(const String& var) {
|
|||
content.concat("<div class='event'>");
|
||||
content.concat("<div>" + String(get_event_enum_string(event_handle)) + "</div>");
|
||||
content.concat("<div>" + String(get_event_level_string(event_handle)) + "</div>");
|
||||
content.concat("<div class='sec-ago'>" + String(datalayer.system.status.millisrolloverCount) + ";" +
|
||||
String(timestamp_now - event_pointer->timestamp) + "</div>");
|
||||
// Frontend expects to see time difference (in ms) from now to event
|
||||
content.concat("<div class='sec-ago'>" + String(current_timestamp - event_pointer->timestamp) + "</div>");
|
||||
content.concat("<div>" + String(event_pointer->occurences) + "</div>");
|
||||
content.concat("<div>" + String(event_pointer->data) + "</div>");
|
||||
content.concat("<div>" + String(get_event_message_string(event_handle)) + "</div>");
|
||||
|
@ -80,7 +86,7 @@ String events_processor(const String& var) {
|
|||
function showEvent() {
|
||||
document.querySelectorAll(".event").forEach(function (e) {
|
||||
var n = e.querySelector(".sec-ago");
|
||||
n && (n.innerText = new Date(Date.now() - (+n.innerText.split(";")[0] * 4294967296 + +n.innerText.split(";")[1])).toLocaleString());
|
||||
n && (n.innerText = new Date(Number(BigInt(Date.now()) - BigInt(n.innerText))).toLocaleString());
|
||||
});
|
||||
}
|
||||
function askClear() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue