dji_mqtt_connect 0.1.8 → 0.1.9
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/config/locales/dji_mqtt_connect.en.yml +2423 -0
- data/config/locales/dji_mqtt_connect.zh.yml +2026 -0
- data/lib/dji_mqtt_connect/messages/thing/product/hms_events_message.rb +27 -0
- data/lib/dji_mqtt_connect/railtie.rb +3 -0
- data/lib/dji_mqtt_connect/translations.rb +91 -0
- data/lib/dji_mqtt_connect/types.rb +6 -1
- data/lib/dji_mqtt_connect/version.rb +1 -1
- data/lib/dji_mqtt_connect.rb +1 -0
- metadata +5 -2
@@ -26,6 +26,33 @@ module DjiMqttConnect
|
|
26
26
|
|
27
27
|
attribute :sensor_index, Types::Integer
|
28
28
|
end
|
29
|
+
|
30
|
+
def in_the_sky?
|
31
|
+
in_the_sky == 1
|
32
|
+
end
|
33
|
+
|
34
|
+
def aircraft_message
|
35
|
+
if in_the_sky?
|
36
|
+
Translations.aircraft_in_the_sky_hms_event_code_message(
|
37
|
+
code: code,
|
38
|
+
sensor_index: args.sensor_index,
|
39
|
+
component_index: args.component_index
|
40
|
+
)
|
41
|
+
else
|
42
|
+
Translations.aircraft_hms_event_code_message(
|
43
|
+
code: code,
|
44
|
+
sensor_index: args.sensor_index,
|
45
|
+
component_index: args.component_index
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def dock_message
|
51
|
+
Translations.dock_hms_event_code_message(
|
52
|
+
code: code,
|
53
|
+
sensor_index: args.sensor_index
|
54
|
+
)
|
55
|
+
end
|
29
56
|
end
|
30
57
|
end
|
31
58
|
end
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module DjiMqttConnect
|
4
4
|
class Railtie < Rails::Railtie
|
5
|
+
# Add all error code translations to I18n
|
6
|
+
DjiMqttConnect::Translations.load_translations!
|
7
|
+
|
5
8
|
# Allow ActiveJob to serialize DjiMqttConnect::Message objects
|
6
9
|
config.active_job.custom_serializers << Railties::MessageSerializer
|
7
10
|
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DjiMqttConnect
|
4
|
+
# https://developer.dji.com/doc/cloud-api-tutorial/en/feature-set/dock-feature-set/hms.html
|
5
|
+
module Translations
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def load_translations!
|
9
|
+
I18n.load_path += Dir[File.expand_path(File.join(__dir__, "../../config/locales/*.yml"))]
|
10
|
+
end
|
11
|
+
|
12
|
+
def aircraft_in_the_sky_hms_event_code_message(code:, sensor_index:, component_index:)
|
13
|
+
I18n.translate(
|
14
|
+
"fpv_tip_#{code}_in_the_sky",
|
15
|
+
alarmid: code,
|
16
|
+
index: sensor_index + 1,
|
17
|
+
component_index: component_index + 1,
|
18
|
+
battery_index: battery_position(sensor_index),
|
19
|
+
scope: "dji_mqtt_connect.hms_event_codes",
|
20
|
+
default: code
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def aircraft_hms_event_code_message(code:, sensor_index:, component_index:)
|
25
|
+
I18n.translate(
|
26
|
+
"fpv_tip_#{code}",
|
27
|
+
alarmid: code,
|
28
|
+
index: sensor_index + 1,
|
29
|
+
component_index: component_index + 1,
|
30
|
+
battery_index: battery_position(sensor_index),
|
31
|
+
scope: "dji_mqtt_connect.hms_event_codes",
|
32
|
+
default: code
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def dock_hms_event_code_message(code:, sensor_index:)
|
37
|
+
I18n.translate(
|
38
|
+
"dock_tip_#{code}",
|
39
|
+
alarmid: code,
|
40
|
+
dock_cover_index: dock_cover_position(sensor_index),
|
41
|
+
charging_rod_index: dock_charging_rod_position(sensor_index),
|
42
|
+
scope: "dji_mqtt_connect.hms_event_codes",
|
43
|
+
default: code
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def position_name(position)
|
48
|
+
I18n.translate(position, scope: "dji_mqtt_connect.position", default: position)
|
49
|
+
end
|
50
|
+
|
51
|
+
# If the text contains "%battery_index" and sensor_index is 0, use "left" to replace "%battery_index", otherwise, use "right" to replace.
|
52
|
+
def battery_position(sensor_index)
|
53
|
+
case sensor_index
|
54
|
+
when 0
|
55
|
+
position_name("left")
|
56
|
+
when 1
|
57
|
+
position_name("right")
|
58
|
+
else
|
59
|
+
position_name("unknown")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# If the text contains "%dock_cover_index" and sensor_index is 0, use "left" to replace "%dock_cover_index", otherwise, use "right" to replace.
|
64
|
+
def dock_cover_position(sensor_index)
|
65
|
+
case sensor_index
|
66
|
+
when 0
|
67
|
+
position_name("left")
|
68
|
+
when 1
|
69
|
+
position_name("right")
|
70
|
+
else
|
71
|
+
position_name("unknown")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# If the text contains "%charging_rod_index", when sensor_index is 0, replace "%charging_rod_index" with "front". When sensor_index is 1, use "back" instead. When sensor_index is 2, use "left" instead. When sensor_index is 3, use "right" instead.
|
76
|
+
def dock_charging_rod_position(sensor_index)
|
77
|
+
case sensor_index
|
78
|
+
when 0
|
79
|
+
position_name("front")
|
80
|
+
when 1
|
81
|
+
position_name("back")
|
82
|
+
when 2
|
83
|
+
position_name("left")
|
84
|
+
when 3
|
85
|
+
position_name("right")
|
86
|
+
else
|
87
|
+
position_name("unknown")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -21,7 +21,12 @@ module DjiMqttConnect
|
|
21
21
|
Longitude = NullInteger | Types::JSON::Decimal.constrained(gteq: -180, lteq: 180)
|
22
22
|
|
23
23
|
# Device Details
|
24
|
-
|
24
|
+
AIRCRAFT_DOMAIN = 0
|
25
|
+
PAYLOAD_DOMAIN = 1
|
26
|
+
REMOTE_CONTROLLER_DOMAIN = 2
|
27
|
+
DOCK_DOMAIN = 3
|
28
|
+
|
29
|
+
DeviceDomain = Types::Coercible::Integer.enum(AIRCRAFT_DOMAIN, PAYLOAD_DOMAIN, REMOTE_CONTROLLER_DOMAIN, DOCK_DOMAIN) # dock returns this value as string
|
25
30
|
DeviceType = Types::Integer
|
26
31
|
DeviceSubType = Types::Integer
|
27
32
|
|
data/lib/dji_mqtt_connect.rb
CHANGED
@@ -11,6 +11,7 @@ module DjiMqttConnect
|
|
11
11
|
autoload :Message, "dji_mqtt_connect/message"
|
12
12
|
autoload :MessageMarshal, "dji_mqtt_connect/message_marshal"
|
13
13
|
autoload :TopicRepository, "dji_mqtt_connect/topic_repository"
|
14
|
+
autoload :Translations, "dji_mqtt_connect/translations"
|
14
15
|
autoload :Types, "dji_mqtt_connect/types"
|
15
16
|
|
16
17
|
module Sys
|
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.9
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -103,6 +103,8 @@ files:
|
|
103
103
|
- Gemfile.lock
|
104
104
|
- README.md
|
105
105
|
- Rakefile
|
106
|
+
- config/locales/dji_mqtt_connect.en.yml
|
107
|
+
- config/locales/dji_mqtt_connect.zh.yml
|
106
108
|
- dji_mqtt_connect.gemspec
|
107
109
|
- lib/dji_mqtt_connect.rb
|
108
110
|
- lib/dji_mqtt_connect/client.rb
|
@@ -150,6 +152,7 @@ files:
|
|
150
152
|
- lib/dji_mqtt_connect/topics/thing/product/osd.rb
|
151
153
|
- lib/dji_mqtt_connect/topics/thing/product/requests.rb
|
152
154
|
- lib/dji_mqtt_connect/topics/thing/product/requests_reply.rb
|
155
|
+
- lib/dji_mqtt_connect/translations.rb
|
153
156
|
- lib/dji_mqtt_connect/types.rb
|
154
157
|
- lib/dji_mqtt_connect/utils/message_parsing.rb
|
155
158
|
- lib/dji_mqtt_connect/utils/message_sanitizer.rb
|