# frozen_string_literal: true require "dry-types" module DjiMqttConnect # Types binding for dry-types module Types include Dry::Types() # DJI does not like null, so it returns Integer 0 instead of a Decimal... NullInteger = Types::Strict::Integer.constrained(eql: 0) # Negative values indicate a fault ErrorInteger = Types::Strict::Integer.constrained(lt: 0) # Not a Strict UUID format... turns out DJI doesn't follow one UUID = Strict::String.constrained(format: /\A[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\z/i) # Just make sure Timestamps are 13 digits long Timestamp = Types::Integer & Types::Coercible::String.constrained(format: /\A[1-9][0-9]{12}\z/) # Serial Numbers are alphanumeric with optional hyphen SerialNumber = Types::String.constrained(format: /\A[0-9A-Z]+(-[0-9A-Z]+)?\z/) # Flight ID is a string with at least 1 character FlightID = Types::String.constrained(min_size: 1) # lat/lng coordinates Latitude = NullInteger | Types::JSON::Decimal.constrained(gteq: -90, lteq: 90) Longitude = NullInteger | Types::JSON::Decimal.constrained(gteq: -180, lteq: 180) # Device Details AIRCRAFT_DOMAIN = 0 PAYLOAD_DOMAIN = 1 REMOTE_CONTROLLER_DOMAIN = 2 DOCK_DOMAIN = 3 DeviceDomain = Types::Coercible::Integer.enum(AIRCRAFT_DOMAIN, PAYLOAD_DOMAIN, REMOTE_CONTROLLER_DOMAIN, DOCK_DOMAIN) # dock returns this value as string DeviceType = Types::Integer DeviceSubType = Types::Integer InvalidTemperature = Types::Integer.constrained(gteq: 1300) # maximum temp of k-type thermocouple, errors are usually 30K+ Temperature = InvalidTemperature | Types::JSON::Decimal # {"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"} EventsProgressStepKey = Types::String.enum( "get_bid", "check_work_mode", "check_task_state", "land_mcu_reboot", "rain_mcu_reboot", "core_mcu_reboot", "sdr_reboot", "write_reboot_param_file", "get_drone_power_state", "close_putter", "check_wired_connect_state", "open_drone", "open_alarm", "check_scram_state", "open_cover", "check_drone_sdr_connect_state", "turn_on_drone", "drone_paddle_forward", "close_cover", "drone_paddle_reverse", "drone_paddle_stop", "free_putter", "stop_charge", "plc_check" ) # {"sent":"sent","in_progress":"in progress","ok":"success","paused":"paused","rejected":"rejected","failed":"failed","canceled":"canceled or stopped","timeout":"timeout"} ServicesOutputStatus = Types::String.enum( SERVICE_OUTPUT_STATUS_SENT = "sent", SERVICE_OUTPUT_STATUS_IN_PROGRESS = "in_progress", SERVICE_OUTPUT_STATUS_OK = "ok", SERVICE_OUTPUT_STATUS_PAUSED = "paused", SERVICE_OUTPUT_STATUS_REJECTED = "rejected", SERVICE_OUTPUT_STATUS_FAILED = "failed", SERVICE_OUTPUT_STATUS_CANCELED = "canceled", SERVICE_OUTPUT_STATUS_TIMEOUT = "timeout" ) # Video Quality # {"0":"Adaptive","1":"Smooth","2":"Standard definition","3":"High definition","4":"Ultra-high definition"} VideoQuality = Types::Integer.enum( VIDEO_QUALITY_ADAPTIVE = 0, VIDEO_QUALITY_SMOOTH = 1, VIDEO_QUALITY_STANDARD_DEFINITION = 2, VIDEO_QUALITY_HIGH_DEFINITION = 3, VIDEO_QUALITY_ULTRA_HIGH_DEFINITION = 4 ) # Video Type # {"ir":"Infrared","normal":"Default","wide":"Wide-angle","zoom":"Zoom"} VideoType = Types::String.enum( VIDEO_TYPE_INFRARED = "ir", VIDEO_TYPE_NORMAL = "normal", VIDEO_TYPE_WIDE_ANGLE = "wide", VIDEO_TYPE_ZOOM = "zoom" ) # Result for messages ResultCode = Types::Integer.constrained(gteq: 0) end end