From ade5b4378fe171745184d90b9dd63c199be09ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Gauthier?= Date: Tue, 21 Jun 2022 15:13:10 +0200 Subject: [PATCH] CMakelists add few test queue --- .gitignore | 5 +- .vscode/settings.json | 3 +- Code-C/CMakeLists.txt | 23 ++++- Code-C/b2hd.c | 19 ++++- Code-C/b2hd.h | 16 ++-- Code-C/ctest.c | 184 ++++++++++++++++++++++++++++++++++++++++ Code-C/main | Bin 46784 -> 0 bytes Code-C/main.c | 105 ++++++++++++++--------- Code-C/power.c | 44 ++++++---- Code-C/queue.c | 155 ++++++++++++++++++++------------- Code-C/queue.h | 121 +++++++++++++++++++++++--- Code-C/simulateFlux.c | 193 ++++++++++++++++++++++++------------------ Code-C/simulateFlux.h | 1 + Code-C/test.c | 46 ---------- 14 files changed, 641 insertions(+), 274 deletions(-) create mode 100644 Code-C/ctest.c delete mode 100755 Code-C/main delete mode 100644 Code-C/test.c diff --git a/.gitignore b/.gitignore index 22d5774..2a3e17d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,10 @@ *.csv Code-C/main -Code-C/exec +Code-C/exect +Code-C/ctest +Code-C/DartConfiguration.tcl + Makefile # Created by https://www.toptal.com/developers/gitignore/api/cmake,c diff --git a/.vscode/settings.json b/.vscode/settings.json index 5c64e94..332f5c0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,6 +15,7 @@ "*.tcc": "c", "type_traits": "c", "simulateflux.h": "c", - "pthread.h": "c" + "pthread.h": "c", + "types.h": "c" } } \ No newline at end of file diff --git a/Code-C/CMakeLists.txt b/Code-C/CMakeLists.txt index 3511d88..ee0dd0f 100644 --- a/Code-C/CMakeLists.txt +++ b/Code-C/CMakeLists.txt @@ -3,8 +3,25 @@ project(Traitement-signal-plantes C) include(CTest) enable_testing() - set(CMAKE_C_FLAGS "-std=c99 -g -Wall") + add_executable(exect fileGestion.c getArray.c average.c growthRate.c power.c queue.c simulateFlux.c main.c) -#add_executable(exect main.c simulateFlux.c queue.c power.c growthRate.c average.c getArray.c fileGestion.c) - \ No newline at end of file + +# add_executable(exect main.c simulateFlux.c queue.c power.c growthRate.c average.c getArray.c fileGestion.c) +find_package(Threads) +target_link_libraries(exect ${CMAKE_THREAD_LIBS_INIT} m) + +set(CTEST_MEMORYCHECK_TYPE "AddressSanitizer") +set(CTEST_MEMORYCHECK_SANITIZER_OPTIONS "verbosity=1:symbolize=1:abort_on_error=1:detect_leaks=1") + +add_executable(ctest fileGestion.c getArray.c average.c growthRate.c queue.c simulateFlux.c ctest.c) +target_link_libraries(ctest ${CMAKE_THREAD_LIBS_INIT} m) + +add_test(test_queueCreateEmpty ./ctest queueCreateEmpty) +add_test(test_queueSetCharLen ./ctest queueSetCharLen) + +# add_test(test_queueGetTabChar ./ctest queueGetTabChar) +add_test(test_queueSetNextE ./ctest queueSetNextE) +add_test(test_queueGetNextE ./ctest queueGetNextE) + +add_test(test_queueGetCharLen ./ctest queueGetCharLen) \ No newline at end of file diff --git a/Code-C/b2hd.c b/Code-C/b2hd.c index 22ce3fe..2de322a 100644 --- a/Code-C/b2hd.c +++ b/Code-C/b2hd.c @@ -1,4 +1,20 @@ #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); + + //#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 * @@ -14,7 +30,7 @@ void b2hd() quartet value; while (fread(&buff, 26, 1, stdin)) { - fprintf(stdout , "%d,", millis()); + fprintf(stdout , "%ld,", millis()); for (int i = 1; i < 9; i++){ /*buff[25] = '\0';*/ if (strncmp(buff, "#################\n", (size_t)18) == 0) { @@ -44,7 +60,6 @@ void b2hd() } } - int main(int argc , char** argv){ b2hd(); } \ No newline at end of file diff --git a/Code-C/b2hd.h b/Code-C/b2hd.h index 5479d31..92a33d4 100644 --- a/Code-C/b2hd.h +++ b/Code-C/b2hd.h @@ -2,23 +2,19 @@ #include #include #include -#include +//#include +#define __USE_ISOC11 1 +#include #include /** * @brief struct used to stock binary 32 bits data from the captor - * + * */ -typedef struct { +typedef struct +{ uint8_t octet1; uint8_t octet2; uint8_t octet3; uint8_t octet4; } quartet; - -int64_t millis() -{ - struct timespec now; - timespec_get(&now, TIME_UTC); - return ((int64_t) now.tv_sec) * 1000 + ((int64_t) now.tv_nsec) / 1000000; -} diff --git a/Code-C/ctest.c b/Code-C/ctest.c new file mode 100644 index 0000000..1cffdd3 --- /dev/null +++ b/Code-C/ctest.c @@ -0,0 +1,184 @@ +#define __USE_GNU +#include +#include +#include +#include +#include + +#include "fileGestion.h" +#include "getArray.h" +#include "growthRate.h" +#include "power.c" +#include "simulateFlux.h" +#include "queue.h" +#include "average.h" +//#include "b2hd.h" + +bool rawDataWriteFlag; +int nRowRawData = 500; +int nRowGR = 150; +int nCol = 1; +double freqEch = 250; + +int nbRowBinFile = 900011; +int nbRowIgnore = 19; + +Pqueue firstRawDataQueue; +// Captor 1 2 3 4 5 6 7 8 +bool selectionCaptors[] = {true, false, true, false, false, false, true, false}; + +int cptData = 0; +int cptFile = 1; +int cptValue = 0; + +double period = 0; +double invTimeBandWidth = 0; + +bool test_queueCreateEmpty() +{ + Pqueue new = queueCreateEmpty(); + + assert(queueGetCharLen(new) == 0); + assert(queueGetTabChar(new) == NULL); + assert(queueGetNextE(new) == NULL); + + // queueDelAll(new); + queueRmFrstE(new); + + return EXIT_SUCCESS; +} + +bool test_queueSetCharLen() +{ + Pqueue new = queueCreateEmpty(); + + queueSetCharLen(new, 13); + + assert(queueGetCharLen(new) == 13); + assert(queueGetTabChar(new) == NULL); + assert(queueGetNextE(new) == NULL); + + // queueDelAll(new); + queueRmFrstE(new); + return EXIT_SUCCESS; +} + +bool test_queueGetTabChar() +{ // Define later + Pqueue new = queueCreateEmpty(); + + // const char tabChar[12] = "PetitNavire\0" + queueSetTabChar(new, 13, NULL); + + assert(queueGetCharLen(new) == 13); + assert(queueGetTabChar(new) == NULL); + assert(queueGetNextE(new) == NULL); + + // queueDelAll(new); + queueRmFrstE(new); + + return EXIT_SUCCESS; +} + +bool test_queueSetNextE() +{ + Pqueue new = queueCreateEmpty(), next = queueCreateEmpty(); + + queueSetNextE(new, next); + + assert(queueGetNextE(new) == next); + assert(queueGetNextE(next) == NULL); + + queueDelAll(new); + return EXIT_SUCCESS; +} + +bool test_queueGetNextE() +{ + Pqueue new = queueCreateEmpty(), next = queueCreateEmpty(); + + queueSetNextE(new, next); + + assert(queueGetNextE(new) == next); + assert(queueGetNextE(next) == NULL); + + queueDelAll(new); + return EXIT_SUCCESS; +} + +bool test_queueGetCharLen() +{ + Pqueue new = queueCreateEmpty(); + + assert(queueGetCharLen(new) == 0); + + queueSetCharLen(new, 13); + + assert(queueGetCharLen(new) == 13); + + queueDelAll(new); + return EXIT_SUCCESS; +} + +void usage(int argc, char *argv[]) +{ + fprintf(stderr, "Usage: %s [<...>]\n", argv[0]); + exit(EXIT_FAILURE); +} + +int main(int argc, char *argv[]) +{ + if (argc == 1) + usage(argc, argv); + + // start test + fprintf(stderr, "=> Start test \"%s\"\n", argv[1]); + int ok = 1; + if (strcmp("queueCreateEmpty", argv[1]) == 0) + ok = test_queueCreateEmpty(); + else if (strcmp("queueSetCharLen", argv[1]) == 0) + { + ok = test_queueSetCharLen(); + } + else if (strcmp("queueGetTabChar", argv[1]) == 0) + { + ok = test_queueGetTabChar(); + } + else if (strcmp("queueSetNextE", argv[1]) == 0) + { + ok = test_queueSetNextE(); + } + else if (strcmp("queueGetNextE", argv[1]) == 0) + { + ok = test_queueGetNextE(); + } + else if (strcmp("queueGetCharLen", argv[1]) == 0) + { + ok = test_queueGetCharLen(); + } + else if (strcmp("queueGetTabChar", argv[1]) == 0) + { + ok = test_queueGetTabChar(); + // }else if(strcmp("update_flags",argv[1]) == 0){ + // ok = test_game_update_flags(); + // }else if(strcmp("default_solution",argv[1]) == 0){ + // ok = test_game_default_solution(); + } + else + { + fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); + exit(EXIT_FAILURE); + } + + // print test result + if (ok == 0) + { + fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]); + return EXIT_SUCCESS; + } + else + { + fprintf(stderr, "Test \"%s\" finished: FAILURE\n", argv[1]); + return EXIT_FAILURE; + } +} \ No newline at end of file diff --git a/Code-C/main b/Code-C/main deleted file mode 100755 index e87cfdbeb8ec346c128f09a750fee30663244d1b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 46784 zcmeHwdwi6|x&Qm_W;Smwd&vz5*X1S`AqfZ=5HtY-8w89<1QgvY$>t)tnQXXN5Ng1( zCt{NxYq39CX={75r&d~z9tySwwSd}Myr-=_rIxmv!m&B1Ep4s&eV@6!`|f5}?Kz)w z`Gc1aJM&!UnP+C6nRn)W-|Q+|xy+{Pn!4=T)f$Jg1*Sw1zO6EvR-zSa8Tg&3P0$=b zr{I5yB*&-qHbGFSA^Ge`N$z1uk55NSK9wp9DJ8jNSAC|Ss8sU^nB*8`B^;mb9547( zs_15UC4wGb(TCFoUZqw!^3ADLf`00j*tC%xfa|nOl^nT)mf&We$q?1eT^(HnO};f{VJ8k zYlV#so94|aY^<5t*wEauZRWP(c{AtDDQIsgn9b{*3q#12%U4%wI~Kl~nSN7W*{esc z`{6rZ^f$Ep;W8W9O*W7|;-QQ9l{+av9{-8X>!p81+YK_|Cg49^F9%<0s;vxo=3nSi z-BJ)NzYCy14jl_t(>ehq!mmhz|5OtEOG)tUN$^x3FaF10wLm1Y=UNY0(67demDU9yOUu_v0s^bz*4q+a6^GaS)_P2)uZ6Uv3uqI?|ZP}`|hU(jbff|1` zenUYM3~p-(Y3-r5>elUAZA)vgnSkc%rdE*x+u9MT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Zc>l6w}CFV+r{yQWl&ShFn7rDCzqn#mPWL-dsueVn}&K6eXBhfJ04@sJcjI?s~vLd zNt!zI@cTElx69TUa{NF&K%5j?t>e4y@~ot`1;@`rTLzsZ{)|kXakT~Mk5a`*Bs^FO zgjyP6xXAJNyIL_g3N?XPH^!d^)$)-UBjxuaUdc#qp2_ftrY7^4c&2*2>S{?3tT-c8 zTm9iFirVs!E5T8&-(S5gK#@Msh-2Uw3%Mp47Wkjs5+_zMJaNayL!JZB3fi|fg#w$9 zhT240uW~s13AVLr1I3cdT0zbBX6O?s z9+BV_9P99-KP%t|tu5FXAOV?cZ47Azyz>_zTTs^mFhpmq1+?M;QwtB!1;Ki`#;LD? z5(NoSvDgt3DvuHZO%2tsr6oj~VH^ee0(5Bn8LyTmdTs%@;HHi`hyikZn zhooYX$1b#4zLLKeIPwYE$1hK8N;1|fzWu`>TIIb`UZtnw93H1$&>* zSJ|Lom3}F%e6@d}(%a*Xwp95_-`C>g)j6a}(-fmjyE2={<4&i!cA_IC*vcsnUJQv7&gh{UxY9j|`o`$YExllb%{7IFz3izk*dt z=UQ%yygIi#{R!oN1z9yVs0?-P+9&0eV^lR%xyp|RAVV%v_N(*RzUxREKA$BL^H<5M z^!K1x<+UowS|QSl5>$zjQ|Y@PSmo6|>qRNA_BZ3@75rypNSCs|Bp@hrt{3Tgk(j?; zGbb`1BBAn&;_ym-N*tbe=~8JbGAb`9;`e4*{_Z$p9H`M(J>zkt;pc0Fp84ZNs(#~n zCnS;24GD=KDMw2M@$yAU #include "power.h" #include "getArray.h" #include "fileGestion.h" @@ -6,43 +7,50 @@ /** * @brief realize the powerThreadFunction calcul - * + * * @param p array with all the values that will be used for the calcul * @param powerArray array where results are stocked */ -void powerCalculation(long **p, double powerArray[]){ - for(int i = 0; i < nCol; i++){ +void powerCalculation(long **p, double powerArray[]) +{ + for (int i = 0; i < nCol; i++) + { int j = 0; powerArray[i] = 0; - while(j < nRowRawData){ - powerArray[i] += pow(p[j][i+1],2); + while (j < nRowRawData) + { + powerArray[i] += pow(p[j][i + 1], 2); j++; } powerArray[i] /= nRowRawData; } - } /** * @brief function that realize all the action to write one lign in the file powerData.csv - * + * * @param rawDataFileName name of the raw data file to use to realize the calcul * @param N number of rows in the file * @param M number of columns in the file */ -void powerFunction(char* rawDataFileName, double **pw){ +void powerFunction(char *rawDataFileName, double **pw) +{ long **p = getRawDataArray(rawDataFileName); - printArrayData(p,nRow,nCol); - double pww[nCol-1]; - if(p !=NULL){ - if(pw == NULL){ - powerCalculation(p,pww); - appendDataInFile("powerData.csv",pww,nCol-1); - }else{ - powerCalculation(p,pw[1]); - appendDataInFile("powerData.csv",pw[1],nCol-1); + printArrayData(p, nRowRawData, nCol); + double pww[nCol - 1]; + if (p != NULL) + { + if (pw == NULL) + { + powerCalculation(p, pww); + appendDataInFile("powerData.csv", pww, nCol - 1); } - freeArray(p,nRowRawData); + else + { + powerCalculation(p, pw[1]); + appendDataInFile("powerData.csv", pw[1], nCol - 1); + } + freeArray(p, nRowRawData); } } \ No newline at end of file diff --git a/Code-C/queue.c b/Code-C/queue.c index 6bcf99c..c44378e 100644 --- a/Code-C/queue.c +++ b/Code-C/queue.c @@ -5,27 +5,29 @@ #include "queue.h" /** - * @brief struct queue struct used for queueing string name - * + * @brief struct queue struct used for queueing string name + * * @param charLen lenght of tabChar pointeur * @param tabChar char array pointer - * @param pNextE point next element + * @param pNextE point next element */ -struct queue { +struct queue +{ int charLen; - char* tabChar; - Pqueue pNextE; + char *tabChar; + Pqueue pNextE; }; typedef struct queue *Pqueue; /** * @brief create an empty element of queue - * - * @return Pqueue + * + * @return Pqueue */ -Pqueue queueCreateEmpty(){ - Pqueue new = (Pqueue) malloc(sizeof(struct queue)); +Pqueue queueCreateEmpty() +{ + Pqueue new = (Pqueue)malloc(sizeof(struct queue)); assert(new); new->charLen = 0; new->tabChar = NULL; @@ -33,92 +35,100 @@ Pqueue queueCreateEmpty(){ return new; } - /************ SETTER ************/ +/************ SETTER ************/ /** * @brief set char size array - * + * * @param elem targeted element * @param _charLen size of char array */ -void queueSetCharLen(Pqueue elem, int _charLen){ +void queueSetCharLen(Pqueue elem, int _charLen) +{ assert(elem); elem->charLen = _charLen; } /** * @brief set the char array in the element - * + * * @param elem targeted element * @param _charLen char array size * @param _tabChar pointer to static char array */ -void queueSetTabChar(Pqueue elem, int _charLen, const char *_tabChar){ +void queueSetTabChar(Pqueue elem, int _charLen, const char *_tabChar) +{ assert(elem); assert(_tabChar); elem->charLen = _charLen; - elem->tabChar = calloc(_charLen , sizeof(char)); - for(int i = 0; i < _charLen; i++){ + elem->tabChar = calloc(_charLen, sizeof(char)); + for (int i = 0; i < _charLen; i++) + { elem->tabChar[i] = _tabChar[i]; } } /** * @brief set next pqueue element - * + * * @param elem target element * @param next next element */ -void queueSetNextE(Pqueue elem , Pqueue next){ +void queueSetNextE(Pqueue elem, Pqueue next) +{ assert(elem); assert(next); - elem -> pNextE = next; + elem->pNextE = next; } - /************ GETTER ************/ +/************ GETTER ************/ /** * @brief switch to the next element - * + * * @param elem current element * @return Pqueue next element */ -Pqueue queueGetNextE(Pqueue elem){ +Pqueue queueGetNextE(Pqueue elem) +{ assert(elem); return elem->pNextE; } /** * @brief get the size char array - * + * * @param elem targeted element - * @return int + * @return int */ -int queueGetCharLen(Pqueue elem){ +int queueGetCharLen(Pqueue elem) +{ assert(elem); return elem->charLen; } /** * @brief get the pointer of char array - * + * * @param elem targeted elemnt - * @return char* + * @return char* */ -char * queueGetTabChar(Pqueue elem){ +char *queueGetTabChar(Pqueue elem) +{ assert(elem); return elem->tabChar; } - /************ ************/ +/************ ************/ /** * @brief Create Element of queue - * - * @param lenChar size of char array that will be created + * + * @param lenChar size of char array that will be created * @return Pqueue new element created */ -Pqueue queueCreateE(int lenChar, const char* _tabChar){ - Pqueue new = (Pqueue) malloc(sizeof(struct queue)); +Pqueue queueCreateE(int lenChar, const char *_tabChar) +{ + Pqueue new = (Pqueue)malloc(sizeof(struct queue)); assert(new); queueSetTabChar(new, lenChar, _tabChar); new->pNextE = NULL; @@ -127,14 +137,16 @@ Pqueue queueCreateE(int lenChar, const char* _tabChar){ /** * @brief remove and free the last element of queue - * + * * @param elem current element * @return Pqueue current element */ -Pqueue queueRmLastE(Pqueue elem){ +Pqueue queueRmLastE(Pqueue elem) +{ assert(elem); Pqueue tmp = elem, previous = NULL; - while(elem->pNextE != NULL){ + while (elem->pNextE != NULL) + { previous = tmp; tmp = queueGetNextE(tmp); } @@ -146,22 +158,27 @@ Pqueue queueRmLastE(Pqueue elem){ /** * @brief remove and free the first element of queue - * + * * @param elem target to remove (the element need to be the first) */ -void queueRmFrstE(Pqueue elem){ +void queueRmFrstE(Pqueue elem) +{ assert(elem); - free(elem->tabChar); + if (elem->tabChar != NULL) + { + free(elem->tabChar); + } free(elem); } /** * @brief delete the first value and return the next value - * - * @param elem - * @return Pqueue + * + * @param elem + * @return Pqueue */ -Pqueue queueNextDelFrst(Pqueue elem){ +Pqueue queueNextDelFrst(Pqueue elem) +{ assert(elem); Pqueue tmp = elem->pNextE; queueRmFrstE(elem); @@ -169,52 +186,70 @@ Pqueue queueNextDelFrst(Pqueue elem){ } /** - * @brief add in the end of queue element with string parameter - * + * @brief add in the end of queue element with string parameter + * * @param elem Pqueue will be added at the end of queue * @param str the string will be bind at the element * @param len the lenght of char array */ -void queueAddLastQ(Pqueue elem, const char* str, int len){ +void queueAddLastQ(Pqueue elem, const char *str, int len) +{ assert(elem); assert(str); Pqueue next = elem, previous = NULL; - while(next->pNextE != NULL){ + while (next->pNextE != NULL) + { previous = next; next = queueGetNextE(next); } previous = next; - next = queueCreateE(len,str); - queueSetNextE(previous,next); + next = queueCreateE(len, str); + queueSetNextE(previous, next); } /** * @brief Print targeted element - * + * * @param elem targeted element */ -void queuePrintE(Pqueue elem){ +void queuePrintE(Pqueue elem) +{ Pqueue next = queueGetNextE(elem); - printf("\nFile Name : %s \n(size of the file name : %d)\n",elem -> tabChar , elem -> charLen ); - if(next != NULL){ - printf("Next File : %s\n", next ->tabChar); + printf("\nFile Name : %s \n(size of the file name : %d)\n", elem->tabChar, elem->charLen); + if (next != NULL) + { + printf("Next File : %s\n", next->tabChar); } - else{ + else + { printf("No nextFile existing (null)\n"); } } /** * @brief Print all the element starting from @param firstE till the end of the linked list - * - * @param firstE + * + * @param firstE */ -void queuePrintWholeQ(Pqueue firstE){ +void queuePrintWholeQ(Pqueue firstE) +{ queuePrintE(firstE); Pqueue elem = firstE; - while(queueGetNextE(elem) != NULL){ + while (queueGetNextE(elem) != NULL) + { elem = queueGetNextE(elem); queuePrintE(elem); } } +void queueDelAll(Pqueue elem) +{ + assert(elem); + Pqueue condemned = elem, tmp; + while (condemned != NULL) + { + tmp = queueGetNextE(condemned); + queueRmFrstE(condemned); + condemned = tmp; + } +} diff --git a/Code-C/queue.h b/Code-C/queue.h index c2ec7a5..156d3f0 100644 --- a/Code-C/queue.h +++ b/Code-C/queue.h @@ -1,27 +1,126 @@ typedef struct queue *Pqueue; -//Constructors -Pqueue queueCreateE(int lenChar, const char* _tabChar); -Pqueue queueCreateEmpty(); +/** + * @brief Create Element of queue + * + * @param lenChar size of char array that will be created + * @return Pqueue new element created + */ +Pqueue queueCreateE(int lenChar, const char *_tabChar); +/** + * @brief create an empty element of queue + * + * @return Pqueue + */ +Pqueue queueCreateEmpty(); -//Getters +/************** Getters **************/ + +/** + * @brief switch to the next element + * + * @param elem current element + * @return Pqueue next element + */ Pqueue queueGetNextE(Pqueue elem); + +/** + * @brief get the size char array + * + * @param elem targeted element + * @return int + */ int queueGetCharLen(Pqueue elem); -char* queueGetTabChar(Pqueue elem); -//Setters +/** + * @brief get the pointer of char array + * + * @param elem targeted elemnt + * @return char* + */ +char *queueGetTabChar(Pqueue elem); + +/************** Setters **************/ + +/** + * @brief set char size array + * + * @param elem targeted element + * @param _charLen size of char array + */ void queueSetCharLen(Pqueue elem, int _charLen); + +/** + * @brief set the char array in the element + * + * @param elem targeted element + * @param _charLen char array size + * @param _tabChar pointer to static char array + */ void queueSetTabChar(Pqueue elem, int _charLen, const char *_tabChar); -void queueSetNextE(Pqueue elem , Pqueue next); -void queueAddLastQ(Pqueue elem, const char* str, int len); +/** + * @brief set next pqueue element + * + * @param elem target element + * @param next next element + */ +void queueSetNextE(Pqueue elem, Pqueue next); -//Removers +/** + * @brief add in the end of queue element with string parameter + * + * @param elem Pqueue will be added at the end of queue + * @param str the string will be bind at the element + * @param len the lenght of char array + */ +void queueAddLastQ(Pqueue elem, const char *str, int len); + +/************** Removers **************/ + +/** + * @brief remove and free the last element of queue + * + * @param elem current element + * @return Pqueue current element + */ Pqueue queueRmLastE(Pqueue elem); + +/** + * @brief remove and free the first element of queue + * + * @param elem target to remove (the element need to be the first) + */ void queueRmFrstE(Pqueue elem); + +/** + * @brief delete the first value and return the next value + * + * @param elem + * @return Pqueue + */ Pqueue queueNextDelFrst(Pqueue elem); -//print function +/************** print function **************/ + +/** + * @brief Print targeted element + * + * @param elem targeted element + */ void queuePrintE(Pqueue elem); -void queuePrintWholeQ(Pqueue firstE); \ No newline at end of file + +/** + * @brief Print all the element starting from @param firstE till the end of the linked list + * + * @param firstE + */ +void queuePrintWholeQ(Pqueue firstE); + +/** + * @brief free all queue list + * + * @param elem the first element of comdemned queue + */ +void queueDelAll(Pqueue elem); \ No newline at end of file diff --git a/Code-C/simulateFlux.c b/Code-C/simulateFlux.c index e19d0a5..460dd7b 100644 --- a/Code-C/simulateFlux.c +++ b/Code-C/simulateFlux.c @@ -1,93 +1,109 @@ #include "simulateFlux.h" #include "initialParameters.h" #include "queue.h" +//#include + +#include "time.h" /** * @brief convert an interger N into a char* - * - * @param N - * @return char* + * + * @param N + * @return char* */ -char* convertIntegerToChar(int N) +char *convertIntegerToChar(int N) { // Count digits in number N int m = N; int digit = 0; - while (m) { + while (m) + { digit++; m /= 10; } - char* arr; + char *arr; char arr1[digit]; - arr = (char*)malloc(digit*sizeof(char)); + arr = (char *)malloc(digit * sizeof(char)); int index = 0; - while (N) { + while (N) + { arr1[++index] = N % 10 + '0'; N /= 10; } int i; - for (i = 0; i < index; i++) { + for (i = 0; i < index; i++) + { arr[i] = arr1[index - i]; } arr[i] = '\0'; - return (char*)arr; + return (char *)arr; } /** - * @brief Create a New Raw Data File Name - * - * @return char* + * @brief Create a New Raw Data File Name + * + * @return char* */ -char *createNewRawDataFileName(){ - char *fileName = "../RawDataFiles/RawData"; +char *createNewRawDataFileName() +{ + char *fileName = "../RawDataFiles/RawData"; char *extension = ".csv\0"; char *fileNumber = convertIntegerToChar(cptFile); - //char *fileNumber; - //sprintf(fileNumber, "%d", cptFile); - //printf("%s\n" , fileNumber); + // char *fileNumber; + // sprintf(fileNumber, "%d", cptFile); + // printf("%s\n" , fileNumber); - char fileNameNumber[strlen(fileName)+strlen(fileNumber)]; - char *fullFileName = malloc((strlen(fileNameNumber)+strlen(extension)) * sizeof(char*)); + char fileNameNumber[strlen(fileName) + strlen(fileNumber)]; + char *fullFileName = malloc((strlen(fileNameNumber) + strlen(extension)) * sizeof(char *)); - strcpy( fileNameNumber, fileName ); - strcat( fileNameNumber, fileNumber ); + strcpy(fileNameNumber, fileName); + strcat(fileNameNumber, fileNumber); + + strcpy(fullFileName, fileNameNumber); + strcat(fullFileName, extension); - strcpy( fullFileName, fileNameNumber ); - strcat( fullFileName, extension ); - return fullFileName; } -int intInArray(int number , int *array , int N){ - for(int i = 0 ; i < N ; i++){ - if(array[i] == number) return 0; +int intInArray(int number, int *array, int N) +{ + for (int i = 0; i < N; i++) + { + if (array[i] == number) + return 0; } return -1; } -int maxInArray(int *array , int N){ - int max = 0; - for(int i = 0 ; i < N ; i++){ - if(array[i]>max) max = array[i]; +int maxInArray(int *array, int N) +{ + int max = 0; + for (int i = 0; i < N; i++) + { + if (array[i] > max) + max = array[i]; } return max; } /** * @brief return the unix time in millisecond - * - * @return int64_t + * + * @return int64_t */ + int64_t millis() { struct timespec now; timespec_get(&now, TIME_UTC); - return ((int64_t) now.tv_sec) * 1000 + ((int64_t) now.tv_nsec) / 1000000; + return ((int64_t)now.tv_sec) * 1000 + ((int64_t)now.tv_nsec) / 1000000; } - -int lastIndexCaptor(){ +int lastIndexCaptor() +{ int lastIndex = 0; - for(int i = 1 ; i < 8 ; i++){ - if(selectionCaptors[i]){ + for (int i = 1; i < 8; i++) + { + if (selectionCaptors[i]) + { lastIndex = i; } } @@ -96,82 +112,97 @@ int lastIndexCaptor(){ /** * @brief write one lign of rawData in the file @param rawDataFile (simulate of freq of the Vegetal Signals Captor) - * - * @param rawDataFile + * + * @param rawDataFile * @return true if the lign is correctly write , else : - * @return false + * @return false */ -bool writeOneRawData(FILE *rawDataFile){ +bool writeOneRawData(FILE *rawDataFile) +{ char buff[26]; char buff2[18]; int32_t values[8]; uint32_t valbin[8]; quartet value; - if(fread(&buff, 26, 1, stdin)) { - //printf("%d\n",cptValue); - if(cptValue < nbRowBinFile - nbRowIgnore){ - FILE *timeFile = fopen("timeFile.csv" , "a+"); - fprintf(timeFile , "%ld\n", millis()); + if (fread(&buff, 26, 1, stdin)) + { + // printf("%d\n",cptValue); + if (cptValue < nbRowBinFile - nbRowIgnore) + { + FILE *timeFile = fopen("timeFile.csv", "a+"); + fprintf(timeFile, "%ld\n", millis()); fclose(timeFile); - fprintf(rawDataFile , "%ld,", millis()); - if (strncmp(buff, "#################\n", (size_t)18) == 0) { - if (!(fread(&buff2, 18, 1, stdin))) { + fprintf(rawDataFile, "%ld,", millis()); + if (strncmp(buff, "#################\n", (size_t)18) == 0) + { + if (!(fread(&buff2, 18, 1, stdin))) + { fprintf(stderr, "Erreur lecture après ###...#"); - } else { + } + else + { strncpy(buff, &buff[18], 8); strncpy(&buff[8], buff2, 18); } } int lastIndex = lastIndexCaptor(); - for (int i = 1; i < 9; i++){ - if(selectionCaptors[i-1]){ - value.octet1 = buff[3*i+1]; - value.octet2 = buff[3*i+2]; - value.octet3 = buff[3*i+3]; + for (int i = 1; i < 9; i++) + { + if (selectionCaptors[i - 1]) + { + value.octet1 = buff[3 * i + 1]; + value.octet2 = buff[3 * i + 2]; + value.octet3 = buff[3 * i + 3]; value.octet4 = 0; - - 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)); - FILE* allRawDataFile = fopen("AllRawData.csv" , "a+"); - if(i-1==lastIndex){ - fprintf(rawDataFile, "%d\n", values[i]/256); - fprintf(allRawDataFile, "%d\n", values[i]/256); + FILE *allRawDataFile = fopen("AllRawData.csv", "a+"); + if (i - 1 == lastIndex) + { + fprintf(rawDataFile, "%d\n", values[i] / 256); + fprintf(allRawDataFile, "%d\n", values[i] / 256); } - else{ - fprintf(rawDataFile, "%d,", values[i]/256); - fprintf(allRawDataFile, "%d,", values[i]/256); + else + { + fprintf(rawDataFile, "%d,", values[i] / 256); + fprintf(allRawDataFile, "%d,", values[i] / 256); } - fclose(allRawDataFile); + fclose(allRawDataFile); } } - cptData++; - //sleep(0.004); //simul freq here + cptData++; + // sleep(0.004); //simul freq here - cptValue++; - return true; - } - else { + cptValue++; + return true; + } + else + { return false; } } } -void *threadSimulateFlux(void *vargp){ +void *threadSimulateFlux(void *vargp) +{ char *fileName = createNewRawDataFileName(); - FILE *rawDataFile = fopen(fileName,"w+"); + FILE *rawDataFile = fopen(fileName, "w+"); - while(writeOneRawData(rawDataFile)){ - if(cptData == nRowRawData){ + while (writeOneRawData(rawDataFile)) + { + if (cptData == nRowRawData) + { fclose(rawDataFile); cptData = 0; cptFile++; - //create struct here - queueAddLastQ(firstRawDataQueue , fileName , strlen(fileName)); - //prepare next file now + // create struct here + queueAddLastQ(firstRawDataQueue, fileName, strlen(fileName)); + // prepare next file now fileName = createNewRawDataFileName(); - FILE *rawDataFile = fopen(fileName,"w+"); + FILE *rawDataFile = fopen(fileName, "w+"); } } rawDataWriteFlag = false; diff --git a/Code-C/simulateFlux.h b/Code-C/simulateFlux.h index ea865bf..36363f9 100644 --- a/Code-C/simulateFlux.h +++ b/Code-C/simulateFlux.h @@ -4,6 +4,7 @@ #include #include #include +#define __USE_ISOC11 1 #include typedef struct { diff --git a/Code-C/test.c b/Code-C/test.c deleted file mode 100644 index eaed558..0000000 --- a/Code-C/test.c +++ /dev/null @@ -1,46 +0,0 @@ - - - - -int main(int argc, char *argv[]){ - if (argc == 1) - usage(argc, argv); - - // start test - fprintf(stderr, "=> Start test \"%s\"\n", argv[1]); - int ok = 1; - if (strcmp("dummy", argv[1]) == 0) - ok = test_dummy(); - else if (strcmp("is_lighted",argv[1]) == 0){ - ok = test_game_is_lighted(); - }else if(strcmp("has_error",argv[1]) == 0){ - ok = test_game_has_error(); - }else if(strcmp("check_move",argv[1]) == 0){ - ok = test_game_check_move(); - }else if(strcmp("game_is_over",argv[1]) == 0){ - ok = test_game_is_over(); - }else if(strcmp("play_move",argv[1]) == 0){ - ok = test_game_play_move(); - }else if(strcmp("game_restart",argv[1]) == 0){ - ok = test_game_restart(); - }else if(strcmp("update_flags",argv[1]) == 0){ - ok = test_game_update_flags(); - }else if(strcmp("default_solution",argv[1]) == 0){ - ok = test_game_default_solution(); - }else{ - fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); - exit(EXIT_FAILURE); - } - - // print test result - if (ok == 0) - { - fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]); - return EXIT_SUCCESS; - } - else - { - fprintf(stderr, "Test \"%s\" finished: FAILURE\n", argv[1]); - return EXIT_FAILURE; - } -} \ No newline at end of file