Merge branch 'Data'

This commit is contained in:
QuentinPerret 2023-05-09 13:41:44 +02:00
commit 4be1462614
35 changed files with 1425 additions and 363 deletions

89
.gitignore vendored
View file

@ -2,3 +2,92 @@
*.png *.png
*.exe *.exe
*.csv *.csv
*.png
*.dia
Code-C/main
Code-C/exect
Code-C/ctest
Code-C/DartConfiguration.tcl
Makefile
# Created by https://www.toptal.com/developers/gitignore/api/cmake,c
# Edit at https://www.toptal.com/developers/gitignore?templates=cmake,c
### C ###
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
*/Executable
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
### CMake ###
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
### CMake Patch ###
# External projects
*-prefix/
### DataFiles ###
*/RawDataFiles
# End of https://www.toptal.com/developers/gitignore/api/cmake,c

7
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,7 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}

View file

@ -15,6 +15,11 @@
"*.tcc": "c", "*.tcc": "c",
"type_traits": "c", "type_traits": "c",
"simulateflux.h": "c", "simulateflux.h": "c",
"pthread.h": "c" "pthread.h": "c",
"types.h": "c",
"average.h": "c",
"queue.h": "c",
"growthrate.h": "c",
"stdbool.h": "c"
} }
} }

41
Code-C/CMakeLists.txt Normal file
View file

@ -0,0 +1,41 @@
cmake_minimum_required(VERSION 2.6)
project(Traitement-signal-plantes C)
include(CTest)
enable_testing()
set(CMAKE_C_FLAGS "-std=c99 -g -Wall") #what are the flag for ?
file(MAKE_DIRECTORY RawDataFiles) #why do we make this folder each time ?
file(MAKE_DIRECTORY Executable)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY Executable) #Set Executable directory as default exectutable file location
add_executable(exect fileGestion.c getArray.c average.c growthRate.c power.c queue.c simulateFlux.c main.c)
# add_executable(exect main.c simulateFlux.c queue.c power.c growthRate.c average.c getArray.c fileGestion.c)
find_package(Threads)
target_link_libraries(exect ${CMAKE_THREAD_LIBS_INIT} m)
set(CTEST_MEMORYCHECK_TYPE "AddressSanitizer")
set(CTEST_MEMORYCHECK_SANITIZER_OPTIONS "verbosity=1:symbolize=1:abort_on_error=1:detect_leaks=1")
add_executable(ctest fileGestion.c getArray.c average.c growthRate.c queue.c simulateFlux.c ctest.c)
target_link_libraries(ctest ${CMAKE_THREAD_LIBS_INIT} m)
add_test(test_queueCreateEmpty ./ctest queueCreateEmpty)
add_test(test_queueCreateE ./ctest queueCreateE)
add_test(test_queueSetCharLen ./ctest queueSetCharLen)
add_test(test_queueGetCharLen ./ctest queueGetCharLen)
add_test(test_queueSetTabChar ./ctest queueSetTabChar)
add_test(test_queueGetTabChar ./ctest queueGetTabChar)
add_test(test_queueSetNextE ./ctest queueSetNextE)
add_test(test_queueGetNextE ./ctest queueGetNextE)
add_test(test_queueAddLastQ ./ctest queueAddLastQ)
add_test(test_queueRmLastE ./ctest queueRmLastE)
add_test(test_queueRmFrstE ./ctest queueRmFrstE)
add_test(test_queueNextDelFrst ./ctest queueNextDelFrst)

View file

@ -1,7 +0,0 @@
CC = gcc
all:
$(CC) fileGestion.c getArray.c average.c power.c queue.c simulateFlux.c main.c -lm -lpthread -o main
# $(CC) queue.c simulateFlux.c main.c -lm -lpthread -o main
./main < ../02400031.TXT

5
Code-C/Makefileold Normal file
View file

@ -0,0 +1,5 @@
CC = gcc
all:
$(CC) -g fileGestion.c getArray.c average.c growthRate.c power.c queue.c simulateFlux.c main.c -lm -lpthread -o main
./main < ../02400031.TXT

View file

@ -1,26 +1,28 @@
#include "average.h" #include "include/average.h"
#include "getArray.h" #include "include/getArray.h"
#include "fileGestion.h" #include "include/fileGestion.h"
#include "initialParameters.h" #include "include/initialParameters.h"
#include "queue.h" #include "include/queue.h"
/** /**
* @brief realize the average calcul * @brief realize the average calcul
* *
* @param p array with all the values that will be used for the calcul * @param p array with all the values that will be used for the calcul
* @param averageArray array where results are stocked * @param averageArray array where results are stocked
* @param N number of rows in p
* @param M number of columns in p
*/ */
void averageCalculation(long **p, double averageArray[]){ void averageCalculation(long **p, double averageArray[])
for(int i = 1; i < nCol; i++){ {
// printArrayData(p, nRowRawData, nCol);
// printf("\n");
for (int i = 1; i < nCol; i++)
{
int j = 0; int j = 0;
averageArray[i] = 0; averageArray[i] = 0;
while(j < nRow -1){ while (j < nRowRawData)
averageArray[i] += p[i][j]; {
averageArray[i - 1] += (double)p[i][j];
j++; j++;
} }
averageArray[i] /= N; averageArray[i] /= nRowRawData;
//printf("%f\n", powerArray[i]);
} }
} }
@ -28,15 +30,26 @@ void averageCalculation(long **p, double averageArray[]){
* @brief function that realize all the action to write one lign in the file averageData.csv * @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 * @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 average(char* rawDataFileName,int N , int M){ void averageFunction(char *rawDataFileName, double **aver)
long **p = getRawDataArray(rawDataFileName,N, M); {
double aver[8]; long **p = getRawDataArray(rawDataFileName);
if(p !=NULL){ double averN[nCol - 1];
averageCalculation(p,aver,N,M); if (p != NULL)
writeDataInFile("averageData.csv",aver,8); {
freeArray(p,N); if (p != NULL)
{
if (aver == NULL)
{
averageCalculation(p, averN);
appendDataInFile("averageData.csv", averN, nCol - 1);
}
else
{
averageCalculation(p, aver[1]);
appendDataInFile("averageData.csv", aver[1], nCol - 1);
}
freeArray(p, nRowRawData);
}
} }
} }

View file

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

View file

@ -1,4 +1,20 @@
#include "b2hd.h" #include "include/b2hd.h"
#include <time.h>
int64_t millis(){
//struct timespec now;
struct timespec *now = (struct timespec *) malloc(sizeof(struct timespec));
//timespec_get(&now, TIME_UTC);
timespec_get(now, TIME_UTC);
//#ifdef __USE_ISOC11 ????
int64_t tmp = (((int64_t) now->tv_sec) * 1000 + ((int64_t) now->tv_nsec) / ((int64_t) 1000000));
free(now);
return tmp;
}
/** /**
* @brief allow to transform all binary hex data send by the Vegetal Signal captor in a .TXT file into decimal values in a .csv * @brief allow to transform all binary hex data send by the Vegetal Signal captor in a .TXT file into decimal values in a .csv
* *
@ -14,7 +30,7 @@ void b2hd()
quartet value; quartet value;
while (fread(&buff, 26, 1, stdin)) { while (fread(&buff, 26, 1, stdin)) {
fprintf(stdout , "%d,", millis()); fprintf(stdout , "%ld,", millis());
for (int i = 1; i < 9; i++){ for (int i = 1; i < 9; i++){
/*buff[25] = '\0';*/ /*buff[25] = '\0';*/
if (strncmp(buff, "#################\n", (size_t)18) == 0) { if (strncmp(buff, "#################\n", (size_t)18) == 0) {
@ -44,7 +60,6 @@ void b2hd()
} }
} }
int main(int argc , char** argv){ int main(int argc , char** argv){
b2hd(); b2hd();
} }

