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",
"*.tcc": "c",
"type_traits": "c",
"simulateflux.h": "c"
"simulateflux.h": "c",
"pthread.h": "c"
}
}

View file

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

Binary file not shown.

View file

@ -1,5 +1,8 @@
#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()
{
int i;

View file

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

View file

@ -1,28 +1,38 @@
#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];
FILE *f = fopen("newFile.csv","w+");
FILE *g = fopen("rawData.csv","r");
for(int i = 0; i < N; i++){
fgets(buffer , sizeof buffer , g);
//printf("Line contaigns: %s" , buffer);
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);
}
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;
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);
}
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+");
for(int i = 0 ; i < N ; i++){
if( i < N-1){
fprintf(f, "%f , ", a[i]);
for(int i = 0 ; i < nCol ; i++){
if( i < nCol-1){
fprintf(f, "%f , ", powerArray[i]);
} else {
fprintf(f, "%f\n", a[i]);
fprintf(f, "%f\n", powerArray[i]);
}
}
fclose(f);

View file

@ -13,7 +13,7 @@ long **get(int N, int M) /* Allocate the array */
return array;
}
void fillRawData(long** p, int N, int M) {
void fillArrayWithRawData(long** p, int N, int M) {
int i, j;
char *buffer;
@ -36,14 +36,27 @@ void fillRawData(long** p, int N, int M) {
//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) {
int i, j;
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){
for(int i = 0 ; i < N ; i++){
if(p[i][0] == '\0'){ return 1; }

View file

@ -1,6 +1,10 @@
const int nRow = 100000;
const int nCol = 9;
const double freqEch = 250;
#include <stdbool.h>
const double period = 1.0/freqEch;
const double timeBandwidth = 1.0 /(nRow * period);
extern int nRow;
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 "fileGestion.h"
#include "power.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){
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 "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++){
int j = 0;
a[i] = 0;
powerArray[i] = 0;
while(j < N-1){
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);
a[i] += aire;
powerArray[i] += aire;
j++;
}
a[i] *= timeBandwidth;
//printf("%f\n", a[i]);
powerArray[i] *= invTimeBandwidth;
//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);
//printArrayData(p,N,M);
double pw[8];
if(p !=NULL){
powerCalculation(p,pw,N,M,periode,timeBandwidth);
powerCalculation(p,pw,N,M,periode,invTimeBandwidth);
writePowerData(pw,8);
freeArray(p,N);
return 0;

Binary file not shown.

View file

@ -1,18 +1,99 @@
#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 buff2[18];
int32_t values[8];
uint32_t valbin[8];
quartet value;
FILE *f = fopen("rawData.csv" , "a");
if(fread(&buff, 26, 1, stdin)) {
fprintf(f , "%d,", millis());
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 ###...#");
@ -22,47 +103,43 @@ int writeOneRawData(){
strncpy(&buff[8], buff2, 18);
}
}
int maxCapteurNb = maxInArray(selectionCaptors,sizeSelectionArray);
for (int i = 1; i < 9; i++){
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(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<8){
fprintf(f, "%d,", values[i]/256);
}
else{
fprintf(f, "%d\n", values[i]/256);
if(i==maxCapteurNb){
fprintf(rawDataFile, "%d\n", values[i]/256);
}
else{
fprintf(rawDataFile, "%d,", values[i]/256);
}
}
}
fclose(f);
cpt++;
sleep(0.004); //simul la freq ech
return 0;
cptData++;
//sleep(0.004); //simul la freq ech
return true;
}
else {
return 1;
return false;
}
}
void *simulateFlux(void *vargp){
int simulateFlux(){
while(writeOneRawData()==0){
if(cpt==nRows){
tFlag = 1;
}
while(tFlag == 1){
/*printf("max nRows");
cpt = 0;
tFlag = 0;
break;*/
FILE *f = createThenOpenNewRawDataFile();
while(writeOneRawData(f)){
if(cptData == nRow){
cptData = 0;
cptFile++;
fclose(f);
// initialiser et/ou modifier la structure ici
f = createThenOpenNewRawDataFile();
}
}
}
int main(int argc , char argv[]){
simulateFlux();
}

View file

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

View file

@ -1,5 +1,5 @@
import numpy as np
#import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
import struct
@ -9,7 +9,7 @@ import struct
AllRes = [[],[],[],[],[],[],[],[]]
link = "02400007.TXT"
link = "02400031.TXT"
f = open(link , "rb")#ouvertuture du fichier txt traiter
@ -47,7 +47,7 @@ while True:
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
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
#Définition des courbes des plots
ax1.plot(t,y)
ax1.plot(t,y) # print y(t)
ax2.plot(f,abs(sp))
#Lancement de l'affichage du plot
plt.show()"""
plt.show()