diff --git a/data/Circuit.duckdb b/data/Circuit.duckdb new file mode 100644 index 0000000..83f1cc7 Binary files /dev/null and b/data/Circuit.duckdb differ diff --git a/src/lapinfo.c b/src/lapinfo.c new file mode 100644 index 0000000..e1dc27e --- /dev/null +++ b/src/lapinfo.c @@ -0,0 +1,38 @@ +#include +#include + +typedef enum { + BOOL, + INT, + FLOAT, + DOUBLE, +} TelemetryDataType; + +typedef struct { + TelemetryDataType type; + int8_t frequency; + void *data; +} TelemetryInfo; + +typedef struct { + int lap_number; + double start_time; + TelemetryInfo throttle_pos; + TelemetryInfo brake_pos; + TelemetryInfo steering_pos; + TelemetryInfo speed; +} LapInfo; + +void free_telemetry_info(TelemetryInfo *t) { + free(t->data); + // free(t); +} + +// Dont use for now +void destroyLapinfo(LapInfo *info) { + free_telemetry_info(&info->throttle_pos); + free_telemetry_info(&info->brake_pos); + free_telemetry_info(&info->steering_pos); + free_telemetry_info(&info->speed); + free(info); +} diff --git a/src/main.c b/src/main.c index 02f38de..95f0198 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -89,8 +90,7 @@ int main(int argc, char **argv) { "Wind Speed", "Yaw Rate"}; - const int channel_table_count = - sizeof(channel_tables) / sizeof(channel_tables[0]); + const int channel_table_count = sizeof(channel_tables) / sizeof(channel_tables[0]); const char *event_tables[] = {"ABS", "ABSLevel", @@ -135,46 +135,51 @@ int main(int argc, char **argv) { "WheelsDetached", "Yellow Flag State"}; - const int event_table_count = - sizeof(event_tables) / sizeof(event_tables[0]); + const int event_table_count = sizeof(event_tables) / sizeof(event_tables[0]); // Test query duckdb_result result; - duckdb_query(conn, "SELECT * from \"Ambient Temperature\";\n", &result); int32_t iterations = 0; int32_t number_of_data_points = 0; - while (true) { - iterations++; + for (int i = 0; i < 1 /*channel_table_count*/; i++) { + char queryBuffer[256]; // buffer to hold the formatted query - duckdb_data_chunk data_chunk = duckdb_fetch_chunk(result); + // snprintf(queryBuffer, sizeof(queryBuffer), "SELECT * FROM \"%s\"\n", channel_tables[i]); - if (!data_chunk) { - break; - } + // duckdb_query(conn, queryBuffer, &result); + duckdb_query(conn, "SELECT CAST(value AS FLOAT) from \"Lap Time\"\n", &result); - idx_t row_count = duckdb_data_chunk_get_size( - data_chunk); // number of rows from the data chunk - number_of_data_points += row_count; + while (true) { + iterations++; - // first 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); + duckdb_data_chunk data_chunk = duckdb_fetch_chunk(result); - for (idx_t row = 0; row < row_count; row++) { - if (duckdb_validity_row_is_valid(col1_validity, row)) { - printf("%f, ", col1_data[row]); - } else { - printf("NULL"); + 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; - duckdb_destroy_data_chunk(&data_chunk); + // set column + duckdb_vector col1 = duckdb_data_chunk_get_vector(data_chunk, 0); + float_t *col1_data = (float_t *)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)) { + 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); + printf("\nNumber of iterations: %d, number of data points: %d\n", iterations, number_of_data_points); printf("Shutting down HardCompound!\n");