Refactor query and telemetry functions into separate files
This commit is contained in:
parent
0ce4fb5c2f
commit
415a83a1f5
|
|
@ -65,12 +65,6 @@ void b_handle_winch(int sig)
|
|||
refresh();
|
||||
clear();
|
||||
getmaxyx(stdscr, bwinx, bwiny);
|
||||
//win23y = winy/3;
|
||||
//win23x = winx/3;
|
||||
//win1 = newwin(winx,winy,0,0);
|
||||
//win2 = newwin(win23x,win23y,1,win23y-1);
|
||||
//win3 = newwin(win23x,win23y,1,win23y*2-1);
|
||||
//win4 = newwin(winx-win23x-2,winy-win23y,win23x+1,win23y-1);
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
|
@ -90,11 +84,6 @@ int b_curses_init()
|
|||
getmaxyx(stdscr, bwinx, bwiny);
|
||||
slogt("windowx %i, windowy %i", bwinx, bwiny);
|
||||
bwin1 = newwin(bwinx,bwiny,0,0);
|
||||
//win23y = winy/3;
|
||||
//win23x = winx/3;
|
||||
//win2 = newwin(win23x,win23y,1,win23y-1);
|
||||
//win3 = newwin(win23x,win23y,1,win23y*2-1);
|
||||
//win4 = newwin(winx-win23x-2,winy-win23y,win23x+1,win23y-1);
|
||||
|
||||
wbkgd(bwin1,COLOR_PAIR(1));
|
||||
wbkgd(bwin2,COLOR_PAIR(1));
|
||||
|
|
@ -107,65 +96,10 @@ int b_curses_init()
|
|||
noecho();
|
||||
|
||||
box(bwin1, 0, 0);
|
||||
//box(bwin2, 0, 0);
|
||||
//box(bwin3, 0, 0);
|
||||
//box(bwin4, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int getstints(struct _h_connection* conn, const char* sessionname, StintDbo* stint, int use_id)
|
||||
{
|
||||
struct _h_result result;
|
||||
struct _h_data * data;
|
||||
char* query = malloc(150 * sizeof(char));
|
||||
slogt("Performing query stints");
|
||||
|
||||
|
||||
sprintf(query, "select stint_id, driver_id, team_member_id, session_id, car_id, game_car_id, laps, valid_laps, best_lap_id FROM %s WHERE session_id=%i", "Stints", use_id);
|
||||
slogt("execute query %s", query);
|
||||
if (h_query_select(conn, query, &result) == H_OK) {
|
||||
stint->rows = malloc(sizeof(StintRowData) * result.nb_rows);
|
||||
get_row_results(result, stint->fields, stint->rows, sizeof(StintRowData));
|
||||
//get_stint_result(result, stint);
|
||||
h_clean_result(&result);
|
||||
} else {
|
||||
printf("Error executing query\n");
|
||||
}
|
||||
free(query);
|
||||
|
||||
return result.nb_rows;
|
||||
}
|
||||
|
||||
int getlaps(struct _h_connection* conn, const char* sessionname, LapDbo* laps, int use_id)
|
||||
{
|
||||
struct _h_result result;
|
||||
struct _h_data * data;
|
||||
char* query = malloc(250 * sizeof(char));
|
||||
slogt("Performing query laps");
|
||||
|
||||
sprintf(query, "select lap_id, stint_id, sector_1, sector_2, sector_3, grip, tyre, time, cuts, crashes, max_speed, avg_speed FROM %s WHERE %s=%i", "Laps", "stint_id", use_id);
|
||||
if (h_query_select(conn, query, &result) == H_OK) {
|
||||
laps->rows = malloc(sizeof(LapRowData) * result.nb_rows);
|
||||
get_row_results(result, laps->fields, laps->rows, sizeof(LapRowData));
|
||||
//print_result(result);
|
||||
//get_stint_result(result, stint);
|
||||
h_clean_result(&result);
|
||||
slogt("lap query returned OK");
|
||||
} else {
|
||||
printf("Error executing query\n");
|
||||
}
|
||||
free(query);
|
||||
|
||||
return result.nb_rows;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void* browseloop(Parameters* p, char* datadir)
|
||||
{
|
||||
|
||||
|
|
@ -204,7 +138,15 @@ void* browseloop(Parameters* p, char* datadir)
|
|||
DBField track;
|
||||
track.type = HOEL_COL_TYPE_TEXT;
|
||||
track.offset = offsetof(SessionRowData, track);
|
||||
track.size = sizeof(unsigned char)*20;
|
||||
track.size = sizeof(unsigned char)*150;
|
||||
DBField car;
|
||||
car.type = HOEL_COL_TYPE_TEXT;
|
||||
car.offset = offsetof(SessionRowData, car);
|
||||
car.size = sizeof(unsigned char)*150;
|
||||
DBField starttime;
|
||||
starttime.type = HOEL_COL_TYPE_DATE;
|
||||
starttime.offset = offsetof(SessionRowData, start_time);
|
||||
starttime.size = sizeof(PDBTimeStamp);
|
||||
|
||||
//SessionFields sf;
|
||||
sess.fields[0] = sessid;
|
||||
|
|
@ -212,6 +154,8 @@ void* browseloop(Parameters* p, char* datadir)
|
|||
sess.fields[2] = eventtype;
|
||||
sess.fields[3] = laps;
|
||||
sess.fields[4] = track;
|
||||
sess.fields[5] = car;
|
||||
sess.fields[6] = starttime;
|
||||
//sf.session_id = sessid;
|
||||
//sf.laps = laps;
|
||||
|
||||
|
|
@ -330,10 +274,10 @@ void* browseloop(Parameters* p, char* datadir)
|
|||
//DBField r_brake_temp;
|
||||
//r_brake_temp.type = HOEL_COL_TYPE_DOUBLE;
|
||||
//r_brake_temp.offset = offsetof(LapRowData, r_brake_temp);
|
||||
//DBField lapsdbfinishedat;
|
||||
//lapsdbfinishedat.type = HOEL_COL_TYPE_DATE;
|
||||
//lapsdbfinishedat.offset = offsetof(LapRowData, finished_at);
|
||||
//lapsdbfinishedat.size = sizeof(PDBTimeStamp);
|
||||
DBField lapsdbfinishedat;
|
||||
lapsdbfinishedat.type = HOEL_COL_TYPE_DATE;
|
||||
lapsdbfinishedat.offset = offsetof(LapRowData, finished_at);
|
||||
lapsdbfinishedat.size = sizeof(PDBTimeStamp);
|
||||
|
||||
lapsdb.fields[0] = lapsdbid;
|
||||
lapsdb.fields[1] = lapsdbstintid;
|
||||
|
|
@ -347,7 +291,7 @@ void* browseloop(Parameters* p, char* datadir)
|
|||
lapsdb.fields[9] = carcrashes;
|
||||
lapsdb.fields[10] = maxspeed;
|
||||
lapsdb.fields[11] = avgspeed;
|
||||
//lapsdb.fields[12] = lapsdbfinishedat;
|
||||
lapsdb.fields[12] = lapsdbfinishedat;
|
||||
//lapsdb.fields[13] = f_tyre_temp;
|
||||
//lapsdb.fields[14] = r_tyre_temp;
|
||||
//lapsdb.fields[15] = f_tyre_wear;
|
||||
|
|
@ -383,9 +327,9 @@ void* browseloop(Parameters* p, char* datadir)
|
|||
if (action == 2)
|
||||
{
|
||||
slogt("going to perform an action");
|
||||
int err = 0;
|
||||
sessions = getsessions(conn, &err, "Sessions", &sess);
|
||||
if (err != E_NO_ERROR)
|
||||
int err = E_NO_ERROR;
|
||||
sessions = getsessions(conn, "Sessions", &sess);
|
||||
if (sessions < 0)
|
||||
{
|
||||
go = false;
|
||||
}
|
||||
|
|
@ -398,17 +342,35 @@ void* browseloop(Parameters* p, char* datadir)
|
|||
if (action == 3)
|
||||
{
|
||||
slogt("going to perform an action");
|
||||
|
||||
|
||||
int err = E_NO_ERROR;
|
||||
stintsid = getstints(conn, "Stints", &stints, stint_useid);
|
||||
curresults = stintsid;
|
||||
if (stintsid < 0)
|
||||
{
|
||||
go = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
curresults = stintsid;
|
||||
}
|
||||
}
|
||||
if (action == 4)
|
||||
{
|
||||
slogt("going to perform an action");
|
||||
|
||||
int err = E_NO_ERROR;
|
||||
lapsresults = getlaps(conn, "laps", &lapsdb, lap_useid);
|
||||
slogt("laps query executed");
|
||||
curresults = lapsresults;
|
||||
if (lapsresults < 0)
|
||||
{
|
||||
go = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
curresults = lapsresults;
|
||||
}
|
||||
}
|
||||
|
||||
if (action > 0)
|
||||
|
|
@ -417,21 +379,26 @@ void* browseloop(Parameters* p, char* datadir)
|
|||
|
||||
switch(screen) {
|
||||
case SESSIONS_SCREEN:
|
||||
|
||||
|
||||
for(int i=0; i<sessions+1; i++)
|
||||
{
|
||||
int displaycolumns = 4;
|
||||
int width1 = displaycolumns + 1;
|
||||
int width2 = displaycolumns * 2;
|
||||
int displaycolumns = 6;
|
||||
int width1 = displaycolumns + 1;
|
||||
int width2 = displaycolumns * 2;
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
|
||||
wattrset(bwin1, COLOR_PAIR(2));
|
||||
wattron(bwin1, A_BOLD);
|
||||
mvwaddnstr(bwin1, 2, bwiny/2, "Sessions", -1);
|
||||
mvwaddnstr(bwin1, 3, bwiny/width2, "idx", 3);
|
||||
mvwaddnstr(bwin1, 3, bwiny/width1+bwiny/width2, "name", 4);
|
||||
mvwaddnstr(bwin1, 3, ((bwiny/width1)*2)+bwiny/width2, "track", 5);
|
||||
mvwaddnstr(bwin1, 3, ((bwiny/width1)*3)+bwiny/width2, "laps", 4);
|
||||
mvwaddnstr(bwin1, 3, bwiny/width2, "idx", -1);
|
||||
mvwaddnstr(bwin1, 3, bwiny/width1+bwiny/width2, "name", -1);
|
||||
mvwaddnstr(bwin1, 3, ((bwiny/width1)*2)+bwiny/width2, "track", -1);
|
||||
mvwaddnstr(bwin1, 3, ((bwiny/width1)*3)+bwiny/width2, "car", -1);
|
||||
mvwaddnstr(bwin1, 3, ((bwiny/width1)*4)+bwiny/width2, "stints", -1);
|
||||
mvwaddnstr(bwin1, 3, ((bwiny/width1)*5)+bwiny/width2, "time", -1);
|
||||
mvwhline(bwin1, 4, 0, 0, bwiny);
|
||||
wattroff(bwin1, A_BOLD);
|
||||
wattrset(bwin1, COLOR_PAIR(1));
|
||||
|
|
@ -454,13 +421,13 @@ void* browseloop(Parameters* p, char* datadir)
|
|||
snprintf(idchar, 4, "%i", sess.rows[i-1].session_id);
|
||||
char lapschar[4];
|
||||
snprintf(lapschar, 4, "%i", sess.rows[i-1].laps);
|
||||
char trackchar[4];
|
||||
snprintf(trackchar, 20, "%s", sess.rows[i-1].track);
|
||||
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/width2+2, idchar, 4);
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/width2+bwiny/width1, "my session name", 15);
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/width2+((bwiny/width1)*2), trackchar, 20);
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/width2+((bwiny/width1)*3), lapschar, 4);
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/width2+2, idchar, -1);
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/width2+bwiny/width1, "my session name", -1);
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/width2+((bwiny/width1)*2), sess.rows[i-1].track, -1);
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/width2+((bwiny/width1)*3), sess.rows[i-1].car, -1);
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/width2+((bwiny/width1)*4), lapschar, -1);
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/width2+((bwiny/width1)*5), sess.rows[i-1].start_time, -1);
|
||||
}
|
||||
wattrset(bwin1, COLOR_PAIR(1));
|
||||
}
|
||||
|
|
@ -514,17 +481,22 @@ void* browseloop(Parameters* p, char* datadir)
|
|||
{
|
||||
break;
|
||||
}
|
||||
|
||||
for(int i=0; i<lapsresults+1; i++)
|
||||
{
|
||||
|
||||
int displaycolumns = 4;
|
||||
int width1 = displaycolumns + 1;
|
||||
int width2 = displaycolumns * 2;
|
||||
if (i == 0)
|
||||
{
|
||||
wattrset(bwin1, COLOR_PAIR(2));
|
||||
wattron(bwin1, A_BOLD);
|
||||
mvwaddnstr(bwin1, 2, bwiny/2, "Laps", -1);
|
||||
mvwaddnstr(bwin1, 3, bwiny/7, "idx", 3);
|
||||
mvwaddnstr(bwin1, 3, bwiny/5+bwiny/7, "name", 4);
|
||||
mvwaddnstr(bwin1, 3, ((bwiny/5)*2)+bwiny/7, "tyre", 4);
|
||||
mvwaddnstr(bwin1, 3, ((bwiny/5)*3)+bwiny/7, "max speed", 4);
|
||||
mvwaddnstr(bwin1, 3, bwiny/width2, "idx", -1);
|
||||
mvwaddnstr(bwin1, 3, bwiny/width1+bwiny/width2, "name", -1);
|
||||
mvwaddnstr(bwin1, 3, ((bwiny/width1)*2)+bwiny/width2, "tyre", -1);
|
||||
mvwaddnstr(bwin1, 3, ((bwiny/width1)*3)+bwiny/width2, "maxspeed", -1);
|
||||
mvwhline(bwin1, 4, 0, 0, bwiny);
|
||||
wattroff(bwin1, A_BOLD);
|
||||
wattrset(bwin1, COLOR_PAIR(1));
|
||||
|
|
@ -532,7 +504,7 @@ void* browseloop(Parameters* p, char* datadir)
|
|||
}
|
||||
else
|
||||
{
|
||||
wattrset(bwin1, COLOR_PAIR(5));
|
||||
|
||||
//stint_useid = lapsdb.rows[i-1].rows;
|
||||
if ( lapsdb.rows[i-1].lap_id == selection1 ) {
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/7 - 4, " 1 ", 3);
|
||||
|
|
@ -544,6 +516,7 @@ void* browseloop(Parameters* p, char* datadir)
|
|||
}
|
||||
if ( i == selection )
|
||||
{
|
||||
wattrset(bwin1, COLOR_PAIR(5));
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/7, " * ", 3);
|
||||
}
|
||||
else
|
||||
|
|
@ -558,10 +531,10 @@ void* browseloop(Parameters* p, char* datadir)
|
|||
char maxspeedchar[4];
|
||||
snprintf(maxspeedchar, 4, "%i", lapsdb.rows[i-1].max_speed);
|
||||
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/7+2, idchar, 4);
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/7+bwiny/5, "my lap name", 13);
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/7+((bwiny/5)*2), tyrechar, 10);
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/7+((bwiny/5)*3), maxspeedchar, 4);
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/width2+2, idchar, -1);
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/width2+bwiny/width1, "my session name", -1);
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/width2+((bwiny/width1)*2), lapsdb.rows[i-1].tyre, -1);
|
||||
mvwaddnstr(bwin1, 4+i, bwiny/width2+((bwiny/width1)*3), maxspeedchar, -1);
|
||||
}
|
||||
wattrset(bwin1, COLOR_PAIR(1));
|
||||
|
||||
|
|
@ -570,15 +543,9 @@ void* browseloop(Parameters* p, char* datadir)
|
|||
}
|
||||
action = 0;
|
||||
}
|
||||
|
||||
box(bwin1, 0, 0);
|
||||
//box(win2, 0, 0);
|
||||
//box(win3, 0, 0);
|
||||
//box(win4, 0, 0);
|
||||
|
||||
wrefresh(bwin1);
|
||||
//wrefresh(win2);
|
||||
//wrefresh(win3);
|
||||
//wrefresh(win4);
|
||||
|
||||
scanf("%c", &ch);
|
||||
if(ch == 'q')
|
||||
|
|
@ -632,7 +599,7 @@ void* browseloop(Parameters* p, char* datadir)
|
|||
{
|
||||
dumptelemetrytofile(conn, datadir, selection1, selection2);
|
||||
|
||||
slogt("finished dumping data");
|
||||
slogi("finished dumping data");
|
||||
size_t strsize = strlen(datadir) + strlen(p->gnuplot_file) + 1;
|
||||
char* plotfile = malloc(strsize);
|
||||
snprintf(plotfile, strsize, "%s%s", datadir, p->gnuplot_file);
|
||||
|
|
@ -682,17 +649,6 @@ void* browseloop(Parameters* p, char* datadir)
|
|||
}
|
||||
|
||||
|
||||
//wrefresh(bwin4);
|
||||
//delwin(bwin4);
|
||||
//endwin();
|
||||
|
||||
//wrefresh(bwin3);
|
||||
//delwin(bwin3);
|
||||
//endwin();
|
||||
|
||||
//wrefresh(bwin2);
|
||||
//delwin(bwin2);
|
||||
//endwin();
|
||||
|
||||
wrefresh(bwin1);
|
||||
delwin(bwin1);
|
||||
|
|
@ -701,6 +657,5 @@ void* browseloop(Parameters* p, char* datadir)
|
|||
h_close_db(conn);
|
||||
h_clean_connection(conn);
|
||||
|
||||
//return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@
|
|||
#include <hoel.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include "hoeldb.h"
|
||||
#include "telemetry.h"
|
||||
#include "gameloop.h"
|
||||
#include "../helper/parameters.h"
|
||||
#include "../helper/confighelper.h"
|
||||
|
|
@ -721,487 +723,6 @@ void* looper(void* thargs)
|
|||
//return 0;
|
||||
}
|
||||
|
||||
int getLastInsertID(struct _h_connection* conn)
|
||||
{
|
||||
json_t* last_id = (h_last_insert_id(conn));
|
||||
int id = json_integer_value(last_id);
|
||||
json_decref(last_id);
|
||||
return id;
|
||||
}
|
||||
|
||||
int adddriver(struct _h_connection* conn, int driverid, const char* drivername)
|
||||
{
|
||||
if (driverid > 0)
|
||||
{
|
||||
return driverid;
|
||||
}
|
||||
json_t *root = json_object();
|
||||
json_t *json_arr = json_array();
|
||||
|
||||
json_object_set_new( root, "table", json_string("drivers") );
|
||||
json_object_set_new( root, "values", json_arr );
|
||||
|
||||
json_t* values = json_object();
|
||||
json_object_set_new(values, "driver_name", json_string(drivername));
|
||||
json_object_set_new(values, "prev_name", json_string(drivername));
|
||||
json_object_set_new(values, "steam64_id", json_integer(17));
|
||||
json_object_set_new(values, "country", json_string("USA"));
|
||||
json_array_append(json_arr, values);
|
||||
int res = h_insert(conn, root, NULL);
|
||||
json_decref(root);
|
||||
json_decref(values);
|
||||
|
||||
driverid = getLastInsertID(conn);
|
||||
return driverid;
|
||||
}
|
||||
|
||||
int addtrackconfig(struct _h_connection* conn, int trackconfigid, const char* track, int length)
|
||||
{
|
||||
//track_config_id | track_name | config_name | display_name | country | city | length
|
||||
if (trackconfigid > 0)
|
||||
{
|
||||
return trackconfigid;
|
||||
}
|
||||
json_t *root = json_object();
|
||||
json_t *json_arr = json_array();
|
||||
|
||||
json_object_set_new( root, "table", json_string("track_config") );
|
||||
json_object_set_new( root, "values", json_arr );
|
||||
|
||||
json_t* values = json_object();
|
||||
json_object_set_new(values, "track_name", json_string(track));
|
||||
json_object_set_new(values, "config_name", json_string("default"));
|
||||
json_object_set_new(values, "display_name", json_string(track));
|
||||
json_object_set_new(values, "country", json_string("USA"));
|
||||
json_object_set_new(values, "city", json_string("USA"));
|
||||
json_object_set_new(values, "length", json_integer(length));
|
||||
|
||||
json_array_append(json_arr, values);
|
||||
char* qq;
|
||||
int res = h_insert(conn, root, &qq);
|
||||
sloge("track config insert result %i", res);
|
||||
sloge("track config query %s", qq);
|
||||
trackconfigid = getLastInsertID(conn);
|
||||
json_decref(root);
|
||||
json_decref(values);
|
||||
|
||||
return trackconfigid;
|
||||
}
|
||||
|
||||
int addevent(struct _h_connection* conn, int track_config)
|
||||
{
|
||||
|
||||
json_t *root = json_object();
|
||||
json_t *json_arr = json_array();
|
||||
|
||||
json_object_set_new( root, "table", json_string("events") );
|
||||
json_object_set_new( root, "values", json_arr );
|
||||
|
||||
json_t* values = json_object();
|
||||
json_object_set_new(values, "track_config_id", json_integer(track_config));
|
||||
json_object_set_new(values, "event_name", json_string("default"));
|
||||
//event_id | server_name | track_config_id | event_name | team_event | active | livery_preview | use_number | practice_duration | quali_duration | race_duration | race_duration_type | race_wait_time | race_extra_laps | reverse_grid_positions
|
||||
json_array_append(json_arr, values);
|
||||
int res = h_insert(conn, root, NULL);
|
||||
json_decref(root);
|
||||
json_decref(values);
|
||||
return getLastInsertID(conn);
|
||||
}
|
||||
|
||||
int addsession(struct _h_connection* conn, int eventid, int carid, int eventtype, int airtemp, int tracktemp, SimData* simdata)
|
||||
{
|
||||
|
||||
// session_id | event_id | event_type | track_time | session_name
|
||||
// | start_time | duration_min | elapsed_ms | laps | weather |
|
||||
// air_temp | road_temp | start_grip |
|
||||
json_t *root = json_object();
|
||||
json_t *json_arr = json_array();
|
||||
|
||||
json_object_set_new( root, "table", json_string("sessions") );
|
||||
json_object_set_new( root, "values", json_arr );
|
||||
|
||||
json_t* values = json_object();
|
||||
json_object_set_new(values, "event_id", json_integer(eventid));
|
||||
json_object_set_new(values, "car_id", json_integer(carid));
|
||||
json_object_set_new(values, "event_type", json_integer(1));
|
||||
json_object_set_new(values, "duration_min", json_integer(60));
|
||||
json_object_set_new(values, "start_time", json_string("NOW()"));
|
||||
json_object_set_new(values, "session_name", json_string("default"));
|
||||
json_object_set_new(values, "air_temp", json_integer(airtemp));
|
||||
json_object_set_new(values, "road_temp", json_integer(tracktemp));
|
||||
json_object_set_new(values, "weather", json_string("Windy"));
|
||||
json_object_set_new(values, "http_port", json_integer(0));
|
||||
json_array_append(json_arr, values);
|
||||
int res = h_insert(conn, root, NULL);
|
||||
slogt("session insert response: %i", res);
|
||||
json_decref(root);
|
||||
json_decref(values);
|
||||
return getLastInsertID(conn);
|
||||
}
|
||||
|
||||
int addstint(struct _h_connection* conn, int sessionid, int driverid, int carid, SimData* simdata)
|
||||
{
|
||||
|
||||
|
||||
json_t *root = json_object();
|
||||
json_t *json_arr = json_array();
|
||||
|
||||
json_object_set_new( root, "table", json_string("stints") );
|
||||
json_object_set_new( root, "values", json_arr );
|
||||
|
||||
json_t* values = json_object();
|
||||
|
||||
json_object_set_new(values, "driver_id", json_integer(driverid));
|
||||
//team_member_id
|
||||
json_object_set_new(values, "session_id", json_integer(sessionid));
|
||||
json_object_set_new(values, "car_id", json_integer(carid));
|
||||
json_object_set_new(values, "game_car_id", json_integer(carid));
|
||||
json_object_set_new(values, "laps", json_integer(0));
|
||||
json_object_set_new(values, "valid_laps", json_integer(0));
|
||||
// best_lap_id
|
||||
json_object_set_new(values, "is_finished", json_integer(0));
|
||||
|
||||
json_object_set_new(values, "started_at", json_string("NOW()") );
|
||||
json_array_append(json_arr, values);
|
||||
int res = h_insert(conn, root, NULL);
|
||||
slogt("stint insert response: %i", res);
|
||||
json_decref(root);
|
||||
json_decref(values);
|
||||
return getLastInsertID(conn);
|
||||
}
|
||||
|
||||
int closesession(struct _h_connection* conn, int sessionid)
|
||||
{
|
||||
|
||||
slogt("closing previous session ", sessionid);
|
||||
// best_lap_id
|
||||
|
||||
// session_id | event_id | event_type | track_time | session_name
|
||||
// | start_time | duration_min | elapsed_ms | laps | weather |
|
||||
// air_temp | road_temp | start_grip | end_grip | is_finished
|
||||
|
||||
char* query = malloc((sizeof(char)*100));
|
||||
sprintf(query, "UPDATE %s SET is_finished=1, finished_at=NOW() WHERE session_id=%i",
|
||||
"sessions", sessionid);
|
||||
|
||||
int res1 = h_query_update(conn, query);
|
||||
slogt("running query %s", query);
|
||||
free(query);
|
||||
|
||||
slogt("closed previous session");
|
||||
return res1;
|
||||
}
|
||||
|
||||
|
||||
int closestint(struct _h_connection* conn, int stintid, int stintlaps, int validstintlaps)
|
||||
{
|
||||
|
||||
// best_lap_id
|
||||
slogt("closing previous stint ", stintid);
|
||||
|
||||
char* query = malloc((sizeof(char)*146));
|
||||
sprintf(query, "UPDATE %s SET %s = %i, %s = %i, is_finished=1, finished_at=NOW() WHERE stint_id=%i",
|
||||
"stints", "laps", stintlaps, "valid_laps", validstintlaps, stintid);
|
||||
|
||||
int res1 = h_query_update(conn, query);
|
||||
slogt("running query %s", query);
|
||||
free(query);
|
||||
|
||||
slogt("closed previous stint");
|
||||
return res1;
|
||||
}
|
||||
|
||||
int closelapquery(struct _h_connection* conn, int lapid, int sector1, int sector2, int sector3, int cuts, int crashes, int maxspeed, int avgspeed, SimData* simdata)
|
||||
{
|
||||
|
||||
// stint laps
|
||||
// lap_id | stint_id | sector_1 | sector_2 | sector_3 | grip | tyre | time | cuts | crashes
|
||||
// max_speed | avg_speed | finished_at
|
||||
|
||||
slogt("closing previous lap ", lapid);
|
||||
|
||||
char* query = malloc((sizeof(char)*622));
|
||||
sprintf(query, "UPDATE %s SET %s=%i, %s=%i, %s=%i, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, finished_at=NOW() WHERE lap_id=%i;",
|
||||
"laps", "sector_1", sector1, "sector_2", sector2, "sector_3", sector3,
|
||||
"right_front_tyre_temp", simdata->tyretemp[1],
|
||||
"right_rear_tyre_temp", simdata->tyretemp[3],
|
||||
"right_front_tyre_wear", simdata->tyrewear[1],
|
||||
"right_rear_tyre_wear", simdata->tyrewear[3],
|
||||
"right_front_tyre_press",simdata->tyrepressure[1],
|
||||
"right_rear_tyre_press", simdata->tyrepressure[3],
|
||||
"right_front_brake_temp",simdata->braketemp[1],
|
||||
"right_rear_brake_temp", simdata->braketemp[3],
|
||||
"left_front_tyre_temp", simdata->tyretemp[0],
|
||||
"left_rear_tyre_temp", simdata->tyretemp[2],
|
||||
"left_front_tyre_wear", simdata->tyrewear[0],
|
||||
"left_rear_tyre_wear", simdata->tyrewear[2],
|
||||
"left_front_tyre_press",simdata->tyrepressure[0],
|
||||
"left_rear_tyre_press", simdata->tyrepressure[2],
|
||||
"left_front_brake_temp",simdata->braketemp[0],
|
||||
"left_rear_brake_temp", simdata->braketemp[2],
|
||||
lapid);
|
||||
|
||||
|
||||
int res1 = h_query_update(conn, query);
|
||||
slogt("running query %s", query);
|
||||
free(query);
|
||||
|
||||
slogt("closed previous lap");
|
||||
return res1;
|
||||
}
|
||||
|
||||
int closelap(struct _h_connection* conn, SimData* simdata, int lapid, int sector1, int sector2, int sector3, int cuts, int crashes, int maxspeed, int avgspeed)
|
||||
{
|
||||
|
||||
closelapquery(conn, lapid, sector1, sector2, sector3, 0, 0, 0, 0, simdata);
|
||||
|
||||
}
|
||||
|
||||
int addstintlap(struct _h_connection* conn, int stintid, SimData* simdata)
|
||||
{
|
||||
|
||||
// stint laps
|
||||
// stint_lap_id | stint_id | sector_1 | sector_2 | sector_3 | grip | tyre | time | cuts | crashes
|
||||
// max_speed | avg_speed | finished_at
|
||||
json_t *root = json_object();
|
||||
json_t *json_arr = json_array();
|
||||
|
||||
json_object_set_new( root, "table", json_string("laps") );
|
||||
json_object_set_new( root, "values", json_arr );
|
||||
|
||||
json_t* values = json_object();
|
||||
|
||||
json_object_set_new(values, "stint_id", json_integer(stintid));
|
||||
json_object_set_new(values, "tyre", json_string("Vintage") );
|
||||
json_array_append(json_arr, values);
|
||||
int res = h_insert(conn, root, NULL);
|
||||
slogt("stint lap insert response: %i", res);
|
||||
json_decref(root);
|
||||
json_decref(values);
|
||||
return getLastInsertID(conn);
|
||||
}
|
||||
|
||||
int addcar(struct _h_connection* conn, int carid, const char* carname)
|
||||
{
|
||||
|
||||
// car_id | display_name | car_name | manufacturer | car_class
|
||||
|
||||
if (carid > 0)
|
||||
{
|
||||
return carid;
|
||||
}
|
||||
json_t *root = json_object();
|
||||
json_t *json_arr = json_array();
|
||||
|
||||
json_object_set_new( root, "table", json_string("cars") );
|
||||
json_object_set_new( root, "values", json_arr );
|
||||
|
||||
json_t* values = json_object();
|
||||
json_object_set_new(values, "display_name", json_string(carname));
|
||||
json_object_set_new(values, "car_name", json_string(carname));
|
||||
json_object_set_new(values, "manufacturer", json_string("Unknown"));
|
||||
json_object_set_new(values, "car_class", json_string("Unknown"));
|
||||
json_array_append(json_arr, values);
|
||||
int res = h_insert(conn, root, NULL);
|
||||
json_decref(root);
|
||||
json_decref(values);
|
||||
|
||||
carid = getLastInsertID(conn);
|
||||
return carid;
|
||||
}
|
||||
|
||||
int addtelemetry(struct _h_connection* conn, int points, int stintid)
|
||||
{
|
||||
|
||||
json_t *root = json_object();
|
||||
json_t *json_arr = json_array();
|
||||
|
||||
json_object_set_new( root, "table", json_string("telemetry") );
|
||||
json_object_set_new( root, "values", json_arr );
|
||||
|
||||
json_t* values = json_object();
|
||||
json_object_set_new(values, "lap_id", json_integer(stintid));
|
||||
json_object_set_new(values, "points", json_integer(points));
|
||||
json_array_append(json_arr, values);
|
||||
int res = h_insert(conn, root, NULL);
|
||||
json_decref(root);
|
||||
json_decref(values);
|
||||
|
||||
int telemid = getLastInsertID(conn);
|
||||
return telemid;
|
||||
}
|
||||
|
||||
int updatetelemetry(struct _h_connection* conn, int telemid, int size, const char* column, void* data)
|
||||
{
|
||||
|
||||
//char *pp = malloc((size*2)+1);
|
||||
char output[(size * 2) + 1];
|
||||
char *ppp = &output[0];
|
||||
unsigned char *p = data;
|
||||
int i;
|
||||
for (i=0; i<size; i++) {
|
||||
ppp += sprintf(ppp, "%02hhX", p[i]);
|
||||
//snprintf(pp, (size*2)+1, "%s%02hhX", pp, p[i]);
|
||||
}
|
||||
|
||||
char* query = malloc((sizeof(char)*71)+(sizeof(column))+(size*2)+1);
|
||||
sprintf(query, "UPDATE telemetry SET %s = decode('%s', 'hex') WHERE telemetry_id = %i", column, &output, telemid);
|
||||
int res1 = h_query_update(conn, query);
|
||||
//int res1 = h_insert(conn, j_query, NULL);
|
||||
slogt("got res %i", res1);
|
||||
free(query);
|
||||
|
||||
return res1;
|
||||
}
|
||||
|
||||
|
||||
int gettrack(struct _h_connection* conn, const char* trackname)
|
||||
{
|
||||
|
||||
|
||||
json_t *j_result;
|
||||
char* where_clause = h_build_where_clause(conn, "config_name=%s AND track_name=%s", "default", trackname);
|
||||
json_t* j_query = json_pack("{sss[s]s{s{ssss}}}", "table", "track_config", "columns", "track_config_id", "where", " ", "operator", "raw",
|
||||
"value", where_clause);
|
||||
|
||||
char* qq;
|
||||
int res = h_select(conn, j_query, &j_result, NULL);
|
||||
|
||||
// Deallocate j_query since it won't be needed anymore
|
||||
json_decref(j_query);
|
||||
h_free(where_clause);
|
||||
int track_config = -1;
|
||||
// Test query execution result
|
||||
if (res == H_OK) {
|
||||
// Print result
|
||||
char* dump = json_dumps(j_result, JSON_INDENT(2));
|
||||
slogi("json select result is\n%s", dump);
|
||||
int index1 = json_array_size(j_result);
|
||||
if (index1 == 0)
|
||||
{
|
||||
slogw("no config for this track");
|
||||
}
|
||||
else {
|
||||
json_t* jj = json_array_get(j_result, index1-1);
|
||||
track_config = json_integer_value(json_object_get(jj, "track_config_id"));
|
||||
}
|
||||
// Deallocate data result
|
||||
json_decref(j_result);
|
||||
free(dump);
|
||||
} else {
|
||||
sloge("Error executing select query: %d", res);
|
||||
}
|
||||
return track_config;
|
||||
}
|
||||
|
||||
int getdriver(struct _h_connection* conn, const char* driver_name)
|
||||
{
|
||||
json_t *j_result;
|
||||
char* where_clause = h_build_where_clause(conn, "driver_name=%s", driver_name);
|
||||
json_t* j_query = json_pack("{sss[s]s{s{ssss}}}","table", "drivers", "columns", "driver_id", "where", " ", "operator", "raw",
|
||||
"value", where_clause);
|
||||
|
||||
slogi("Looking for driver named %s", driver_name);
|
||||
//char* qq;
|
||||
int res = h_select(conn, j_query, &j_result, NULL);
|
||||
//slogi("here your query: %s", qq);
|
||||
// Deallocate j_query since it won't be needed anymore
|
||||
json_decref(j_query);
|
||||
h_free(where_clause);
|
||||
int driver_id = -1;
|
||||
// Test query execution result
|
||||
if (res == H_OK) {
|
||||
// Print result
|
||||
char* dump = json_dumps(j_result, JSON_INDENT(2));
|
||||
slogi("json select result is\n%s", dump);
|
||||
int index1 = json_array_size(j_result);
|
||||
if (index1 == 0)
|
||||
{
|
||||
slogw("no driver by this name");
|
||||
}
|
||||
else {
|
||||
json_t* jj = json_array_get(j_result, index1-1);
|
||||
driver_id = json_integer_value(json_object_get(jj, "driver_id"));
|
||||
}
|
||||
// Deallocate data result
|
||||
json_decref(j_result);
|
||||
free(dump);
|
||||
} else {
|
||||
sloge("Error executing select query: %d", res);
|
||||
}
|
||||
return driver_id;
|
||||
}
|
||||
|
||||
int getcar(struct _h_connection* conn, const char* carname)
|
||||
{
|
||||
json_t *j_result;
|
||||
char* where_clause = h_build_where_clause(conn, "car_name=%s", carname);
|
||||
json_t* j_query = json_pack("{sss[s]s{s{ssss}}}","table", "cars", "columns", "car_id", "where", " ", "operator", "raw",
|
||||
"value", where_clause);
|
||||
|
||||
slogi("Looking for car named %s", carname);
|
||||
//char* qq;
|
||||
int res = h_select(conn, j_query, &j_result, NULL);
|
||||
//slogi("here your query: %s", qq);
|
||||
// Deallocate j_query since it won't be needed anymore
|
||||
json_decref(j_query);
|
||||
h_free(where_clause);
|
||||
int car_id = -1;
|
||||
// Test query execution result
|
||||
if (res == H_OK) {
|
||||
// Print result
|
||||
char* dump = json_dumps(j_result, JSON_INDENT(2));
|
||||
slogi("json select result is\n%s", dump);
|
||||
int index1 = json_array_size(j_result);
|
||||
if (index1 == 0)
|
||||
{
|
||||
slogw("no car by this name");
|
||||
}
|
||||
else {
|
||||
json_t* jj = json_array_get(j_result, index1-1);
|
||||
car_id = json_integer_value(json_object_get(jj, "car_id"));
|
||||
}
|
||||
// Deallocate data result
|
||||
json_decref(j_result);
|
||||
free(dump);
|
||||
} else {
|
||||
sloge("Error executing select query: %d", res);
|
||||
}
|
||||
return car_id;
|
||||
}
|
||||
|
||||
void print_bytes(void *ptr, int size)
|
||||
{
|
||||
char *pp = malloc((size*2)+1);
|
||||
char output[(size * 2) + 1];
|
||||
char *ppp = &output[0];
|
||||
unsigned char *p = ptr;
|
||||
int i;
|
||||
for (i=0; i<size; i++) {
|
||||
slogt("%02hhX", p[i]);
|
||||
ppp += sprintf(ppp, "%02X", p[i]);
|
||||
//snprintf(pp, (size*2)+1, "%s%02hhX", pp, p[i]);
|
||||
}
|
||||
slogt("\n");
|
||||
slogt("bytes %s", output);
|
||||
}
|
||||
|
||||
|
||||
int updatetelemetrydata(struct _h_connection* conn, int tracksamples, int telemid, int lapid,
|
||||
int* speeddata, int* rpmdata, int* geardata,
|
||||
double* steerdata, double* acceldata, double* brakedata)
|
||||
{
|
||||
int b = 0;
|
||||
b = updatetelemetry(conn, telemid, tracksamples*sizeof(double), "steer", steerdata);
|
||||
b = updatetelemetry(conn, telemid, tracksamples*sizeof(double), "accel", acceldata);
|
||||
b = updatetelemetry(conn, telemid, tracksamples*sizeof(double), "brake", brakedata);
|
||||
b = updatetelemetry(conn, telemid, tracksamples*sizeof(int), "rpms", rpmdata);
|
||||
b = updatetelemetry(conn, telemid, tracksamples*sizeof(int), "gear", geardata);
|
||||
b = updatetelemetry(conn, telemid, tracksamples*sizeof(int), "speed", speeddata);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
void* simviewmysql(void* thargs)
|
||||
{
|
||||
Parameters* p = (Parameters*) thargs;
|
||||
|
|
@ -1221,7 +742,20 @@ void* simviewmysql(void* thargs)
|
|||
slogi("Starting telemetry");
|
||||
|
||||
int trackconfig = gettrack(conn, simdata->track);
|
||||
if (trackconfig == -1)
|
||||
{
|
||||
slogf("Problem performing select query. Does the db user have read permissions?");
|
||||
p->err = E_FAILED_DB_CONN;
|
||||
return 0;
|
||||
}
|
||||
|
||||
trackconfig = addtrackconfig(conn, trackconfig, simdata->track, simdata->trackdistancearound);
|
||||
if (trackconfig == -1)
|
||||
{
|
||||
slogf("Problem performing insert query. Does the db user have write permissions?");
|
||||
p->err = E_FAILED_DB_CONN;
|
||||
return 0;
|
||||
}
|
||||
slogt("Detected track configuration id: %i", trackconfig);
|
||||
int eventid = addevent(conn, trackconfig);
|
||||
int driverid = getdriver(conn, simdata->driver);
|
||||
|
|
@ -1339,7 +873,7 @@ void* simviewmysql(void* thargs)
|
|||
validstintlaps++;
|
||||
}
|
||||
|
||||
closelap(conn, simdata, stintlapid, sectortimes[1], sectortimes[2], simdata->lastsectorinms, 0, 0, 0, 0);
|
||||
closelap(conn, stintlapid, sectortimes[1], sectortimes[2], simdata->lastsectorinms, 0, 0, 0, 0, simdata);
|
||||
|
||||
stintlapid = addstintlap(conn, stintid, simdata);
|
||||
int telemid = addtelemetry(conn, track_samples, stintlapid);
|
||||
|
|
@ -1362,7 +896,7 @@ void* simviewmysql(void* thargs)
|
|||
{
|
||||
int telemid = addtelemetry(conn, track_samples, stintlapid);
|
||||
int b = updatetelemetrydata(conn, track_samples, telemid, stintlapid, speeddata, geardata, rpmdata, steerdata, acceldata, brakedata);
|
||||
closelap(conn, simdata, stintlapid, sectortimes[1], sectortimes[2], simdata->lastsectorinms, 0, 0, 0, 0);
|
||||
closelap(conn, stintlapid, sectortimes[1], sectortimes[2], simdata->lastsectorinms, 0, 0, 0, 0, simdata);
|
||||
closestint(conn, stintid, stintlaps, validstintlaps);
|
||||
closesession(conn, sessionid);
|
||||
go = false;
|
||||
|
|
|
|||
|
|
@ -8,9 +8,18 @@
|
|||
#include <jansson.h>
|
||||
|
||||
#include "hoeldb.h"
|
||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||
#include "../helper/confighelper.h"
|
||||
#include "../slog/slog.h"
|
||||
|
||||
int getLastInsertID(struct _h_connection* conn)
|
||||
{
|
||||
json_t* last_id = (h_last_insert_id(conn));
|
||||
int id = json_integer_value(last_id);
|
||||
json_decref(last_id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void get_row_results(struct _h_result result, DBField* fields, void* rows, size_t rowsize) {
|
||||
int col, row, i;
|
||||
char buf[64];
|
||||
|
|
@ -57,33 +66,538 @@ void get_row_results(struct _h_result result, DBField* fields, void* rows, size_
|
|||
}
|
||||
}
|
||||
|
||||
int getsessions(struct _h_connection* conn, int* err, const char* sessionname, SessionDbo* sess)
|
||||
int getsessions(struct _h_connection* conn, const char* sessionname, SessionDbo* sess)
|
||||
{
|
||||
struct _h_result result;
|
||||
struct _h_data * data;
|
||||
char* query = malloc(247 * sizeof(char));
|
||||
slogt("Performing query");
|
||||
char* query = malloc(515 * sizeof(char));
|
||||
slogt("Performing query sessions");
|
||||
|
||||
//sprintf(query, "select session_id, event_id, event_type, duration_min, elapsed_ms, laps, air_temp, road_temp, start_grip, current_grip, is_finished, http_port from %s", "Sessions");
|
||||
sprintf(query, "select session_id, events.event_id, sessions.event_type, laps, display_name FROM %s JOIN events ON sessions.event_id=events.event_id JOIN track_config ON events.track_config_id=track_config.track_config_id ORDER BY session_id DESC LIMIT 25", "Sessions");
|
||||
sprintf(query, "select sessions.session_id, events.event_id, sessions.event_type, table1.stints, track_config.display_name, cars.car_name, start_time "
|
||||
"FROM %s JOIN events ON sessions.event_id=events.event_id JOIN track_config ON events.track_config_id=track_config.track_config_id "
|
||||
"JOIN cars ON sessions.car_id=cars.car_id "
|
||||
"JOIN (Select session_id, COUNT(stint_id) AS stints FROM stints GROUP BY session_id) AS table1 ON table1.session_id=sessions.session_id "
|
||||
"ORDER BY session_id DESC LIMIT 25", "Sessions");
|
||||
|
||||
int errcode = h_query_select(conn, query, &result);
|
||||
if (errcode == H_OK)
|
||||
{
|
||||
|
||||
sess->rows = malloc(sizeof(SessionRowData) * result.nb_rows);
|
||||
get_row_results(result, sess->fields, sess->rows, sizeof(SessionRowData));
|
||||
//get_session_result(result, sess);
|
||||
h_clean_result(&result);
|
||||
}
|
||||
else
|
||||
{
|
||||
sloge("Error executing query %s returned %i", query, errcode);
|
||||
*err = E_DB_QUERY_FAIL;;
|
||||
free(query);
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
free(query);
|
||||
|
||||
return result.nb_rows;
|
||||
}
|
||||
|
||||
int getstints(struct _h_connection* conn, const char* sessionname, StintDbo* stint, int use_id)
|
||||
{
|
||||
struct _h_result result;
|
||||
struct _h_data * data;
|
||||
char* query = malloc(150 * sizeof(char));
|
||||
slogt("Performing query stints");
|
||||
|
||||
|
||||
sprintf(query, "select stint_id, driver_id, team_member_id, session_id, car_id, game_car_id, laps, valid_laps, best_lap_id FROM %s WHERE session_id=%i", "Stints", use_id);
|
||||
slogt("execute query %s", query);
|
||||
int errcode = h_query_select(conn, query, &result);
|
||||
if (errcode == H_OK)
|
||||
{
|
||||
stint->rows = malloc(sizeof(StintRowData) * result.nb_rows);
|
||||
get_row_results(result, stint->fields, stint->rows, sizeof(StintRowData));
|
||||
h_clean_result(&result);
|
||||
}
|
||||
else
|
||||
{
|
||||
sloge("Error executing query %s returned %i", query, errcode);
|
||||
free(query);
|
||||
return -1;
|
||||
}
|
||||
free(query);
|
||||
|
||||
return result.nb_rows;
|
||||
}
|
||||
|
||||
int getlaps(struct _h_connection* conn, const char* sessionname, LapDbo* laps, int use_id)
|
||||
{
|
||||
struct _h_result result;
|
||||
struct _h_data * data;
|
||||
char* query = malloc(250 * sizeof(char));
|
||||
slogt("Performing query laps");
|
||||
|
||||
sprintf(query, "select lap_id, stint_id, sector_1, sector_2, sector_3, grip, tyre, time, cuts, crashes, max_speed, avg_speed, finished_at FROM %s WHERE %s=%i", "Laps", "stint_id", use_id);
|
||||
int errcode = h_query_select(conn, query, &result);
|
||||
if (errcode == H_OK)
|
||||
{
|
||||
laps->rows = malloc(sizeof(LapRowData) * result.nb_rows);
|
||||
get_row_results(result, laps->fields, laps->rows, sizeof(LapRowData));
|
||||
h_clean_result(&result);
|
||||
} else {
|
||||
sloge("Error executing query %s returned %i", query, errcode);
|
||||
free(query);
|
||||
return -1;
|
||||
}
|
||||
free(query);
|
||||
|
||||
return result.nb_rows;
|
||||
}
|
||||
|
||||
int gettrack(struct _h_connection* conn, const char* trackname)
|
||||
{
|
||||
|
||||
|
||||
json_t *j_result;
|
||||
char* where_clause = h_build_where_clause(conn, "config_name=%s AND track_name=%s", "default", trackname);
|
||||
json_t* j_query = json_pack("{sss[s]s{s{ssss}}}", "table", "track_config", "columns", "track_config_id", "where", " ", "operator", "raw",
|
||||
"value", where_clause);
|
||||
|
||||
char* qq;
|
||||
int res = h_select(conn, j_query, &j_result, &qq);
|
||||
|
||||
// Deallocate j_query since it won't be needed anymore
|
||||
json_decref(j_query);
|
||||
h_free(where_clause);
|
||||
int track_config = -1;
|
||||
// Test query execution result
|
||||
if (res == H_OK) {
|
||||
// Print result
|
||||
//char* dump = json_dumps(j_result, JSON_INDENT(2));
|
||||
//slogi("json select result is\n%s", dump);
|
||||
int index1 = json_array_size(j_result);
|
||||
//if (index1 == 0)
|
||||
//{
|
||||
// slogw("no config for this track");
|
||||
//}
|
||||
//else {
|
||||
json_t* jj = json_array_get(j_result, index1-1);
|
||||
track_config = json_integer_value(json_object_get(jj, "track_config_id"));
|
||||
//}
|
||||
// Deallocate data result
|
||||
|
||||
//free(dump);
|
||||
} else {
|
||||
sloge("Error executing select query %s: %d", qq, res);
|
||||
}
|
||||
json_decref(j_result);
|
||||
free(qq);
|
||||
json_decref(j_query);
|
||||
h_free(where_clause);
|
||||
return track_config;
|
||||
}
|
||||
|
||||
int getdriver(struct _h_connection* conn, const char* driver_name)
|
||||
{
|
||||
json_t *j_result;
|
||||
char* where_clause = h_build_where_clause(conn, "driver_name=%s", driver_name);
|
||||
json_t* j_query = json_pack("{sss[s]s{s{ssss}}}","table", "drivers", "columns", "driver_id", "where", " ", "operator", "raw",
|
||||
"value", where_clause);
|
||||
|
||||
slogi("Looking for driver named %s", driver_name);
|
||||
char* qq;
|
||||
int res = h_select(conn, j_query, &j_result, &qq);
|
||||
//slogi("here your query: %s", qq);
|
||||
// Deallocate j_query since it won't be needed anymore
|
||||
json_decref(j_query);
|
||||
h_free(where_clause);
|
||||
int driver_id = -1;
|
||||
// Test query execution result
|
||||
if (res == H_OK) {
|
||||
// Print result
|
||||
char* dump = json_dumps(j_result, JSON_INDENT(2));
|
||||
slogt("json select result is\n%s", dump);
|
||||
int index1 = json_array_size(j_result);
|
||||
if (index1 == 0)
|
||||
{
|
||||
slogw("no driver by this name");
|
||||
}
|
||||
else {
|
||||
json_t* jj = json_array_get(j_result, index1-1);
|
||||
driver_id = json_integer_value(json_object_get(jj, "driver_id"));
|
||||
}
|
||||
// Deallocate data result
|
||||
free(dump);
|
||||
} else {
|
||||
sloge("Error executing select query %s: %d", qq, res);
|
||||
}
|
||||
json_decref(j_result);
|
||||
free(qq);
|
||||
json_decref(j_query);
|
||||
h_free(where_clause);
|
||||
return driver_id;
|
||||
}
|
||||
|
||||
int getcar(struct _h_connection* conn, const char* carname)
|
||||
{
|
||||
json_t *j_result;
|
||||
char* where_clause = h_build_where_clause(conn, "car_name=%s", carname);
|
||||
json_t* j_query = json_pack("{sss[s]s{s{ssss}}}","table", "cars", "columns", "car_id", "where", " ", "operator", "raw",
|
||||
"value", where_clause);
|
||||
|
||||
slogi("Looking for car named %s", carname);
|
||||
char* qq;
|
||||
int res = h_select(conn, j_query, &j_result, &qq);
|
||||
//slogi("here your query: %s", qq);
|
||||
// Deallocate j_query since it won't be needed anymore
|
||||
|
||||
int car_id = -1;
|
||||
// Test query execution result
|
||||
if (res == H_OK) {
|
||||
// Print result
|
||||
char* dump = json_dumps(j_result, JSON_INDENT(2));
|
||||
slogt("json select result is\n%s", dump);
|
||||
int index1 = json_array_size(j_result);
|
||||
if (index1 == 0)
|
||||
{
|
||||
slogw("no car by this name");
|
||||
}
|
||||
else {
|
||||
json_t* jj = json_array_get(j_result, index1-1);
|
||||
car_id = json_integer_value(json_object_get(jj, "car_id"));
|
||||
}
|
||||
// Deallocate data result
|
||||
free(dump);
|
||||
} else {
|
||||
sloge("Error executing select query %s: %d", qq, res);
|
||||
}
|
||||
json_decref(j_result);
|
||||
free(qq);
|
||||
json_decref(j_query);
|
||||
h_free(where_clause);
|
||||
return car_id;
|
||||
}
|
||||
|
||||
|
||||
// inserts
|
||||
int addtrackconfig(struct _h_connection* conn, int trackconfigid, const char* track, int length)
|
||||
{
|
||||
//track_config_id | track_name | config_name | display_name | country | city | length
|
||||
if (trackconfigid > 0)
|
||||
{
|
||||
return trackconfigid;
|
||||
}
|
||||
json_t *root = json_object();
|
||||
json_t *json_arr = json_array();
|
||||
|
||||
json_object_set_new( root, "table", json_string("track_config") );
|
||||
json_object_set_new( root, "values", json_arr );
|
||||
|
||||
json_t* values = json_object();
|
||||
json_object_set_new(values, "track_name", json_string(track));
|
||||
json_object_set_new(values, "config_name", json_string("default"));
|
||||
json_object_set_new(values, "display_name", json_string(track));
|
||||
json_object_set_new(values, "country", json_string("USA"));
|
||||
json_object_set_new(values, "city", json_string("USA"));
|
||||
json_object_set_new(values, "length", json_integer(length));
|
||||
|
||||
json_array_append(json_arr, values);
|
||||
char* qq;
|
||||
int res = h_insert(conn, root, &qq);
|
||||
json_decref(root);
|
||||
json_decref(values);
|
||||
|
||||
if (res != 0)
|
||||
{
|
||||
sloge("track config insert result %i", res);
|
||||
sloge("track config query %s", qq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
trackconfigid = getLastInsertID(conn);
|
||||
return trackconfigid;
|
||||
}
|
||||
|
||||
int addsession(struct _h_connection* conn, int eventid, int carid, int eventtype, int airtemp, int tracktemp, SimData* simdata)
|
||||
{
|
||||
|
||||
// session_id | event_id | event_type | track_time | session_name
|
||||
// | start_time | duration_min | elapsed_ms | laps | weather |
|
||||
// air_temp | road_temp | start_grip |
|
||||
json_t *root = json_object();
|
||||
json_t *json_arr = json_array();
|
||||
|
||||
json_object_set_new( root, "table", json_string("sessions") );
|
||||
json_object_set_new( root, "values", json_arr );
|
||||
|
||||
json_t* values = json_object();
|
||||
json_object_set_new(values, "event_id", json_integer(eventid));
|
||||
json_object_set_new(values, "car_id", json_integer(carid));
|
||||
json_object_set_new(values, "event_type", json_integer(1));
|
||||
json_object_set_new(values, "duration_min", json_integer(60));
|
||||
json_object_set_new(values, "start_time", json_string("NOW()"));
|
||||
json_object_set_new(values, "session_name", json_string("default"));
|
||||
json_object_set_new(values, "air_temp", json_integer(airtemp));
|
||||
json_object_set_new(values, "road_temp", json_integer(tracktemp));
|
||||
json_object_set_new(values, "weather", json_string("Windy"));
|
||||
json_object_set_new(values, "http_port", json_integer(0));
|
||||
json_array_append(json_arr, values);
|
||||
|
||||
char* qq;
|
||||
int res = h_insert(conn, root, &qq);
|
||||
json_decref(root);
|
||||
json_decref(values);
|
||||
|
||||
if (res != 0)
|
||||
{
|
||||
sloge("track config insert result %i", res);
|
||||
sloge("track config query %s", qq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return getLastInsertID(conn);
|
||||
}
|
||||
|
||||
int adddriver(struct _h_connection* conn, int driverid, const char* drivername)
|
||||
{
|
||||
if (driverid > 0)
|
||||
{
|
||||
return driverid;
|
||||
}
|
||||
json_t *root = json_object();
|
||||
json_t *json_arr = json_array();
|
||||
|
||||
json_object_set_new( root, "table", json_string("drivers") );
|
||||
json_object_set_new( root, "values", json_arr );
|
||||
|
||||
json_t* values = json_object();
|
||||
json_object_set_new(values, "driver_name", json_string(drivername));
|
||||
json_object_set_new(values, "prev_name", json_string(drivername));
|
||||
json_object_set_new(values, "steam64_id", json_integer(17));
|
||||
json_object_set_new(values, "country", json_string("USA"));
|
||||
json_array_append(json_arr, values);
|
||||
int res = h_insert(conn, root, NULL);
|
||||
json_decref(root);
|
||||
json_decref(values);
|
||||
|
||||
driverid = getLastInsertID(conn);
|
||||
return driverid;
|
||||
}
|
||||
|
||||
|
||||
int addevent(struct _h_connection* conn, int track_config)
|
||||
{
|
||||
|
||||
json_t *root = json_object();
|
||||
json_t *json_arr = json_array();
|
||||
|
||||
json_object_set_new( root, "table", json_string("events") );
|
||||
json_object_set_new( root, "values", json_arr );
|
||||
|
||||
json_t* values = json_object();
|
||||
json_object_set_new(values, "track_config_id", json_integer(track_config));
|
||||
json_object_set_new(values, "event_name", json_string("default"));
|
||||
//event_id | server_name | track_config_id | event_name | team_event | active | livery_preview | use_number | practice_duration | quali_duration | race_duration | race_duration_type | race_wait_time | race_extra_laps | reverse_grid_positions
|
||||
json_array_append(json_arr, values);
|
||||
int res = h_insert(conn, root, NULL);
|
||||
json_decref(root);
|
||||
json_decref(values);
|
||||
return getLastInsertID(conn);
|
||||
}
|
||||
|
||||
|
||||
int addstint(struct _h_connection* conn, int sessionid, int driverid, int carid, SimData* simdata)
|
||||
{
|
||||
|
||||
|
||||
json_t *root = json_object();
|
||||
json_t *json_arr = json_array();
|
||||
|
||||
json_object_set_new( root, "table", json_string("stints") );
|
||||
json_object_set_new( root, "values", json_arr );
|
||||
|
||||
json_t* values = json_object();
|
||||
|
||||
json_object_set_new(values, "driver_id", json_integer(driverid));
|
||||
//team_member_id
|
||||
json_object_set_new(values, "session_id", json_integer(sessionid));
|
||||
json_object_set_new(values, "car_id", json_integer(carid));
|
||||
json_object_set_new(values, "game_car_id", json_integer(carid));
|
||||
json_object_set_new(values, "laps", json_integer(0));
|
||||
json_object_set_new(values, "valid_laps", json_integer(0));
|
||||
json_object_set_new(values, "tyre", json_string("Vintage") );
|
||||
// best_lap_id
|
||||
json_object_set_new(values, "is_finished", json_integer(0));
|
||||
|
||||
json_object_set_new(values, "started_at", json_string("NOW()") );
|
||||
json_array_append(json_arr, values);
|
||||
int res = h_insert(conn, root, NULL);
|
||||
slogt("stint insert response: %i", res);
|
||||
json_decref(root);
|
||||
json_decref(values);
|
||||
return getLastInsertID(conn);
|
||||
}
|
||||
|
||||
int addstintlap(struct _h_connection* conn, int stintid, SimData* simdata)
|
||||
{
|
||||
|
||||
// stint laps
|
||||
// stint_lap_id | stint_id | sector_1 | sector_2 | sector_3 | grip | tyre | time | cuts | crashes
|
||||
// max_speed | avg_speed | finished_at
|
||||
json_t *root = json_object();
|
||||
json_t *json_arr = json_array();
|
||||
|
||||
json_object_set_new( root, "table", json_string("laps") );
|
||||
json_object_set_new( root, "values", json_arr );
|
||||
|
||||
json_t* values = json_object();
|
||||
|
||||
json_object_set_new(values, "stint_id", json_integer(stintid));
|
||||
json_object_set_new(values, "tyre", json_string("Vintage") );
|
||||
json_array_append(json_arr, values);
|
||||
int res = h_insert(conn, root, NULL);
|
||||
slogt("stint lap insert response: %i", res);
|
||||
json_decref(root);
|
||||
json_decref(values);
|
||||
return getLastInsertID(conn);
|
||||
}
|
||||
|
||||
int addcar(struct _h_connection* conn, int carid, const char* carname)
|
||||
{
|
||||
|
||||
// car_id | display_name | car_name | manufacturer | car_class
|
||||
|
||||
if (carid > 0)
|
||||
{
|
||||
return carid;
|
||||
}
|
||||
json_t *root = json_object();
|
||||
json_t *json_arr = json_array();
|
||||
|
||||
json_object_set_new( root, "table", json_string("cars") );
|
||||
json_object_set_new( root, "values", json_arr );
|
||||
|
||||
json_t* values = json_object();
|
||||
json_object_set_new(values, "display_name", json_string(carname));
|
||||
json_object_set_new(values, "car_name", json_string(carname));
|
||||
json_object_set_new(values, "manufacturer", json_string("Unknown"));
|
||||
json_object_set_new(values, "car_class", json_string("Unknown"));
|
||||
json_array_append(json_arr, values);
|
||||
int res = h_insert(conn, root, NULL);
|
||||
json_decref(root);
|
||||
json_decref(values);
|
||||
|
||||
carid = getLastInsertID(conn);
|
||||
return carid;
|
||||
}
|
||||
|
||||
int addtelemetry(struct _h_connection* conn, int points, int stintid)
|
||||
{
|
||||
|
||||
json_t *root = json_object();
|
||||
json_t *json_arr = json_array();
|
||||
|
||||
json_object_set_new( root, "table", json_string("telemetry") );
|
||||
json_object_set_new( root, "values", json_arr );
|
||||
|
||||
json_t* values = json_object();
|
||||
json_object_set_new(values, "lap_id", json_integer(stintid));
|
||||
json_object_set_new(values, "points", json_integer(points));
|
||||
json_array_append(json_arr, values);
|
||||
int res = h_insert(conn, root, NULL);
|
||||
json_decref(root);
|
||||
json_decref(values);
|
||||
|
||||
int telemid = getLastInsertID(conn);
|
||||
return telemid;
|
||||
}
|
||||
|
||||
|
||||
int closelap(struct _h_connection* conn, int lapid, int sector1, int sector2, int sector3, int cuts, int crashes, int maxspeed, int avgspeed, SimData* simdata)
|
||||
{
|
||||
|
||||
// stint laps
|
||||
// lap_id | stint_id | sector_1 | sector_2 | sector_3 | grip | tyre | time | cuts | crashes
|
||||
// max_speed | avg_speed | finished_at
|
||||
|
||||
slogt("closing previous lap ", lapid);
|
||||
|
||||
char* query = malloc((sizeof(char)*632));
|
||||
sprintf(query, "UPDATE %s SET %s=%i, %s=%i, %s=%i, %s=%i, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, finished_at=NOW() WHERE lap_id=%i;",
|
||||
"laps", "time", simdata->lastlap, "sector_1", sector1, "sector_2", sector2, "sector_3", sector3,
|
||||
"right_front_tyre_temp", simdata->tyretemp[1],
|
||||
"right_rear_tyre_temp", simdata->tyretemp[3],
|
||||
"right_front_tyre_wear", simdata->tyrewear[1],
|
||||
"right_rear_tyre_wear", simdata->tyrewear[3],
|
||||
"right_front_tyre_press",simdata->tyrepressure[1],
|
||||
"right_rear_tyre_press", simdata->tyrepressure[3],
|
||||
"right_front_brake_temp",simdata->braketemp[1],
|
||||
"right_rear_brake_temp", simdata->braketemp[3],
|
||||
"left_front_tyre_temp", simdata->tyretemp[0],
|
||||
"left_rear_tyre_temp", simdata->tyretemp[2],
|
||||
"left_front_tyre_wear", simdata->tyrewear[0],
|
||||
"left_rear_tyre_wear", simdata->tyrewear[2],
|
||||
"left_front_tyre_press",simdata->tyrepressure[0],
|
||||
"left_rear_tyre_press", simdata->tyrepressure[2],
|
||||
"left_front_brake_temp",simdata->braketemp[0],
|
||||
"left_rear_brake_temp", simdata->braketemp[2],
|
||||
lapid);
|
||||
|
||||
int errcode = h_query_update(conn, query);
|
||||
if (errcode != H_OK)
|
||||
{
|
||||
sloge("Error executing query %s returned %i", query, errcode);
|
||||
free(query);
|
||||
return -1;
|
||||
}
|
||||
|
||||
slogt("closed previous lap");
|
||||
free(query);
|
||||
return errcode;
|
||||
}
|
||||
|
||||
int closesession(struct _h_connection* conn, int sessionid)
|
||||
{
|
||||
|
||||
slogt("closing previous session ", sessionid);
|
||||
// best_lap_id
|
||||
|
||||
// session_id | event_id | event_type | track_time | session_name
|
||||
// | start_time | duration_min | elapsed_ms | laps | weather |
|
||||
// air_temp | road_temp | start_grip | end_grip | is_finished
|
||||
|
||||
char* query = malloc((sizeof(char)*100));
|
||||
sprintf(query, "UPDATE %s SET is_finished=1, finished_at=NOW() WHERE session_id=%i",
|
||||
"sessions", sessionid);
|
||||
|
||||
int errcode = h_query_update(conn, query);
|
||||
if (errcode != H_OK)
|
||||
{
|
||||
sloge("Error executing query %s returned %i", query, errcode);
|
||||
free(query);
|
||||
return -1;
|
||||
}
|
||||
|
||||
slogt("closed previous session");
|
||||
free(query);
|
||||
return errcode;
|
||||
}
|
||||
|
||||
|
||||
int closestint(struct _h_connection* conn, int stintid, int stintlaps, int validstintlaps)
|
||||
{
|
||||
|
||||
// best_lap_id
|
||||
slogt("closing previous stint ", stintid);
|
||||
|
||||
char* query = malloc((sizeof(char)*146));
|
||||
sprintf(query, "UPDATE %s SET %s = %i, %s = %i, is_finished=1, finished_at=NOW() WHERE stint_id=%i",
|
||||
"stints", "laps", stintlaps, "valid_laps", validstintlaps, stintid);
|
||||
|
||||
int errcode = h_query_update(conn, query);
|
||||
if (errcode != H_OK)
|
||||
{
|
||||
sloge("Error executing query %s returned %i", query, errcode);
|
||||
free(query);
|
||||
return -1;
|
||||
}
|
||||
|
||||
slogt("closed previous stint");
|
||||
free(query);
|
||||
return errcode;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||
|
||||
typedef struct DBData DBData;
|
||||
typedef struct DBField DBField;
|
||||
typedef struct SessionFieldsData SessionFieldsData;
|
||||
|
|
@ -38,7 +40,9 @@ typedef struct SessionRowData
|
|||
//int duration_min;
|
||||
//int elapsed_ms;
|
||||
int laps;
|
||||
unsigned char track[20];
|
||||
unsigned char track[150];
|
||||
unsigned char car[150];
|
||||
PDBTimeStamp start_time;
|
||||
//char weather[100];
|
||||
//double air_temp;
|
||||
//double road_temp;
|
||||
|
|
@ -87,7 +91,7 @@ typedef struct LapRowData
|
|||
int crashes;
|
||||
int max_speed;
|
||||
int avg_speed;
|
||||
//PDBTimeStamp finished_at;
|
||||
PDBTimeStamp finished_at;
|
||||
//double f_tyre_temp;
|
||||
//double r_tyre_temp;
|
||||
//double f_tyre_wear;
|
||||
|
|
@ -104,7 +108,7 @@ typedef struct SessionDbo
|
|||
int numrows;
|
||||
bool hasdata;
|
||||
|
||||
DBField fields[5];
|
||||
DBField fields[7];
|
||||
SessionRowData* rows;
|
||||
}
|
||||
SessionDbo;
|
||||
|
|
@ -124,13 +128,46 @@ typedef struct LapDbo
|
|||
int numrows;
|
||||
bool hasdata;
|
||||
|
||||
DBField fields[12];
|
||||
DBField fields[13];
|
||||
LapRowData* rows;
|
||||
}
|
||||
LapDbo;
|
||||
|
||||
int getLastInsertID(struct _h_connection* conn);
|
||||
|
||||
void get_row_results(struct _h_result result, DBField* fields, void* rows, size_t rowsize);
|
||||
|
||||
int getsessions(struct _h_connection* conn, int* err, const char* sessionname, SessionDbo* sess);
|
||||
int getsessions(struct _h_connection* conn, const char* sessionname, SessionDbo* sess);
|
||||
|
||||
int getstints(struct _h_connection* conn, const char* sessionname, StintDbo* stint, int use_id);
|
||||
|
||||
int getlaps(struct _h_connection* conn, const char* sessionname, LapDbo* laps, int use_id);
|
||||
|
||||
int gettrack(struct _h_connection* conn, const char* trackname);
|
||||
|
||||
int getdriver(struct _h_connection* conn, const char* driver_name);
|
||||
|
||||
int getcar(struct _h_connection* conn, const char* carname);
|
||||
|
||||
int addtrackconfig(struct _h_connection* conn, int trackconfigid, const char* track, int length);
|
||||
|
||||
int adddriver(struct _h_connection* conn, int driverid, const char* drivername);
|
||||
|
||||
int addevent(struct _h_connection* conn, int track_config);
|
||||
|
||||
int addsession(struct _h_connection* conn, int eventid, int carid, int eventtype, int airtemp, int tracktemp, SimData* simdata);
|
||||
|
||||
int addstint(struct _h_connection* conn, int sessionid, int driverid, int carid, SimData* simdata);
|
||||
|
||||
int addstintlap(struct _h_connection* conn, int stintid, SimData* simdata);
|
||||
|
||||
int addcar(struct _h_connection* conn, int carid, const char* carname);
|
||||
|
||||
int addtelemetry(struct _h_connection* conn, int points, int stintid);
|
||||
|
||||
int closelap(struct _h_connection* conn, int lapid, int sector1, int sector2, int sector3, int cuts, int crashes, int maxspeed, int avgspeed, SimData* simdata);
|
||||
|
||||
int closestint(struct _h_connection* conn, int stintid, int stintlaps, int validstintlaps);
|
||||
|
||||
int closesession(struct _h_connection* conn, int sessionid);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ int dumptelemetrytofile(struct _h_connection* conn, char* datadir, int lap1id, i
|
|||
snprintf(datafile, strsize, "%s%s", datadir, filename1);
|
||||
slogt("dumping %i points to file %s", points, datafile);
|
||||
FILE *out = fopen(datafile, "w");
|
||||
fprintf(out, "%s %s %s %s %s %s %s %s %s %s %s %s %s\n", "point", "speed1", "gear1", "rpms1", "brake1", "accel1", "steer1", "speed2", "gear2", "rpms2", "brake2", "accel2", "steer2" );
|
||||
fprintf(out, "%s %s %s %s %s %s %s %s %s %s %s %s %s\n", "point", "speed1", "rpms1", "gear1", "brake1", "accel1", "steer1", "speed2", "rpms2", "gear2", "brake2", "accel2", "steer2" );
|
||||
for (int i=0; i<points; i++)
|
||||
{
|
||||
fprintf(out, "%i %i %i %i %f %f %f", i+1, intarrays1[i], intarrays1[i+points], intarrays1[i+(points*2)], doublearrays1[i], doublearrays1[i+points], doublearrays1[i+(points*2)]);
|
||||
|
|
@ -226,3 +226,57 @@ int dumptelemetrytofile(struct _h_connection* conn, char* datadir, int lap1id, i
|
|||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void print_bytes(void *ptr, int size)
|
||||
{
|
||||
char *pp = malloc((size*2)+1);
|
||||
char output[(size * 2) + 1];
|
||||
char *ppp = &output[0];
|
||||
unsigned char *p = ptr;
|
||||
int i;
|
||||
for (i=0; i<size; i++) {
|
||||
slogt("%02hhX", p[i]);
|
||||
ppp += sprintf(ppp, "%02X", p[i]);
|
||||
//snprintf(pp, (size*2)+1, "%s%02hhX", pp, p[i]);
|
||||
}
|
||||
slogt("\n");
|
||||
slogt("bytes %s", output);
|
||||
}
|
||||
|
||||
int updatetelemetry(struct _h_connection* conn, int telemid, int size, const char* column, void* data)
|
||||
{
|
||||
|
||||
//char *pp = malloc((size*2)+1);
|
||||
char output[(size * 2) + 1];
|
||||
char *ppp = &output[0];
|
||||
unsigned char *p = data;
|
||||
int i;
|
||||
for (i=0; i<size; i++) {
|
||||
ppp += sprintf(ppp, "%02hhX", p[i]);
|
||||
//snprintf(pp, (size*2)+1, "%s%02hhX", pp, p[i]);
|
||||
}
|
||||
|
||||
char* query = malloc((sizeof(char)*71)+(sizeof(column))+(size*2)+1);
|
||||
sprintf(query, "UPDATE telemetry SET %s = decode('%s', 'hex') WHERE telemetry_id = %i", column, &output, telemid);
|
||||
int res1 = h_query_update(conn, query);
|
||||
//int res1 = h_insert(conn, j_query, NULL);
|
||||
slogt("got res %i", res1);
|
||||
free(query);
|
||||
|
||||
return res1;
|
||||
}
|
||||
|
||||
int updatetelemetrydata(struct _h_connection* conn, int tracksamples, int telemid, int lapid,
|
||||
int* speeddata, int* rpmdata, int* geardata,
|
||||
double* steerdata, double* acceldata, double* brakedata)
|
||||
{
|
||||
int b = 0;
|
||||
b = updatetelemetry(conn, telemid, tracksamples*sizeof(double), "steer", steerdata);
|
||||
b = updatetelemetry(conn, telemid, tracksamples*sizeof(double), "accel", acceldata);
|
||||
b = updatetelemetry(conn, telemid, tracksamples*sizeof(double), "brake", brakedata);
|
||||
b = updatetelemetry(conn, telemid, tracksamples*sizeof(int), "rpms", rpmdata);
|
||||
b = updatetelemetry(conn, telemid, tracksamples*sizeof(int), "gear", geardata);
|
||||
b = updatetelemetry(conn, telemid, tracksamples*sizeof(int), "speed", speeddata);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,4 +3,10 @@
|
|||
|
||||
int dumptelemetrytofile(struct _h_connection* conn, char* datadir, int lap1id, int lap2id);
|
||||
|
||||
void print_bytes(void *ptr, int size);
|
||||
|
||||
int updatetelemetrydata(struct _h_connection* conn, int tracksamples, int telemid, int lapid,
|
||||
int* speeddata, int* rpmdata, int* geardata,
|
||||
double* steerdata, double* acceldata, double* brakedata);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue