Skip to content

Commit

Permalink
Merge branch 'master' into Alberto
Browse files Browse the repository at this point in the history
  • Loading branch information
albertosaurio65 committed Aug 19, 2023
2 parents f082204 + 02f51f4 commit d8b3a5b
Show file tree
Hide file tree
Showing 37 changed files with 601 additions and 207 deletions.
109 changes: 109 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build_win:
name: Build for Win64

strategy:
matrix:
sr_flag: ["ON", "OFF"]

runs-on: windows-2022

steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Configure
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -A x64 -DSIMRAIL=${{matrix.sr_flag}}

- name: Build
run: cmake --build ${{github.workspace}}/build --config Release

- name: Publish
uses: actions/upload-artifact@v3
with:
name: build-win64-sr${{matrix.sr_flag}}
path: |
${{github.workspace}}/build/DMI/Release
${{github.workspace}}/build/EVC/Release
build_wasm:
name: Build for WASM

strategy:
matrix:
sr_flag: ["ON", "OFF"]

runs-on: ubuntu-22.04

steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Cache wasi-sdk
id: cache-wasi-sdk
uses: actions/cache@v3
with:
path: ${{github.workspace}}/wasi-sdk
key: wasi-sdk-20

- name: Download wasi-sdk
if: steps.cache-wasi-sdk.outputs.cache-hit != 'true'
run: |
mkdir -p ${{github.workspace}}/wasi-sdk
cd ${{github.workspace}}/wasi-sdk
export WASI_VERSION=20
export WASI_VERSION_FULL=${WASI_VERSION}.0
wget -nv https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_VERSION}/wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz
tar xf wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz --strip-components=1
- name: Configure
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DSIMRAIL=${{matrix.sr_flag}} -DWASI_HOST_EXE_SUFFIX= -DWASI_SDK_PREFIX=${{github.workspace}}/wasi-sdk -DCMAKE_TOOLCHAIN_FILE=wasi-sdk.cmake

- name: Build
run: cmake --build ${{github.workspace}}/build --config Release

- name: Publish
uses: actions/upload-artifact@v3
with:
name: build-wasm-sr${{matrix.sr_flag}}
path: |
${{github.workspace}}/build/DMI/dmi.wasm
${{github.workspace}}/build/EVC/evc.wasm
compile_locales:
name: Compile locales

