-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMavLinkDecoder.cpp
More file actions
58 lines (46 loc) · 1.31 KB
/
MavLinkDecoder.cpp
File metadata and controls
58 lines (46 loc) · 1.31 KB
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
//Library for Decoding Mavlink written with the help of:
//https://discuss.ardupilot.org/t/mavlink-and-arduino-step-by-step/25566
#include <ESP8266WiFi.h>
#include "MavLinkDecoder.h"
MavLinkDecoder::MavLinkDecoder() {
failSafeTimer=millis();
}
void MavLinkDecoder::comm_receive() {
mavlink_message_t msg;
mavlink_status_t status;
while(Serial.available()>0) {
uint8_t c = Serial.read();
// Try to get a new message
if(mavlink_parse_char(MAVLINK_COMM_0, c, &msg, &status)) {
// Handle message
switch(msg.msgid) {
case MAVLINK_MSG_ID_HEARTBEAT: // #0: Heartbeat
{
// E.g. read GCS heartbeat and go into
// comm lost mode if timer times out
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
break;
case MAVLINK_MSG_ID_RC_CHANNELS_RAW: // #35: RAW_CHANNELS
{
/* getting channel8 position */
channel8=mavlink_msg_rc_channels_raw_get_chan8_raw(&msg);
}
break;
case MAVLINK_MSG_ID_SYS_STATUS: // #1: SYS_STATUS
{
/* getting failsafe status*/
failsafe=( (mavlink_msg_sys_status_get_onboard_control_sensors_health(&msg)& 0x10000)==0);
failSafeTimer=millis();
}
break;
default:
break;
}
}
}
}
bool MavLinkDecoder::failSafe(void) {
if (millis()-failSafeTimer < MAX_FRAME_PERIOD) return(failsafe);
else return(true);
}