Class: DjiMqttConnect::Thing::Product::OsdMarshal

Inherits:
MessageMarshal show all
Includes:
Utils::MessageParsing
Defined in:
lib/dji_mqtt_connect/marshals/thing/product/osd_marshal.rb

Defined Under Namespace

Classes: OsdTransformer

Instance Method Summary collapse

Methods inherited from MessageMarshal

#dump

Instance Method Details

#load(raw_message) ⇒ Object

Parse message from Device > Cloud Server



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/dji_mqtt_connect/marshals/thing/product/osd_marshal.rb', line 57

def load(raw_message)
  parsed_message = parse_json(raw_message)

  message_data = parsed_message.fetch("data", {})

  message_class = if FlightHubDroneOsdMessage.matches?(parsed_message)
    FlightHubDroneOsdMessage
  elsif FlightHubDockOsdMessage.matches?(parsed_message)
    FlightHubDockOsdMessage
  elsif drone_osd_data_attributes.all? { |attribute| message_data.key?(attribute.to_s) }
    DroneOsdMessage
  elsif required_remote_osd_data_attributes.all? { |attribute| message_data.key?(attribute.to_s) } &&
      optional_remote_osd_data_attributes.any? { |attribute| message_data.key?(attribute.to_s) }
    RemoteOsdMessage
  elsif dock_osd_data_attributes.any? { |attribute| message_data.key?(attribute.to_s) }
    DockOsdMessage
  else
    OsdMessage
  end

  transformed_message = osd_transformer.call(parsed_message)

  build_message(message_class, transformed_message)
end