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 # rm powerData.csv
# $(CC) simulateFlux.c fileGestion.c getArray.c power.c main.c -lm -o main # $(CC) simulateFlux.c fileGestion.c getArray.c power.c main.c -lm -o main
$(CC) simulateFlux.c main.c -lpthread -o main $(CC) simulateFlux.c main.c -lpthread -o main
# $(CC) queue.c -o queue
./main < ../02400031.TXT ./main < ../02400031.TXT

Binary file not shown.

View file

@ -1,7 +1,9 @@
#include <assert.h> #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 charLen lenght of tabChar pointeur
* @param tabChar char array pointer * @param tabChar char array pointer
@ -11,9 +13,9 @@ struct queue {
int charLen; int charLen;
char * tabChar; char * tabChar;
Pqueue pNextE; Pqueue pNextE;
}squeue; };
typedef squeue *Pqueue; typedef struct queue *Pqueue;
/** /**
* @brief Create Element of queue * @brief Create Element of queue
@ -22,12 +24,12 @@ typedef squeue *Pqueue;
* @return Pqueue new element created * @return Pqueue new element created
*/ */
Pqueue createE(int lenChar){ Pqueue createE(int lenChar){
Pqueue new = (Pqueue) malloc(sizeof(squeue)); Pqueue new = (Pqueue) malloc(sizeof(struct queue));
assert(new); assert(new);
/* ???? tab char create or give pointer ???*/ /* ???? tab char create or give pointer ???*/
new.charLen = lenChar; new->charLen = lenChar;
new.tabChar = (char *) malloc(lenChar * sizeof(char)); new->tabChar = (char *) malloc(lenChar * sizeof(char));
new.pNextE = NULL; new->pNextE = NULL;
return new; return new;
} }
@ -39,7 +41,7 @@ Pqueue createE(int lenChar){
*/ */
Pqueue pNextE(Pqueue elem){ Pqueue pNextE(Pqueue elem){
assert(elem); assert(elem);
return elem.pNextE return elem->pNextE;
} }
/** /**
@ -51,13 +53,13 @@ Pqueue pNextE(Pqueue elem){
Pqueue rmLastE(Pqueue elem){ Pqueue rmLastE(Pqueue elem){
assert(elem); assert(elem);
Pqueue tmp = elem, previous = NULL; Pqueue tmp = elem, previous = NULL;
while(elem.pNextE != NULL){ while(elem->pNextE != NULL){
previous = tmp; previous = tmp;
tmp = pNextE(tmp); tmp = pNextE(tmp);
} }
free(tmp.tabChar); free(tmp->tabChar);
free(tmp); free(tmp);
previous.pNextE = NULL; previous->pNextE = NULL;
return elem; return elem;
} }
@ -69,8 +71,8 @@ Pqueue rmLastE(Pqueue elem){
*/ */
Pqueue rmFrstE(Pqueue elem){ Pqueue rmFrstE(Pqueue elem){
assert(elem); assert(elem);
Pqueue tmp = elem.pNextE; Pqueue tmp = elem->pNextE;
free(elem.tabChar); free(elem->tabChar);
free(elem); free(elem);
return tmp; return tmp;
} }
@ -83,7 +85,7 @@ Pqueue rmFrstE(Pqueue elem){
*/ */
Pqueue nextDelFrst(Pqueue elem){ Pqueue nextDelFrst(Pqueue elem){
assert(elem); assert(elem);
Pqueue tmp = elem.pNextE; Pqueue tmp = elem->pNextE;
rmFrstE(elem); rmFrstE(elem);
return tmp; return tmp;
} }
@ -100,13 +102,13 @@ Pqueue addLastQ(Pqueue elem, const char* str, int len){
assert(elem); assert(elem);
assert(str); assert(str);
Pqueue tmp = elem, previous = NULL; Pqueue tmp = elem, previous = NULL;
while(elem.pNextE != NULL){ while(elem->pNextE != NULL){
previous = tmp; previous = tmp;
tmp = pNextE(tmp); tmp = pNextE(tmp);
} }
tmp = createE(len); tmp = createE(len);
tmp.tabChar = str; tmp->tabChar = str;
tmp.charLen = len; tmp->charLen = len;
return tmp; 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; return (char*)arr;
} }
FILE *createThenOpenNewRawDataFile(){ char *createNewRawDataFileName(){
char *fileName = "RawData"; char *fileName = "RawData";
char *extension = ".csv"; char *extension = ".csv";
char *fileNumber = convertIntegerToChar(cptFile); char *fileNumber = convertIntegerToChar(cptFile);
char fileNameNumber[strlen(fileName)+strlen(fileNumber)]; char fileNameNumber[strlen(fileName)+strlen(fileNumber)];
char fullFillName[strlen(fileNameNumber)+strlen(extension)]; char *fullFillName = malloc( (strlen(fileNameNumber)+strlen(extension)) * sizeof(char*) );
strcpy( fileNameNumber, fileName ); strcpy( fileNameNumber, fileName );
strcat( fileNameNumber, fileNumber ); strcat( fileNameNumber, fileNumber );
@ -43,15 +43,7 @@ FILE *createThenOpenNewRawDataFile(){
strcpy( fullFillName, fileNameNumber ); strcpy( fullFillName, fileNameNumber );
strcat( fullFillName, extension ); strcat( fullFillName, extension );
FILE *file = fopen(fullFillName,"w+"); return fullFillName;
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;
} }
int intInArray(int number , int *array , int N){ int intInArray(int number , int *array , int N){
@ -68,7 +60,13 @@ int maxInArray(int *array , int N){
return max; 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 buff[26];
char buff2[18]; char buff2[18];
int32_t values[8]; int32_t values[8];
@ -77,7 +75,7 @@ bool writeOneRawData(FILE *rawDataFile){
if(fread(&buff, 26, 1, stdin)) { if(fread(&buff, 26, 1, stdin)) {
fprintf(rawDataFile , "%d,", millis()); fprintf(rawDataFill , "%d,", millis());
if (strncmp(buff, "#################\n", (size_t)18) == 0) { if (strncmp(buff, "#################\n", (size_t)18) == 0) {
if (!(fread(&buff2, 18, 1, stdin))) { if (!(fread(&buff2, 18, 1, stdin))) {
fprintf(stderr, "Erreur lecture après ###...#"); fprintf(stderr, "Erreur lecture après ###...#");
@ -87,7 +85,7 @@ bool writeOneRawData(FILE *rawDataFile){
strncpy(&buff[8], buff2, 18); strncpy(&buff[8], buff2, 18);
} }
} }
int maxCapteurNb = maxInArray(selectionCaptors,sizeSelectionArray); int maxCApteurNb = maxInArray(selectionCaptors,sizeSelectionArray);
for (int i = 1; i < 9; i++){ for (int i = 1; i < 9; i++){
if(intInArray(i,selectionCaptors,sizeSelectionArray)==0){ if(intInArray(i,selectionCaptors,sizeSelectionArray)==0){
value.octet1 = buff[3*i+1]; 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; 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)); 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{ else{
fprintf(rawDataFile, "%d,", values[i]/256); fprintf(rawDataFill, "%d,", values[i]/256);
} }
} }
} }
cptData++; cptData++;
//sleep(0.004); //simul la freq ech sleep(0.004); //simul la freq ech
return true; return true;
} }
else { else {
return false; return false;
} }
} }
void *simulateFlux(void *vargp){ void *simulateFlux(void *vargp){
FILE *f = createThenOpenNewRawDataFile(); char *fillName = createNewRawDataFileName();
while(writeOneRawData(f)){ FILE *rawDataFill = fopen(fillName,"w+");
while(writeOneRawData(rawDataFill)){
if(cptData == nRow){ if(cptData == nRow){
cptData = 0; cptData = 0;
cptFile++; cptFile++;
fclose(f); fillName = createNewRawDataFileName();
// initialiser et/ou modifier la structure ici FILE *rawDataFill = fopen(fillName,"w+");
f = createThenOpenNewRawDataFile();
} }
} }
} }

View file