Sha256: cc78351a98d96d8a8e2fe606a2438096c515796f3cb4f571feb41e8c092541f0

Contents?: true

Size: 1.19 KB

Versions: 35

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module DjiMqttConnect
  module Thing::Product
    class OsdTopicRepository < TopicRepository
      OSD_TOPIC_REGEX = /\Athing\/product\/(?<device_identifier>.+)\/osd\z/

      def listen!
        listen_to_topic("thing/product/+/osd") do |topic, raw_message|
          logger.debug(raw_message)

          matched_topic = OSD_TOPIC_REGEX.match(topic)
          raise Error, "Unknown topic: #{topic}" unless matched_topic

          device_identifier = matched_topic[:device_identifier]
          message = OsdMarshal.load(raw_message)

          logger.info("Received #{message} from #{device_identifier}")

          if message.instance_of?(OsdMessage)
            # Broadcast an unsupported message event
            broadcast(:unsupported_message, topic, raw_message)
          else
            # Build event name and broadcast (i.e. ::RemoteOsdMessage => remote_osd_update)
            event_name = message.class.name.demodulize.sub(/Message\z/, "Update").underscore.to_sym
            broadcast(event_name, device_identifier, message)
          end
        rescue ParseError => error
          broadcast(:parse_error, error, topic, raw_message)
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
dji_mqtt_connect-0.1.13.1 lib/dji_mqtt_connect/topics/thing/product/osd.rb
dji_mqtt_connect-0.1.13 lib/dji_mqtt_connect/topics/thing/product/osd.rb
dji_mqtt_connect-0.1.12.1 lib/dji_mqtt_connect/topics/thing/product/osd.rb
dji_mqtt_connect-0.1.12 lib/dji_mqtt_connect/topics/thing/product/osd.rb
dji_mqtt_connect-0.1.11 lib/dji_mqtt_connect/topics/thing/product/osd.rb
dji_mqtt_connect-0.1.10 lib/dji_mqtt_connect/topics/thing/product/osd.rb
dji_mqtt_connect-0.1.9 lib/dji_mqtt_connect/topics/thing/product/osd.rb
dji_mqtt_connect-0.1.8 lib/dji_mqtt_connect/topics/thing/product/osd.rb
dji_mqtt_connect-0.1.7 lib/dji_mqtt_connect/topics/thing/product/osd.rb
dji_mqtt_connect-0.1.6 lib/dji_mqtt_connect/topics/thing/product/osd.rb
dji_mqtt_connect-0.1.5 lib/dji_mqtt_connect/topics/thing/product/osd.rb
dji_mqtt_connect-0.1.4.1 lib/dji_mqtt_connect/topics/thing/product/osd.rb
dji_mqtt_connect-0.1.4 lib/dji_mqtt_connect/topics/thing/product/osd.rb
dji_mqtt_connect-0.1.3 lib/dji_mqtt_connect/topics/thing/product/osd.rb
dji_mqtt_connect-0.1.2 lib/dji_mqtt_connect/topics/thing/product/osd.rb