# frozen_string_literal: true module DjiMqttConnect # Factories for building example messages # Do not include this in your production code module Factories # Events def build_file_upload_callback_events_message message_data = { file: { object_key: "object_key", path: "xxx", name: "dog.jpeg", ext: { flight_id: "xxx", drone_model_key: "0-67-0", payload_model_key: "0-67-0", is_original: true }, metadata: { shoot_position: { lat: 22.1, lng: 122.5 }, gimbal_yaw_degree: -91.4, absolute_altitude: 56.311, relative_altitude: 41.124, created_time: "2021-05-10 16:04:20" } }, result: 0 } Thing::Product::FileUploadCallbackEventsMessage.new( _method: "file_upload_callback", bid: Message.generate_bid, tid: Message.generate_tid, need_reply: 1, gateway: "xxx", timestamp: Message.current_timestamp, data: message_data, _data: message_data ) end def build_fileupload_progress_events_message message_data = { output: { ext: { files: [ { module: "0", size: 155232, device_sn: "drone_sn", key: "4bf0039f-6434-44a8-b891-8d7b6b7ff138/drone_sn/video_20220621_110830.log", fingerprint: "4f65b891f3bc09bdb6d4c36a996b532d", progress: { current_step: 19, progress: 100, finish_time: 1655781395926, upload_rate: 0, result: 0, status: "ok" } }, { module: "3", size: 155232, device_sn: "dock_sn", key: "4bf0039f-6434-44a8-b891-8d7b6b7ff138/dock_sn/video_20220621_110830.log", fingerprint: "4f65b891f3bc09bdb6d4c36a996b532d", progress: { current_step: 19, total_step: 30, progress: 100, finish_time: 1655781395926, upload_rate: 0, result: 0, status: "ok" } } ] }, status: "ok" } } Thing::Product::FileuploadProgressEventsMessage.new( _method: "fileupload_progress", need_reply: 0, bid: Message.generate_bid, tid: Message.generate_tid, timestamp: Message.current_timestamp, gateway: "dock_sn", _data: message_data, data: message_data ) end def build_highest_priority_upload_flighttask_media_events_message message_data = { flight_id: SecureRandom.uuid } Thing::Product::HighestPriorityUploadFlighttaskMediaEventsMessage.new( bid: Message.generate_bid, _data: message_data, data: message_data, _method: "highest_priority_upload_flighttask_media", need_reply: 1, tid: Message.generate_tid, timestamp: Message.current_timestamp, gateway: "DOCK01" ) end # Status def build_device_online_update_topo_message message_data = { type: 98, sub_type: 0, device_secret: "secret", nonce: "nonce", version: 1, sub_devices: [ { sn: "drone001", type: 116, sub_type: 0, index: "A", device_secret: "secret", nonce: "nonce", version: 1 } ] } Sys::Product::UpdateTopoStatusMessage.new( _method: "update_topo", tid: Message.generate_tid, bid: Message.generate_bid, timestamp: Message.current_timestamp, data: message_data, _data: message_data.deep_stringify_keys ) end def build_update_topo_status_reply_message Sys::Product::UpdateTopoStatusReplyMessage.new( _method: "update_topo", tid: Message.generate_tid, bid: Message.generate_bid, timestamp: Message.current_timestamp, data: { result: 0 } ) end # Requests def build_thing_product_config_requests_message message_data = { config_type: "json", config_scope: "product" } Thing::Product::ConfigRequestsMessage.new( _method: "config", tid: Message.generate_tid, bid: Message.generate_bid, timestamp: Message.current_timestamp, gateway: "gatewaysn", data: message_data, _data: message_data.deep_stringify_keys ) end def build_thing_product_config_requests_reply_message request_message = build_thing_product_config_requests_message reply_data = { ntp_server_host: "http://time.google.com/", app_id: "123456", app_key: "app_key", app_license: "app_license" } Thing::Product::ConfigRequestsReplyMessage.build_for(request_message, data: reply_data) end def build_thing_product_airport_bind_status_requests_message message_data = { devices: [ { sn: "drone-sn" }, { sn: "dock-sn" } ] } Thing::Product::AirportBindStatusRequestsMessage.new( _method: "airport_bind_status", _data: message_data, tid: Message.generate_tid, bid: Message.generate_bid, timestamp: Message.current_timestamp, data: message_data ) end def build_thing_product_airport_bind_status_requests_reply_message airport_bind_status_request = build_thing_product_airport_bind_status_requests_message Thing::Product::AirportBindStatusRequestsReplyMessage.build_for( airport_bind_status_request, result: 0, bind_status: airport_bind_status_request.data.devices.map.with_index do |device, index| { sn: device.sn, is_device_bind_organization: (index % 2).zero?, organization_id: "12345678", organization_name: "12345", device_callsign: "Device organization callsign" } end ) end def build_thing_product_airport_organization_bind_requests_message message_data = { bind_devices: [ { device_binding_code: "", organization_id: "curo", device_callsign: "", sn: "DOCK01", device_secret: "DEVICE_SECRET", device_nonce: "DEVICE_NONCE", device_model_key: "3-1-0" }, { device_binding_code: "", organization_id: "curo", device_callsign: "", sn: "M30DRONE01", device_secret: "DEVICE_SECRET", device_nonce: "DEVICE_NONCE", device_model_key: "0-67-0" } ] } Thing::Product::AirportOrganizationBindRequestsMessage.new( _method: "airport_organization_bind", _data: message_data, tid: Message.generate_tid, bid: Message.generate_bid, timestamp: Message.current_timestamp, data: message_data, gateway: "DOCK01" ) end def build_thing_product_airport_organization_bind_requests_reply_message airport_organization_bind_request = build_thing_product_airport_organization_bind_requests_message Thing::Product::AirportOrganizationBindRequestsReplyMessage.build_for( airport_organization_bind_request, result: 0 ) end def build_thing_product_airport_organization_get_requests_message message_data = { device_binding_code: "device_binding_code", organization_id: "organization_id" } Thing::Product::AirportOrganizationGetRequestsMessage.new( _method: "airport_organization_get", _data: message_data, tid: Message.generate_tid, bid: Message.generate_bid, timestamp: Message.current_timestamp, data: message_data ) end def build_thing_product_airport_organization_get_requests_reply_message airport_organization_get_request = build_thing_product_airport_organization_get_requests_message Thing::Product::AirportOrganizationGetRequestsReplyMessage.build_for( airport_organization_get_request, result: 0, output: { organization_name: "12345" } ) end def build_thing_product_storage_config_get_requests_message message_data = { module: 0 } Thing::Product::StorageConfigGetRequestsMessage.new( _method: "storage_config_get", _data: message_data, tid: Message.generate_tid, bid: Message.generate_bid, timestamp: Message.current_timestamp, data: message_data ) end def build_thing_product_storage_config_get_requests_reply_message storage_config_get_request = build_thing_product_storage_config_get_requests_message Thing::Product::StorageConfigGetRequestsReplyMessage.build_for( storage_config_get_request, result: 0, output: { bucket: "bucket_name", credentials: { access_key_id: "access_key_id", access_key_secret: "access_key_secret", expire: 3600, security_token: "security_token" }, endpoint: "https://oss-cn-hangzhou.aliyuncs.com", object_key_prefix: "b4cfaae6-bd9d-4cd0-8472-63b608c3c581", provider: "ali", region: "hz" } ) end # Services def build_thing_product_cover_close_services_message Thing::Product::CoverCloseServicesMessage.build end def build_thing_product_cover_open_services_message Thing::Product::CoverOpenServicesMessage.build end def build_thing_product_fileupload_list_services_message Thing::Product::FileuploadListServicesMessage.build( module_list: [0, 3] ) end def build_thing_product_fileupload_start_services_message timestamp = Message.current_timestamp Thing::Product::FileuploadStartServicesMessage.build( data: { bucket: "stg-dji-service-hz-ksd7", region: "hz", credentials: { access_key_id: "STS.access_key_id", access_key_secret: "access_key_secret", expire: 3600, security_token: "security_token" }, endpoint: "https://oss-cn-hangzhou.aliyuncs.com", params: { files: [ { list: [ { boot_index: 1111, end_time: timestamp - 3000, size: 33789, start_time: timestamp - 4000 }, { boot_index: 22222, end_time: timestamp - 1000, size: 33789, start_time: timestamp - 2000 } ], module: "3", object_key: "object_key" } ] }, provider: "ali" } ) end end end