-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCommandInterface.h
149 lines (122 loc) · 3.58 KB
/
CommandInterface.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//
// Created by ebassetti on 23/07/15.
//
#ifndef GALILEO_TERREMOTI_COMMANDINTERFACE_H
#define GALILEO_TERREMOTI_COMMANDINTERFACE_H
#include "net/Udp.h"
#include "Seismometer.h"
#define CMD_INTERFACE_PORT 62001
#define PACKET_SIZE 252
typedef enum {
PKTTYPE_DISCOVERY = 1,
PKTTYPE_DISCOVERY_REPLY = 2,
PKYTYPE_PING = 3,
PKYTYPE_PONG = 4,
PKTTYPE_START = 5,
PKTTYPE_STOP = 6,
PKTTYPE_SENDGPS = 7,
PKTTYPE_OK = 8,
PKTTYPE_SETSYSLOG = 9,
PKTTYPE_REBOOT = 10,
PKTTYPE_GETINFO = 11,
PKTTYPE_GETINFO_REPLY = 12,
PKTTYPE_RESET = 13,
PKTTYPE_TRACE = 14
} PacketType;
typedef struct _PACKET {
PacketType type;
// My IP Address
IPaddr source;
// SYSLOG server (debug only)
IPaddr syslogServer;
// Configured Position
float latitude;
float longitude;
// MAC Address / device ID
byte mac[6];
// Current threshold value (in m/s^2)
float threshold;
// Unix time in milliseconds
uint32_t uptime;
// Unix time in milliseconds
uint32_t unixts;
// String with length of 4 (padded with space)
uint8_t softwareVersion[4 + 1];
// Free RAM (if available)
uint32_t freeRam;
// Network latency if available
float latency;
// NTP server
IPaddr ntpServer;
// HTTP base (deprecated)
std::string httpBaseAddress;
// Platform name (raspi, galileo, etc)
std::string platformName;
// Accelerometer model/version
std::string accelerometerName;
// Sensor probe speed (for debug only)
uint32_t statProbeSpeed;
} PACKET;
/**
* Packet definition:
*
* Offset Size Only when Description
* ==========================================
* 0 5 Magic-bytes "INGV\0"
* 5 1 Command (see enum below)
*
* 6 6 DISCOVERY_REPLY MAC address
* 12 4 DISCOVERY_REPLY Version string (not zero terminated)
* 16 8 DISCOVERY_REPLY Model ("galileo1", "galileo2", "simulator") not zero terminated
*
* 6 6 SENDGPS MAC address
* 12 4 SENDGPS Latitude (IEEE 754)
* 16 4 SENDGPS Longitude (IEEE 754)
*
* 6 4 SETSYSLOG Syslog server
*
* 6 6 GETINFO_REPLY MAC Address
* 12 4 GETINFO_REPLY Syslog server
* 16 12 GETINFO_REPLY Thresholds (X, Y, Z)
* 28 4 GETINFO_REPLY Uptime (seconds)
* 32 4 GETINFO_REPLY UNIX time
* 36 4 GETINFO_REPLY Software version
* 40 4 GETINFO_REPLY Free RAM
* 44 4 GETINFO_REPLY Latency
* 48 4 GETINFO_REPLY NTP Server
* 52 - GETINFO_REPLY HTTP base address (MAX: 170 chars including ZERO)
* - - GETINFO_REPLY Platform name (+ variant if any) (MAX: 20 chars including ZERO)
* - - GETINFO_REPLY Accelerometer name (MAX: 10 chars including ZERO)
* ? 4 GETINFO_REPLY Accelerometer probe speed
* String max size (sum): 200
*
*/
class CommandInterface {
public:
/**
* Check if a command packet is received, if so, execute that
*/
static void checkCommandPacket();
/**
* Send accelerometer values to Android
* @param db Accelerometer values
*/
// static void sendValues(float x, float y, float z);
/**
* Init command interface
*/
static bool commandInterfaceInit();
private:
/**
* Read packet and populate the structure
* Returns: true if the packet is valid, false otherwise
*/
static bool readPacket(PACKET *);
/**
* Send the packet to the network
*/
static void sendPacket(PACKET);
static Udp cmdc;
// static IPaddr udpDest;
};
#endif //GALILEO_TERREMOTI_COMMANDINTERFACE_H