go back to : threads clean , captors choice ok

This commit is contained in:
quentin.perret 2022-06-15 16:56:58 +02:00
parent 9bb5e5e99d
commit 9030c3df0e
6 changed files with 31 additions and 14 deletions

View file

@ -11,11 +11,11 @@
* @param N number of rows in p * @param N number of rows in p
* @param M number of columns in p * @param M number of columns in p
*/ */
void averageCalculation(long **p, double averageArray[] , int N, int M){ void averageCalculation(long **p, double averageArray[]){
for(int i = 0; i < M-1; i++){ for(int i = 1; i < nCol; i++){
int j = 0; int j = 0;
averageArray[i] = 0; averageArray[i] = 0;
while(j < N){ while(j < nRow -1){
averageArray[i] += p[i][j]; averageArray[i] += p[i][j];
j++; j++;
} }

View file

@ -69,9 +69,9 @@ bool checkArrayFullyFill(long **p, int N , int M){
* @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);
} }
@ -85,13 +85,13 @@ void freeArray(long **p, int N) {
*/ */
long **getRawDataArray(char* rawDataFileName , int N , int M){ long **getRawDataArray(char* rawDataFileName , int N , int M){
long **p; long **p;
p = get(N, M); p = get(nRow, nCol);
fillArrayWithRawData(rawDataFileName,p ,N, M); fillArrayWithRawData(rawDataFileName,p ,nRow, nCol);
if(checkArrayFullyFill(p,N,M)){ //if(checkArrayFullyFill(p,nRow)){
//clearRawData(N); //clearRawData(N);
return p; return p;
} /*}
else{ else{
return NULL; return NULL;
} }*/
} }

View file

@ -8,4 +8,4 @@
long **getRawDataArray(char *rawDataFileName, int N , int M); long **getRawDataArray(char *rawDataFileName, int N , int M);
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;

View file

@ -64,6 +64,12 @@ void *threadCalculBoth(void *vargp){
int main(int argc , char** argv){ int main(int argc , char** argv){
for(int i = 0 ; i < 8 ; i++){
if(selectionCaptors[i]){
nCol++;
}
}
rawDataWriteFlag = true; rawDataWriteFlag = true;
period = 1 / freqEch; period = 1 / freqEch;

View file

@ -80,6 +80,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)
* *
@ -106,7 +116,7 @@ bool writeOneRawData(FILE *rawDataFile){
strncpy(&buff[8], buff2, 18); strncpy(&buff[8], buff2, 18);
} }
} }
int maxCApteurNb = maxInArray(selectionCaptors,sizeSelectionArray); int lastIndex = lastIndexCaptor();
for (int i = 1; i < 9; i++){ for (int i = 1; i < 9; i++){
if(intInArray(i,selectionCaptors,sizeSelectionArray)==0){ if(intInArray(i,selectionCaptors,sizeSelectionArray)==0){
value.octet1 = buff[3*i+1]; value.octet1 = buff[3*i+1];
@ -117,8 +127,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==lastIndex){
if(i==maxCApteurNb){
fprintf(rawDataFile, "%d\n", values[i]/256); fprintf(rawDataFile, "%d\n", values[i]/256);
} }
else{ else{