aboutsummaryrefslogtreecommitdiff
path: root/mavigator-cockpit/src/main/scala/mavigator/index/ActiveVehicle.scala
blob: 7e59ed8385d95f563cdeed2a5ab68d7b1d71419c (plain) (blame)
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
package mavigator.index

import org.mavlink.enums.MavAutopilot
import org.mavlink.enums.MavState
import org.mavlink.enums.MavType
import org.mavlink.messages.Heartbeat

case class ActiveVehicle(systemId: Int, vehicleType: String, autopilot: String, state: String)

object ActiveVehicle {

  def fromHeartbeat(id: Int, hb: Heartbeat) = ActiveVehicle(
    id,
    vehicleType(hb.`type`),
    autopilot(hb.autopilot),
    state(hb.systemStatus)
  )

  def vehicleType(tpe: Int) = tpe match {
    case MavType.MavTypeGeneric => "Generic"
    case MavType.MavTypeQuadrotor => "Quadcopter"
    case MavType.MavTypeFixedWing => "Fixed Wing"
    case _ => "Other"
  }

  def autopilot(tpe: Int) = tpe match {
    case MavAutopilot.MavAutopilotGeneric => "Generic"
    case MavAutopilot.MavAutopilotInvalid => "Invalid"
    case MavAutopilot.MavAutopilotPixhawk => "Pixhawk"
    case _ => "Other"
  }

  def state(s: Int) = s match {
    case MavState.MavStateActive => "Active"
    case MavState.MavStateBoot => "Booting"
    case MavState.MavStateCalibrating => "Calibrating"
    case MavState.MavStateCritical => "Critical"
    case MavState.MavStateEmergency => "Emergency"
    case MavState.MavStatePoweroff => "Poweroff"
    case MavState.MavStateStandby => "Standby"
    case MavState.MavStateUninit => "Uninitialized"
    case _ => "Unknown"
  }

}