25
Code-C/csv2json.c Normal file
View file

@ -0,0 +1,25 @@
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
void writeCaptorNumber(int N)
{
fprintf(stdout ,"{\n\"captorNumber\" : %d , " , N);
}
void writeTimeArray()
{
while
}
void writeValuesArray(int N)
{
}
int main(int argc, char **argv)
{
}

308
Code-C/ctest.c Normal file
View file

@ -0,0 +1,308 @@
#define __USE_GNU
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "include/fileGestion.h"
#include "include/getArray.h"
#include "include/growthRate.h"
#include "include/power.h"
#include "include/simulateFlux.h"
#include "include/queue.h"
#include "include/average.h"
//#include "b2hd.h"
bool rawDataWriteFlag;
int nRowRawData = 500;
int nRowGR = 150;
int nCol = 1;
double freqEch = 250;
int nbRowBinFile = 900011;
int nbRowIgnore = 19;
Pqueue firstRawDataQueue;
// Captor 1 2 3 4 5 6 7 8
bool selectionCaptors[] = {true, false, true, false, false, false, true, false};
int cptData = 0;
int cptFile = 1;
int cptValue = 0;
double period = 0;
double invTimeBandWidth = 0;
bool test_queueCreateEmpty()
{
Pqueue new = queueCreateEmpty();
assert(queueGetCharLen(new) == 0);
assert(queueGetTabChar(new) == NULL);
assert(queueGetNextE(new) == NULL);
// queueDelAll(new);
queueRmFrstE(new);
return EXIT_SUCCESS;
}
bool test_queueCreateE()
{
const char tabChar[12] = "PetitNavire\0";
Pqueue new = queueCreateE(12, tabChar);
const char *test = queueGetTabChar(new);
assert(queueGetCharLen(new) == 12);
assert(test != NULL);
assert(strcmp(test, tabChar) == 0);
assert(queueGetNextE(new) == NULL);
queueRmFrstE(new);
return EXIT_SUCCESS;
}
bool test_queueSetCharLen()
{
Pqueue new = queueCreateEmpty();
queueSetCharLen(new, 13);
assert(queueGetCharLen(new) == 13);
assert(queueGetTabChar(new) == NULL);
assert(queueGetNextE(new) == NULL);
// queueDelAll(new);
queueRmFrstE(new);
return EXIT_SUCCESS;
}
bool test_queueSetTabChar()
{
// Set and Get tabChar are similar because use for same test
Pqueue new = queueCreateEmpty();
const char tabChar[12] = "PetitNavire\0";
queueSetTabChar(new, 12, tabChar);
const char *test = queueGetTabChar(new);
assert(queueGetCharLen(new) == 12);
assert(test != NULL);
assert(strcmp(test, tabChar) == 0);
assert(queueGetNextE(new) == NULL);
queueRmFrstE(new);
return EXIT_SUCCESS;
}
bool test_queueGetTabChar()
{
Pqueue new = queueCreateEmpty();
const char tabChar[12] = "PetitNavire\0";
queueSetTabChar(new, 12, tabChar);
const char *test = queueGetTabChar(new);
assert(queueGetCharLen(new) == 12);
assert(test != NULL);
assert(strcmp(test, tabChar) == 0);
assert(queueGetNextE(new) == NULL);
queueRmFrstE(new);
return EXIT_SUCCESS;
}
bool test_queueSetNextE()
{
Pqueue new = queueCreateEmpty(), next = queueCreateEmpty();
queueSetNextE(new, next);
assert(queueGetNextE(new) == next);
assert(queueGetNextE(next) == NULL);
queueDelAll(new);
return EXIT_SUCCESS;
}
bool test_queueGetNextE()
{
Pqueue new = queueCreateEmpty(), next = queueCreateEmpty();
queueSetNextE(new, next);
assert(queueGetNextE(new) == next);
assert(queueGetNextE(next) == NULL);
queueDelAll(new);
return EXIT_SUCCESS;
}
bool test_queueGetCharLen()
{
Pqueue new = queueCreateEmpty();
assert(queueGetCharLen(new) == 0);
queueSetCharLen(new, 13);
assert(queueGetCharLen(new) == 13);
queueDelAll(new);
return EXIT_SUCCESS;
}
bool test_queueAddLastQ()
{
Pqueue new = queueCreateEmpty(), next = NULL;
const char tabChar[12] = "PetitNavire\0";
queueAddLastQ(new, tabChar, 12);
next = queueGetNextE(new);
assert(next != NULL);
assert(queueGetCharLen(next) == 12);
assert(strcmp(queueGetTabChar(next), tabChar) == 0);
assert(queueGetNextE(next) == NULL);
queueDelAll(new);
return EXIT_SUCCESS;
}
bool test_queueRmLastE()
{
Pqueue new = queueCreateEmpty();
const char tabChar[12] = "PetitNavire\0";
queueAddLastQ(new, tabChar, 12);
queueAddLastQ(new, tabChar, 12);
assert(queueGetNextE(new) != NULL && queueGetNextE(queueGetNextE(new)) != NULL && queueGetNextE(queueGetNextE(queueGetNextE(new))) == NULL);
queueRmLastE(new);
assert(queueGetNextE(new) != NULL && queueGetNextE(queueGetNextE(new)) == NULL);
queueDelAll(new);
return EXIT_SUCCESS;
}
bool test_queueRmFrstE()
{
Pqueue new = queueCreateEmpty(), second;
const char tabChar[12] = "PetitNavire\0";
queueAddLastQ(new, tabChar, 12);
queueAddLastQ(new, tabChar, 12);
second = queueGetNextE(new);
assert(queueGetNextE(new) != NULL && queueGetNextE(queueGetNextE(new)) != NULL && queueGetNextE(queueGetNextE(queueGetNextE(new))) == NULL);
new = queueRmFrstE(new);
assert((new == second) && (queueGetNextE(new) != NULL) && (queueGetNextE(queueGetNextE(new)) == NULL));
queueDelAll(new);
return EXIT_SUCCESS;
}
bool test_queueNextDelFrst()
{
Pqueue new = queueCreateEmpty(), second;
const char tabChar[12] = "PetitNavire\0";
queueAddLastQ(new, tabChar, 12);
queueAddLastQ(new, tabChar, 12);
second = queueGetNextE(new);
assert(queueGetNextE(new) != NULL && queueGetNextE(queueGetNextE(new)) != NULL && queueGetNextE(queueGetNextE(queueGetNextE(new))) == NULL);
new = queueNextDelFrst(new);
assert((new == second) && (queueGetNextE(new) != NULL) && (queueGetNextE(queueGetNextE(new)) == NULL));
queueDelAll(new);
return EXIT_SUCCESS;
}
/***************** Main test start *****************/
void usage(int argc, char *argv[])
{
fprintf(stderr, "Usage: %s <testname> [<...>]\n", argv[0]);
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[])
{
if (argc == 1)
usage(argc, argv);
// start test
fprintf(stderr, "=> Start test \"%s\"\n", argv[1]);
int ok = 1;
if (strcmp("queueCreateEmpty", argv[1]) == 0)
{
ok = test_queueCreateEmpty();
}
else if (strcmp("queueCreateE", argv[1]) == 0)
{
ok = test_queueCreateE();
}
else if (strcmp("queueSetCharLen", argv[1]) == 0)
{
ok = test_queueSetCharLen();
}
else if (strcmp("queueGetTabChar", argv[1]) == 0)
{
ok = test_queueGetTabChar();
}
else if (strcmp("queueSetNextE", argv[1]) == 0)
{
ok = test_queueSetNextE();
}
else if (strcmp("queueGetNextE", argv[1]) == 0)
{
ok = test_queueGetNextE();
}
else if (strcmp("queueGetCharLen", argv[1]) == 0)
{
ok = test_queueGetCharLen();
}
else if (strcmp("queueGetTabChar", argv[1]) == 0)
{
ok = test_queueGetTabChar();
}
else if (strcmp("queueSetTabChar", argv[1]) == 0)
{
ok = test_queueSetTabChar();
}
else if (strcmp("queueAddLastQ", argv[1]) == 0)
{
ok = test_queueAddLastQ();
}
else if (strcmp("queueRmLastE", argv[1]) == 0)
{
ok = test_queueRmLastE();
}
else if (strcmp("queueRmFrstE", argv[1]) == 0)
{
ok = test_queueRmFrstE();
}
else if (strcmp("queueNextDelFrst", argv[1]) == 0)
{
ok = test_queueNextDelFrst();
// }else if(strcmp("default_solution",argv[1]) == 0){
// ok = test_game_default_solution();
// }else if(strcmp("default_solution",argv[1]) == 0){
// ok = test_game_default_solution();
}
else
{
fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]);
exit(EXIT_FAILURE);
}
// print test result
if (ok == 0)
{
fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]);
return EXIT_SUCCESS;
}
else
{
fprintf(stderr, "Test \"%s\" finished: FAILURE\n", argv[1]);
return EXIT_FAILURE;
}
}

