dji_mqtt_connect 0.1.24.1 → 0.1.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/config/locales/flighttask_status.en.yml +136 -0
  4. data/config/locales/result_codes.en.yml +2 -0
  5. data/config/locales/sys_product_status.en.yml +4 -0
  6. data/config/locales/thing_product_events.en.yml +64 -0
  7. data/config/locales/thing_product_events_reply.en.yml +4 -0
  8. data/config/locales/thing_product_osd.en.yml +7 -0
  9. data/config/locales/thing_product_requests.en.yml +12 -0
  10. data/config/locales/thing_product_requests_reply.en.yml +14 -0
  11. data/config/locales/thing_product_services.en.yml +27 -0
  12. data/config/locales/thing_product_services_reply.en.yml +4 -0
  13. data/config/locales/thing_product_state.en.yml +4 -0
  14. data/config/locales/thing_product_state_reply.en.yml +3 -0
  15. data/config/locales/video_qualities.en.yml +8 -0
  16. data/config/locales/video_types.en.yml +7 -0
  17. data/lib/dji_mqtt_connect/factories/events_messages.rb +73 -14
  18. data/lib/dji_mqtt_connect/factories/services_messages.rb +190 -0
  19. data/lib/dji_mqtt_connect/factories/state_messages.rb +19 -19
  20. data/lib/dji_mqtt_connect/factories.rb +14 -176
  21. data/lib/dji_mqtt_connect/marshals/sys/product/status_reply_marshal.rb +2 -16
  22. data/lib/dji_mqtt_connect/marshals/thing/product/events_marshal.rb +11 -4
  23. data/lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb +2 -16
  24. data/lib/dji_mqtt_connect/marshals/thing/product/osd_marshal.rb +4 -4
  25. data/lib/dji_mqtt_connect/marshals/thing/product/requests_marshal.rb +4 -4
  26. data/lib/dji_mqtt_connect/marshals/thing/product/requests_reply_marshal.rb +2 -16
  27. data/lib/dji_mqtt_connect/marshals/thing/product/services_marshal.rb +2 -16
  28. data/lib/dji_mqtt_connect/marshals/thing/product/services_reply_marshal.rb +4 -4
  29. data/lib/dji_mqtt_connect/marshals/thing/product/state_marshal.rb +4 -4
  30. data/lib/dji_mqtt_connect/marshals/thing/product/state_reply_marshal.rb +2 -16
  31. data/lib/dji_mqtt_connect/messages/sys/product/status/update_topo.rb +1 -1
  32. data/lib/dji_mqtt_connect/messages/sys/product/status_message.rb +10 -0
  33. data/lib/dji_mqtt_connect/messages/sys/product/status_reply/update_topo.rb +1 -10
  34. data/lib/dji_mqtt_connect/messages/sys/product/status_reply_message.rb +22 -0
  35. data/lib/dji_mqtt_connect/messages/thing/product/events/airsense_warning.rb +16 -15
  36. data/lib/dji_mqtt_connect/messages/thing/product/events/cover_close.rb +9 -0
  37. data/lib/dji_mqtt_connect/messages/thing/product/events/cover_open.rb +9 -0
  38. data/lib/dji_mqtt_connect/messages/thing/product/events/device_exit_homing_notify.rb +13 -0
  39. data/lib/dji_mqtt_connect/messages/thing/product/events/device_reboot.rb +9 -0
  40. data/lib/dji_mqtt_connect/messages/thing/product/events/file_upload_callback.rb +13 -1
  41. data/lib/dji_mqtt_connect/messages/thing/product/events/fileupload_progress.rb +28 -1
  42. data/lib/dji_mqtt_connect/messages/thing/product/events/flight_areas_sync_progress.rb +8 -0
  43. data/lib/dji_mqtt_connect/messages/thing/product/events/flighttask_progress.rb +50 -2
  44. data/lib/dji_mqtt_connect/messages/thing/product/events/flighttask_ready.rb +6 -1
  45. data/lib/dji_mqtt_connect/messages/thing/product/events/highest_priority_upload_flighttask_media.rb +6 -1
  46. data/lib/dji_mqtt_connect/messages/thing/product/events/return_home_info.rb +24 -1
  47. data/lib/dji_mqtt_connect/messages/thing/product/events/takeoff_to_point_progress.rb +7 -1
  48. data/lib/dji_mqtt_connect/messages/thing/product/events_message.rb +19 -1
  49. data/lib/dji_mqtt_connect/messages/thing/product/events_reply_message.rb +12 -1
  50. data/lib/dji_mqtt_connect/messages/thing/product/osd/dock.rb +5 -1
  51. data/lib/dji_mqtt_connect/messages/thing/product/osd/drone.rb +5 -1
  52. data/lib/dji_mqtt_connect/messages/thing/product/osd/remote.rb +4 -0
  53. data/lib/dji_mqtt_connect/messages/thing/product/osd_message.rb +14 -4
  54. data/lib/dji_mqtt_connect/messages/thing/product/requests/airport_bind_status.rb +8 -1
  55. data/lib/dji_mqtt_connect/messages/thing/product/requests/airport_organization_bind.rb +15 -1
  56. data/lib/dji_mqtt_connect/messages/thing/product/requests/config.rb +0 -1
  57. data/lib/dji_mqtt_connect/messages/thing/product/requests/flight_areas_get.rb +0 -2
  58. data/lib/dji_mqtt_connect/messages/thing/product/requests/flighttask_resource_get.rb +6 -1
  59. data/lib/dji_mqtt_connect/messages/thing/product/requests/offline_map_get.rb +0 -2
  60. data/lib/dji_mqtt_connect/messages/thing/product/requests_message.rb +18 -1
  61. data/lib/dji_mqtt_connect/messages/thing/product/requests_reply/airport_bind_status.rb +16 -6
  62. data/lib/dji_mqtt_connect/messages/thing/product/requests_reply/airport_organization_bind.rb +2 -6
  63. data/lib/dji_mqtt_connect/messages/thing/product/requests_reply/airport_organization_get.rb +7 -5
  64. data/lib/dji_mqtt_connect/messages/thing/product/requests_reply/config.rb +9 -5
  65. data/lib/dji_mqtt_connect/messages/thing/product/requests_reply/flight_areas_get.rb +21 -5
  66. data/lib/dji_mqtt_connect/messages/thing/product/requests_reply/flighttask_resource_get.rb +1 -5
  67. data/lib/dji_mqtt_connect/messages/thing/product/requests_reply/offline_map_get.rb +3 -14
  68. data/lib/dji_mqtt_connect/messages/thing/product/requests_reply/storage_config_get.rb +7 -5
  69. data/lib/dji_mqtt_connect/messages/thing/product/requests_reply_message.rb +26 -0
  70. data/lib/dji_mqtt_connect/messages/thing/product/services/alarm_state_switch.rb +10 -0
  71. data/lib/dji_mqtt_connect/messages/thing/product/services/cover_close.rb +0 -2
  72. data/lib/dji_mqtt_connect/messages/thing/product/services/cover_open.rb +0 -2
  73. data/lib/dji_mqtt_connect/messages/thing/product/services/debug_mode_close.rb +0 -2
  74. data/lib/dji_mqtt_connect/messages/thing/product/services/debug_mode_open.rb +0 -2
  75. data/lib/dji_mqtt_connect/messages/thing/product/services/flighttask_execute.rb +81 -1
  76. data/lib/dji_mqtt_connect/messages/thing/product/services/flighttask_pause.rb +0 -2
  77. data/lib/dji_mqtt_connect/messages/thing/product/services/flighttask_prepare.rb +19 -5
  78. data/lib/dji_mqtt_connect/messages/thing/product/services/flighttask_progress_get.rb +25 -0
  79. data/lib/dji_mqtt_connect/messages/thing/product/services/flighttask_recovery.rb +0 -2
  80. data/lib/dji_mqtt_connect/messages/thing/product/services/flighttask_stop.rb +37 -0
  81. data/lib/dji_mqtt_connect/messages/thing/product/services/flighttask_undo.rb +12 -1
  82. data/lib/dji_mqtt_connect/messages/thing/product/services/live_lens_change.rb +10 -16
  83. data/lib/dji_mqtt_connect/messages/thing/product/services/live_set_quality.rb +10 -18
  84. data/lib/dji_mqtt_connect/messages/thing/product/services/live_start_push.rb +5 -19
  85. data/lib/dji_mqtt_connect/messages/thing/product/services/live_stop_push.rb +2 -1
  86. data/lib/dji_mqtt_connect/messages/thing/product/services/return_home.rb +1 -6
  87. data/lib/dji_mqtt_connect/messages/thing/product/services/return_home_cancel.rb +1 -6
  88. data/lib/dji_mqtt_connect/messages/thing/product/services/return_specific_home.rb +27 -0
  89. data/lib/dji_mqtt_connect/messages/thing/product/services_message.rb +18 -1
  90. data/lib/dji_mqtt_connect/messages/thing/product/services_reply/flighttask_progress_get.rb +48 -0
  91. data/lib/dji_mqtt_connect/messages/thing/product/services_reply/flighttask_stop.rb +9 -0
  92. data/lib/dji_mqtt_connect/messages/thing/product/services_reply/return_specific_home.rb +22 -0
  93. data/lib/dji_mqtt_connect/messages/thing/product/services_reply_message.rb +8 -0
  94. data/lib/dji_mqtt_connect/messages/thing/product/state_message.rb +71 -9
  95. data/lib/dji_mqtt_connect/messages/thing/product/state_reply_message.rb +12 -1
  96. data/lib/dji_mqtt_connect/mixins/video_quality.rb +43 -0
  97. data/lib/dji_mqtt_connect/mixins/video_type.rb +37 -0
  98. data/lib/dji_mqtt_connect/translations.rb +144 -0
  99. data/lib/dji_mqtt_connect/types.rb +24 -1
  100. data/lib/dji_mqtt_connect/utils/message_dumping.rb +49 -0
  101. data/lib/dji_mqtt_connect/version.rb +1 -1
  102. data/lib/dji_mqtt_connect.rb +12 -0
  103. metadata +26 -2
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DjiMqttConnect
4
+ module Thing::Product
5
+ # Return to Specific Home
6
+ # https://developer.dji.com/doc/cloud-api-tutorial/en/api-reference/dock-to-cloud/mqtt/dock/dock2/wayline.html#designate-home-point-for-returning
7
+ class ReturnSpecificHomeServicesMessage < ServicesMessage
8
+ def self.build(home_dock_sn:, bid: generate_bid, tid: generate_tid, timestamp: current_timestamp)
9
+ new(
10
+ bid: bid,
11
+ tid: tid,
12
+ timestamp: timestamp,
13
+ _method: "return_specific_home",
14
+ data: {
15
+ home_dock_sn: home_dock_sn
16
+ }
17
+ )
18
+ end
19
+
20
+ attribute :_method, Types::String.enum("return_specific_home")
21
+
22
+ attribute :data do
23
+ attribute :home_dock_sn, Types::SerialNumber
24
+ end
25
+ end
26
+ end
27
+ end
@@ -2,13 +2,30 @@
2
2
 
3
3
  module DjiMqttConnect
4
4
  module Thing::Product
5
- class ServicesMessage < Message
5
+ class ServicesMessage < DjiMqttConnect::Message
6
6
  # Ensure all values are accepted
7
7
  schema schema.strict
8
8
 
9
9
  attribute :tid, Types::UUID
10
10
  attribute :bid, Types::UUID
11
11
  attribute :timestamp, Types::Timestamp
12
+
13
+ attribute :_method, Types::String
14
+
15
+ attribute :data, Types::Hash.default({}.freeze)
16
+
17
+ def humanized_summary
18
+ Translations.thing_product_services_summary(_method, **humanized_summary_interpolation)
19
+ end
20
+
21
+ def humanized_summary_interpolation
22
+ data.to_h.merge(method: _method)
23
+ end
24
+
25
+ # Returns all the flight IDs in the message
26
+ def flight_ids
27
+ []
28
+ end
12
29
  end
13
30
  end
14
31
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DjiMqttConnect
4
+ module Thing::Product
5
+ class FlighttaskProgressGetServicesReplyMessage < ServicesReplyMessage
6
+ attribute :_method, Types::String.enum("flighttask_progress_get")
7
+
8
+ attribute :data do
9
+ include Mixins::ResultMessage
10
+
11
+ attribute :result, Types::ResultCode
12
+
13
+ attribute :output do
14
+ attribute :flight_id, Types::String
15
+
16
+ # {"partially_done":"partially done","sent":"sent","in_progress":"in progress","ok":"success","paused":"paused","rejected":"rejected","failed":"failed","canceled":"canceled or stopped","timeout":"timeout"}
17
+ attribute :status, Types::String.enum(
18
+ "partially_done",
19
+ "sent",
20
+ "in_progress",
21
+ "ok",
22
+ "paused",
23
+ "rejected",
24
+ "failed",
25
+ "canceled",
26
+ "timeout"
27
+ )
28
+
29
+ def humanized_status
30
+ I18n.t(status, scope: "dji_mqtt_connect.flighttask_status", default: status.titleize)
31
+ end
32
+
33
+ attribute :progress do
34
+ # {"0":"Initial state","1":"Pre-flight check, whether the aircraft is executing a wayline","2":"Pre-flight check, whether the dock has exited working mode","3":"Pre-flight check, wayline execution in progress","4":"Pre-return-to-home check, in the process of returning to home","5":"Wayline execution enters the preparation state, waiting for the mission to be issued","6":"Dock enters working state","7":"Enter the startup check and cover preparation work","8":"Remote image transmission frequency Pairing","9":"Waiting for the flight system to be ready, push connection established","10":"Waiting for RTK source to listen for reported values","11":"Check if the RTK source is from the dock, if not, reset it","12":"Waiting for flight control notification","13":"The dock has no control and seizes the control of the aircraft","14":"Consistency check of custom flight area","15":"Consistency check of offline maps","16":"Get the latest KMZ URL","17":"Download KMZ","18":"KMZ uploading","19":"Coloring configuration","20":"Aircraft takeoff parameter setting, alternate landing point setting, takeoff altitude setting, coloring setting","21":"Aircraft flyto takeoff parameter setting","22":"Takeoff dock checks the landing dock preparation status","23":"Home point setting","24":"Trigger wayline execution","25":"Wayline executing","26":"Enter pre-return-to-home check","27":"Aircraft landing at the dock","28":"Close the cover after landing","29":"Dock exits working mode","30":"Dock abnormal recovery","31":"Dock uploads flight system logs","32":"Check camera recording state","33":"Get the number of media files","34":"Abnormal recovery after dock takeoff cover","35":"Notify mission result","36":"Log list retrieval - Aircraft list","37":"Log list retrieval - Retrieve the list of docks","38":"Log list retrieval - Upload log list result","39":"Log retrieval - Retrieve aircraft logs","40":"Log retrieval - Retrieve dock logs","41":"Log retrieval - Compress aircraft logs","42":"Log retrieval - Compress dock logs","43":"Log retrieval - Upload aircraft logs","44":"Log retrieval - Upload dock logs","45":"Log retrieval - Notify the result","46":"Custom flight area file update preparation","47":"Custom flight area updating","48":"Offline map update preparation","49":"Offline map updating","65533":"Wait for service response after completion","65534":"No specific state","65535":"UNKNOWN"}
35
+ attribute :current_step, Types::Integer
36
+
37
+ def humanized_current_step
38
+ I18n.t(current_step, scope: "dji_mqtt_connect.flighttask_progress.current_step", default: current_step.to_s)
39
+ end
40
+
41
+ # {"min":"0","max":"100","step":"1"}
42
+ attribute :percent, Types::Integer.constrained(gteq: 0, lteq: 100)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DjiMqttConnect
4
+ module Thing::Product
5
+ class FlighttaskStopServicesReplyMessage < ServicesReplyMessage
6
+ attribute :_method, Types::String.enum("flighttask_stop")
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DjiMqttConnect
4
+ module Thing::Product
5
+ class ReturnSpecificHomeServicesReplyMessage < ServicesReplyMessage
6
+ attribute :_method, Types::String.enum("return_specific_home")
7
+
8
+ attribute :data do
9
+ include Mixins::ResultMessage
10
+
11
+ attribute :result, Types::ResultCode
12
+
13
+ attribute? :output do
14
+ include Mixins::ServicesOutputStatusChecks
15
+
16
+ # {"sent":"sent","in_progress":"in progress","ok":"succeeded","paused":"paused","rejected":"rejected","failed":"failed","canceled":"canceled or terminated","timeout":"timeout"}
17
+ attribute :status, Types::ServicesOutputStatus
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -16,6 +16,14 @@ module DjiMqttConnect
16
16
  attribute :result, Types::ResultCode
