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

86 lines
2.1 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-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-09 17:34:24 +02:00
int nCol = 9;
double freqEch = 250;
2022-06-10 17:22:01 +02:00
Pqueue firstRawDataQueue;
2022-06-10 15:05:04 +02:00
2022-06-09 17:34:24 +02:00
int selectionCaptors[] = {1,2,3,4,5,6,7,8};
int sizeSelectionArray = 8;
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-13 17:11:16 +02:00
power(fileName,nRow,nCol,period,invTimeBandWidth);
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);
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);
2022-06-15 16:25:43 +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-01 12:32:04 +02:00
int main(int argc , char** argv){
2022-06-13 17:24:53 +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-10 15:50:27 +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-10 17:22:01 +02:00
2022-06-13 15:03:51 +02:00
pthread_t calcul;
2022-06-14 10:24:59 +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
}