Traitement-signal-plantes/Code-C/main.c

120 lines
3.4 KiB
C
Raw Normal View History

2022-06-09 17:34:24 +02:00
#include <pthread.h>
#include <stdbool.h>
#include "simulateFlux.h"
2022-06-01 12:32:04 +02:00
#include "power.h"
2022-06-07 14:28:32 +02:00
#include "initialParameters.h"
2022-06-10 15:05:04 +02:00
#include "queue.h"
2022-06-14 10:24:59 +02:00
#include "average.h"
2022-06-15 11:57:15 +02:00
#include "growthRate.h"
2022-06-01 12:32:04 +02:00
2022-06-13 17:11:16 +02:00
bool rawDataWriteFlag;
2022-06-14 10:24:59 +02:00
int nRow = 500;
2022-06-14 18:01:52 +02:00
int nCol = 1;
2022-06-09 17:34:24 +02:00
double freqEch = 250;
2022-06-10 17:22:01 +02:00
Pqueue firstRawDataQueue;
2022-06-10 15:05:04 +02:00
2022-06-14 18:01:52 +02:00
bool selectionCaptors[] = {true,false,true,false,false,false,true,false};
2022-06-10 10:10:28 +02:00
2022-06-10 17:22:01 +02:00
int cptData = 0;
int cptFile = 1;
double period = 0;
double invTimeBandWidth = 0;
2022-06-14 10:24:59 +02:00
void *threadCalculPower(void *vargp){
2022-06-13 15:03:51 +02:00
Pqueue rawDataQueue = firstRawDataQueue;
2022-06-13 17:24:53 +02:00
char* fileName;
2022-06-13 17:11:16 +02:00
while(rawDataWriteFlag){
while(queueGetNextE(rawDataQueue) != NULL){
2022-06-13 17:24:53 +02:00
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
2022-06-15 15:45:14 +02:00
powerFunction(fileName, NULL);
2022-06-14 10:24:59 +02:00
remove(fileName);
}
}
}
void *threadCalculAverage(void *vargp){
Pqueue rawDataQueue = firstRawDataQueue;
char* fileName;
while(rawDataWriteFlag){
while(queueGetNextE(rawDataQueue) != NULL){
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
2022-06-15 11:57:15 +02:00
averageThreadFunction(fileName);
2022-06-14 10:24:59 +02:00
remove(fileName);
}
}
}
void *threadCalculBoth(void *vargp){
Pqueue rawDataQueue = firstRawDataQueue;
char* fileName;
while(rawDataWriteFlag){
while(queueGetNextE(rawDataQueue) != NULL){
2022-06-15 16:27:56 +02:00
printf("ertyu\n");
2022-06-14 10:24:59 +02:00
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
2022-06-15 15:45:14 +02:00
powerFunction(fileName, NULL);
2022-06-15 11:57:15 +02:00
averageThreadFunction(fileName);
2022-06-14 10:24:59 +02:00
remove(fileName);
2022-06-13 17:11:16 +02:00
}
2022-06-13 15:03:51 +02:00
}
}
2022-06-10 17:22:01 +02:00
2022-06-15 11:57:15 +02:00
void *threadCalculGrowthRate(void * vargp){
Pqueue rawDataQueue = firstRawDataQueue;
char* fileName;
2022-06-15 15:45:14 +02:00
//double pw[nCol-1];
double *dataLign[2][nCol-1];
int i = 0;
2022-06-15 11:57:15 +02:00
while(rawDataWriteFlag){
2022-06-15 13:59:27 +02:00
//add case first file traitement
//(possibility 1: call twice powerfunction , following while strat after 2 file encountered)
//(posibilty 2 : initialiaze with a 0-fill array, move ligns for first encounter then let the following whil e do the job)
2022-06-15 11:57:15 +02:00
while(queueGetNextE(rawDataQueue) != NULL){
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
2022-06-15 15:45:14 +02:00
if(i < 2){
if(i == 1){
powerFunction(fileName, dataLign[1]);
growthRateFunction(**dataLign);
}else{
powerFunction(fileName, dataLign[0]);
}
i++;
}else{
for(int y = 0; y < (nCol-1); y++){
dataLign[0][y] = dataLign[1][y];
}
powerFunction(fileName, dataLign[1]);
growthRateFunction(**dataLign);
}
2022-06-15 11:57:15 +02:00
remove(fileName);
}
}
}
2022-06-14 18:01:52 +02:00
2022-06-01 12:32:04 +02:00
int main(int argc , char** argv){
2022-06-13 17:24:53 +02:00
2022-06-14 18:01:52 +02:00
for(int i = 0 ; i < 8 ; i++){
if(selectionCaptors[i]){
nCol++;
}
}
2022-06-13 17:11:16 +02:00
rawDataWriteFlag = true;
2022-06-09 17:34:24 +02:00
2022-06-10 17:22:01 +02:00
period = 1 / freqEch;
invTimeBandWidth = 1 /(nRow * period);
2022-06-13 15:03:51 +02:00
firstRawDataQueue = queueCreateEmpty(); // change this for create empty
2022-06-15 16:27:56 +02:00
2022-06-09 17:34:24 +02:00
pthread_t rawData;
2022-06-14 10:46:12 +02:00
pthread_create(&rawData , NULL, threadSimulateFlux, (void *)&rawData);
2022-06-13 15:03:51 +02:00
pthread_t calcul;
2022-06-15 10:49:21 +02:00
pthread_create(&calcul , NULL, threadCalculBoth, (void *)&calcul);
2022-06-10 17:22:01 +02:00
2022-06-09 17:34:24 +02:00
pthread_exit(NULL);
2022-06-01 12:32:04 +02:00
}