merge struct and fill rawdata gestion

This commit is contained in:
quentin.perret 2022-06-10 10:47:17 +02:00
parent 9ab534b727
commit a7ce786b92
6 changed files with 45 additions and 41 deletions

View file

@ -4,4 +4,5 @@ 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 -o queue
./main < ../02400031.TXT

Binary file not shown.

View file

@ -1,7 +1,9 @@
#include <assert.h>
#include <stdlib.h>
#include "queue.h"
/**
* @brief squeue struct used for queueing string name
* @brief struct queue struct used for queueing string name
*
* @param charLen lenght of tabChar pointeur
* @param tabChar char array pointer
@ -11,9 +13,9 @@ struct queue {
int charLen;
char * tabChar;
Pqueue pNextE;
}squeue;
};
typedef squeue *Pqueue;
typedef struct queue *Pqueue;
/**
* @brief Create Element of queue
@ -22,12 +24,12 @@ typedef squeue *Pqueue;
* @return Pqueue new element created
*/
Pqueue createE(int lenChar){
Pqueue new = (Pqueue) malloc(sizeof(squeue));
Pqueue new = (Pqueue) malloc(sizeof(struct queue));
assert(new);
/* ???? tab char create or give pointer ???*/
new.charLen = lenChar;
new.tabChar = (char *) malloc(lenChar * sizeof(char));
new.pNextE = NULL;
new->charLen = lenChar;
new->tabChar = (char *) malloc(lenChar * sizeof(char));
new->pNextE = NULL;
return new;
}
@ -39,7 +41,7 @@ Pqueue createE(int lenChar){
*/
Pqueue pNextE(Pqueue elem){
assert(elem);
return elem.pNextE
return elem->pNextE;
}
/**
@ -51,13 +53,13 @@ Pqueue pNextE(Pqueue elem){
Pqueue rmLastE(Pqueue elem){
assert(elem);
Pqueue tmp = elem, previous = NULL;
while(elem.pNextE != NULL){
while(elem->pNextE != NULL){
previous = tmp;
tmp = pNextE(tmp);
}
free(tmp.tabChar);
free(tmp->tabChar);
free(tmp);
previous.pNextE = NULL;
previous->pNextE = NULL;
return elem;
}
@ -69,8 +71,8 @@ Pqueue rmLastE(Pqueue elem){
*/
Pqueue rmFrstE(Pqueue elem){
assert(elem);
Pqueue tmp = elem.pNextE;
free(elem.tabChar);
Pqueue tmp = elem->pNextE;
free(elem->tabChar);
free(elem);
return tmp;
}
@ -83,7 +85,7 @@ Pqueue rmFrstE(Pqueue elem){
*/
Pqueue nextDelFrst(Pqueue elem){
assert(elem);
Pqueue tmp = elem.pNextE;
Pqueue tmp = elem->pNextE;
rmFrstE(elem);
return tmp;
}
@ -100,13 +102,13 @@ Pqueue addLastQ(Pqueue elem, const char* str, int len){
assert(elem);
assert(str);
Pqueue tmp = elem, previous = NULL;
while(elem.pNextE != NULL){
while(elem->pNextE != NULL){
previous = tmp;
tmp = pNextE(tmp);
}
tmp = createE(len);
tmp.tabChar = str;
tmp.charLen = len;
tmp->tabChar = str;
tmp->charLen = len;
return tmp;
}

1
Code-C/queue.h Normal file
View file

@ -0,0 +1 @@
typedef struct queue *Pqueue;

View file

@ -29,13 +29,13 @@ char* convertIntegerToChar(int N)
return (char*)arr;
}
FILE *createThenOpenNewRawDataFile(){
char *createNewRawDataFileName(){
char *fileName = "RawData";
char *extension = ".csv";
char *fileNumber = convertIntegerToChar(cptFile);
char fileNameNumber[strlen(fileName)+strlen(fileNumber)];
char fullFillName[strlen(fileNameNumber)+strlen(extension)];
char *fullFillName = malloc( (strlen(fileNameNumber)+strlen(extension)) * sizeof(char*) );
strcpy( fileNameNumber, fileName );
strcat( fileNameNumber, fileNumber );
@ -43,15 +43,7 @@ FILE *createThenOpenNewRawDataFile(){
strcpy( fullFillName, fileNameNumber );
strcat( fullFillName, extension );
FILE *file = fopen(fullFillName,"w+");
return file;
}
int64_t millis()
{
struct timespec now;
timespec_get(&now, TIME_UTC);
return ((int64_t) now.tv_sec) * 1000 + ((int64_t) now.tv_nsec) / 1000000;
return fullFillName;
}
int intInArray(int number , int *array , int N){
@ -68,7 +60,13 @@ int maxInArray(int *array , int N){
return max;
}
bool writeOneRawData(FILE *rawDataFile){
int64_t millis()
{
struct timespec now;
timespec_get(&now, TIME_UTC);
return ((int64_t) now.tv_sec) * 1000 + ((int64_t) now.tv_nsec) / 1000000;
}
bool writeOneRawData(FILE *rawDataFill){
char buff[26];
char buff2[18];
int32_t values[8];
@ -76,8 +74,8 @@ bool writeOneRawData(FILE *rawDataFile){
quartet value;
if(fread(&buff, 26, 1, stdin)) {
fprintf(rawDataFile , "%d,", millis());
if(fread(&buff, 26, 1, stdin)) {
fprintf(rawDataFill , "%d,", millis());
if (strncmp(buff, "#################\n", (size_t)18) == 0) {
if (!(fread(&buff2, 18, 1, stdin))) {
fprintf(stderr, "Erreur lecture après ###...#");
@ -87,7 +85,7 @@ bool writeOneRawData(FILE *rawDataFile){
strncpy(&buff[8], buff2, 18);
}
}
int maxCapteurNb = maxInArray(selectionCaptors,sizeSelectionArray);
int maxCApteurNb = maxInArray(selectionCaptors,sizeSelectionArray);
for (int i = 1; i < 9; i++){
if(intInArray(i,selectionCaptors,sizeSelectionArray)==0){
value.octet1 = buff[3*i+1];
@ -98,32 +96,34 @@ bool writeOneRawData(FILE *rawDataFile){
valbin[i] = buff[3*i+1]*256*256*256 + buff[3*i+2]*256*256 + buff[3*i+3]*256;
memcpy(&values[i], &valbin[i], sizeof(uint32_t));
if(i==maxCapteurNb){
fprintf(rawDataFile, "%d\n", values[i]/256);
if(i==maxCApteurNb){
fprintf(rawDataFill, "%d\n", values[i]/256);
}
else{
fprintf(rawDataFile, "%d,", values[i]/256);
fprintf(rawDataFill, "%d,", values[i]/256);
}
}
}
cptData++;
//sleep(0.004); //simul la freq ech
sleep(0.004); //simul la freq ech
return true;
}
else {
return false;
}
}
void *simulateFlux(void *vargp){
FILE *f = createThenOpenNewRawDataFile();
while(writeOneRawData(f)){
char *fillName = createNewRawDataFileName();
FILE *rawDataFill = fopen(fillName,"w+");
while(writeOneRawData(rawDataFill)){
if(cptData == nRow){
cptData = 0;
cptFile++;
fclose(f);
// initialiser et/ou modifier la structure ici
f = createThenOpenNewRawDataFile();
fillName = createNewRawDataFileName();
FILE *rawDataFill = fopen(fillName,"w+");
}
}
}

View file