implement queue in code

This commit is contained in:
quentin.perret 2022-06-10 15:05:04 +02:00
parent 1f350d095d
commit 9386dd5364
7 changed files with 71 additions and 13 deletions

View file

@ -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) simulateFlux.c main.c -lpthread -o main
$(CC) queue.c simulateFlux.c main.c -lpthread -o main
# $(CC) queue.c -o queue
./main < ../02400031.TXT

View file

@ -1,4 +1,5 @@
#include <stdbool.h>
#include "queue.h"
extern bool rawDataWriteFlag , stopFlag;
extern int nRow;
@ -8,4 +9,4 @@ extern double freqEch;
extern int selectionCaptors[];
extern int sizeSelectionArray;
extern bool flag;
extern Pqueue firstRawDataQueue;

Binary file not shown.

View file

@ -1,16 +1,17 @@
#include <pthread.h>
#include <stdbool.h>
#include "simulateFlux.h"
#include "getArray.h"
#include "fileGestion.h"
#include "power.h"
#include "initialParameters.h"
#include "queue.h"
bool rawDataWriteFlag = 0, stopFlag = 0;
int nRow = 100000;
int nCol = 9;
double freqEch = 250;
Pqueue firstRawDataQueue = NULL;
int selectionCaptors[] = {1,2,3,4,5,6,7,8};
int sizeSelectionArray = 8;
@ -18,9 +19,10 @@ int main(int argc , char** argv){
double period = 1 / freqEch;
double invTimeBandWidth = 1 /(nRow * period);
Pqueue new = createE
/*
pthread_t rawData;
pthread_create(&rawData , NULL, simulateFlux, (void *)&rawData);
pthread_exit(NULL);
while(power(nRow,nCol,period,invTimeBandWidth)){}
*/
}

View file

@ -1,4 +1,5 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "queue.h"
@ -23,7 +24,7 @@ typedef struct queue *Pqueue;
* @param lenChar size of char array that will be created
* @return Pqueue new element created
*/
Pqueue createE(int lenChar){
Pqueue createE(int lenChar , char* _tabChar){
Pqueue new = (Pqueue) malloc(sizeof(struct queue));
assert(new);
/* ???? tab char create or give pointer ???*/
@ -39,11 +40,33 @@ Pqueue createE(int lenChar){
* @param elem current element
* @return Pqueue next element
*/
Pqueue pNextE(Pqueue elem){
Pqueue getNextE(Pqueue elem){
assert(elem);
return elem->pNextE;
}
int getCharLen(Pqueue elem){
assert(elem);
return elem->charLen;
}
char *gettabChar(Pqueue elem){
assert(elem);
return elem->tabChar;
}
Pqueue setCharLen(Pqueue elem , int _charLen){
assert(elem);
elem->charLen = _charLen;
}
Pqueue setTabChar(Pqueue elem , int _charLen , char *_tabChar){
assert(elem);
elem->charLen = _charLen;
elem->tabChar = (char *) malloc(_charLen * sizeof(char));
elem->tabChar = _tabChar;
}
/**
* @brief remove and free the last element of queue
*
@ -55,7 +78,7 @@ Pqueue rmLastE(Pqueue elem){
Pqueue tmp = elem, previous = NULL;
while(elem->pNextE != NULL){
previous = tmp;
tmp = pNextE(tmp);
tmp = getNextE(tmp);
}
free(tmp->tabChar);
free(tmp);
@ -104,7 +127,7 @@ Pqueue addLastQ(Pqueue elem, const char* str, int len){
Pqueue tmp = elem, previous = NULL;
while(elem->pNextE != NULL){
previous = tmp;
tmp = pNextE(tmp);
tmp = getNextE(tmp);
}
tmp = createE(len);
tmp->tabChar = str;
@ -112,3 +135,14 @@ Pqueue addLastQ(Pqueue elem, const char* str, int len){
return tmp;
}
void printE(Pqueue elem){
Pqueue next = getNextE(elem);
printf("File Name : %s \n(size of the file name : %d)\n",elem -> tabChar , elem -> charLen );
if(next != NULL){
printf("Next File : %s\n", next ->tabChar);
}
else{
printf("No nextFile existing\n");
}
}

View file

@ -1 +1,13 @@
typedef struct queue *Pqueue;
Pqueue createE(int lenChar);
Pqueue createEEmpty(); //create a new element but all variables in are null, use to create the first element of the queue in the main before define the elements in
// seter /getter pour la struct
// constructeur avec 2 paramètres : strlen et tabchar
Pqueue getNextE(Pqueue elem);
Pqueue setCharLen(Pqueue elem , int _charLen);
Pqueue setTabChar(Pqueue elem , int _charLen , char *_tabChar);
Pqueue rmLastE(Pqueue elem);
Pqueue rmFrstE(Pqueue elem);
Pqueue nextDelFrst(Pqueue elem);
Pqueue addLastQ(Pqueue elem, const char* str, int len);
void printE(Pqueue elem);

View file

@ -1,5 +1,6 @@
#include "simulateFlux.h"
#include "initialParameters.h"
#include "queue.h"
int cptData = 0;
int cptFile = 1;
@ -30,7 +31,7 @@ char* convertIntegerToChar(int N)
}
char *createNewRawDataFileName(){
char *fileName = "RawData";
char *fileName = "../RawDataFiles/RawData";
char *extension = ".csv";
char *fileNumber = convertIntegerToChar(cptFile);
@ -117,6 +118,11 @@ bool writeOneRawData(FILE *rawDataFile){
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){
fclose(rawDataFile);
@ -124,9 +130,12 @@ void *simulateFlux(void *vargp){
cptFile++;
//create struct here
char *fileName = createNewRawDataFileName();
printf(fileName);
printf("\n");
FILE *rawDataFile = fopen(fileName,"w+");
rawDataQueue = addLastQ(rawDataQueue , fileName , strlen(fileName));
printE(rawDataQueue);
}
}
printf("\n");
printE(firstRawDataQueue);
}