17
17
  end
18
18
 
19
+ def humanized_summary
20
+ Translations.thing_product_services_reply_summary(_method, **humanized_summary_interpolation)
21
+ end
22
+
23
+ def humanized_summary_interpolation
24
+ data.to_h.merge(method: _method)
25
+ end
26
+
19
27
  def to_s
20
28
  # Include data method for Generic messages
21
29
  instance_of?(ServicesReplyMessage) ? "#{super}[#{_method}]" : super
@@ -78,7 +78,9 @@ module DjiMqttConnect
78
78
  attribute :tid, Types::UUID
79
79
  attribute :bid, Types::UUID
80
80
  attribute :timestamp, Types::Timestamp
81
- attribute :gateway, Types::String
81
+
82
+ # Can be determined from the topic, but included for convenience
83
+ attribute :gateway, Types::SerialNumber
82
84
 
83
85
  attribute :_data, Types::Hash
84
86
 
@@ -94,12 +96,51 @@ module DjiMqttConnect
94
96
  attribute :state, Types::Integer
95
97
  end
96
98
 
99
+ attribute? :cameras, Types::Array do
100
+ attribute :camera_mode, Types::Integer
101
+ attribute :liveview_world_region do
102
+ attribute :bottom, Types::JSON::Decimal
103
+ attribute :left, Types::JSON::Decimal
104
+ attribute :right, Types::JSON::Decimal
105
+ attribute :top, Types::JSON::Decimal
106
+ end
107
+ attribute :payload_index, Types::String
108
+ attribute :photo_state, Types::Integer
109
+ attribute :record_time, Types::Integer
110
+ attribute :recording_state, Types::Integer
111
+ attribute :remain_photo_num, Types::Integer
112
+ attribute :remain_record_duration, Types::Integer
113
+ attribute :wide_calibrate_farthest_focus_value, Types::Integer
114
+ attribute :wide_calibrate_nearest_focus_value, Types::Integer
115
+ attribute :wide_exposure_mode, Types::Integer
116
+ attribute :wide_exposure_value, Types::Integer
117
+ attribute :wide_focus_mode, Types::Integer
118
+ attribute :wide_focus_state, Types::Integer
119
+ attribute :wide_focus_value, Types::Integer
120
+ attribute :wide_iso, Types::Integer
121
+ attribute :wide_max_focus_value, Types::Integer
122
+ attribute :wide_min_focus_value, Types::Integer
123
+ attribute :wide_shutter_speed, Types::Integer
124
+ attribute :zoom_calibrate_farthest_focus_value, Types::Integer
125
+ attribute :zoom_calibrate_nearest_focus_value, Types::Integer
126
+ attribute :zoom_exposure_mode, Types::Integer
127
+ attribute :zoom_exposure_value, Types::Integer
128
+ attribute :zoom_factor, Types::JSON::Decimal
129
+ attribute :zoom_focus_mode, Types::Integer
130
+ attribute :zoom_focus_state, Types::Integer
131
+ attribute :zoom_focus_value, Types::Integer
132
+ attribute :zoom_iso, Types::Integer
133
+ attribute :zoom_max_focus_value, Types::Integer
134
+ attribute :zoom_min_focus_value, Types::Integer
135
+ attribute :zoom_shutter_speed, Types::Integer
136
+ end
137
+
97
138
  # Not all messages will have a live_capacity attribute
