diff --git a/Code-C/Makefile b/Code-C/Makefile index ddfb997..de97bc3 100644 --- a/Code-C/Makefile +++ b/Code-C/Makefile @@ -3,6 +3,6 @@ CC = gcc all: # rm powerData.csv # $(CC) simulateFlux.c fileGestion.c getArray.c power.c main.c -lm -o main - $(CC) queue.c simulateFlux.c main.c -lpthread -o main + $(CC) fileGestion.c getArray.c power.c queue.c simulateFlux.c main.c -lm -lpthread -o main # $(CC) queue.c -o queue ./main < ../02400031.TXT \ No newline at end of file diff --git a/Code-C/fileGestion.c b/Code-C/fileGestion.c index c081480..5a54c0c 100644 --- a/Code-C/fileGestion.c +++ b/Code-C/fileGestion.c @@ -38,14 +38,3 @@ void writePowerData(double powerArray[], int nCol){ fclose(f); } -void threadCalcul(){ - while(stopFlag == false){ - if(rawDataWriteFlag){ - pthread_mutex_lock(&mutex); - while(power(nRow,nCol,period,timeBandwidth) == false){} - pthread_mutex_unlock(&mutex); - rawDataWriteFlag = true; - delay(10); - } - } -} \ No newline at end of file diff --git a/Code-C/fileGestion.h b/Code-C/fileGestion.h index 4df4dcf..afebd10 100644 --- a/Code-C/fileGestion.h +++ b/Code-C/fileGestion.h @@ -3,7 +3,6 @@ #include #include -bool writeFlag = 0; void clearRawData(int N); void writePowerData(double a[], int N); \ No newline at end of file diff --git a/Code-C/getArray.c b/Code-C/getArray.c index 73e6893..8b2087c 100644 --- a/Code-C/getArray.c +++ b/Code-C/getArray.c @@ -13,7 +13,7 @@ long **get(int N, int M) /* Allocate the array */ return array; } -void fillArrayWithRawData(long** p, int N, int M) { +void fillArrayWithRawData(char *rawDataFileName,long** p, int N, int M) { int i, j; char *buffer; @@ -21,7 +21,7 @@ void fillArrayWithRawData(long** p, int N, int M) { buffer = (char *)malloc(bufsize * sizeof(char)); char* token; - FILE *f = fopen("rawData.csv","r"); + FILE *f = fopen(rawDataFileName,"r"); for(i = 0 ; i < N ; i++){ if (!getline(&buffer, &bufsize, f)) break; // condition d'arret de la boucle si fichier fini //printf("buffer : %s token : ",buffer); @@ -35,6 +35,7 @@ void fillArrayWithRawData(long** p, int N, int M) { } //printf("\n\n"); } + fclose(f); } /** * @brief print all the element of a bidimensionnal array p of shape : N x M @@ -71,10 +72,10 @@ void freeArray(long **p, int N) { free(p); } -long **getRawDataArray(int N , int M){ +long **getRawDataArray(char* rawDataFileName , int N , int M){ long **p; p = get(N, M); - fillRawData(p ,N, M); + fillArrayWithRawData(rawDataFileName,p ,N, M); //printf("before test\n"); if(checkArrayFullyFill(p,N,M)==0){ //printf("after test 0\n"); diff --git a/Code-C/getArray.h b/Code-C/getArray.h index c975391..6a501b1 100644 --- a/Code-C/getArray.h +++ b/Code-C/getArray.h @@ -5,7 +5,7 @@ #include #include -long **getRawDataArray(); +long **getRawDataArray(char *rawDataFileName, int N , int M); 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 b91c822..9a2e2f4 100644 --- a/Code-C/initialParameters.h +++ b/Code-C/initialParameters.h @@ -6,6 +6,9 @@ extern int nRow; extern int nCol; extern double freqEch; +extern double period; +extern double invTimeBandWidth; + extern int selectionCaptors[]; extern int sizeSelectionArray; diff --git a/Code-C/main b/Code-C/main index 17258e9..60acc4f 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 d02a0a3..88ad736 100644 --- a/Code-C/main.c +++ b/Code-C/main.c @@ -10,18 +10,31 @@ int nRow = 100000; int nCol = 9; double freqEch = 250; -Pqueue firstRawDataQueue = NULL; +Pqueue firstRawDataQueue; int selectionCaptors[] = {1,2,3,4,5,6,7,8}; int sizeSelectionArray = 8; +int cptData = 0; +int cptFile = 1; + +double period = 0; +double invTimeBandWidth = 0; + + int main(int argc , char** argv){ - double period = 1 / freqEch; - double invTimeBandWidth = 1 /(nRow * period); + period = 1 / freqEch; + invTimeBandWidth = 1 /(nRow * period); + firstRawDataQueue = NULL; // change this for create empty pthread_t rawData; pthread_create(&rawData , NULL, simulateFlux, (void *)&rawData); + + pthread_t power; + pthread_create(&power , NULL, threadCalcul, (void *)&power); + pthread_exit(NULL); + } \ No newline at end of file diff --git a/Code-C/power.c b/Code-C/power.c index b99ad45..b0aa00c 100644 --- a/Code-C/power.c +++ b/Code-C/power.c @@ -1,6 +1,8 @@ #include "power.h" #include "getArray.h" #include "fileGestion.h" +#include "initialParameters.h" +#include "queue.h" void powerCalculation(long **p, double powerArray[] , int N, int M , double period , double invTimeBandwidth){ for(int i = 0; i < M-1; i++){ @@ -16,8 +18,8 @@ void powerCalculation(long **p, double powerArray[] , int N, int M , double peri //printf("%f\n", powerArray[i]); } } -bool power(int N , int M, double periode , double invTimeBandwidth){ - long **p = getRawDataArray(N, M); +bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth){ + long **p = getRawDataArray(rawDataFileName,N, M); double pw[8]; if(p !=NULL){ powerCalculation(p,pw,N,M,periode,invTimeBandwidth); @@ -28,4 +30,18 @@ bool power(int N , int M, double periode , double invTimeBandwidth){ else{ return false; } +} +void *threadCalcul(void *vargp){ + Pqueue rawDataQueue = firstRawDataQueue; + printf("print in power of first eleme in queue : \n"); + printE(firstRawDataQueue); + while(rawDataQueue == NULL || getNextE(rawDataQueue) != NULL){ + //pthread_mutex_lock(&mutex); + while(power(gettabChar(rawDataQueue),nRow,nCol,period,invTimeBandWidth) == false){ + remove(gettabChar(rawDataQueue)); + rawDataQueue = rmFrstE(rawDataQueue); + } + //pthread_mutex_unlock(&mutex); + //delay(10); + } } \ No newline at end of file diff --git a/Code-C/power.h b/Code-C/power.h index f83ba8c..474b206 100644 --- a/Code-C/power.h +++ b/Code-C/power.h @@ -1,4 +1,5 @@ #include #include -int power(int N , int M, double periode , double timeBandwidth); \ No newline at end of file +//bool power(int N , int M, double periode , double timeBandwidth); +void *threadCalcul(void *vargp); \ No newline at end of file diff --git a/Code-C/simulateFlux.c b/Code-C/simulateFlux.c index 7286853..0eea048 100644 --- a/Code-C/simulateFlux.c +++ b/Code-C/simulateFlux.c @@ -2,8 +2,6 @@ #include "initialParameters.h" #include "queue.h" -int cptData = 0; -int cptFile = 1; char* convertIntegerToChar(int N) { @@ -119,9 +117,6 @@ void *simulateFlux(void *vargp){ char *fileName = createNewRawDataFileName(); FILE *rawDataFile = fopen(fileName,"w+"); Pqueue rawDataQueue = createE(strlen(fileName)); - setTabChar(rawDataQueue , strlen(fileName) , fileName); - firstRawDataQueue = rawDataQueue; - printE(rawDataQueue); while(writeOneRawData(rawDataFile)){ if(cptData == nRow){ @@ -132,10 +127,8 @@ void *simulateFlux(void *vargp){ char *fileName = createNewRawDataFileName(); FILE *rawDataFile = fopen(fileName,"w+"); rawDataQueue = addLastQ(rawDataQueue , fileName , strlen(fileName)); - printE(rawDataQueue); + } } - printf("\n"); - printE(firstRawDataQueue); } diff --git a/Code-C/simulateFlux.h b/Code-C/simulateFlux.h index b9edec8..dd2b3d7 100644 --- a/Code-C/simulateFlux.h +++ b/Code-C/simulateFlux.h @@ -13,5 +13,9 @@ typedef struct { uint8_t octet4; } quartet; +extern int cptData; +extern int cptFile; + +char* convertIntegerToChar(int N); bool writeOneRawData(FILE *f); void *simulateFlux(void *vargp); \ No newline at end of file