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

80 lines
2 KiB
C

#include <pthread.h>
#include <stdbool.h>
#include "simulateFlux.h"
#include "power.h"
#include "initialParameters.h"
#include "queue.h"
#include "average.h"
bool rawDataWriteFlag;
int nRow = 500;
int nCol = 9;
double freqEch = 250;
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;
void *threadCalculPower(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);
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);
remove(fileName);
}
}
}
int main(int argc , char** argv){
rawDataWriteFlag = true;
period = 1 / freqEch;
invTimeBandWidth = 1 /(nRow * period);
firstRawDataQueue = queueCreateEmpty(); // change this for create empty
pthread_t rawData;
pthread_create(&rawData , NULL, simulateFlux, (void *)&rawData);
pthread_t calcul;
pthread_create(&calcul , NULL, threadCalculBoth, (void *)&calcul);
pthread_exit(NULL);
}