#include "simulateFlux.h" #include "initialParameters.h" typedef struct { char *fileName; } nameFill; typedef struct { nameFill curentFile; nameFill *nextFile; }rawDataFile; nameFill getNameFill(int N){ nameFill file; file.fileName = (char *) malloc(N*sizeof(char *)); return file; } int cptData = 0; int cptFile = 1; nameFill FirstFile; char* convertIntegerToChar(int N) { // Count digits in number N int m = N; int digit = 0; while (m) { digit++; m /= 10; } char* arr; char arr1[digit]; arr = (char*)malloc(digit); int index = 0; while (N) { arr1[++index] = N % 10 + '0'; N /= 10; } int i; for (i = 0; i < index; i++) { arr[i] = arr1[index - i]; } arr[i] = '\0'; return (char*)arr; } FILE *createThenOpenNewRawDataFile(){ char *fileName = "RawData"; char *extension = ".csv"; char *fileNumber = convertIntegerToChar(cptFile); char fileNameNumber[strlen(fileName)+strlen(fileNumber)]; char fullFillName[strlen(fileNameNumber)+strlen(extension)]; strcpy( fileNameNumber, fileName ); strcat( fileNameNumber, fileNumber ); 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; } int intInArray(int number , int *array , int N){ for(int i = 0 ; i < N ; i++){ if(array[i] == number) return 0; } return -1; } int maxInArray(int *array , int N){ int max = 0; for(int i = 0 ; i < N ; i++){ if(array[i]>max) max = array[i]; } return max; } bool writeOneRawData(FILE *rawDataFile){ char buff[26]; char buff2[18]; int32_t values[8]; uint32_t valbin[8]; quartet value; if(fread(&buff, 26, 1, stdin)) { fprintf(rawDataFile , "%d,", millis()); if (strncmp(buff, "#################\n", (size_t)18) == 0) { if (!(fread(&buff2, 18, 1, stdin))) { fprintf(stderr, "Erreur lecture après ###...#"); return 2; } else { strncpy(buff, &buff[18], 8); strncpy(&buff[8], buff2, 18); } } int maxCapteurNb = maxInArray(selectionCaptors,sizeSelectionArray); for (int i = 1; i < 9; i++){ if(intInArray(i,selectionCaptors,sizeSelectionArray)==0){ value.octet1 = buff[3*i+1]; value.octet2 = buff[3*i+2]; value.octet3 = buff[3*i+3]; value.octet4 = 0; 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); } else{ fprintf(rawDataFile, "%d,", values[i]/256); } } } cptData++; //sleep(0.004); //simul la freq ech return true; } else { return false; } } void *simulateFlux(void *vargp){ FILE *f = createThenOpenNewRawDataFile(); while(writeOneRawData(f)){ if(cptData == nRow){ cptData = 0; cptFile++; fclose(f); // initialiser et/ou modifier la structure ici f = createThenOpenNewRawDataFile(); } } }