2025-12-28 21:32:38 +01:00
|
|
|
#include <duckdb.h>
|
2025-12-29 13:46:15 +01:00
|
|
|
#include <stdint.h>
|
2025-12-28 18:17:59 +01:00
|
|
|
#include <stdio.h>
|
2025-12-28 21:32:38 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2026-01-02 20:01:19 +01:00
|
|
|
#include "lapinfo.h"
|
|
|
|
|
|
|
|
|
|
void get_data_from_db(const char *query, duckdb_connection *conn, TelemetryInfo *info) {
|
|
|
|
|
duckdb_result result;
|
|
|
|
|
int32_t iterations = 0;
|
|
|
|
|
int32_t number_of_data_points = 0;
|
|
|
|
|
|
|
|
|
|
duckdb_query(*conn, query, &result);
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
iterations++;
|
|
|
|
|
|
|
|
|
|
duckdb_data_chunk data_chunk = duckdb_fetch_chunk(result);
|
|
|
|
|
if (!data_chunk) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
idx_t row_count = duckdb_data_chunk_get_size(data_chunk); // number of rows from the data chunk
|
|
|
|
|
number_of_data_points += row_count;
|
|
|
|
|
|
|
|
|
|
// set column
|
|
|
|
|
duckdb_vector col1 = duckdb_data_chunk_get_vector(data_chunk, 0);
|
|
|
|
|
float *col1_data = (float *)duckdb_vector_get_data(col1);
|
|
|
|
|
uint64_t *col1_validity = duckdb_vector_get_validity(col1);
|
|
|
|
|
|
|
|
|
|
for (idx_t row = 0; row < row_count; row++) {
|
|
|
|
|
if (duckdb_validity_row_is_valid(col1_validity, row)) {
|
|
|
|
|
// put a switch here based on the info from the struct
|
|
|
|
|
((float *)info->data)[info->data_last_index] = col1_data[row];
|
|
|
|
|
info->data_last_index++;
|
|
|
|
|
// TODO: set info->data_size as capacity at struct creation
|
|
|
|
|
printf("%f, ", col1_data[row]);
|
|
|
|
|
} else {
|
|
|
|
|
printf("NULL");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
duckdb_destroy_data_chunk(&data_chunk);
|
|
|
|
|
}
|
|
|
|
|
duckdb_destroy_result(&result);
|
|
|
|
|
printf("\nNumber of iterations: %d, number of data points: %d\n", iterations, number_of_data_points);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-29 14:59:04 +01:00
|
|
|
int main(int argc, char **argv) {
|
2025-12-28 21:32:38 +01:00
|
|
|
printf("Hello from HardCompound!\n");
|
|
|
|
|
|
2025-12-29 14:59:04 +01:00
|
|
|
if (argc < 2) {
|
2025-12-28 21:32:38 +01:00
|
|
|
printf("You need to specify a duckdb file path! Terminating!\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2025-12-29 13:46:15 +01:00
|
|
|
printf("First argument: %s\n", argv[1]);
|
2025-12-28 21:32:38 +01:00
|
|
|
|
|
|
|
|
duckdb_database db;
|
2025-12-29 14:59:04 +01:00
|
|
|
if (duckdb_open(argv[1], &db) == DuckDBError) {
|
2025-12-29 13:46:15 +01:00
|
|
|
printf("Error opening duckdb file, terminating!\n");
|
2025-12-28 21:32:38 +01:00
|
|
|
exit(2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
duckdb_connection conn;
|
2025-12-29 14:59:04 +01:00
|
|
|
if (duckdb_connect(db, &conn) == DuckDBError) {
|
2025-12-29 13:46:15 +01:00
|
|
|
printf("Error connecting to the duckdb database! Terminating!\n");
|
2025-12-28 21:32:38 +01:00
|
|
|
exit(3);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-29 14:59:04 +01:00
|
|
|
const char *channel_tables[] = {"Ambient Temperature",
|
|
|
|
|
"Brake Pos",
|
|
|
|
|
"Brake Pos Unfiltered",
|
|
|
|
|
"Brake Thickness",
|
|
|
|
|
"Brakes Air Temp",
|
|
|
|
|
"Brakes Force",
|
|
|
|
|
"Brakes Temp",
|
|
|
|
|
"Clutch Pos",
|
|
|
|
|
"Clutch Pos Unfiltered",
|
|
|
|
|
"Clutch RPM",
|
|
|
|
|
"Drag",
|
|
|
|
|
"Engine Oil Temp",
|
|
|
|
|
"Engine RPM",
|
|
|
|
|
"Engine Water Temp",
|
|
|
|
|
"FFB Output",
|
|
|
|
|
"Front3rdDeflection",
|
|
|
|
|
"FrontDownForce",
|
|
|
|
|
"FrontRideHeight",
|
|
|
|
|
"FrontWingHeight",
|
|
|
|
|
"Fuel Level",
|
|
|
|
|
"G Force Lat",
|
|
|
|
|
"G Force Long",
|
|
|
|
|
"G Force Vert",
|
|
|
|
|
"GPS Latitude",
|
|
|
|
|
"GPS Longitude",
|
|
|
|
|
"GPS Speed",
|
|
|
|
|
"GPS Time",
|
|
|
|
|
"Ground Speed",
|
|
|
|
|
"Lap Dist",
|
|
|
|
|
"Lateral Acceleration",
|
|
|
|
|
"Longitudinal Acceleration",
|
|
|
|
|
"OverheatingState",
|
|
|
|
|
"Path Lateral",
|
|
|
|
|
"ReadDownForce",
|
|
|
|
|
"Rear3rdDeflection",
|
|
|
|
|
"RearRideHeight",
|
|
|
|
|
"Regen Rate",
|
|
|
|
|
"RideHeights",
|
|
|
|
|
"SoC",
|
|
|
|
|
"Steered Angle",
|
|
|
|
|
"Steering Pos",
|
|
|
|
|
"Steering Pos Unfiltered",
|
|
|
|
|
"Steering Shaft Torque",
|
|
|
|
|
"Susp Pos",
|
|
|
|
|
"Throttle Pos",
|
|
|
|
|
"Throttle Pos Unfiltered",
|
|
|
|
|
"Time Behind Next",
|
|
|
|
|
"Total Dist",
|
|
|
|
|
"Track Edge",
|
|
|
|
|
"Track Temperature",
|
|
|
|
|
"Turbo Boost Pressure",
|
|
|
|
|
"Tyres Wear",
|
|
|
|
|
"TyresCarcassTemp",
|
|
|
|
|
"TyresPressure",
|
|
|
|
|
"TyresRimTemp",
|
|
|
|
|
"TyresRubberTemp",
|
|
|
|
|
"TyresTempCentre",
|
|
|
|
|
"TyresTempLeft",
|
|
|
|
|
"TyresTempRight",
|
|
|
|
|
"Virtual Energy",
|
|
|
|
|
"Wheel Speed",
|
|
|
|
|
"Wind Heading",
|
|
|
|
|
"Wind Speed",
|
|
|
|
|
"Yaw Rate"};
|
|
|
|
|
|
2025-12-31 23:30:18 +01:00
|
|
|
const int channel_table_count = sizeof(channel_tables) / sizeof(channel_tables[0]);
|
2025-12-29 14:59:04 +01:00
|
|
|
|
|
|
|
|
const char *event_tables[] = {"ABS",
|
|
|
|
|
"ABSLevel",
|
|
|
|
|
"AntiStall Activated",
|
|
|
|
|
"Best LapTime",
|
|
|
|
|
"Best Sector1",
|
|
|
|
|
"Best Sector2",
|
|
|
|
|
"Brake Bias Rear",
|
|
|
|
|
"Brake Migration",
|
|
|
|
|
"CloudDarkness",
|
|
|
|
|
"Current LapTime",
|
|
|
|
|
"Current Sector",
|
|
|
|
|
"Current Sector1",
|
|
|
|
|
"Current Sector2",
|
|
|
|
|
"Engine Max RPM",
|
|
|
|
|
"Finish Status",
|
|
|
|
|
"FrontFlapActivated",
|
|
|
|
|
"FuelMixtureMap",
|
|
|
|
|
"Gear",
|
|
|
|
|
"Headlights State",
|
|
|
|
|
"In Pits",
|
|
|
|
|
"Lap",
|
|
|
|
|
"Lap Time",
|
|
|
|
|
"Last Sector1",
|
|
|
|
|
"Last Sector2",
|
|
|
|
|
"LastImpactMagnitude",
|
|
|
|
|
"LaunchControlActive",
|
|
|
|
|
"Minimum Path Wetness",
|
|
|
|
|
"OffpathWetness",
|
|
|
|
|
"RearFlapActivated",
|
|
|
|
|
"RearFlapLegalStatus",
|
|
|
|
|
"Sector1 Flag",
|
|
|
|
|
"Sector2 Flag",
|
|
|
|
|
"Sector3 Flag",
|
|
|
|
|
"Speed Limiter",
|
|
|
|
|
"SurfaceTypes",
|
|
|
|
|
"TC",
|
|
|
|
|
"TCCut",
|
|
|
|
|
"TCLevel",
|
|
|
|
|
"TCSlipAngle",
|
|
|
|
|
"TyresCompound",
|
|
|
|
|
"WheelsDetached",
|
|
|
|
|
"Yellow Flag State"};
|
|
|
|
|
|
2025-12-31 23:30:18 +01:00
|
|
|
const int event_table_count = sizeof(event_tables) / sizeof(event_tables[0]);
|
2025-12-29 14:59:04 +01:00
|
|
|
|
2026-01-02 20:01:19 +01:00
|
|
|
LapInfo info = {.lap_number = 0,
|
|
|
|
|
.start_time = 0,
|
|
|
|
|
.throttle_pos = {.data_last_index = 0,
|
|
|
|
|
.data_size = 75000,
|
|
|
|
|
.frequency = 50,
|
|
|
|
|
.type = FLOAT,
|
|
|
|
|
.validity = NULL,
|
|
|
|
|
.data = malloc(sizeof(float) * 75000)},
|
|
|
|
|
.brake_pos = {.data_last_index = 0,
|
|
|
|
|
.data_size = 75000,
|
|
|
|
|
.frequency = 50,
|
|
|
|
|
.type = FLOAT,
|
|
|
|
|
.validity = NULL,
|
|
|
|
|
.data = malloc(sizeof(float) * 75000)},
|
|
|
|
|
.steering_pos = {.data_last_index = 0,
|
|
|
|
|
.data_size = 75000,
|
|
|
|
|
.frequency = 50,
|
|
|
|
|
.type = FLOAT,
|
|
|
|
|
.validity = NULL,
|
|
|
|
|
.data = malloc(sizeof(float) * 75000)},
|
|
|
|
|
.speed = {.data_last_index = 0,
|
|
|
|
|
.data_size = 75000,
|
|
|
|
|
.frequency = 50,
|
|
|
|
|
.type = FLOAT,
|
|
|
|
|
.validity = NULL,
|
|
|
|
|
.data = malloc(sizeof(float) * 75000)}};
|
|
|
|
|
|
|
|
|
|
get_data_from_db("Select * from \"Throttle Pos\"\n", &conn, &info.throttle_pos);
|
|
|
|
|
destroyLapinfo(&info);
|
2025-12-29 13:46:15 +01:00
|
|
|
|
|
|
|
|
printf("Shutting down HardCompound!\n");
|
|
|
|
|
|
|
|
|
|
printf("Closing database and any connection.\n");
|
|
|
|
|
duckdb_disconnect(&conn);
|
|
|
|
|
duckdb_close(&db);
|
|
|
|
|
|
2025-12-28 18:17:59 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|