Skip to content

Commit

Permalink
Merge pull request #704 from victrox-dev/master
Browse files Browse the repository at this point in the history
AH-64D IFF and Cipher
  • Loading branch information
ciribob authored Apr 26, 2024
2 parents 0cccd59 + 7f9e321 commit 564d323
Showing 1 changed file with 84 additions and 131 deletions.
215 changes: 84 additions & 131 deletions Scripts/DCS-SRS/Scripts/DCS-SimpleRadioStandalone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -665,106 +665,21 @@ function SR.exportRadioSU27(_data)
return _data
end

local _ah64 = {}
_ah64.cipher = {
key = 1,
enabled = false
}


local _ah64Mode1Persist = -1 -- Need this persistence for only MODE1 because it's pulled from the XPNDR page; default it to off
function SR.exportRadioAH64D(_data)
_data.capabilities = { dcsPtt = true, dcsIFF = false, dcsRadioSwitch = true, intercomHotMic = true, desc = "Recommended: Always Allow SRS Hotkeys - OFF. Bind Intercom Select & PTT, Radio PTT and DCS RTS up down" }

-- 17 is the pilot (back seat)
-- 18 is the gunner (front seat)
-- Rts_FM1 is LEFT (single underscore) - current radio selected
-- Rts__FM1 is RIGHT (double underscore) - current radio selected in the OTHER seat (swaps if front or back)
-- we only care bout LEFT
-- { ["Net_FM1"] = ,
-- ["Net_Standby_FM2"] = ,
-- ["Frequency_Standby_VHF"] = 121.500,
-- ["Idm_FM2"] = ,
-- ["Idm_UHF"] = ,
-- ["Transponder_ID"] = XPNDR,
-- ["Net_VHF"] = ,
-- ["PowerStatus_FM1"] = NORM,
-- ["AdvisoryList_1"] = TAIL WHL LOCK SEL ,
-- ["Rts__FM1"] = =,
-- ["Idm_FM1"] = ],
-- ["Squelch_FM2"] = *,
-- ["Net_Standby_FM1"] = ,
-- ["Net_Standby_VHF"] = ,
-- ["Symbols_1"] = |,
-- ["RadioStats_HF"] = ,
-- ["Call_Standby_FM2"] = -----,
-- ["Idm_VHF"] = [,
-- ["Call_Standby_VHF"] = -----,
-- ["PowerStatus_HF"] = LOW,
-- ["Frequency_FM1"] = 30.000,
-- ["Symbols_5"] = |,
-- ["Arrows_3"] = |,
-- ["Symbols_10"] = |,
-- ["Rts_FM1_"] = =,
-- ["Symbols_6"] = |,
-- ["Radio_VHF"] = VHF,
-- ["Symbols_4"] = |,
-- ["Squelch_VHF"] = *,
-- ["Transponder_MODE_3A"] = 1200,
-- ["Rts__VHF"] = =,
-- ["Call_Standby_FM1"] = -----,
-- ["Call_UHF"] = -----,
-- ["Frequency_VHF"] = 121.000,
-- ["Radio_FM1"] = FM1,
-- ["background"] = ,
-- ["Frequency_Standby_UHF"] = 305.000,
-- ["Transponder_MC"] = NORM,
-- ["Call_VHF"] = -----,
-- ["Call_FM2"] = -----,
-- ["Net_UHF"] = ,
-- ["Arrows_4"] = |,
-- ["Symbols_7"] = |,
-- ["Frequency_HF"] = 2.0000A,
-- ["Watch_"] = 04:02:40 Z,
-- ["Frequency_Standby_FM1"] = 30.000,
-- ["Symbols_2"] = |,
-- ["Frequency_FM2"] = 30.000,
-- ["Rts__FM2"] = =,
-- ["XPNDR_MODE_S"] = S,
-- ["Call_FM1"] = -----,
-- ["Fuel_"] = 3140,
-- ["Fuel"] = FUEL,
-- ["XPNDR_MODE_4"] = A,
-- ["Call_Standby_HF"] = -----,
-- ["Symbols_3"] = |,
-- ["Call_Standby_UHF"] = -----,
-- ["Frequency_Standby_HF"] = 2.0000A,
-- ["Frequency_Standby_FM2"] = 30.000,
-- ["Idm_HF"] = ,
-- ["Net_FM2"] = ,
-- ["Rts__UHF"] = >,
-- ["Rts_HF_"] = =,
-- ["Guard"] = ,
-- ["Symbols_9"] = |,
-- ["Squelch_HF"] = *,
-- ["Radio_HF"] = HF ,
-- ["Arrows_1"] = |,
-- ["Squelch_UHF"] = *,
-- ["Squelch_FM1"] = *,
-- ["Radio_FM2"] = FM2,
-- ["Rts__HF"] = =,
-- ["Arrows_2"] = |,
-- ["Symbols_8"] = |,
-- ["Rts_VHF_"] = =,
-- ["Frequency_UHF"] = 305.000,
-- ["Call_HF"] = -----,
-- ["Rts_UHF_"] = =,
-- ["Rts_FM2_"] = <,
-- ["Radio_UHF"] = UHF,
-- ["Net_Standby_UHF"] = ,
-- }


