Compare commits

...

38 commits

Author SHA1 Message Date
quentin.perret 33115049f6 threads clean , captors choice ok 2022-06-15 10:49:21 +02:00
quentin.perret f9a6f00972 trying to debug power 2022-06-14 18:01:52 +02:00
quentin.perret 9bb5e5e99d Merge branch 'SimulFlux' 2022-06-14 11:42:00 +02:00
theo.canaud 16948e901b Courbe seul 2022-06-14 11:16:54 +02:00
quentin.perret 64a50327e7 comment c code 2022-06-14 10:46:12 +02:00
quentin.perret 2080c37eef comment c code 2022-06-14 10:46:04 +02:00
quentin.perret 05a9142c7e add average thread 2022-06-14 10:24:59 +02:00
quentin.perret 6cd7513501 remove file during traitment 2022-06-13 17:35:00 +02:00
quentin.perret ce37306f65 thread calcul ok 2022-06-13 17:24:53 +02:00
quentin.perret 52bded6534 almost debug second thread 2022-06-13 17:11:16 +02:00
theo.canaud 13b07003ee Merge branch 'master' of https://git.cohabit.fr/pgp/Traitement-signal-plantes 2022-06-13 15:24:05 +02:00
theo.canaud 8906063068 Tableau une seul courbe 2022-06-13 15:22:50 +02:00
theo.canaud c0e70cec4e Merge branch 'master' of https://git.cohabit.fr/pgp/Traitement-signal-plantes 2022-06-13 15:22:05 +02:00
quentin.perret af985c81df Merge branch 'SimulFlux' 2022-06-13 15:20:21 +02:00
quentin.perret bfe730e0ba debug rawdatafile close 2022-06-13 15:19:05 +02:00
quentin.perret 2e1462a0ff adapt code for pack 2022-06-13 15:12:07 +02:00
quentin.perret ceacb1c512 Merge branch 'SimulFlux' 2022-06-13 15:10:22 +02:00
theo.canaud cde4670a1c Tableau de données avec une seul courbe 2022-06-13 15:07:02 +02:00
quentin.perret 75639d3c4a maj queue debug simul 2022-06-13 15:03:51 +02:00
quentin.perret b0fa82b06e finalize merge 2022-06-10 17:25:33 +02:00
quentin.perret 6899115d94 Merge branch 'SimulFlux' of https://git.cohabit.fr/pgp/Traitement-signal-plantes into SimulFlux 2022-06-10 17:23:32 +02:00
quentin.perret 4d19b6539e prepare power thread 2022-06-10 17:22:01 +02:00
Aurélien Gauthier 925c42ba2c merge real 2022-06-10 17:21:16 +02:00
Aurélien Gauthier 012de80d21 merge 2022-06-10 17:21:08 +02:00
Aurélien Gauthier 3e550297d6 add createEmpty and modify struct queue 2022-06-10 17:20:10 +02:00
quentin.perret 2e7253c43c queue ok for flux 2022-06-10 15:50:27 +02:00
quentin.perret 8c9de2d97d add comment in queue.h 2022-06-10 15:16:13 +02:00
quentin.perret 9386dd5364 implement queue in code 2022-06-10 15:05:04 +02:00
quentin.perret 1f350d095d debug dtatFill gestion 2022-06-10 11:13:03 +02:00
quentin.perret a7ce786b92 merge struct and fill rawdata gestion 2022-06-10 10:47:17 +02:00
Aurélien Gauthier 9ab534b727 add files queue c and h 2022-06-10 10:15:14 +02:00
Aurélien Gauthier 98e11c2443 merge struct queue file and functions 2022-06-10 10:11:57 +02:00
Aurélien Gauthier 023b77aeba struct queue file and functions 2022-06-10 10:10:28 +02:00
quentin.perret 46e02c1d6d add bool in code 2022-06-09 17:56:45 +02:00
quentin.perret 446d3b5fd7 create multiple file of rawdat 2022-06-09 17:34:24 +02:00
quentin.perret a8f1486e2c add flag 2022-06-08 12:29:34 +02:00
quentin.perret 38366241a1 add flux 2022-06-08 11:25:19 +02:00
theo.canaud 926016943f Ajout de la branch courbe 2022-06-07 16:22:49 +02:00
25 changed files with 818 additions and 88 deletions

View file

@ -13,6 +13,8 @@
"math.h": "c",
"limits": "c",
"*.tcc": "c",
"type_traits": "c"
"type_traits": "c",
"simulateflux.h": "c",
"pthread.h": "c"
}
}

5
Code-C/.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,5 @@
{
"files.associations": {
"power.h": "c"
}
}

View file

@ -1,10 +1,4 @@
CC = gcc
all:
# rm powerData.csv
$(CC) b2hd.c -o b2hd
$(CC) fileGestion.c getArray.c power.c main.c -lm -o main
# getArray.c fileGestion.c power.c main.c -o main
./b2hd < ../02400001.TXT > rawData.csv
./main
$(CC) -g fileGestion.c getArray.c average.c power.c queue.c simulateFlux.c main.c -lm -lpthread -o main

38
Code-C/average.c Normal file
View file

@ -0,0 +1,38 @@
#include "average.h"
#include "getArray.h"
#include "fileGestion.h"
#include "initialParameters.h"
#include "queue.h"
/**
* @brief realize the average calcul
*
* @param p array with all the values that will be used for the calcul
* @param averageArray array where results are stocked
*/
void averageCalculation(long **p, double averageArray[]){
for(int i = 1; i < nCol; i++){
int j = 0;
averageArray[i] = 0;
while(j < nRow -1){
averageArray[i] += p[i][j];
j++;
}
averageArray[i] /= nRow;
//printf("%f\n", powerArray[i]);
}
}
/**
* @brief function that realize all the action to write one lign in the file averageData.csv
*
* @param rawDataFileName name of the raw data file to use to realize the calcul
*/
void average(char* rawDataFileName){
long **p = getRawDataArray(rawDataFileName);
double aver[nCol -1];
if(p !=NULL){
averageCalculation(p,aver);
appendDataInFile("averageData.csv",aver,nCol-1);
freeArray(p,nRow);
}
}

4
Code-C/average.h Normal file
View file

@ -0,0 +1,4 @@
#include <math.h>
#include <stdbool.h>
void average(char* rawDataFileName);

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;
@ -40,6 +43,8 @@ void b2hd()
}
}
}
int main(int argc , char** argv){
b2hd();
}

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,27 +1,39 @@
#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){
FILE *f = fopen("powerData.csv","a+");
for(int i = 0 ; i < N ; i++){
if( i < N-1){
fprintf(f, "%f , ", a[i]);
/**
* @brief use to write one lign in the file "fileName"
*
* @param array array that contaign all the values to write in the file
* @param nCol size of the array (correspond to the number of captor used)
*/
void appendDataInFile(char* fileName , double array[], int nCol){
FILE *f = fopen(fileName,"a+");
for(int i = 0 ; i < nCol ; i++){
if( i < nCol-1){
fprintf(f, "%f , ", array[i]);
} else {
fprintf(f, "%f\n", a[i]);
fprintf(f, "%f\n", array[i]);
}
}
fclose(f);
}

View file

@ -3,5 +3,6 @@
#include <stdint.h>
#include <stdlib.h>
void clearRawData(int N);
void writePowerData(double a[], int N);
void appendDataInFile(char* fileName , double a[], int N);

View file

@ -1,5 +1,6 @@
#include "getArray.h"
#include "fileGestion.h"
#include "initialParameters.h"
//#include <string.h>
long **get(int N, int M) /* Allocate the array */
@ -13,63 +14,85 @@ long **get(int N, int M) /* Allocate the array */
return array;
}
void fillRawData(long** p, int N, int M) {
void fillArrayWithRawData(char *rawDataFileName,long** p, int N, int M) {
int i, j;
char *buffer;
size_t bufsize = 200;
buffer = (char *)malloc(bufsize * sizeof(char));
char* token;
FILE *f = fopen("rawData.csv","r");
FILE *f = fopen(rawDataFileName,"r");
for(i = 0 ; i < N ; i++){
if (!getline(&buffer, &bufsize, f)) break; // condition d'arret de la boucle si fichier fini
//printf("buffer : %s token : ",buffer);
j = 0;
while((token = strsep(&buffer,",")) != NULL){ // séparation valeur par virgule initiale : csv
//printf(token);
p[i][j] = atoi(token);
//printf("%d,", p[i][j]);
//printf("%d, " , p[i][j]);
j++;
}
//printf("\n\n");
}
}
fclose(f);
}
/**
* @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");
}
}
int checkArrayFullyFill(long **p, int N , int M){
for(int i = 0 ; i < N ; i++){
if(p[i][0] == '\0'){ return 1; }
}
return 0;
}
/**
* @brief verify if all the element of an array are not NULL, return
*
* @param p array to check
* @param N number of rows in p
* @param M number of columns in p
* @return true if the array contaign no NULL element
* @return false if at least one element is null
*/
bool checkArrayFullyFill(long **p, int N){
for(int i = 0 ; i < N ; i++){
if(p[i][0] == '\0'){ return false; }
}
return true;
}
/**
* @brief free memory allocate to an array p
*
* @param p array to free memory
* @param N number of rows in array
*/
void freeArray(long **p, int N) {
int i;
for(i = 0 ; i < N ; i++)
for(int i = 0 ; i < N ; i++){
free(p[i]);
}
free(p);
}
long **getRawDataArray(int N , int M){
/**
* @brief Get the Raw Data Array object
*
* @param rawDataFileName name of the file to use to file the array
* @param N numbers of rows to have i the array
* @param M numbers of columns to have i the array
* @return long** the array fill with raw data
*/
long **getRawDataArray(char* rawDataFileName){
long **p;
p = get(N, M);
fillRawData(p ,N, M);
//printf("before test\n");
if(checkArrayFullyFill(p,N,M)==0){
//printf("after test 0\n");
clearRawData(N);
p = get(nRow, nCol);
fillArrayWithRawData(rawDataFileName,p ,nRow, nCol);
//if(checkArrayFullyFill(p,nRow)){
//clearRawData(N);
return p;
}
/*}
else{
//printf("after test 1\n");
return NULL;
}
}*/
}

View file

@ -2,9 +2,10 @@
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <inttypes.h>
long **getRawDataArray();
long **getRawDataArray(char *rawDataFileName);
void printArrayData(long** p, int N, int M);
void freeArray(long **p, int N);
int checkArrayFullyFill(long **p, int N , int M);
bool checkArrayFullyFill(long **p, int N );

View file

@ -1,6 +1,16 @@
const int nRow = 100000;
const int nCol = 9;
const double freqEch = 250;
#include <stdbool.h>
#include "queue.h"
const double period = 1.0/freqEch;
const double timeBandwidth = 1.0 /(nRow * period);
extern bool rawDataWriteFlag;
extern int nRow;
extern int nCol;
extern double freqEch;
extern int cptFile;
extern double period;
extern double invTimeBandWidth;
extern bool selectionCaptors[];
extern Pqueue firstRawDataQueue;

Binary file not shown.

View file

@ -1,9 +1,86 @@
#include "b2hd.h"
#include "getArray.h"
#include "fileGestion.h"
#include <pthread.h>
#include <stdbool.h>
#include "simulateFlux.h"
#include "power.h"
#include "initialParameters.h"
#include "queue.h"
#include "average.h"
bool rawDataWriteFlag;
int nRow = 500;
int nCol = 1;
double freqEch = 250;
Pqueue firstRawDataQueue;
bool selectionCaptors[] = {true,false,true,false,false,false,true,false};
int cptData = 0;
int cptFile = 1;
double period = 0;
double invTimeBandWidth = 0;
void *threadCalculPower(void *vargp){
Pqueue rawDataQueue = firstRawDataQueue;
char* fileName;
while(rawDataWriteFlag){
while(queueGetNextE(rawDataQueue) != NULL){
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
power(fileName);
remove(fileName);
}
}
}
void *threadCalculAverage(void *vargp){
Pqueue rawDataQueue = firstRawDataQueue;
char* fileName;
while(rawDataWriteFlag){
while(queueGetNextE(rawDataQueue) != NULL){
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
average(fileName);
remove(fileName);
}
}
}
void *threadCalculBoth(void *vargp){
Pqueue rawDataQueue = firstRawDataQueue;
char* fileName;
while(rawDataWriteFlag){
while(queueGetNextE(rawDataQueue) != NULL){
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
power(fileName);
average(fileName);
remove(fileName);
}
}
}
int main(int argc , char** argv){
while(power(nRow,nCol,period,timeBandwidth)==0){}
for(int i = 0 ; i < 8 ; i++){
if(selectionCaptors[i]){
nCol++;
}
}
rawDataWriteFlag = true;
period = 1 / freqEch;
invTimeBandWidth = 1 /(nRow * period);
firstRawDataQueue = queueCreateEmpty(); // change this for create empty
pthread_t rawData;
pthread_create(&rawData , NULL, threadSimulateFlux, (void *)&rawData);
pthread_t calcul;
pthread_create(&calcul , NULL, threadCalculBoth, (void *)&calcul);
pthread_exit(NULL);
}

Binary file not shown.

View file

@ -1,32 +1,41 @@
#include "power.h"
#include "getArray.h"
#include "fileGestion.h"
#include "initialParameters.h"
#include "queue.h"
void powerCalculation(long **p, double a[] , int N, int M , double period , double timeBandwidth){
for(int i = 0; i < M-1; i++){
/**
* @brief realize the power calcul
*
* @param p array with all the values that will be used for the calcul
* @param powerArray array where results are stocked
*/
void powerCalculation(long **p, double powerArray[]){
for(int i = 1; i < nCol; i++){
int j = 0;
a[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] = 0;
while(j < nRow-1){
double aire = ( pow(p[j][i],2) + pow(p[j+1][i],2) ) / 2 * period;
powerArray[i] += aire;
j++;
}
a[i] *= timeBandwidth;
//printf("%f\n", a[i]);
powerArray[i] *= invTimeBandWidth;
}
}
int power(int N , int M, double periode , double timeBandwidth){
long **p = getRawDataArray(N, M);
//printArrayData(p,N,M);
double pw[8];
/**
* @brief function that realize all the action to write one lign in the file powerData.csv
*
* @param rawDataFileName name of the raw data file to use to realize the calcul
* @param N number of rows in the file
* @param M number of columns in the file
*/
void power(char* rawDataFileName){
long **p = getRawDataArray(rawDataFileName);
double pw[nCol-1];
if(p !=NULL){
powerCalculation(p,pw,N,M,periode,timeBandwidth);
writePowerData(pw,8);
freeArray(p,N);
return 0;
}
else{
return 1;
powerCalculation(p,pw);
appendDataInFile("powerData.csv",pw,nCol-1);
freeArray(p,nRow);
}
}

View file

@ -1,3 +1,4 @@
#include <math.h>
#include <stdbool.h>
int power(int N , int M, double periode , double timeBandwidth);
void power(char* rawDataFileName);

220
Code-C/queue.c Normal file
View file

@ -0,0 +1,220 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "queue.h"
/**
* @brief struct queue struct used for queueing string name
*
* @param charLen lenght of tabChar pointeur
* @param tabChar char array pointer
* @param pNextE point next element
*/
struct queue {
int charLen;
char* tabChar;
Pqueue pNextE;
};
typedef struct queue *Pqueue;
/**
* @brief create an empty element of queue
*
* @return Pqueue
*/
Pqueue queueCreateEmpty(){
Pqueue new = (Pqueue) malloc(sizeof(struct queue));
assert(new);
new->charLen = 0;
new->tabChar = NULL;
new->pNextE = NULL;
return new;
}
/************ SETTER ************/
/**
* @brief set char size array
*
* @param elem targeted element
* @param _charLen size of char array
*/
void queueSetCharLen(Pqueue elem, int _charLen){
assert(elem);
elem->charLen = _charLen;
}
/**
* @brief set the char array in the element
*
* @param elem targeted element
* @param _charLen char array size
* @param _tabChar pointer to static char array
*/
void queueSetTabChar(Pqueue elem, int _charLen, const char *_tabChar){
assert(elem);
assert(_tabChar);
elem->charLen = _charLen;
elem->tabChar = calloc(_charLen , sizeof(char));
for(int i = 0; i < _charLen; i++){
elem->tabChar[i] = _tabChar[i];
}
}
/**
* @brief set next pqueue element
*
* @param elem target element
* @param next next element
*/
void queueSetNextE(Pqueue elem , Pqueue next){
assert(elem);
assert(next);
elem -> pNextE = next;
}
/************ GETTER ************/
/**
* @brief switch to the next element
*
* @param elem current element
* @return Pqueue next element
*/
Pqueue queueGetNextE(Pqueue elem){
assert(elem);
return elem->pNextE;
}
/**
* @brief get the size char array
*
* @param elem targeted element
* @return int
*/
int queueGetCharLen(Pqueue elem){
assert(elem);
return elem->charLen;
}
/**
* @brief get the pointer of char array
*
* @param elem targeted elemnt
* @return char*
*/
char * queueGetTabChar(Pqueue elem){
assert(elem);
return elem->tabChar;
}
/************ ************/
/**
* @brief Create Element of queue
*
* @param lenChar size of char array that will be created
* @return Pqueue new element created
*/
Pqueue queueCreateE(int lenChar, const char* _tabChar){
Pqueue new = (Pqueue) malloc(sizeof(struct queue));
assert(new);
queueSetTabChar(new, lenChar, _tabChar);
new->pNextE = NULL;
return new;
}
/**
* @brief remove and free the last element of queue
*
* @param elem current element
* @return Pqueue current element
*/
Pqueue queueRmLastE(Pqueue elem){
assert(elem);
Pqueue tmp = elem, previous = NULL;
while(elem->pNextE != NULL){
previous = tmp;
tmp = queueGetNextE(tmp);
}
free(tmp->tabChar);
free(tmp);
previous->pNextE = NULL;
return elem;
}
/**
* @brief remove and free the first element of queue
*
* @param elem target to remove (the element need to be the first)
*/
void queueRmFrstE(Pqueue elem){
assert(elem);
free(elem->tabChar);
free(elem);
}
/**
* @brief delete the first value and return the next value
*
* @param elem
* @return Pqueue
*/
Pqueue queueNextDelFrst(Pqueue elem){
assert(elem);
Pqueue tmp = elem->pNextE;
queueRmFrstE(elem);
return tmp;
}
/**
* @brief add in the end of queue element with string parameter
*
* @param elem Pqueue will be added at the end of queue
* @param str the string will be bind at the element
* @param len the lenght of char array
*/
void queueAddLastQ(Pqueue elem, const char* str, int len){
assert(elem);
assert(str);
Pqueue next = elem, previous = NULL;
while(next->pNextE != NULL){
previous = next;
next = queueGetNextE(next);
}
previous = next;
next = queueCreateE(len,str);
queueSetNextE(previous,next);
}
/**
* @brief Print targeted element
*
* @param elem targeted element
*/
void queuePrintE(Pqueue elem){
Pqueue next = queueGetNextE(elem);
printf("\nFile Name : %s \n(size of the file name : %d)\n",elem -> tabChar , elem -> charLen );
if(next != NULL){
printf("Next File : %s\n", next ->tabChar);
}
else{
printf("No nextFile existing (null)\n");
}
}
/**
* @brief Print all the element starting from @param firstE till the end of the linked list
*
* @param firstE
*/
void queuePrintWholeQ(Pqueue firstE){
queuePrintE(firstE);
Pqueue elem = firstE;
while(queueGetNextE(elem) != NULL){
elem = queueGetNextE(elem);
queuePrintE(elem);
}
}

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

@ -0,0 +1,27 @@
typedef struct queue *Pqueue;
//Constructors
Pqueue queueCreateE(int lenChar, const char* _tabChar);
Pqueue queueCreateEmpty();
//Getters
Pqueue queueGetNextE(Pqueue elem);
int queueGetCharLen(Pqueue elem);
char* queueGetTabChar(Pqueue elem);
//Setters
void queueSetCharLen(Pqueue elem, int _charLen);
void queueSetTabChar(Pqueue elem, int _charLen, const char *_tabChar);
void queueSetNextE(Pqueue elem , Pqueue next);
void queueAddLastQ(Pqueue elem, const char* str, int len);
//Removers
Pqueue queueRmLastE(Pqueue elem);
void queueRmFrstE(Pqueue elem);
Pqueue queueNextDelFrst(Pqueue elem);
//print function
void queuePrintE(Pqueue elem);
void queuePrintWholeQ(Pqueue firstE);

6
Code-C/rmRawData.sh Normal file
View file

@ -0,0 +1,6 @@
#!/bin/bash
cd ../RawDataFiles
for i in *
do
rm $i
done

166
Code-C/simulateFlux.c Normal file
View file

@ -0,0 +1,166 @@
#include "simulateFlux.h"
#include "initialParameters.h"
#include "queue.h"
/**
* @brief convert an interger N into a char*
*
* @param N
* @return char*
*/
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*sizeof(char));
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;
}
/**
* @brief Create a New Raw Data File Name
*
* @return char*
*/
char *createNewRawDataFileName(){
char *fileName = "../RawDataFiles/RawData";
char *extension = ".csv\0";
char *fileNumber = convertIntegerToChar(cptFile);
//char *fileNumber;
//sprintf(fileNumber, "%d", cptFile);
//printf("%s\n" , fileNumber);
char fileNameNumber[strlen(fileName)+strlen(fileNumber)];
char *fullFileName = malloc((strlen(fileNameNumber)+strlen(extension)) * sizeof(char*));
strcpy( fileNameNumber, fileName );
strcat( fileNameNumber, fileNumber );
strcpy( fullFileName, fileNameNumber );
strcat( fullFileName, extension );
return fullFileName;
}
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;
}
/**
* @brief return the unix time in millisecond
*
* @return int64_t
*/
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 lastIndexCaptor(){
int lastIndex = 0;
for(int i = 1 ; i < 8 ; i++){
if(selectionCaptors[i]){
lastIndex = i;
}
}
return lastIndex;
}
/**
* @brief write one lign of rawData in the file @param rawDataFile (simulate of freq of the Vegetal Signals Captor)
*
* @param rawDataFile
* @return true if the lign is correctly write , else :
* @return false
*/
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 ###...#");
} else {
strncpy(buff, &buff[18], 8);
strncpy(&buff[8], buff2, 18);
}
}
int lastIndex = lastIndexCaptor();
for (int i = 1; i < 9; i++){
if(selectionCaptors[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(i==lastIndex){
fprintf(rawDataFile, "%d\n", values[i]/256);
}
else{
fprintf(rawDataFile, "%d,", values[i]/256);
}
}
}
cptData++;
//sleep(0.004); //simul freq here
return true;
}
else {
return false;
}
}
void *threadSimulateFlux(void *vargp){
char *fileName = createNewRawDataFileName();
FILE *rawDataFile = fopen(fileName,"w+");
while(writeOneRawData(rawDataFile)){
if(cptData == nRow){
fclose(rawDataFile);
cptData = 0;
cptFile++;
//create struct here
queueAddLastQ(firstRawDataQueue , fileName , strlen(fileName));
//prepare next file now
fileName = createNewRawDataFileName();
FILE *rawDataFile = fopen(fileName,"w+");
}
}
rawDataWriteFlag = false;
}

