From 64a50327e74887b02d6aa5280c6c48c63f3fb948 Mon Sep 17 00:00:00 2001 From: "quentin.perret" Date: Tue, 14 Jun 2022 10:46:12 +0200 Subject: [PATCH] comment c code --- Code-C/average.h | 2 +- Code-C/b2hd.c | 2 ++ Code-C/fileGestion.c | 12 ++++++------ Code-C/getArray.c | 23 +++++++++++++++++++---- Code-C/main | Bin 24840 -> 24800 bytes Code-C/main.c | 2 +- Code-C/power.c | 17 ++++++++++++++++- Code-C/queue.c | 7 +++++-- Code-C/simulateFlux.c | 31 ++++++++++++++++++++++++++----- Code-C/simulateFlux.h | 2 +- 10 files changed, 77 insertions(+), 21 deletions(-) diff --git a/Code-C/average.h b/Code-C/average.h index 7ae6f90..b4bdf81 100644 --- a/Code-C/average.h +++ b/Code-C/average.h @@ -1,4 +1,4 @@ #include #include -bool average(char* rawDataFileName,int N , int M); \ No newline at end of file +void average(char* rawDataFileName,int N , int M); \ No newline at end of file diff --git a/Code-C/b2hd.c b/Code-C/b2hd.c index c6e5147..22ce3fe 100644 --- a/Code-C/b2hd.c +++ b/Code-C/b2hd.c @@ -43,6 +43,8 @@ void b2hd() } } } + + int main(int argc , char** argv){ b2hd(); } \ No newline at end of file diff --git a/Code-C/fileGestion.c b/Code-C/fileGestion.c index 1d1d73d..57aa3e9 100644 --- a/Code-C/fileGestion.c +++ b/Code-C/fileGestion.c @@ -21,18 +21,18 @@ void clearRawData(int nRow){ fclose(f); fclose(g); } /** - * @brief use to write the file powerData.csv that contaign all power calculous results + * @brief use to write one lign in the file "fileName" * - * @param powerArray - * @param nCol size of the power array, correspond to the number of captor used + * @param array array that contaign all the values to write in the file + * @param nCol size of the array (correspond to the number of captor used) */ -void writeDataInFile(char* fileName , double powerArray[], int nCol){ +void writeDataInFile(char* fileName , double array[], int nCol){ FILE *f = fopen(fileName,"a+"); for(int i = 0 ; i < nCol ; i++){ if( i < nCol-1){ - fprintf(f, "%f , ", powerArray[i]); + fprintf(f, "%f , ", array[i]); } else { - fprintf(f, "%f\n", powerArray[i]); + fprintf(f, "%f\n", array[i]); } } fclose(f); diff --git a/Code-C/getArray.c b/Code-C/getArray.c index 9b78b07..dd3f1fe 100644 --- a/Code-C/getArray.c +++ b/Code-C/getArray.c @@ -49,10 +49,11 @@ void printArrayData(long** p, int N, int M) { /** * @brief verify if all the element of an array are not NULL, return * - * @param p - * @param N - * @param M - * @return int + * @param p array to check + * @param N number of rows in p + * @param M number of columns in p + * @return true if the array contaign no NULL element + * @return false if at least one element is null */ bool checkArrayFullyFill(long **p, int N , int M){ for(int i = 0 ; i < N ; i++){ @@ -61,6 +62,12 @@ bool checkArrayFullyFill(long **p, int N , int M){ return true; } +/** + * @brief free memory allocate to an array p + * + * @param p array to free memory + * @param N number of rows in array + */ void freeArray(long **p, int N) { int i; for(i = 0 ; i < N ; i++) @@ -68,6 +75,14 @@ void freeArray(long **p, int N) { free(p); } +/** + * @brief Get the Raw Data Array object + * + * @param rawDataFileName name of the file to use to file the array + * @param N numbers of rows to have i the array + * @param M numbers of columns to have i the array + * @return long** the array fill with raw data + */ long **getRawDataArray(char* rawDataFileName , int N , int M){ long **p; p = get(N, M); diff --git a/Code-C/main b/Code-C/main index 45755a38c8213233c34a258d84a084c5e99a0d7a..69213d78d46a50620a794cc57b661390d41c589d 100755 GIT binary patch delta 4729 zcmZ`-3sjU<9=~^R_ntHNckliG{*U|m zf8RGRf6krFygo$F1~Iivl)y?G;&=L%`O98e!*@x(Bg158q(jdS^WZz7`tcWcE%|b8 z#Z7xPP^j78BfuS7oHQQ-9k=W$fvW!$8#=aJN) zJfX5%^gfHp8BlEfSVdggm#8yef2wFJoS;{Jvbn z7I@@>zggAq$6oM^Nxp`a({&%C$?2JV>omb-%tr#-N|C-cg!rMa(G=ww6R@>FcC>(K z#}B@L);Nk2-}KrOc!O7GFt)f}iWwVqCD(fDF~xdTsXgC0b56cp>t|w2u@C$pL_qo( zBV%sE-gL%p>de{d(5OrS+5`dPx|bUin|34QN?p@(U$;|dt`W8mdk`kL%1^x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`K)K{mi**5uUUgsAF-G$$M(OC=*+fWSWjD!kZUoQ_hkk!&Z&Dl^$M_W^ijW zHyv7%cJrcmFH9S;rS&Lso0le$YiSU*FP(DpFFoG#olI<5k|7W8Io|S|8OwZiI*Czk e#jm&_IhARnHfT8+;YW{GPBYXk6r#Qe()K@xpfnl) diff --git a/Code-C/main.c b/Code-C/main.c index de1b7eb..9957208 100644 --- a/Code-C/main.c +++ b/Code-C/main.c @@ -71,7 +71,7 @@ int main(int argc , char** argv){ firstRawDataQueue = queueCreateEmpty(); // change this for create empty pthread_t rawData; - pthread_create(&rawData , NULL, simulateFlux, (void *)&rawData); + pthread_create(&rawData , NULL, threadSimulateFlux, (void *)&rawData); pthread_t calcul; pthread_create(&calcul , NULL, threadCalculBoth, (void *)&calcul); diff --git a/Code-C/power.c b/Code-C/power.c index 6d836e6..df99179 100644 --- a/Code-C/power.c +++ b/Code-C/power.c @@ -3,8 +3,15 @@ #include "fileGestion.h" #include "initialParameters.h" #include "queue.h" -#include +/** + * @brief realize the power calcul + * + * @param p array with all the values that will be used for the calcul + * @param powerArray array where results are stocked + * @param N number of rows in p + * @param M number of columns in p + */ void powerCalculation(long **p, double powerArray[] , int N, int M , double period , double invTimeBandwidth){ for(int i = 0; i < M-1; i++){ int j = 0; @@ -19,6 +26,14 @@ void powerCalculation(long **p, double powerArray[] , int N, int M , double peri //printf("%f\n", powerArray[i]); } } + +/** + * @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 + */ bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth){ long **p = getRawDataArray(rawDataFileName,N, M); double pw[8]; diff --git a/Code-C/queue.c b/Code-C/queue.c index 432807e..6bcf99c 100644 --- a/Code-C/queue.c +++ b/Code-C/queue.c @@ -148,7 +148,6 @@ 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) - * @return Pqueue the second element after remove first */ void queueRmFrstE(Pqueue elem){ assert(elem); @@ -175,7 +174,6 @@ Pqueue queueNextDelFrst(Pqueue elem){ * @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 - * @return Pqueue pointer to the last element */ void queueAddLastQ(Pqueue elem, const char* str, int len){ assert(elem); @@ -206,6 +204,11 @@ void queuePrintE(Pqueue elem){ } } +/** + * @brief Print all the element starting from @param firstE till the end of the linked list + * + * @param firstE + */ void queuePrintWholeQ(Pqueue firstE){ queuePrintE(firstE); Pqueue elem = firstE; diff --git a/Code-C/simulateFlux.c b/Code-C/simulateFlux.c index 92935c9..3066bf3 100644 --- a/Code-C/simulateFlux.c +++ b/Code-C/simulateFlux.c @@ -2,7 +2,12 @@ #include "initialParameters.h" #include "queue.h" - +/** + * @brief convert an interger N into a char* + * + * @param N + * @return char* + */ char* convertIntegerToChar(int N) { // Count digits in number N @@ -28,6 +33,11 @@ char* convertIntegerToChar(int N) return (char*)arr; } +/** + * @brief Create a New Raw Data File Name + * + * @return char* + */ char *createNewRawDataFileName(){ char *fileName = "../RawDataFiles/RawData"; char *extension = ".csv\0"; @@ -58,13 +68,25 @@ int maxInArray(int *array , int N){ } return max; } - +/** + * @brief return the unix time in millisecond + * + * @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; } + +/** + * @brief write one lign of rawData in the file @param rawDataFile (simulate of freq of the Vegetal Signals Captor) + * + * @param rawDataFile + * @return true if the lign is correctly write , else : + * @return false + */ bool writeOneRawData(FILE *rawDataFile){ char buff[26]; char buff2[18]; @@ -105,7 +127,7 @@ bool writeOneRawData(FILE *rawDataFile){ } } cptData++; - sleep(0.004); //simul la freq ech + //sleep(0.004); //simul freq here return true; } else { @@ -113,7 +135,7 @@ bool writeOneRawData(FILE *rawDataFile){ } } -void *simulateFlux(void *vargp){ +void *threadSimulateFlux(void *vargp){ char *fileName = createNewRawDataFileName(); FILE *rawDataFile = fopen(fileName,"w+"); @@ -130,6 +152,5 @@ void *simulateFlux(void *vargp){ FILE *rawDataFile = fopen(fileName,"w+"); } } - //queuePrintWholeQ(firstRawDataQueue); rawDataWriteFlag = false; } diff --git a/Code-C/simulateFlux.h b/Code-C/simulateFlux.h index de271bd..ea865bf 100644 --- a/Code-C/simulateFlux.h +++ b/Code-C/simulateFlux.h @@ -18,4 +18,4 @@ extern int cptFile; char *convertIntegerToChar(int N); bool writeOneRawData(FILE *f); -void *simulateFlux(void *vargp); \ No newline at end of file +void *threadSimulateFlux(void *vargp); \ No newline at end of file