mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 01:59:19 +02:00
uart fixes, odometer and time/date on uart, simulation time fixes
This commit is contained in:
@@ -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<float>( mvOccupied->Compressor ),
|
||||
static_cast<float>( mvOccupied->PipePress ),
|
||||
static_cast<float>( 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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
1
Train.h
1
Train.h
@@ -99,6 +99,7 @@ class TTrain
|
||||
float brake_pressure;
|
||||
float hv_voltage;
|
||||
std::array<float, 3> hv_current;
|
||||
float distance;
|
||||
};
|
||||
typedef std::tuple<std::string, std::shared_ptr<python_rt>, std::unique_ptr<python_screen_viewer>> screen_entry;
|
||||
typedef std::vector<screen_entry> screen_map;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 );
|
||||
|
||||
|
||||
15
uart.cpp
15
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<uint8_t, 31> 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)
|
||||
|
||||
Reference in New Issue
Block a user