runs-on: ubuntu-22.04

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install gettext
run: |
sudo apt-get install -y gettext
- name: Compile
run: |
cd ${{github.workspace}}/locales
./compile_locales.sh
- name: Publish
uses: actions/upload-artifact@v3
with:
name: locales
path: |
${{github.workspace}}/locales/dmi/*.mo
${{github.workspace}}/locales/evc/*.mo
40 changes: 0 additions & 40 deletions .github/workflows/cmake.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "libs/liborts"]
path = libs/liborts
url = https://github.com/cesarBLG/liborts
[submodule "libs/c-ares"]
path = libs/c-ares
url = https://github.com/c-ares/c-ares/
21 changes: 18 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,34 @@ project (ETCS)
set(CMAKE_CXX_STANDARD 17)
option(SIMRAIL "SimRail" OFF)
if (NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "wasm.*")
set (WASM FALSE)
else()
set (WASM TRUE)
endif()
set(RADIO_TCP OFF)
if (NOT WASM)
if (NOT SIMRAIL)
set (RADIO_TCP ON)
endif()
option(ETCS_VENDORED "Use vendored libraries" ON)
if (ETCS_VENDORED)
set(SDL2TTF_VENDORED ON CACHE BOOL "Vendored TTF libs")
add_subdirectory(libs/SDL EXCLUDE_FROM_ALL)
add_subdirectory(libs/SDL_ttf EXCLUDE_FROM_ALL)
add_subdirectory(libs/liborts EXCLUDE_FROM_ALL)
if (RADIO_TCP)
add_subdirectory(libs/c-ares EXCLUDE_FROM_ALL)
endif()
endif()
set (WASM FALSE)
else()
set (WASM TRUE)
endif()
if (SIMRAIL)
add_definitions(-DSIMRAIL)
endif()
if (RADIO_TCP)
add_definitions(-DRADIO_TCP)
endif()
if (WIN32)
add_definitions(-D_WIN32_WINNT=0x602)
endif()
add_subdirectory(EVC)
add_subdirectory(DMI)
4 changes: 4 additions & 0 deletions DMI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ elseif(ANDROID)
target_link_libraries(dmi PRIVATE log android GLESv1_CM GLESv2 OpenSLES)
endif()

if (WASM)
set_target_properties(dmi PROPERTIES SUFFIX ".wasm")
endif()

if (WITH_SDL AND WIN32)
add_custom_command(TARGET dmi POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
Expand Down
2 changes: 1 addition & 1 deletion DMI/softkeys/softkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ void setupSoftKeys()
for (int i=2; i<7; i++) {
softH[i] = SoftKey(620, 60+64*(i-2));
}
softH[7] = SoftKey(620, 413);
softH[7] = SoftKey(620, 389);
}
1 change: 0 additions & 1 deletion DMI/softkeys/softkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class SoftKey
SoftKey(float x, float y) : x(x), y(y) {}
void setPressed(bool pressed)
{
platform->debug_print("Soft key "+std::to_string(pressed));
input_received({pressed ? UiPlatform::InputEvent::Action::Press : UiPlatform::InputEvent::Action::Release, x, y});
}
};
Expand Down
2 changes: 1 addition & 1 deletion DMI/state/acks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Component c4(37, 50, nullptr);
Component c1(58, 50, dispAcks);
Component c5(37, 50, nullptr);
Component c6(37, 50, nullptr);
Component ackButton(40, 64);
Component ackButton(40, 82);
extern Component c9;
extern Component textArea;
bool prevAck = false;
Expand Down
2 changes: 1 addition & 1 deletion DMI/window/input_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "keyboard.h"
#include "platform_runtime.h"
input_data::input_data(std::string label_text, bool echo) : label(label_text), show_echo(echo), data_get([this] {return getData();}),
data_set([this](std::string s){setData(s);}), more("symbols/Navigation/NA_23.bmp", softkeys ? 64 : 102, 50), enter_button("symbols/Navigation/NA_20.bmp", 40, 64, nullptr, "symbols/Navigation/NA_20.bmp")
data_set([this](std::string s){setData(s);}), more("symbols/Navigation/NA_23.bmp", softkeys ? 64 : 102, 50), enter_button("symbols/Navigation/NA_20.bmp", 40, 82, nullptr, "symbols/Navigation/NA_20.bmp")
{
holdcursor = {0};
if(label!="")
Expand Down
16 changes: 16 additions & 0 deletions EVC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ NationalFN/nationalfn.cpp NationalFN/asfa.cpp

add_definitions(-DNO_THREADS)

if (RADIO_TCP)
list (APPEND SOURCES Euroradio/tcp_safe_connection.cpp)
endif()

if (NOT WASM)
list(APPEND SOURCES ../platform/console_platform.cpp ../platform/console_fd_poller.cpp ../platform/tcp_socket.cpp ../platform/bus_socket_impl.cpp ../platform/tcp_listener.cpp ../platform/libc_time_impl.cpp ../platform/fstream_file_impl.cpp ../platform/bus_socket_server.cpp ../platform/bus_tcp_bridge.cpp ../libs/liborts/ip_discovery.cpp)
else()
Expand Down Expand Up @@ -48,9 +52,21 @@ target_include_directories(evc PRIVATE ../libs/liborts/include)

add_definitions(-DEVC)

if (RADIO_TCP)
if (ETCS_VENDORED)
target_link_libraries(evc PRIVATE c-ares)
else()
find_package(c-ares REQUIRED CONFIG REQUIRED COMPONENTS c-ares)
target_link_libraries(evc PRIVATE ${c-ares_LIBRARY})
endif()
endif()

if(WIN32)
target_link_libraries(evc PRIVATE imagehlp ws2_32 psapi)
endif()
if(ANDROID)
target_link_libraries(evc PRIVATE log)
endif()
if (WASM)
set_target_properties(evc PROPERTIES SUFFIX ".wasm")
endif()
6 changes: 3 additions & 3 deletions EVC/DMI/windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ json rbc_data_window()
json j = R"({"active":"rbc_data_window"})"_json;
std::vector<json> inputs = {
build_numeric_field(get_text("RBC ID"), rbc_contact ? std::to_string(rbc_contact->country<<14 | rbc_contact->id) : ""),
build_numeric_field(get_text("RBC phone number"), rbc_contact ? std::to_string(rbc_contact->phone_number) : "")
build_numeric_field(get_text("RBC phone number"), rbc_contact ? from_bcd(rbc_contact->phone_number) : "")
};
inputs[0]["Echo"] = false;
inputs[1]["Echo"] = false;
Expand Down Expand Up @@ -291,7 +291,7 @@ json data_view_window()
fields.push_back(build_field(get_text("Radio network ID"), RadioNetworkId));
if (rbc_contact) {
fields.push_back(build_field(get_text("RBC ID"), std::to_string(rbc_contact->id)));
fields.push_back(build_field(get_text("RBC phone number"), std::to_string(rbc_contact->phone_number)));
fields.push_back(build_field(get_text("RBC phone number"), from_bcd(rbc_contact->phone_number)));

}
fields.push_back(build_field("", ""));
Expand Down Expand Up @@ -989,7 +989,7 @@ void validate_data_entry(std::string name, json &result)
active_dialog_step = "S1";
} else if (name == get_text("RBC data")) {
uint32_t id = atoll(result[get_text("RBC ID")].get<std::string>().c_str());
uint64_t number = atoll(result[get_text("RBC phone number")].get<std::string>().c_str());
uint64_t number = to_bcd(result[get_text("RBC phone number")].get<std::string>().c_str());
set_supervising_rbc(contact_info({id>>14,id&((1<<14) - 1),number}));
if (som_active && som_status == S3 ) {
som_status = A31;
Expand Down
13 changes: 12 additions & 1 deletion EVC/Euroradio/safe_radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <vector>
#include "../Packets/radio.h"
#include "safe_radio.h"
#include "platform.h"
#include "platform_runtime.h"
class communication_session;
class mobile_terminal;
enum struct safe_radio_status
Expand Down Expand Up @@ -39,4 +39,15 @@ class safe_radio_connection
virtual void release() = 0;
void send(std::shared_ptr<euroradio_message_traintotrack> msg);
PlatformUtil::Promise<std::shared_ptr<euroradio_message>> receive();
};
class bus_safe_connection : public safe_radio_connection
{
std::unique_ptr<BasePlatform::BusSocket> socket;
PlatformUtil::Promise<BasePlatform::BusSocket::ReceiveResult> rx_promise;
void data_receive(BasePlatform::BusSocket::ReceiveResult &&msg);
public:
bus_safe_connection(communication_session *session, mobile_terminal *terminal);
void update() override;
void release() override;
void send(unsigned char *data, size_t size) override;
};
28 changes: 27 additions & 1 deletion EVC/Euroradio/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ void load_contact_info()
void set_rbc_contact(contact_info contact)
{
rbc_contact = contact;
rbc_contact_valid = true;
json j;
j["NID_C"] = rbc_contact->country;
j["NID_RBC"] = rbc_contact->id;
Expand All @@ -461,7 +462,8 @@ void set_supervising_rbc(contact_info info)
handing_over_rbc = accepting_rbc = nullptr;
handover_report_accepting = handover_report_max = handover_report_min = false;
if (info.phone_number == NID_RADIO_t::UseShortNumber) {
info.phone_number = 5015;
info.country = 0;
info.id = 0;
}
if (info.id == NID_RBC_t::ContactLastRBC) {
if (rbc_contact)
Expand Down Expand Up @@ -517,4 +519,28 @@ void terminate_session(contact_info info)
accepting_rbc = nullptr;
}
}
}
std::string from_bcd(uint64_t number)
{
std::string str;
for (int i=15; i>=0; i--)
{
int c = (number>>(4*i))&15;
if (c == 15)
continue;
if (c >= 10)
return "";
str += (char)(c+48);
}
return str;
}
uint64_t to_bcd(std::string number)
{
uint64_t bcd = 0;
for (int i=0; i<16; i++) {
if (i < number.size())
bcd = (bcd<<4) | (number[i]-48);
else bcd = (bcd<<4) | 0xF;
}
return bcd;
}
4 changes: 3 additions & 1 deletion EVC/Euroradio/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,6 @@ void set_rbc_contact(contact_info contact);
void update_euroradio();
void set_supervising_rbc(contact_info info);
void terminate_session(contact_info info);
void rbc_handover(distance d, contact_info newrbc);
void rbc_handover(distance d, contact_info newrbc);
std::string from_bcd(uint64_t number);
uint64_t to_bcd(std::string number);
Loading

0 comments on commit d8b3a5b

Please sign in to comment.