dji_mqtt_connect 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/dji_mqtt_connect/client.rb +5 -0
- data/lib/dji_mqtt_connect/marshals/sys/product/status_marshal.rb +1 -1
- data/lib/dji_mqtt_connect/marshals/thing/product/events_marshal.rb +48 -0
- data/lib/dji_mqtt_connect/marshals/thing/product/requests_marshal.rb +1 -1
- data/lib/dji_mqtt_connect/messages/thing/product/events_message.rb +19 -0
- data/lib/dji_mqtt_connect/messages/thing/product/hms_events_message.rb +33 -0
- data/lib/dji_mqtt_connect/messages/thing/product/storage_config_get_requests_reply_message.rb +1 -1
- data/lib/dji_mqtt_connect/topics/thing/product/events.rb +32 -0
- data/lib/dji_mqtt_connect/utils/message_parsing.rb +5 -2
- data/lib/dji_mqtt_connect/version.rb +1 -1
- data/lib/dji_mqtt_connect.rb +6 -0
- metadata +6 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 3a9ba8caf2ea370ed33848df512fbebcc63dfd4b63dd07947a1a653f56fdb1a8
         | 
| 4 | 
            +
              data.tar.gz: 16ec8180f911733314fc2be3dbfefc5433c758663b3a52fd9a9fe7e6c00ca370
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: dfacde33b13c8aa12e096013273c8ca597a3ae7cf1a54fde85eaf353a6ff3c0b94bc062f0ad351e6d47bdad0f599c2c12b41f1dde9ddf91bd8ae3b666360e725
         | 
| 7 | 
            +
              data.tar.gz: ac51091158d1459ca3e6d4666ec86abbae044a04b130e8f4bfc374b7b5dcf315c418b61a25e3a7b78019bc7d3aa024c025656b2de15aa1951e4e1300b82d5c88
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
| @@ -41,6 +41,11 @@ module DjiMqttConnect | |
| 41 41 | 
             
                  Sys::Product::StatusReplyTopicRepository.new(self)
         | 
| 42 42 | 
             
                end
         | 
| 43 43 |  | 
| 44 | 
            +
                # Handles topic thing/product/#{pid}/events
         | 
| 45 | 
            +
                def thing_product_events_topic
         | 
| 46 | 
            +
                  Thing::Product::EventsTopicRepository.new(self)
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
             | 
| 44 49 | 
             
                # Handles topic thing/product/#{pid}/osd
         | 
| 45 50 | 
             
                def thing_product_osd_topic
         | 
| 46 51 | 
             
                  Thing::Product::OsdTopicRepository.new(self)
         | 
| @@ -29,7 +29,7 @@ module DjiMqttConnect | |
| 29 29 | 
             
                    transformed_message = attribute_transformer.call(parsed_message)
         | 
| 30 30 |  | 
| 31 31 | 
             
                    # Build an instance of the class, or a generic message from the current class
         | 
| 32 | 
            -
                    message_class =  | 
| 32 | 
            +
                    message_class = message_class_from_method_value(parsed_message, StatusMessage)
         | 
| 33 33 | 
             
                    message_class.new transformed_message
         | 
| 34 34 | 
             
                  rescue JSON::ParserError => e
         | 
| 35 35 | 
             
                    raise ParseError.new(e, "Unable to parse message as JSON")
         | 
| @@ -0,0 +1,48 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require "dry-struct"
         | 
| 4 | 
            +
            require "dry-transformer"
         | 
| 5 | 
            +
            require "json"
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            module DjiMqttConnect
         | 
| 8 | 
            +
              module Thing::Product
         | 
| 9 | 
            +
                class EventsMarshal < MessageMarshal
         | 
| 10 | 
            +
                  include Utils::MessageParsing
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  # Rename pesky `method` argument to `_method` and makes a copy of the raw data
         | 
| 13 | 
            +
                  class AttributeTransformer < Dry::Transformer::Pipe
         | 
| 14 | 
            +
                    import Dry::Transformer::HashTransformations
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    define! do
         | 
| 17 | 
            +
                      symbolize_keys
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                      copy_keys data: :_data
         | 
| 20 | 
            +
                      rename_keys method: :_method
         | 
| 21 | 
            +
                    end
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  # Attempts to look a the method attribute, and builds a specific Message class for the message
         | 
