dji_mqtt_connect 0.1.12.1 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/dji_mqtt_connect/client.rb +5 -0
  4. data/lib/dji_mqtt_connect/factories.rb +356 -0
  5. data/lib/dji_mqtt_connect/marshals/thing/product/services_reply_marshal.rb +47 -0
  6. data/lib/dji_mqtt_connect/messages/thing/product/events/cover_close.rb +65 -0
  7. data/lib/dji_mqtt_connect/messages/thing/product/events/cover_open.rb +65 -0
  8. data/lib/dji_mqtt_connect/messages/thing/product/events/device_exit_homing_notify.rb +36 -0
  9. data/lib/dji_mqtt_connect/messages/thing/product/events/device_log.rb +20 -0
  10. data/lib/dji_mqtt_connect/messages/thing/product/{file_upload_callback_events_message.rb → events/file_upload_callback.rb} +0 -7
  11. data/lib/dji_mqtt_connect/messages/thing/product/{fileupload_progress_events_message.rb → events/fileupload_progress.rb} +0 -7
  12. data/lib/dji_mqtt_connect/messages/thing/product/events/flighttask_progress.rb +67 -0
  13. data/lib/dji_mqtt_connect/messages/thing/product/events/flighttask_ready.rb +15 -0
  14. data/lib/dji_mqtt_connect/messages/thing/product/{highest_priority_upload_flighttask_media_events_message.rb → events/highest_priority_upload_flighttask_media.rb} +0 -7
  15. data/lib/dji_mqtt_connect/messages/thing/product/events_message.rb +7 -0
  16. data/lib/dji_mqtt_connect/messages/thing/product/events_reply_message.rb +3 -0
  17. data/lib/dji_mqtt_connect/messages/thing/product/requests/flighttask_resource_get.rb +15 -0
  18. data/lib/dji_mqtt_connect/messages/thing/product/requests_reply/flighttask_resource_get.rb +44 -0
  19. data/lib/dji_mqtt_connect/messages/thing/product/services/alarm_state_switch.rb +29 -0
  20. data/lib/dji_mqtt_connect/messages/thing/product/{cover_close_services_message.rb → services/cover_close.rb} +2 -5
  21. data/lib/dji_mqtt_connect/messages/thing/product/{cover_open_services_message.rb → services/cover_open.rb} +2 -5
  22. data/lib/dji_mqtt_connect/messages/thing/product/services/debug_mode_close.rb +20 -0
  23. data/lib/dji_mqtt_connect/messages/thing/product/services/debug_mode_open.rb +20 -0
  24. data/lib/dji_mqtt_connect/messages/thing/product/{fileupload_list_services_message.rb → services/fileupload_list.rb} +1 -4
  25. data/lib/dji_mqtt_connect/messages/thing/product/{fileupload_start_services_message.rb → services/fileupload_start.rb} +1 -5
  26. data/lib/dji_mqtt_connect/messages/thing/product/services/flighttask_execute.rb +27 -0
  27. data/lib/dji_mqtt_connect/messages/thing/product/services/flighttask_pause.rb +20 -0
  28. data/lib/dji_mqtt_connect/messages/thing/product/services/flighttask_prepare.rb +86 -0
  29. data/lib/dji_mqtt_connect/messages/thing/product/services/flighttask_recovery.rb +22 -0
  30. data/lib/dji_mqtt_connect/messages/thing/product/services/flighttask_undo.rb +27 -0
  31. data/lib/dji_mqtt_connect/messages/thing/product/services/return_home.rb +25 -0
  32. data/lib/dji_mqtt_connect/messages/thing/product/services/return_home_cancel.rb +28 -0
  33. data/lib/dji_mqtt_connect/messages/thing/product/services_message.rb +14 -0
  34. data/lib/dji_mqtt_connect/messages/thing/product/services_reply/alarm_state_switch.rb +27 -0
  35. data/lib/dji_mqtt_connect/messages/thing/product/services_reply/cover_close.rb +27 -0
  36. data/lib/dji_mqtt_connect/messages/thing/product/services_reply/cover_open.rb +27 -0
  37. data/lib/dji_mqtt_connect/messages/thing/product/services_reply/debug_mode_close.rb +27 -0
  38. data/lib/dji_mqtt_connect/messages/thing/product/services_reply/debug_mode_open.rb +27 -0
  39. data/lib/dji_mqtt_connect/messages/thing/product/services_reply/flighttask_execute.rb +9 -0
  40. data/lib/dji_mqtt_connect/messages/thing/product/services_reply/flighttask_pause.rb +9 -0
  41. data/lib/dji_mqtt_connect/messages/thing/product/services_reply/flighttask_prepare.rb +9 -0
  42. data/lib/dji_mqtt_connect/messages/thing/product/services_reply/flighttask_recovery.rb +9 -0
  43. data/lib/dji_mqtt_connect/messages/thing/product/services_reply/flighttask_undo.rb +9 -0
  44. data/lib/dji_mqtt_connect/messages/thing/product/services_reply/return_home.rb +27 -0
  45. data/lib/dji_mqtt_connect/messages/thing/product/services_reply/return_home_cancel.rb +9 -0
  46. data/lib/dji_mqtt_connect/messages/thing/product/services_reply_message.rb +23 -0
  47. data/lib/dji_mqtt_connect/topics/thing/product/services_reply.rb +40 -0
  48. data/lib/dji_mqtt_connect/types.rb +2 -0
  49. data/lib/dji_mqtt_connect/version.rb +1 -1
  50. data/lib/dji_mqtt_connect.rb +61 -26
  51. metadata +60 -26
  52. /data/lib/dji_mqtt_connect/messages/sys/product/{update_topo_status_message.rb → status/update_topo.rb} +0 -0
  53. /data/lib/dji_mqtt_connect/messages/sys/product/{update_topo_status_reply_message.rb → status_reply/update_topo.rb} +0 -0
  54. /data/lib/dji_mqtt_connect/messages/thing/product/{hms_events_message.rb → events/hms.rb} +0 -0
  55. /data/lib/dji_mqtt_connect/messages/thing/product/{status_code_events_message.rb → events/status_code.rb} +0 -0
  56. /data/lib/dji_mqtt_connect/messages/thing/product/{dock_osd_message.rb → osd/dock.rb} +0 -0
  57. /data/lib/dji_mqtt_connect/messages/thing/product/{drone_osd_message.rb → osd/drone.rb} +0 -0
  58. /data/lib/dji_mqtt_connect/messages/thing/product/{remote_osd_message.rb → osd/remote.rb} +0 -0
  59. /data/lib/dji_mqtt_connect/messages/thing/product/{airport_bind_status_requests_message.rb → requests/airport_bind_status.rb} +0 -0
  60. /data/lib/dji_mqtt_connect/messages/thing/product/{airport_organization_bind_requests_message.rb → requests/airport_organization_bind.rb} +0 -0
  61. /data/lib/dji_mqtt_connect/messages/thing/product/{airport_organization_get_requests_message.rb → requests/airport_organization_get.rb} +0 -0
  62. /data/lib/dji_mqtt_connect/messages/thing/product/{config_requests_message.rb → requests/config.rb} +0 -0
  63. /data/lib/dji_mqtt_connect/messages/thing/product/{storage_config_get_requests_message.rb → requests/storage_config_get.rb} +0 -0
  64. /data/lib/dji_mqtt_connect/messages/thing/product/{airport_bind_status_requests_reply_message.rb → requests_reply/airport_bind_status.rb} +0 -0
  65. /data/lib/dji_mqtt_connect/messages/thing/product/{airport_organization_bind_requests_reply_message.rb → requests_reply/airport_organization_bind.rb} +0 -0
  66. /data/lib/dji_mqtt_connect/messages/thing/product/{airport_organization_get_requests_reply_message.rb → requests_reply/airport_organization_get.rb} +0 -0
  67. /data/lib/dji_mqtt_connect/messages/thing/product/{config_requests_reply_message.rb → requests_reply/config.rb} +0 -0
  68. /data/lib/dji_mqtt_connect/messages/thing/product/{storage_config_get_requests_reply_message.rb → requests_reply/storage_config_get.rb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b9a7cb30f8a2cdf1f9b5d0648f1bd1175905abb81d1ab7730216d703a7e3224
4
- data.tar.gz: '0338037ac0061b0885333b5664b80e4ad6c901d832e9fb24a8879c385553207c'
3
+ metadata.gz: bce94ddd2e510ce30f293372def6fbfd54916a2bfcd18968ebd99b5d017b4aed
4
+ data.tar.gz: 9377ad974ca8a62082e28e72b1f2b00fe598ddeaa1ad5f16ebbf6371d5546412
5
5
  SHA512:
6
- metadata.gz: e15ece0befefe9c5d60946d51083813f94cba248d6704f6dbb495cc634d5c1c514fe5670e3c9be4bc1fdfd8ad5c51ab5b39d0cf399e7c502ce496849e6bc8b5f
7
- data.tar.gz: 8d659ae8e15bfd49da81adfde6837ac6ca2028d69a2860c6f25834f3c3b443112b73b7f81a752a3adbfdc5f6617d390c779f7292503cc9d20487706628d5a82d
6
+ metadata.gz: f0a86b3fe0a3be72cf761c40e23ac869a65a177431699389daf8c2282d9136b443bc19e35650ab701c6b4261ddccbcb2ff53f2bf653b76e07e62dc8a82168495
7
+ data.tar.gz: 0a6cd2977635c78779d9be386f82d9fb68e26e9fc30a230a314129589bfeb9342ecb59328a6291c5765ce4ea71a63bc1e68119ed3c0db2257afa54b21c85f480
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dji_mqtt_connect (0.1.12.1)
4
+ dji_mqtt_connect (0.1.13)
5
5
  activesupport (>= 6.0, <= 8)
6
6
  dry-struct (~> 1.6)
7
7
  dry-transformer (~> 1.0)
@@ -71,6 +71,11 @@ module DjiMqttConnect
71
71
  Thing::Product::ServicesTopicRepository.new(self)
72
72
  end
73
73
 
74
+ # Handles topic thing/product/#{pid}/services_reply
75
+ def thing_product_services_reply_topic
76
+ Thing::Product::ServicesReplyTopicRepository.new(self)
77
+ end
78
+
74
79
  attr_reader :mqtt_client
75
80
  end
76
81
  end
@@ -6,6 +6,24 @@ module DjiMqttConnect
6
6
  module Factories
7
7
  # Events
8
8
 
9
+ def build_device_exit_homing_notify_events_message
10
+ message_data = {
11
+ action: 1,
12
+ sn: "DOCK01",
13
+ reason: "0"
14
+ }
15
+ Thing::Product::DeviceExitHomingNotifyEventsMessage.new(
16
+ _method: "device_exit_homing_notify",
17
+ bid: Message.generate_bid,
18
+ tid: Message.generate_tid,
19
+ need_reply: 1,
20
+ gateway: "GATEWAY01",
21
+ timestamp: Message.current_timestamp,
22
+ data: message_data,
23
+ _data: message_data
24
+ )
25
+ end
26
+
9
27
  def build_file_upload_callback_events_message
10
28
  message_data = {
11
29
  file: {
@@ -98,6 +116,63 @@ module DjiMqttConnect
98
116
  )
99
117
  end
100
118
 
119
+ def build_flighttask_progress_events_message
120
+ message_data = {
121
+ output: {
122
+ ext: {
123
+ current_waypoint_index: 3,
124
+ media_count: 6,
125
+ track_id: "track_id",
126
+ flight_id: "flight_id",
127
+ break_point: {
128
+ index: 1,
129
+ state: 0,
130
+ progress: 0.34,
131
+ wayline_id: 0,
132
+ break_reason: 1,
133
+ latitude: 23.4,
134
+ longitude: 113.99,
135
+ height: 100.23,
136
+ attitude_head: 30
137
+ }
138
+ },
139
+ progress: {
140
+ current_step: 19,
141
+ percent: 100
142
+ },
143
+ status: "ok"
144
+ },
145
+ result: 0
146
+ }
147
+
148
+ Thing::Product::FlighttaskProgressEventsMessage.new(
149
+ bid: Message.generate_bid,
150
+ tid: Message.generate_tid,
151
+ data: message_data,
152
+ _data: message_data,
153
+ _method: "flighttask_progress",
154
+ timestamp: Message.current_timestamp
155
+ )
156
+ end
157
+
158
+ def build_flighttask_ready_events_message
159
+ message_data = {
160
+ flight_ids: [
161
+ SecureRandom.uuid,
162
+ SecureRandom.uuid
163
+ ]
164
+ }
165
+
166
+ Thing::Product::FlighttaskReadyEventsMessage.new(
167
+ bid: Message.generate_bid,
168
+ tid: Message.generate_tid,
169
+ data: message_data,
170
+ _data: message_data,
171
+ _method: "flighttask_ready",
172
+ timestamp: Message.current_timestamp
173
+ )
174
+ end
175
+
101
176
  def build_highest_priority_upload_flighttask_media_events_message
102
177
  message_data = {
103
178
  flight_id: SecureRandom.uuid
@@ -302,6 +377,33 @@ module DjiMqttConnect
302
377
  )
303
378
  end
304
379
 
380
+ def build_thing_product_flighttask_resource_get_requests_message
381
+ message_data = {
382
+ flight_id: SecureRandom.uuid
383
+ }
384
+
385
+ Thing::Product::FlighttaskResourceGetRequestsMessage.new(
386
+ tid: Message.generate_tid,
387
+ bid: Message.generate_bid,
388
+ timestamp: Message.current_timestamp,
389
+ _method: "flighttask_resource_get",
390
+ data: message_data,
391
+ _data: message_data
392
+ )
393
+ end
394
+
395
+ def build_thing_product_flighttask_resource_get_requests_reply_message
396
+ flighttask_resource_get_request = build_thing_product_flighttask_resource_get_requests_message
397
+ Thing::Product::FlighttaskResourceGetRequestsReplyMessage.build_for(
398
+ flighttask_resource_get_request,
399
+ result: 0,
400
+ file: {
401
+ fingerprint: "signxxxx",
402
+ url: "https://xx.oss-cn-hangzhou.aliyuncs.com/xx.kmz?Expires=xx&OSSAccessKeyId=xxx&Signature=xxx"
403
+ }
404
+ )
405
+ end
406
+
305
407
  def build_thing_product_storage_config_get_requests_message
306
408
  message_data = {
307
409
  module: 0
@@ -341,6 +443,10 @@ module DjiMqttConnect
341
443
 
342
444
  # Services
343
445
 
446
+ def build_thing_product_alarm_state_switch_services_message
447
+ Thing::Product::AlarmStateSwitchServicesMessage.build(action: Thing::Product::AlarmStateSwitchServicesMessage::ACTION_OPEN)
448
+ end
449
+
344
450
  def build_thing_product_cover_close_services_message
345
451
  Thing::Product::CoverCloseServicesMessage.build
346
452
  end
@@ -349,6 +455,14 @@ module DjiMqttConnect
349
455
  Thing::Product::CoverOpenServicesMessage.build
350
456
  end
351
457
 
458
+ def build_thing_product_debug_mode_close_services_message
459
+ Thing::Product::DebugModeCloseServicesMessage.build
460
+ end
461
+
462
+ def build_thing_product_debug_mode_open_services_message
463
+ Thing::Product::DebugModeOpenServicesMessage.build
464
+ end
465
+
352
466
  def build_thing_product_fileupload_list_services_message
353
467
  Thing::Product::FileuploadListServicesMessage.build(
354
468
  module_list: [0, 3]
@@ -394,5 +508,247 @@ module DjiMqttConnect
394
508
  }
395
509
  )
396
510
  end
511
+
512
+ def build_thing_product_flighttask_execute_services_message
513
+ Thing::Product::FlighttaskExecuteServicesMessage.build(flight_id: SecureRandom.uuid)
514
+ end
515
+
516
+ def build_thing_product_flighttask_pause_services_message
517
+ Thing::Product::FlighttaskPauseServicesMessage.build
518
+ end
519
+
520
+ def build_thing_product_flighttask_prepare_services_message
521
+ Thing::Product::FlighttaskPrepareServicesMessage.build(
522
+ data: {
523
+ execute_time: 1234567890123,
524
+ flight_id: "xxxxxxx",
525
+ task_type: 2,
526
+ wayline_type: 0,
527
+ file: {
528
+ url: "https://xxx.com/xxxx",
529
+ fingerprint: "xxxx"
530
+ },
531
+ ready_conditions: {
532
+ battery_capacity: 90,
533
+ begin_time: 1234567890123,
534
+ end_time: 1234567890123
535
+ },
536
+ executable_conditions: {
537
+ storage_capacity: 1000
538
+ },
539
+ break_point: {
540
+ index: 1,
541
+ state: 0,
542
+ progress: 0.34,
543
+ wayline_id: 0
544
+ },
545
+ rth_altitude: 100,
546
+ out_of_control_action: 0,
547
+ exit_wayline_when_rc_lost: 0
548
+ }
549
+ )
550
+ end
551
+
552
+ def build_thing_product_flighttask_recovery_services_message
553
+ Thing::Product::FlighttaskRecoveryServicesMessage.build
554
+ end
555
+
556
+ def build_thing_product_flighttask_undo_services_message
557
+ Thing::Product::FlighttaskUndoServicesMessage.build(
558
+ flight_ids: [SecureRandom.uuid, SecureRandom.uuid]
559
+ )
560
+ end
561
+
562
+ def build_thing_product_return_home_services_message
563
+ Thing::Product::ReturnHomeServicesMessage.build
564
+ end
565
+
566
+ def build_thing_product_return_home_cancel_services_message
567
+ Thing::Product::ReturnHomeCancelServicesMessage.build
568
+ end
569
+
570
+ def build_thing_product_alarm_state_switch_services_reply_message
571
+ message_data = {
572
+ result: 0,
573
+ output: {
574
+ status: "in_progress"
575
+ }
576
+ }
577
+
578
+ Thing::Product::AlarmStateSwitchServicesReplyMessage.new(
579
+ bid: Message.generate_bid,
580
+ tid: Message.generate_tid,
581
+ timestamp: Message.current_timestamp,
582
+ _method: "alarm_state_switch",
583
+ data: message_data,
584
+ _data: message_data
585
+ )
586
+ end
587
+
588
+ def build_thing_product_cover_close_services_reply_message
589
+ message_data = {
590
+ result: 0,
591
+ output: {
592
+ status: "in_progress"
593
+ }
594
+ }
595
+
596
+ Thing::Product::CoverCloseServicesReplyMessage.new(
597
+ bid: Message.generate_bid,
598
+ tid: Message.generate_tid,
599
+ timestamp: Message.current_timestamp,
600
+ _method: "cover_close",
601
+ data: message_data,
602
+ _data: message_data
603
+ )
604
+ end
605
+
606
+ def build_thing_product_cover_open_services_reply_message
607
+ message_data = {
608
+ result: 0,
609
+ output: {
610
+ status: "ok"
611
+ }
612
+ }
613
+
614
+ Thing::Product::CoverOpenServicesReplyMessage.new(
615
+ bid: Message.generate_bid,
616
+ tid: Message.generate_tid,
617
+ timestamp: Message.current_timestamp,
618
+ _method: "cover_open",
619
+ data: message_data,
620
+ _data: message_data
621
+ )
622
+ end
623
+
624
+ def build_thing_product_debug_mode_close_services_reply_message
625
+ message_data = {
626
+ result: 0,
627
+ output: {
628
+ status: "ok"
629
+ }
630
+ }
631
+
632
+ Thing::Product::DebugModeCloseServicesReplyMessage.new(
633
+ bid: Message.generate_bid,
634
+ tid: Message.generate_tid,
635
+ timestamp: Message.current_timestamp,
636
+ _method: "debug_mode_close",
637
+ data: message_data,
638
+ _data: message_data
639
+ )
640
+ end
641
+
642
+ def build_thing_product_debug_mode_open_services_reply_message
643
+ message_data = {
644
+ result: 0,
645
+ output: {
646
+ status: "in_progress"
647
+ }
648
+ }
649
+
650
+ Thing::Product::DebugModeOpenServicesReplyMessage.new(
651
+ bid: Message.generate_bid,
652
+ tid: Message.generate_tid,
653
+ timestamp: Message.current_timestamp,
654
+ _method: "debug_mode_open",
655
+ data: message_data,
656
+ _data: message_data
657
+ )
658
+ end
659
+
660
+ def build_thing_product_flighttask_prepare_services_reply_message
661
+ message_data = {result: 0}
662
+
663
+ Thing::Product::FlighttaskPrepareServicesReplyMessage.new(
664
+ bid: Message.generate_bid,
665
+ tid: Message.generate_tid,
666
+ timestamp: Message.current_timestamp,
667
+ _method: "flighttask_prepare",
668
+ _data: message_data,
669
+ data: message_data
670
+ )
671
+ end
672
+
673
+ def build_thing_product_flighttask_execute_services_reply_message
674
+ message_data = {result: 0}
675
+
676
+ Thing::Product::FlighttaskExecuteServicesReplyMessage.new(
677
+ bid: Message.generate_bid,
678
+ tid: Message.generate_tid,
679
+ timestamp: Message.current_timestamp,
680
+ _method: "flighttask_execute",
681
+ _data: message_data,
682
+ data: message_data
683
+ )
684
+ end
685
+
686
+ def build_thing_product_flighttask_undo_services_reply_message
687
+ message_data = {result: 0}
688
+
689
+ Thing::Product::FlighttaskUndoServicesReplyMessage.new(
690
+ bid: Message.generate_bid,
691
+ tid: Message.generate_tid,
692
+ timestamp: Message.current_timestamp,
693
+ _method: "flighttask_undo",
694
+ _data: message_data,
695
+ data: message_data
696
+ )
697
+ end
698
+
699
+ def build_thing_product_flighttask_pause_services_reply_message
700
+ message_data = {result: 0}
701
+
702
+ Thing::Product::FlighttaskPauseServicesReplyMessage.new(
703
+ bid: Message.generate_bid,
704
+ tid: Message.generate_tid,
705
+ timestamp: Message.current_timestamp,
706
+ _method: "flighttask_pause",
707
+ _data: message_data,
708
+ data: message_data
709
+ )
710
+ end
711
+
712
+ def build_thing_product_flighttask_recovery_services_reply_message
713
+ message_data = {result: 0}
714
+
715
+ Thing::Product::FlighttaskRecoveryServicesReplyMessage.new(
716
+ bid: Message.generate_bid,
717
+ tid: Message.generate_tid,
718
+ timestamp: Message.current_timestamp,
719
+ _method: "flighttask_recovery",
720
+ _data: message_data,
721
+ data: message_data
722
+ )
723
+ end
724
+
725
+ def build_thing_product_return_home_services_reply_message
726
+ message_data = {
727
+ result: 0,
728
+ output: {status: "ok"}
729
+ }
730
+
731
+ Thing::Product::ReturnHomeServicesReplyMessage.new(
732
+ bid: Message.generate_bid,
733
+ tid: Message.generate_tid,
734
+ timestamp: Message.current_timestamp,
735
+ _method: "return_home",
736
+ _data: message_data,
737
+ data: message_data
738
+ )
739
+ end
740
+
741
+ def build_thing_product_return_home_cancel_services_reply_message
742
+ message_data = {result: 0}
743
+
744
+ Thing::Product::ReturnHomeCancelServicesReplyMessage.new(
745
+ bid: Message.generate_bid,
746
+ tid: Message.generate_tid,
747
+ timestamp: Message.current_timestamp,
748
+ _method: "return_home_cancel",
749
+ _data: message_data,
750
+ data: message_data
751
+ )
752
+ end
397
753
  end
398
754
  end
@@ -0,0 +1,47 @@
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 ServicesReplyMarshal < 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
+ copy_keys "data" => "_data"
18
+ rename_keys "method" => "_method"
19
+ end
20
+ end
21
+
22
+ # Attempts to look a the method attribute, and builds a specific Message class for the message
23
+ def load(raw_message)
24
+ # Parse the message from JSON
25
+ parsed_message = JSON.parse(raw_message)
26
+
27
+ # Transform the message
28
+ transformed_message = attribute_transformer.call(parsed_message)
29
+ message_method = transformed_message["_method"]
30
+
31
+ # Build an instance of the class, or a generic message from the current class
32
+ message_class = message_class_from_message_method(message_method, ServicesReplyMessage)
33
+ message_class.new transformed_message
34
+ rescue JSON::ParserError => e
35
+ raise ParseError.new(e, "Unable to parse message as JSON")
36
+ rescue Dry::Struct::Error => e
37
+ raise ParseError.new(e, "Unexpected #{message_class} payload")
38
+ end
39
+
40
+ private
41
+
42
+ def attribute_transformer
43
+ @attribute_transformer ||= AttributeTransformer.new
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DjiMqttConnect
4
+ module Thing::Product
5
+ class CoverCloseEventsMessage < EventsMessage
6
+ attribute :_method, Types::String.enum("cover_close")
7
+
8
+ attribute :data do
9
+ attribute :result, Types::Integer
10
+
11
+ attribute :output do
12
+ # {"sent":"sent","in_progress":"in progress","ok":"success","paused":"paused","rejected":"rejected","failed":"failed","canceled":"canceled or stopped","timeout":"timeout"}
13
+ attribute :status, Types::String.enum(
14
+ "sent",
15
+ "in_progress",
16
+ "ok",
17
+ "paused",
18
+ "rejected",
19
+ "failed",
20
+ "canceled",
21
+ "timeout"
22
+ )
23
+
24
+ attribute :progress do
25
+ # {"min":"0","max":"100","step":"1"}
26
+ attribute :percent, Types::Integer.constrained(gteq: 0, lteq: 100)
27
+
28
+ attribute? :current_step, Types::Integer
29
+
30
+ attribute? :total_steps, Types::Integer
31
+
32
+ # {"get_bid":"Get bid","check_work_mode":"Check whether to enter remote debugging mode","check_task_state":"Check if the DJI Dock is free","land_mcu_reboot":"Land MCU reboot","rain_mcu_reboot":"Weather station MCU reboot","core_mcu_reboot":"Central control MCU reboot","sdr_reboot":"SDR reboot","write_reboot_param_file":"Write reboot flag","get_drone_power_state":"Get battery charge state","close_putter":"Close the putter","check_wired_connect_state":"Get aircraft state","open_drone":"Open the plane","open_alarm":"Open sound and light alarm","check_scram_state":"Check if the emergency stop switch is pressed","open_cover":"Open the hatch","check_drone_sdr_connect_state":"Establish SDR wireless connection","turn_on_drone":"Turn the plane on","drone_paddle_forward":"Turn on forward paddle","close_cover":"Close the hatch","drone_paddle_reverse":"Turn on reverse paddle","drone_paddle_stop":"Stop Paddle Rotation","free_putter":"Free Putter","stop_charge":"Stop charging"}
33
+ attribute? :step_key, Types::String.enum(
34
+ "get_bid",
35
+ "check_work_mode",
36
+ "check_task_state",
37
+ "land_mcu_reboot",
38
+ "rain_mcu_reboot",
39
+ "core_mcu_reboot",
40
+ "sdr_reboot",
41
+ "write_reboot_param_file",
42
+ "get_drone_power_state",
43
+ "close_putter",
44
+ "check_wired_connect_state",
45
+ "open_drone",
46
+ "open_alarm",
47
+ "check_scram_state",
48
+ "open_cover",
49
+ "check_drone_sdr_connect_state",
50
+ "turn_on_drone",
51
+ "drone_paddle_forward",
52
+ "close_cover",
53
+ "drone_paddle_reverse",
54
+ "drone_paddle_stop",
55
+ "free_putter",
56
+ "stop_charge"
57
+ )
58
+
59
+ attribute? :step_result, Types::Integer
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DjiMqttConnect
4
+ module Thing::Product
5
+ class CoverOpenEventsMessage < EventsMessage
6
+ attribute :_method, Types::String.enum("cover_open")
7
+
8
+ attribute :data do
9
+ attribute :result, Types::Integer
10
+
11
+ attribute :output do
12
+ # {"sent":"sent","in_progress":"in progress","ok":"success","paused":"paused","rejected":"rejected","failed":"failed","canceled":"canceled or stopped","timeout":"timeout"}
13
+ attribute :status, Types::String.enum(
14
+ "sent",
15
+ "in_progress",
16
+ "ok",
17
+ "paused",
18
+ "rejected",
19
+ "failed",
20
+ "canceled",
21
+ "timeout"
22
+ )
23
+
24
+ attribute :progress do
25
+ # {"min":"0","max":"100","step":"1"}
26
+ attribute :percent, Types::Integer.constrained(gteq: 0, lteq: 100)
27
+
28
+ attribute? :current_step, Types::Integer
29
+
30
+ attribute? :total_steps, Types::Integer
31
+
32
+ # {"get_bid":"Get bid","check_work_mode":"Check whether to enter remote debugging mode","check_task_state":"Check if the DJI Dock is free","land_mcu_reboot":"Land MCU reboot","rain_mcu_reboot":"Weather station MCU reboot","core_mcu_reboot":"Central control MCU reboot","sdr_reboot":"SDR reboot","write_reboot_param_file":"Write reboot flag","get_drone_power_state":"Get battery charge state","close_putter":"Close the putter","check_wired_connect_state":"Get aircraft state","open_drone":"Open the plane","open_alarm":"Open sound and light alarm","check_scram_state":"Check if the emergency stop switch is pressed","open_cover":"Open the hatch","check_drone_sdr_connect_state":"Establish SDR wireless connection","turn_on_drone":"Turn the plane on","drone_paddle_forward":"Turn on forward paddle","close_cover":"Close the hatch","drone_paddle_reverse":"Turn on reverse paddle","drone_paddle_stop":"Stop Paddle Rotation","free_putter":"Free Putter","stop_charge":"Stop charging"}
33
+ attribute? :step_key, Types::String.enum(
34
+ "get_bid",
35
+ "check_work_mode",
36
+ "check_task_state",
37
+ "land_mcu_reboot",
38
+ "rain_mcu_reboot",
39
+ "core_mcu_reboot",
40
+ "sdr_reboot",
41
+ "write_reboot_param_file",
42
+ "get_drone_power_state",
43
+ "close_putter",
44
+ "check_wired_connect_state",
45
+ "open_drone",
46
+ "open_alarm",
47
+ "check_scram_state",
48
+ "open_cover",
49
+ "check_drone_sdr_connect_state",
50
+ "turn_on_drone",
51
+ "drone_paddle_forward",
52
+ "close_cover",
53
+ "drone_paddle_reverse",
54
+ "drone_paddle_stop",
55
+ "free_putter",
56
+ "stop_charge"
57
+ )
58
+
59
+ attribute? :step_result, Types::Integer
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DjiMqttConnect
4
+ module Thing::Product
5
+ # Notification of device exits the Return to Home (RTH) state
6
+ # https://developer.dji.com/doc/cloud-api-tutorial/en/server-api-reference/mqtt/thing-model/gateway/dock/wayline.html#notification-of-device-exits-the-return-to-home-rth-state
7
+ class DeviceExitHomingNotifyEventsMessage < EventsMessage
8
+ ENTERING_EXIT_RTH_STATE_ACTION = 1
9
+ EXIT_EXITING_RTH_STATE_ACTION = 0
10
+
11
+ attribute :_method, Types::String.enum("device_exit_homing_notify")
12
+
13
+ attribute :data do
14
+ # {"1":"Enter exiting RTH state"},{"0":"Exit exiting RTH state"}
15
+ attribute :action, Types::Coercible::Integer.enum(EXIT_EXITING_RTH_STATE_ACTION, ENTERING_EXIT_RTH_STATE_ACTION)
16
+
17
+ attribute :sn, Types::SerialNumber
18
+
19
+ # {"0":"Add joystick throttle","1":"Add joystick pitch","2":"The initialization of behavior tree is failed","3":"Surrounded by obstacles","4":"Flight restriction is triggered","5":"Obstacle is too closed","6":"No GPS signal","7":"The output flag of GPS and VIO location is false","8":"The error of GPS and VIO fusion position is too large","9":"Backtrack in a short distance","10":"Trigger the RTH in a short distance"}
20
+ attribute :reason, Types::Coercible::Integer.enum(
21
+ ADD_JOYSTICK_THROTTLE_REASON = 0,
22
+ ADD_JOYSTICK_PITCH_REASON = 1,
23
+ THE_INITIALIZATION_OF_BEHAVIOR_TREE_IS_FAILED_REASON = 2,
24
+ SURROUNDED_BY_OBSTACLES_REASON = 3,
25
+ FLIGHT_RESTRICTION_IS_TRIGGERED_REASON = 4,
26
+ OBSTACLE_IS_TOO_CLOSE_REASON = 5,
27
+ NO_GPS_SIGNAL_REASON = 6,
28
+ THE_OUTPUT_FLAG_OF_GPS_AND_VIO_LOCATION_IS_FALSE_REASON = 7,
29
+ THE_ERROR_OF_GPS_AND_VIO_FUSION_POSITION_IS_TOO_LARGE_REASON = 8,
30
+ BACKTRACK_IN_A_SHORT_DISTANCE_REASON = 9,
31
+ TRIGGER_THE_RTH_IN_A_SHORT_DISTANCE_REASON = 10
32
+ )
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DjiMqttConnect
4
+ module Thing::Product
5
+ class DeviceLogEventsMessage < ServicesReplyMessage
6
+ # BID is not always included in message
7
+ attribute? :bid, Types::UUID
8
+
9
+ attribute :_method, Types::String.enum("device_log")
10
+
11
+ attribute :data do
12
+ attribute :level, Types::Integer
13
+ attribute :key, Types::Integer
14
+ attribute :module, Types::Integer
15
+ attribute :create_time, Types::Timestamp
16
+ attribute :args, Types::Hash
17
+ end
18
+ end
19
+ end
20
+ end
@@ -5,9 +5,6 @@ module DjiMqttConnect
5
5
  class FileUploadCallbackEventsMessage < EventsMessage
6
6
  attribute :_method, Types::String.enum("file_upload_callback")
7
7
 
8
- # NOTE: Not documented, but appears in examples
9
- attribute? :need_reply, Types::Integer.enum(0, 1)
10
-
11
8
  attribute :data do
12
9
  attribute :file do
13
10
  attribute :object_key, Types::String
@@ -51,10 +48,6 @@ module DjiMqttConnect
51
48
 
52
49
  attribute :result, Types::Integer
53
50
  end
54
-
55
- def need_reply?
56
- need_reply == 1
57
- end
58
51
  end
59
52
  end
60
53
  end