98
139
  attribute? :live_capacity do
99
140
  attribute :available_video_number, Types::Integer
100
141
  attribute :coexist_video_number_max, Types::Integer
101
142
  attribute :device_list, Types::Array do
102
- attribute :sn, Types::String
143
+ attribute :sn, Types::SerialNumber
103
144
  attribute :available_video_number, Types::Integer
104
145
  attribute :coexist_video_number_max, Types::Integer
105
146
  attribute :camera_list, Types::Array do
@@ -107,18 +148,28 @@ module DjiMqttConnect
107
148
  attribute :available_video_number, Types::Integer
108
149
  attribute :coexist_video_number_max, Types::Integer
109
150
  attribute :video_list, Types::Array do
151
+ include Mixins::VideoType
152
+
110
153
  attribute :video_index, Types::String
111
- attribute :video_type, Types::String
112
- attribute :switchable_video_types, Types::Array.of(Types::String)
154
+
155
+ attribute :video_type, Types::VideoType
156
+
157
+ attribute :switchable_video_types, Types::Array.of(Types::VideoType)
113
158
  end
114
159
  end
115
160
  end
116
161
  end
117
162
 
118
163
  attribute? :live_status, Types::Array do
164
+ include Mixins::VideoType
165
+ include Mixins::VideoQuality
166
+
119
167
  attribute :video_id, Types::String
