diff --git a/Code-C/Makefile b/Code-C/Makefile index 6107882..0328aff 100644 --- a/Code-C/Makefile +++ b/Code-C/Makefile @@ -1,7 +1,4 @@ CC = gcc all: - $(CC) fileGestion.c getArray.c average.c power.c queue.c simulateFlux.c main.c -lm -lpthread -o main - -# $(CC) queue.c simulateFlux.c main.c -lm -lpthread -o main - ./main < ../02400031.TXT \ No newline at end of file + $(CC) -g fileGestion.c getArray.c average.c power.c queue.c simulateFlux.c main.c -lm -lpthread -o main \ No newline at end of file diff --git a/Code-C/average.c b/Code-C/average.c index 79dbf4a..dd83fe7 100644 --- a/Code-C/average.c +++ b/Code-C/average.c @@ -8,18 +8,16 @@ * * @param p array with all the values that will be used for the calcul * @param averageArray array where results are stocked - * @param N number of rows in p - * @param M number of columns in p */ -void averageCalculation(long **p, double averageArray[] , int N, int M){ - for(int i = 0; i < M-1; i++){ +void averageCalculation(long **p, double averageArray[]){ + for(int i = 0; i < nCol-1; i++){ int j = 0; averageArray[i] = 0; - while(j < N){ + while(j < nRow){ averageArray[i] += p[i][j]; j++; } - averageArray[i] /= N; + averageArray[i] /= nRow; //printf("%f\n", powerArray[i]); } } @@ -28,15 +26,13 @@ void averageCalculation(long **p, double averageArray[] , int N, int M){ * @brief function that realize all the action to write one lign in the file averageData.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 average(char* rawDataFileName,int N , int M){ - long **p = getRawDataArray(rawDataFileName,N, M); - double aver[8]; +void average(char* rawDataFileName){ + long **p = getRawDataArray(rawDataFileName); + double aver[nCol -1]; if(p !=NULL){ - averageCalculation(p,aver,N,M); - writeDataInFile("averageData.csv",aver,8); - freeArray(p,N); + averageCalculation(p,aver); + appendDataInFile("averageData.csv",aver,nCol-1); + freeArray(p,nRow); } } \ No newline at end of file diff --git a/Code-C/average.h b/Code-C/average.h index b4bdf81..25be1e0 100644 --- a/Code-C/average.h +++ b/Code-C/average.h @@ -1,4 +1,4 @@ #include #include -void average(char* rawDataFileName,int N , int M); \ No newline at end of file +void average(char* rawDataFileName); \ No newline at end of file diff --git a/Code-C/fileGestion.c b/Code-C/fileGestion.c index 57aa3e9..7749080 100644 --- a/Code-C/fileGestion.c +++ b/Code-C/fileGestion.c @@ -26,7 +26,7 @@ void clearRawData(int nRow){ * @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 array[], int nCol){ +void appendDataInFile(char* fileName , double array[], int nCol){ FILE *f = fopen(fileName,"a+"); for(int i = 0 ; i < nCol ; i++){ if( i < nCol-1){ @@ -36,5 +36,4 @@ void writeDataInFile(char* fileName , double array[], int nCol){ } } fclose(f); -} - +} \ No newline at end of file diff --git a/Code-C/fileGestion.h b/Code-C/fileGestion.h index b001d93..02e8bb8 100644 --- a/Code-C/fileGestion.h +++ b/Code-C/fileGestion.h @@ -5,4 +5,4 @@ void clearRawData(int N); -void writeDataInFile(char* fileName , double a[], int N); \ No newline at end of file +void appendDataInFile(char* fileName , double a[], int N); \ No newline at end of file diff --git a/Code-C/getArray.c b/Code-C/getArray.c index dd3f1fe..77a71ba 100644 --- a/Code-C/getArray.c +++ b/Code-C/getArray.c @@ -1,5 +1,6 @@ #include "getArray.h" #include "fileGestion.h" +#include "initialParameters.h" //#include long **get(int N, int M) /* Allocate the array */ @@ -55,7 +56,7 @@ void printArrayData(long** p, int N, int M) { * @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){ +bool checkArrayFullyFill(long **p, int N){ for(int i = 0 ; i < N ; i++){ if(p[i][0] == '\0'){ return false; } } @@ -83,11 +84,13 @@ void freeArray(long **p, int N) { * @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 **getRawDataArray(char* rawDataFileName){ long **p; - p = get(N, M); - fillArrayWithRawData(rawDataFileName,p ,N, M); - if(checkArrayFullyFill(p,N,M)){ + p = get(nRow, nCol); + printf("before fill\n"); + fillArrayWithRawData(rawDataFileName,p ,nRow, nCol); + printf("after fill\n"); + if(checkArrayFullyFill(p,nRow, nCol)){ //clearRawData(N); return p; } diff --git a/Code-C/getArray.h b/Code-C/getArray.h index 6a501b1..6a0c836 100644 --- a/Code-C/getArray.h +++ b/Code-C/getArray.h @@ -5,7 +5,7 @@ #include #include -long **getRawDataArray(char *rawDataFileName, int N , int M); +long **getRawDataArray(char *rawDataFileName); void printArrayData(long** p, int N, int M); void freeArray(long **p, int N); bool checkArrayFullyFill(long **p, int N , int M); \ No newline at end of file diff --git a/Code-C/initialParameters.h b/Code-C/initialParameters.h index ba11617..546b17a 100644 --- a/Code-C/initialParameters.h +++ b/Code-C/initialParameters.h @@ -9,7 +9,6 @@ extern double freqEch; extern double period; extern double invTimeBandWidth; -extern int selectionCaptors[]; -extern int sizeSelectionArray; +extern bool selectionCaptors[]; extern Pqueue firstRawDataQueue; diff --git a/Code-C/main b/Code-C/main index 69213d7..7652bd4 100755 Binary files a/Code-C/main and b/Code-C/main differ diff --git a/Code-C/main.c b/Code-C/main.c index 9957208..6065f7c 100644 --- a/Code-C/main.c +++ b/Code-C/main.c @@ -8,13 +8,12 @@ bool rawDataWriteFlag; int nRow = 500; -int nCol = 9; +int nCol = 1; double freqEch = 250; Pqueue firstRawDataQueue; -int selectionCaptors[] = {1,2,3,4,5,6,7,8}; -int sizeSelectionArray = 8; +bool selectionCaptors[] = {true,false,true,false,false,false,true,false}; int cptData = 0; int cptFile = 1; @@ -29,7 +28,7 @@ void *threadCalculPower(void *vargp){ while(queueGetNextE(rawDataQueue) != NULL){ rawDataQueue = queueGetNextE(rawDataQueue); fileName = queueGetTabChar(rawDataQueue); - power(fileName,nRow,nCol,period,invTimeBandWidth); + power(fileName); remove(fileName); } } @@ -42,7 +41,7 @@ void *threadCalculAverage(void *vargp){ while(queueGetNextE(rawDataQueue) != NULL){ rawDataQueue = queueGetNextE(rawDataQueue); fileName = queueGetTabChar(rawDataQueue); - average(fileName,nRow,nCol); + average(fileName); remove(fileName); } } @@ -55,15 +54,23 @@ void *threadCalculBoth(void *vargp){ while(queueGetNextE(rawDataQueue) != NULL){ rawDataQueue = queueGetNextE(rawDataQueue); fileName = queueGetTabChar(rawDataQueue); - power(fileName,nRow,nCol,period,invTimeBandWidth); - average(fileName,nRow,nCol); + power(fileName); + average(fileName); remove(fileName); } } } + int main(int argc , char** argv){ + for(int i = 0 ; i < 8 ; i++){ + if(selectionCaptors[i]){ + nCol++; + } + } + printf("%d\n" , nCol); + rawDataWriteFlag = true; period = 1 / freqEch; @@ -74,7 +81,7 @@ int main(int argc , char** argv){ pthread_create(&rawData , NULL, threadSimulateFlux, (void *)&rawData); pthread_t calcul; - pthread_create(&calcul , NULL, threadCalculBoth, (void *)&calcul); + pthread_create(&calcul , NULL, threadCalculPower, (void *)&calcul); pthread_exit(NULL); } \ No newline at end of file diff --git a/Code-C/power.c b/Code-C/power.c index df99179..66f4f75 100644 --- a/Code-C/power.c +++ b/Code-C/power.c @@ -9,21 +9,17 @@ * * @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++){ +void powerCalculation(long **p, double powerArray[]){ + for(int i = 1; i < nCol; i++){ int j = 0; powerArray[i] = 0; - while(j < N-1){ - double aire = ( pow(p[j][i+1],2) + pow(p[j+1][i+1],2) ) / 2 * period; - //printf("aire [%d,%d] : %f\n",j,i,aire); + while(j < nRow-1){ + double aire = ( pow(p[j][i],2) + pow(p[j+1][i],2) ) / 2 * period; powerArray[i] += aire; j++; } - powerArray[i] *= invTimeBandwidth; - //printf("%f\n", powerArray[i]); + powerArray[i] *= invTimeBandWidth; } } @@ -34,16 +30,12 @@ void powerCalculation(long **p, double powerArray[] , int N, int M , double peri * @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]; +void power(char* rawDataFileName){ + long **p = getRawDataArray(rawDataFileName); + double pw[nCol-1]; if(p !=NULL){ - powerCalculation(p,pw,N,M,periode,invTimeBandwidth); - writeDataInFile("powerData.csv",pw,8); - freeArray(p,N); - return true; - } - else{ - return false; + powerCalculation(p,pw); + appendDataInFile("powerData.csv",pw,nCol-1); + freeArray(p,nRow); } } \ No newline at end of file diff --git a/Code-C/power.h b/Code-C/power.h index 51e4dae..85480f9 100644 --- a/Code-C/power.h +++ b/Code-C/power.h @@ -1,4 +1,4 @@ #include #include -bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth); \ No newline at end of file +void power(char* rawDataFileName); \ No newline at end of file diff --git a/Code-C/simulateFlux.c b/Code-C/simulateFlux.c index 3066bf3..07a350c 100644 --- a/Code-C/simulateFlux.c +++ b/Code-C/simulateFlux.c @@ -19,7 +19,7 @@ char* convertIntegerToChar(int N) } char* arr; char arr1[digit]; - arr = (char*)malloc(digit); + arr = (char*)malloc(digit*sizeof(char)); int index = 0; while (N) { arr1[++index] = N % 10 + '0'; @@ -42,6 +42,9 @@ 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 fileNameNumber[strlen(fileName)+strlen(fileNumber)]; char *fullFileName = malloc((strlen(fileNameNumber)+strlen(extension)) * sizeof(char*)); @@ -94,21 +97,18 @@ bool writeOneRawData(FILE *rawDataFile){ uint32_t valbin[8]; quartet value; - if(fread(&buff, 26, 1, stdin)) { fprintf(rawDataFile , "%d,", millis()); if (strncmp(buff, "#################\n", (size_t)18) == 0) { if (!(fread(&buff2, 18, 1, stdin))) { fprintf(stderr, "Erreur lecture après ###...#"); - return 2; } else { strncpy(buff, &buff[18], 8); strncpy(&buff[8], buff2, 18); } } - int maxCApteurNb = maxInArray(selectionCaptors,sizeSelectionArray); for (int i = 1; i < 9; i++){ - if(intInArray(i,selectionCaptors,sizeSelectionArray)==0){ + if(selectionCaptors[i]){ value.octet1 = buff[3*i+1]; value.octet2 = buff[3*i+2]; value.octet3 = buff[3*i+3]; @@ -117,8 +117,7 @@ bool writeOneRawData(FILE *rawDataFile){ 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==maxCApteurNb){ + if(i==8){ fprintf(rawDataFile, "%d\n", values[i]/256); } else{