querying the throttle position from the db
This commit is contained in:
56
src/main.c
56
src/main.c
@@ -5,6 +5,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include "arrays.h"
|
||||||
#include "exit_code.h"
|
#include "exit_code.h"
|
||||||
#include "lapinfo.h"
|
#include "lapinfo.h"
|
||||||
|
|
||||||
@@ -30,7 +31,30 @@ bool is_valid_path(const char *path) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_data_from_db(const char *query, duckdb_connection *conn, TelemetryInfo *info) {
|
void allocate_array_for_db_data(float_array *array, const char *table, duckdb_connection *conn) {
|
||||||
|
char query[100];
|
||||||
|
sprintf(query, "Select count(*) from \"%s\"", table);
|
||||||
|
duckdb_result result;
|
||||||
|
duckdb_query(*conn, query, &result);
|
||||||
|
|
||||||
|
duckdb_data_chunk chunk = duckdb_fetch_chunk(result);
|
||||||
|
if (!chunk) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
duckdb_vector col1 = duckdb_data_chunk_get_vector(chunk, 0);
|
||||||
|
int32_t *col1_data = (int32_t *)duckdb_vector_get_data(col1);
|
||||||
|
uint64_t *col1_validity = duckdb_vector_get_validity(col1);
|
||||||
|
|
||||||
|
if (duckdb_validity_row_is_valid(col1_validity, 0)) {
|
||||||
|
printf("capycity of array: %d", col1_data[0]);
|
||||||
|
float_array_allocate(array, col1_data[0]);
|
||||||
|
}
|
||||||
|
duckdb_destroy_data_chunk(&chunk);
|
||||||
|
duckdb_destroy_result(&result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void get_data_from_db(const char *query, duckdb_connection *conn, float_array *info) {
|
||||||
duckdb_result result;
|
duckdb_result result;
|
||||||
|
|
||||||
duckdb_query(*conn, query, &result);
|
duckdb_query(*conn, query, &result);
|
||||||
@@ -50,26 +74,7 @@ void get_data_from_db(const char *query, duckdb_connection *conn, TelemetryInfo
|
|||||||
|
|
||||||
for (idx_t row = 0; row < row_count; row++) {
|
for (idx_t row = 0; row < row_count; row++) {
|
||||||
if (duckdb_validity_row_is_valid(col1_validity, row)) {
|
if (duckdb_validity_row_is_valid(col1_validity, row)) {
|
||||||
switch (info->type) {
|
float_array_set(info, ((float *)col1_data)[row], -1);
|
||||||
case FLOAT:
|
|
||||||
((float *)info->data)[info->data_last_index] = ((float *)col1_data)[row];
|
|
||||||
info->data_last_index++;
|
|
||||||
break;
|
|
||||||
case BOOL:
|
|
||||||
((bool *)info->data)[info->data_last_index] = ((bool *)col1_data)[row];
|
|
||||||
info->data_last_index++;
|
|
||||||
break;
|
|
||||||
case DOUBLE:
|
|
||||||
((double *)info->data)[info->data_last_index] = ((double *)col1_data)[row];
|
|
||||||
info->data_last_index++;
|
|
||||||
break;
|
|
||||||
case INT:
|
|
||||||
((int32_t *)info->data)[info->data_last_index] = ((int32_t *)col1_data)[row];
|
|
||||||
info->data_last_index++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
printf("NULL");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +189,14 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
// get the per laptime data
|
// throttle
|
||||||
|
float_array throttle_data_all;
|
||||||
|
float_array_init(&throttle_data_all);
|
||||||
|
allocate_array_for_db_data(&throttle_data_all, "Throttle Pos", &conn);
|
||||||
|
get_data_from_db("Select value as FLOAT from \"Throttle Pos\"\n", &conn, &throttle_data_all);
|
||||||
|
for (int32_t i = 0; i < throttle_data_all.length; ++i) {
|
||||||
|
printf(" %f", float_array_get(&throttle_data_all, i));
|
||||||
|
}
|
||||||
|
|
||||||
printf("Shutting down HardCompound!\n");
|
printf("Shutting down HardCompound!\n");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user