-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sensor.cpp
43 lines (36 loc) · 923 Bytes
/
Sensor.cpp
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
36
37
38
39
40
41
42
43
#include <iostream>
#include "Sensor.h"
#include "shirtt.h"
#define SHUTDOWN_DEBUG
//Task Spawning ( called from Sensor::init() )
static void* collector_task(void* c) {
setup_rt_task(10);
Sensor* s = (Sensor*)c;
s->collector();
}
static void* analysis_task(void* c) {
setup_rt_task(11);
Sensor* s = (Sensor*)c;
s->analysis();
}
void Sensor::init(){
init_sensor();
if(pthread_create( &tCollector, NULL, &collector_task, (void *)(this)) != 0) {
perror("Error creating collector thread for sensor! ");
}
if(pthread_create( &tAnalysis, NULL, &analysis_task, (void *)(this)) != 0) {
perror("Error creating analysis thread for sensor! ");
}
}
void Sensor::shutdown() {
#ifdef SHUTDOWN_DEBUG
std::cout << "Sensor Shutdown" << std::endl;
#endif
pthread_cancel(tCollector);
pthread_cancel(tAnalysis);
}
Sensor::~Sensor(){
#ifdef SHUTDOWN_DEBUG
std::cout << "Sensor Destructor" << std::endl;
#endif
}