120
- attribute :video_type, Types::String
121
- attribute :video_quality, Types::Integer
168
+
169
+ attribute :video_type, Types::VideoType
170
+
171
+ attribute :video_quality, Types::VideoQuality
172
+
122
173
  attribute :status, Types::Integer
123
174
  attribute :error_status, Types::Integer
124
175
  end
@@ -127,7 +178,7 @@ module DjiMqttConnect
127
178
  attribute :control_source, Types::String
128
179
  attribute? :firmware_version, Types::String
129
180
  attribute :payload_index, Types::String
130
- attribute? :sn, Types::String
181
+ attribute? :sn, Types::SerialNumber
131
182
  end
132
183
 
133
184
  attribute? :rtcm_info do
@@ -141,13 +192,13 @@ module DjiMqttConnect
141
192
  attribute? :wireless_link_topo do
142
193
  attribute :center_node do
143
194
  attribute :sdr_id, Types::Integer
144
- attribute :sn, Types::String
195
+ attribute :sn, Types::SerialNumber
145
196
  end
146
197
 
147
198
  attribute :leaf_nodes, Types::Array do
148
199
  attribute :control_source_index, Types::Integer
149
200
  attribute :sdr_id, Types::Integer
150
- attribute :sn, Types::String
201
+ attribute :sn, Types::SerialNumber
151
202
  attribute :valid, Types::Bool
