moving development to master for a while since there is no need for branching yet #8
BIN
.cache/clangd/index/duckdb.h.63D53BDB55D39D0A.idx
Normal file
BIN
.cache/clangd/index/duckdb.h.63D53BDB55D39D0A.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/lapinfo.c.F9698B9BD3295BA4.idx
Normal file
BIN
.cache/clangd/index/lapinfo.c.F9698B9BD3295BA4.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/lapinfo.h.702DAF4EDA4E0E47.idx
Normal file
BIN
.cache/clangd/index/lapinfo.h.702DAF4EDA4E0E47.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/main.c.8770424B51F7A3DB.idx
Normal file
BIN
.cache/clangd/index/main.c.8770424B51F7A3DB.idx
Normal file
Binary file not shown.
44
compile_commands.json
Normal file
44
compile_commands.json
Normal file
@@ -0,0 +1,44 @@
|
||||
[
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/gcc",
|
||||
"-Wall",
|
||||
"-O0",
|
||||
"-g",
|
||||
"-DDEBUG",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Isrc",
|
||||
"-I/usr/include/mysql/",
|
||||
"-Ivendor/duckdb/linux/include",
|
||||
"-c",
|
||||
"-o",
|
||||
"build/lapinfo.o",
|
||||
"src/lapinfo.c"
|
||||
],
|
||||
"directory": "/home/tom/Dev/HardCompound",
|
||||
"file": "/home/tom/Dev/HardCompound/src/lapinfo.c",
|
||||
"output": "/home/tom/Dev/HardCompound/build/lapinfo.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/gcc",
|
||||
"-Wall",
|
||||
"-O0",
|
||||
"-g",
|
||||
"-DDEBUG",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Isrc",
|
||||
"-I/usr/include/mysql/",
|
||||
"-Ivendor/duckdb/linux/include",
|
||||
"-c",
|
||||
"-o",
|
||||
"build/main.o",
|
||||
"src/main.c"
|
||||
],
|
||||
"directory": "/home/tom/Dev/HardCompound",
|
||||
"file": "/home/tom/Dev/HardCompound/src/main.c",
|
||||
"output": "/home/tom/Dev/HardCompound/build/main.o"
|
||||
}
|
||||
]
|
||||
@@ -1,38 +1,17 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
#include "lapinfo.h"
|
||||
|
||||
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);
|
||||
// free(info);
|
||||
}
|
||||
|
||||
31
src/lapinfo.h
Normal file
31
src/lapinfo.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
BOOL,
|
||||
INT,
|
||||
FLOAT,
|
||||
DOUBLE,
|
||||
} TelemetryDataType;
|
||||
|
||||
typedef struct {
|
||||
TelemetryDataType type;
|
||||
int8_t frequency;
|
||||
void *data;
|
||||
uint64_t *validity;
|
||||
uint32_t data_size;
|
||||
uint32_t data_last_index;
|
||||
} TelemetryInfo;
|
||||
|
||||
typedef struct {
|
||||
int lap_number;
|
||||
double start_time;
|
||||
TelemetryInfo throttle_pos; // freq: 50
|
||||
TelemetryInfo brake_pos; // freq: 50
|
||||
TelemetryInfo steering_pos; // freq: 100
|
||||
TelemetryInfo speed;
|
||||
} LapInfo;
|
||||
|
||||
void free_telemetry_info(TelemetryInfo *t);
|
||||
void destroyLapinfo(LapInfo *info);
|
||||
117
src/main.c
117
src/main.c
@@ -1,9 +1,51 @@
|
||||
#include <duckdb.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
printf("Hello from HardCompound!\n");
|
||||
|
||||
@@ -137,55 +179,38 @@ int main(int argc, char **argv) {
|
||||
|
||||
const int event_table_count = sizeof(event_tables) / sizeof(event_tables[0]);
|
||||
|
||||
// Test query
|
||||
duckdb_result result;
|
||||
int32_t iterations = 0;
|
||||
int32_t number_of_data_points = 0;
|
||||
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)}};
|
||||
|
||||
for (int i = 0; i < 1 /*channel_table_count*/; i++) {
|
||||
char queryBuffer[256]; // buffer to hold the formatted query
|
||||
|
||||
// snprintf(queryBuffer, sizeof(queryBuffer), "SELECT * FROM \"%s\"\n", channel_tables[i]);
|
||||
|
||||
// duckdb_query(conn, queryBuffer, &result);
|
||||
duckdb_query(conn, "SELECT CAST(value AS FLOAT) from \"Lap Time\"\n", &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_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);
|
||||
get_data_from_db("Select * from \"Throttle Pos\"\n", &conn, &info.throttle_pos);
|
||||
destroyLapinfo(&info);
|
||||
|
||||
printf("Shutting down HardCompound!\n");
|
||||
|
||||
printf("Destroying result!\n");
|
||||
duckdb_destroy_result(&result);
|
||||
|
||||
printf("Closing database and any connection.\n");
|
||||
duckdb_disconnect(&conn);
|
||||
duckdb_close(&db);
|
||||
|
||||
Reference in New Issue
Block a user