-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduilink.h
112 lines (92 loc) · 2.57 KB
/
Arduilink.h
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <Arduino.h>
#define S_INFO 1
#define S_HIT 2
#define S_ACTION 4
#define S_BATTERY 8
typedef struct SensorItem {
// Main attributes
unsigned int id;
unsigned int flags;
const char* name;
const char* unit;
void(*writter)(const char *msg);
// Operational attributes
bool verbose;
String value;
// Chained list
SensorItem* next;
};
class Arduilink {
public:
/**
* Constructor.
*/
Arduilink(unsigned int nodeId);
/**
* Prepares communication on the serial link by sending a frame indicating the identifier of the node and the protocol version used.
*/
void init();
/**
* Adds a sensor with minimal information.
*/
SensorItem* addSensor(unsigned int sensorId, unsigned int sensorFlags, const char* sensorName, const char* quantityUnit);
/**
* Adds a sensor with a callback function used to execute operations on it.
*/
SensorItem* addSensor(unsigned int sensorId, unsigned int sensorFlags, const char* sensorName, const char* quantityUnit, void(*_writter)(const char *msg));
/**
* Get a sensor by id.
*/
SensorItem* getSensor(unsigned int sensorId);
/**
* Update the current value of a sensor.
*/
SensorItem* setValue(unsigned int sensorId, const char* sensorValue);
/**
* Update the current value of a sensor.
*/
SensorItem* setValue(unsigned int sensorId, double sensorValue);
/**
* Update the current value of a sensor.
*/
SensorItem* setValue(unsigned int sensorId, unsigned long sensorValue);
/**
* Send an operation to a sensor.
*/
void send(unsigned int sensorId, String &msg);
/**
* Send an operation to a sensor.
*/
void send(unsigned int sensorId, const char* msg);
/**
* Indicate that sensor returns an error.
*/
void setFailure(unsigned int sensorId, const char* msg);
/**
* Return current value of this sensor as encoded 32 long.
*/
unsigned long getEncoded32(unsigned int sensorId);
/**
* Describes all sensors and sends the information on the serial link .
*/
void printSensors();
/**
* Manages the reception of data over the serial link, to interpret and handle received orders.
* Returns:
* 0 OK, command handled
* 1 OK, nothing to handle
* 2 Invalid opcode (400 bad request)
* 3 Invalid node-id (404 not found)
* 4 Invalid sensor-id
* 5 Invalid attribute for the SET operation (400 bad request)
* 6 Invalid value for an attribute, for the SET operation (400 bad request)
*/
int handleInput();
private:
unsigned int nodeId;
SensorItem *head;
SensorItem *queue;
int sensorsCount;
bool write;
void printSensor(SensorItem* sensor, unsigned int nodeId);
};