Skip to content

Commit

Permalink
Merge pull request #37 from Lihis/35-more-details-to-job
Browse files Browse the repository at this point in the history
Fixes #34, fixes #35, fixes #38, more details of the job
  • Loading branch information
Lihis authored Feb 17, 2020
2 parents b348097 + a8328f6 commit 5fa1e3b
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 111 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ set(CMAKE_CXX_STANDARD 11)
if(MSVC)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
endif()

add_subdirectory(scs-sdk)
Expand Down
63 changes: 59 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,46 @@ in 30 seconds intervals until API responds with HTTP code `200`.

Below is an example of JSON format for a job.

**Note:** If `isSpecial` is `true` then `company` object in `source` and
`destination` will not exist.
**Notes:**

- If `isSpecial` is `true` then `company` object in `source` and
`destination` will not exist.
- Truck _can be_ wrong when status is `Delivered` or `Cancelled`
- e.g. when user owns a truck but decides to do a quick job; truck is
correct when `OnJob` but when `Delivered`/`Cancelled` the truck is
reported as the truck the user owns instead of the one used in the job.

```
{
"game": "ets2", // Game type (ets2, ats)
"status": 1, // 0 = FreeAsWind, 1 = OnJob, 2 = Cancelled, 3 = Delivered
"status": 1, // See "Status" below
"type": 1 // See "Types" below
"isSpecial": false // Is this special transport job
"income": 6878, // In game specific units (€, $)
"income": 6878, // In game specific units (ETS2: €, ATS: $)
"revenue": 6878, // In game specific units (ETS2: €, ATS: $)
"xp": 120 // XP received
"time": 234 // Time spend on the job in game minutes
"maxSpeed": 0.0, // Maximum speed during the delivery (can be negative)
"fuelConsumed": 0.0, // Liters
"autoPark": false, // Was auto parking used
"autoLoad": false, // Was auto loading used (always true for non cargo market jobs)
"distance": {
"driven": 0.0, // Kilometers
"planned": 248 // Planned trip distance kilometers
},
"trailer": {
"id": "scs_box.moving_floor.chassis_stwx2esii"
"accessoryId": ""
},
"truck": {
"id": "vehicle.scania.streamline",
"name": "Streamline",
"wheels": 6,
"brand": {
"id": "scania",
"name": "Scania"
}
},
"cargo": {
"id": "paper",
"name": "Office Paper",
Expand Down Expand Up @@ -119,6 +144,36 @@ Below is an example of JSON format for a job.
}
```

#### Status

Description of job status:

```
0 = FreeAsWind
1 = OnJob
2 = Cancelled
3 = Delivered
```

**Note:** Job with a status `0` should not ever be sent to the API, if that
happens it's a bug.

#### Types

Description of job types:

```
0 = Unknown
1 = CargoMarket
2 = QuickJob
3 = FreightMarket
4 = ExternalContract
5 = ExternalMarket
```

**Note:** If job has status of `0` it's most likely bug and an Issue should
be opened if there is no open issue of it already.

### Truck

Trucks positional data will be sent to `<API_URL>/truck` once in a second only
Expand Down
11 changes: 6 additions & 5 deletions gui/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "Logger/Settings.h"
#include "MainWindow.h"

