This commit is contained in:
Vincenzo Pio Florio 2024-11-20 01:26:04 +01:00
parent eb76c2e4c7
commit 4a97a81d7a
3 changed files with 12 additions and 33 deletions

View File

@ -5,25 +5,14 @@
#include <math.h>
#include <stdlib.h>
// Struttura per la gestione dei dati di acquisizione
typedef struct {
int sensorsNumber;
int slidingWindowSize;
} dataAcquisition;
// Funzioni per la gestione dei dati di acquisizione
void initializeReadings();
void freeReadings();
// Funzioni getter
int getSensorsNumber();
int getSlidingWindowSize();
bool isFull(int sensorIndex);
// Funzioni setter
void addReading(float value, int sensorIndex);
void setSensorsNumber(int number);
void setSlidingWindowSize(int size);
float getAverageOnSensor(int sensorIndex);
float getAverageOnAllSensors();

View File

@ -4,11 +4,19 @@
#include <math.h>
// Variable definition
static float **readings;
static int sensorsNumber;
static int slidingWindowSize;
static void setSensorsNumber(int number) {
sensorsNumber = number;
}
static void setSlidingWindowSize(int size) {
slidingWindowSize = size;
}
int sensorsNumber;
int slidingWindowSize;
void initializeReadings(int numSensors, int windowSize) {
readings = (float **)malloc(numSensors * sizeof(float *));
if (readings == NULL) {
@ -22,7 +30,7 @@ void initializeReadings(int numSensors, int windowSize) {
exit(EXIT_FAILURE);
}
}
// Assign sensorsNumber and slidingWindowSize
// Chiamate private ai setter
setSensorsNumber(numSensors);
setSlidingWindowSize(windowSize);
}
@ -34,13 +42,6 @@ void freeReadings() {
free(readings);
}
typedef struct
{
int sensorsNumber;
int slidingWindowSize;
} dataAcquisition;
// Functions
// Get the number of sensors
@ -53,16 +54,6 @@ int getSlidingWindowSize() {
return slidingWindowSize;
}
// Set the number of sensors
void setSensorsNumber(int number) {
sensorsNumber = number;
}
// Set the sliding window size
void setSlidingWindowSize(int size) {
slidingWindowSize = size;
}
// Control on the fullness of the sliding window
bool isFull(int sensorIndex) {
for (int i = 0; i < slidingWindowSize; i++) {

View File

@ -11,7 +11,6 @@ void test_initializeReadings() {
int main() {
printf("Running tests...\n");
test_initializeReadings();
return 0;
}