| 25 | 
            +
                  def load(raw_message)
         | 
| 26 | 
            +
                    # Parse the message from JSON
         | 
| 27 | 
            +
                    parsed_message = JSON.parse(raw_message)
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                    # Transform the message
         | 
| 30 | 
            +
                    transformed_message = attribute_transformer.call(parsed_message)
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                    # Build an instance of the class, or a generic message from the current class
         | 
| 33 | 
            +
                    message_class = message_class_from_method_value(parsed_message, EventsMessage)
         | 
| 34 | 
            +
                    message_class.new transformed_message
         | 
| 35 | 
            +
                  rescue JSON::ParserError => e
         | 
| 36 | 
            +
                    raise ParseError.new(e, "Unable to parse message as JSON")
         | 
| 37 | 
            +
                  rescue Dry::Struct::Error => e
         | 
| 38 | 
            +
                    raise ParseError.new(e, "Unexpected #{message_class} payload")
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  private
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                  def attribute_transformer
         | 
| 44 | 
            +
                    @attribute_transformer ||= AttributeTransformer.new
         | 
| 45 | 
            +
                  end
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
            end
         | 
| @@ -30,7 +30,7 @@ module DjiMqttConnect | |
| 30 30 | 
             
                    transformed_message = attribute_transformer.call(parsed_message)
         | 
| 31 31 |  | 
| 32 32 | 
             
                    # Build an instance of the class, or a generic message from the current class
         | 
| 33 | 
            -
                    message_class =  | 
| 33 | 
            +
                    message_class = message_class_from_method_value(parsed_message, RequestsMessage)
         | 
| 34 34 | 
             
                    message_class.new transformed_message
         | 
| 35 35 | 
             
                  rescue JSON::ParserError => e
         | 
| 36 36 | 
             
                    raise ParseError.new(e, "Unable to parse message as JSON")
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module DjiMqttConnect
         | 
| 4 | 
            +
              module Thing::Product
         | 
| 5 | 
            +
                class EventsMessage < Message
         | 
| 6 | 
            +
                  attribute :bid, Types::UUID
         | 
| 7 | 
            +
                  attribute :tid, Types::UUID
         | 
| 8 | 
            +
                  attribute :timestamp, Types::Timestamp
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  attribute :_data, Types::Hash
         | 
| 11 | 
            +
                  attribute :_method, Types::String
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  def to_s
         | 
| 14 | 
            +
                    # Include data method for Generic messages
         | 
| 15 | 
            +
                    instance_of?(EventsMessage) ? "#{super}[#{_method}]" : super
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,33 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module DjiMqttConnect
         | 
| 4 | 
            +
              module Thing::Product
         | 
| 5 | 
            +
                class HmsEventsMessage < EventsMessage
         | 
| 6 | 
            +
                  attribute :_method, Types::String.enum("hms")
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  attribute :data do
         | 
| 9 | 
            +
                    attribute :list, Types::Array do
         | 
| 10 | 
            +
                      # {"0":"Inform","1":"Notice","2":"Alarm"}
         | 
| 11 | 
            +
                      attribute :level, Types::Integer.enum(0, 1, 2)
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                      # {"0":"flight mission","1":"device management","2":"media","3":"hms"}
         | 
| 14 | 
            +
                      attribute :module, Types::Integer.enum(0, 1, 2, 3)
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                      # {"0":"on the ground","1":"in the sky"}
         | 
| 17 | 
            +
                      attribute :in_the_sky, Types::Integer.enum(0, 1)
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                      attribute :code, Types::String
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                      # {"0":"No","1":"Yes"}
         | 
| 22 | 
            +
                      attribute :imminent, Types::Integer.enum(0, 1)
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                      attribute :args do
         | 
| 25 | 
            +
                        attribute :component_index, Types::Integer
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                        attribute :sensor_index, Types::Integer
         | 
| 28 | 
            +
                      end
         | 
| 29 | 
            +
                    end
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
            end
         | 
    
        data/lib/dji_mqtt_connect/messages/thing/product/storage_config_get_requests_reply_message.rb
    CHANGED
    
    | @@ -30,7 +30,7 @@ module DjiMqttConnect | |
| 30 30 | 
             
                      attribute :credentials do
         | 
| 31 31 | 
             
                        attribute :access_key_id, Types::String
         | 
| 32 32 | 
             
                        attribute :access_key_secret, Types::String
         | 
