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

117 lines
3.2 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-16 14:35:02 +02:00
#include "getArray.h"
2022-06-01 12:32:04 +02:00
2022-06-13 17:11:16 +02:00
bool rawDataWriteFlag;
2022-06-16 14:35:02 +02:00
int nRow = 4;
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-16 14:35:02 +02:00
//Captor 1 2 3 4 5 6 7 8
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){
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];
2022-06-16 14:35:02 +02:00
double **dataLign = getDoubleArray(2,nCol);
2022-06-15 15:45:14 +02:00
int i = 0;
2022-06-15 11:57:15 +02:00
while(rawDataWriteFlag){
while(queueGetNextE(rawDataQueue) != NULL){
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
2022-06-15 15:45:14 +02:00
if(i < 2){
if(i == 1){
2022-06-16 14:35:02 +02:00
powerFunction(fileName, dataLign);
growthRateFunction(dataLign);
2022-06-15 15:45:14 +02:00
}else{
2022-06-16 14:35:02 +02:00
powerFunction(fileName, dataLign);
2022-06-15 15:45:14 +02:00
}
i++;
}else{
for(int y = 0; y < (nCol-1); y++){
dataLign[0][y] = dataLign[1][y];
}
2022-06-16 14:35:02 +02:00
powerFunction(fileName, dataLign);
growthRateFunction(dataLign);
2022-06-15 15:45:14 +02:00
}
2022-06-16 14:35:02 +02:00
//remove(fileName);
2022-06-15 11:57:15 +02:00
}
}
}
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 17:50:47 +02:00
pthread_create(&calcul , NULL, threadCalculGrowthRate, (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
}