-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsensoremu.cpp
More file actions
35 lines (34 loc) · 776 Bytes
/
Copy pathsensoremu.cpp
File metadata and controls
35 lines (34 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Sensor emulator to test the measuring module.
*/
#include <cstdlib>
#include <time.h>
#include "sensoremu.h"
double sensorEmu::doubleRand(double min, double max) {
srand(time(NULL));
double f = (double)rand()/RAND_MAX;
return min + (f*(max-min));
}
void sensorEmu::initSensor(void) {
temperature = 0.1;
humidity = 33.0;
crcError = 0;
}
sensorEmu::sensorEmu(void) {
initSensor();
if(bcm2835_init()==false) {
log::err("BCM2835 library initialization failed!");
}
}
sensorEmu::~sensorEmu(void) {
}
void sensorEmu::readOut(void) {
temperature = doubleRand(28.0, 45.0);
humidity = doubleRand(40.0, 80.0);
crcError = (int)doubleRand(0.0,2.0);
if(crcError>0) crcErrorCounter++;
else crcErrorCounter = 0;
}
bool sensorEmu::helloSensor(void) {
return true;
}