| 33 | 
            -
                        attribute :expire, Types::Integer
         | 
| 33 | 
            +
                        attribute :expire, Types::Integer.constrained(gt: 0)
         | 
| 34 34 | 
             
                        attribute :security_token, Types::String
         | 
| 35 35 | 
             
                      end
         | 
| 36 36 | 
             
                      attribute :endpoint, Types::String
         | 
| @@ -0,0 +1,32 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module DjiMqttConnect
         | 
| 4 | 
            +
              module Thing::Product
         | 
| 5 | 
            +
                class EventsTopicRepository < TopicRepository
         | 
| 6 | 
            +
                  EVENTS_TOPIC_REGEX = /\Athing\/product\/(?<device_sn>.+)\/events\z/
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def listen!
         | 
| 9 | 
            +
                    listen_to_topic("thing/product/+/events") do |topic, raw_message|
         | 
| 10 | 
            +
                      logger.debug(raw_message)
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                      matched_topic = EVENTS_TOPIC_REGEX.match(topic)
         | 
| 13 | 
            +
                      raise Error, "Unknown topic: #{topic}" unless matched_topic
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                      device_sn = matched_topic[:device_sn]
         | 
| 16 | 
            +
                      message = EventsMarshal.load(raw_message)
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                      logger.info("Received #{message} from #{device_sn}")
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                      if message.instance_of?(EventsMessage)
         | 
| 21 | 
            +
                        # Broadcast an unsupported message event
         | 
| 22 | 
            +
                        broadcast(:unsupported_message, topic, raw_message)
         | 
| 23 | 
            +
                      else
         | 
| 24 | 
            +
                        # Build event name and broadcast (i.e. ::HmsEventsMessage => hms_event)
         | 
| 25 | 
            +
                        event_name = message.class.name.demodulize.sub(/sMessage\z/, "").underscore.to_sym
         | 
| 26 | 
            +
                        broadcast(event_name, device_sn, message)
         | 
| 27 | 
            +
                      end
         | 
| 28 | 
            +
                    end
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
            end
         | 
| @@ -5,9 +5,12 @@ module DjiMqttConnect | |
| 5 5 | 
             
                module MessageParsing
         | 
| 6 6 | 
             
                  private
         | 
| 7 7 |  | 
| 8 | 
            -
                  def  | 
| 8 | 
            +
                  def message_class_from_method_value(parsed_message, generic_class)
         | 
| 9 | 
            +
                    message_method = parsed_message["method"]
         | 
| 10 | 
            +
                    return generic_class if message_method.blank?
         | 
| 11 | 
            +
             | 
| 9 12 | 
             
                    # update_topo => UpdateTopo
         | 
| 10 | 
            -
                    classified_method =  | 
| 13 | 
            +
                    classified_method = message_method.split("_").collect! { |w| w.capitalize }.join
         | 
| 11 14 |  | 
| 12 15 | 
             
                    # UpdateTopo => DjiMqttConnect::Sys::Product::UpdateTopoStatusMessage
         | 
| 13 16 | 
             
                    module_prefix, joiner, class_suffix = generic_class.name.rpartition("::")
         | 
    
        data/lib/dji_mqtt_connect.rb
    CHANGED
    
    | @@ -33,6 +33,9 @@ module DjiMqttConnect | |
| 33 33 | 
             
              module Thing
         | 
| 34 34 | 
             
                module Product
         | 
| 35 35 | 
             
                  # Messages
         | 
| 36 | 
            +
                  autoload :HmsEventsMessage, "dji_mqtt_connect/messages/thing/product/hms_events_message"
         | 
| 37 | 
            +
                  autoload :EventsMessage, "dji_mqtt_connect/messages/thing/product/events_message"
         | 
| 38 | 
            +
             | 
| 36 39 | 
             
                  autoload :OsdMessage, "dji_mqtt_connect/messages/thing/product/osd_message"
         | 
| 37 40 | 
             
                  autoload :DockOsdMessage, "dji_mqtt_connect/messages/thing/product/dock_osd_message"
         | 
| 38 41 | 
             
                  autoload :DroneOsdMessage, "dji_mqtt_connect/messages/thing/product/drone_osd_message"
         | 
