CMakelists add few test queue

This commit is contained in:
Aurélien Gauthier 2022-06-21 15:13:10 +02:00
parent f4fd64e63c
commit ade5b4378f
14 changed files with 641 additions and 274 deletions

5
.gitignore vendored
View file

@ -4,7 +4,10 @@
*.csv
Code-C/main
Code-C/exec
Code-C/exect
Code-C/ctest
Code-C/DartConfiguration.tcl
Makefile
# Created by https://www.toptal.com/developers/gitignore/api/cmake,c

View file

@ -15,6 +15,7 @@
"*.tcc": "c",
"type_traits": "c",
"simulateflux.h": "c",
"pthread.h": "c"
"pthread.h": "c",
"types.h": "c"
}
}

View file

@ -3,8 +3,25 @@ project(Traitement-signal-plantes C)
include(CTest)
enable_testing()
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 main.c simulateFlux.c queue.c power.c growthRate.c average.c getArray.c fileGestion.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)
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)

View file

@ -1,4 +1,20 @@
#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();
}

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;
}

184
Code-C/ctest.c Normal file
View 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;
}
}

Binary file not shown.

View file

@ -18,8 +18,8 @@ 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};
// 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;
@ -28,11 +28,14 @@ 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);
powerFunction(fileName, NULL);
@ -41,11 +44,14 @@ void *threadCalculPower(void *vargp){
}
}
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);
averageFunction(fileName, NULL);
@ -54,62 +60,79 @@ void *threadCalculAverage(void *vargp){
}
}
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);
powerFunction(fileName, NULL);
averageFunction(fileName , NULL);
averageFunction(fileName, NULL);
remove(fileName);
}
}
}
void *threadCalculGrowthRate(void * vargp){
void *threadCalculGrowthRate(void *vargp)
{
Pqueue rawDataQueue = firstRawDataQueue;
char* fileName;
//double pw[nCol-1];
double **dataLignPw = getDoubleArray(2,nCol);
double **dataLignAv = getDoubleArray(2,nCol);
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){
while (rawDataWriteFlag)
{
while (queueGetNextE(rawDataQueue) != NULL)
{
rawDataQueue = queueGetNextE(rawDataQueue);
fileName = queueGetTabChar(rawDataQueue);
if(i < 2){
if(i == 1){
if (i < 2)
{
if (i == 1)
{
powerFunction(fileName, dataLignPw);
averageFunction(fileName , dataLignAv);
growthRateFunction(dataLignPw , "growthRatePw.csv");
growthRateFunction(dataLignPw,"growthRateAv.csv");
}else{
averageFunction(fileName , dataLignAv);
averageFunction(fileName, dataLignAv);
growthRateFunction(dataLignPw, "growthRatePw.csv");
growthRateFunction(dataLignPw, "growthRateAv.csv");
}
else
{
averageFunction(fileName, dataLignAv);
powerFunction(fileName, dataLignPw);
}
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];
dataLignAv[0][y] = dataLignAv[1][y];
}
powerFunction(fileName, dataLignPw);
averageFunction(fileName , dataLignAv);
growthRateFunction(dataLignPw,"growthRatePw.csv");
growthRateFunction(dataLignPw,"growthRateAv.csv");
averageFunction(fileName, dataLignAv);
growthRateFunction(dataLignPw, "growthRatePw.csv");
growthRateFunction(dataLignPw, "growthRateAv.csv");
}
remove(fileName);
}
}
}
int main(int argc , char** argv){
int main(int argc, char **argv)
{
for(int i = 0 ; i < 8 ; i++){
if(selectionCaptors[i]){
for (int i = 0; i < 8; i++)
{
if (selectionCaptors[i])
{
nCol++;
}
}
@ -117,13 +140,13 @@ int main(int argc , char** argv){
rawDataWriteFlag = true;
period = 1 / freqEch;
invTimeBandWidth = 1 /(nRowRawData * period);
invTimeBandWidth = 1 / (nRowRawData * period);
firstRawDataQueue = queueCreateEmpty(); // change this for create empty
pthread_t rawData;
pthread_create(&rawData , NULL, threadSimulateFlux, (void *)&rawData);
pthread_create(&rawData, NULL, threadSimulateFlux, (void *)&rawData);
pthread_t calcul;
pthread_create(&calcul , NULL, threadCalculGrowthRate, (void *)&calcul);
pthread_create(&calcul, NULL, threadCalculGrowthRate, (void *)&calcul);
pthread_exit(NULL);
}

View file

@ -1,3 +1,4 @@
#include <math.h>
#include "power.h"
#include "getArray.h"
#include "fileGestion.h"
@ -10,18 +11,20 @@
* @param p array with all the values that will be used for the calcul
* @param powerArray array where results are stocked
*/
void powerCalculation(long **p, double powerArray[]){
for(int i = 0; i < nCol; i++){
void powerCalculation(long **p, double powerArray[])
{
for (int i = 0; i < nCol; i++)
{
int j = 0;
powerArray[i] = 0;
while(j < nRowRawData){
powerArray[i] += pow(p[j][i+1],2);
while (j < nRowRawData)
{
powerArray[i] += pow(p[j][i + 1], 2);
j++;
}
powerArray[i] /= nRowRawData;
}
}
/**
@ -31,18 +34,23 @@ void powerCalculation(long **p, double powerArray[]){
* @param N number of rows 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);
printArrayData(p,nRow,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);
printArrayData(p, nRowRawData, nCol);
double pww[nCol - 1];
if (p != NULL)
{
if (pw == NULL)
{
powerCalculation(p, pww);
appendDataInFile("powerData.csv", pww, nCol - 1);
}
freeArray(p,nRowRawData);
else
{
powerCalculation(p, pw[1]);
appendDataInFile("powerData.csv", pw[1], nCol - 1);
}
freeArray(p, nRowRawData);
}
}

View file

@ -11,9 +11,10 @@
* @param tabChar char array pointer
* @param pNextE point next element
*/
struct queue {
struct queue
{
int charLen;
char* tabChar;
char *tabChar;
Pqueue pNextE;
};
@ -24,8 +25,9 @@ typedef struct queue *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,7 +35,7 @@ Pqueue queueCreateEmpty(){
return new;
}
/************ SETTER ************/
/************ SETTER ************/
/**
* @brief set char size array
@ -41,7 +43,8 @@ Pqueue queueCreateEmpty(){
* @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;
}
@ -53,12 +56,14 @@ void queueSetCharLen(Pqueue elem, int _charLen){
* @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];
}
}
@ -68,13 +73,14 @@ void queueSetTabChar(Pqueue elem, int _charLen, const char *_tabChar){
* @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
@ -82,7 +88,8 @@ void queueSetNextE(Pqueue elem , Pqueue next){
* @param elem current element
* @return Pqueue next element
*/
Pqueue queueGetNextE(Pqueue elem){
Pqueue queueGetNextE(Pqueue elem)
{
assert(elem);
return elem->pNextE;
}
@ -93,7 +100,8 @@ Pqueue queueGetNextE(Pqueue elem){
* @param elem targeted element
* @return int
*/
int queueGetCharLen(Pqueue elem){
int queueGetCharLen(Pqueue elem)
{
assert(elem);
return elem->charLen;
}
@ -104,12 +112,13 @@ int queueGetCharLen(Pqueue elem){
* @param elem targeted elemnt
* @return char*
*/
char * queueGetTabChar(Pqueue elem){
char *queueGetTabChar(Pqueue elem)
{
assert(elem);
return elem->tabChar;
}
/************ ************/
/************ ************/
/**
* @brief Create Element of queue
@ -117,8 +126,9 @@ char * queueGetTabChar(Pqueue elem){
* @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;
@ -131,10 +141,12 @@ Pqueue queueCreateE(int lenChar, const char* _tabChar){
* @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){
while (elem->pNextE != NULL)
{
previous = tmp;
tmp = queueGetNextE(tmp);
}
@ -149,9 +161,13 @@ Pqueue queueRmLastE(Pqueue elem){
*
* @param elem target to remove (the element need to be the first)
*/
void queueRmFrstE(Pqueue elem){
void queueRmFrstE(Pqueue elem)
{
assert(elem);
if (elem->tabChar != NULL)
{
free(elem->tabChar);
}
free(elem);
}
@ -161,7 +177,8 @@ void queueRmFrstE(Pqueue elem){
* @param elem
* @return Pqueue
*/
Pqueue queueNextDelFrst(Pqueue elem){
Pqueue queueNextDelFrst(Pqueue elem)
{
assert(elem);
Pqueue tmp = elem->pNextE;
queueRmFrstE(elem);
@ -175,17 +192,19 @@ Pqueue queueNextDelFrst(Pqueue elem){
* @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){
while (next->pNextE != NULL)
{
previous = next;
next = queueGetNextE(next);
}
previous = next;
next = queueCreateE(len,str);
queueSetNextE(previous,next);
next = queueCreateE(len, str);
queueSetNextE(previous, next);
}
/**
@ -193,13 +212,16 @@ void queueAddLastQ(Pqueue elem, const char* str, int len){
*
* @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");
}
}
@ -209,12 +231,25 @@ void queuePrintE(Pqueue elem){
*
* @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 +1,126 @@
typedef struct queue *Pqueue;
//Constructors
Pqueue queueCreateE(int lenChar, const char* _tabChar);
/**
* @brief Create Element of queue
*
* @param lenChar size of char array that will be created
* @return Pqueue new element created
*/
Pqueue queueCreateE(int lenChar, const char *_tabChar);
/**
* @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);
/**
* @brief get the size char array
*
* @param elem targeted element
* @return int
*/
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);
/**
* @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 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);
/**
* @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);
/**
* @brief delete the first value and return the next value
*
* @param elem
* @return Pqueue
*/
Pqueue queueNextDelFrst(Pqueue elem);
//print function
/************** 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

@ -1,6 +1,9 @@
#include "simulateFlux.h"
#include "initialParameters.h"
#include "queue.h"
//#include <linux/time.h>
#include "time.h"
/**
* @brief convert an interger N into a char*
@ -8,29 +11,32 @@
* @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*sizeof(char));
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;
}
/**
@ -38,36 +44,43 @@ char* convertIntegerToChar(int N)
*
* @return char*
*/
char *createNewRawDataFileName(){
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 *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 maxInArray(int *array, int N)
{
int max = 0;
for(int i = 0 ; i < N ; i++){
if(array[i]>max) max = array[i];
for (int i = 0; i < N; i++)
{
if (array[i] > max)
max = array[i];
}
return max;
}
@ -76,18 +89,21 @@ int maxInArray(int *array , int N){
*
* @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)now.tv_sec) * 1000 + ((int64_t)now.tv_nsec) / 1000000;
}
int lastIndexCaptor(){
int lastIndexCaptor()
{
int lastIndex = 0;
for(int i = 1 ; i < 8 ; i++){
if(selectionCaptors[i]){
for (int i = 1; i < 8; i++)
{
if (selectionCaptors[i])
{
lastIndex = i;
}
}
@ -101,77 +117,92 @@ int lastIndexCaptor(){
* @return true if the lign is correctly write , else :
* @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());
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 (strncmp(buff, "#################\n", (size_t)18) == 0) {
if (!(fread(&buff2, 18, 1, stdin))) {
fprintf(rawDataFile, "%ld,", millis());
if (strncmp(buff, "#################\n", (size_t)18) == 0)
{
if (!(fread(&buff2, 18, 1, stdin)))
{
fprintf(stderr, "Erreur lecture après ###...#");
} else {
}
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]){
value.octet1 = buff[3*i+1];
value.octet2 = buff[3*i+2];
value.octet3 = buff[3*i+3];
for (int i = 1; i < 9; i++)
{
if (selectionCaptors[i - 1])
{
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;
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);
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);
else
{
fprintf(rawDataFile, "%d,", values[i] / 256);
fprintf(allRawDataFile, "%d,", values[i] / 256);
}
fclose(allRawDataFile);
}
}
cptData++;
//sleep(0.004); //simul freq here
// sleep(0.004); //simul freq here
cptValue++;
return true;
}
else {
else
{
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 == nRowRawData){
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+");
FILE *rawDataFile = fopen(fileName, "w+");
}
}
rawDataWriteFlag = false;

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,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;
}
}