View file

@ -1,24 +1,29 @@
#include "fileGestion.h" #include "include/fileGestion.h"
/** /**
* @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 * @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 * @param nRow number of lign in the beginning of the file rawData.csv that has to be delete
*/ */
void clearRawData(int nRow){ 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 < nRow; i++){ //first the program read the first nRow ligns of the csv file but do nothing 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);
} }
while(1){ //then, till the end of the csv file it copy the lign to a new csv : newFile.csv while (1)
if(!fgets(buffer,sizeof buffer , g)) break; { // 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); fprintf(f, "%s", buffer);
} }
remove("rawData.csv"); rename("newFile.csv", "rawData.csv"); //finally we remove the original file and rename the new one to replace rawData.csv remove("rawData.csv");
fclose(f); fclose(g); rename("newFile.csv", "rawData.csv"); // finally we remove the original file and rename the new one to replace rawData.csv
fclose(f);
fclose(g);
} }
/** /**
* @brief use to write one lign in the file "fileName" * @brief use to write one lign in the file "fileName"
@ -26,15 +31,19 @@ void clearRawData(int nRow){
* @param array array that contaign all the values to write in the file * @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) * @param nCol size of the array (correspond to the number of captor used)
*/ */
void writeDataInFile(char* fileName , double array[], int nCol){ void appendDataInFile(char *fileName, double array[], int nCol)
{
FILE *f = fopen(fileName, "a+"); FILE *f = fopen(fileName, "a+");
for(int i = 0 ; i < nCol ; i++){ for (int i = 0; i < nCol; i++)
if( i < nCol-1){ {
if (i < nCol - 1)
{
fprintf(f, "%f , ", array[i]); fprintf(f, "%f , ", array[i]);
} else { }
else
{
fprintf(f, "%f\n", array[i]); fprintf(f, "%f\n", array[i]);
} }
} }
fclose(f); fclose(f);
} }

View file