_data.capabilities = { dcsPtt = true, dcsIFF = true, dcsRadioSwitch = true, intercomHotMic = true, desc = "Recommended: Always Allow SRS Hotkeys - OFF. Bind Intercom Select & PTT, Radio PTT and DCS RTS up down" }
_data.control = 1

local _iffSettings = {
status = 0,
mode1 = _ah64Mode1Persist,
mode2 = -1,
mode3 = -1,
mode4 = 0,
control = 0,
expansion = false
}

-- Check if player is in a new aircraft
if _lastUnitId ~= _data.unitId then
-- New aircraft; SENS volume is at 0
Expand Down Expand Up @@ -792,33 +707,39 @@ function SR.exportRadioAH64D(_data)
_data.radios[3].freq = SR.getRadioFrequency(57)
_data.radios[3].modulation = SR.getRadioModulation(57)
_data.radios[3].volMode = 0
_data.radios[3].encMode = 2

_data.radios[4].name = "FM1-ARC-201D"
_data.radios[4].freq = SR.getRadioFrequency(59)
_data.radios[4].modulation = SR.getRadioModulation(59)
_data.radios[4].volMode = 0
_data.radios[4].encKey = 1
_data.radios[4].encMode = 1 -- FC3 Gui Toggle + Gui Enc key setting
_data.radios[4].encMode = 2

_data.radios[5].name = "FM2-ARC-201D"
_data.radios[5].freq = SR.getRadioFrequency(60)
_data.radios[5].modulation = SR.getRadioModulation(60)
_data.radios[5].volMode = 0
_data.radios[5].encKey = 1
_data.radios[5].encMode = 1 -- FC3 Gui Toggle + Gui Enc key setting
_data.radios[5].encMode = 2

_data.radios[6].name = "HF-ARC-220"
_data.radios[6].freq = SR.getRadioFrequency(61)
_data.radios[6].modulation = 0
_data.radios[6].volMode = 0
_data.radios[6].encMode = 2 -- As of DCS ver 2.9.4.53627 the HF preset functionality is bugged, but I'll leave this here in hopes ED fixes the bug

local _radioPanel = nil
local _cipher = nil
local _seat = get_param_handle("SEAT"):get() -- PLT/CPG ?
local _eufdDevice = nil
local _mpdLeft = nil
local _mpdRight = nil
local _iffIdentBtn = nil
local _iffEmergency = nil

if SR.lastKnownSeat == 0 then

_radioPanel = SR.getListIndicatorValue(17)
_cipher = SR.getListIndicatorValue(6)
if _seat == 0 then
_eufdDevice = SR.getListIndicatorValue(17)
_mpdLeft = SR.getListIndicatorValue(6)
_mpdRight = SR.getListIndicatorValue(8)
_iffIdentBtn = SR.getButtonPosition(347) -- PLT comm panel ident button
_iffEmergency = GetDevice(0):get_argument_value(404) -- PLT Emergency Panel XPNDR Indicator

local _masterVolume = SR.getRadioVolume(0, 344, { 0.0, 1.0 }, false)

Expand Down Expand Up @@ -865,10 +786,13 @@ function SR.exportRadioAH64D(_data)
end

else
local _masterVolume = SR.getRadioVolume(0, 385, { 0.0, 1.0 }, false)
_cipher = SR.getListIndicatorValue(10)
_eufdDevice = SR.getListIndicatorValue(18)
_mpdLeft = SR.getListIndicatorValue(10)
_mpdRight = SR.getListIndicatorValue(12)
_iffIdentBtn = SR.getButtonPosition(388) -- CPG comm panel ident button
_iffEmergency = GetDevice(0):get_argument_value(428) -- CPG Emergency Panel XPNDR Indicator

_radioPanel = SR.getListIndicatorValue(18)
local _masterVolume = SR.getRadioVolume(0, 385, { 0.0, 1.0 }, false)

--intercom
_data.radios[1].volume = SR.getRadioVolume(0, 386, { 0.0, 1.0 }, false) * _masterVolume
Expand Down Expand Up @@ -914,45 +838,72 @@ function SR.exportRadioAH64D(_data)

end

