diff --git a/.gitignore b/.gitignore index e1e226f..bd5c1e0 100644 --- a/.gitignore +++ b/.gitignore @@ -83,6 +83,7 @@ install_manifest.txt compile_commands.json CTestTestfile.cmake _deps +build ### CMake Patch ### # External projects diff --git a/Code-C/TSL2561.c b/Code-C/TSL2561.c index 152fa5d..2cafddf 100644 --- a/Code-C/TSL2561.c +++ b/Code-C/TSL2561.c @@ -1,5 +1,5 @@ // Code from the following github repo: https://github.com/ControlEverythingCommunity/TSL2561/blob/master/C/TSL2561.c -#include "include/TSL2561.h" +#include "./Include/TSL2561.h" void printSpectrum(int file) { @@ -8,15 +8,15 @@ void printSpectrum(int file) char reg[1] = {0x0C | 0x80}; write(file, reg, 1); char data[4] = {0}; - if(read(file, data, 4) != 4) + if (read(file, data, 4) != 4) { printf("Erorr : Input/output Erorr \n"); } else { // Convert the data - float ch0 = (data[1] * 256 + data[0]); //Full Spectrum(IR + Visible) - float ch1 = (data[3] * 256 + data[2]); //Infrared Value + float ch0 = (data[1] * 256 + data[0]); // Full Spectrum(IR + Visible) + float ch1 = (data[3] * 256 + data[2]); // Infrared Value // Output data to screen printf("Full Spectrum(IR + Visible) : %.1f lux \n", ch0); printf("Infrared Value : %.1f lux \n", ch1); @@ -31,14 +31,14 @@ float getFullSpectrum(int file) char reg[1] = {0x0C | 0x80}; write(file, reg, 1); char data[4] = {0}; - if(read(file, data, 4) != 4) + if (read(file, data, 4) != 4) { printf("Erorr : Input/output Erorr \n"); } else { // Convert the data - float ch0 = (data[1] * 256 + data[0]); //Full Spectrum(IR + Visible) + float ch0 = (data[1] * 256 + data[0]); // Full Spectrum(IR + Visible) return ch0; } } @@ -50,14 +50,14 @@ float getInfraredLight(int file) char reg[1] = {0x0C | 0x80}; write(file, reg, 1); char data[4] = {0}; - if(read(file, data, 4) != 4) + if (read(file, data, 4) != 4) { printf("Erorr : Input/output Erorr \n"); } else { // Convert the data - float ch1 = (data[3] * 256 + data[2]); //Infrared Value + float ch1 = (data[3] * 256 + data[2]); // Infrared Value return ch1; } } @@ -65,7 +65,7 @@ float getInfraredLight(int file) int init_TSL2561(char *bus) { int file; - if((file = open(bus, O_RDWR)) < 0) + if ((file = open(bus, O_RDWR)) < 0) { printf("Failed to open the bus. \n"); exit(1); @@ -87,21 +87,22 @@ int init_TSL2561(char *bus) return file; } -void TSL2561() +void TSL2561() { int fe = 1; int file; file = init_TSL2561(bus); - while(1) + while (1) { - sleep(1/fe); + sleep(1 / fe); float a = getFullSpectrum(file); float b = getInfraredLight(file); - printf("%.1f\n",a); - printf("%.1f\n",b); + printf("%.1f\n", a); + printf("%.1f\n", b); printSpectrum(file); } } -void main(){ - TSL2561(); +void main() +{ + TSL2561(); } \ No newline at end of file diff --git a/Code-C/average.c b/Code-C/average.c index afdc6bc..d9795ef 100644 --- a/Code-C/average.c +++ b/Code-C/average.c @@ -1,8 +1,8 @@ -#include "include/average.h" -#include "include/getArray.h" -#include "include/fileGestion.h" -#include "include/initialParameters.h" -#include "include/queue.h" +#include "./Include/average.h" +#include "./Include/getArray.h" +#include "./Include/fileGestion.h" +#include "./Include/initialParameters.h" +#include "./Include/queue.h" /** * @brief realize the average calcul * diff --git a/Code-C/b2hd.c b/Code-C/b2hd.c index 25c0a2d..bf78305 100644 --- a/Code-C/b2hd.c +++ b/Code-C/b2hd.c @@ -1,23 +1,22 @@ -#include "include/b2hd.h" +#include "./Include/b2hd.h" #include +int64_t millis() +{ + // struct timespec now; + struct timespec *now = (struct timespec *)malloc(sizeof(struct timespec)); + // timespec_get(&now, TIME_UTC); + timespec_get(now, TIME_UTC); - -int64_t millis(){ - //struct timespec now; - struct timespec *now = (struct timespec *) malloc(sizeof(struct timespec)); - //timespec_get(&now, TIME_UTC); - timespec_get(now, TIME_UTC); - - //#ifdef __USE_ISOC11 ???? - int64_t tmp = (((int64_t) now->tv_sec) * 1000 + ((int64_t) now->tv_nsec) / ((int64_t) 1000000)); - free(now); - return tmp; + // #ifdef __USE_ISOC11 ???? + int64_t tmp = (((int64_t)now->tv_sec) * 1000 + ((int64_t)now->tv_nsec) / ((int64_t)1000000)); + free(now); + return tmp; } /** * @brief allow to transform all binary hex data send by the Vegetal Signal captor in a .TXT file into decimal values in a .csv - * + * */ void b2hd() { @@ -28,38 +27,47 @@ void b2hd() int32_t values[8]; uint32_t valbin[8]; quartet value; - - while (fread(&buff, 26, 1, stdin)) { - fprintf(stdout , "%ld,", millis()); - for (int i = 1; i < 9; i++){ - /*buff[25] = '\0';*/ - if (strncmp(buff, "#################\n", (size_t)18) == 0) { - if (!(fread(&buff2, 18, 1, stdin))) { + + while (fread(&buff, 26, 1, stdin)) + { + fprintf(stdout, "%ld,", millis()); + for (int i = 1; i < 9; i++) + { + /*buff[25] = '\0';*/ + if (strncmp(buff, "#################\n", (size_t)18) == 0) + { + if (!(fread(&buff2, 18, 1, stdin))) + { fprintf(stderr, "Erreur lesture après ###...#"); - break; - } else { + break; + } + else + { /*buff2[17] = '\0';*/ strncpy(buff, &buff[18], 8); strncpy(&buff[8], buff2, 18); } } - value.octet1 = buff[3*i+1]; - value.octet2 = buff[3*i+2]; - value.octet3 = buff[3*i+3]; + value.octet1 = buff[3 * i + 1]; + value.octet2 = buff[3 * i + 2]; + value.octet3 = buff[3 * i + 3]; value.octet4 = 0; /*memcpy(&values[i], &value, sizeof(quartet));*/ - valbin[i] = buff[3*i+1]*256*256*256 + buff[3*i+2]*256*256 + buff[3*i+3]*256; + valbin[i] = buff[3 * i + 1] * 256 * 256 * 256 + buff[3 * i + 2] * 256 * 256 + buff[3 * i + 3] * 256; memcpy(&values[i], &valbin[i], sizeof(uint32_t)); - if(i<8){ - fprintf(stdout, "%d,", values[i]/256); + if (i < 8) + { + fprintf(stdout, "%d,", values[i] / 256); } - else{ - fprintf(stdout, "%d\n", values[i]/256); + else + { + fprintf(stdout, "%d\n", values[i] / 256); } } } } -int main(int argc , char** argv){ +int main(int argc, char **argv) +{ b2hd(); } \ No newline at end of file diff --git a/Code-C/csv2json.c b/Code-C/csv2json.c deleted file mode 100644 index 17be9cd..0000000 --- a/Code-C/csv2json.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include -#include -#include - -void writeCaptorNumber(int N) -{ - fprintf(stdout ,"{\n\"captorNumber\" : %d , " , N); -} - -void writeTimeArray() -{ - while -} - -void writeValuesArray(int N) -{ - -} - -int main(int argc, char **argv) -{ - -} \ No newline at end of file diff --git a/Code-C/ctest.c b/Code-C/ctest.c index 8beca7e..8e05438 100644 --- a/Code-C/ctest.c +++ b/Code-C/ctest.c @@ -5,14 +5,14 @@ #include #include -#include "include/fileGestion.h" -#include "include/getArray.h" -#include "include/growthRate.h" -#include "include/power.h" -#include "include/simulateFlux.h" -#include "include/queue.h" -#include "include/average.h" -//#include "b2hd.h" +#include "./Include/fileGestion.h" +#include "./Include/getArray.h" +#include "./Include/growthRate.h" +#include "./Include/power.h" +#include "./Include/simulateFlux.h" +#include "./Include/queue.h" +#include "./Include/average.h" +// #include "b2hd.h" bool rawDataWriteFlag; int nRowRawData = 500; diff --git a/Code-C/fileGestion.c b/Code-C/fileGestion.c index 99e0a62..545d3a6 100644 --- a/Code-C/fileGestion.c +++ b/Code-C/fileGestion.c @@ -1,4 +1,4 @@ -#include "include/fileGestion.h" +#include "./Include/fileGestion.h" /** * @brief function that delete nRow lign in the beginning of the file rawData.csv . This function is necessary to not deal with the same ligns over and over diff --git a/Code-C/getArray.c b/Code-C/getArray.c index 903c4f5..12b7fbf 100644 --- a/Code-C/getArray.c +++ b/Code-C/getArray.c @@ -1,6 +1,6 @@ -#include "include/getArray.h" -#include "include/fileGestion.h" -#include "include/initialParameters.h" +#include "./Include/getArray.h" +#include "./Include/fileGestion.h" +#include "./Include/initialParameters.h" // #include long **getlongArray(int N, int M) /* Allocate the array */ diff --git a/Code-C/growthRate.c b/Code-C/growthRate.c index 8188a8f..17255b3 100644 --- a/Code-C/growthRate.c +++ b/Code-C/growthRate.c @@ -1,34 +1,40 @@ -#include "include/initialParameters.h" -#include "include/fileGestion.h" -#include "include/getArray.h" -#include "include/growthRate.h" +#include "./Include/initialParameters.h" +#include "./Include/fileGestion.h" +#include "./Include/getArray.h" +#include "./Include/growthRate.h" /** * @brief calculate de growth rate between to point next to each other - * + * * @param dataArray array with data of points next to each other for each captor (dim : 2 * nCols) * @param gRateArray array that contaigns results of the growth ratecalculation */ -void growthRateCalculation(double **dataArray , double *gRateArray){ - for(int i = 0 ; i < nCol-1 ; i++){ +void growthRateCalculation(double **dataArray, double *gRateArray) +{ + for (int i = 0; i < nCol - 1; i++) + { gRateArray[i] = (dataArray[0][i] - dataArray[1][i]) / period; } } /** * @brief calcul then print differentiate in csv - * - * @param dataLign + * + * @param dataLign */ -void growthRateFunction(double **dataLign , char* fileName){ - double gRateArray[nCol-1]; - growthRateCalculation(dataLign , gRateArray); - appendDataInFile(fileName,gRateArray , nCol-1); +void growthRateFunction(double **dataLign, char *fileName) +{ + double gRateArray[nCol - 1]; + growthRateCalculation(dataLign, gRateArray); + appendDataInFile(fileName, gRateArray, nCol - 1); } -void sumColArray(long **p, double res[] , int N , int M){ - for(int i = 1; i < M; i++){ +void sumColArray(long **p, double res[], int N, int M) +{ + for (int i = 1; i < M; i++) + { int j = 0; res[i] = 0; - while(j < N){ + while (j < N) + { res[i] += p[i][j]; j++; } diff --git a/Code-C/main.c b/Code-C/main.c index 3a20725..2bd72cd 100644 --- a/Code-C/main.c +++ b/Code-C/main.c @@ -1,13 +1,13 @@ #include #include -#include "include/simulateFlux.h" -#include "include/power.h" -#include "include/initialParameters.h" -#include "include/queue.h" -#include "include/average.h" -#include "include/growthRate.h" -#include "include/getArray.h" +#include "./Include/simulateFlux.h" +#include "./Include/power.h" +#include "./Include/initialParameters.h" +#include "./Include/queue.h" +#include "./Include/average.h" +#include "./Include/growthRate.h" +#include "./Include/getArray.h" bool rawDataWriteFlag; int nRowRawData = 5000; @@ -146,8 +146,10 @@ int main(int argc, char **argv) } printf("%d", nCol); - for(int i = 0 ; i < 8 ; i++){ - if(selectionCaptors[i]){ + for (int i = 0; i < 8; i++) + { + if (selectionCaptors[i]) + { nCol++; } } diff --git a/Code-C/power.c b/Code-C/power.c index 87ae6a3..426ea8a 100644 --- a/Code-C/power.c +++ b/Code-C/power.c @@ -1,10 +1,10 @@ #include -#include "include/power.h" -#include "include/getArray.h" -#include "include/fileGestion.h" -#include "include/initialParameters.h" -#include "include/queue.h" +#include "./Include/power.h" +#include "./Include/getArray.h" +#include "./Include/fileGestion.h" +#include "./Include/initialParameters.h" +#include "./Include/queue.h" /** * @brief realize the powerThreadFunction calcul diff --git a/Code-C/queue.c b/Code-C/queue.c index b311c39..4459b9f 100644 --- a/Code-C/queue.c +++ b/Code-C/queue.c @@ -4,7 +4,7 @@ #include #include -#include "include/queue.h" +#include "./Include/queue.h" /** * @brief struct queue struct used for queueing string name diff --git a/Code-C/simulateFlux.c b/Code-C/simulateFlux.c index dd5cef2..d2b0e05 100644 --- a/Code-C/simulateFlux.c +++ b/Code-C/simulateFlux.c @@ -1,6 +1,6 @@ -#include "include/simulateFlux.h" -#include "include/initialParameters.h" -#include "include/queue.h" +#include "./Include/simulateFlux.h" +#include "./Include/initialParameters.h" +#include "./Include/queue.h" #include #include @@ -212,7 +212,7 @@ void *threadSimulateFlux(void *vargp) // prepare next file now fileName = createNewRawDataFileName(); rawDataFile = fopen(fileName, "w+"); - //add test to get p then print it here // p is gotten from fileName file + // add test to get p then print it here // p is gotten from fileName file } } rawDataWriteFlag = false; diff --git a/Db-Script/Db-Script.py b/Db-Script/Db-Script.py deleted file mode 100644 index 9a1fda4..0000000 --- a/Db-Script/Db-Script.py +++ /dev/null @@ -1,40 +0,0 @@ -##Imports - -import sqlite3 as sql -import pandas as pd -import os -import datetime -import matplotlib.pyplot as plt -import numpy as np - -def createMetadataTable(): - """Create the db table which contaign all data """ - db = sql.connect("robotgowestdb.db") - c = db.cursor() - - requestCreate = '''CREATE TABLE IF NOT EXISTS METADATA_TABLE ( - [Id] INTEGER PRIMARY KEY, - [Place] TEXT, - [Start] TEXT - )''' - c.execute(requestCreate) - db.commit() - -def insertMetadataElement(place : str , start : datetime): - """Insert a new element in the metadat table - - Args: - currency (str): name of the currency to fetch its metadata with the yFinance API - """ - db = sql.connect("robotgowestdb.db") - c = db.cursor() - request = f'''INSERT INTO METADATA_TABLE (Place,Start) - VALUES ( - '{place}', - '{start}' - )''' - c.execute(request) - db.commit() - -createMetadataTable() -insertMetadataElement("ici", datetime.datetime.now()) \ No newline at end of file diff --git a/Db-Script/database.c b/Db-Script/database.c new file mode 100644 index 0000000..97cd524 --- /dev/null +++ b/Db-Script/database.c @@ -0,0 +1,124 @@ +#include "./database.h" + +int openDb(sqlite3 *db) +{ + + int rc = sqlite3_open("robotgowest.db", &db); + + if (rc != SQLITE_OK) + { + + fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); + sqlite3_close(db); + + return 1; + } + return 0; +} + +int initializeTrailsAndCaptorMetadataTables() +{ + sqlite3 *db; + char *err_msg = 0; + int rc; + if (!openDb(db)) + { + char *sql = "DROP TABLE IF EXISTS Trials;" + "DROP TABLE IF EXISTS CaptorMetadata;" + "CREATE TABLE Trials(Id INTEGER PRIMARY KEY AUTOINCREMENT, Position TEXT, Start INT, Frequency NUMBER, Duration INT);" + "CREATE TABLE CaptorMetadata(Id INTEGER PRIMARY KEY AUTOINCREMENT, CaptorNumber INT, TrialId INT, FOREIGN KEY (TrialId) REFERENCES Trials(Id));"; + + rc = sqlite3_prepare_v2(db, sql, 0, 0, &err_msg); + + if (rc != SQLITE_OK) + { + + fprintf(stderr, "SQL error: %s\n", err_msg); + + sqlite3_free(err_msg); + sqlite3_close(db); + + return 1; + } + sqlite3_close(db); + + return 0; + } +} + +int createCaptorDataTable(int trialId, int captorNumber) +{ + sqlite3 *db; + char *err_msg = 0; + int rc; + + // Create Table Name + char tableName[8]; + strcpy(tableName, "T"); + strcat(tableName, convertIntegerToChar(trialId)); + strcat(tableName, "C"); + strcat(tableName, convertIntegerToChar(captorNumber)); + strcat(tableName, "Data"); + + if (!openDb(db)) + { + char sql[101] = "CREATE TABLE "; + strcat(sql, tableName); + strcat(sql, " (Id INTEGER PRIMARY KEY AUTOINCREMENT, Lux NUMBER, Mean NUMBER , Power NUMBER);"); + rc = sqlite3_exec(db, sql, 0, 0, &err_msg); + + if (rc != SQLITE_OK) + { + printf("Error code : %i", rc); + fprintf(stderr, "SQL error: %s\n", err_msg); + + sqlite3_free(err_msg); + sqlite3_close(db); + + return 1; + } + sqlite3_close(db); + + return 0; + } +} + +/** + * @brief convert an interger N into a char* + * + * @param N + * @return char* + */ +char *convertIntegerToChar(int N) +{ + // Count digits in number N + int m = N; + int digit = 0; + while (m) + { + digit++; + m /= 10; + } + char *arr; + char arr1[digit]; + arr = (char *)malloc(digit * sizeof(char)); + int index = 0; + while (N) + { + arr1[++index] = N % 10 + '0'; + N /= 10; + } + int i; + for (i = 0; i < index; i++) + { + arr[i] = arr1[index - i]; + } + arr[i] = '\0'; + return (char *)arr; +} + +int main(void) +{ + initializeTrailsAndCaptorMetadataTables(); + // createCaptorDataTable(1, 1); +} \ No newline at end of file diff --git a/Db-Script/database.h b/Db-Script/database.h new file mode 100644 index 0000000..1383f6a --- /dev/null +++ b/Db-Script/database.h @@ -0,0 +1,14 @@ +#include +#include +#include +#include + +// Duplication from simulFlux.c + +/** + * @brief convert an interger N into a char* + * + * @param N + * @return char* + */ +char *convertIntegerToChar(int N); \ No newline at end of file diff --git a/Db-Script/database.py b/Db-Script/database.py new file mode 100644 index 0000000..49069d7 --- /dev/null +++ b/Db-Script/database.py @@ -0,0 +1 @@ +##This mist include all fetch function and also init and insert function for nn training annd testing result \ No newline at end of file diff --git a/Db-Script/db b/Db-Script/db new file mode 100755 index 0000000..5e51ebf Binary files /dev/null and b/Db-Script/db differ diff --git a/Db-Script/robotgowest.db b/Db-Script/robotgowest.db new file mode 100644 index 0000000..e69de29