21
Code-C/simulateFlux.h Normal file
View file

@ -0,0 +1,21 @@
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include <time.h>
typedef struct {
uint8_t octet1;
uint8_t octet2;
uint8_t octet3;
uint8_t octet4;
} quartet;
extern int cptData;
extern int cptFile;
char *convertIntegerToChar(int N);
bool writeOneRawData(FILE *f);
void *threadSimulateFlux(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()

104
Py-Script/courbe.py Normal file
View file

@ -0,0 +1,104 @@
import math
import numpy as np
import matplotlib.pyplot as plt
import struct
import csv
import sys
#"C:\Users\quent\OneDrive\Bureau\ENSC\TransD\Framboisier\02400001.TXT"
#! /usr/bin/env python3
# -*- coding: UTF-8 -*-
csv_reader1 = csv.reader(open('./RawDataFiles/RawData1.csv')) #Ouvre le fichier .csv
bigx = float(-sys.maxsize-1)
bigy = float(-sys.maxsize-1)
smallx = float(sys.maxsize)
smally = float(sys.maxsize)
capteurs = []
for ligne in csv_reader1:
capteurs.append(ligne)
if float(ligne[0]) > bigx:
bigx = float(ligne[0])
if float(ligne[1]) > bigy:
bigy = float(ligne[1])
if float(ligne[0]) < smallx:
smallx = float(ligne[0])
if float(ligne[1]) < smally:
smally = float(ligne[1])
capteurs.sort()
x_arr = []
y_arr = []
for capteur in capteurs:
x_arr.append(capteur[0])
y_arr.append(capteur[1])
fig1 = plt.figure(1, figsize = (5.91, 2.758))
fig2 = plt.figure(1, figsize = (5.91, 2.758))
fig3 = plt.figure(1, figsize = (5.91, 2.758))
fig4 = plt.figure(1, figsize = (5.91, 2.758))
fig5 = plt.figure(1, figsize = (5.91, 2.758))
fig6 = plt.figure(1, figsize = (5.91, 2.758))
fig7 = plt.figure(1, figsize = (5.91, 2.758))
fig8 = plt.figure(1, figsize = (5.91, 2.758))
fig9 = plt.figure(1, figsize = (5.91, 2.758))
fig10 = plt.figure(1, figsize = (5.91, 2.758))
fig1.xlabel('Temps')
fig1.ylabel('Tension')
fig1.title("Données tableau 1")
fig1.plot(x_arr, y_arr, 'r')
#fig, (ax1) = plt.subplots(2, 1)
# Fe = 250000 #Fréquence d'échantillonage
# tstep = 1 / Fe
# y = capteur[:][0]
# y2 = capteur[:][0]
# N = len(y)
# t = np.linspace(0, (N-1) * tstep, N)
#Légende des plot 1, 2, 3, 4, 5, 6, 7 et 8
# ax1.set_xlabel('Temps')
# ax1.set_ylabel('Tension')
# ax1.set_title("Données du premier capteur")
# ax1.plot(t, y)
# ax2.set_xlabel('Temps')
# ax2.set_ylabel('Tension')
# ax2.set_title("Données du deuxième capteur")
# ax2.plot(t, y2)
# ax3.set_xlabel('Temps')
# ax3.set_ylabel('Tension')
# ax3.set_title("Données du troisième capteur")
# ax3.plot(t, y3)
# ax4.set_xlabel('Temps')
# ax4.set_ylabel('Tension')
# ax4.set_title("Données du quatrième capteur")
# ax4.plot(t, y4)
# ax5.set_xlabel('Temps')
# ax5.set_ylabel('Tension')
# ax5.set_title("Données du cinquième capteur")
# ax5.plot(t, y5)
# ax6.set_xlabel('Temps')
# ax6.set_ylabel('Tension')
# ax6.set_title("Données du sixième capteur")
# ax6.plot(t, y6)
# ax7.set_xlabel('Temps')
# ax7.set_ylabel('Tension')
# ax7.set_title("Données du septième capteur")
# ax7.plot(t, y7)
# ax8.set_xlabel('Temps')
# ax8.set_ylabel('Tension')
# ax8.set_title("Données du huitième capteur")
# ax8.plot(t, y8)
plt.show() #Affiche le tableau à l'écran