152
203
  end
153
204
 
@@ -178,6 +229,17 @@ module DjiMqttConnect
178
229
  attribute? :low_battery_warning_threshold, Types::Integer
179
230
  attribute? :serious_low_battery_warning_threshold, Types::Integer
180
231
  end
232
+
233
+ def humanized_summary
234
+ Translations.thing_product_state_summary(**humanized_summary_interpolation)
235
+ end
236
+
237
+ def humanized_summary_interpolation
238
+ data.to_h.merge(
239
+ # Provides a list of all keys that are not nil or empty
240
+ topics: data.to_h.compact.keys.sort.join(", ").presence || "-"
241
+ )
242
+ end
181
243
  end
182
244
  end
183
245
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DjiMqttConnect
4
4
  module Thing::Product
5
- class StateReplyMessage < Message
5
+ class StateReplyMessage < DjiMqttConnect::Message
6
6
  # a result of 0 means we approve of this action
7
7
  def self.build_for(events_message, result: 0)
8
8
  new(
@@ -15,6 +15,9 @@ module DjiMqttConnect
15
15
  )
16
16
  end
17
17
 
18
+ # Ensure all values are accepted
19
+ schema schema.strict
20
+
18
21
  attribute :bid, Types::UUID
19
22
  attribute :tid, Types::UUID
20
23
  attribute :timestamp, Types::Timestamp
@@ -24,6 +27,14 @@ module DjiMqttConnect
24
27
 
25
28
  attribute :result, Types::ResultCode
26
29
  end
30
+
31
+ def humanized_summary
32
+ Translations.thing_product_state_reply_summary(**humanized_summary_interpolation)
33
+ end
34
+
35
+ def humanized_summary_interpolation
36
+ data.to_h
37
+ end
27
38
  end
28
39
  end
29
40
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DjiMqttConnect
4
+ module Mixins
5
+ # Adds video quality helper methods
6
+ # Assumes a `video_quality` attribute is present of type `Types::VideoQuality`
7
+ module VideoQuality
8
+ def humanized_video_quality
9
+ if video_quality_adaptive?
10
+ I18n.t("adaptive", scope: "dji_mqtt_connect.video_quality")
11
+ elsif video_quality_smooth?
12
+ I18n.t("smooth", scope: "dji_mqtt_connect.video_quality")
13
+ elsif video_quality_standard_definition?
14
+ I18n.t("standard_definition", scope: "dji_mqtt_connect.video_quality")
15
+ elsif video_quality_high_definition?
16
+ I18n.t("high_definition", scope: "dji_mqtt_connect.video_quality")
17
+ elsif video_quality_ultra_high_definition?
18
+ I18n.t("ultra_high_definition", scope: "dji_mqtt_connect.video_quality")
19
+ end
20
+ end
21
+
22
+ def video_quality_adaptive?
23
+ video_quality == Types::VIDEO_QUALITY_ADAPTIVE
24
+ end
25
+
26
+ def video_quality_smooth?
27
+ video_quality == Types::VIDEO_QUALITY_SMOOTH
28
+ end
29
+
30
+ def video_quality_standard_definition?
31
+ video_quality == Types::VIDEO_QUALITY_STANDARD_DEFINITION
32
+ end
33
+
34
+ def video_quality_high_definition?
35
+ video_quality == Types::VIDEO_QUALITY_HIGH_DEFINITION
36
+ end
37
+
38
+ def video_quality_ultra_high_definition?
39
+ video_quality == Types::VIDEO_QUALITY_ULTRA_HIGH_DEFINITION
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DjiMqttConnect
4
+ module Mixins
5
+ # Adds video type helper methods
6
+ # Assumes a `video_type` attribute is present of type `Types::VideoType`
7
+ module VideoType
8
+ def humanized_video_type
9
+ if video_type_infrared?
10
+ I18n.t("infrared", scope: "dji_mqtt_connect.video_types") # Infrared
11
+ elsif video_type_normal?
12
+ I18n.t("normal", scope: "dji_mqtt_connect.video_types") # Default
13
+ elsif video_type_wide_angle?
14
+ I18n.t("wide_angle", scope: "dji_mqtt_connect.video_types") # Wide-angle
15
+ elsif video_type_zoom?
16
+ I18n.t("zoom", scope: "dji_mqtt_connect.video_types") # Zoom
17
+ end
18
+ end
19
+
20
+ def video_type_infrared?
21
+ video_type == Types::VIDEO_TYPE_INFRARED
22
+ end
23
+
24
+ def video_type_normal?
25
+ video_type == Types::VIDEO_TYPE_NORMAL
26
+ end
27
+
28
+ def video_type_wide_angle?
29
+ video_type == Types::VIDEO_TYPE_WIDE_ANGLE
30
+ end
31
+
32
+ def video_type_zoom?
33
+ video_type == Types::VIDEO_TYPE_ZOOM
34
+ end
35
+ end
36
+ end
37
+ end
@@ -91,5 +91,149 @@ module DjiMqttConnect
91
91
  position_name("unknown")
