From 17c82d96416473d3de7c5256733cddefe8827c50 Mon Sep 17 00:00:00 2001 From: milek7 Date: Sat, 31 Aug 2019 15:46:05 +0200 Subject: [PATCH] uart fixes, odometer and time/date on uart, simulation time fixes --- Train.cpp | 9 +++++---- Train.h | 1 + application.cpp | 12 ++++++++++-- simulationtime.cpp | 6 +++--- uart.cpp | 15 ++++++++++++--- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Train.cpp b/Train.cpp index c02fc004..ab2f0517 100644 --- a/Train.cpp +++ b/Train.cpp @@ -583,8 +583,8 @@ TTrain::state_t TTrain::get_state() const { return { - btLampkaSHP.GetValue(), - btLampkaCzuwaka.GetValue(), + mvOccupied->SecuritySystem.is_cabsignal_blinking(), + mvOccupied->SecuritySystem.is_vigilance_blinking(), btLampkaRadioStop.GetValue(), btLampkaOpory.GetValue(), btLampkaWylSzybki.GetValue(), @@ -599,14 +599,15 @@ TTrain::get_state() const { btLampkaOgrzewanieSkladu.GetValue(), btHaslerBrakes.GetValue(), btHaslerCurrent.GetValue(), - mvOccupied->SecuritySystem.is_blinking(), + mvOccupied->SecuritySystem.is_beeping(), btLampkaHVoltageB.GetValue(), fTachoVelocity, static_cast( mvOccupied->Compressor ), static_cast( mvOccupied->PipePress ), static_cast( mvOccupied->BrakePress ), fHVoltage, - { fHCurrent[ ( mvControlled->TrainType & dt_EZT ) ? 0 : 1 ], fHCurrent[ 2 ], fHCurrent[ 3 ] } + { fHCurrent[ ( mvControlled->TrainType & dt_EZT ) ? 0 : 1 ], fHCurrent[ 2 ], fHCurrent[ 3 ] }, + mvOccupied->DistCounter }; } diff --git a/Train.h b/Train.h index 1fe2d795..4c0cc7c2 100644 --- a/Train.h +++ b/Train.h @@ -99,6 +99,7 @@ class TTrain float brake_pressure; float hv_voltage; std::array hv_current; + float distance; }; typedef std::tuple, std::unique_ptr> screen_entry; typedef std::vector screen_map; diff --git a/application.cpp b/application.cpp index ec8d1580..b42e386f 100644 --- a/application.cpp +++ b/application.cpp @@ -817,9 +817,17 @@ bool eu07_application::init_network() { // TODO: sort out this timezone mess std::time_t utc_now = std::time(nullptr); - std::time_t local_now = utc_now + (std::mktime(std::localtime(&utc_now)) - std::mktime(std::gmtime(&utc_now))); - Global.starting_timestamp = local_now; + tm tm_local, tm_utc; + tm *tmp = std::localtime(&utc_now); + memcpy(&tm_local, tmp, sizeof(tm)); + tmp = std::gmtime(&utc_now); + memcpy(&tm_utc, tmp, sizeof(tm)); + + int64_t offset = (tm_local.tm_hour * 3600 + tm_local.tm_min * 60 + tm_local.tm_sec) + - (tm_utc.tm_hour * 3600 + tm_utc.tm_min * 60 + tm_utc.tm_sec); + + Global.starting_timestamp = utc_now + offset; Global.ready_to_load = true; } diff --git a/simulationtime.cpp b/simulationtime.cpp index e18c0216..2216db6a 100644 --- a/simulationtime.cpp +++ b/simulationtime.cpp @@ -33,8 +33,8 @@ scenario_time::init(std::time_t timestamp) { // cache requested elements, if any std::tm *tms = std::gmtime(×tamp); - m_time.wYear = tms->tm_year; - m_time.wMonth = tms->tm_mon; + m_time.wYear = tms->tm_year + 1900; + m_time.wMonth = tms->tm_mon + 1; m_time.wDayOfWeek = tms->tm_wday; m_time.wDay = tms->tm_mday; m_time.wHour = tms->tm_hour; @@ -53,7 +53,7 @@ scenario_time::init(std::time_t timestamp) { if( ( requestedhour != -1 ) || ( requestedminute != 1 ) ) { m_time.wSecond = 0; - } + } m_yearday = year_day( m_time.wDay, m_time.wMonth, m_time.wYear ); diff --git a/uart.cpp b/uart.cpp index 81116ccb..90d8e9a8 100644 --- a/uart.cpp +++ b/uart.cpp @@ -6,6 +6,7 @@ #include "Train.h" #include "parser.h" #include "Logs.h" +#include "simulationtime.h" uart_input::uart_input() { @@ -121,7 +122,7 @@ uart_input::recall_bindings() { return true; } -#define SPLIT_INT16(x) (uint8_t)x, (uint8_t)(x >> 8) +#define SPLIT_INT16(x) (uint8_t)(x), (uint8_t)((x) >> 8) void uart_input::poll() { @@ -234,6 +235,7 @@ void uart_input::poll() // TODO: ugly! move it into structure like input_bits auto const trainstate = t->get_state(); + SYSTEMTIME time = simulation::Time.data(); uint16_t tacho = Global.iPause ? 0 : (trainstate.velocity * conf.tachoscale); uint16_t tank_press = (uint16_t)std::min(conf.tankuart, trainstate.reservoir_pressure * 0.1f / conf.tankmax * conf.tankuart); uint16_t pipe_press = (uint16_t)std::min(conf.pipeuart, trainstate.pipe_pressure * 0.1f / conf.pipemax * conf.pipeuart); @@ -242,6 +244,7 @@ void uart_input::poll() uint16_t current1 = (uint16_t)std::min(conf.currentuart, trainstate.hv_current[0] / conf.currentmax * conf.currentuart); uint16_t current2 = (uint16_t)std::min(conf.currentuart, trainstate.hv_current[1] / conf.currentmax * conf.currentuart); uint16_t current3 = (uint16_t)std::min(conf.currentuart, trainstate.hv_current[2] / conf.currentmax * conf.currentuart); + uint32_t odometer = trainstate.distance * 1000.0f; std::array buffer { //byte 0-1 @@ -287,8 +290,14 @@ void uart_input::poll() SPLIT_INT16(current2), //byte 19-20 SPLIT_INT16(current3), - //byte 21-30 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + //byte 21-22 + SPLIT_INT16((time.wYear - 1) * 12 + time.wMonth - 1), + //byte 23-24 + SPLIT_INT16((time.wDay - 1) * 1440 + time.wHour * 60 + time.wMinute), + //byte 25-26 + SPLIT_INT16(time.wSecond * 1000 + time.wMilliseconds), + //byte 27-30 + SPLIT_INT16((uint16_t)odometer), SPLIT_INT16((uint16_t)(odometer >> 16)) }; if (conf.debug)