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

91
.gitignore vendored
View file

@ -1,4 +1,93 @@
*.TXT
*.png
*.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",
"type_traits": "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,42 +1,55 @@
#include "average.h"
#include "getArray.h"
#include "fileGestion.h"
#include "initialParameters.h"
#include "queue.h"
#include "include/average.h"
#include "include/getArray.h"
#include "include/fileGestion.h"
#include "include/initialParameters.h"
#include "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
* @param N number of rows in p
* @param M number of columns in p
*/
void averageCalculation(long **p, double averageArray[]){
for(int i = 1; i < nCol; i++){
void averageCalculation(long **p, double averageArray[])
{
// printArrayData(p, nRowRawData, nCol);
// printf("\n");
for (int i = 1; i < nCol; i++)
{
int j = 0;
averageArray[i] = 0;
while(j < nRow -1){
averageArray[i] += p[i][j];
while (j < nRowRawData)
{
averageArray[i - 1] += (double)p[i][j];
j++;
}
averageArray[i] /= N;
//printf("%f\n", powerArray[i]);
averageArray[i] /= nRowRawData;
}
}
/**
* @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 N number of rows in the file
* @param M number of columns in the file
*/
void average(char* rawDataFileName,int N , int M){
long **p = getRawDataArray(rawDataFileName,N, M);
double aver[8];
if(p !=NULL){
averageCalculation(p,aver,N,M);
writeDataInFile("averageData.csv",aver,8);
freeArray(p,N);
void averageFunction(char *rawDataFileName, double **aver)
{
long **p = getRawDataArray(rawDataFileName);
double averN[nCol - 1];
if (p != NULL)
{
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
*
@ -14,7 +30,7 @@ void b2hd()
quartet value;
while (fread(&buff, 26, 1, stdin)) {
fprintf(stdout , "%d,", millis());
fprintf(stdout , "%ld,", millis());
for (int i = 1; i < 9; i++){
/*buff[25] = '\0';*/
if (strncmp(buff, "#################\n", (size_t)18) == 0) {
@ -44,7 +60,6 @@ void b2hd()
}
}
int main(int argc , char** argv){
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,40 +1,49 @@
#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
*
*
* @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];
FILE *f = fopen("newFile.csv","w+");
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
fgets(buffer , sizeof buffer , g);
FILE *f = fopen("newFile.csv", "w+");
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
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
if(!fgets(buffer,sizeof buffer , g)) break;
fprintf(f,"%s",buffer);
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"); //finally we remove the original file and rename the new one to replace rawData.csv
fclose(f); fclose(g);
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);
}
/**
* @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 writeDataInFile(char* fileName , double array[], int nCol){
FILE *f = fopen(fileName,"a+");
for(int i = 0 ; i < nCol ; i++){
if( i < nCol-1){
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 {
}
else
{
fprintf(f, "%f\n", array[i]);
}
}
fclose(f);
}
}

View file

@ -1,75 +1,199 @@
#include "getArray.h"
#include "fileGestion.h"
#include "include/getArray.h"
#include "include/fileGestion.h"
#include "include/initialParameters.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) */
int i;
long **array;
array = (long **) malloc(N*sizeof(long *));
for(i = 0 ; i < N ; i++)
array[i] = (long *) malloc( M*sizeof(long) );
array = (long **)malloc(N * sizeof(long *));
for (i = 0; i < N; i++)
array[i] = (long *)malloc(M * sizeof(long));
return array;
}
void fillArrayWithRawData(char *rawDataFileName,long** p, int N, int M) {
int i, j;
double **getDoubleArray(int N, int M) /* Allocate the array */
{
/* 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;
size_t bufsize = 200;
buffer = (char *)malloc(bufsize * sizeof(char));
char* token;
char *token;
FILE *f = fopen(rawDataFileName,"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
j = 0;
while((token = strsep(&buffer,",")) != NULL){ // séparation valeur par virgule initiale : csv
p[i][j] = atoi(token);
j++;
long t, c1, c2, c3, c4, c5, c6, c7, c8;
switch (M)
{
case 2:
while (fscanf(f, "%ld,%ld[^\n] ", &t, &c1) != EOF)
{
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
*/
void printArrayData(long** p, int N, int M) {
int i, j;
for(i = 0 ; i < N ; i++){
printf("line n°%d : " , i);
for(int j = 0 ; j < M ; j++){
printf("%d , " , p[i][j]);
if(j==(M-1)) printf("\n");
void printArrayData(long **p, int N, int M)
{
for (int i = 0; i < N; i++)
{
printf("line n°%d : ", i);
for (int j = 0; j < M; j++)
{
printf("%ld , ", p[i][j]);
if (j == (M - 1))
printf("\n");
}
}
}
/**
* @brief verify if all the element of an array are not NULL, return
*
* @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 , int M){
for(int i = 0 ; i < N ; i++){
if(p[i][0] == '\0'){ return false; }
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) {
for(int i = 0 ; i < N ; i++){
void freeArray(long **p, int N)
{
for (int i = 0; i < N; i++)
{
free(p[i]);
}
free(p);
@ -77,19 +201,20 @@ void freeArray(long **p, int N) {
/**
* @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 , int N , int M){
long **getRawDataArray(char *rawDataFileName)
{
long **p;
p = get(nRow, nCol);
fillArrayWithRawData(rawDataFileName,p ,nRow, nCol);
//if(checkArrayFullyFill(p,nRow)){
//clearRawData(N);
return p;
p = getlongArray(nRowRawData, nCol);
fillArrayWithRawData(rawDataFileName, p, nRowRawData, nCol);
// if(checkArrayFullyFill(p,nRow)){
// clearRawData(N);
return p;
/*}
else{
return NULL;

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 <stdint.h>
#include <stdlib.h>
#include <time.h>
//#include <linuxstruct_timespec.h>
#define __USE_ISOC11 1
#include <linux/time.h>
#include <math.h>
/**
* @brief struct used to stock binary 32 bits data from the captor
*
*
*/
typedef struct {
typedef struct
{
uint8_t octet1;
uint8_t octet2;
uint8_t octet3;
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;
}

View file

@ -5,4 +5,4 @@
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"
extern bool rawDataWriteFlag;
extern int nRow;
extern int nRowRawData;
extern int nRowGR;
extern int nCol;
extern double freqEch;
extern int nbRowBinFile;
extern int nbRowIgnore;
extern int cptFile;
extern int cptValue;
extern double period;
extern double invTimeBandWidth;
extern int selectionCaptors[];
extern int sizeSelectionArray;
extern bool selectionCaptors[];
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 <unistd.h>
#include <stdbool.h>
#define __USE_ISOC11 1
#include <time.h>
typedef struct {

View file

@ -1,68 +1,156 @@
#include <pthread.h>
#include <stdbool.h>
#include "simulateFlux.h"
#include "power.h"
#include "initialParameters.h"
#include "queue.h"
#include "average.h"
#include "include/simulateFlux.h"
#include "include/power.h"
#include "include/initialParameters.h"
#include "include/queue.h"
#include "include/average.h"
#include "include/growthRate.h"
#include "include/getArray.h"
bool rawDataWriteFlag;
int nRow = 500;
int nCol = 9;
int nRowRawData = 5000;
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 selectionCaptors[] = {1,2,3,4,5,6,7,8};
int sizeSelectionArray = 8;
int cptData = 0;
int cptData = 0;
int cptFile = 1;
int cptValue = 0;
double period = 0;
double invTimeBandWidth = 0;
void *threadCalculPower(void *vargp){
void *threadCalculPower(void *vargp)
{
Pqueue rawDataQueue = firstRawDataQueue;
char* fileName;
while(rawDataWriteFlag){
while(queueGetNextE(rawDataQueue) != NULL){
char *fileName;
while (rawDataWriteFlag)
{
while (queueGetNextE(rawDataQueue) != NULL)
{
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
power(fileName,nRow,nCol,period,invTimeBandWidth);
powerFunction(fileName, NULL);
remove(fileName);
}
}
return NULL;
}
void *threadCalculAverage(void *vargp){
void *threadCalculAverage(void *vargp)
{
Pqueue rawDataQueue = firstRawDataQueue;
char* fileName;
while(rawDataWriteFlag){
while(queueGetNextE(rawDataQueue) != NULL){
char *fileName;
while (rawDataWriteFlag)
{
while (queueGetNextE(rawDataQueue) != NULL)
{
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
average(fileName,nRow,nCol);
printf("%s\n", fileName);
averageFunction(fileName, NULL);
remove(fileName);
}
}
return NULL;
}
void *threadCalculBoth(void *vargp){
void *threadCalculBoth(void *vargp)
{
Pqueue rawDataQueue = firstRawDataQueue;
char* fileName;
while(rawDataWriteFlag){
while(queueGetNextE(rawDataQueue) != NULL){
char *fileName;
while (rawDataWriteFlag)
{
while (queueGetNextE(rawDataQueue) != NULL)
{
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
<<<<<<< HEAD
power(fileName,nRow,nCol,period,invTimeBandWidth);
average(fileName,nRow,nCol);
//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++){
if(selectionCaptors[i]){
@ -73,14 +161,29 @@ int main(int argc , char** argv){
rawDataWriteFlag = true;
period = 1 / freqEch;
invTimeBandWidth = 1 /(nRow * period);
invTimeBandWidth = 1 / (nRowRawData * 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_t rawData;
if (pthread_create(&rawData, NULL, threadSimulateFlux, "threadSimulflux") != 0)
{
perror("threadSimulflux() error");
exit(1);
}
pthread_t calculAverage;
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);
}

View file

@ -1,49 +1,57 @@
#include "power.h"
#include "getArray.h"
#include "fileGestion.h"
#include "initialParameters.h"
#include "queue.h"
#include <math.h>
#include "include/power.h"
#include "include/getArray.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 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){
for(int i = 0; i < M-1; i++){
void powerCalculation(long **p, double powerArray[])
{
for (int i = 0; i < nCol; i++)
{
int j = 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);
powerArray[i] += aire;
while (j < nRowRawData)
{
powerArray[i] += pow(p[j][i + 1], 2);
j++;
}
powerArray[i] *= invTimeBandwidth;
//printf("%f\n", powerArray[i]);
powerArray[i] /= nRowRawData;
}
}
/**
* @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
*/
bool power(char* rawDataFileName,int N , int M, double periode , double invTimeBandwidth){
long **p = getRawDataArray(rawDataFileName,N, M);
double pw[8];
if(p !=NULL){
powerCalculation(p,pw,N,M,periode,invTimeBandwidth);
writeDataInFile("powerData.csv",pw,8);
freeArray(p,N);
return true;
}
else{
return false;
void powerFunction(char *rawDataFileName, double **pw)
{
long **p = getRawDataArray(rawDataFileName);
// printArrayData(p, nRowRawData, nCol);
double pww[nCol - 1];
if (p != NULL)
{
if (pw == NULL)
{
powerCalculation(p, pww);
appendDataInFile("powerData.csv", pww, nCol - 1);
}
else
{
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,30 +2,34 @@
#include <stdio.h>
#include <stdlib.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
*
* @param charLen lenght of tabChar pointeur
* @param tabChar char array pointer
* @param pNextE point next element
* @param pNextE point next element
*/
struct queue {
struct queue
{
int charLen;
char* tabChar;
Pqueue pNextE;
char *tabChar;
Pqueue pNextE;
};
typedef struct queue *Pqueue;
/**
* @brief create an empty element of queue
*
* @return Pqueue
*
* @return Pqueue
*/
Pqueue queueCreateEmpty(){
Pqueue new = (Pqueue) malloc(sizeof(struct queue));
Pqueue queueCreateEmpty()
{
Pqueue new = (Pqueue)malloc(sizeof(struct queue));
assert(new);
new->charLen = 0;
new->tabChar = NULL;
@ -33,92 +37,100 @@ Pqueue queueCreateEmpty(){
return new;
}
/************ SETTER ************/
/************ SETTER ************/
/**
* @brief set char size array
*
*
* @param elem targeted element
* @param _charLen size of char array
*/
void queueSetCharLen(Pqueue elem, int _charLen){
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){
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 = 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){
void queueSetNextE(Pqueue elem, Pqueue next)
{
assert(elem);
assert(next);
elem -> pNextE = next;
elem->pNextE = next;
}
/************ GETTER ************/
/************ GETTER ************/
/**
* @brief switch to the next element
*
*
* @param elem current element
* @return Pqueue next element
*/
Pqueue queueGetNextE(Pqueue elem){
Pqueue queueGetNextE(Pqueue elem)
{
assert(elem);
return elem->pNextE;
}
/**
* @brief get the size char array
*
*
* @param elem targeted element
* @return int
* @return int
*/
int queueGetCharLen(Pqueue elem){
int queueGetCharLen(Pqueue elem)
{
assert(elem);
return elem->charLen;
}
/**
* @brief get the pointer of char array
*
*
* @param elem targeted elemnt
* @return char*
* @return char*
*/
char * queueGetTabChar(Pqueue elem){
char *queueGetTabChar(Pqueue elem)
{
assert(elem);
return elem->tabChar;
}
/************ ************/
/************ ************/
/**
* @brief Create Element of queue
*
* @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
*/
Pqueue queueCreateE(int lenChar, const char* _tabChar){
Pqueue new = (Pqueue) malloc(sizeof(struct queue));
Pqueue queueCreateE(int lenChar, const char *_tabChar)
{
Pqueue new = (Pqueue)malloc(sizeof(struct queue));
assert(new);
queueSetTabChar(new, lenChar, _tabChar);
new->pNextE = NULL;
@ -127,41 +139,51 @@ Pqueue queueCreateE(int lenChar, const char* _tabChar){
/**
* @brief remove and free the last element of queue
*
*
* @param elem current element
* @return Pqueue current element
*/
Pqueue queueRmLastE(Pqueue elem){
Pqueue queueRmLastE(Pqueue elem)
{
assert(elem);
Pqueue tmp = elem, previous = NULL;
while(elem->pNextE != NULL){
previous = tmp;
Pqueue tmp = elem, current = NULL;
while (tmp->pNextE != NULL)
{
current = tmp;
tmp = queueGetNextE(tmp);
}
free(tmp->tabChar);
free(tmp);
previous->pNextE = NULL;
current->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)
* @return next element of the queue
*/
void queueRmFrstE(Pqueue elem){
Pqueue queueRmFrstE(Pqueue elem)
{
assert(elem);
free(elem->tabChar);
Pqueue next = queueGetNextE(elem);
if (elem->tabChar != NULL)
{
free(elem->tabChar);
}
free(elem);
return next;
}
/**
* @brief delete the first value and return the next value
*
* @param elem
* @return Pqueue
*
* @param elem
* @return Pqueue
*/
Pqueue queueNextDelFrst(Pqueue elem){
Pqueue queueNextDelFrst(Pqueue elem)
{
assert(elem);
Pqueue tmp = elem->pNextE;
queueRmFrstE(elem);
@ -169,52 +191,85 @@ Pqueue queueNextDelFrst(Pqueue elem){
}
/**
* @brief add in the end of queue element with string parameter
*
* @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){
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);
bool str1 = true;
if (len == 0)
{
str = false;
}
previous = next;
next = queueCreateE(len,str);
queueSetNextE(previous,next);
else
{
assert(str);
}
Pqueue current = elem, next = NULL;
while (current->pNextE != NULL)
{
current = queueGetNextE(current);
}
if (str1 == true)
{
next = queueCreateE(len, str);
}
else
{
next = queueCreateEmpty();
}
queueSetNextE(current, next);
}
/**
* @brief Print targeted element
*
*
* @param elem targeted element
*/
void queuePrintE(Pqueue elem){
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);
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{
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
*
* @param firstE
*/
void queuePrintWholeQ(Pqueue firstE){
void queuePrintWholeQ(Pqueue firstE)
{
queuePrintE(firstE);
Pqueue elem = firstE;
while(queueGetNextE(elem) != NULL){
while (queueGetNextE(elem) != NULL)
{
elem = queueGetNextE(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,83 +1,113 @@
#include "simulateFlux.h"
#include "initialParameters.h"
#include "queue.h"
#include "include/simulateFlux.h"
#include "include/initialParameters.h"
#include "include/queue.h"
#include <time.h>
#include <errno.h>
/**
* @brief convert an interger N into a char*
*
* @param N
* @return char*
*
* @param N
* @return char*
*/
char* convertIntegerToChar(int N)
char *convertIntegerToChar(int N)
{
// Count digits in number N
int m = N;
int digit = 0;
while (m) {
while (m)
{
digit++;
m /= 10;
}
char* arr;
char *arr;
char arr1[digit];
arr = (char*)malloc(digit);
arr = (char *)malloc(digit * sizeof(char));
int index = 0;
while (N) {
while (N)
{
arr1[++index] = N % 10 + '0';
N /= 10;
}
int i;
for (i = 0; i < index; i++) {
for (i = 0; i < index; i++)
{
arr[i] = arr1[index - i];
}
arr[i] = '\0';
return (char*)arr;
return (char *)arr;
}
/**
* @brief Create a New Raw Data File Name
*
* @return char*
* @brief Create a New Raw Data File Name
*
* @return char*
*/
char *createNewRawDataFileName(){
char *fileName = "../RawDataFiles/RawData";
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*));
char fileNameNumber[strlen(fileName) + strlen(fileNumber)];
char *fullFileName = malloc((strlen(fileNameNumber) + strlen(extension)) * sizeof(char *));
strcpy( fileNameNumber, fileName );
strcat( fileNameNumber, fileNumber );
strcpy(fileNameNumber, fileName);
strcat(fileNameNumber, fileNumber);
strcpy(fullFileName, fileNameNumber);
strcat(fullFileName, extension);
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;
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];
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
*
* @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;
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;
}
@ -92,74 +122,109 @@ int lastIndexCaptor(){
}
/**
* @brief write one lign of rawData in the file @param rawDataFile (simulate of freq of the Vegetal Signals Captor)
*
* @param rawDataFile
*
* @param rawDataFile
* @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 buff2[18];
int32_t values[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)) {
fprintf(rawDataFile , "%d,", millis());
if (strncmp(buff, "#################\n", (size_t)18) == 0) {
if (!(fread(&buff2, 18, 1, stdin))) {
fprintf(stderr, "Erreur lecture après ###...#");
return 2;
} else {
strncpy(buff, &buff[18], 8);
strncpy(&buff[8], buff2, 18);
}
}
int lastIndex = lastIndexCaptor();
for (int i = 1; i < 9; i++){
if(intInArray(i,selectionCaptors,sizeSelectionArray)==0){
value.octet1 = buff[3*i+1];
value.octet2 = buff[3*i+2];
value.octet3 = buff[3*i+3];
value.octet4 = 0;
valbin[i] = buff[3*i+1]*256*256*256 + buff[3*i+2]*256*256 + buff[3*i+3]*256;
memcpy(&values[i], &valbin[i], sizeof(uint32_t));
if(i==lastIndex){
fprintf(rawDataFile, "%d\n", values[i]/256);
if (strncmp(buff, "#################\n", (size_t)18) == 0)
{
if (!(fread(&buff2, 18, 1, stdin)))
{
fprintf(stderr, "Erreur lecture après ###...#");
}
else{
fprintf(rawDataFile, "%d,", values[i]/256);
else
{
strncpy(buff, &buff[18], 8);
strncpy(&buff[8], buff2, 18);
}
}
int lastIndex = lastIndexCaptor();
for (int i = 1; i < 9; i++)
{
if (selectionCaptors[i - 1])
{
quartet value;
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));
FILE *allRawDataFile = fopen("AllRawData.csv", "a+");
if (i - 1 == lastIndex)
{
fprintf(rawDataFile, "%d\n", values[i] / 256);
fprintf(allRawDataFile, "%d\n", values[i] / 256);
}
else
{
fprintf(rawDataFile, "%d,", values[i] / 256);
fprintf(allRawDataFile, "%d,", values[i] / 256);
}
fclose(allRawDataFile);
}
}
cptData++;
/************** simul freq here **************/
// struct timespec ts;
// ts.tv_sec = 0;
// ts.tv_nsec = 4 * 1000000;
// nanosleep(&ts, &ts);
cptValue++;
return true;
}
else
{
return false;
}
cptData++;
//sleep(0.004); //simul freq here
return true;
}
else {
return false;
}
return false;
}
void *threadSimulateFlux(void *vargp){
void *threadSimulateFlux(void *vargp)
{
char *fileName = createNewRawDataFileName();
FILE *rawDataFile = fopen(fileName,"w+");
FILE *rawDataFile = fopen(fileName, "w+");
while(writeOneRawData(rawDataFile)){
if(cptData == nRow){
while (writeOneRawData(rawDataFile))
{
if (cptData == nRowRawData)
{
fclose(rawDataFile);
cptData = 0;
cptFile++;
//create struct here
queueAddLastQ(firstRawDataQueue , fileName , strlen(fileName));
//prepare next file now
// create struct here
queueAddLastQ(firstRawDataQueue, fileName, strlen(fileName));
// prepare next file now
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;
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

@ -85,4 +85,27 @@ def final():
function()
#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.