92
92
  end
93
93
  end
94
+
95
+ ### Message Summaries ###
96
+
97
+ def result_summary(result)
98
+ I18n.t(
99
+ "dji_mqtt_connect.result_summary",
100
+ result: result,
101
+ result_message: result_message(result)
102
+ )
103
+ end
104
+
105
+ def failed_result_summary(result)
106
+ I18n.t(
107
+ "dji_mqtt_connect.failed_result_summary",
108
+ result: result,
109
+ result_message: result_message(result)
110
+ )
111
+ end
112
+
113
+ def sys_product_status_summary(method, result: 0, **data)
114
+ return failed_result_summary(result) if result != 0
115
+
116
+ I18n.t(
117
+ method,
118
+ **data,
119
+ scope: "dji_mqtt_connect.sys_product_status_summary",
120
+ default: :default,
121
+ method: method,
122
+ result: result_summary(result)
123
+ )
124
+ end
125
+
126
+ def thing_product_events_summary(method, result: 0, **data)
127
+ return failed_result_summary(result) if result != 0
128
+
129
+ I18n.t(
130
+ method,
131
+ **data,
132
+ scope: "dji_mqtt_connect.thing_product_events_summary",
133
+ default: :default,
134
+ method: method,
135
+ result: result_summary(result)
136
+ )
137
+ end
138
+
139
+ def thing_product_events_reply_summary(method, result: 0, **data)
140
+ return failed_result_summary(result) if result != 0
141
+
142
+ I18n.t(
143
+ method,
144
+ **data,
145
+ scope: "dji_mqtt_connect.thing_product_events_reply_summary",
146
+ default: :default,
147
+ method: method,
148
+ result: result_summary(result)
149
+ )
150
+ end
151
+
152
+ def thing_product_osd_summary(**data)
153
+ I18n.t("default", **data, scope: "dji_mqtt_connect.thing_product_osd_summary")
154
+ end
155
+
156
+ def thing_product_dock_osd_summary(**data)
157
+ I18n.t("dock", **data, scope: "dji_mqtt_connect.thing_product_osd_summary", default: :default)
158
+ end
159
+
160
+ def thing_product_drone_osd_summary(**data)
161
+ I18n.t("drone", **data, scope: "dji_mqtt_connect.thing_product_osd_summary", default: :default)
162
+ end
163
+
164
+ def thing_product_remote_osd_summary(**data)
165
+ I18n.t("remote", **data, scope: "dji_mqtt_connect.thing_product_osd_summary", default: :default)
166
+ end
167
+
168
+ def thing_product_requests_summary(method, result: 0, **data)
169
+ return failed_result_summary(result) if result != 0
170
+
171
+ I18n.t(
172
+ method,
173
+ **data,
174
+ scope: "dji_mqtt_connect.thing_product_requests_summary",
175
+ default: :default,
176
+ method: method,
177
+ result: result_summary(result)
178
+ )
179
+ end
180
+
181
+ def thing_product_requests_reply_summary(method, result: 0, **data)
182
+ return failed_result_summary(result) if result != 0
183
+
184
+ I18n.t(
185
+ method,
186
+ **data,
187
+ scope: "dji_mqtt_connect.thing_product_requests_reply_summary",
188
+ default: :default,
189
+ method: method,
190
+ result: result_summary(result)
191
+ )
192
+ end
193
+
194
+ def thing_product_services_summary(method, **data)
195
+ I18n.t(
196
+ method,
197
+ **data,
198
+ scope: "dji_mqtt_connect.thing_product_services_summary",
199
+ default: :default,
200
+ method: method
201
+ )
202
+ end
203
+
204
+ def thing_product_services_reply_summary(method, result: 0, **data)
205
+ return failed_result_summary(result) if result != 0
206
+
207
+ I18n.t(
208
+ method,
209
+ **data,
210
+ scope: "dji_mqtt_connect.thing_product_services_reply_summary",
211
+ default: :default,
212
+ method: method,
213
+ result: result_summary(result)
214
+ )
215
+ end
216
+
217
+ def thing_product_state_summary(result: 0, **data)
218
+ return failed_result_summary(result) if result != 0
219
+
220
+ I18n.t(
221
+ "state",
222
+ **data,
223
+ scope: "dji_mqtt_connect.thing_product_state_summary",
224
+ default: :default,
225
+ result: result_summary(result)
226
+ )
227
+ end
228
+
229
+ def thing_product_state_reply_summary(result: 0, **data)
230
+ return failed_result_summary(result) if result != 0
231
+
232
+ I18n.t(
233
+ "dji_mqtt_connect.thing_product_state_reply_summary",
234
+ **data,
235
+ result: result_summary(result)
236
+ )
237
+ end
94
238
  end
