prepare power thread
This commit is contained in:
parent
2e7253c43c
commit
4d19b6539e
|
@ -3,6 +3,6 @@ CC = gcc
|
|||
all:
|
||||
# rm powerData.csv
|
||||
# $(CC) simulateFlux.c fileGestion.c getArray.c power.c main.c -lm -o main
|
||||
$(CC) queue.c simulateFlux.c main.c -lpthread -o main
|
||||
$(CC) fileGestion.c getArray.c power.c queue.c simulateFlux.c main.c -lm -lpthread -o main
|
||||
# $(CC) queue.c -o queue
|
||||
./main < ../02400031.TXT
|
|
@ -38,14 +38,3 @@ void writePowerData(double powerArray[], int nCol){
|
|||
fclose(f);
|
||||
}
|
||||
|
||||
void threadCalcul(){
|
||||
while(stopFlag == false){
|
||||
if(rawDataWriteFlag){
|
||||
pthread_mutex_lock(&mutex);
|
||||
while(power(nRow,nCol,period,timeBandwidth) == false){}
|
||||
pthread_mutex_unlock(&mutex);
|
||||
rawDataWriteFlag = true;
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@
|
|||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
bool writeFlag = 0;
|
||||
|
||||
void clearRawData(int N);
|
||||
void writePowerData(double a[], int N);
|
|
@ -13,7 +13,7 @@ long **get(int N, int M) /* Allocate the array */
|
|||
return array;
|
||||
}
|
||||
|
||||
void fillArrayWithRawData(long** p, int N, int M) {
|
||||
void fillArrayWithRawData(char *rawDataFileName,long** p, int N, int M) {
|
||||
int i, j;
|
||||
|
||||
char *buffer;
|
||||
|
@ -21,7 +21,7 @@ void fillArrayWithRawData(long** p, int N, int M) {
|
|||
buffer = (char *)malloc(bufsize * sizeof(char));
|
||||
char* token;
|
||||
|
||||
FILE *f = fopen("rawData.csv","r");
|
||||
FILE *f = fopen(rawDataFileName,"r");
|
||||
for(i = 0 ; i < N ; i++){
|
||||
if (!getline(&buffer, &bufsize, f)) break; // condition d'arret de la boucle si fichier fini
|
||||
//printf("buffer : %s token : ",buffer);
|
||||
|
@ -35,6 +35,7 @@ void fillArrayWithRawData(long** p, int N, int M) {
|
|||
}
|
||||
//printf("\n\n");
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
/**
|
||||
* @brief print all the element of a bidimensionnal array p of shape : N x M
|
||||
|
@ -71,10 +72,10 @@ void freeArray(long **p, int N) {
|
|||
free(p);
|
||||
}
|
||||
|
||||
long **getRawDataArray(int N , int M){
|
||||
long **getRawDataArray(char* rawDataFileName , int N , int M){
|
||||
long **p;
|
||||
p = get(N, M);
|
||||
fillRawData(p ,N, M);
|
||||
fillArrayWithRawData(rawDataFileName,p ,N, M);
|
||||
//printf("before test\n");
|
||||
if(checkArrayFullyFill(p,N,M)==0){
|
||||
//printf("after test 0\n");
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <stdbool.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
long **getRawDataArray();
|
||||
long **getRawDataArray(char *rawDataFileName, int N , int M);
|
||||
void printArrayData(long** p, int N, int M);
|
||||
void freeArray(long **p, int N);
|
||||
bool checkArrayFullyFill(long **p, int N , int M);
|
|
@ -6,6 +6,9 @@ extern int nRow;
|
|||
extern int nCol;
|
||||
extern double freqEch;
|
||||
|
||||
extern double period;
|
||||
extern double invTimeBandWidth;
|
||||
|
||||
extern int selectionCaptors[];
|
||||
extern int sizeSelectionArray;
|
||||
|
||||
|
|
BIN
Code-C/main
BIN
Code-C/main
Binary file not shown.
|
@ -10,18 +10,31 @@ int nRow = 100000;
|
|||
int nCol = 9;
|
||||
double freqEch = 250;
|
||||
|
||||
Pqueue firstRawDataQueue = NULL;
|
||||
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;
|
||||
|
||||
|
||||
int main(int argc , char** argv){
|
||||
|
||||
double period = 1 / freqEch;
|
||||
double invTimeBandWidth = 1 /(nRow * period);
|
||||
period = 1 / freqEch;
|
||||
invTimeBandWidth = 1 /(nRow * period);
|
||||
firstRawDataQueue = NULL; // change this for create empty
|
||||
|
||||
pthread_t rawData;
|
||||
pthread_create(&rawData , NULL, simulateFlux, (void *)&rawData);
|
||||
|
||||
pthread_t power;
|
||||
pthread_create(&power , NULL, threadCalcul, (void *)&power);
|
||||
|
||||
pthread_exit(NULL);
|
||||
|
||||
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
#include "power.h"
|
||||
#include "getArray.h"
|
||||
#include "fileGestion.h"
|
||||
#include "initialParameters.h"
|
||||
#include "queue.h"
|
||||
|
||||
void powerCalculation(long **p, double powerArray[] , int N, int M , double period , double invTimeBandwidth){
|
||||
for(int i = 0; i < M-1; i++){
|
||||
|
@ -16,8 +18,8 @@ void powerCalculation(long **p, double powerArray[] , int N, int M , double peri
|
|||
//printf("%f\n", powerArray[i]);
|
||||
}
|
||||
}
|
||||
bool power(int N , int M, double periode , double invTimeBandwidth){
|
||||
long **p = getRawDataArray(N, M);
|
||||
bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth){
|
||||
long **p = getRawDataArray(rawDataFileName,N, M);
|
||||
double pw[8];
|
||||
if(p !=NULL){
|
||||
powerCalculation(p,pw,N,M,periode,invTimeBandwidth);
|
||||
|
@ -29,3 +31,17 @@ bool power(int N , int M, double periode , double invTimeBandwidth){
|
|||
return false;
|
||||
}
|
||||
}
|
||||
void *threadCalcul(void *vargp){
|
||||
Pqueue rawDataQueue = firstRawDataQueue;
|
||||
printf("print in power of first eleme in queue : \n");
|
||||
printE(firstRawDataQueue);
|
||||
while(rawDataQueue == NULL || getNextE(rawDataQueue) != NULL){
|
||||
//pthread_mutex_lock(&mutex);
|
||||
while(power(gettabChar(rawDataQueue),nRow,nCol,period,invTimeBandWidth) == false){
|
||||
remove(gettabChar(rawDataQueue));
|
||||
rawDataQueue = rmFrstE(rawDataQueue);
|
||||
}
|
||||
//pthread_mutex_unlock(&mutex);
|
||||
//delay(10);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int power(int N , int M, double periode , double timeBandwidth);
|
||||
//bool power(int N , int M, double periode , double timeBandwidth);
|
||||
void *threadCalcul(void *vargp);
|
|
@ -2,8 +2,6 @@
|
|||
#include "initialParameters.h"
|
||||
#include "queue.h"
|
||||
|
||||
int cptData = 0;
|
||||
int cptFile = 1;
|
||||
|
||||
char* convertIntegerToChar(int N)
|
||||
{
|
||||
|
@ -119,9 +117,6 @@ void *simulateFlux(void *vargp){
|
|||
char *fileName = createNewRawDataFileName();
|
||||
FILE *rawDataFile = fopen(fileName,"w+");
|
||||
Pqueue rawDataQueue = createE(strlen(fileName));
|
||||
setTabChar(rawDataQueue , strlen(fileName) , fileName);
|
||||
firstRawDataQueue = rawDataQueue;
|
||||
printE(rawDataQueue);
|
||||
|
||||
while(writeOneRawData(rawDataFile)){
|
||||
if(cptData == nRow){
|
||||
|
@ -132,10 +127,8 @@ void *simulateFlux(void *vargp){
|
|||
char *fileName = createNewRawDataFileName();
|
||||
FILE *rawDataFile = fopen(fileName,"w+");
|
||||
rawDataQueue = addLastQ(rawDataQueue , fileName , strlen(fileName));
|
||||
|
||||
printE(rawDataQueue);
|
||||
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
printE(firstRawDataQueue);
|
||||
}
|
||||
|
|
|
@ -13,5 +13,9 @@ typedef struct {
|
|||
uint8_t octet4;
|
||||
} quartet;
|
||||
|
||||
extern int cptData;
|
||||
extern int cptFile;
|
||||
|
||||
char* convertIntegerToChar(int N);
|
||||
bool writeOneRawData(FILE *f);
|
||||
void *simulateFlux(void *vargp);
|
Loading…
Reference in a new issue