Compare commits
9
Commits
3bfdec5b69
..
b4mad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ac2ce935c | ||
|
|
ae7e54c253 | ||
|
|
fab3a5e631 | ||
|
|
db7548cb1a | ||
|
|
ad132c0574 | ||
|
|
9908326ac5 | ||
|
|
c16a758e94 | ||
|
|
f8670ad393 | ||
|
|
170ad25020 |
+1
-1
@@ -24,7 +24,7 @@ add_subdirectory(src/gilles/helper)
|
|||||||
add_subdirectory(src/gilles/slog)
|
add_subdirectory(src/gilles/slog)
|
||||||
|
|
||||||
add_executable(gilles src/gilles/gilles.c)
|
add_executable(gilles src/gilles/gilles.c)
|
||||||
target_link_libraries(gilles m ncurses argtable2 config gameloop helper slog simulatorapi eclipse-paho-mqtt-c::paho-mqtt3c)
|
target_link_libraries(gilles m ncursesw argtable2 config gameloop helper slog simulatorapi eclipse-paho-mqtt-c::paho-mqtt3c json-c)
|
||||||
|
|
||||||
# used for enabling additional compiler options if supported
|
# used for enabling additional compiler options if supported
|
||||||
include(CheckCXXCompilerFlag)
|
include(CheckCXXCompilerFlag)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ ncurses based telemetry monitor for racing sims
|
|||||||
- argtable2
|
- argtable2
|
||||||
- libconfig
|
- libconfig
|
||||||
- ncurses
|
- ncurses
|
||||||
- slog (static)
|
- [slog](https://github.com/kala13x/slog) (static)
|
||||||
- [simshmbridge](https://github.com/spacefreak18/simshmbridge)
|
- [simshmbridge](https://github.com/spacefreak18/simshmbridge)
|
||||||
- [simapi](https://github.com/spacefreak18/simapi)
|
- [simapi](https://github.com/spacefreak18/simapi)
|
||||||
|
|
||||||
|
|||||||
+116
-17
@@ -3,6 +3,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include <MQTTClient.h>
|
#include <MQTTClient.h>
|
||||||
|
|
||||||
#include "gameloop.h"
|
#include "gameloop.h"
|
||||||
@@ -12,6 +14,8 @@
|
|||||||
#include "../simulatorapi/simapi/simapi/simmapper.h"
|
#include "../simulatorapi/simapi/simapi/simmapper.h"
|
||||||
#include "../slog/slog.h"
|
#include "../slog/slog.h"
|
||||||
|
|
||||||
|
#include <json-c/json.h>
|
||||||
|
|
||||||
#define DEFAULT_UPDATE_RATE 100
|
#define DEFAULT_UPDATE_RATE 100
|
||||||
|
|
||||||
#define ADDRESS "tcp://localhost:1883"
|
#define ADDRESS "tcp://localhost:1883"
|
||||||
@@ -21,6 +25,8 @@
|
|||||||
#define QOS 0
|
#define QOS 0
|
||||||
#define TIMEOUT 10000L
|
#define TIMEOUT 10000L
|
||||||
|
|
||||||
|
char datestring[30];
|
||||||
|
|
||||||
WINDOW* win1;
|
WINDOW* win1;
|
||||||
WINDOW* win2;
|
WINDOW* win2;
|
||||||
WINDOW* win3;
|
WINDOW* win3;
|
||||||
@@ -30,6 +36,8 @@ int winx, winy;
|
|||||||
|
|
||||||
int win23y, win23x;
|
int win23y, win23x;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void handle_winch(int sig)
|
void handle_winch(int sig)
|
||||||
{
|
{
|
||||||
endwin();
|
endwin();
|
||||||
@@ -91,6 +99,32 @@ int curses_init()
|
|||||||
box(win4, 0, 0);
|
box(win4, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char * removeSpacesFromStr(char *string)
|
||||||
|
{
|
||||||
|
int non_space_count = 0;
|
||||||
|
|
||||||
|
for (int i = 0; string[i] != '\0'; i++)
|
||||||
|
{
|
||||||
|
if (string[i] != ' ')
|
||||||
|
{
|
||||||
|
string[non_space_count] = string[i];
|
||||||
|
non_space_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string[non_space_count] = '\0';
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
void update_date()
|
||||||
|
{
|
||||||
|
time_t rawtime;
|
||||||
|
struct tm * timeinfo;
|
||||||
|
time ( &rawtime );
|
||||||
|
timeinfo = localtime ( &rawtime );
|
||||||
|
sprintf(datestring, "%.24s", asctime (timeinfo));
|
||||||
|
}
|
||||||
|
|
||||||
int looper(Simulator simulator, Parameters* p)
|
int looper(Simulator simulator, Parameters* p)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -98,7 +132,6 @@ int looper(Simulator simulator, Parameters* p)
|
|||||||
SimMap* simmap = malloc(sizeof(SimMap));
|
SimMap* simmap = malloc(sizeof(SimMap));
|
||||||
|
|
||||||
int error = siminit(simdata, simmap, simulator);
|
int error = siminit(simdata, simmap, simulator);
|
||||||
|
|
||||||
if (error != GILLES_ERROR_NONE)
|
if (error != GILLES_ERROR_NONE)
|
||||||
{
|
{
|
||||||
slogf("Fatal error getting simulator data");
|
slogf("Fatal error getting simulator data");
|
||||||
@@ -112,6 +145,8 @@ int looper(Simulator simulator, Parameters* p)
|
|||||||
bool mqtt = p->mqtt;
|
bool mqtt = p->mqtt;
|
||||||
bool mqtt_connected = false;
|
bool mqtt_connected = false;
|
||||||
|
|
||||||
|
long unix_time_start;
|
||||||
|
char time_buff[11];
|
||||||
MQTTClient client;
|
MQTTClient client;
|
||||||
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
|
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
|
||||||
MQTTClient_message pubmsg = MQTTClient_message_initializer;
|
MQTTClient_message pubmsg = MQTTClient_message_initializer;
|
||||||
@@ -120,7 +155,7 @@ int looper(Simulator simulator, Parameters* p)
|
|||||||
|
|
||||||
// Create a new MQTT client
|
// Create a new MQTT client
|
||||||
MQTTClient_create(&client, ADDRESS, CLIENTID,
|
MQTTClient_create(&client, ADDRESS, CLIENTID,
|
||||||
MQTTCLIENT_PERSISTENCE_NONE, NULL);
|
MQTTCLIENT_PERSISTENCE_NONE, NULL);
|
||||||
|
|
||||||
// Connect to the MQTT server
|
// Connect to the MQTT server
|
||||||
if (mqtt == true)
|
if (mqtt == true)
|
||||||
@@ -136,27 +171,91 @@ int looper(Simulator simulator, Parameters* p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int go = true;
|
int go = true;
|
||||||
|
char lastsimstatus = false;
|
||||||
while (go == true)
|
while (go == true)
|
||||||
{
|
{
|
||||||
simdatamap(simdata, simmap, simulator);
|
simdatamap(simdata, simmap, simulator);
|
||||||
|
|
||||||
if (mqtt_connected == true)
|
char* newdatestring;
|
||||||
|
char simstatus = (simdata->simstatus > 0) ? true : false;
|
||||||
|
if (simdata->simstatus > 0 && simstatus != lastsimstatus)
|
||||||
{
|
{
|
||||||
char payloads[6][20];
|
//update_date();
|
||||||
sprintf(payloads[0], "gas, lap=%i, %04f", simdata->lap, simdata->gas);
|
unix_time_start = (unsigned long) time(NULL);
|
||||||
sprintf(payloads[1], "brake, lap=%i, %04f", simdata->lap, simdata->brake);
|
sprintf(time_buff, "%lu", unix_time_start);
|
||||||
sprintf(payloads[2], "steer, lap=%i, %04f", simdata->lap, simdata->brake);
|
//sprintf(time_buff, "%lu", (unsigned long)time(NULL));
|
||||||
sprintf(payloads[3], "gear, lap=%i, %04i", simdata->lap, simdata->gear);
|
//newdatestring = removeSpacesFromStr(datestring);
|
||||||
sprintf(payloads[4], "speed, lap=%i, %04i", simdata->lap, simdata->velocity);
|
}
|
||||||
|
lastsimstatus = simstatus;
|
||||||
|
|
||||||
for (int k =0; k < 6; k++)
|
if (mqtt_connected == true && simdata->simstatus > 0)
|
||||||
{
|
{
|
||||||
pubmsg.payload = payloads[k];
|
json_object *root = json_object_new_object();
|
||||||
pubmsg.payloadlen = strlen(payloads[k]);
|
if (!root)
|
||||||
pubmsg.qos = QOS;
|
return 1;
|
||||||
pubmsg.retained = 0;
|
|
||||||
MQTTClient_publishMessage(client, TOPIC, &pubmsg, &token);
|
json_object *child = json_object_new_object();
|
||||||
}
|
|
||||||
|
struct timeval tv;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
unsigned long long millisecondsSinceEpoch = (unsigned long long)(tv.tv_sec) * 1000 + (unsigned long long)(tv.tv_usec) / 1000;
|
||||||
|
|
||||||
|
json_object_object_add(root, "time", json_object_new_int64(millisecondsSinceEpoch)); //unix time milliseconds
|
||||||
|
|
||||||
|
const char* topic_root = "racing/gilles/TuxRacerX";
|
||||||
|
//const char* game_name = "Assetto Corsa (64 bit)";
|
||||||
|
const char* game_name = "assetto_64_bit";
|
||||||
|
const char* session_type = "Practice";
|
||||||
|
|
||||||
|
json_object_object_add(child, "CarModel", json_object_new_string(simdata->car));
|
||||||
|
json_object_object_add(child, "GameName", json_object_new_string(game_name));
|
||||||
|
json_object_object_add(child, "SessionId", json_object_new_int(unix_time_start));
|
||||||
|
json_object_object_add(child, "SessionTypeName", json_object_new_string("Practice"));
|
||||||
|
json_object_object_add(child, "TrackCode", json_object_new_string(simdata->track));
|
||||||
|
|
||||||
|
json_object_object_add(child, "Clutch", json_object_new_double(simdata->clutch));
|
||||||
|
json_object_object_add(child, "Brake", json_object_new_double(simdata->brake));
|
||||||
|
json_object_object_add(child, "Throtte", json_object_new_double(simdata->gas));
|
||||||
|
json_object_object_add(child, "HandBrake", json_object_new_double(simdata->handbrake));
|
||||||
|
json_object_object_add(child, "SteeringAngle", json_object_new_double(simdata->steer));
|
||||||
|
json_object_object_add(child, "Rpms", json_object_new_int(simdata->rpms));
|
||||||
|
json_object_object_add(child, "Gear", json_object_new_int(simdata->gear));
|
||||||
|
json_object_object_add(child, "SpeedMs", json_object_new_double(simdata->velocity * 0.2777778));
|
||||||
|
json_object_object_add(child, "DistanceRoundTrack", json_object_new_double(simdata->trackdistancearound));
|
||||||
|
json_object_object_add(child, "WorldPosition_x", json_object_new_double(simdata->worldposx));
|
||||||
|
json_object_object_add(child, "WorldPosition_y", json_object_new_double(simdata->worldposy));
|
||||||
|
json_object_object_add(child, "WorldPosition_z", json_object_new_double(simdata->worldposz));
|
||||||
|
json_object_object_add(child, "CurrentLap", json_object_new_int(simdata->playerlaps));
|
||||||
|
json_object_object_add(child, "CurrentLapTime", json_object_new_int(simdata->currentlapinseconds));
|
||||||
|
json_object_object_add(child, "LapTimePrevious", json_object_new_int(simdata->lastlapinseconds));
|
||||||
|
json_object_object_add(child, "CurrentLapIsValid", json_object_new_int(simdata->lapisvalid));
|
||||||
|
json_object_object_add(child, "PreviousLapWasValid", json_object_new_int(1));
|
||||||
|
|
||||||
|
json_object_object_add(root, "telemetry", child);
|
||||||
|
|
||||||
|
slogi(json_object_to_json_string_ext(root, JSON_C_TO_STRING_PRETTY));
|
||||||
|
|
||||||
|
// TODO: generate this topic string only once
|
||||||
|
char* topic = ( char* ) malloc(1 + strlen(topic_root) + strlen("/") + strlen(game_name) + strlen("/") + strlen(session_type)
|
||||||
|
+ strlen("/") + strlen(simdata->car) + strlen("/") + strlen(simdata->track) + strlen("/") + 11);
|
||||||
|
strcpy(topic, topic_root);
|
||||||
|
strcat(topic, "/");
|
||||||
|
strcat(topic, time_buff);
|
||||||
|
strcat(topic, "/");
|
||||||
|
strcat(topic, game_name);
|
||||||
|
strcat(topic, "/");
|
||||||
|
strcat(topic, simdata->track);
|
||||||
|
strcat(topic, "/");
|
||||||
|
strcat(topic, simdata->car);
|
||||||
|
strcat(topic, "/");
|
||||||
|
strcat(topic, session_type);
|
||||||
|
|
||||||
|
pubmsg.payload = json_object_to_json_string_ext(root, JSON_C_TO_STRING_PRETTY);
|
||||||
|
pubmsg.payloadlen = strlen(json_object_to_json_string_ext(root, JSON_C_TO_STRING_PRETTY));
|
||||||
|
pubmsg.qos= QOS;
|
||||||
|
pubmsg.retained = 0;
|
||||||
|
|
||||||
|
MQTTClient_publishMessage(client, topic, &pubmsg, &token);
|
||||||
}
|
}
|
||||||
|
|
||||||
wclear(win1);
|
wclear(win1);
|
||||||
|
|||||||
Submodule src/gilles/simulatorapi/simapi updated: 85c063eac3...db3cd3eec3
Reference in New Issue
Block a user