1
1
package org .droidplanner .services .android .core .drone .variables ;
2
2
3
+ import com .MAVLink .Messages .MAVLinkMessage ;
3
4
import com .MAVLink .common .msg_heartbeat ;
4
5
5
6
import org .droidplanner .services .android .core .drone .DroneInterfaces .DroneEventsType ;
@@ -60,25 +61,35 @@ public short getMavlinkVersion() {
60
61
return mMavlinkVersion ;
61
62
}
62
63
63
- public void onHeartbeat (msg_heartbeat msg ) {
64
- sysid = (byte ) msg .sysid ;
65
- compid = (byte ) msg .compid ;
66
- mMavlinkVersion = msg .mavlink_version ;
64
+ public void onHeartbeat (MAVLinkMessage msg ) {
65
+ msg_heartbeat heartBeatMsg = msg instanceof msg_heartbeat ? (msg_heartbeat ) msg : null ;
66
+ if (heartBeatMsg != null ){
67
+ sysid = (byte ) msg .sysid ;
68
+ compid = (byte ) msg .compid ;
69
+ mMavlinkVersion = heartBeatMsg .mavlink_version ;
70
+ }
67
71
68
72
switch (heartbeatState ) {
69
73
case FIRST_HEARTBEAT :
70
- notifyConnected ();
71
- Timber .d ("Received first heartbeat." );
72
- myDrone .notifyDroneEvent (DroneEventsType .HEARTBEAT_FIRST );
74
+ if (heartBeatMsg != null ) {
75
+ Timber .i ("Received first heartbeat." );
76
+
77
+ heartbeatState = HeartbeatState .NORMAL_HEARTBEAT ;
78
+ restartWatchdog (HEARTBEAT_NORMAL_TIMEOUT );
79
+
80
+ myDrone .notifyDroneEvent (DroneEventsType .HEARTBEAT_FIRST );
81
+ }
73
82
break ;
74
83
75
84
case LOST_HEARTBEAT :
76
85
myDrone .notifyDroneEvent (DroneEventsType .HEARTBEAT_RESTORED );
86
+ // FALL THROUGH
87
+
88
+ default :
89
+ heartbeatState = HeartbeatState .NORMAL_HEARTBEAT ;
90
+ restartWatchdog (HEARTBEAT_NORMAL_TIMEOUT );
77
91
break ;
78
92
}
79
-
80
- heartbeatState = HeartbeatState .NORMAL_HEARTBEAT ;
81
- restartWatchdog (HEARTBEAT_NORMAL_TIMEOUT );
82
93
}
83
94
84
95
public boolean hasHeartbeat () {
@@ -108,10 +119,6 @@ public void onDroneEvent(DroneEventsType event, MavLinkDrone drone) {
108
119
}
109
120
}
110
121
111
- private void notifyConnected () {
112
- restartWatchdog (HEARTBEAT_NORMAL_TIMEOUT );
113
- }
114
-
115
122
private void notifyDisconnected () {
116
123
watchdog .removeCallbacks (watchdogCallback );
117
124
heartbeatState = HeartbeatState .FIRST_HEARTBEAT ;
@@ -126,7 +133,7 @@ private void onHeartbeatTimeout() {
126
133
break ;
127
134
128
135
case FIRST_HEARTBEAT :
129
- Timber .d ("First heartbeat timeout." );
136
+ Timber .i ("First heartbeat timeout." );
130
137
myDrone .notifyDroneEvent (DroneEventsType .CONNECTION_FAILED );
131
138
break ;
132
139
0 commit comments