@ -1,8 +1,9 @@
#include "getArray.h" #include "include/getArray.h"
#include "fileGestion.h" #include "include/fileGestion.h"
#include "include/initialParameters.h"
//#include <string.h> //#include <string.h>
long **get(int N, int M) /* Allocate the array */ long **getlongArray(int N, int M) /* Allocate the array */
{ {
/* Check if allocation succeeded. (check for NULL pointer) */ /* Check if allocation succeeded. (check for NULL pointer) */
int i; int i;
@ -13,8 +14,20 @@ long **get(int N, int M) /* Allocate the array */
return array; return array;
} }
void fillArrayWithRawData(char *rawDataFileName,long** p, int N, int M) { double **getDoubleArray(int N, int M) /* Allocate the array */
int i, j; {
/* Check if allocation succeeded. (check for NULL pointer) */
int i;
double **array;
array = (double **)malloc(N * sizeof(double *));
for (i = 0; i < N; i++)
array[i] = (double *)malloc(M * sizeof(double));
return array;
}
void fillArrayWithRawData(char *rawDataFileName, long **p, int N, int M)
{
int i = 0, j;
char *buffer; char *buffer;
size_t bufsize = 200; size_t bufsize = 200;
buffer = (char *)malloc(bufsize * sizeof(char)); buffer = (char *)malloc(bufsize * sizeof(char));
@ -22,27 +35,131 @@ void fillArrayWithRawData(char *rawDataFileName,long** p, int N, int M) {
FILE *f = fopen(rawDataFileName, "r"); FILE *f = fopen(rawDataFileName, "r");
for(i = 0 ; i < N ; i++){ long t, c1, c2, c3, c4, c5, c6, c7, c8;
if (!getline(&buffer, &bufsize, f)) break; // condition d'arret de la boucle si fichier fini switch (M)
j = 0; {
while((token = strsep(&buffer,",")) != NULL){ // séparation valeur par virgule initiale : csv case 2:
p[i][j] = atoi(token); while (fscanf(f, "%ld,%ld[^\n] ", &t, &c1) != EOF)
j++; {
p[i][0] = t;
p[i][1] = c1;
i++;
} }
break;
case 3:
while (fscanf(f, "%ld,%ld,%ld[^\n] ", &t, &c1, &c2) != EOF)
{
p[i][0] = t;
p[i][1] = c1;
p[i][2] = c2;
i++;
}
break;
case 4:
while (fscanf(f, "%ld,%ld,%ld,%ld[^\n] ", &t, &c1, &c2, &c3) != EOF)
{
p[i][0] = t;
p[i][1] = c1;
p[i][2] = c2;
p[i][3] = c3;
i++;
}
break;
case 5:
while (fscanf(f, "%ld,%ld,%ld,%ld,%ld[^\n] ", &t, &c1, &c2, &c3, &c4) != EOF)
{
p[i][0] = t;
p[i][1] = c1;
p[i][2] = c2;
p[i][3] = c3;
p[i][4] = c4;
i++;
}
break;
case 6:
while (fscanf(f, "%ld,%ld,%ld,%ld,%ld,%ld[^\n] ", &t, &c1, &c2, &c3, &c4, &c5) != EOF)
{
p[i][0] = t;
p[i][1] = c1;
p[i][2] = c2;
p[i][3] = c3;
p[i][4] = c4;
p[i][5] = c5;
i++;
}
break;
case 7:
while (fscanf(f, "%ld,%ld,%ld,%ld,%ld,%ld,%ld[^\n] ", &t, &c1, &c2, &c3, &c4, &c5, &c6) != EOF)
{
p[i][0] = t;
p[i][1] = c1;
p[i][2] = c2;
p[i][3] = c3;
p[i][4] = c4;
p[i][5] = c5;
p[i][6] = c6;
i++;
}
break;
case 8:
while (fscanf(f, "%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld[^\n] ", &t, &c1, &c2, &c3, &c4, &c5, &c6, &c7) != EOF)
{
p[i][0] = t;
p[i][1] = c1;
p[i][2] = c2;
p[i][3] = c3;
p[i][4] = c4;
p[i][5] = c5;
p[i][6] = c6;
p[i][7] = c7;
i++;
}
break;
case 9:
while (fscanf(f, "%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld[^\n] ", &t, &c1, &c2, &c3, &c4, &c5, &c6, &c7, &c8) != EOF)
{
p[i][0] = t;
p[i][1] = c1;
p[i][2] = c2;
p[i][3] = c3;
p[i][4] = c4;
p[i][5] = c5;
p[i][6] = c6;
p[i][7] = c7;
p[i][8] = c8;
i++;
}
break;
default:
printf("bad column size -> time + nbr captor\n");
} }
fclose(f);
/************** Debug part **************/
// for (int ii = 0; ii < nRowRawData; ii++)
// {
// for (int y = 0; y < nCol; y++)
// {
// printf("%ld,", p[ii][y]);
// if (y == nCol - 1)
// printf("lol\n");
// }
// }
fclose(f);
} }
/** /**
* @brief print all the element of a bidimensionnal array p of shape : N x M * @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; {
for(i = 0 ; i < N ; i++){ for (int i = 0; i < N; i++)
{
printf("line n°%d : ", i); printf("line n°%d : ", i);
for(int j = 0 ; j < M ; j++){ for (int j = 0; j < M; j++)
printf("%d , " , p[i][j]); {
if(j==(M-1)) printf("\n"); printf("%ld , ", p[i][j]);
if (j == (M - 1))
printf("\n");
} }
} }
} }
@ -55,9 +172,14 @@ void printArrayData(long** p, int N, int M) {
* @return true if the array contaign no NULL element * @return true if the array contaign no NULL element
* @return false if at least one element is null * @return false if at least one element is null
*/ */
bool checkArrayFullyFill(long **p, int N , int M){ bool checkArrayFullyFill(long **p, int N)
for(int i = 0 ; i < N ; i++){ {
if(p[i][0] == '\0'){ return false; } for (int i = 0; i < N; i++)
{
if (p[i][0] == '\0')
{
return false;
}
} }
return true; return true;
} }
@ -68,8 +190,10 @@ bool checkArrayFullyFill(long **p, int N , int M){
* @param p array to free memory * @param p array to free memory
* @param N number of rows in array * @param N number of rows in array
*/ */
void freeArray(long **p, int N) { void freeArray(long **p, int N)
for(int i = 0 ; i < N ; i++){ {
for (int i = 0; i < N; i++)
{
free(p[i]); free(p[i]);
} }
free(p); free(p);
@ -83,10 +207,11 @@ void freeArray(long **p, int N) {
* @param M numbers of columns to have i the array * @param M numbers of columns to have i the array
* @return long** the array fill with raw data * @return long** the array fill with raw data
*/ */
long **getRawDataArray(char* rawDataFileName , int N , int M){ long **getRawDataArray(char *rawDataFileName)
{
long **p; long **p;
p = get(nRow, nCol); p = getlongArray(nRowRawData, nCol);
fillArrayWithRawData(rawDataFileName,p ,nRow, nCol); fillArrayWithRawData(rawDataFileName, p, nRowRawData, nCol);
// if(checkArrayFullyFill(p,nRow)){ // if(checkArrayFullyFill(p,nRow)){
// clearRawData(N); // clearRawData(N);
return p; return p;

36
Code-C/growthRate.c Normal file
View file

@ -0,0 +1,36 @@
#include "include/initialParameters.h"
#include "include/fileGestion.h"
#include "include/getArray.h"
#include "include/growthRate.h"
/**
* @brief calculate de growth rate between to point next to each other
*
* @param dataArray array with data of points next to each other for each captor (dim : 2 * nCols)
* @param gRateArray array that contaigns results of the growth ratecalculation
*/
void growthRateCalculation(double **dataArray , double *gRateArray){
for(int i = 0 ; i < nCol-1 ; i++){
gRateArray[i] = (dataArray[0][i] - dataArray[1][i]) / period;
}
}
/**
* @brief calcul then print differentiate in csv
*
* @param dataLign
*/
void growthRateFunction(double **dataLign , char* fileName){
double gRateArray[nCol-1];
growthRateCalculation(dataLign , gRateArray);
appendDataInFile(fileName,gRateArray , nCol-1);
}
void sumColArray(long **p, double res[] , int N , int M){
for(int i = 1; i < M; i++){
int j = 0;
res[i] = 0;
while(j < N){
res[i] += p[i][j];
j++;
}
}
}

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

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

View file

@ -2,23 +2,19 @@
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> //#include <linuxstruct_timespec.h>
#define __USE_ISOC11 1
#include <linux/time.h>
#include <math.h> #include <math.h>
/** /**
* @brief struct used to stock binary 32 bits data from the captor * @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;
uint8_t octet3; uint8_t octet3;
uint8_t octet4; uint8_t octet4;
} quartet; } 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;
}

View file

@ -5,4 +5,4 @@
void clearRawData(int N); void clearRawData(int N);
void writeDataInFile(char* fileName , double a[], int N); void appendDataInFile(char* fileName , double a[], int N);

12
Code-C/include/getArray.h Normal file
View file

@ -0,0 +1,12 @@
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <inttypes.h>
long **getRawDataArray(char *rawDataFileName);
void printArrayData(long **p , int N , int M);
void freeArray(long **p, int N);
bool checkArrayFullyFill(long **p, int N);
double **getDoubleArray(int N, int M);

View file

@ -0,0 +1,4 @@
#include <math.h>
#include <stdbool.h>
void growthRateFunction(double **dataLign , char* fileName);

View file

@ -2,16 +2,18 @@
#include "queue.h" #include "queue.h"
extern bool rawDataWriteFlag; extern bool rawDataWriteFlag;
extern int nRow; extern int nRowRawData;
extern int nRowGR;
extern int nCol; extern int nCol;
extern double freqEch; extern double freqEch;
extern int nbRowBinFile;
extern int nbRowIgnore;
extern int cptFile; extern int cptFile;
extern int cptValue;
extern double period; extern double period;
extern double invTimeBandWidth; extern double invTimeBandWidth;
extern int selectionCaptors[]; extern bool selectionCaptors[];
extern int sizeSelectionArray;
extern Pqueue firstRawDataQueue; extern Pqueue firstRawDataQueue;

4
Code-C/include/power.h Normal file
View file

@ -0,0 +1,4 @@
#include <math.h>
#include <stdbool.h>
void powerFunction(char* rawDataFileName, double *pw[]);

127
Code-C/include/queue.h Normal file
View file

@ -0,0 +1,127 @@
typedef struct queue *Pqueue;
/**
* @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);
/**
* @brief create an empty element of queue
*
* @return Pqueue
*/
Pqueue queueCreateEmpty();
/************** Getters **************/
/**
* @brief switch to the next element
*
* @param elem current element
* @return Pqueue next element
*/
Pqueue queueGetNextE(Pqueue elem);
/**
* @brief get the size char array
*
* @param elem targeted element
* @return int
*/
int queueGetCharLen(Pqueue elem);
/**
* @brief get the pointer of char array
*
* @param elem targeted elemnt
* @return char*
*/
char *queueGetTabChar(Pqueue elem);
/************** Setters **************/
/**
* @brief set char size array
*
* @param elem targeted element
* @param _charLen size of char array
*/
void queueSetCharLen(Pqueue elem, int _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);
/**
* @brief set next pqueue element
*
* @param elem target element
* @param next next element
*/
void queueSetNextE(Pqueue elem, Pqueue next);
/**
* @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);
/************** Removers **************/
/**
* @brief remove and free the last element of queue
*
* @param elem current element
* @return Pqueue current element
*/
Pqueue queueRmLastE(Pqueue elem);
/**
* @brief remove and free the first element of queue
*
* @param elem target to remove (the element need to be the first)
* @return the next element of elem
*/
Pqueue queueRmFrstE(Pqueue elem); // same of queueNextDelFrst()
/**
* @brief delete the first value and return the next value
*
* @param elem
* @return Pqueue
*/
Pqueue queueNextDelFrst(Pqueue elem); // same of queueRmFrstE()
/************** print function **************/
/**
* @brief Print targeted element
*
* @param elem targeted element
*/
void queuePrintE(Pqueue elem);
/**
* @brief Print all the element starting from @param firstE till the end of the linked list
*
* @param firstE
*/
void queuePrintWholeQ(Pqueue firstE);
/**
* @brief free all queue list
*
* @param elem the first element of comdemned queue
*/
void queueDelAll(Pqueue elem);

View file

@ -4,6 +4,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <stdbool.h> #include <stdbool.h>
#define __USE_ISOC11 1
#include <time.h> #include <time.h>
typedef struct { typedef struct {

View file

@ -1,68 +1,156 @@
#include <pthread.h> #include <pthread.h>
#include <stdbool.h> #include <stdbool.h>
#include "simulateFlux.h"
#include "power.h" #include "include/simulateFlux.h"
#include "initialParameters.h" #include "include/power.h"
#include "queue.h" #include "include/initialParameters.h"
#include "average.h" #include "include/queue.h"
#include "include/average.h"
#include "include/growthRate.h"
#include "include/getArray.h"
bool rawDataWriteFlag; bool rawDataWriteFlag;
int nRow = 500; int nRowRawData = 5000;
int nCol = 9; int nRowGR = 150;
int nCol = 1;
double freqEch = 250; double freqEch = 250;
Pqueue firstRawDataQueue; int nbRowBinFile = 900011;
int nbRowIgnore = 19;
int selectionCaptors[] = {1,2,3,4,5,6,7,8}; Pqueue firstRawDataQueue;
int sizeSelectionArray = 8; // Captor 1 2 3 4 5 6 7 8
bool selectionCaptors[] = {true, false, true, false, false, false, true, false};
int cptData = 0; int cptData = 0;
int cptFile = 1; int cptFile = 1;
int cptValue = 0;
double period = 0; double period = 0;
double invTimeBandWidth = 0; double invTimeBandWidth = 0;
void *threadCalculPower(void *vargp){ void *threadCalculPower(void *vargp)
{
Pqueue rawDataQueue = firstRawDataQueue; Pqueue rawDataQueue = firstRawDataQueue;
char *fileName; char *fileName;
while(rawDataWriteFlag){ while (rawDataWriteFlag)
while(queueGetNextE(rawDataQueue) != NULL){ {
while (queueGetNextE(rawDataQueue) != NULL)
{
rawDataQueue = queueGetNextE(rawDataQueue); rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue); fileName = queueGetTabChar(rawDataQueue);
power(fileName,nRow,nCol,period,invTimeBandWidth); powerFunction(fileName, NULL);
remove(fileName); remove(fileName);
} }
} }
return NULL;
} }
void *threadCalculAverage(void *vargp){ void *threadCalculAverage(void *vargp)
{
Pqueue rawDataQueue = firstRawDataQueue; Pqueue rawDataQueue = firstRawDataQueue;
char *fileName; char *fileName;
while(rawDataWriteFlag){
while(queueGetNextE(rawDataQueue) != NULL){ while (rawDataWriteFlag)
{
while (queueGetNextE(rawDataQueue) != NULL)
{
rawDataQueue = queueGetNextE(rawDataQueue); rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue); fileName = queueGetTabChar(rawDataQueue);
average(fileName,nRow,nCol); printf("%s\n", fileName);
averageFunction(fileName, NULL);
remove(fileName); remove(fileName);
} }
} }
return NULL;
} }
void *threadCalculBoth(void *vargp){ void *threadCalculBoth(void *vargp)
{
Pqueue rawDataQueue = firstRawDataQueue; Pqueue rawDataQueue = firstRawDataQueue;
char *fileName; char *fileName;
while(rawDataWriteFlag){ while (rawDataWriteFlag)
while(queueGetNextE(rawDataQueue) != NULL){ {
while (queueGetNextE(rawDataQueue) != NULL)
{
rawDataQueue = queueGetNextE(rawDataQueue); rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue); fileName = queueGetTabChar(rawDataQueue);
<<<<<<< HEAD
power(fileName,nRow,nCol,period,invTimeBandWidth); power(fileName,nRow,nCol,period,invTimeBandWidth);
average(fileName,nRow,nCol); average(fileName,nRow,nCol);
//remove(fileName); //remove(fileName);
=======
powerFunction(fileName, NULL);
averageFunction(fileName, NULL);
remove(fileName);
>>>>>>> Data
} }
} }
return NULL;
} }
int main(int argc , char** argv){ void *threadCalculGrowthRate(void *vargp)
{
Pqueue rawDataQueue = firstRawDataQueue;
char *fileName;
// double pw[nCol-1];
double **dataLignPw = getDoubleArray(2, nCol);
double **dataLignAv = getDoubleArray(2, nCol);
int i = 0;
while (rawDataWriteFlag)
{
while (queueGetNextE(rawDataQueue) != NULL)
{
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
printf("%s\n", fileName);
if (i < 2)
{
if (i == 1)
{
powerFunction(fileName, dataLignPw);
averageFunction(fileName, dataLignAv);
growthRateFunction(dataLignPw, "growthRatePw.csv");
growthRateFunction(dataLignAv, "growthRateAv.csv");
}
else
{
averageFunction(fileName, dataLignAv);
powerFunction(fileName, dataLignPw);
}
i++;
}
else
{
for (int y = 0; y < (nCol - 1); y++)
{
dataLignPw[0][y] = dataLignPw[1][y];
dataLignAv[0][y] = dataLignAv[1][y];
}
powerFunction(fileName, dataLignPw);
averageFunction(fileName, dataLignAv);
growthRateFunction(dataLignPw, "growthRatePw.csv");
growthRateFunction(dataLignPw, "growthRateAv.csv");
}
remove(fileName);
}
}
return NULL;
}
int main(int argc, char **argv)
{
for (int i = 0; i < 8; i++)
{
if (selectionCaptors[i])
{
nCol++;
}
}
printf("%d", nCol);
for(int i = 0 ; i < 8 ; i++){ for(int i = 0 ; i < 8 ; i++){
if(selectionCaptors[i]){ if(selectionCaptors[i]){
@ -73,14 +161,29 @@ int main(int argc , char** argv){
rawDataWriteFlag = true; rawDataWriteFlag = true;
period = 1 / freqEch; period = 1 / freqEch;
invTimeBandWidth = 1 /(nRow * period); invTimeBandWidth = 1 / (nRowRawData * period);
firstRawDataQueue = queueCreateEmpty(); // change this for create empty firstRawDataQueue = queueCreateEmpty(); // change this for create empty
pthread_t rawData; pthread_t rawData;
pthread_create(&rawData , NULL, threadSimulateFlux, (void *)&rawData); if (pthread_create(&rawData, NULL, threadSimulateFlux, "threadSimulflux") != 0)
{
perror("threadSimulflux() error");
exit(1);
}
pthread_t calcul; pthread_t calculAverage;
pthread_create(&calcul , NULL, threadCalculBoth, (void *)&calcul); if (pthread_create(&calculAverage, NULL, threadCalculAverage, "threadCalculAverage"))
{
perror("threadCalculAverage() error");
exit(1);
}
// pthread_t calculGrowthRate;
// if (pthread_create(&calculGrowthRate, NULL, threadCalculGrowthRate, "threadCalculGrowthRate"))
// {
// perror("threadcalculGrowthRate() error");
// exit(1);
// }
pthread_exit(NULL); pthread_exit(NULL);
} }

View file

@ -1,29 +1,30 @@
#include "power.h" #include <math.h>
#include "getArray.h"
#include "fileGestion.h" #include "include/power.h"
#include "initialParameters.h" #include "include/getArray.h"
#include "queue.h" #include "include/fileGestion.h"
#include "include/initialParameters.h"
#include "include/queue.h"
/** /**
* @brief realize the power calcul * @brief realize the powerThreadFunction calcul
* *
* @param p array with all the values that will be used for the calcul * @param p array with all the values that will be used for the calcul
* @param powerArray array where results are stocked * @param powerArray array where results are stocked
* @param N number of rows in p
* @param M number of columns in p
*/ */
void powerCalculation(long **p, double powerArray[] , int N, int M , double period , double invTimeBandwidth){ void powerCalculation(long **p, double powerArray[])
for(int i = 0; i < M-1; i++){ {
for (int i = 0; i < nCol; i++)
{
int j = 0; int j = 0;
powerArray[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; while (j < nRowRawData)
//printf("aire [%d,%d] : %f\n",j,i,aire); {
powerArray[i] += aire; powerArray[i] += pow(p[j][i + 1], 2);
j++; j++;
} }
powerArray[i] *= invTimeBandwidth; powerArray[i] /= nRowRawData;
//printf("%f\n", powerArray[i]);
} }
} }
@ -34,16 +35,23 @@ void powerCalculation(long **p, double powerArray[] , int N, int M , double peri
* @param N number of rows in the file * @param N number of rows in the file
* @param M number of columns in the file * @param M number of columns in the file
*/ */
bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth){ void powerFunction(char *rawDataFileName, double **pw)
long **p = getRawDataArray(rawDataFileName,N, M); {
double pw[8]; long **p = getRawDataArray(rawDataFileName);
if(p !=NULL){ // printArrayData(p, nRowRawData, nCol);
powerCalculation(p,pw,N,M,periode,invTimeBandwidth); double pww[nCol - 1];
writeDataInFile("powerData.csv",pw,8); if (p != NULL)
freeArray(p,N); {
return true; if (pw == NULL)
{
powerCalculation(p, pww);
appendDataInFile("powerData.csv", pww, nCol - 1);
} }
else{ else
return false; {
powerCalculation(p, pw[1]);
appendDataInFile("powerData.csv", pw[1], nCol - 1);
}
freeArray(p, nRowRawData);
} }
} }

View file

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

View file

@ -2,7 +2,9 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "queue.h" #include <stdbool.h>
#include "include/queue.h"
/** /**
* @brief struct queue struct used for queueing string name * @brief struct queue struct used for queueing string name
@ -11,7 +13,8 @@
* @param tabChar char array pointer * @param tabChar char array pointer
* @param pNextE point next element * @param pNextE point next element
*/ */
struct queue { struct queue
{
int charLen; int charLen;
char *tabChar; char *tabChar;
Pqueue pNextE; Pqueue pNextE;
@ -24,7 +27,8 @@ typedef struct queue *Pqueue;
* *
* @return Pqueue * @return Pqueue
*/ */
Pqueue queueCreateEmpty(){ Pqueue queueCreateEmpty()
{
Pqueue new = (Pqueue)malloc(sizeof(struct queue)); Pqueue new = (Pqueue)malloc(sizeof(struct queue));
assert(new); assert(new);
new->charLen = 0; new->charLen = 0;
@ -41,7 +45,8 @@ Pqueue queueCreateEmpty(){
* @param elem targeted element * @param elem targeted element
* @param _charLen size of char array * @param _charLen size of char array
*/ */
void queueSetCharLen(Pqueue elem, int _charLen){ void queueSetCharLen(Pqueue elem, int _charLen)
{
assert(elem); assert(elem);
elem->charLen = _charLen; elem->charLen = _charLen;
} }
@ -53,12 +58,14 @@ void queueSetCharLen(Pqueue elem, int _charLen){
* @param _charLen char array size * @param _charLen char array size
* @param _tabChar pointer to static char array * @param _tabChar pointer to static char array
*/ */
void queueSetTabChar(Pqueue elem, int _charLen, const char *_tabChar){ void queueSetTabChar(Pqueue elem, int _charLen, const char *_tabChar)
{
assert(elem); assert(elem);
assert(_tabChar); assert(_tabChar);
elem->charLen = _charLen; elem->charLen = _charLen;
elem->tabChar = calloc(_charLen, sizeof(char)); elem->tabChar = calloc(_charLen, sizeof(char));
for(int i = 0; i < _charLen; i++){ for (int i = 0; i < _charLen; i++)
{
elem->tabChar[i] = _tabChar[i]; elem->tabChar[i] = _tabChar[i];
} }
} }
@ -68,7 +75,8 @@ void queueSetTabChar(Pqueue elem, int _charLen, const char *_tabChar){
* @param elem target element * @param elem target element
* @param next next element * @param next next element
*/ */
void queueSetNextE(Pqueue elem , Pqueue next){ void queueSetNextE(Pqueue elem, Pqueue next)
{
assert(elem); assert(elem);
assert(next); assert(next);
elem->pNextE = next; elem->pNextE = next;
@ -82,7 +90,8 @@ void queueSetNextE(Pqueue elem , Pqueue next){
* @param elem current element * @param elem current element
* @return Pqueue next element * @return Pqueue next element
*/ */
Pqueue queueGetNextE(Pqueue elem){ Pqueue queueGetNextE(Pqueue elem)
{
assert(elem); assert(elem);
return elem->pNextE; return elem->pNextE;
} }
@ -93,7 +102,8 @@ Pqueue queueGetNextE(Pqueue elem){
* @param elem targeted element * @param elem targeted element
* @return int * @return int
*/ */
int queueGetCharLen(Pqueue elem){ int queueGetCharLen(Pqueue elem)
{
assert(elem); assert(elem);
return elem->charLen; return elem->charLen;
} }
@ -104,7 +114,8 @@ int queueGetCharLen(Pqueue elem){
* @param elem targeted elemnt * @param elem targeted elemnt
* @return char* * @return char*
*/ */
char * queueGetTabChar(Pqueue elem){ char *queueGetTabChar(Pqueue elem)
{
assert(elem); assert(elem);
return elem->tabChar; return elem->tabChar;
} }
@ -117,7 +128,8 @@ char * queueGetTabChar(Pqueue elem){
* @param lenChar size of char array that will be created * @param lenChar size of char array that will be created
* @return Pqueue new element created * @return Pqueue new element created
*/ */
Pqueue queueCreateE(int lenChar, const char* _tabChar){ Pqueue queueCreateE(int lenChar, const char *_tabChar)
{
Pqueue new = (Pqueue)malloc(sizeof(struct queue)); Pqueue new = (Pqueue)malloc(sizeof(struct queue));
assert(new); assert(new);
queueSetTabChar(new, lenChar, _tabChar); queueSetTabChar(new, lenChar, _tabChar);
@ -131,16 +143,18 @@ Pqueue queueCreateE(int lenChar, const char* _tabChar){
* @param elem current element * @param elem current element
* @return Pqueue current element * @return Pqueue current element
*/ */
Pqueue queueRmLastE(Pqueue elem){ Pqueue queueRmLastE(Pqueue elem)
{
assert(elem); assert(elem);
Pqueue tmp = elem, previous = NULL; Pqueue tmp = elem, current = NULL;
while(elem->pNextE != NULL){ while (tmp->pNextE != NULL)
previous = tmp; {
current = tmp;
tmp = queueGetNextE(tmp); tmp = queueGetNextE(tmp);
} }
free(tmp->tabChar); free(tmp->tabChar);
free(tmp); free(tmp);
previous->pNextE = NULL; current->pNextE = NULL;
return elem; return elem;
} }
@ -148,11 +162,18 @@ Pqueue queueRmLastE(Pqueue elem){
* @brief remove and free the first element of queue * @brief remove and free the first element of queue
* *
* @param elem target to remove (the element need to be the first) * @param elem target to remove (the element need to be the first)
* @return next element of the queue
*/ */
void queueRmFrstE(Pqueue elem){ Pqueue queueRmFrstE(Pqueue elem)
{
assert(elem); assert(elem);
Pqueue next = queueGetNextE(elem);
if (elem->tabChar != NULL)
{
free(elem->tabChar); free(elem->tabChar);
}
free(elem); free(elem);
return next;
} }
/** /**
@ -161,7 +182,8 @@ void queueRmFrstE(Pqueue elem){
* @param elem * @param elem
* @return Pqueue * @return Pqueue
*/ */
Pqueue queueNextDelFrst(Pqueue elem){ Pqueue queueNextDelFrst(Pqueue elem)
{
assert(elem); assert(elem);
Pqueue tmp = elem->pNextE; Pqueue tmp = elem->pNextE;
queueRmFrstE(elem); queueRmFrstE(elem);
@ -175,17 +197,34 @@ Pqueue queueNextDelFrst(Pqueue elem){
* @param str the string will be bind at the element * @param str the string will be bind at the element
* @param len the lenght of char array * @param len the lenght of char array
*/ */
void queueAddLastQ(Pqueue elem, const char* str, int len){ void queueAddLastQ(Pqueue elem, const char *str, int len)
{
assert(elem); assert(elem);
assert(str); bool str1 = true;
Pqueue next = elem, previous = NULL; if (len == 0)
while(next->pNextE != NULL){ {
previous = next; str = false;
next = queueGetNextE(next);
} }
previous = next; else
{
assert(str);
}
Pqueue current = elem, next = NULL;
while (current->pNextE != NULL)
{
current = queueGetNextE(current);
}
if (str1 == true)
{
next = queueCreateE(len, str); next = queueCreateE(len, str);
queueSetNextE(previous,next); }
else
{
next = queueCreateEmpty();
}
queueSetNextE(current, next);
} }
/** /**
@ -193,13 +232,16 @@ void queueAddLastQ(Pqueue elem, const char* str, int len){
* *
* @param elem targeted element * @param elem targeted element
*/ */
void queuePrintE(Pqueue elem){ void queuePrintE(Pqueue elem)
{
Pqueue next = queueGetNextE(elem); Pqueue next = queueGetNextE(elem);
printf("\nFile Name : %s \n(size of the file name : %d)\n", elem->tabChar, elem->charLen); printf("\nFile Name : %s \n(size of the file name : %d)\n", elem->tabChar, elem->charLen);
if(next != NULL){ if (next != NULL)
{
printf("Next File : %s\n", next->tabChar); printf("Next File : %s\n", next->tabChar);
} }
else{ else
{
printf("No nextFile existing (null)\n"); printf("No nextFile existing (null)\n");
} }
} }
@ -209,12 +251,25 @@ void queuePrintE(Pqueue elem){
* *
* @param firstE * @param firstE
*/ */
void queuePrintWholeQ(Pqueue firstE){ void queuePrintWholeQ(Pqueue firstE)
{
queuePrintE(firstE); queuePrintE(firstE);
Pqueue elem = firstE; Pqueue elem = firstE;
while(queueGetNextE(elem) != NULL){ while (queueGetNextE(elem) != NULL)
{
elem = queueGetNextE(elem); elem = queueGetNextE(elem);
queuePrintE(elem); queuePrintE(elem);
} }
} }
void queueDelAll(Pqueue elem)
{
assert(elem);
Pqueue condemned = elem, tmp;
while (condemned != NULL)
{
tmp = queueGetNextE(condemned);
queueRmFrstE(condemned);
condemned = tmp;
}
}

View file

@ -1,27 +0,0 @@
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);

View file

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

View file

@ -1,6 +1,9 @@
#include "simulateFlux.h" #include "include/simulateFlux.h"
#include "initialParameters.h" #include "include/initialParameters.h"
#include "queue.h" #include "include/queue.h"
#include <time.h>
#include <errno.h>
/** /**
* @brief convert an interger N into a char* * @brief convert an interger N into a char*
@ -13,20 +16,23 @@ char* convertIntegerToChar(int N)
// Count digits in number N // Count digits in number N
int m = N; int m = N;
int digit = 0; int digit = 0;
while (m) { while (m)
{
digit++; digit++;
m /= 10; m /= 10;
} }
char *arr; char *arr;
char arr1[digit]; char arr1[digit];
arr = (char*)malloc(digit); arr = (char *)malloc(digit * sizeof(char));
int index = 0; int index = 0;
while (N) { while (N)
{
arr1[++index] = N % 10 + '0'; arr1[++index] = N % 10 + '0';
N /= 10; N /= 10;
} }
int i; int i;
for (i = 0; i < index; i++) { for (i = 0; i < index; i++)
{
arr[i] = arr1[index - i]; arr[i] = arr1[index - i];
} }
arr[i] = '\0'; arr[i] = '\0';
@ -38,10 +44,14 @@ char* convertIntegerToChar(int N)
* *
* @return char* * @return char*
*/ */
char *createNewRawDataFileName(){ char *createNewRawDataFileName()
char *fileName = "../RawDataFiles/RawData"; {
char *fileName = "RawDataFiles/RawData";
char *extension = ".csv\0"; char *extension = ".csv\0";
char *fileNumber = convertIntegerToChar(cptFile); char *fileNumber = convertIntegerToChar(cptFile);
// char *fileNumber;
// sprintf(fileNumber, "%d", cptFile);
// printf("%s\n" , fileNumber);
char fileNameNumber[strlen(fileName) + strlen(fileNumber)]; char fileNameNumber[strlen(fileName) + strlen(fileNumber)];
char *fullFileName = malloc((strlen(fileNameNumber) + strlen(extension)) * sizeof(char *)); char *fullFileName = malloc((strlen(fileNameNumber) + strlen(extension)) * sizeof(char *));
@ -55,16 +65,22 @@ char *createNewRawDataFileName(){
return fullFileName; return fullFileName;
} }
int intInArray(int number , int *array , int N){ int intInArray(int number, int *array, int N)
for(int i = 0 ; i < N ; i++){ {
if(array[i] == number) return 0; for (int i = 0; i < N; i++)
{
if (array[i] == number)
return 0;
} }
return -1; return -1;
} }
int maxInArray(int *array , int N){ int maxInArray(int *array, int N)
{
int max = 0; int max = 0;
for(int i = 0 ; i < N ; i++){ for (int i = 0; i < N; i++)
if(array[i]>max) max = array[i]; {
if (array[i] > max)
max = array[i];
} }
return max; return max;
} }
@ -73,11 +89,25 @@ int maxInArray(int *array , int N){
* *
* @return int64_t * @return int64_t
*/ */
int64_t millis() int64_t millis()
{ {
struct timespec now; struct timespec now;
timespec_get(&now, TIME_UTC); timespec_get(&now, TIME_UTC);
return ((int64_t) now.tv_sec) * 1000 + ((int64_t) now.tv_nsec) / 1000000; return ((int64_t)((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;
} }
@ -97,28 +127,42 @@ int lastIndexCaptor(){
* @return true if the lign is correctly write , else : * @return true if the lign is correctly write , else :
* @return false * @return false
*/ */
bool writeOneRawData(FILE *rawDataFile){ 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;
if (fread(&buff, 26, 1, stdin))
{
// printf("%d\n",cptValue);
if (cptValue < nbRowBinFile - nbRowIgnore)
{
FILE *timeFile = fopen("timeFile.csv", "a+");
fprintf(timeFile, "%ld\n", millis());
fclose(timeFile);
fprintf(rawDataFile, "%ld,", millis());
if(fread(&buff, 26, 1, stdin)) { if (strncmp(buff, "#################\n", (size_t)18) == 0)
fprintf(rawDataFile , "%d,", millis()); {
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 ###...#");
return 2; }
} else { else
{
strncpy(buff, &buff[18], 8); strncpy(buff, &buff[18], 8);
strncpy(&buff[8], buff2, 18); strncpy(&buff[8], buff2, 18);
} }
} }
int lastIndex = lastIndexCaptor(); int lastIndex = lastIndexCaptor();
for (int i = 1; i < 9; i++){ for (int i = 1; i < 9; i++)
if(intInArray(i,selectionCaptors,sizeSelectionArray)==0){ {
if (selectionCaptors[i - 1])
{
quartet value;
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];
@ -126,31 +170,50 @@ 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));
FILE *allRawDataFile = fopen("AllRawData.csv", "a+");
if(i==lastIndex){ if (i - 1 == lastIndex)
{
fprintf(rawDataFile, "%d\n", values[i] / 256); fprintf(rawDataFile, "%d\n", values[i] / 256);
fprintf(allRawDataFile, "%d\n", values[i] / 256);
} }
else{ else
{
fprintf(rawDataFile, "%d,", values[i] / 256); fprintf(rawDataFile, "%d,", values[i] / 256);
fprintf(allRawDataFile, "%d,", values[i] / 256);
} }
fclose(allRawDataFile);
} }
} }
cptData++; cptData++;
//sleep(0.004); //simul freq here
/************** simul freq here **************/
// struct timespec ts;
// ts.tv_sec = 0;
// ts.tv_nsec = 4 * 1000000;
// nanosleep(&ts, &ts);
cptValue++;
return true; return true;
} }
else { else
{
return false; return false;
} }
} }
return false;
}
void *threadSimulateFlux(void *vargp){ void *threadSimulateFlux(void *vargp)
{
char *fileName = createNewRawDataFileName(); char *fileName = createNewRawDataFileName();
FILE *rawDataFile = fopen(fileName, "w+"); FILE *rawDataFile = fopen(fileName, "w+");
while(writeOneRawData(rawDataFile)){ while (writeOneRawData(rawDataFile))
if(cptData == nRow){ {
if (cptData == nRowRawData)
{
fclose(rawDataFile); fclose(rawDataFile);
cptData = 0; cptData = 0;
cptFile++; cptFile++;
@ -158,8 +221,10 @@ void *threadSimulateFlux(void *vargp){
queueAddLastQ(firstRawDataQueue, fileName, strlen(fileName)); queueAddLastQ(firstRawDataQueue, fileName, strlen(fileName));
// prepare next file now // prepare next file now
fileName = createNewRawDataFileName(); fileName = createNewRawDataFileName();
FILE *rawDataFile = fopen(fileName,"w+"); rawDataFile = fopen(fileName, "w+");
//add test to get p then print it here // p is gotten from fileName file
} }
} }
rawDataWriteFlag = false; rawDataWriteFlag = false;
return NULL;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

BIN
Image_Diagram/chaien.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View file

@ -86,3 +86,26 @@ def final():
#printFig() #printFig()
final() final()
def function():
for i in range(1, 10):
rawdata = 'Code-C/RawDataFiles/RawData' + str(i) + '.csv' #Définit le fichier à ouvrir
with open(rawdata, newline='') as csvfile:
reader = csv.reader(csvfile, quoting=csv.QUOTE_NONNUMERIC)
x = [row for row in reader]
int_x = np.array(x, int)
for j in range(1,len(int_x[0])):
aver = average(int_x[:,j])
print("I = " , i ," J = " ,j ," aver = " , aver , '\0')
def average(x):
res = 0
for i in range(len(x)):
res += x[i]
return res / len(x)
function()

28
README.md Normal file
View file

@ -0,0 +1,28 @@
# [Robot Go West](https://projets.cohabit.fr/redmine/projects/communication-racinaire/wiki/Robot_Go-West)
### Introduction
This projet is a part of larger projet [_Communication Racinaire_](https://projets.cohabit.fr/redmine/projects/communication-racinaire/wiki/Wiki#section-8) which aims to drive plante into the direction of the sun.
When a plant received the solar radiation, a **difference of potential** will be created inside the plant. This physical reaction interest us to **measure** it and **interpret** the signal to drive the robot.
![Diagram](https://git.cohabit.fr/pgp/Traitement-signal-plantes/src/branch/Data/Image_Diagram/chaien.PNG)
On the diagram we can see a "**Pi**" symbole which represents the micro-controller who calculate and drive the robot, who will make the **C sources** work. After many hours of working or test phase the microcontroller create and store data interpretable by the **Python script**.
## Embedded C sources
![Graphical representation](https://git.cohabit.fr/pgp/Traitement-signal-plantes/src/branch/Data/Image_Diagram/ResumeWorkingDiagram.PNG)
The scheme represents well the program operation on the raspberry, the diagram is read from left to right.
**The first** represent the stream from vegetalsignal's captor through the USB port. This part block us because we don't have stream for now with the captor then we have create a thread to similate it. The stream send Raw data correspond to the electrique tension generated by the plant.
**The second** part with the thread storeRawData catch the raw data and store it in the memory in several files.(Usable data for python script)
**The third** part is used to gather data files and calculate to have pertinante data (Power or GrowthRate) and store it in file.
**The fourth** is not yet done, the thread drive will recovers the power and/or the gorwthRate data recognize events in the data and drive the robot.
## Graphic visualization Python script
The Python script is used to print the tension data on a graph.