Skip to content

Commit

Permalink
General fixes. Work in progress STM-DMI implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarBLG committed Sep 23, 2022
1 parent d69d70f commit a276d8a
Show file tree
Hide file tree
Showing 42 changed files with 1,115 additions and 224 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
ETCS.kdev4
.directory
Thumbs.db
EVC/orts
error.log
MakeLists.txt.user
CMakeCache.txt
Expand All @@ -20,3 +19,5 @@ install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
libs/
build/
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.14)
project (ETCS)
option(ETCS_VENDORED "Use vendored libraries" ON)
option(ETCS_VENDORED "Use vendored libraries" OFF)
if (ETCS_VENDORED)
set(SDL2TTF_VENDORED ON CACHE BOOL "Vendored TTF libs")
add_subdirectory(libs/SDL EXCLUDE_FROM_ALL)
Expand Down
170 changes: 170 additions & 0 deletions DMI/STM/stm_objects.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#include "../graphics/button.h"
#include "../graphics/component.h"
#include "../graphics/color.h"
#include "../messages/messages.h"
#include "../window/window.h"
std::map<int, std::vector<int>> but_pos;
std::map<int, std::vector<int>> ind_pos;
void setup_areas()
{
areas["A1"] = {0, 15, 54, 54};
areas["A2"] = {0, 69, 54, 30};
areas["A3"] = {0, 99, 54, 191};
areas["A4"] = {0, 290, 54, 25};
areas["B3"] = {140, 271, 36, 36};
areas["B4"] = {176, 271, 36, 36};
areas["B5"] = {212, 271, 36, 36};
areas["C8"] = {0, 315, 54, 25};
areas["C9"] = {0, 340, 54, 25};
areas["C2"] = {54, 315, 37, 50};
areas["C3"] = {91, 315, 37, 50};
areas["C4"] = {128, 315, 37, 50};
areas["C1"] = {165, 315, 58, 50};
areas["C5"] = {223, 315, 37, 50};
areas["C6"] = {260, 315, 37, 50};
areas["C7"] = {297, 315, 37, 50};
for (int i=1; i<=4; i++) {
areas["E"+std::to_string(i)] = {0, 365 + 20*(i-1), 54, 25};
}
for (int i=5; i<=9; i++) {
areas["E"+std::to_string(i)] = {54, 365 + 20*(i-5), 234, 20};
}
areas["E10"] = {288, 365, 46, 50};
areas["E11"] = {288, 415, 46, 50};
for (int i=5; i<=9; i++) {
areas["E"+std::to_string(i)] = {54, 365 + 20*(i-5), 234, 20};
}
for (int i=1; i<=9; i++) {
areas["F"+std::to_string(i)] = {580, 15 + 50*(i-1), 60, 50};
}
for (int i=1; i<=10; i++) {
areas["G"+std::to_string(i)] = {334 + ((i-1)%5)*49, 315 + ((i-1)/5) * 50, (i==5 || i==10) ? 50 : 49, 50};
}
areas["G11"] = {334, 415, 63, 50};
areas["G12"] = {397, 415, 120, 50};
areas["G13"] = {517, 415, 63, 50};
}
class ntc_window : window
{
int nid_stm;
std::map<int, Button*> buttons;
std::map<int, Component*> indicators;
std::map<int, image_graphic*> icons;
std::map<int, Message> messages;
texture *get_icon(int num)
{
if (icons.find(num) == icons.end()) {
icons[num] = Component::getImage("symbols/STM/"+std::to_string(nid_stm)+"/"+std::to_string(num));
}
return icons[num];
}
Color get_color(int col, bool bg)
{
switch (col) {
case 0:
return bg ? DarkBlue : Black;
case 1:
return White;
case 2:
return Red;
case 3:
return Blue;
case 4:
return Green;
case 5:
return Yellow;
case 5:
return LightRed;
case 5:
return LightGreen;
}
}
public:
ntc_window() : window(construct_main)
{

}
void display_button(int id, int icon, std::string text, int properties)
{
bool displayed = (properties>>9)&1;
if (!displayed) {
auto it = buttons.find(id);
if (it != buttons.end()) {
delete it->second;
buttons.erase(it);
}
return;
}
Button *b = new TextButton(text);
if (icon > 0)
b->add(get_icon(icon));
bool counterflash = (properties>>8)&1;
int flash = (properties>>6)&3;
b->setBackgroundColor(get_color((properties>>3)&7, true));
b->setForegroundColor(get_color(properties&7, false));
buttons[id] = b;
}
void display_indicator(int id, int position, int icon, std::string text, int properties)
{
bool displayed = (properties>>9)&1;
if (!displayed) {
auto it = indicators.find(id);
if (it != indicators.end()) {
delete it->second;
indicators.erase(it);
}
return;
}
std::string area;
if (position < 4)
area = "B"+std::to_string(position+2);
else if (position == 4)
area = "H1";
else if (position < 10)
area = "C"+std::to_string(position-3);
else if (position < 20)
area = "G"+std::to_string(position-9);
/*{
if (position < 3)
area = "F"+std::to_string(position+7);
else if (position < 8)
area = "C"+std::to_string(position-1);
else if (position < 18)
area = "G"+std::to_string(position-7);
}*/
if (areas.find(area) == areas.end())
return;
auto pos = areas[area];
Component *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 (icon > 0)
c->add(get_icon(icon));
if (text.size() > 0)
c->addText(text, 0, 0, 12, fg);
bool counterflash = (properties>>8)&1;
int flash = (properties>>6)&3;
indicators[id] = c;
addToLayout(c, new RelativeAlignment(nullptr, pos[0], pos[1]));
}
~ntc_window()
{
for (auto it : buttons) {
delete it.second;
}
for (auto it : indicators) {
delete it.second;
}
for (auto it : icons) {
delete it.second;
}
for (auto it : icons) {
delete it.second;
}
for (auto it : messages) {
revokeMessage(it.second.Id);
}
}
};
4 changes: 4 additions & 0 deletions DMI/graphics/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ const Color Orange = {234,145,0};
const Color DarkBlue = {3, 17, 34};
const Color PASPdark = {33, 49, 74};
const Color PASPlight = {41, 74, 107};
const Color Blue = {0, 0, 234};
const Color Green = {0, 234, 0};
const Color LightRed = {255, 96, 96};
const Color LightGreen = {96, 255, 96};
#endif
4 changes: 4 additions & 0 deletions DMI/graphics/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,8 @@ void Layout::updateLocations()
vector<LayoutElement>& Layout::getElements()
{
return elements;
}
Layout::~Layout()
{
removeAll();
}
1 change: 1 addition & 0 deletions DMI/graphics/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Layout
{
std::vector<LayoutElement> elements;
public:
~Layout();
std::vector<Component*> order;
void add(Component *comp, ComponentAlignment *alignment);
void removeAll();
Expand Down
2 changes: 1 addition & 1 deletion DMI/graphics/sdl/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ image_graphic *Component::getImage(string path, float cx, float cy, float sx, fl
ig->cy = cy;
ig->sx = sx;
ig->sy = sy;
ig->load_function = [this, ig]{getImageGraphic(ig,ig->path,ig->cx, ig->cy, ig->sx, ig->sy);};
ig->load_function = [ig,this]{getImageGraphic(ig,ig->path,ig->cx, ig->cy, ig->sx, ig->sy);};
return ig;
}
void Component::getImageGraphic(texture *t, string path, float cx, float cy, float sx, float sy)
Expand Down
21 changes: 19 additions & 2 deletions DMI/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ void quit()
#elif defined(_WIN32)
#include <windows.h>
#include <imagehlp.h>
#include <errhandlingapi.h>
#include <psapi.h>
LONG WINAPI windows_exception_handler(EXCEPTION_POINTERS * ExceptionInfo)
{
HANDLE process = GetCurrentProcess();
Expand Down Expand Up @@ -76,6 +78,9 @@ LONG WINAPI windows_exception_handler(EXCEPTION_POINTERS * ExceptionInfo)
stackframe.AddrStack.Mode = AddrModeFlat;
#endif*/

MODULEINFO moduleInfo;
GetModuleInformation(process, GetModuleHandleA(NULL), &moduleInfo, sizeof(MODULEINFO));

FILE *file = fopen("error.log", "w+");
for (size_t i = 0; i < 25; i++) {

Expand All @@ -93,9 +98,17 @@ LONG WINAPI windows_exception_handler(EXCEPTION_POINTERS * ExceptionInfo)

DWORD64 displacement = 0;
if (SymFromAddr(process, stackframe.AddrPC.Offset, &displacement, symbol)) {
fprintf(file, "[%i] %s\n", i, symbol->Name);
fprintf(file, "[%i] %s", i, symbol->Name);
IMAGEHLP_LINE64 line;
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
DWORD d;
if (SymGetLineFromAddr64(process, stackframe.AddrPC.Offset, &d, &line)) {
fprintf(file, " %s:%i\n", line.FileName, line.LineNumber);
} else {
fprintf(file, "\n");
}
} else {
fprintf(file, "[%i] %p\n", i, (void*)stackframe.AddrPC.Offset);
fprintf(file, "[%i] %p\n", i, (void*)(stackframe.AddrPC.Offset-(unsigned long long)moduleInfo.lpBaseOfDll+0x140000000ULL));
}

}
Expand Down Expand Up @@ -150,6 +163,7 @@ extern "C" void Java_com_etcs_dmi_DMI_DMIstop(JNIEnv *env, jobject thiz)
running = false;
}
#endif
#include <fstream>
int main(int argc, char** argv)
{
#ifdef __ANDROID__
Expand All @@ -169,6 +183,9 @@ int main(int argc, char** argv)
setSupervision(NoS);
//std::thread video(init_video);
std::thread tcp(startSocket);
extern int maxSpeed;
std::ifstream file("speed.txt");
file>>maxSpeed;
startWindows();
init_video();
//manage_windows();
Expand Down
2 changes: 1 addition & 1 deletion DMI/messages/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void updateMessages()
textArea.setAck([msg]() {
msg->ack = false;
setAck(AckType::Message, msg->Id, false);
write_command("json", R"({"DriverSelection":"MessageAcknowledge,"MessageId:")"+to_string(msg->Id)+"}");
write_command("json", R"({"DriverSelection":"MessageAcknowledge","MessageId":)"+to_string(msg->Id)+"}");
updateMessages();
});
}
Expand Down
1 change: 1 addition & 0 deletions DMI/speed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
400
7 changes: 4 additions & 3 deletions DMI/speed/gauge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,14 @@ static bool inited = false;
void displayLines()
{
setColor(White);
for(int i = 0; i<=maxSpeed; i+=10)
int step = maxSpeed == 150 ? 5 : 10;
for(int i = 0; i<=maxSpeed; i+=step)
{
float size;
float an = speedToAngle(i);
int longinterval = maxSpeed == 400 ? 50 : 20;
int longinterval = maxSpeed == 400 ? 50 : (maxSpeed == 150 ? 25 : 20);
size = i%longinterval!=0 ? -110 : -100;
if(!inited && ((maxSpeed != 400 && i%20==0) || (maxSpeed == 400 && i%50==0 && i!=250 && i!=350)))
if(!inited && i%longinterval == 0 && (maxSpeed != 400 || (i!=250 && i!=350)))
{
std::string s = to_string(i);
const char *str = s.c_str();
Expand Down
Loading

0 comments on commit a276d8a

Please sign in to comment.