Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Baseline 4 preliminary steps #22

Merged
merged 42 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a159710
Initial Baseline 4 implementation for DMI
cesarBLG Sep 19, 2023
90cb196
Update odometer relocation for baseline 4
cesarBLG Sep 24, 2023
dc4cd52
Fix distance bugs
cesarBLG Sep 24, 2023
4d53ab7
Debug messages
cesarBLG Sep 29, 2023
769ae1c
Fix shift not included
cesarBLG Oct 1, 2023
58759d2
Fix menu items
cesarBLG Oct 1, 2023
a35eb9e
Fix confidence interval calculation
cesarBLG Oct 1, 2023
4904c0f
Fix confidence interval for odometer distances. Second try
cesarBLG Oct 2, 2023
8fd51e7
Baseline 3 and 4 variables
cesarBLG Oct 2, 2023
2df9420
Fix LX in rear bug
cesarBLG Oct 5, 2023
c270528
Do not terminate session if phone number changes
cesarBLG Oct 9, 2023
1cc8436
Show debug messages
cesarBLG Oct 15, 2023
dff903b
Bug fixes
cesarBLG Oct 18, 2023
6239cae
Refactor distances
cesarBLG Oct 19, 2023
132af87
Suppress PBD compile error
cesarBLG Oct 19, 2023
1cb66b3
Fix according to 3.12.2.5
cesarBLG Oct 20, 2023
85b6ca3
Minor fixes according to specs
cesarBLG Oct 20, 2023
f40a923
STM fixes
cesarBLG Oct 27, 2023
2c98f5c
STM improvements
cesarBLG Oct 29, 2023
8912252
Fix button press
cesarBLG Oct 29, 2023
f335677
Detect STM level icons
cesarBLG Oct 30, 2023
0aa9b7c
Obtain STM isolation status from train interface
cesarBLG Nov 1, 2023
051f01f
STM condition A15
cesarBLG Nov 1, 2023
edf20ea
Fix removal bug
cesarBLG Nov 2, 2023
1d5d4b9
STM broadcast
cesarBLG Nov 3, 2023
0d88a5d
Degraded transition to ASFA from LZB
cesarBLG Nov 4, 2023
18fd51d
Debug print option CMake
cesarBLG Nov 5, 2023
1ff4c31
Android file overwriting on update
cesarBLG Nov 5, 2023
3b23494
Add more unimplemented packets
cesarBLG Nov 6, 2023
78d8630
Do not use STM speeds until DA
cesarBLG Nov 12, 2023
50b9a05
Send consistend position reports
cesarBLG Nov 12, 2023
4595f23
Debug info about MA shortening
cesarBLG Nov 22, 2023
af5903e
Add default value for input fields
cesarBLG Nov 22, 2023
325bef1
Multi-row data view
cesarBLG Nov 22, 2023
d1d48d8
Merge branch 'skwara' into baseline-4
cesarBLG Dec 3, 2023
a31ec9e
Fix font size for not-SR mode
cesarBLG Dec 3, 2023
7409f5a
Add null pointer check
cesarBLG Dec 4, 2023
f4a5e26
Traindata update
albertosaurio65 Dec 4, 2023
d3e922a
OR wall time
cesarBLG Dec 4, 2023
1853b37
Use system time if no time set
cesarBLG Dec 4, 2023
33c34c6
Fix empty keyboard button
cesarBLG Dec 4, 2023
4a90dd3
Merge pull request #27 from cesarBLG/Alberto
cesarBLG Dec 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required (VERSION 3.14)
project (ETCS)
set(CMAKE_CXX_STANDARD 17)
option(SIMRAIL "SimRail" OFF)
option(DEBUG_VERBOSE "Print debug messages" ON)
if (NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "wasm.*")
set (WASM FALSE)
else()
Expand Down Expand Up @@ -32,5 +33,6 @@ endif()
if (WIN32)
add_definitions(-D_WIN32_WINNT=0x602)
endif()
add_definitions(-DBASELINE=3)
add_subdirectory(EVC)
add_subdirectory(DMI)
71 changes: 65 additions & 6 deletions DMI/STM/stm_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
*/
#include "stm_objects.h"
#include "../monitor.h"
#include "../tcp/server.h"
#include "../graphics/display.h"
#include "../graphics/text_button.h"
#include "../graphics/icon_button.h"
#include "../messages/messages.h"
#include "../time_etcs.h"
#include "../../EVC/Packets/STM/15.h"
#include "../../EVC/Packets/STM/32.h"
#include "../../EVC/Packets/STM/34.h"
#include "../../EVC/Packets/STM/35.h"
#include "../../EVC/Packets/STM/38.h"
#include "../../EVC/Packets/STM/39.h"
Expand Down Expand Up @@ -66,6 +68,7 @@ void setup_areas()
}
ntc_window::ntc_window(int nid_stm) : nid_stm(nid_stm)
{
customized = nullptr;
auto contents = platform->read_file(stm_layout_file);
if (contents) {
json j = json::parse(*contents);
Expand All @@ -85,7 +88,9 @@ ntc_window::ntc_window(int nid_stm) : nid_stm(nid_stm)
void ntc_window::display_indicator(int id, int position, int icon, std::string text, int properties, bool isButton)
{
auto it = indicators.find((isButton ? 256 : 0) + id);
bool wasPressed = false;
if (it != indicators.end()) {
if (it->second->isButton && ((Button*)it->second)->pressed) wasPressed = true;
remove(it->second);
delete it->second;
indicators.erase(it);
Expand Down Expand Up @@ -147,12 +152,21 @@ void ntc_window::display_indicator(int id, int position, int icon, std::string t
pos = areas[area];
}
Component *c;
if (isButton) c = new Button(pos[2], pos[3]);
if (isButton)
{
c = new Button(pos[2], pos[3]);
((Button*)c)->pressed = wasPressed;
}
else c = new Component(pos[2],pos[3]);
Color bg = get_color((properties>>3)&7, true);
Color fg = get_color(properties&7, false);
c->setBackgroundColor(bg);
c->setForegroundColor(fg);
if (bg != DarkBlue)
{
//c->dispBorder = false;
if (isButton) ((Button*)c)->showBorder = false;
}
bool text_also;
if (customized != nullptr)
{
Expand Down Expand Up @@ -188,7 +202,7 @@ void ntc_window::display_indicator(int id, int position, int icon, std::string t
c->flash_style = (flash-1) | (counterflash<<1);
if (customized != nullptr && customized->flash_style == 1) c->flash_style |= 4;
}
indicators[id] = c;
indicators[(isButton ? 256 : 0) + id] = c;
addToLayout(c, new RelativeAlignment(nullptr, pos[0], pos[1]));
}
void ntc_window::display_text(int id, bool ack, std::string text, int properties)
Expand All @@ -202,6 +216,48 @@ void ntc_window::display_text(int id, bool ack, std::string text, int properties
messages[id] = m;
if (active_ntc_window == this) addMsg(m);
}
void ntc_window::event(int evNo, float x, float y)
{
int64_t CurrentTime = platform->get_timer();
bool pressed = evNo == 1;
std::map<int, bool> changed;
for (auto &kvp : indicators) {
if (kvp.second->isButton) {
Button *b = (Button*)kvp.second;
bool inside = b->x < x && b->x + b->sx > x && b->y < y && b->y + b->sy > y;
bool p = inside && pressed;
if (p != b->pressed) {
b->pressed = p;
changed[kvp.first - 256] = p;
}
}
}
if (changed.size() > 0) {
stm_message msg;
msg.NID_STM.rawdata = nid_stm;
auto stmevent = std::make_shared<STMButtonEvent>();
stmevent->N_ITER.rawdata = changed.size();
for (auto &kvp : changed) {
STMButtonEventElement e;
e.NID_BUTTON.rawdata = kvp.first;
e.Q_BUTTON.rawdata = kvp.second;
e.T_BUTTONEVENT.rawdata = CurrentTime & 0xFFFFFFFF;
stmevent->elements.push_back(e);
}
msg.packets.push_back(stmevent);
bit_manipulator w;
msg.write_to(w);
std::string str;
for (auto &var : w.log_entries)
{
str += var.first + '\t' + var.second + '\n';
}
platform->debug_print(str);
std::string s = w.to_base64();
write_command("stmData", s);
}
window::event(evNo, x, y);
}
void initialize_stm_windows()
{
setup_areas();
Expand Down Expand Up @@ -239,10 +295,13 @@ void parse_stm_message(stm_message &message)
if (pack->NID_PACKET == 43)
{
STMSupervisionInformation &info = *((STMSupervisionInformation*)pack.get());
Vperm = info.V_PERMIT.rawdata;
Vtarget = info.V_TARGET.rawdata*5;
Vrelease = info.V_RELEASE.rawdata;
Vsbi = info.V_INTERV.rawdata;
if (state == stm_state::DA)
{
Vperm = info.V_PERMIT.rawdata;
Vtarget = info.V_TARGET.rawdata*5;
Vrelease = info.V_RELEASE.rawdata;
Vsbi = info.V_INTERV.rawdata;
}
Dtarg = (int)info.D_TARGET.get_value(info.Q_SCALE);
window->monitoring_data = stm_monitoring_data(info);
}
Expand Down
13 changes: 7 additions & 6 deletions DMI/STM/stm_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
using json = nlohmann::json;
struct stm_monitoring_data
{
Color needle_color;
int Vperm_display;
Color needle_color = Grey;
int Vperm_display = 0;
Color Vperm_color;
int Vtarget_display;
int Vtarget_display = 0;
Color Vtarget_color;
int Vsbi_display;
int Vsbi_display = 0;
Color Vsbi_color;
int Vrelease_display;
int Vrelease_display = 0;
Color Vrelease_color;
int Dtarget_display;
int Dtarget_display = 0;
stm_monitoring_data() = default;
stm_monitoring_data(const STMSupervisionInformation &info)
{
Expand Down Expand Up @@ -180,6 +180,7 @@ class ntc_window : public window
ntc_window(int nid_stm);
void display_indicator(int id, int position, int icon, std::string text, int properties, bool isButton);
void display_text(int id, bool ack, std::string text, int properties);
void event(int evNo, float x, float y);
~ntc_window()
{
for (auto &it : indicators)
Expand Down
8 changes: 1 addition & 7 deletions DMI/control/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,7 @@ void setWindow(json &data)
}
else if (type == "DataView")
{
std::vector<std::pair<std::string,std::string>> data;
json &fields = def["Fields"];
for (json &j : fields)
{
data.push_back({j["Label"], j["Value"]});
}
w = new data_view_window(def["WindowTitle"], data);
w = new data_view_window(def["WindowTitle"], def["Fields"]);
}
/*else if (type == "Menu") w = new menu(j["WindowDefinitionW"]);*/
}
Expand Down
Binary file added DMI/sound/ASFA_REC.wav
Binary file not shown.
Binary file added DMI/sound/ASFA_corto.wav
Binary file not shown.
74 changes: 67 additions & 7 deletions DMI/speed/gauge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ bool showSpeeds = false;
void displaya1();
Component a1(54,54, displaya1);
Component csg(2*cx, 2*cy, displayGauge);
#if BASELINE == 4
Component b8(36,36);
#endif
IconButton togglingButton("symbols/Driver Request/DR_01.bmp", 64, 50, []() {showSpeeds = !showSpeeds;});
#include "../graphics/text_graphic.h"
text_graphic *spd_nums[10] = {nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr};
Expand Down Expand Up @@ -74,6 +77,12 @@ void drawNeedle()
{
if (active_ntc_window != nullptr) needleColor = active_ntc_window->monitoring_data.needle_color;
}
#if BASELINE == 4
else if (mode == Mode::AD)
{
needleColor = Vtarget<=Vest || monitoring == RSM ? White : Grey;
}
#endif
else if(supervision == IntS)
{
needleColor = Red;
Expand Down Expand Up @@ -197,9 +206,17 @@ void displayCSG()
if (stm.Vrelease_display & 2) drawGauge(0,Vrelease,stm.Vrelease_color,133);
return;
}
if(mode != Mode::FS)
#if BASELINE < 4
if (mode != Mode::FS)
#else
if (mode != Mode::FS && mode != Mode::AD)
#endif
{
if((mode == Mode::OS || mode == Mode::SR) && showSpeeds)
if((mode == Mode::OS || mode == Mode::SR) && showSpeeds
#if BASELINE == 4
|| mode == Mode::SM
#endif
)
{
platform->set_color(White);
drawHook(Vperm);
Expand Down Expand Up @@ -231,15 +248,30 @@ void displayCSG()
if(monitoring == TSM)
{
drawGauge(0,Vtarget, DarkGrey);
#if BASELINE == 4
drawGauge(Vtarget, Vperm, mode == Mode::AD ? White : Yellow);
#else
drawGauge(Vtarget, Vperm, Yellow);
#endif
drawHook(Vperm);
}
if(monitoring == RSM)
{
#if BASELINE == 4
platform->set_color(mode == Mode::AD ? White : Yellow);
#else
platform->set_color(Yellow);
#endif
drawHook(Vperm);
}
if(supervision == OvS || supervision == WaS) drawGauge(Vperm,Vsbi,Orange,117);
if(supervision == OvS || supervision == WaS)
{
#if BASELINE == 4
drawGauge(Vperm,Vsbi, mode == Mode::AD ? (Vtarget<Vperm ? White : DarkGrey) : Orange,117);
#else
drawGauge(Vperm,Vsbi,Orange,117);
#endif
}
if(supervision == IntS) drawGauge(Vperm,Vsbi,Red,117);
if(Vrelease!=0 && Vtarget == 0 && (monitoring == TSM || monitoring == RSM))
{
Expand All @@ -249,12 +281,23 @@ void displayCSG()
float ang = speedToAngle(Vperm);
platform->set_color(Black);
csg.drawSolidArc(ang0,ang,132,133,cx,cy);
#if BASELINE == 4
platform->set_color(mode == Mode::AD ? White : Yellow);
#else
platform->set_color(Yellow);
#endif
csg.drawSolidArc(ang0,ang,128, 132,cx,cy);
}
else
{
if(monitoring == RSM) drawGauge(0, Vperm, Yellow);
if(monitoring == RSM)
{
#if BASELINE == 4
drawGauge(0, Vperm, mode == Mode::AD ? White : Yellow);
#else
drawGauge(0, Vperm, Yellow);
#endif
}
drawGauge(0,Vrelease,Black,132);
drawGauge(0,Vrelease,MediumGrey,133);
}
Expand Down Expand Up @@ -326,7 +369,13 @@ void displayVrelease()
{
releaseSignShown = true;
releaseRegion.clear();
releaseRegion.addText(to_string((int)std::round(Vrelease)).c_str(), 0, 0, 17, MediumGrey, CENTER, 0);
releaseRegion.addText(to_string((int)std::round(Vrelease)).c_str(), 0, 0, 17,
#if BASELINE == 4
mode == Mode::AD ? MediumGrey : Yellow,
#else
MediumGrey,
#endif
CENTER, 0);
prevVrelease = Vrelease;
}
} else {
Expand Down Expand Up @@ -367,9 +416,20 @@ void setLSSMA(int nlssma)
void displaya1()
{
if(mode == Mode::LS) return;
if((mode == Mode::FS || ((mode == Mode::OS || mode == Mode::SR) && showSpeeds)) && monitoring == CSM && TTI < TdispTTI)
if((mode == Mode::FS
#if BASELINE == 4
|| mode == Mode::AD || mode == Mode::SM
#endif
|| ((mode == Mode::OS || mode == Mode::SR) && showSpeeds)) && monitoring == CSM && TTI < TdispTTI)
{
if(!ttiShown) playSinfo();
if(!ttiShown)
{
#if BASELINE == 4
if (mode != Mode::AD) playSinfo();
#else
playSinfo();
#endif
}
ttiShown = true;
int n;
for(n = 1; n<11; n++)
Expand Down
2 changes: 2 additions & 0 deletions DMI/state/acks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ void dispAcks()
case Level::N2:
num=4;
break;
#if BASELINE < 4
case Level::N3:
num=5;
break;
#endif
}
num = 4 + 2*num;
if(levelAck == 2) num++;
Expand Down
12 changes: 10 additions & 2 deletions DMI/state/level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ extern Component distanceBar;
Component a4(54, 25, nullptr);
Component levelRegion(54, 25, displayLevel);
static Level prevlevel;
static int prevNTC;
void displayLevel()
{
if(prevlevel==level) return;
if(prevlevel==level && (level != Level::NTC || prevNTC == nid_ntc)) return;
prevlevel = level;
prevNTC = nid_ntc;
levelRegion.clear();
string path = "symbols/Level/LE_";
int num = 0;
Expand All @@ -36,14 +38,20 @@ void displayLevel()
case Level::N2:
num=4;
break;
#if BASELINE < 4
case Level::N3:
num=5;
break;
#endif
}
if (num == 0) return;
if(num<10) path+="0";
path+=to_string(num);
if (level == Level::NTC && (nid_ntc == 0 || nid_ntc == 10 || nid_ntc == 26)) path += "_" + to_string(nid_ntc);
if (level == Level::NTC)
{
std::string testpath = path + "_" + to_string(nid_ntc) + ".bmp";
if (levelRegion.getImageGraphic(testpath) != nullptr) path += "_" + to_string(nid_ntc);
}
path+=".bmp";
levelRegion.addImage(path);
}
10 changes: 9 additions & 1 deletion DMI/state/mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,17 @@ void displayMode()
case Mode::LS:
num = 21;
break;
case Mode::IS:
#if BASELINE == 4
case Mode::AD:
num = 23;
break;
case Mode::SM:
num = 24;
break;
#endif
case Mode::IS:
num = 25;
break;
}
if(num<10) path+="0";
path+=to_string(num);
Expand Down
Loading