threads clean , captors choice ok

This commit is contained in:
quentin.perret 2022-06-15 10:49:21 +02:00
parent f9a6f00972
commit 33115049f6
7 changed files with 23 additions and 13 deletions

View file

@ -10,10 +10,10 @@
* @param averageArray array where results are stocked * @param averageArray array where results are stocked
*/ */
void averageCalculation(long **p, double averageArray[]){ void averageCalculation(long **p, double averageArray[]){
for(int i = 0; i < nCol-1; i++){ for(int i = 1; i < nCol; i++){
int j = 0; int j = 0;
averageArray[i] = 0; averageArray[i] = 0;
while(j < nRow){ while(j < nRow -1){
averageArray[i] += p[i][j]; averageArray[i] += p[i][j];
j++; j++;
} }

View file

@ -70,9 +70,9 @@ bool checkArrayFullyFill(long **p, int N){
* @param N number of rows in array * @param N number of rows in array
*/ */
void freeArray(long **p, int N) { void freeArray(long **p, int N) {
int i; for(int i = 0 ; i < N ; i++){
for(i = 0 ; i < N ; i++)
free(p[i]); free(p[i]);
}
free(p); free(p);
} }
@ -87,14 +87,12 @@ void freeArray(long **p, int N) {
long **getRawDataArray(char* rawDataFileName){ long **getRawDataArray(char* rawDataFileName){
long **p; long **p;
p = get(nRow, nCol); p = get(nRow, nCol);
printf("before fill\n");
fillArrayWithRawData(rawDataFileName,p ,nRow, nCol); fillArrayWithRawData(rawDataFileName,p ,nRow, nCol);
printf("after fill\n"); //if(checkArrayFullyFill(p,nRow)){
if(checkArrayFullyFill(p,nRow, nCol)){
//clearRawData(N); //clearRawData(N);
return p; return p;
} /*}
else{ else{
return NULL; return NULL;
} }*/
} }

View file

@ -8,4 +8,4 @@
long **getRawDataArray(char *rawDataFileName); long **getRawDataArray(char *rawDataFileName);
void printArrayData(long** p, int N, int M); void printArrayData(long** p, int N, int M);
void freeArray(long **p, int N); void freeArray(long **p, int N);
bool checkArrayFullyFill(long **p, int N , int M); bool checkArrayFullyFill(long **p, int N );

View file

@ -6,6 +6,8 @@ extern int nRow;
extern int nCol; extern int nCol;
extern double freqEch; extern double freqEch;
extern int cptFile;
extern double period; extern double period;
extern double invTimeBandWidth; extern double invTimeBandWidth;

Binary file not shown.

View file

@ -69,7 +69,6 @@ int main(int argc , char** argv){
nCol++; nCol++;
} }
} }
printf("%d\n" , nCol);
rawDataWriteFlag = true; rawDataWriteFlag = true;
@ -81,7 +80,7 @@ int main(int argc , char** argv){
pthread_create(&rawData , NULL, threadSimulateFlux, (void *)&rawData); pthread_create(&rawData , NULL, threadSimulateFlux, (void *)&rawData);
pthread_t calcul; pthread_t calcul;
pthread_create(&calcul , NULL, threadCalculPower, (void *)&calcul); pthread_create(&calcul , NULL, threadCalculBoth, (void *)&calcul);
pthread_exit(NULL); pthread_exit(NULL);
} }

View file

@ -83,6 +83,16 @@ int64_t millis()
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 lastIndex = 0;
for(int i = 1 ; i < 8 ; i++){
if(selectionCaptors[i]){
lastIndex = i;
}
}
return lastIndex;
}
/** /**
* @brief write one lign of rawData in the file @param rawDataFile (simulate of freq of the Vegetal Signals Captor) * @brief write one lign of rawData in the file @param rawDataFile (simulate of freq of the Vegetal Signals Captor)
* *
@ -107,6 +117,7 @@ bool writeOneRawData(FILE *rawDataFile){
strncpy(&buff[8], buff2, 18); strncpy(&buff[8], buff2, 18);
} }
} }
int lastIndex = lastIndexCaptor();
for (int i = 1; i < 9; i++){ for (int i = 1; i < 9; i++){
if(selectionCaptors[i]){ if(selectionCaptors[i]){
value.octet1 = buff[3*i+1]; value.octet1 = buff[3*i+1];
@ -117,7 +128,7 @@ bool writeOneRawData(FILE *rawDataFile){
valbin[i] = buff[3*i+1]*256*256*256 + buff[3*i+2]*256*256 + buff[3*i+3]*256; valbin[i] = buff[3*i+1]*256*256*256 + buff[3*i+2]*256*256 + buff[3*i+3]*256;
memcpy(&values[i], &valbin[i], sizeof(uint32_t)); memcpy(&values[i], &valbin[i], sizeof(uint32_t));
if(i==8){ if(i==lastIndex){
fprintf(rawDataFile, "%d\n", values[i]/256); fprintf(rawDataFile, "%d\n", values[i]/256);
} }
else{ else{