static const wxCmdLineEntryDesc CMD_DESCRIPTION [] = {
static const wxCmdLineEntryDesc CMD_DESCRIPTION[] = {
{
wxCMD_LINE_SWITCH,
"m", "minimized", "Start minimized",
Expand All @@ -43,8 +43,9 @@ static const wxCmdLineEntryDesc CMD_DESCRIPTION [] = {
{
wxCMD_LINE_SWITCH,
"h", "help", "Displays this help and exit.",
wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
{ wxCMD_LINE_NONE }
wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP
},
wxCMD_LINE_DESC_END
};

class IPCConnection;
Expand Down Expand Up @@ -118,7 +119,7 @@ class IPCConnection : public wxConnection {
explicit IPCConnection(Application *app) : m_app(app) {};

protected:
bool OnExec(const wxString& topic, const wxString& data) override {
bool OnExec(const wxString &topic, const wxString &data) override {
if (topic.compare("window") == 0 && data.compare("raise") == 0) {
m_app->ShowWindow();
return true;
Expand All @@ -135,7 +136,7 @@ class IPCServer : public wxServer {
public:
explicit IPCServer(Application *app) : m_app(app) {};

wxConnectionBase *OnAcceptConnection(const wxString& topic) override {
wxConnectionBase *OnAcceptConnection(const wxString &/*topic*/) override {
return new IPCConnection(m_app);
}

Expand Down
4 changes: 3 additions & 1 deletion gui/Logger/JobSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,14 @@ void JobSender::send_truck() {
m_truck_queue.pop_front();
}

truck.Serialize(json);
json["speed"] = truck.speed;
truck.position.Serialize(json);

send_data(url, json.toStyledString().c_str(), response, error);
}

#ifdef _WIN32
#pragma warning(suppress: 4138)
int JobSender::add_certificates(void */*curl*/, void *sslctx, void *userdata) {
auto certStore = SSL_CTX_get_cert_store(reinterpret_cast<SSL_CTX *>(sslctx));
auto obj = static_cast<JobSender *>(userdata);
Expand Down
2 changes: 2 additions & 0 deletions gui/Logger/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ bool Settings::SettingsLoad() {
pluginPathOk &= PluginInstaller::CheckGamePath(m_ats_path);
}

delete config;

return (pluginPathOk && !m_url.empty() && !m_token.empty());
}

Expand Down
23 changes: 13 additions & 10 deletions gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ MainWindow::MainWindow(Settings *settings) :
base::MainWindow(nullptr),
m_sender(nullptr),
m_settings(settings),
m_job(Game::Unknown),
m_job(),
m_odometerOnStart(-1.f),
m_fuelOnStart(-1.f),
m_socket_running(false)
Expand Down Expand Up @@ -70,6 +70,10 @@ m_socket_running(false)
Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(MainWindow::on_close));
Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(MainWindow::on_job_update));
Bind(wxEVT_THREAD, &MainWindow::on_sender_update, this);

wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED);
event.SetInt(static_cast<int>(PacketType::Job));
AddPendingEvent(event);
}

MainWindow::~MainWindow() {
Expand All @@ -86,8 +90,9 @@ void MainWindow::on_job_update(wxCommandEvent &event) {
const auto type = static_cast<PacketType>(event.GetInt());

if (type == PacketType::Job) {
m_lblCargo->SetLabel(wxString::FromUTF8(m_job.cargo.name.c_str()));
if (m_job.status != JobStatus::FreeAsWind) {
m_lblCargo->SetLabel(wxString::FromUTF8(m_job.cargo.name.c_str()));

wxString origin(wxString::FromUTF8(m_job.source.city.name.c_str()));
wxString sender(wxString::FromUTF8(m_job.source.company.name.c_str()));
m_lblOrigin->SetLabel(origin + (sender.empty() ? "" : " (" + sender + ")"));
Expand All @@ -96,6 +101,7 @@ void MainWindow::on_job_update(wxCommandEvent &event) {
wxString receiver(wxString::FromUTF8(m_job.destination.company.name.c_str()));
m_lblDestination->SetLabel(destination + (receiver.empty() ? "" : " (" + receiver + ")"));
} else {
m_lblCargo->SetLabel("-");
m_lblOrigin->SetLabel("-");
m_lblDestination->SetLabel("-");
}
Expand Down Expand Up @@ -212,17 +218,14 @@ void MainWindow::socket_run() {
void MainWindow::socket_connect() {
wxSleep(1);
websocketpp::lib::error_code ec;
m_connection = m_client.get_connection("ws://127.0.0.1:" + std::to_string(WEBSOCK_PORT), ec);
std::string uri("ws://127.0.0.1:" + std::to_string(WEBSOCK_PORT));
WebsocketClient::connection_ptr con = m_client.get_connection(uri, ec);
if (!ec) {
m_client.connect(m_connection);
m_client.connect(con);
}
}

void MainWindow::socket_on_fail() {
m_job = job_t(m_job.game);
wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED);
event.SetInt(static_cast<int>(PacketType::Job));
AddPendingEvent(event);
socket_connect();
}

Expand Down Expand Up @@ -250,7 +253,7 @@ void MainWindow::socket_on_message(const websocketpp::connection_hdl &hdl,
}

if (m_job.status == JobStatus::Cancelled || m_job.status == JobStatus::Delivered) {
m_job = job_t(m_job.game);
m_job = job_t();
m_odometerOnStart = -1.f;
m_fuelOnStart = -1.f;
}
Expand Down Expand Up @@ -293,7 +296,7 @@ void MainWindow::socket_on_message(const websocketpp::connection_hdl &hdl,
}

void MainWindow::socket_on_close() {
m_job = job_t(m_job.game);
m_job = job_t();
wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED);
event.SetInt(static_cast<int>(PacketType::Job));
AddPendingEvent(event);
Expand Down
1 change: 0 additions & 1 deletion gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ class MainWindow : public base::MainWindow {
std::mutex m_socket_lock;
std::thread m_socket_thread;
WebsocketClient m_client;
WebsocketClient::connection_ptr m_connection;
};

#endif //ETS2_JOB_LOGGER_MAINWINDOW_H
4 changes: 2 additions & 2 deletions gui/SettingsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ m_mainWindow(mainWindow)
m_checkBoxRunInBackground->SetValue(m_settings->GetRunInBackground());
}

void SettingsWindow::on_install_ets2(wxCommandEvent &event) {
void SettingsWindow::on_install_ets2(wxCommandEvent &/*event*/) {
m_dirCtrlETS2Path->Enable(m_checkBoxETS2->IsChecked());
}

void SettingsWindow::on_install_ats(wxCommandEvent &event) {
void SettingsWindow::on_install_ats(wxCommandEvent &/*event*/) {
m_dirCtrlATSPath->Enable(m_checkBoxATS->IsChecked());
}

Expand Down
Loading

0 comments on commit 5fa1e3b

Please sign in to comment.