| @@ -50,11 +53,14 @@ module DjiMqttConnect | |
| 50 53 | 
             
                  autoload :StorageConfigGetRequestsReplyMessage, "dji_mqtt_connect/messages/thing/product/storage_config_get_requests_reply_message"
         | 
| 51 54 |  | 
| 52 55 | 
             
                  # Topics
         | 
| 56 | 
            +
                  autoload :EventsTopicRepository, "dji_mqtt_connect/topics/thing/product/events"
         | 
| 53 57 | 
             
                  autoload :OsdTopicRepository, "dji_mqtt_connect/topics/thing/product/osd"
         | 
| 54 58 | 
             
                  autoload :RequestsTopicRepository, "dji_mqtt_connect/topics/thing/product/requests"
         | 
| 55 59 | 
             
                  autoload :RequestsReplyTopicRepository, "dji_mqtt_connect/topics/thing/product/requests_reply"
         | 
| 56 60 |  | 
| 57 61 | 
             
                  # Marshals
         | 
| 62 | 
            +
                  autoload :EventsMarshal, "dji_mqtt_connect/marshals/thing/product/events_marshal"
         | 
| 63 | 
            +
             | 
| 58 64 | 
             
                  autoload :OsdMarshal, "dji_mqtt_connect/marshals/thing/product/osd_marshal"
         | 
| 59 65 |  | 
| 60 66 | 
             
                  autoload :RequestsMarshal, "dji_mqtt_connect/marshals/thing/product/requests_marshal"
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: dji_mqtt_connect
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Sphere Drones
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2023-05- | 
| 11 | 
            +
            date: 2023-05-16 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activesupport
         | 
| @@ -110,6 +110,7 @@ files: | |
| 110 110 | 
             
            - lib/dji_mqtt_connect/factories.rb
         | 
| 111 111 | 
             
            - lib/dji_mqtt_connect/marshals/sys/product/status_marshal.rb
         | 
| 112 112 | 
             
            - lib/dji_mqtt_connect/marshals/sys/product/status_reply_marshal.rb
         | 
| 113 | 
            +
            - lib/dji_mqtt_connect/marshals/thing/product/events_marshal.rb
         | 
| 113 114 | 
             
            - lib/dji_mqtt_connect/marshals/thing/product/osd_marshal.rb
         | 
| 114 115 | 
             
            - lib/dji_mqtt_connect/marshals/thing/product/requests_marshal.rb
         | 
| 115 116 | 
             
            - lib/dji_mqtt_connect/marshals/thing/product/requests_reply_marshal.rb
         | 
| @@ -126,6 +127,8 @@ files: | |
| 126 127 | 
             
            - lib/dji_mqtt_connect/messages/thing/product/config_requests_reply_message.rb
         | 
| 127 128 | 
             
            - lib/dji_mqtt_connect/messages/thing/product/dock_osd_message.rb
         | 
| 128 129 | 
             
            - lib/dji_mqtt_connect/messages/thing/product/drone_osd_message.rb
         | 
| 130 | 
            +
            - lib/dji_mqtt_connect/messages/thing/product/events_message.rb
         | 
| 131 | 
            +
            - lib/dji_mqtt_connect/messages/thing/product/hms_events_message.rb
         | 
| 129 132 | 
             
            - lib/dji_mqtt_connect/messages/thing/product/osd_message.rb
         | 
| 130 133 | 
             
            - lib/dji_mqtt_connect/messages/thing/product/remote_osd_message.rb
         | 
| 131 134 | 
             
            - lib/dji_mqtt_connect/messages/thing/product/requests_message.rb
         | 
| @@ -139,6 +142,7 @@ files: | |
| 139 142 | 
             
            - lib/dji_mqtt_connect/topic_repository.rb
         | 
| 140 143 | 
             
            - lib/dji_mqtt_connect/topics/sys/product/status.rb
         | 
| 141 144 | 
             
            - lib/dji_mqtt_connect/topics/sys/product/status_reply.rb
         | 
| 145 | 
            +
            - lib/dji_mqtt_connect/topics/thing/product/events.rb
         | 
| 142 146 | 
             
            - lib/dji_mqtt_connect/topics/thing/product/osd.rb
         | 
| 143 147 | 
             
            - lib/dji_mqtt_connect/topics/thing/product/requests.rb
         | 
| 144 148 | 
             
            - lib/dji_mqtt_connect/topics/thing/product/requests_reply.rb
         |