Compare commits

..

No commits in common. "9bb5e5e99db07be48f85040186123329ab250dad" and "16948e901b755b34b8ed5d964cd2f344d86b777d" have entirely different histories.

16 changed files with 56 additions and 178 deletions

View file

@ -1,7 +1,7 @@
CC = gcc CC = gcc
all: all:
$(CC) fileGestion.c getArray.c average.c power.c queue.c simulateFlux.c main.c -lm -lpthread -o main $(CC) fileGestion.c getArray.c power.c queue.c simulateFlux.c main.c -lm -lpthread -o main
# $(CC) queue.c simulateFlux.c main.c -lm -lpthread -o main # $(CC) queue.c simulateFlux.c main.c -lm -lpthread -o main
./main < ../02400031.TXT ./main < ../02400031.TXT

View file

@ -1,42 +0,0 @@
#include "average.h"
#include "getArray.h"
#include "fileGestion.h"
#include "initialParameters.h"
#include "queue.h"
/**
* @brief realize the average calcul
*
* @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++){
int j = 0;
averageArray[i] = 0;
while(j < N){
averageArray[i] += p[i][j];
j++;
}
averageArray[i] /= N;
//printf("%f\n", powerArray[i]);
}
}
/**
* @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];
if(p !=NULL){
averageCalculation(p,aver,N,M);
writeDataInFile("averageData.csv",aver,8);
freeArray(p,N);
}
}

View file

@ -1,4 +0,0 @@
#include <math.h>
#include <stdbool.h>
void average(char* rawDataFileName,int N , int M);

View file

@ -43,8 +43,6 @@ void b2hd()
} }
} }
} }
int main(int argc , char** argv){ int main(int argc , char** argv){
b2hd(); b2hd();
} }

View file

@ -21,18 +21,18 @@ void clearRawData(int nRow){
fclose(f); fclose(g); fclose(f); fclose(g);
} }
/** /**
* @brief use to write one lign in the file "fileName" * @brief use to write the file powerData.csv that contaign all power calculous results
* *
* @param array array that contaign all the values to write in the file * @param powerArray
* @param nCol size of the array (correspond to the number of captor used) * @param nCol size of the power array, correspond to the number of captor used
*/ */
void writeDataInFile(char* fileName , double array[], int nCol){ void writePowerData(double powerArray[], int nCol){
FILE *f = fopen(fileName,"a+"); FILE *f = fopen("powerData.csv","a+");
for(int i = 0 ; i < nCol ; i++){ for(int i = 0 ; i < nCol ; i++){
if( i < nCol-1){ if( i < nCol-1){
fprintf(f, "%f , ", array[i]); fprintf(f, "%f , ", powerArray[i]);
} else { } else {
fprintf(f, "%f\n", array[i]); fprintf(f, "%f\n", powerArray[i]);
} }
} }
fclose(f); fclose(f);

View file

@ -5,4 +5,4 @@
void clearRawData(int N); void clearRawData(int N);
void writeDataInFile(char* fileName , double a[], int N); void writePowerData(double a[], int N);

View file

@ -15,23 +15,27 @@ long **get(int N, int M) /* Allocate the array */
void fillArrayWithRawData(char *rawDataFileName,long** p, int N, int M) { void fillArrayWithRawData(char *rawDataFileName,long** p, int N, int M) {
int i, j; int i, j;
char *buffer; char *buffer;
size_t bufsize = 200; size_t bufsize = 200;
buffer = (char *)malloc(bufsize * sizeof(char)); buffer = (char *)malloc(bufsize * sizeof(char));
char* token; char* token;
FILE *f = fopen(rawDataFileName,"r"); FILE *f = fopen(rawDataFileName,"r");
for(i = 0 ; i < N ; i++){ for(i = 0 ; i < N ; i++){
if (!getline(&buffer, &bufsize, f)) break; // condition d'arret de la boucle si fichier fini if (!getline(&buffer, &bufsize, f)) break; // condition d'arret de la boucle si fichier fini
//printf("buffer : %s token : ",buffer);
j = 0; j = 0;
while((token = strsep(&buffer,",")) != NULL){ // séparation valeur par virgule initiale : csv while((token = strsep(&buffer,",")) != NULL){ // séparation valeur par virgule initiale : csv
//printf(token);
p[i][j] = atoi(token); p[i][j] = atoi(token);
//printf("%d,", p[i][j]);
//printf("%d, " , p[i][j]);
j++; j++;
} }
//printf("\n\n");
} }
fclose(f); fclose(f);
} }
/** /**
* @brief print all the element of a bidimensionnal array p of shape : N x M * @brief print all the element of a bidimensionnal array p of shape : N x M
@ -49,11 +53,10 @@ void printArrayData(long** p, int N, int M) {
/** /**
* @brief verify if all the element of an array are not NULL, return * @brief verify if all the element of an array are not NULL, return
* *
* @param p array to check * @param p
* @param N number of rows in p * @param N
* @param M number of columns in p * @param M
* @return true if the array contaign no NULL element * @return int
* @return false if at least one element is null
*/ */
bool checkArrayFullyFill(long **p, int N , int M){ bool checkArrayFullyFill(long **p, int N , int M){
for(int i = 0 ; i < N ; i++){ for(int i = 0 ; i < N ; i++){
@ -62,12 +65,6 @@ bool checkArrayFullyFill(long **p, int N , int M){
return true; 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) { void freeArray(long **p, int N) {
int i; int i;
for(i = 0 ; i < N ; i++) for(i = 0 ; i < N ; i++)
@ -75,23 +72,18 @@ void freeArray(long **p, int N) {
free(p); 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 **getRawDataArray(char* rawDataFileName , int N , int M){
long **p; long **p;
p = get(N, M); p = get(N, M);
fillArrayWithRawData(rawDataFileName,p ,N, M); fillArrayWithRawData(rawDataFileName,p ,N, M);
if(checkArrayFullyFill(p,N,M)){ //printf("before test\n");
//clearRawData(N); if(checkArrayFullyFill(p,N,M)==0){
//printf("after test 0\n");
clearRawData(N);
return p; return p;
} }
else{ else{
//printf("after test 1\n");
return NULL; return NULL;
} }
} }

View file

@ -1,7 +1,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "queue.h" #include "queue.h"
extern bool rawDataWriteFlag; extern bool rawDataWriteFlag , stopFlag;
extern int nRow; extern int nRow;
extern int nCol; extern int nCol;
extern double freqEch; extern double freqEch;

Binary file not shown.

View file

@ -4,10 +4,9 @@
#include "power.h" #include "power.h"
#include "initialParameters.h" #include "initialParameters.h"
#include "queue.h" #include "queue.h"
#include "average.h"
bool rawDataWriteFlag; bool rawDataWriteFlag = 0, stopFlag = 0;
int nRow = 500; int nRow = 100000;
int nCol = 9; int nCol = 9;
double freqEch = 250; double freqEch = 250;
@ -22,59 +21,31 @@ int cptFile = 1;
double period = 0; double period = 0;
double invTimeBandWidth = 0; double invTimeBandWidth = 0;
void *threadCalculPower(void *vargp){ void *threadCalcul(void *vargp){
printf("start thread calcul\n");
Pqueue rawDataQueue = firstRawDataQueue; Pqueue rawDataQueue = firstRawDataQueue;
char* fileName; while(queueGetNextE(rawDataQueue) != NULL){
while(rawDataWriteFlag){ printf("wile calcul\n");
while(queueGetNextE(rawDataQueue) != NULL){ //pthread_mutex_lock(&mutex);
rawDataQueue = queueGetNextE(rawDataQueue); power(queueGetTabChar(rawDataQueue),nRow,nCol,period,invTimeBandWidth);
fileName = queueGetTabChar(rawDataQueue); /*remove(queueGetTabChar(rawDataQueue));
power(fileName,nRow,nCol,period,invTimeBandWidth); rawDataQueue = queueRmFrstE(rawDataQueue);*/
remove(fileName);
} //pthread_mutex_unlock(&mutex);
}
}
void *threadCalculAverage(void *vargp){
Pqueue rawDataQueue = firstRawDataQueue;
char* fileName;
while(rawDataWriteFlag){
while(queueGetNextE(rawDataQueue) != NULL){
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
average(fileName,nRow,nCol);
remove(fileName);
}
}
}
void *threadCalculBoth(void *vargp){
Pqueue rawDataQueue = firstRawDataQueue;
char* fileName;
while(rawDataWriteFlag){
while(queueGetNextE(rawDataQueue) != NULL){
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
power(fileName,nRow,nCol,period,invTimeBandWidth);
average(fileName,nRow,nCol);
remove(fileName);
}
} }
} }
int main(int argc , char** argv){ int main(int argc , char** argv){
rawDataWriteFlag = true;
period = 1 / freqEch; period = 1 / freqEch;
invTimeBandWidth = 1 /(nRow * period); invTimeBandWidth = 1 /(nRow * period);
firstRawDataQueue = queueCreateEmpty(); // change this for create empty firstRawDataQueue = queueCreateEmpty(); // change this for create empty
pthread_t rawData; pthread_t rawData;
pthread_create(&rawData , NULL, threadSimulateFlux, (void *)&rawData); pthread_create(&rawData , NULL, simulateFlux, (void *)&rawData);
pthread_t calcul; //pthread_t calcul;
pthread_create(&calcul , NULL, threadCalculBoth, (void *)&calcul); //pthread_create(&calcul , NULL, threadCalcul, (void *)&calcul);
pthread_exit(NULL); pthread_exit(NULL);
} }

View file

@ -4,14 +4,6 @@
#include "initialParameters.h" #include "initialParameters.h"
#include "queue.h" #include "queue.h"
/**
* @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){ void powerCalculation(long **p, double powerArray[] , int N, int M , double period , double invTimeBandwidth){
for(int i = 0; i < M-1; i++){ for(int i = 0; i < M-1; i++){
int j = 0; int j = 0;
@ -26,20 +18,12 @@ void powerCalculation(long **p, double powerArray[] , int N, int M , double peri
//printf("%f\n", powerArray[i]); //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){ bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth){
long **p = getRawDataArray(rawDataFileName,N, M); long **p = getRawDataArray(rawDataFileName,N, M);
double pw[8]; double pw[8];
if(p !=NULL){ if(p !=NULL){
powerCalculation(p,pw,N,M,periode,invTimeBandwidth); powerCalculation(p,pw,N,M,periode,invTimeBandwidth);
writeDataInFile("powerData.csv",pw,8); writePowerData(pw,8);
freeArray(p,N); freeArray(p,N);
return true; return true;
} }

View file

@ -1,4 +1,5 @@
#include <math.h> #include <math.h>
#include <stdbool.h> #include <stdbool.h>
bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth); bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth);
void *threadCalcul(void *vargp);

View file

@ -148,11 +148,14 @@ Pqueue queueRmLastE(Pqueue elem){
* @brief remove and free the first element of queue * @brief remove and free the first element of queue
* *
* @param elem target to remove (the element need to be the first) * @param elem target to remove (the element need to be the first)
* @return Pqueue the second element after remove first
*/ */
void queueRmFrstE(Pqueue elem){ Pqueue queueRmFrstE(Pqueue elem){
assert(elem); assert(elem);
Pqueue tmp = elem->pNextE;
free(elem->tabChar); free(elem->tabChar);
free(elem); free(elem);
return tmp;
} }
/** /**
@ -174,6 +177,7 @@ Pqueue queueNextDelFrst(Pqueue elem){
* @param elem Pqueue will be added at the end of queue * @param elem Pqueue will be added at the end of queue
* @param str the string will be bind at the element * @param str the string will be bind at the element
* @param len the lenght of char array * @param len the lenght of char array
* @return Pqueue pointer to the last element
*/ */
void queueAddLastQ(Pqueue elem, const char* str, int len){ void queueAddLastQ(Pqueue elem, const char* str, int len){
assert(elem); assert(elem);
@ -204,11 +208,6 @@ 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){ void queuePrintWholeQ(Pqueue firstE){
queuePrintE(firstE); queuePrintE(firstE);
Pqueue elem = firstE; Pqueue elem = firstE;

View file

@ -19,7 +19,7 @@ void queueAddLastQ(Pqueue elem, const char* str, int len);
//Removers //Removers
Pqueue queueRmLastE(Pqueue elem); Pqueue queueRmLastE(Pqueue elem);
void queueRmFrstE(Pqueue elem); Pqueue queueRmFrstE(Pqueue elem);
Pqueue queueNextDelFrst(Pqueue elem); Pqueue queueNextDelFrst(Pqueue elem);
//print function //print function

View file

@ -2,12 +2,7 @@
#include "initialParameters.h" #include "initialParameters.h"
#include "queue.h" #include "queue.h"
/**
* @brief convert an interger N into a char*
*
* @param N
* @return char*
*/
char* convertIntegerToChar(int N) char* convertIntegerToChar(int N)
{ {
// Count digits in number N // Count digits in number N
@ -33,11 +28,6 @@ char* convertIntegerToChar(int N)
return (char*)arr; return (char*)arr;
} }
/**
* @brief Create a New Raw Data File Name
*
* @return char*
*/
char *createNewRawDataFileName(){ char *createNewRawDataFileName(){
char *fileName = "../RawDataFiles/RawData"; char *fileName = "../RawDataFiles/RawData";
char *extension = ".csv\0"; char *extension = ".csv\0";
@ -68,25 +58,13 @@ int maxInArray(int *array , int N){
} }
return max; return max;
} }
/**
* @brief return the unix time in millisecond
*
* @return int64_t
*/
int64_t millis() int64_t millis()
{ {
struct timespec now; struct timespec now;
timespec_get(&now, TIME_UTC); 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;
} }
/**
* @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){ bool writeOneRawData(FILE *rawDataFile){
char buff[26]; char buff[26];
char buff2[18]; char buff2[18];
@ -127,7 +105,7 @@ bool writeOneRawData(FILE *rawDataFile){
} }
} }
cptData++; cptData++;
//sleep(0.004); //simul freq here //sleep(0.004); //simul la freq ech
return true; return true;
} }
else { else {
@ -135,7 +113,8 @@ bool writeOneRawData(FILE *rawDataFile){
} }
} }
void *threadSimulateFlux(void *vargp){ void *simulateFlux(void *vargp){
printf("start thread simul\n");
char *fileName = createNewRawDataFileName(); char *fileName = createNewRawDataFileName();
FILE *rawDataFile = fopen(fileName,"w+"); FILE *rawDataFile = fopen(fileName,"w+");
@ -152,5 +131,5 @@ void *threadSimulateFlux(void *vargp){
FILE *rawDataFile = fopen(fileName,"w+"); FILE *rawDataFile = fopen(fileName,"w+");
} }
} }
rawDataWriteFlag = false; queuePrintWholeQ(firstRawDataQueue);
} }

View file

@ -18,4 +18,4 @@ extern int cptFile;
char *convertIntegerToChar(int N); char *convertIntegerToChar(int N);
bool writeOneRawData(FILE *f); bool writeOneRawData(FILE *f);
void *threadSimulateFlux(void *vargp); void *simulateFlux(void *vargp);