Consts and references

This commit is contained in:
2022-09-09 20:10:38 +02:00
parent b050c23577
commit 699e2a4784
16 changed files with 156 additions and 179 deletions
+12 -21
View File
@@ -3,12 +3,14 @@
#include <cstdint>
#pragma pack(push) /* push current alignment to stack */
#pragma pack(1) /* set alignment to 1 byte boundary */
namespace germanairlinesva_websocket
{
#pragma pack(push) /* push current alignment to stack */
#pragma pack(1) /* set alignment to 1 byte boundary */
/* Structures and enums */
typedef struct data {
struct data {
std::int32_t pause = 0;
float pBrake = 0;
std::int32_t onGrnd = 0;
@@ -27,30 +29,19 @@ namespace germanairlinesva_websocket
float magHeading = 0;
float payloadKg = 0;
float totalWeightKg = 0;
} data;
};
typedef enum commands {
PROCESS,
SAVE,
LOAD,
TEXT,
TIME,
UNPAUSE,
PAUSE,
PORT,
END
} commands;
enum commands { PROCESS, SAVE, LOAD, TEXT, TIME, UNPAUSE, PAUSE, PORT, END };
typedef struct command_base {
commands type;
} command_base;
struct command_base {
enum commands type;
};
typedef struct command_port {
struct command_port {
double latitude;
double longitude;
float trueHeading;
} command_port;
};
#pragma pack(pop) /* restore original alignment from stack */
} // namespace germanairlinesva_websocket
+27 -24
View File
@@ -12,19 +12,20 @@ namespace germanairlinesva_websocket
ix::initNetSystem();
#endif
webSocket = new ix::WebSocket();
webSocket->enableAutomaticReconnection();
webSocket->setUrl(host);
webSocket->setOnMessageCallback([this](const ix::WebSocketMessagePtr &msg) {
this->onClientMessageCallback(msg);
});
webSocket->start();
this->webSocket = new ix::WebSocket();
this->webSocket->enableAutomaticReconnection();
this->webSocket->setUrl(host);
this->webSocket->setOnMessageCallback(
[this](const ix::WebSocketMessagePtr &msg) {
this->onClientMessageCallback(msg);
});
this->webSocket->start();
}
Websocket::~Websocket()
{
webSocket->stop();
toLog("WebSocket stopped");
this->webSocket->stop();
this->toLog("WebSocket stopped");
#ifdef IBM
// Required on Windows
ix::uninitNetSystem();
@@ -43,15 +44,15 @@ namespace germanairlinesva_websocket
debug_msg << it.first << ": " << it.second << std::endl;
}
toLog(debug_msg.str());
this->toLog(debug_msg.str());
webSocket->send("MASTER:" + user);
toLog("Connecting as " + user);
this->webSocket->send("MASTER:" + user);
this->toLog("Connecting as " + user);
} else if (msg->type == ix::WebSocketMessageType::Close) {
if (msg->closeInfo.reason.compare("DUPLICATE")) {
webSocket->disableAutomaticReconnection();
this->webSocket->disableAutomaticReconnection();
toLog("Disconnected due to beeing a duplicate simualtor");
this->toLog("Disconnected due to beeing a duplicate simualtor");
} else {
std::stringstream debug_msg;
@@ -60,7 +61,7 @@ namespace germanairlinesva_websocket
debug_msg << "Reason: " << msg->closeInfo.reason << std::endl;
debug_msg << "Remote: " << msg->closeInfo.remote << std::endl;
toLog(debug_msg.str());
this->toLog(debug_msg.str());
}
} else if (msg->type == ix::WebSocketMessageType::Error) {
std::stringstream debug_msg;
@@ -73,20 +74,22 @@ namespace germanairlinesva_websocket
debug_msg << "Retries: " << msg->errorInfo.retries << std::endl;
debug_msg << "Wait time: " << msg->errorInfo.wait_time << std::endl;
toLog(debug_msg.str());
this->toLog(debug_msg.str());
} else if (msg->type == ix::WebSocketMessageType::Message) {
if (!msg->str.empty()) {
toLog(msg->str);
this->toLog(msg->str);
}
}
}
void Websocket::sendData(data &d)
{
if (strcmp(d.path, lastPath) != 0) {
strcpy(lastPath, d.path);
if (germanairlinesva_util::generateMD5(d.path, lastHash, toLog)) {
strcpy(lastHash, "NOT SET");
if (strcmp(d.path, this->lastPath) != 0) {
strcpy(this->lastPath, d.path);
if (germanairlinesva_util::generateMD5(d.path,
this->lastHash,
this->toLog)) {
strcpy(this->lastHash, "NOT SET");
}
}
@@ -98,13 +101,13 @@ namespace germanairlinesva_websocket
{"truHdg", d.truHdg},
{"totFuel", d.totFuelKg},
{"fuelFlow", d.ff},
{"hash", lastHash},
{"hash", this->lastHash},
};
if (webSocket != nullptr) {
if (this->webSocket != nullptr) {
std::ostringstream msg;
msg << "SEND:" << user << ":" << json.dump();
webSocket->send(msg.str(), false);
this->webSocket->send(msg.str(), false);
}
}
} // namespace germanairlinesva_websocket