95
239
  end
@@ -19,7 +19,11 @@ module DjiMqttConnect
19
19
  # Just make sure Timestamps are 13 digits long
20
20
  Timestamp = Types::Integer & Types::Coercible::String.constrained(format: /\A[1-9][0-9]{12}\z/)
21
21
 
22
- SerialNumber = Types::String
22
+ # Serial Numbers are alphanumeric with optional hyphen
23
+ SerialNumber = Types::String.constrained(format: /\A[0-9A-Z]+(-[0-9A-Z]+)?\z/)
24
+
25
+ # Flight ID is a string with at least 1 character
26
+ FlightID = Types::String.constrained(min_size: 1)
23
27
 
24
28
  # lat/lng coordinates
25
29
  Latitude = NullInteger | Types::JSON::Decimal.constrained(gteq: -90, lteq: 90)
@@ -78,6 +82,25 @@ module DjiMqttConnect
78
82
  SERVICE_OUTPUT_STATUS_TIMEOUT = "timeout"
79
83
  )
80
84
 
85
+ # Video Quality
86
+ # {"0":"Adaptive","1":"Smooth","2":"Standard definition","3":"High definition","4":"Ultra-high definition"}
87
+ VideoQuality = Types::Integer.enum(
88
+ VIDEO_QUALITY_ADAPTIVE = 0,
89
+ VIDEO_QUALITY_SMOOTH = 1,
90
+ VIDEO_QUALITY_STANDARD_DEFINITION = 2,
91
+ VIDEO_QUALITY_HIGH_DEFINITION = 3,
92
+ VIDEO_QUALITY_ULTRA_HIGH_DEFINITION = 4
93
+ )
94
+
95
+ # Video Type
96
+ # {"ir":"Infrared","normal":"Default","wide":"Wide-angle","zoom":"Zoom"}
97
+ VideoType = Types::String.enum(
98
+ VIDEO_TYPE_INFRARED = "ir",
99
+ VIDEO_TYPE_NORMAL = "normal",
100
+ VIDEO_TYPE_WIDE_ANGLE = "wide",
101
+ VIDEO_TYPE_ZOOM = "zoom"
102
+ )
103
+
81
104
  # Result for messages
82
105
  ResultCode = Types::Integer.constrained(gteq: 0)
83
106
  end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry-transformer"
4
+
5
+ module DjiMqttConnect
6
+ module Utils
7
+ # Provides methods for transforming data for a marshal to dump
8
+ module MessageDumping
9
+ # Renames the method attribute
10
+ class MessageTransformer < Dry::Transformer::Pipe
11
+ import Dry::Transformer::HashTransformations
12
+
13
+ define! do
14
+ rename_keys _method: :method
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ # Converts a DjiMqttConnect::Message to a serializeable hash
21
+ def convert_message_to_hash(message)
22
+ # Fix up the hash representation
23
+ transformed_message = message_transformer.call(message)
24
+
25
+ # Convert the transformed message into JSON-compatible data
26
+ convert_to_serializable_object(transformed_message)
27
+ end
28
+
29
+ # Converts an object to a mqtt serializable object
30
+ def convert_to_serializable_object(object)
31
+ case object
32
+ when Hash
33
+ object.transform_values { |value| convert_to_serializable_object(value) }
34
+ when Array
35
+ object.map { |value| convert_to_serializable_object(value) }
36
+ when BigDecimal
37
+ # DJI expects floats, not string decimals
38
+ object.to_f
39
+ else
40
+ object
41
+ end
42
+ end
43
+
44
+ def message_transformer
45
+ @message_transformer ||= MessageTransformer.new
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DjiMqttConnect
4
- VERSION = "0.1.24.1"
4
+ VERSION = "0.1.25"
5
5
  end