if _radioPanel then
if _eufdDevice then
-- figure out selected
if _radioPanel['Rts_VHF_'] == '<' then
if _eufdDevice['Rts_VHF_'] == '<' then
_data.selected = 1
elseif _radioPanel['Rts_UHF_'] == '<' then
elseif _eufdDevice['Rts_UHF_'] == '<' then
_data.selected = 2
elseif _radioPanel['Rts_FM1_'] == '<' then
elseif _eufdDevice['Rts_FM1_'] == '<' then
_data.selected = 3
elseif _radioPanel['Rts_FM2_'] == '<' then
elseif _eufdDevice['Rts_FM2_'] == '<' then
_data.selected = 4
elseif _radioPanel['Rts_HF_'] == '<' then
elseif _eufdDevice['Rts_HF_'] == '<' then
_data.selected = 5
end

if _radioPanel['Guard'] == 'G' then
if _eufdDevice['Guard'] == 'G' then
_data.radios[3].secFreq = 243e6
end
end

if _cipher then
-- PLAIN, CIPHER , RECEIVE
if _cipher["PB7_17"] then
_ah64.cipher.enabled = _cipher["PB7_17"] == "CIPHER"
-- TODO??: Regarding IFF, I had not checked prior to @falcoger pointing it out... the Apache XPNDR
-- page only runs a simple logic check (#digits) to accept input for modes. I considered
-- scripting the logic on SRS' end to perform the check for validity, but without sufficient
-- means to provide user feedback regarding the validity, I opted to just let the user input
-- invalid codes since it seems (?) LotAtc doesn't perform a proper logic check either, just a
-- #digit check. Hopefully ED will someday emplace the logic check within the Apache.

if _eufdDevice["Transponder_MC"] == "NORM" then -- IFF NORM
_iffSettings.status = (_iffIdentBtn > 0) and 2 or 1 -- IDENT and Power

_iffSettings.mode3 = _eufdDevice["Transponder_MODE_3A"] and string.format("%04d", _eufdDevice["Transponder_MODE_3A"]) or -1

_iffSettings.mode4 = _eufdDevice["XPNDR_MODE_4"] and 1 or 0
else -- Transponder_MC == "STBY" or there's no power
_iffSettings.status = 0
end

-- KEY 1,2,3,4,5,6
if _cipher["PB8_21"] then
_ah64.cipher.key = tonumber(_cipher["PB8_21"])
if _iffEmergency == 1 then
_iffSettings.mode3 = 7700
_iffSettings.status = 1 -- XPNDR btn would actually turn on the XPNDR if it were in STBY (in real life)
end
_data.radios[3].encKey = _ah64.cipher.key
_data.radios[3].enc = _ah64.cipher.enabled

_data.radios[3].enc = _eufdDevice["Cipher_UHF"] and 1 or 0
_data.radios[3].encKey = _eufdDevice["Cipher_UHF"] and string.format("%01d", string.match(_eufdDevice["Cipher_UHF"], "%d+")) or 1

_data.radios[4].enc = _eufdDevice["Cipher_FM1"] and 1 or 0
_data.radios[4].encKey = _eufdDevice["Cipher_FM1"] and string.format("%01d", string.match(_eufdDevice["Cipher_FM1"], "%d+")) or 1

_data.radios[5].enc = _eufdDevice["Cipher_FM2"] and 1 or 0
_data.radios[5].encKey = _eufdDevice["Cipher_FM2"] and string.format("%01d", string.match(_eufdDevice["Cipher_FM2"], "%d+")) or 1

_data.radios[6].enc = _eufdDevice["Cipher_HF"] and 1 or 0
_data.radios[6].encKey = _eufdDevice["Cipher_HF"] and string.format("%01d", string.match(_eufdDevice["Cipher_HF"], "%d+"))
end

_data.control = 1
_data.radios[3].encMode = 2 -- Mode 2 is set by aircraft
if (_mpdLeft or _mpdRight) then
if _mpdLeft["Mode_S_Codes_Window_text_1"] then -- We're on the XPNDR page on the LEFT MPD
_ah64Mode1Persist = _mpdLeft["PB24_9"] == "}1" and -1 or string.format("%02d", _mpdLeft["PB7_23"])
end

if _mpdRight["Mode_S_Codes_Window_text_1"] then -- We're on the XPNDR page on the RIGHT MPD
_ah64Mode1Persist = _mpdRight["PB24_9"] == "}1" and -1 or string.format("%02d", _mpdRight["PB7_23"])
end
end

--CYCLIC_RTS_SW_LEFT 573 CPG 531 PLT
local _pttButtonId = 573
if SR.lastKnownSeat == 0 then
if _seat == 0 then
_pttButtonId = 531
end

Expand Down Expand Up @@ -993,6 +944,8 @@ function SR.exportRadioAH64D(_data)
_data.ambient = {vol = 0, abType = 'ah64' }
end

for k,v in pairs(_iffSettings) do _data.iff[k] = v end -- IFF table overwrite

return _data

end
Expand Down

0 comments on commit 564d323

Please sign in to comment.