CMakelists add few test queue
This commit is contained in:
parent
f4fd64e63c
commit
ade5b4378f
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -4,7 +4,10 @@
|
||||||
*.csv
|
*.csv
|
||||||
|
|
||||||
Code-C/main
|
Code-C/main
|
||||||
Code-C/exec
|
Code-C/exect
|
||||||
|
Code-C/ctest
|
||||||
|
Code-C/DartConfiguration.tcl
|
||||||
|
|
||||||
Makefile
|
Makefile
|
||||||
|
|
||||||
# Created by https://www.toptal.com/developers/gitignore/api/cmake,c
|
# Created by https://www.toptal.com/developers/gitignore/api/cmake,c
|
||||||
|
|
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -15,6 +15,7 @@
|
||||||
"*.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"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,8 +3,25 @@ project(Traitement-signal-plantes C)
|
||||||
|
|
||||||
include(CTest)
|
include(CTest)
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS "-std=c99 -g -Wall")
|
set(CMAKE_C_FLAGS "-std=c99 -g -Wall")
|
||||||
|
|
||||||
add_executable(exect fileGestion.c getArray.c average.c growthRate.c power.c queue.c simulateFlux.c main.c)
|
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)
|
|
||||||
|
# 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_queueSetCharLen ./ctest queueSetCharLen)
|
||||||
|
|
||||||
|
# add_test(test_queueGetTabChar ./ctest queueGetTabChar)
|
||||||
|
add_test(test_queueSetNextE ./ctest queueSetNextE)
|
||||||
|
add_test(test_queueGetNextE ./ctest queueGetNextE)
|
||||||
|
|
||||||
|
add_test(test_queueGetCharLen ./ctest queueGetCharLen)
|
|
@ -1,4 +1,20 @@
|
||||||
#include "b2hd.h"
|
#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();
|
||||||
}
|
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
184
Code-C/ctest.c
Normal file
184
Code-C/ctest.c
Normal file
|
@ -0,0 +1,184 @@
|
||||||
|
#define __USE_GNU
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "fileGestion.h"
|
||||||
|
#include "getArray.h"
|
||||||
|
#include "growthRate.h"
|
||||||
|
#include "power.c"
|
||||||
|
#include "simulateFlux.h"
|
||||||
|
#include "queue.h"
|
||||||
|
#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_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_queueGetTabChar()
|
||||||
|
{ // Define later
|
||||||
|
Pqueue new = queueCreateEmpty();
|
||||||
|
|
||||||
|
// const char tabChar[12] = "PetitNavire\0"
|
||||||
|
queueSetTabChar(new, 13, NULL);
|
||||||
|
|
||||||
|
assert(queueGetCharLen(new) == 13);
|
||||||
|
assert(queueGetTabChar(new) == NULL);
|
||||||
|
assert(queueGetNextE(new) == NULL);
|
||||||
|
|
||||||
|
// queueDelAll(new);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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("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("update_flags",argv[1]) == 0){
|
||||||
|
// ok = test_game_update_flags();
|
||||||
|
// }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;
|
||||||
|
}
|
||||||
|
}
|
BIN
Code-C/main
BIN
Code-C/main
Binary file not shown.
105
Code-C/main.c
105
Code-C/main.c
|
@ -18,21 +18,24 @@ int nbRowBinFile = 900011;
|
||||||
int nbRowIgnore = 19;
|
int nbRowIgnore = 19;
|
||||||
|
|
||||||
Pqueue firstRawDataQueue;
|
Pqueue firstRawDataQueue;
|
||||||
//Captor 1 2 3 4 5 6 7 8
|
// Captor 1 2 3 4 5 6 7 8
|
||||||
bool selectionCaptors[] = {true,false,true,false,false,false,true,false};
|
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;
|
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);
|
||||||
powerFunction(fileName, NULL);
|
powerFunction(fileName, NULL);
|
||||||
|
@ -41,11 +44,14 @@ void *threadCalculPower(void *vargp){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *threadCalculAverage(void *vargp){
|
void *threadCalculAverage(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);
|
||||||
averageFunction(fileName, NULL);
|
averageFunction(fileName, NULL);
|
||||||
|
@ -54,62 +60,79 @@ void *threadCalculAverage(void *vargp){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
powerFunction(fileName, NULL);
|
powerFunction(fileName, NULL);
|
||||||
averageFunction(fileName , NULL);
|
averageFunction(fileName, NULL);
|
||||||
remove(fileName);
|
remove(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *threadCalculGrowthRate(void * vargp){
|
void *threadCalculGrowthRate(void *vargp)
|
||||||
|
{
|
||||||
Pqueue rawDataQueue = firstRawDataQueue;
|
Pqueue rawDataQueue = firstRawDataQueue;
|
||||||
char* fileName;
|
char *fileName;
|
||||||
//double pw[nCol-1];
|
// double pw[nCol-1];
|
||||||
double **dataLignPw = getDoubleArray(2,nCol);
|
double **dataLignPw = getDoubleArray(2, nCol);
|
||||||
double **dataLignAv = getDoubleArray(2,nCol);
|
double **dataLignAv = getDoubleArray(2, nCol);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(rawDataWriteFlag){
|
while (rawDataWriteFlag)
|
||||||
while(queueGetNextE(rawDataQueue) != NULL){
|
{
|
||||||
|
while (queueGetNextE(rawDataQueue) != NULL)
|
||||||
|
{
|
||||||
rawDataQueue = queueGetNextE(rawDataQueue);
|
rawDataQueue = queueGetNextE(rawDataQueue);
|
||||||
fileName = queueGetTabChar(rawDataQueue);
|
fileName = queueGetTabChar(rawDataQueue);
|
||||||
if(i < 2){
|
if (i < 2)
|
||||||
if(i == 1){
|
{
|
||||||
|
if (i == 1)
|
||||||
|
{
|
||||||
powerFunction(fileName, dataLignPw);
|
powerFunction(fileName, dataLignPw);
|
||||||
averageFunction(fileName , dataLignAv);
|
averageFunction(fileName, dataLignAv);
|
||||||
growthRateFunction(dataLignPw , "growthRatePw.csv");
|
growthRateFunction(dataLignPw, "growthRatePw.csv");
|
||||||
growthRateFunction(dataLignPw,"growthRateAv.csv");
|
growthRateFunction(dataLignPw, "growthRateAv.csv");
|
||||||
}else{
|
}
|
||||||
averageFunction(fileName , dataLignAv);
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
averageFunction(fileName, dataLignAv);
|
||||||
powerFunction(fileName, dataLignPw);
|
powerFunction(fileName, dataLignPw);
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}else{
|
}
|
||||||
for(int y = 0; y < (nCol-1); y++){
|
else
|
||||||
|
{
|
||||||
|
for (int y = 0; y < (nCol - 1); y++)
|
||||||
|
{
|
||||||
dataLignPw[0][y] = dataLignPw[1][y];
|
dataLignPw[0][y] = dataLignPw[1][y];
|
||||||
dataLignAv[0][y] = dataLignAv[1][y];
|
dataLignAv[0][y] = dataLignAv[1][y];
|
||||||
}
|
}
|
||||||
powerFunction(fileName, dataLignPw);
|
powerFunction(fileName, dataLignPw);
|
||||||
averageFunction(fileName , dataLignAv);
|
averageFunction(fileName, dataLignAv);
|
||||||
growthRateFunction(dataLignPw,"growthRatePw.csv");
|
growthRateFunction(dataLignPw, "growthRatePw.csv");
|
||||||
growthRateFunction(dataLignPw,"growthRateAv.csv");
|
growthRateFunction(dataLignPw, "growthRateAv.csv");
|
||||||
}
|
}
|
||||||
remove(fileName);
|
remove(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc , char** argv){
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
|
||||||
for(int i = 0 ; i < 8 ; i++){
|
for (int i = 0; i < 8; i++)
|
||||||
if(selectionCaptors[i]){
|
{
|
||||||
|
if (selectionCaptors[i])
|
||||||
|
{
|
||||||
nCol++;
|
nCol++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,13 +140,13 @@ int main(int argc , char** argv){
|
||||||
rawDataWriteFlag = true;
|
rawDataWriteFlag = true;
|
||||||
|
|
||||||
period = 1 / freqEch;
|
period = 1 / freqEch;
|
||||||
invTimeBandWidth = 1 /(nRowRawData * 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);
|
pthread_create(&rawData, NULL, threadSimulateFlux, (void *)&rawData);
|
||||||
pthread_t calcul;
|
pthread_t calcul;
|
||||||
pthread_create(&calcul , NULL, threadCalculGrowthRate, (void *)&calcul);
|
pthread_create(&calcul, NULL, threadCalculGrowthRate, (void *)&calcul);
|
||||||
|
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
}
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <math.h>
|
||||||
#include "power.h"
|
#include "power.h"
|
||||||
#include "getArray.h"
|
#include "getArray.h"
|
||||||
#include "fileGestion.h"
|
#include "fileGestion.h"
|
||||||
|
@ -6,43 +7,50 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief realize the powerThreadFunction 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
|
||||||
*/
|
*/
|
||||||
void powerCalculation(long **p, double powerArray[]){
|
void powerCalculation(long **p, double powerArray[])
|
||||||
for(int i = 0; i < nCol; i++){
|
{
|
||||||
|
for (int i = 0; i < nCol; i++)
|
||||||
|
{
|
||||||
int j = 0;
|
int j = 0;
|
||||||
powerArray[i] = 0;
|
powerArray[i] = 0;
|
||||||
|
|
||||||
while(j < nRowRawData){
|
while (j < nRowRawData)
|
||||||
powerArray[i] += pow(p[j][i+1],2);
|
{
|
||||||
|
powerArray[i] += pow(p[j][i + 1], 2);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
powerArray[i] /= nRowRawData;
|
powerArray[i] /= nRowRawData;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief function that realize all the action to write one lign in the file powerData.csv
|
* @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 rawDataFileName name of the raw data file to use to realize the calcul
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
void powerFunction(char* rawDataFileName, double **pw){
|
void powerFunction(char *rawDataFileName, double **pw)
|
||||||
|
{
|
||||||
long **p = getRawDataArray(rawDataFileName);
|
long **p = getRawDataArray(rawDataFileName);
|
||||||
printArrayData(p,nRow,nCol);
|
printArrayData(p, nRowRawData, nCol);
|
||||||
double pww[nCol-1];
|
double pww[nCol - 1];
|
||||||
if(p !=NULL){
|
if (p != NULL)
|
||||||
if(pw == NULL){
|
{
|
||||||
powerCalculation(p,pww);
|
if (pw == NULL)
|
||||||
appendDataInFile("powerData.csv",pww,nCol-1);
|
{
|
||||||
}else{
|
powerCalculation(p, pww);
|
||||||
powerCalculation(p,pw[1]);
|
appendDataInFile("powerData.csv", pww, nCol - 1);
|
||||||
appendDataInFile("powerData.csv",pw[1],nCol-1);
|
|
||||||
}
|
}
|
||||||
freeArray(p,nRowRawData);
|
else
|
||||||
|
{
|
||||||
|
powerCalculation(p, pw[1]);
|
||||||
|
appendDataInFile("powerData.csv", pw[1], nCol - 1);
|
||||||
|
}
|
||||||
|
freeArray(p, nRowRawData);
|
||||||
}
|
}
|
||||||
}
|
}
|
155
Code-C/queue.c
155
Code-C/queue.c
|
@ -5,27 +5,29 @@
|
||||||
#include "queue.h"
|
#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 charLen lenght of tabChar pointeur
|
||||||
* @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;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct queue *Pqueue;
|
typedef struct queue *Pqueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief create an empty element of queue
|
* @brief create an empty element of queue
|
||||||
*
|
*
|
||||||
* @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;
|
||||||
new->tabChar = NULL;
|
new->tabChar = NULL;
|
||||||
|
@ -33,92 +35,100 @@ Pqueue queueCreateEmpty(){
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************ SETTER ************/
|
/************ SETTER ************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief set char size array
|
* @brief set char size array
|
||||||
*
|
*
|
||||||
* @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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief set the char array in the element
|
* @brief set the char array in the element
|
||||||
*
|
*
|
||||||
* @param elem targeted element
|
* @param elem targeted element
|
||||||
* @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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief set next pqueue element
|
* @brief set next pqueue element
|
||||||
*
|
*
|
||||||
* @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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************ GETTER ************/
|
/************ GETTER ************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief switch to the next element
|
* @brief switch to the next element
|
||||||
*
|
*
|
||||||
* @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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief get the size char array
|
* @brief get the size char array
|
||||||
*
|
*
|
||||||
* @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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief get the pointer of char array
|
* @brief get the pointer of char array
|
||||||
*
|
*
|
||||||
* @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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************ ************/
|
/************ ************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create Element of queue
|
* @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
|
* @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);
|
||||||
new->pNextE = NULL;
|
new->pNextE = NULL;
|
||||||
|
@ -127,14 +137,16 @@ Pqueue queueCreateE(int lenChar, const char* _tabChar){
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief remove and free the last element of queue
|
* @brief remove and free the last element of queue
|
||||||
*
|
*
|
||||||
* @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, previous = NULL;
|
||||||
while(elem->pNextE != NULL){
|
while (elem->pNextE != NULL)
|
||||||
|
{
|
||||||
previous = tmp;
|
previous = tmp;
|
||||||
tmp = queueGetNextE(tmp);
|
tmp = queueGetNextE(tmp);
|
||||||
}
|
}
|
||||||
|
@ -146,22 +158,27 @@ 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)
|
||||||
*/
|
*/
|
||||||
void queueRmFrstE(Pqueue elem){
|
void queueRmFrstE(Pqueue elem)
|
||||||
|
{
|
||||||
assert(elem);
|
assert(elem);
|
||||||
free(elem->tabChar);
|
if (elem->tabChar != NULL)
|
||||||
|
{
|
||||||
|
free(elem->tabChar);
|
||||||
|
}
|
||||||
free(elem);
|
free(elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief delete the first value and return the next value
|
* @brief delete the first value and return the next value
|
||||||
*
|
*
|
||||||
* @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);
|
||||||
|
@ -169,52 +186,70 @@ 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 elem Pqueue will be added at the end of queue
|
||||||
* @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);
|
assert(str);
|
||||||
Pqueue next = elem, previous = NULL;
|
Pqueue next = elem, previous = NULL;
|
||||||
while(next->pNextE != NULL){
|
while (next->pNextE != NULL)
|
||||||
|
{
|
||||||
previous = next;
|
previous = next;
|
||||||
next = queueGetNextE(next);
|
next = queueGetNextE(next);
|
||||||
}
|
}
|
||||||
previous = next;
|
previous = next;
|
||||||
next = queueCreateE(len,str);
|
next = queueCreateE(len, str);
|
||||||
queueSetNextE(previous,next);
|
queueSetNextE(previous, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Print targeted element
|
* @brief Print targeted element
|
||||||
*
|
*
|
||||||
* @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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Print all the element starting from @param firstE till the end of the linked list
|
* @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);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
121
Code-C/queue.h
121
Code-C/queue.h
|
@ -1,27 +1,126 @@
|
||||||
typedef struct queue *Pqueue;
|
typedef struct queue *Pqueue;
|
||||||
|
|
||||||
//Constructors
|
/**
|
||||||
Pqueue queueCreateE(int lenChar, const char* _tabChar);
|
* @brief Create Element of queue
|
||||||
Pqueue queueCreateEmpty();
|
*
|
||||||
|
* @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
|
/************** Getters **************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief switch to the next element
|
||||||
|
*
|
||||||
|
* @param elem current element
|
||||||
|
* @return Pqueue next element
|
||||||
|
*/
|
||||||
Pqueue queueGetNextE(Pqueue elem);
|
Pqueue queueGetNextE(Pqueue elem);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief get the size char array
|
||||||
|
*
|
||||||
|
* @param elem targeted element
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
int queueGetCharLen(Pqueue elem);
|
int queueGetCharLen(Pqueue elem);
|
||||||
char* queueGetTabChar(Pqueue elem);
|
|
||||||
|
|
||||||
//Setters
|
/**
|
||||||
|
* @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);
|
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);
|
void queueSetTabChar(Pqueue elem, int _charLen, const char *_tabChar);
|
||||||
void queueSetNextE(Pqueue elem , Pqueue next);
|
|
||||||
|
|
||||||
void queueAddLastQ(Pqueue elem, const char* str, int len);
|
/**
|
||||||
|
* @brief set next pqueue element
|
||||||
|
*
|
||||||
|
* @param elem target element
|
||||||
|
* @param next next element
|
||||||
|
*/
|
||||||
|
void queueSetNextE(Pqueue elem, Pqueue next);
|
||||||
|
|
||||||
//Removers
|
/**
|
||||||
|
* @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);
|
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)
|
||||||
|
*/
|
||||||
void queueRmFrstE(Pqueue elem);
|
void queueRmFrstE(Pqueue elem);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief delete the first value and return the next value
|
||||||
|
*
|
||||||
|
* @param elem
|
||||||
|
* @return Pqueue
|
||||||
|
*/
|
||||||
Pqueue queueNextDelFrst(Pqueue elem);
|
Pqueue queueNextDelFrst(Pqueue elem);
|
||||||
|
|
||||||
//print function
|
/************** print function **************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Print targeted element
|
||||||
|
*
|
||||||
|
* @param elem targeted element
|
||||||
|
*/
|
||||||
void queuePrintE(Pqueue elem);
|
void queuePrintE(Pqueue elem);
|
||||||
void queuePrintWholeQ(Pqueue firstE);
|
|
||||||
|
/**
|
||||||
|
* @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);
|
|
@ -1,93 +1,109 @@
|
||||||
#include "simulateFlux.h"
|
#include "simulateFlux.h"
|
||||||
#include "initialParameters.h"
|
#include "initialParameters.h"
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
//#include <linux/time.h>
|
||||||
|
|
||||||
|
#include "time.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief convert an interger N into a char*
|
* @brief convert an interger N into a char*
|
||||||
*
|
*
|
||||||
* @param N
|
* @param N
|
||||||
* @return char*
|
* @return char*
|
||||||
*/
|
*/
|
||||||
char* convertIntegerToChar(int N)
|
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*sizeof(char));
|
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';
|
||||||
return (char*)arr;
|
return (char *)arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a New Raw Data File Name
|
* @brief Create a New Raw Data File Name
|
||||||
*
|
*
|
||||||
* @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;
|
// char *fileNumber;
|
||||||
//sprintf(fileNumber, "%d", cptFile);
|
// sprintf(fileNumber, "%d", cptFile);
|
||||||
//printf("%s\n" , fileNumber);
|
// 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 *));
|
||||||
|
|
||||||
strcpy( fileNameNumber, fileName );
|
strcpy(fileNameNumber, fileName);
|
||||||
strcat( fileNameNumber, fileNumber );
|
strcat(fileNameNumber, fileNumber);
|
||||||
|
|
||||||
|
strcpy(fullFileName, fileNameNumber);
|
||||||
|
strcat(fullFileName, extension);
|
||||||
|
|
||||||
strcpy( fullFileName, fileNameNumber );
|
|
||||||
strcat( fullFileName, extension );
|
|
||||||
|
|
||||||
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;
|
{
|
||||||
for(int i = 0 ; i < N ; i++){
|
int max = 0;
|
||||||
if(array[i]>max) max = array[i];
|
for (int i = 0; i < N; i++)
|
||||||
|
{
|
||||||
|
if (array[i] > max)
|
||||||
|
max = array[i];
|
||||||
}
|
}
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief return the unix time in millisecond
|
* @brief return the unix time in millisecond
|
||||||
*
|
*
|
||||||
* @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)now.tv_sec) * 1000 + ((int64_t)now.tv_nsec) / 1000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lastIndexCaptor()
|
||||||
int lastIndexCaptor(){
|
{
|
||||||
int lastIndex = 0;
|
int lastIndex = 0;
|
||||||
for(int i = 1 ; i < 8 ; i++){
|
for (int i = 1; i < 8; i++)
|
||||||
if(selectionCaptors[i]){
|
{
|
||||||
|
if (selectionCaptors[i])
|
||||||
|
{
|
||||||
lastIndex = i;
|
lastIndex = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,82 +112,97 @@ int lastIndexCaptor(){
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief write one lign of rawData in the file @param rawDataFile (simulate of freq of the Vegetal Signals Captor)
|
* @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 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;
|
quartet value;
|
||||||
|
|
||||||
if(fread(&buff, 26, 1, stdin)) {
|
if (fread(&buff, 26, 1, stdin))
|
||||||
//printf("%d\n",cptValue);
|
{
|
||||||
if(cptValue < nbRowBinFile - nbRowIgnore){
|
// printf("%d\n",cptValue);
|
||||||
FILE *timeFile = fopen("timeFile.csv" , "a+");
|
if (cptValue < nbRowBinFile - nbRowIgnore)
|
||||||
fprintf(timeFile , "%ld\n", millis());
|
{
|
||||||
|
FILE *timeFile = fopen("timeFile.csv", "a+");
|
||||||
|
fprintf(timeFile, "%ld\n", millis());
|
||||||
fclose(timeFile);
|
fclose(timeFile);
|
||||||
fprintf(rawDataFile , "%ld,", millis());
|
fprintf(rawDataFile, "%ld,", millis());
|
||||||
if (strncmp(buff, "#################\n", (size_t)18) == 0) {
|
if (strncmp(buff, "#################\n", (size_t)18) == 0)
|
||||||
if (!(fread(&buff2, 18, 1, stdin))) {
|
{
|
||||||
|
if (!(fread(&buff2, 18, 1, stdin)))
|
||||||
|
{
|
||||||
fprintf(stderr, "Erreur lecture après ###...#");
|
fprintf(stderr, "Erreur lecture après ###...#");
|
||||||
} 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(selectionCaptors[i-1]){
|
{
|
||||||
value.octet1 = buff[3*i+1];
|
if (selectionCaptors[i - 1])
|
||||||
value.octet2 = buff[3*i+2];
|
{
|
||||||
value.octet3 = buff[3*i+3];
|
value.octet1 = buff[3 * i + 1];
|
||||||
|
value.octet2 = buff[3 * i + 2];
|
||||||
|
value.octet3 = buff[3 * i + 3];
|
||||||
value.octet4 = 0;
|
value.octet4 = 0;
|
||||||
|
|
||||||
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+");
|
FILE *allRawDataFile = fopen("AllRawData.csv", "a+");
|
||||||
if(i-1==lastIndex){
|
if (i - 1 == lastIndex)
|
||||||
fprintf(rawDataFile, "%d\n", values[i]/256);
|
{
|
||||||
fprintf(allRawDataFile, "%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(allRawDataFile, "%d,", values[i]/256);
|
fprintf(rawDataFile, "%d,", values[i] / 256);
|
||||||
|
fprintf(allRawDataFile, "%d,", values[i] / 256);
|
||||||
}
|
}
|
||||||
fclose(allRawDataFile);
|
fclose(allRawDataFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cptData++;
|
cptData++;
|
||||||
//sleep(0.004); //simul freq here
|
// sleep(0.004); //simul freq here
|
||||||
|
|
||||||
cptValue++;
|
cptValue++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
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 == nRowRawData){
|
{
|
||||||
|
if (cptData == nRowRawData)
|
||||||
|
{
|
||||||
fclose(rawDataFile);
|
fclose(rawDataFile);
|
||||||
cptData = 0;
|
cptData = 0;
|
||||||
cptFile++;
|
cptFile++;
|
||||||
//create struct here
|
// create struct here
|
||||||
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+");
|
FILE *rawDataFile = fopen(fileName, "w+");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rawDataWriteFlag = false;
|
rawDataWriteFlag = false;
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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("dummy", argv[1]) == 0)
|
|
||||||
ok = test_dummy();
|
|
||||||
else if (strcmp("is_lighted",argv[1]) == 0){
|
|
||||||
ok = test_game_is_lighted();
|
|
||||||
}else if(strcmp("has_error",argv[1]) == 0){
|
|
||||||
ok = test_game_has_error();
|
|
||||||
}else if(strcmp("check_move",argv[1]) == 0){
|
|
||||||
ok = test_game_check_move();
|
|
||||||
}else if(strcmp("game_is_over",argv[1]) == 0){
|
|
||||||
ok = test_game_is_over();
|
|
||||||
}else if(strcmp("play_move",argv[1]) == 0){
|
|
||||||
ok = test_game_play_move();
|
|
||||||
}else if(strcmp("game_restart",argv[1]) == 0){
|
|
||||||
ok = test_game_restart();
|
|
||||||
}else if(strcmp("update_flags",argv[1]) == 0){
|
|
||||||
ok = test_game_update_flags();
|
|
||||||
}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;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue