dji_mqtt_connect 0.1.9 → 0.1.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0fdf863220666d558b5c4172d11802585133231df7de49352e8d516094a69e38
4
- data.tar.gz: ca3937a310a7c19f671bc5afd8d5c5d2b82e40e6bdc02c1c42e56cbfe2898717
3
+ metadata.gz: 2685591a0d96c757f12c00f683a9dc45ee25b81091414dc81d72f93ccfe2f324
4
+ data.tar.gz: 53e45915630050082bd9dd1ddeb228d1eb9ce318d47eab213e0df0fb42c4d18a
5
5
  SHA512:
6
- metadata.gz: 3edf674897efce7593a2086c61c3dab3d9757b4b05b0d13686dccaf8c8e21a382302e96f2a5832f3c2fcdd89427748de4e4bdb646c643dceec9da45a6370e50b
7
- data.tar.gz: 99f44ec7e179f04e6966dfc112dadde605d491e991d3f59caa460196cdc1d805bf4bcae6c301d7ae31c919a09d8031886b5762c477346baf7d104d067ca770c6
6
+ metadata.gz: fc83f3608e9162591d40e6bc0115f804b55d779149ef6612a3ae84b4864e98052e5d40b8faedc8b2f541fa056e589b9c1c7eba79dd3a812f35012c72b906947b
7
+ data.tar.gz: da787b447741b0236e9c31bb28ea04ef33a900e47f5386e18dff9ebd43d243449a7d3119a9348f9f0515c314887288b4b3021b88ab4d522d6c8a266952a51ace
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dji_mqtt_connect (0.1.9)
4
+ dji_mqtt_connect (0.1.11)
5
5
  activesupport (>= 6.0, <= 8)
6
6
  dry-struct (~> 1.6)
7
7
  dry-transformer (~> 1.0)
@@ -46,6 +46,11 @@ module DjiMqttConnect
46
46
  Thing::Product::EventsTopicRepository.new(self)
47
47
  end
48
48
 
49
+ # Handles topic thing/product/#{pid}/events_reply
50
+ def thing_product_events_reply_topic
51
+ Thing::Product::EventsReplyTopicRepository.new(self)
52
+ end
53
+
49
54
  # Handles topic thing/product/#{pid}/osd
50
55
  def thing_product_osd_topic
51
56
  Thing::Product::OsdTopicRepository.new(self)
@@ -4,6 +4,119 @@ module DjiMqttConnect
4
4
  # Factories for building example messages
5
5
  # Do not include this in your production code
6
6
  module Factories
7
+ # Events
8
+
9
+ def build_file_upload_callback_events_message
10
+ message_data = {
11
+ file: {
12
+ object_key: "object_key",
13
+ path: "xxx",
14
+ name: "dog.jpeg",
15
+ ext: {
16
+ flight_id: "xxx",
17
+ drone_model_key: "0-67-0",
18
+ payload_model_key: "0-67-0",
19
+ is_original: true
20
+ },
21
+ metadata: {
22
+ shoot_position: {
23
+ lat: 22.1,
24
+ lng: 122.5
25
+ },
26
+ gimbal_yaw_degree: -91.4,
27
+ absolute_altitude: 56.311,
28
+ relative_altitude: 41.124,
29
+ created_time: "2021-05-10 16:04:20"
30
+ }
31
+ },
32
+ result: 0
33
+ }
34
+
35
+ Thing::Product::FileUploadCallbackEventsMessage.new(
36
+ _method: "file_upload_callback",
37
+ bid: "12345678-1234-1234-1234-12345678901B",
38
+ tid: "12345678-1234-1234-1234-12345678901A",
39
+ need_reply: 1,
40
+ gateway: "xxx",
41
+ timestamp: 1654070968655,
42
+ data: message_data,
43
+ _data: message_data
44
+ )
45
+ end
46
+
47
+ def build_fileupload_progress_events_message
48
+ message_data = {
49
+ output: {
50
+ ext: {
51
+ files: [
52
+ {
53
+ module: "0",
54
+ size: 155232,
55
+ device_sn: "drone_sn",
56
+ key: "4bf0039f-6434-44a8-b891-8d7b6b7ff138/drone_sn/video_20220621_110830.log",
57
+ fingerprint: "4f65b891f3bc09bdb6d4c36a996b532d",
58
+ progress: {
59
+ current_step: 19,
60
+ prgress: 100,
61
+ finish_time: 1655781395926,
62
+ upload_rate: 0,
63
+ result: 0,
64
+ status: "ok"
65
+ }
66
+ },
67
+ {
68
+ module: "3",
69
+ size: 155232,
70
+ device_sn: "dock_sn",
71
+ key: "4bf0039f-6434-44a8-b891-8d7b6b7ff138/dock_sn/video_20220621_110830.log",
72
+ fingerprint: "4f65b891f3bc09bdb6d4c36a996b532d",
73
+ progress: {
74
+ current_step: 19,
75
+ total_step: 30,
76
+ prgress: 100,
77
+ finish_time: 1655781395926,
78
+ upload_rate: 0,
79
+ result: 0,
80
+ status: "ok"
81
+ }
82
+ }
83
+ ]
84
+ },
85
+ status: "ok"
86
+ }
87
+ }
88
+
89
+ Thing::Product::FileuploadProgressEventsMessage.new(
90
+ _method: "fileupload_progress",
91
+ need_reply: 0,
92
+ bid: "12345678-1234-1234-1234-12345678901B",
93
+ tid: "12345678-1234-1234-1234-12345678901A",
94
+ timestamp: 1655781395926,
95
+ gateway: "dock_sn",
96
+ _data: message_data,
97
+ data: message_data
98
+ )
99
+ end
100
+
101
+ def build_highest_priority_upload_flighttask_media_events_message
102
+ message_data = {
103
+ flight_id: SecureRandom.uuid
104
+ }
105
+
106
+ Thing::Product::HighestPriorityUploadFlighttaskMediaEventsMessage.new(
107
+ bid: "fe0e2218-038f-46fe-b27d-74cd257c386a",
108
+ _data: message_data,
109
+ data: message_data,
110
+ _method: "highest_priority_upload_flighttask_media",
111
+ need_reply: 1,
112
+ tid: "c6aa22c0-e9dd-4895-a25c-6c12411513df",
113
+ timestamp: 1684986146586,
114
+ gateway: "DOCK01"
115
+ )
116
+ end
117
+
118
+ # Status
119
+
7
120
  def build_device_online_update_topo_message
8
121
  message_data = {
9
122
  type: 98,
@@ -46,6 +159,8 @@ module DjiMqttConnect
46
159
  )
47
160
  end
48
161
 
162
+ # Requests
163
+
49
164
  def build_thing_product_config_requests_message
50
165
  message_data = {
51
166
  config_type: "json",
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry-transformer"
4
+ require "json"
5
+
6
+ module DjiMqttConnect
7
+ module Thing::Product
8
+ class EventsReplyMarshal < MessageMarshal
9
+ # Renames the method attribute
10
+ class HashTransformer < Dry::Transformer::Pipe
11
+ import Dry::Transformer::HashTransformations
12
+
13
+ define! do
14
+ rename_keys _method: :method
15
+ end
16
+ end
17
+
18
+ # Converts a message for transmission via MQTT
19
+ def dump(message)
20
+ # Fix up the hash representation
21
+ transformed_message = hash_transformer.call(message)
22
+
23
+ # Convert the transformed message into JSON
24
+ JSON.generate(transformed_message)
25
+ end
26
+
27
+ private
28
+
29
+ def hash_transformer
30
+ @hash_transformer ||= HashTransformer.new
31
+ end
32
+ end
33
+ end
34
+ end
@@ -15,12 +15,15 @@ module DjiMqttConnect
15
15
 
16
16
  attribute :sub_devices, Types::Array do
17
17
  attribute :sn, Types::String
18
+ attribute? :domain, Types::DeviceDomain
18
19
  attribute :type, Types::DeviceType
19
20
  attribute :sub_type, Types::DeviceSubType
20
21
  attribute :index, Types::String
21
22
  attribute :device_secret, Types::String
22
23
  attribute :nonce, Types::String
23
24
  attribute? :version, Types::Integer
25
+
26
+ alias_method :serial_number, :sn
24
27
  end
25
28
  end
26
29
  end
@@ -11,6 +11,9 @@ module DjiMqttConnect
11
11
  job_number
12
12
  ]
13
13
 
