create multiple file of rawdat

This commit is contained in:
quentin.perret 2022-06-09 17:34:24 +02:00
parent a8f1486e2c
commit 446d3b5fd7
16 changed files with 214 additions and 88 deletions

View file

@ -14,6 +14,7 @@
"limits": "c", "limits": "c",
"*.tcc": "c", "*.tcc": "c",
"type_traits": "c", "type_traits": "c",
"simulateflux.h": "c" "simulateflux.h": "c",
"pthread.h": "c"
} }
} }

View file

@ -2,8 +2,6 @@ CC = gcc
all: all:
# rm powerData.csv # rm powerData.csv
$(CC) simulateFlux.c -o simulateFlux # $(CC) simulateFlux.c fileGestion.c getArray.c power.c main.c -lm -o main
$(CC) fileGestion.c getArray.c power.c main.c -lm -o main $(CC) simulateFlux.c main.c -lpthread -o main
./main < ../02400031.TXT
./simulateFlux < ../02400001.TXT
./main

Binary file not shown.

View file

@ -1,5 +1,8 @@
#include "b2hd.h" #include "b2hd.h"
/**
* @brief allow to transform all binary hex data send by the Vegetal Signal captor in a .TXT file into decimal values in a .csv
*
*/
void b2hd() void b2hd()
{ {
int i; int i;

View file

@ -5,6 +5,10 @@
#include <time.h> #include <time.h>
#include <math.h> #include <math.h>
/**
* @brief struct used to stock binary 32 bits data from the captor
*
*/
typedef struct { typedef struct {
uint8_t octet1; uint8_t octet1;
uint8_t octet2; uint8_t octet2;

View file

@ -1,28 +1,38 @@
#include "fileGestion.h" #include "fileGestion.h"
void clearRawData(int N){
/**
* @brief function that delete nRow lign in the beginning of the file rawData.csv . This function is necessary to not deal with the same ligns over and over
*
* @param nRow number of lign in the beginning of the file rawData.csv that has to be delete
*/
void clearRawData(int nRow){
char buffer[256]; char buffer[256];
FILE *f = fopen("newFile.csv","w+"); FILE *f = fopen("newFile.csv","w+");
FILE *g = fopen("rawData.csv","r"); FILE *g = fopen("rawData.csv","r");
for(int i = 0; i < N; i++){ for(int i = 0; i < nRow; i++){ //first the program read the first nRow ligns of the csv file but do nothing
fgets(buffer , sizeof buffer , g); fgets(buffer , sizeof buffer , g);
//printf("Line contaigns: %s" , buffer);
} }
while(1){ while(1){ //then, till the end of the csv file it copy the lign to a new csv : newFile.csv
if(!fgets(buffer,sizeof buffer , g)) break; if(!fgets(buffer,sizeof buffer , g)) break;
fprintf(f,"%s",buffer); fprintf(f,"%s",buffer);
} }
remove("rawData.csv"); rename("newFile.csv", "rawData.csv"); remove("rawData.csv"); rename("newFile.csv", "rawData.csv"); //finally we remove the original file and rename the new one to replace rawData.csv
fclose(f); fclose(g); fclose(f); fclose(g);
} }
/**
void writePowerData(double a[], int N){ * @brief use to write the file powerData.csv that contaign all power calculous results
*
* @param powerArray
* @param nCol size of the power array, correspond to the number of captor used
*/
void writePowerData(double powerArray[], int nCol){
FILE *f = fopen("powerData.csv","a+"); FILE *f = fopen("powerData.csv","a+");
for(int i = 0 ; i < N ; i++){ for(int i = 0 ; i < nCol ; i++){
if( i < N-1){ if( i < nCol-1){
fprintf(f, "%f , ", a[i]); fprintf(f, "%f , ", powerArray[i]);
} else { } else {
fprintf(f, "%f\n", a[i]); fprintf(f, "%f\n", powerArray[i]);
} }
} }
fclose(f); fclose(f);

View file

@ -13,7 +13,7 @@ long **get(int N, int M) /* Allocate the array */
return array; return array;
} }
void fillRawData(long** p, int N, int M) { void fillArrayWithRawData(long** p, int N, int M) {
int i, j; int i, j;
char *buffer; char *buffer;
@ -36,14 +36,27 @@ void fillRawData(long** p, int N, int M) {
//printf("\n\n"); //printf("\n\n");
} }
} }
/**
* @brief print all the element of a bidimensionnal array p of shape : N x M
*/
void printArrayData(long** p, int N, int M) { void printArrayData(long** p, int N, int M) {
int i, j; int i, j;
for(i = 0 ; i < N ; i++){ for(i = 0 ; i < N ; i++){
printf("line n°%d : %d , %d , %d , %d , %d , %d , %d , %d , %d\n" ,i,p[i][0],p[i][1],p[i][2],p[i][3],p[i][4],p[i][5],p[i][6],p[i][7],p[i][8]); printf("line n°%d : " , i);
for(int j = 0 ; j < M ; j++){
printf("%d , " , p[i][j]);
if(j==(M-1)) printf("\n");
} }
} }
}
/**
* @brief verify if all the element of an array are not NULL, return
*
* @param p
* @param N
* @param M
* @return int
*/
int checkArrayFullyFill(long **p, int N , int M){ int checkArrayFullyFill(long **p, int N , int M){
for(int i = 0 ; i < N ; i++){ for(int i = 0 ; i < N ; i++){
if(p[i][0] == '\0'){ return 1; } if(p[i][0] == '\0'){ return 1; }

View file

@ -1,6 +1,10 @@
const int nRow = 100000; #include <stdbool.h>
const int nCol = 9;
const double freqEch = 250;
const double period = 1.0/freqEch; extern int nRow;
const double timeBandwidth = 1.0 /(nRow * period); extern int nCol;
extern double freqEch;
extern int selectionCaptors[];
extern int sizeSelectionArray;
extern bool flag;

Binary file not shown.

View file

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

Binary file not shown.

View file

@ -2,26 +2,26 @@
#include "getArray.h" #include "getArray.h"
#include "fileGestion.h" #include "fileGestion.h"
void powerCalculation(long **p, double a[] , int N, int M , double period , double timeBandwidth){ void powerCalculation(long **p, double powerArray[] , int N, int M , double period , double invTimeBandwidth){
for(int i = 0; i < M-1; i++){ for(int i = 0; i < M-1; i++){
int j = 0; int j = 0;
a[i] = 0; powerArray[i] = 0;
while(j < N-1){ while(j < N-1){
double aire = ( pow(p[j][i+1],2) + pow(p[j+1][i+1],2) ) / 2 * period; double aire = ( pow(p[j][i+1],2) + pow(p[j+1][i+1],2) ) / 2 * period;
//printf("aire [%d,%d] : %f\n",j,i,aire); //printf("aire [%d,%d] : %f\n",j,i,aire);
a[i] += aire; powerArray[i] += aire;
j++; j++;
} }
a[i] *= timeBandwidth; powerArray[i] *= invTimeBandwidth;
//printf("%f\n", a[i]); //printf("%f\n", powerArray[i]);
} }
} }
int power(int N , int M, double periode , double timeBandwidth){ int power(int N , int M, double periode , double invTimeBandwidth){
long **p = getRawDataArray(N, M); long **p = getRawDataArray(N, M);
//printArrayData(p,N,M); //printArrayData(p,N,M);
double pw[8]; double pw[8];
if(p !=NULL){ if(p !=NULL){
powerCalculation(p,pw,N,M,periode,timeBandwidth); powerCalculation(p,pw,N,M,periode,invTimeBandwidth);
writePowerData(pw,8); writePowerData(pw,8);
freeArray(p,N); freeArray(p,N);
return 0; return 0;

Binary file not shown.

View file

@ -1,18 +1,99 @@
#include "simulateFlux.h" #include "simulateFlux.h"
#include "initialParameters.h"
typedef struct {
char *fileName;
} nameFill;
int writeOneRawData(){ 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 buff[26];
char buff2[18]; char buff2[18];
int32_t values[8]; int32_t values[8];
uint32_t valbin[8]; uint32_t valbin[8];
quartet value; quartet value;
FILE *f = fopen("rawData.csv" , "a");
if(fread(&buff, 26, 1, stdin)) { if(fread(&buff, 26, 1, stdin)) {
fprintf(f , "%d,", millis()); fprintf(rawDataFile , "%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 ###...#");
@ -22,8 +103,9 @@ int writeOneRawData(){
strncpy(&buff[8], buff2, 18); strncpy(&buff[8], buff2, 18);
} }
} }
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){
value.octet1 = buff[3*i+1]; value.octet1 = buff[3*i+1];
value.octet2 = buff[3*i+2]; value.octet2 = buff[3*i+2];
value.octet3 = buff[3*i+3]; value.octet3 = buff[3*i+3];
@ -32,37 +114,32 @@ int writeOneRawData(){
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<8){ if(i==maxCapteurNb){
fprintf(f, "%d,", values[i]/256); fprintf(rawDataFile, "%d\n", values[i]/256);
} }
else{ else{
fprintf(f, "%d\n", values[i]/256); 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); fclose(f);
cpt++; // initialiser et/ou modifier la structure ici
sleep(0.004); //simul la freq ech f = createThenOpenNewRawDataFile();
return 0;
}
else {
return 1;
}
}
int simulateFlux(){
while(writeOneRawData()==0){
if(cpt==nRows){
tFlag = 1;
}
while(tFlag == 1){
/*printf("max nRows");
cpt = 0;
tFlag = 0;
break;*/
} }
} }
} }
int main(int argc , char argv[]){
simulateFlux();
}

View file

@ -3,12 +3,9 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <stdbool.h>
#include <time.h> #include <time.h>
int cpt = 0;
int tFlag = 0;
int nRows = 1000;
typedef struct { typedef struct {
uint8_t octet1; uint8_t octet1;
uint8_t octet2; uint8_t octet2;
@ -16,9 +13,12 @@ typedef struct {
uint8_t octet4; uint8_t octet4;
} quartet; } quartet;
int64_t millis() extern struct nameFill;
{
struct timespec now;
timespec_get(&now, TIME_UTC); extern struct rawDataFile;
return ((int64_t) now.tv_sec) * 1000 + ((int64_t) now.tv_nsec) / 1000000;
} nameFill getNameFill(int N);
bool writeOneRawData(FILE *f);
void *simulateFlux(void *vargp);

View file

@ -1,5 +1,5 @@
import numpy as np import numpy as np
#import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import struct import struct
@ -9,7 +9,7 @@ import struct
AllRes = [[],[],[],[],[],[],[],[]] AllRes = [[],[],[],[],[],[],[],[]]
link = "02400007.TXT" link = "02400031.TXT"
f = open(link , "rb")#ouvertuture du fichier txt traiter f = open(link , "rb")#ouvertuture du fichier txt traiter
@ -47,7 +47,7 @@ while True:
f.close()#fermeturedu fichier txt f.close()#fermeturedu fichier txt
"""fig, (ax1, ax2) = plt.subplots(2, 1) #Création de la figure à 2 plots fig, (ax1, ax2) = plt.subplots(2, 1) #Création de la figure à 2 plots
Fe = 250000 #Fréquence d'échantillonage Fe = 250000 #Fréquence d'échantillonage
tstep = 1 / Fe #Time spacing tstep = 1 / Fe #Time spacing
@ -70,8 +70,8 @@ sp = np.fft.fft(y,Fe)
f = np.fft.fftfreq(Fe,tstep) #axe des abscisses: fréquence f = np.fft.fftfreq(Fe,tstep) #axe des abscisses: fréquence
#Définition des courbes des plots #Définition des courbes des plots
ax1.plot(t,y) ax1.plot(t,y) # print y(t)
ax2.plot(f,abs(sp)) ax2.plot(f,abs(sp))
#Lancement de l'affichage du plot #Lancement de l'affichage du plot
plt.show()""" plt.show()