14
+ # {"0":"Idle mode (No cooling, heating, and dehumidification)","1":"Cooling mode","2":"Heating mode","3":"Dehumidification mode","4":"Cooling exit mode","5":"Heating exit mode","6":"Dehumidification exit mode","7":"Cooling preparation mode","8":"Heating preparation mode","9":"Dehumidification preparation mode"}
15
+ AirConditionerState = Types::Integer.enum(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
16
+
14
17
  attribute :data do
15
18
  include Mixins::LatitudeConditional
16
19
  include Mixins::LongitudeConditional
@@ -152,9 +155,12 @@ module DjiMqttConnect
152
155
  attribute? :mode_code, Types::Integer.enum(0, 1, 2, 3, 4)
153
156
 
154
157
  attribute? :air_conditioner do
155
- # {"0":"Idle mode (No cooling, heating, and dehumidification)","1":"Cooling mode","2":"Heating mode","3":"Dehumidification mode","4":"Cooling exit mode","5":"Heating exit mode","6":"Dehumidification exit mode","7":"Cooling preparation mode","8":"Heating preparation mode","9":"Dehumidification preparation mode"}
156
- attribute :air_conditioner_state, Types::Integer.enum(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
158
+ attribute :air_conditioner_state, AirConditionerState | Types::Integer
157
159
  attribute :switch_time, Types::Integer
160
+
161
+ def air_conditioner_state?
162
+ AirConditionerState.valid?(air_conditioner_state)
163
+ end
158
164
  end
159
165
 
160
166
  # {"0":"Closed","1":"Opened"}
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DjiMqttConnect
4
+ module Thing::Product
5
+ # https://developer.dji.com/doc/cloud-api-tutorial/en/server-api-reference/mqtt/topic-definition.html#events-reply-struct-example
6
+ class EventsReplyMessage < Message
7
+ # a result of 0 means we approve of this action
8
+ def self.build_for(events_message, result: 0)
9
+ new(
10
+ _method: events_message._method,
11
+ tid: events_message.tid,
12
+ bid: events_message.bid,
13
+ timestamp: Time.now.strftime("%s%L").to_i,
14
+ data: {
15
+ result: result
16
+ }
17
+ )
18
+ end
19
+
20
+ attribute :bid, Types::UUID
21
+ attribute :tid, Types::UUID
22
+ attribute :timestamp, Types::Timestamp
23
+
24
+ attribute :_method, Types::String.enum(
25
+ "file_upload_callback",
26
+ "fileupload_progress",
27
+ "highest_priority_upload_flighttask_media"
28
+ )
29
+
30
+ attribute :data do
31
+ attribute :result, Types::Integer
32
+ end
33
+ end
34
+ end
35
+ end
@@ -51,6 +51,10 @@ module DjiMqttConnect
51
51
 
52
52
  attribute :result, Types::Integer
53
53
  end
54
+
55
+ def need_reply?
56
+ need_reply == 1
57
+ end
54
58
  end
55
59
  end
56
60
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DjiMqttConnect
4
+ module Thing::Product
5
+ # https://developer.dji.com/doc/cloud-api-tutorial/en/server-api-reference/mqtt/thing-model/gateway/dock/log.html#inform-of-file-uploading-progress
6
+ class FileuploadProgressEventsMessage < EventsMessage
7
+ attribute :_method, Types::String.enum("fileupload_progress")
8
+
9
+ # NOTE: Not documented, but appears in examples
10
+ attribute? :need_reply, Types::Integer.enum(0, 1)
11
+
12
+ attribute :data do
13
+ attribute :output do
14
+ attribute :ext do
15
+ attribute :files, Types::Array do
16
+ # {"0":"Aircraft","3":"DJI Dock"}
17
+ attribute :module, Types::Coercible::Integer.enum(0, 3)
18
+
19
+ attribute :size, Types::Integer
20
+ attribute :device_sn, Types::String
21
+ attribute :key, Types::String
22
+ attribute :fingerprint, Types::String
23
+
24
+ attribute :progress do
25
+ attribute :current_step, Types::Integer
26
+ attribute? :total_step, Types::Integer
27
+ attribute :prgress, Types::Integer
28
+ attribute :finish_time, Types::Timestamp
29
+ attribute :upload_rate, Types::Integer
30
+ attribute :result, Types::Integer
31
+ attribute :status, Types::String
32
+ end
33
+ end
34
+ end
35
+ attribute :status, Types::String
36
+ end
37
+ end
38
+
39
+ def need_reply?
40
+ need_reply == 1
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DjiMqttConnect
4
+ module Thing::Product
5
+ class HighestPriorityUploadFlighttaskMediaEventsMessage < EventsMessage
6
+ attribute :_method, Types::String.enum("highest_priority_upload_flighttask_media")
7
+
8
+ # NOTE: Not documented, but appears in examples
9
+ attribute? :need_reply, Types::Integer.enum(0, 1)
10
+
11
+ attribute :data do
12
+ attribute :flight_id, Types::String
13
+ end
14
+
15
+ def need_reply?
16
+ need_reply == 1
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DjiMqttConnect
4
+ module Thing::Product
5
+ class EventsReplyTopicRepository < TopicRepository
6
+ # Publishes a message to gateway_sn on the "thing/product/+/events_reply" topic.
7
+ def publish_to_device(gateway_sn, events_reply_message)
8
+ publish_to_topic(
9
+ "thing/product/#{gateway_sn}/events_reply",
10
+ events_reply_message,
11
+ marshal: EventsReplyMarshal
12
+ )
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DjiMqttConnect
4
- VERSION = "0.1.9"
4
+ VERSION = "0.1.11"
5
5
  end
@@ -35,10 +35,14 @@ module DjiMqttConnect
35
35
  module Product
36
36
  # Messages
37
37
  autoload :FileUploadCallbackEventsMessage, "dji_mqtt_connect/messages/thing/product/file_upload_callback_events_message"
38
+ autoload :FileuploadProgressEventsMessage, "dji_mqtt_connect/messages/thing/product/fileupload_progress_events_message"
39
+ autoload :HighestPriorityUploadFlighttaskMediaEventsMessage, "dji_mqtt_connect/messages/thing/product/highest_priority_upload_flighttask_media_events_message"
38
40
  autoload :HmsEventsMessage, "dji_mqtt_connect/messages/thing/product/hms_events_message"
39
41
  autoload :StatusCodeEventsMessage, "dji_mqtt_connect/messages/thing/product/status_code_events_message"
40
42
  autoload :EventsMessage, "dji_mqtt_connect/messages/thing/product/events_message"
41
43
 
44
+ autoload :EventsReplyMessage, "dji_mqtt_connect/messages/thing/product/events_reply_message"
45
+
42
46
  autoload :OsdMessage, "dji_mqtt_connect/messages/thing/product/osd_message"
43
47
  autoload :DockOsdMessage, "dji_mqtt_connect/messages/thing/product/dock_osd_message"
44
48
  autoload :DroneOsdMessage, "dji_mqtt_connect/messages/thing/product/drone_osd_message"
@@ -59,12 +63,14 @@ module DjiMqttConnect
59
63
 
60
64
  # Topics
61
65
  autoload :EventsTopicRepository, "dji_mqtt_connect/topics/thing/product/events"
66
+ autoload :EventsReplyTopicRepository, "dji_mqtt_connect/topics/thing/product/events_reply"
62
67
  autoload :OsdTopicRepository, "dji_mqtt_connect/topics/thing/product/osd"
63
68
  autoload :RequestsTopicRepository, "dji_mqtt_connect/topics/thing/product/requests"
64
69
  autoload :RequestsReplyTopicRepository, "dji_mqtt_connect/topics/thing/product/requests_reply"
65
70
 
66
71
  # Marshals
67
72
  autoload :EventsMarshal, "dji_mqtt_connect/marshals/thing/product/events_marshal"
73
+ autoload :EventsReplyMarshal, "dji_mqtt_connect/marshals/thing/product/events_reply_marshal"
68
74
 
69
75
  autoload :OsdMarshal, "dji_mqtt_connect/marshals/thing/product/osd_marshal"
70
76
 
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.9
4
+ version: 0.1.11
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-24 00:00:00.000000000 Z
11
+ date: 2023-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -113,6 +113,7 @@ files:
113
113
  - lib/dji_mqtt_connect/marshals/sys/product/status_marshal.rb
114
114
  - lib/dji_mqtt_connect/marshals/sys/product/status_reply_marshal.rb
115
115
  - lib/dji_mqtt_connect/marshals/thing/product/events_marshal.rb
116
+ - lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
116
117
  - lib/dji_mqtt_connect/marshals/thing/product/osd_marshal.rb
117
118
  - lib/dji_mqtt_connect/marshals/thing/product/requests_marshal.rb
118
119
  - lib/dji_mqtt_connect/marshals/thing/product/requests_reply_marshal.rb
@@ -132,7 +133,10 @@ files:
132
133
  - lib/dji_mqtt_connect/messages/thing/product/dock_osd_message.rb
133
134
  - lib/dji_mqtt_connect/messages/thing/product/drone_osd_message.rb
134
135
  - lib/dji_mqtt_connect/messages/thing/product/events_message.rb
136
+ - lib/dji_mqtt_connect/messages/thing/product/events_reply_message.rb
135
137
  - lib/dji_mqtt_connect/messages/thing/product/file_upload_callback_events_message.rb
138
+ - lib/dji_mqtt_connect/messages/thing/product/fileupload_progress_events_message.rb
139
+ - lib/dji_mqtt_connect/messages/thing/product/highest_priority_upload_flighttask_media_events_message.rb
136
140
  - lib/dji_mqtt_connect/messages/thing/product/hms_events_message.rb
137
141
  - lib/dji_mqtt_connect/messages/thing/product/osd_message.rb
138
142
  - lib/dji_mqtt_connect/messages/thing/product/remote_osd_message.rb
@@ -149,6 +153,7 @@ files:
149
153
  - lib/dji_mqtt_connect/topics/sys/product/status.rb
150
154
  - lib/dji_mqtt_connect/topics/sys/product/status_reply.rb
151
155
  - lib/dji_mqtt_connect/topics/thing/product/events.rb
156
+ - lib/dji_mqtt_connect/topics/thing/product/events_reply.rb
152
157
  - lib/dji_mqtt_connect/topics/thing/product/osd.rb
153
158
  - lib/dji_mqtt_connect/topics/thing/product/requests.rb
154
159
  - lib/dji_mqtt_connect/topics/thing/product/requests_reply.rb