mirror of
https://github.com/weyne85/DCS-ExportScripts.git
synced 2025-10-29 16:58:18 +00:00
added other aircraft luas
added as a 1-stop-shop
This commit is contained in:
43
lib/Maps.lua
Normal file
43
lib/Maps.lua
Normal file
@@ -0,0 +1,43 @@
|
||||
-- Ikarus and D.A.C. Export Script
|
||||
--
|
||||
-- Map Config File
|
||||
--
|
||||
-- Copyright by Michael aka McMicha 2014
|
||||
-- Contact dcs2arcaze.micha@farbpigmente.org
|
||||
--
|
||||
-- This file contains the data to identify the loaded map.
|
||||
--
|
||||
-- The data can be read in the editor.
|
||||
-- Load the corresponding map and read the latitude and longitude values and write specify the decimal degree format (convert from degrees, decimal to decimal degrees).
|
||||
-- Lat1 and Long1 contain the coordinates of the upper left corner.
|
||||
-- Lat2 and Long2 contain the coordinates of the lower right corner.
|
||||
--
|
||||
|
||||
ExportScript.Version.Maps = "1.2.1"
|
||||
|
||||
-- Maps
|
||||
ExportScript.Maps = {}
|
||||
-- Caucasus Map
|
||||
ExportScript.Maps.CaucasusBase = {}
|
||||
ExportScript.Maps.CaucasusBase.Lat1 = 48.384867 -- high left Latitude 48° 23. 92 N
|
||||
ExportScript.Maps.CaucasusBase.Long1 = 26.779467 -- high left Longitude 26° 46.768 E
|
||||
ExportScript.Maps.CaucasusBase.Lat2 = 38.865183 -- low right Latitude 38° 51.911 N
|
||||
ExportScript.Maps.CaucasusBase.Long2 = 47.14225 -- low right Longitude 47° 8.535 E
|
||||
-- Nevada (NTTR) Map
|
||||
ExportScript.Maps.Nevada = {} -- Nevada Map
|
||||
ExportScript.Maps.Nevada.Lat1 = 37.578333 -- high left Latitude 37° 34' 42" N
|
||||
ExportScript.Maps.Nevada.Long1 = -119.964722 -- high left Longitude 119° 57' 53" W
|
||||
ExportScript.Maps.Nevada.Lat2 = 34.651667 -- low right Latitude 34° 39' 06" N
|
||||
ExportScript.Maps.Nevada.Long2 = -114.536111 -- low right Longitude 114° 32' 10" W
|
||||
-- Normandy Map
|
||||
ExportScript.Maps.Normandy = {} -- Normandy Map
|
||||
ExportScript.Maps.Normandy.Lat1 = 53.85556 -- high left Latitude 53° 51' 20" N
|
||||
ExportScript.Maps.Normandy.Long1 = -15.02667 -- high left Longitude 15° 01' 36" W
|
||||
ExportScript.Maps.Normandy.Lat2 = 45.07167 -- low right Latitude 45° 04' 18" N
|
||||
ExportScript.Maps.Normandy.Long2 = 8.437222 -- low right Longitude 08° 26' 14" E
|
||||
-- Persian Gulf Map
|
||||
ExportScript.Maps.PersianGulf = {}
|
||||
ExportScript.Maps.PersianGulf.Lat1 = 30.50833 -- high left Latitude 30° 20.630 N
|
||||
ExportScript.Maps.PersianGulf.Long1 = 45.15167 -- high left Longitude 44° 54.906 E
|
||||
ExportScript.Maps.PersianGulf.Lat2 = 22.43528 -- low right Latitude 22° 24.127 N
|
||||
ExportScript.Maps.PersianGulf.Long2 = 61.67306 -- low right Longitude 61° 36.263 E
|
||||
992
lib/Tools.lua
Normal file
992
lib/Tools.lua
Normal file
@@ -0,0 +1,992 @@
|
||||
-- Ikarus and D.A.C. Export Script
|
||||
--
|
||||
-- Tools
|
||||
--
|
||||
-- Copyright by Michael aka McMicha 2014 - 2018
|
||||
-- Contact dcs2arcaze.micha@farbpigmente.org
|
||||
|
||||
ExportScript.Tools = {}
|
||||
ExportScript.Version.Tools = "1.2.1"
|
||||
|
||||
function ExportScript.Tools.WriteToLog(message)
|
||||
if ExportScript.logFile then
|
||||
local ltmp, lMiliseconds = math.modf(os.clock())
|
||||
if lMiliseconds==0 then
|
||||
lMiliseconds='000'
|
||||
else
|
||||
lMiliseconds=tostring(lMiliseconds):sub(3,5)
|
||||
end
|
||||
ExportScript.logFile:write(os.date("%X")..":"..lMiliseconds.." : "..message.."\r\n")
|
||||
end
|
||||
end
|
||||
|
||||
function ExportScript.Tools.createUDPSender()
|
||||
ExportScript.socket = require("socket")
|
||||
|
||||
local lcreateUDPSender = ExportScript.socket.protect(function()
|
||||
ExportScript.UDPsender = ExportScript.socket.udp()
|
||||
ExportScript.socket.try(ExportScript.UDPsender:setsockname("*", 0))
|
||||
--ExportScript.socket.try(ExportScript.UDPsender:settimeout(.004)) -- set the timeout for reading the socket; 250 fps
|
||||
end)
|
||||
|
||||
local ln, lerror = lcreateUDPSender()
|
||||
if lerror ~= nil then
|
||||
ExportScript.Tools.WriteToLog("createUDPSender protect: "..ExportScript.Tools.dump(ln)..", "..ExportScript.Tools.dump(lerror))
|
||||
return
|
||||
end
|
||||
|
||||
ExportScript.Tools.WriteToLog("Create UDPSender")
|
||||
end
|
||||
|
||||
function ExportScript.Tools.createUDPListner()
|
||||
if ExportScript.Config.Listener then
|
||||
ExportScript.socket = require("socket")
|
||||
|
||||
local lcreateUDPListner = ExportScript.socket.protect(function()
|
||||
ExportScript.UDPListener = ExportScript.socket.udp()
|
||||
ExportScript.socket.try(ExportScript.UDPListener:setsockname("*", ExportScript.Config.ListenerPort))
|
||||
ExportScript.socket.try(ExportScript.UDPListener:settimeout(.001)) -- set the timeout for reading the socket; 250 fps
|
||||
end)
|
||||
|
||||
local ln, lerror = lcreateUDPListner()
|
||||
if lerror ~= nil then
|
||||
ExportScript.Tools.WriteToLog("createUDPListner protect: "..ExportScript.Tools.dump(ln)..", "..ExportScript.Tools.dump(lerror))
|
||||
return
|
||||
end
|
||||
|
||||
ExportScript.Tools.WriteToLog("Create UDPListner")
|
||||
end
|
||||
end
|
||||
|
||||
function ExportScript.Tools.ProcessInput()
|
||||
local lCommand, lCommandArgs, lDevice
|
||||
-- C1,3001,4
|
||||
-- lComand = C
|
||||
-- lCommandArgs[1] = 1 => lDevice
|
||||
-- lCommandArgs[2] = 3001 => ButtonID
|
||||
-- lCommandArgs[3] = 4 => Value
|
||||
if ExportScript.Config.Listener then
|
||||
--local lInput,from,port = ExportScript.UDPListener:receivefrom()
|
||||
ExportScript.UDPListenerValues = {}
|
||||
|
||||
local lUDPListenerReceivefrom = ExportScript.socket.protect(function()
|
||||
--[[
|
||||
local try = ExportScript.socket.newtry(function()
|
||||
ExportScript.UDPListener:close()
|
||||
ExportScript.Tools.createUDPListner()
|
||||
end)
|
||||
ExportScript.UDPListenerValues.Input, ExportScript.UDPListenerValues.from, ExportScript.UDPListenerValues.port = try(ExportScript.UDPListener:receivefrom())
|
||||
]] -- Bei einer newtry Funktion wird im fehlerfall deren inhalt ausgeführt.
|
||||
ExportScript.UDPListenerValues.Input, ExportScript.UDPListenerValues.from, ExportScript.UDPListenerValues.port = ExportScript.socket.try(ExportScript.UDPListener:receivefrom())
|
||||
end)
|
||||
|
||||
local ln, lerror = lUDPListenerReceivefrom()
|
||||
if lerror ~= nil and lerror ~= "timeout" then
|
||||
ExportScript.Tools.WriteToLog("UDPListenerReceivefrom protect: "..ExportScript.Tools.dump(ln)..", "..ExportScript.Tools.dump(lerror))
|
||||
ExportScript.UDPListener:close()
|
||||
ExportScript.Tools.createUDPListner()
|
||||
end
|
||||
|
||||
local lInput, from, port = ExportScript.UDPListenerValues.Input, ExportScript.UDPListenerValues.from, ExportScript.UDPListenerValues.port
|
||||
|
||||
if ExportScript.Config.SocketDebug then
|
||||
ExportScript.Tools.WriteToLog("lInput: "..ExportScript.Tools.dump(lInput)..", from: "..ExportScript.Tools.dump(from)..", port: "..ExportScript.Tools.dump(port))
|
||||
end
|
||||
if lInput then
|
||||
lCommand = string.sub(lInput,1,1)
|
||||
|
||||
if lCommand == "R" then -- R == Reset
|
||||
if ExportScript.Config.IkarusExport then
|
||||
ExportScript.Tools.ResetChangeValues()
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("Reset fuer Ikarus Daten")
|
||||
end
|
||||
end
|
||||
if ExportScript.Config.DACExport then
|
||||
ExportScript.Tools.ResetChangeValuesDAC()
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("Reset fuer DAC Daten")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (lCommand == "C") then
|
||||
lCommandArgs = ExportScript.Tools.StrSplit(string.sub(lInput,2),",")
|
||||
lDeviceID = tonumber(lCommandArgs[1])
|
||||
if lDeviceID < 1000 then
|
||||
-- DCS Modules
|
||||
lDevice = GetDevice(lCommandArgs[1])
|
||||
if ExportScript.FoundDCSModule and type(lDevice) == "table" then
|
||||
lDevice:performClickableAction(lCommandArgs[2],lCommandArgs[3])
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("performClickableAction for Device: "..lCommandArgs[1]..", ButtonID: "..lCommandArgs[2]..", Value: "..lCommandArgs[3])
|
||||
end
|
||||
end
|
||||
elseif lDeviceID == 1000 then
|
||||
-- ExportScript.genericRadio(key, value)
|
||||
if ExportScript.FoundDCSModule then
|
||||
ExportScript.genericRadio(lCommandArgs[2],lCommandArgs[3])
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("genericRadio, ButtonID: "..lCommandArgs[2]..", Value: "..lCommandArgs[3])
|
||||
end
|
||||
end
|
||||
elseif lDeviceID == 2000 then
|
||||
-- Flaming Cliffs Module (Buttons)
|
||||
if ExportScript.FoundFCModule then
|
||||
-- ComamndID > 3000, because DAC or Ikarus add 300 to CommandID
|
||||
local lComandID = (tonumber(lCommandArgs[2]) - 3000)
|
||||
if tonumber(lCommandArgs[3]) == 1.0 then
|
||||
LoSetCommand(lComandID)
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("LoSetCommand, CommandID: "..lComandID)
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif lDeviceID == 2001 then
|
||||
-- Flaming Cliffs Module (analog axies)
|
||||
if ExportScript.FoundFCModule then
|
||||
-- ComamndID > 3000, because DAC or Ikarus add 3000 to CommandID
|
||||
local lComandID = (tonumber(lCommandArgs[2]) - 3000)
|
||||
LoSetCommand(lComandID, lCommandArgs[3])
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("LoSetCommand, CommandID: "..lComandID..", Value: "..lCommandArgs[3])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ExportScript.Tools.ProcessOutput()
|
||||
local coStatus
|
||||
--local currentTime = LoGetModelTime()
|
||||
|
||||
local lMyInfo = LoGetSelfData()
|
||||
if lMyInfo ~= nil then
|
||||
if ExportScript.ModuleName ~= lMyInfo.Name then
|
||||
ExportScript.NoLuaExportBeforeNextFrame = false
|
||||
ExportScript.Tools.SelectModule() -- point globals to Module functions and data.
|
||||
return
|
||||
end
|
||||
lMyInfo = nil
|
||||
end
|
||||
|
||||
local lDevice = GetDevice(0)
|
||||
if type(lDevice) == "table" and ExportScript.FoundDCSModule then
|
||||
|
||||
lDevice:update_arguments()
|
||||
|
||||
--if currentTime - ExportScript.lastExportTimeHI > ExportScript.Config.ExportInterval then
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("run hight importance export universally")
|
||||
ExportScript.Tools.ProcessArguments(lDevice, ExportScript.EveryFrameArguments) -- Module arguments as appropriate
|
||||
else
|
||||
ExportScript.coProcessArguments_EveryFrame = coroutine.create(ExportScript.Tools.ProcessArguments)
|
||||
coStatus = coroutine.resume( ExportScript.coProcessArguments_EveryFrame, lDevice, ExportScript.EveryFrameArguments)
|
||||
end
|
||||
|
||||
if ExportScript.Config.IkarusExport then
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("run hight importance export Ikarus")
|
||||
ExportScript.ProcessIkarusDCSHighImportance(lDevice) -- Module, as appropriate; determined in ExportScript.Tools.SelectModule()
|
||||
else
|
||||
ExportScript.coProcessIkarusDCSHighImportance = coroutine.create(ExportScript.ProcessIkarusDCSHighImportance)
|
||||
coStatus = coroutine.resume( ExportScript.coProcessIkarusDCSHighImportance, lDevice)
|
||||
end
|
||||
end
|
||||
|
||||
if ExportScript.Config.DACExport then
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("run hight importance export DAC")
|
||||
ExportScript.ProcessDACHighImportance(lDevice) -- Module, as appropriate; determined in ExportScript.Tools.SelectModule()
|
||||
else
|
||||
ExportScript.coProcessDACHighImportance = coroutine.create(ExportScript.ProcessDACHighImportance)
|
||||
coStatus = coroutine.resume( ExportScript.coProcessDACHighImportance, lDevice)
|
||||
end
|
||||
end
|
||||
|
||||
if ExportScript.FirstNewDataSend and ExportScript.FirstNewDataSendCount == 0 then
|
||||
if ExportScript.Config.DACExport then
|
||||
ExportScript.Tools.ResetChangeValuesDAC()
|
||||
end
|
||||
if ExportScript.Config.IkarusExport then
|
||||
ExportScript.Tools.WriteToLog("reset dcs ikarus")
|
||||
ExportScript.Tools.ResetChangeValues()
|
||||
end
|
||||
ExportScript.FirstNewDataSend = false
|
||||
else
|
||||
ExportScript.FirstNewDataSendCount = ExportScript.FirstNewDataSendCount - 1
|
||||
end
|
||||
|
||||
--ExportScript.lastExportTimeHI = currentTime
|
||||
ExportScript.lastExportTimeHI = ExportScript.lastExportTimeHI + ExportScript.Config.ExportInterval
|
||||
--end
|
||||
|
||||
--if currentTime - ExportScript.lastExportTimeLI > ExportScript.Config.ExportLowTickInterval then
|
||||
if ExportScript.lastExportTimeHI > ExportScript.Config.ExportLowTickInterval then
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("run low importance export universally")
|
||||
ExportScript.Tools.ProcessArguments(lDevice, ExportScript.Arguments) -- Module arguments as appropriate
|
||||
else
|
||||
ExportScript.coProcessArguments_Arguments = coroutine.create(ExportScript.Tools.ProcessArguments)
|
||||
coStatus = coroutine.resume( ExportScript.coProcessArguments_Arguments, lDevice, ExportScript.Arguments)
|
||||
end
|
||||
|
||||
if ExportScript.Config.IkarusExport then
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("run low importance export Ikarus")
|
||||
ExportScript.ProcessIkarusDCSLowImportance(lDevice) -- Module as appropriate; determined in ExportScript.Tools.SelectModule()
|
||||
else
|
||||
ExportScript.coProcessIkarusDCSLowImportance = coroutine.create(ExportScript.ProcessIkarusDCSLowImportance)
|
||||
coStatus = coroutine.resume( ExportScript.coProcessIkarusDCSLowImportance, lDevice)
|
||||
end
|
||||
end
|
||||
|
||||
if ExportScript.Config.DACExport then
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("run low importance export DAC")
|
||||
ExportScript.ProcessDACLowImportance(lDevice) -- Module, as appropriate; determined in ExportScript.Tools.SelectModule()
|
||||
else
|
||||
ExportScript.coProcessDACLowImportance = coroutine.create(ExportScript.ProcessDACLowImportance)
|
||||
coStatus = coroutine.resume( ExportScript.coProcessDACLowImportance, lDevice)
|
||||
end
|
||||
end
|
||||
|
||||
--ExportScript.lastExportTimeLI = currentTime
|
||||
ExportScript.lastExportTimeHI = 0
|
||||
end
|
||||
|
||||
if ExportScript.Config.IkarusExport then
|
||||
ExportScript.Tools.FlushData()
|
||||
end
|
||||
|
||||
if ExportScript.Config.DACExport then
|
||||
for i=1, #ExportScript.Config.DAC, 1 do
|
||||
ExportScript.Tools.FlushDataDAC(i)
|
||||
end
|
||||
end
|
||||
elseif ExportScript.FoundFCModule then -- Assume FC Aircraft
|
||||
|
||||
ExportScript.AF.EventNumber = os.clock() --tonumber(tostring(os.clock()):gsub(".", ""))
|
||||
|
||||
--if currentTime - ExportScript.lastExportTimeHI > ExportScript.Config.ExportInterval then
|
||||
|
||||
if ExportScript.Config.IkarusExport then
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("run hight importance export Ikarus")
|
||||
ExportScript.ProcessIkarusFCHighImportance()
|
||||
else
|
||||
ExportScript.coProcessGlassCockpitFCHighImportance = coroutine.create(ExportScript.ProcessIkarusFCHighImportance)
|
||||
coStatus = coroutine.resume( ExportScript.coProcessGlassCockpitFCHighImportance)
|
||||
end
|
||||
end
|
||||
if ExportScript.Config.DACExport then
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("run hight importance export DAC")
|
||||
ExportScript.ProcessDACHighImportance(lDevice)
|
||||
else
|
||||
ExportScript.coProcessDACHighImportance = coroutine.create(ExportScript.ProcessDACHighImportance)
|
||||
coStatus = coroutine.resume( ExportScript.coProcessDACHighImportance, lDevice)
|
||||
end
|
||||
end
|
||||
|
||||
if ExportScript.FirstNewDataSend and ExportScript.FirstNewDataSendCount == 0 then
|
||||
if ExportScript.Config.DACExport then
|
||||
ExportScript.Tools.ResetChangeValuesDAC()
|
||||
end
|
||||
if ExportScript.Config.IkarusExport then
|
||||
ExportScript.Tools.WriteToLog("reset fc ikarus")
|
||||
ExportScript.Tools.ResetChangeValues()
|
||||
end
|
||||
ExportScript.FirstNewDataSend = false
|
||||
else
|
||||
ExportScript.FirstNewDataSendCount = ExportScript.FirstNewDataSendCount - 1
|
||||
end
|
||||
|
||||
--ExportScript.lastExportTimeHI = currentTime
|
||||
ExportScript.lastExportTimeHI = ExportScript.lastExportTimeHI + ExportScript.Config.ExportInterval
|
||||
--end
|
||||
|
||||
--if currentTime - ExportScript.lastExportTimeLI > ExportScript.Config.ExportLowTickInterval then
|
||||
if ExportScript.lastExportTimeHI > ExportScript.Config.ExportLowTickInterval then
|
||||
if ExportScript.Config.IkarusExport then
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("run low importance export Ikarus")
|
||||
ExportScript.ProcessIkarusFCLowImportance()
|
||||
else
|
||||
ExportScript.coProcessIkarusFCLowImportance = coroutine.create(ExportScript.ProcessIkarusFCLowImportance)
|
||||
coStatus = coroutine.resume( ExportScript.coProcessIkarusFCLowImportance)
|
||||
end
|
||||
end
|
||||
|
||||
if ExportScript.Config.DACExport then
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("run low importance export DAC")
|
||||
ExportScript.ProcessDACLowImportance(lDevice)
|
||||
else
|
||||
ExportScript.coProcessDACLowImportance = coroutine.create(ExportScript.ProcessDACLowImportance)
|
||||
coStatus = coroutine.resume( ExportScript.coProcessDACLowImportance, lDevice)
|
||||
end
|
||||
end
|
||||
|
||||
--ExportScript.lastExportTimeLI = currentTime
|
||||
ExportScript.lastExportTimeHI = 0
|
||||
end
|
||||
|
||||
if ExportScript.Config.IkarusExport then
|
||||
ExportScript.Tools.FlushData()
|
||||
end
|
||||
|
||||
if ExportScript.Config.DACExport then
|
||||
for i=1, #ExportScript.Config.DAC, 1 do
|
||||
ExportScript.Tools.FlushDataDAC(i)
|
||||
end
|
||||
end
|
||||
else -- No Module found
|
||||
if ExportScript.FoundNoModul then
|
||||
ExportScript.Tools.WriteToLog("No Module Found.")
|
||||
ExportScript.Tools.SelectModule() -- point globals to Module functions and data.
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ExportScript.Tools.StrSplit(str, delim, maxNb)
|
||||
-- Eliminate bad cases...
|
||||
if string.find(str, delim) == nil then
|
||||
return { str }
|
||||
end
|
||||
if maxNb == nil or maxNb < 1 then
|
||||
maxNb = 0 -- No limit
|
||||
end
|
||||
local lResult = {}
|
||||
local lPat = "(.-)" .. delim .. "()"
|
||||
local lNb = 0
|
||||
local lLastPos
|
||||
for part, pos in string.gfind(str, lPat) do
|
||||
-- for part, pos in string.gmatch(str, lPat) do -- Lua Version > 5.1
|
||||
lNb = lNb + 1
|
||||
lResult[lNb] = part
|
||||
lLastPos = pos
|
||||
if lNb == maxNb then break end
|
||||
end
|
||||
-- Handle the last field
|
||||
if lNb ~= maxNb then
|
||||
lResult[lNb + 1] = string.sub(str, lLastPos)
|
||||
end
|
||||
return lResult
|
||||
end
|
||||
|
||||
-- remove trailing and leading whitespace from string.
|
||||
function ExportScript.Tools.trim(s)
|
||||
return (s:gsub("^%s*(.-)%s*$", "%1"))
|
||||
end
|
||||
|
||||
-- remove leading whitespace from string.
|
||||
function ExportScript.Tools.ltrim(s)
|
||||
return (s:gsub("^%s*", ""))
|
||||
end
|
||||
|
||||
-- remove trailing whitespace from string.
|
||||
function ExportScript.Tools.rtrim(s)
|
||||
local n = #s
|
||||
while n > 0 and s:find("^%s", n) do n = n - 1 end
|
||||
return s:sub(1, n)
|
||||
end
|
||||
-- The following more obvious implementation is generally not
|
||||
-- as efficient, particularly for long strings since Lua pattern matching
|
||||
-- starts at the left (though in special cases it is more efficient).
|
||||
-- Related discussion on p.197 of book "Beginning Lua Programming".
|
||||
--[[
|
||||
function ExportScript.Tools.rtrim(s)
|
||||
return (s:gsub("%s*$", ""))
|
||||
end
|
||||
]]
|
||||
|
||||
-- substitute variables into string.
|
||||
-- Example: subst("a=$(a),b=$(b)", {a=1, b=2}) --> "a=1,b=2".
|
||||
function ExportScript.Tools.subst(s, t)
|
||||
-- note: handle {a=false} substitution
|
||||
s = s:gsub("%$%(([%w_]+)%)", function(name)
|
||||
local val = t[name]
|
||||
return val ~= nil and tostring(val)
|
||||
end)
|
||||
return s
|
||||
end
|
||||
|
||||
--[[
|
||||
function ExportScript.Tools.round(num, idp)
|
||||
local lMult = 10^(idp or 0)
|
||||
return math.floor(num * lMult + 0.5) / lMult
|
||||
end
|
||||
]]
|
||||
|
||||
-- this function negate the numeric input values
|
||||
function ExportScript.Tools.negate(Input)
|
||||
if type(Input) == "number" then
|
||||
return (Input > 0.0 and (0 - Input) or (Input - Input - Input))
|
||||
else
|
||||
return Input
|
||||
end
|
||||
end
|
||||
|
||||
-- Status Gathering Functions
|
||||
function ExportScript.Tools.ProcessArguments(device, arguments)
|
||||
local lArgument , lFormat , lArgumentValue
|
||||
local lCounter = 0
|
||||
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("======Begin========")
|
||||
end
|
||||
|
||||
for lArgument, lFormat in pairs(arguments) do
|
||||
lArgumentValue = string.format(lFormat,device:get_argument_value(lArgument))
|
||||
if ExportScript.Config.Debug then
|
||||
lCounter = lCounter + 1
|
||||
ExportScript.Tools.WriteToLog(lCounter..". ID: "..lArgument..", Fromat: "..lFormat..", Value: "..lArgumentValue)
|
||||
end
|
||||
if ExportScript.Config.IkarusExport then
|
||||
ExportScript.Tools.SendData(lArgument, lArgumentValue)
|
||||
end
|
||||
if ExportScript.Config.DACExport then
|
||||
ExportScript.Tools.SendDataDAC(lArgument, lArgumentValue)
|
||||
end
|
||||
end
|
||||
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("======End========")
|
||||
end
|
||||
end
|
||||
|
||||
-- Network Functions for GlassCockpit
|
||||
function ExportScript.Tools.SendData(id, value)
|
||||
if id == nil then
|
||||
ExportScript.Tools.WriteToLog("Export id is nil")
|
||||
return
|
||||
end
|
||||
if value == nil then
|
||||
ExportScript.Tools.WriteToLog("Value for id "..id.." is nil")
|
||||
return
|
||||
end
|
||||
|
||||
if string.len(value) > 3 and value == string.sub("-0.00000000",1, string.len(value)) then
|
||||
value = value:sub(2)
|
||||
end
|
||||
|
||||
if ExportScript.LastData[id] == nil or ExportScript.LastData[id] ~= value then
|
||||
local ldata = id .. "=" .. value
|
||||
local ldataLen = string.len(ldata)
|
||||
|
||||
if ldataLen + ExportScript.PacketSize > 576 then
|
||||
ExportScript.Tools.FlushData()
|
||||
end
|
||||
|
||||
table.insert(ExportScript.SendStrings, ldata)
|
||||
ExportScript.LastData[id] = value
|
||||
ExportScript.PacketSize = ExportScript.PacketSize + ldataLen + 1
|
||||
end
|
||||
end
|
||||
|
||||
-- Network Functions for DAC
|
||||
function ExportScript.Tools.SendDataDAC(id, value)
|
||||
for hardware=1, #ExportScript.Config.DAC, 1 do
|
||||
if id == nil then
|
||||
ExportScript.Tools.WriteToLog("Export id is nil")
|
||||
return
|
||||
end
|
||||
if value == nil then
|
||||
ExportScript.Tools.WriteToLog("Value for id "..id.." is nil")
|
||||
return
|
||||
end
|
||||
if ExportScript.Config.DAC[hardware] == nil then
|
||||
ExportScript.Tools.WriteToLog("unknown hardware ID '"..hardware.."' for value: '"..id.."="..value.."'")
|
||||
return
|
||||
end
|
||||
|
||||
if string.len(value) > 3 and value == string.sub("-0.00000000",1, string.len(value)) then
|
||||
value = value:sub(2)
|
||||
end
|
||||
|
||||
if ExportScript.LastDataDAC[hardware][id] == nil or ExportScript.LastDataDAC[hardware][id] ~= value then
|
||||
local ldata = id .. "=" .. value
|
||||
local ldataLen = string.len(ldata)
|
||||
|
||||
if ldataLen + ExportScript.PacketSizeDAC[hardware] > 576 then
|
||||
ExportScript.Tools.FlushDataDAC(hardware)
|
||||
end
|
||||
|
||||
table.insert(ExportScript.SendStringsDAC[hardware], ldata)
|
||||
ExportScript.LastDataDAC[hardware][id] = value
|
||||
ExportScript.PacketSizeDAC[hardware] = ExportScript.PacketSizeDAC[hardware] + ldataLen + 1
|
||||
--ExportScript.Tools.WriteToLog("id=ldata: "..ldata)
|
||||
--ExportScript.Tools.WriteToLog("ExportScript.LastDataDAC["..hardware.."]: "..ExportScript.Tools.dump(ExportScript.LastDataDAC[hardware]))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
function ExportScript.Tools.FlushData()
|
||||
if #ExportScript.SendStrings > 0 then
|
||||
local lES_SimID = ""
|
||||
|
||||
lES_SimID = ExportScript.SimID
|
||||
|
||||
local lPacket = lES_SimID .. table.concat(ExportScript.SendStrings, ExportScript.Config.IkarusSeparator) .. "\n"
|
||||
ExportScript.socket.try(ExportScript.UDPsender:sendto(lPacket, ExportScript.Config.IkarusHost, ExportScript.Config.IkarusPort))
|
||||
|
||||
if ExportScript.Config.SocketDebug then
|
||||
ExportScript.Tools.WriteToLog("FlushData: send the following data to host: "..ExportScript.Config.IkarusHost..", Port: "..ExportScript.Config.IkarusPort..", Data: "..lPacket)
|
||||
end
|
||||
|
||||
ExportScript.SendStrings = {}
|
||||
ExportScript.PacketSize = 0
|
||||
else
|
||||
if ExportScript.Config.SocketDebug then
|
||||
ExportScript.Tools.WriteToLog("FlushData: nothing sent")
|
||||
end
|
||||
end
|
||||
end
|
||||
]]
|
||||
|
||||
function ExportScript.Tools.FlushData()
|
||||
local lFlushData = ExportScript.socket.protect(function()
|
||||
if #ExportScript.SendStrings > 0 then
|
||||
local lES_SimID = ""
|
||||
|
||||
lES_SimID = ExportScript.SimID
|
||||
|
||||
local lPacket = lES_SimID .. table.concat(ExportScript.SendStrings, ExportScript.Config.IkarusSeparator) .. "\n"
|
||||
--ExportScript.socket.try(ExportScript.UDPsender:sendto(lPacket, ExportScript.Config.IkarusHost, ExportScript.Config.IkarusPort))
|
||||
local try = ExportScript.socket.newtry(function() ExportScript.UDPsender:close() ExportScript.Tools.createUDPSender() ExportScript.Tools.ResetChangeValues() end)
|
||||
try(ExportScript.UDPsender:sendto(lPacket, ExportScript.Config.IkarusHost, ExportScript.Config.IkarusPort))
|
||||
|
||||
if ExportScript.Config.SocketDebug then
|
||||
ExportScript.Tools.WriteToLog("FlushData: send to host: "..ExportScript.Config.IkarusHost..", Port: "..ExportScript.Config.IkarusPort..", Data: "..lPacket)
|
||||
end
|
||||
|
||||
ExportScript.SendStrings = {}
|
||||
ExportScript.PacketSize = 0
|
||||
else
|
||||
if ExportScript.Config.SocketDebug then
|
||||
ExportScript.Tools.WriteToLog("FlushData: nothing sent")
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local ln, lerror = lFlushData()
|
||||
if lerror ~= nil then
|
||||
ExportScript.Tools.WriteToLog("FlushData protect: "..ExportScript.Tools.dump(ln)..", "..ExportScript.Tools.dump(lerror))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function ExportScript.Tools.FlushDataDAC(hardware)
|
||||
hardware = hardware or 1
|
||||
|
||||
if ExportScript.Config.DAC[hardware] == nil then
|
||||
ExportScript.Tools.WriteToLog("FlushDataDAC: unknown hardware ID '"..hardware.."'")
|
||||
return
|
||||
end
|
||||
|
||||
local lFlushDataDAC = ExportScript.socket.protect(function()
|
||||
if #ExportScript.SendStringsDAC[hardware] > 0 then
|
||||
local lPacket = ExportScript.SimID .. table.concat(ExportScript.SendStringsDAC[hardware], ExportScript.Config.DAC[hardware].Separator) .. "\n"
|
||||
--ExportScript.socket.try(ExportScript.UDPsender:sendto(lPacket, ExportScript.Config.DAC[hardware].Host, ExportScript.Config.DAC[hardware].SendPort))
|
||||
local try = ExportScript.socket.newtry(function() ExportScript.UDPsender:close() ExportScript.Tools.createUDPSender() ExportScript.Tools.ResetChangeValuesDAC() end)
|
||||
try(ExportScript.UDPsender:sendto(lPacket, ExportScript.Config.DAC[hardware].Host, ExportScript.Config.DAC[hardware].SendPort))
|
||||
|
||||
if ExportScript.Config.SocketDebug then
|
||||
ExportScript.Tools.WriteToLog("FlushDataDAC["..hardware.."]: send to host: "..ExportScript.Config.DAC[hardware].Host..", Port: "..ExportScript.Config.DAC[hardware].SendPort..", Data: "..lPacket)
|
||||
end
|
||||
|
||||
ExportScript.SendStringsDAC[hardware] = {}
|
||||
ExportScript.PacketSizeDAC[hardware] = 0
|
||||
else
|
||||
if ExportScript.Config.SocketDebug then
|
||||
ExportScript.Tools.WriteToLog("FlushDataDAC["..hardware.."]: nothing sent")
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local ln, lerror = lFlushDataDAC()
|
||||
if lerror ~= nil then
|
||||
ExportScript.Tools.WriteToLog("FlushDataDAC protect: "..ExportScript.Tools.dump(ln)..", "..ExportScript.Tools.dump(lerror))
|
||||
end
|
||||
end
|
||||
|
||||
function ExportScript.Tools.ResetChangeValues()
|
||||
ExportScript.LastData = {}
|
||||
end
|
||||
|
||||
function ExportScript.Tools.ResetChangeValuesDAC()
|
||||
for i = 1, #ExportScript.Config.DAC, 1 do
|
||||
ExportScript.LastDataDAC[i] = {}
|
||||
end
|
||||
end
|
||||
|
||||
function ExportScript.Tools.SelectModule()
|
||||
-- Select Module...
|
||||
ExportScript.FoundDCSModule = false
|
||||
ExportScript.FoundFCModule = false
|
||||
ExportScript.FoundNoModul = true
|
||||
|
||||
local lMyInfo = LoGetSelfData()
|
||||
if lMyInfo == nil then -- End SelectModule, if don't selected a aircraft
|
||||
return
|
||||
end
|
||||
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("MyInfo: "..ExportScript.Tools.dump(lMyInfo))
|
||||
end
|
||||
|
||||
ExportScript.ModuleName = lMyInfo.Name
|
||||
local lModuleName = ExportScript.ModuleName..".lua"
|
||||
local lModuleFile = ""
|
||||
|
||||
ExportScript.FoundNoModul = false
|
||||
|
||||
for file in lfs.dir(ExportScript.Config.ExportModulePath) do
|
||||
if lfs.attributes(ExportScript.Config.ExportModulePath..file,"mode") == "file" then
|
||||
if file == lModuleName then
|
||||
lModuleFile = ExportScript.Config.ExportModulePath..file
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ExportScript.Tools.WriteToLog("File Path: "..lModuleFile)
|
||||
|
||||
if string.len(lModuleFile) > 1 then
|
||||
ExportScript.Tools.ResetChangeValuesDAC()
|
||||
|
||||
-- load Aircraft File
|
||||
dofile(lModuleFile)
|
||||
if ExportScript.Config.DACExport then
|
||||
ExportScript.Tools.SendDataDAC("File", lMyInfo.Name)
|
||||
for i=1, #ExportScript.Config.DAC, 1 do
|
||||
ExportScript.Tools.FlushDataDAC(i)
|
||||
end
|
||||
end
|
||||
|
||||
if ExportScript.Config.IkarusExport then
|
||||
ExportScript.Tools.SendData("File", lMyInfo.Name)
|
||||
end
|
||||
|
||||
ExportScript.Tools.WriteToLog("File '"..lModuleFile.."' loaded")
|
||||
|
||||
ExportScript.Tools.WriteToLog("Version:")
|
||||
for k,v in pairs(ExportScript.Version) do
|
||||
ExportScript.Tools.WriteToLog(k..": "..v)
|
||||
end
|
||||
|
||||
ExportScript.FirstNewDataSend = ExportScript.Config.FirstNewDataSend
|
||||
ExportScript.FirstNewDataSendCount = ExportScript.Config.FirstNewDataSendCount
|
||||
|
||||
if ExportScript.FoundDCSModule then
|
||||
local lCounter = 0
|
||||
for k, v in pairs(ExportScript.ConfigEveryFrameArguments) do
|
||||
lCounter = lCounter + 1
|
||||
end
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("ExportScript.ConfigEveryFrameArguments Count: "..lCounter)
|
||||
end
|
||||
if lCounter > 0 then
|
||||
ExportScript.EveryFrameArguments = ExportScript.ConfigEveryFrameArguments
|
||||
else
|
||||
-- no Arguments
|
||||
ExportScript.EveryFrameArguments = {}
|
||||
end
|
||||
lCounter = 0
|
||||
for k, v in pairs(ExportScript.ConfigArguments) do
|
||||
lCounter = lCounter + 1
|
||||
end
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog("ExportScript.ConfigArguments Count: "..lCounter)
|
||||
end
|
||||
if lCounter > 0 then
|
||||
ExportScript.Arguments = ExportScript.ConfigArguments
|
||||
else
|
||||
-- no Arguments
|
||||
ExportScript.Arguments = {}
|
||||
end
|
||||
|
||||
ExportScript.ProcessIkarusDCSHighImportance = ExportScript.ProcessIkarusDCSConfigHighImportance
|
||||
ExportScript.ProcessIkarusDCSLowImportance = ExportScript.ProcessIkarusDCSConfigLowImportance
|
||||
ExportScript.ProcessDACHighImportance = ExportScript.ProcessDACConfigHighImportance
|
||||
ExportScript.ProcessDACLowImportance = ExportScript.ProcessDACConfigLowImportance
|
||||
|
||||
elseif ExportScript.FoundFCModule then
|
||||
ExportScript.ProcessIkarusFCHighImportance = ExportScript.ProcessIkarusFCHighImportanceConfig
|
||||
ExportScript.ProcessIkarusFCLowImportance = ExportScript.ProcessIkarusFCLowImportanceConfig
|
||||
ExportScript.ProcessDACHighImportance = ExportScript.ProcessDACConfigHighImportance
|
||||
ExportScript.ProcessDACLowImportance = ExportScript.ProcessDACConfigLowImportance
|
||||
else
|
||||
ExportScript.Tools.WriteToLog("Unknown Module Type: "..lMyInfo.Name)
|
||||
end
|
||||
|
||||
if ExportScript.Config.IkarusExport then
|
||||
for Map, LatLong in pairs(ExportScript.Maps) do
|
||||
if lMyInfo.LatLongAlt.Lat > LatLong.Lat2 and lMyInfo.LatLongAlt.Lat < LatLong.Lat1 then
|
||||
if lMyInfo.LatLongAlt.Long > LatLong.Long1 and lMyInfo.LatLongAlt.Long < LatLong.Long2 then
|
||||
ExportScript.Tools.WriteToLog("Detected Map: "..Map)
|
||||
ExportScript.Tools.SendData("Map", Map)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ExportScript.Tools.FlushData()
|
||||
end
|
||||
|
||||
else -- Unknown Module
|
||||
ExportScript.ProcessIkarusDCSHighImportance = ExportScript.ProcessIkarusDCSHighImportanceNoConfig
|
||||
ExportScript.ProcessIkarusDCSLowImportance = ExportScript.ProcessIkarusDCSLowImportanceNoConfig
|
||||
ExportScript.ProcessIkarusFCHighImportance = ExportScript.ProcessIkarusFCHighImportanceNoConfig
|
||||
ExportScript.ProcessIkarusFCLowImportance = ExportScript.ProcessIkarusFCLowImportanceNoConfig
|
||||
ExportScript.ProcessDACHighImportance = ExportScript.ProcessDACHighImportanceNoConfig
|
||||
ExportScript.ProcessDACLowImportance = ExportScript.ProcessDACLowImportanceNoConfig
|
||||
ExportScript.EveryFrameArguments = {}
|
||||
ExportScript.Arguments = {}
|
||||
|
||||
ExportScript.Tools.WriteToLog("Version:")
|
||||
for k,v in pairs(ExportScript.Version) do
|
||||
ExportScript.Tools.WriteToLog(k..": "..v)
|
||||
end
|
||||
ExportScript.Tools.WriteToLog("Unknown Module Name: "..lMyInfo.Name)
|
||||
end
|
||||
end
|
||||
|
||||
-- The ExportScript.Tools.dump function show the content of the specified variable.
|
||||
-- ExportScript.Tools.dump is similar to PHP function dump and show variables from type
|
||||
-- "nil, "number", "string", "boolean, "table", "function", "thread" and "userdata"
|
||||
function ExportScript.Tools.dump(var, depth)
|
||||
depth = depth or 0
|
||||
if type(var) == "string" then
|
||||
return 'string: "' .. var .. '"\n'
|
||||
elseif type(var) == "nil" then
|
||||
return 'nil\n'
|
||||
elseif type(var) == "number" then
|
||||
return 'number: "' .. var .. '"\n'
|
||||
elseif type(var) == "boolean" then
|
||||
return 'boolean: "' .. tostring(var) .. '"\n'
|
||||
elseif type(var) == "function" then
|
||||
if debug and debug.getinfo then
|
||||
fcnname = tostring(var)
|
||||
local info = debug.getinfo(var, "S")
|
||||
if info.what == "C" then
|
||||
return string.format('%q', fcnname .. ', C function') .. '\n'
|
||||
else
|
||||
if (string.sub(info.source, 1, 2) == [[./]]) then
|
||||
return string.format('%q', fcnname .. ', defined in (' .. info.linedefined .. '-' .. info.lastlinedefined .. ')' .. info.source) ..'\n'
|
||||
else
|
||||
return string.format('%q', fcnname .. ', defined in (' .. info.linedefined .. '-' .. info.lastlinedefined .. ')') ..'\n'
|
||||
end
|
||||
end
|
||||
else
|
||||
return 'a function\n'
|
||||
end
|
||||
elseif type(var) == "thread" then
|
||||
return 'thread\n'
|
||||
elseif type(var) == "userdata" then
|
||||
return tostring(var)..'\n'
|
||||
elseif type(var) == "table" then
|
||||
depth = depth + 1
|
||||
out = "{\n"
|
||||
for k,v in pairs(var) do
|
||||
out = out .. (" "):rep(depth*4).. "["..k.."] = " .. ExportScript.Tools.dump(v, depth)
|
||||
end
|
||||
return out .. (" "):rep((depth-1)*4) .. "}\n"
|
||||
else
|
||||
return tostring(var) .. "\n"
|
||||
end
|
||||
end
|
||||
|
||||
-- round function for math libraray
|
||||
-- number : value
|
||||
-- decimals: number of decimal
|
||||
-- method : ceil: Returns the smallest integer larger than or equal to number
|
||||
-- floor: Returns the smallest integer smaller than or equal to number
|
||||
function ExportScript.Tools.round(number, decimals, method)
|
||||
if string.find(number, "%p" ) ~= nil then
|
||||
decimals = decimals or 0
|
||||
local lFactor = 10 ^ decimals
|
||||
if (method == "ceil" or method == "floor") then
|
||||
-- ceil: Returns the smallest integer larger than or equal to number
|
||||
-- floor: Returns the smallest integer smaller than or equal to number
|
||||
return math[method](number * lFactor) / lFactor
|
||||
else
|
||||
return tonumber(("%."..decimals.."f"):format(number))
|
||||
end
|
||||
else
|
||||
return number
|
||||
end
|
||||
end
|
||||
|
||||
-- split function for string libraray
|
||||
-- stringvalue: value
|
||||
-- delimiter : delimiter for split
|
||||
-- for example, see http://www.lua.org/manual/5.1/manual.html#5.4.1
|
||||
function ExportScript.Tools.split(stringvalue, delimiter)
|
||||
result = {};
|
||||
for match in (stringvalue..delimiter):gmatch("(.-)"..delimiter) do
|
||||
table.insert(result, match);
|
||||
end
|
||||
return result;
|
||||
end
|
||||
|
||||
-- the function checks whether the cockpit light should be activated in ikarus on the basis of the parameters
|
||||
-- functional parameters, a single ID, or a table with IDs
|
||||
function ExportScript.Tools.IkarusCockpitLights(mainPanelDevice, ExportIDs)
|
||||
local TmpExportIDs = ExportIDs or 0
|
||||
local TmpLight = false
|
||||
|
||||
if type(mainPanelDevice) ~= "table" then
|
||||
return
|
||||
end
|
||||
|
||||
if type(TmpExportIDs) == "table" then
|
||||
for key,value in pairs(TmpExportIDs) do
|
||||
if type(value) == "number" then
|
||||
if mainPanelDevice:get_argument_value(value) > 0.4 then
|
||||
TmpLight = true
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif type(TmpExportIDs) == "number" then
|
||||
if mainPanelDevice:get_argument_value(TmpExportIDs) > 0.4 then
|
||||
TmpLight = true
|
||||
end
|
||||
end
|
||||
|
||||
if TmpLight then
|
||||
ExportScript.Tools.SendData(2222, "1.0") -- Ikarus Cockpit Light on
|
||||
else
|
||||
ExportScript.Tools.SendData(2222, "0.0") -- Ikarus Cockpit Light off
|
||||
end
|
||||
end
|
||||
|
||||
-- The function returns a correctly formatted string with the given radio frequency.
|
||||
-- Frequency: MHz/KHz, format: e.g. "7.3" or "5.2", fill with leading zeros (default false), least value of frequency (default 0.025 (MHz))
|
||||
function ExportScript.Tools.RoundFreqeuncy(Freqeuncy, Format, PrefixZeros, LeastValue)
|
||||
local freqeuncy = Freqeuncy or 0.0
|
||||
local format = Format or "7.3"
|
||||
local prefixzeros = PrefixZeros or false
|
||||
local leastvalue = LeastValue or 0.025
|
||||
local tmpstring = ""
|
||||
local tmp1, tmp2, tmp3, tmp4 = 0, 0, 0, 0
|
||||
|
||||
local from ,to = string.find(format, "%.")
|
||||
tmp1 = string.sub(format, 0, to)
|
||||
tmp2 = string.sub(format, to)
|
||||
tmp1 = tonumber(string.sub(tmp1, string.find(tmp1, "%d+")))
|
||||
tmp2 = tonumber(string.sub(tmp2, string.find(tmp2, "%d+")))
|
||||
|
||||
local tmp3, tmp4 = math.modf(freqeuncy)
|
||||
local bla3, bla4 = math.modf(tmp4 / leastvalue)
|
||||
|
||||
tmpstring = (tmp3 + (bla3 * leastvalue ))
|
||||
|
||||
tmpstring = string.format("%."..tmp2.."f", tmpstring)
|
||||
|
||||
-- while string.len(tmpstring) < tmp1 do
|
||||
-- tmpstring = " "..tmpstring
|
||||
-- end
|
||||
|
||||
tmpstring = string.rep(" ", tmp1 - string.len(tmpstring))..tmpstring
|
||||
|
||||
if prefixzeros then
|
||||
tmpstring = string.gsub(tmpstring, " ", "0")
|
||||
end
|
||||
|
||||
return tmpstring
|
||||
end
|
||||
|
||||
-- The function return a table with values of given indicator
|
||||
-- The value is retrievable via a named index. e.g. TmpReturn.txt_digits
|
||||
function ExportScript.Tools.getListIndicatorValue(IndicatorID)
|
||||
local ListIindicator = list_indication(IndicatorID)
|
||||
local TmpReturn = {}
|
||||
|
||||
if ExportScript.Config.Debug then
|
||||
ExportScript.Tools.WriteToLog('list_indication('..IndicatorID..'): '..ExportScript.Tools.dump(ListIindicator))
|
||||
end
|
||||
|
||||
if ListIindicator == "" then
|
||||
return nil
|
||||
end
|
||||
|
||||
local ListindicatorMatch = ListIindicator:gmatch("-----------------------------------------\n([^\n]+)\n([^\n]*)\n")
|
||||
while true do
|
||||
local Key, Value = ListindicatorMatch()
|
||||
if not Key then
|
||||
break
|
||||
end
|
||||
TmpReturn[Key] = Value
|
||||
end
|
||||
|
||||
return TmpReturn
|
||||
end
|
||||
|
||||
-- The function format a given string for a display
|
||||
-- String: value for show in display, maxChars: Display size (default 5), LEFTorRIGHT: flush with left "l" or right "r" site (default "r")
|
||||
function ExportScript.Tools.DisplayFormat(String, maxChars, LEFTorRight, DAC)
|
||||
local lString = String or ""
|
||||
local lmaxChars = maxChars or 5
|
||||
local lLEFTorRight = LEFTorRight or "r"
|
||||
local lDAC = DAC or false
|
||||
local lTmpLen = 0
|
||||
local lRep = " "
|
||||
|
||||
if lDAC then
|
||||
lRep = "-"
|
||||
end
|
||||
|
||||
lString = ExportScript.utf8.sub(lString, 0, lmaxChars)
|
||||
lTmpLen = ExportScript.utf8.len(lString)
|
||||
|
||||
if lTmpLen < lmaxChars then
|
||||
if string.lower(lLEFTorRight) == "l" then
|
||||
lString = lString..string.rep(" ", lmaxChars - lTmpLen)
|
||||
else
|
||||
lString = string.rep(" ", lmaxChars - lTmpLen)..lString
|
||||
end
|
||||
end
|
||||
|
||||
return lString
|
||||
end
|
||||
|
||||
function ExportScript.Tools.KeyInTable(Table, Key)
|
||||
for key, value in pairs(Table) do
|
||||
if key == Key then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function ExportScript.Tools.ValueInTable(Table, Value)
|
||||
for key, value in pairs(Table) do
|
||||
if value == Value then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Pointed to by ExportScript.ProcessIkarusDCSHighImportance, if the player aircraft is something else
|
||||
function ExportScript.ProcessIkarusDCSHighImportanceNoConfig(mainPanelDevice)
|
||||
end
|
||||
-- Pointed to by ExportScript.ProcessIkarusDCSLowImportance, if the player aircraft is something else
|
||||
function ExportScript.ProcessIkarusDCSLowImportanceNoConfig(mainPanelDevice)
|
||||
end
|
||||
|
||||
-- the player aircraft is a Flaming Cliffs or similar aircraft
|
||||
function ExportScript.ProcessIkarusFCHighImportanceNoConfig()
|
||||
end
|
||||
function ExportScript.ProcessIkarusFCLowImportanceNoConfig()
|
||||
end
|
||||
|
||||
-- Hardware exports
|
||||
function ExportScript.ProcessDACHighImportanceNoConfig(mainPanelDevice)
|
||||
end
|
||||
function ExportScript.ProcessDACLowImportanceNoConfig(mainPanelDevice)
|
||||
end
|
||||
411
lib/genericRadio.lua
Normal file
411
lib/genericRadio.lua
Normal file
@@ -0,0 +1,411 @@
|
||||
-- Ikarus and D.A.C. Export Script
|
||||
--
|
||||
-- generic Radio File
|
||||
--
|
||||
-- Copyright by Michael aka McMicha 2014
|
||||
-- Contact dcs2arcaze.micha@farbpigmente.org
|
||||
|
||||
ExportScript.Version.genericRadio = "1.2.1"
|
||||
|
||||
--[[
|
||||
-- Config and execute in function ExportScript.ProcessDACConfigLowImportance()
|
||||
|
||||
-- genericRadioConf for example A-10C Radio AN/ARC-164 UHF
|
||||
ExportScript.genericRadioConf = {}
|
||||
ExportScript.genericRadioConf['maxRadios'] = 1 -- numbers of aviables/supported radios
|
||||
ExportScript.genericRadioConf[1] = {} -- first radio
|
||||
ExportScript.genericRadioConf[1]['Name'] = "AN/ARC-164 UHF" -- name of radio
|
||||
ExportScript.genericRadioConf[1]['DeviceID'] = 54 -- DeviceID for GetDevice from device.lua
|
||||
ExportScript.genericRadioConf[1]['setFrequency'] = true -- change frequency active
|
||||
ExportScript.genericRadioConf[1]['FrequencyMultiplicator'] = 1000000 -- multiplicator from Hz to MHz
|
||||
ExportScript.genericRadioConf[1]['FrequencyFormat'] = "%7.3f" -- frequency view format LUA style
|
||||
ExportScript.genericRadioConf[1]['FrequencyStep'] = 25 -- minimal step for frequency change
|
||||
ExportScript.genericRadioConf[1]['minFrequency'] = 220.000 -- lowest frequency
|
||||
ExportScript.genericRadioConf[1]['maxFrequency'] = 314.450 -- highest frequency
|
||||
ExportScript.genericRadioConf[1]['Power'] = {} -- power button active
|
||||
ExportScript.genericRadioConf[1]['Power']['ButtonID'] = 3008 -- power button id from cklickable.lua
|
||||
ExportScript.genericRadioConf[1]['Power']['ValueOn'] = 0.1 -- power on value from cklickable.lua
|
||||
ExportScript.genericRadioConf[1]['Power']['ValueOff'] = 0.0 -- power off value from cklickable.lua
|
||||
ExportScript.genericRadioConf[1]['Volume'] = {} -- volume knob active
|
||||
ExportScript.genericRadioConf[1]['Volume']['ButtonID'] = 3011 -- volume button id from cklickable.lua
|
||||
ExportScript.genericRadioConf[1]['Preset'] = {} -- preset knob active
|
||||
ExportScript.genericRadioConf[1]['Preset']['ArgumentID'] = 161 -- ManualPreset argument id from cklickable.lua
|
||||
ExportScript.genericRadioConf[1]['Preset']['ButtonID'] = 3001 -- preset button id from cklickable.lua
|
||||
-- ExportScript.genericRadioConf[1]['Preset']['ButtonID2'] = 3002 -- preset button id from cklickable.lua
|
||||
-- Preset based on switchlogic on clickabledata.lua
|
||||
ExportScript.genericRadioConf[1]['Preset']['List'] = {[0.0]="01",[0.05]="02",[0.10]="03",[0.15]="04",[0.20]="05",[0.25]="06",[0.30]="07",[0.35]="08",[0.40]="09",[0.45]="10",[0.50]="11",[0.55]="12",[0.60]="13",[0.65]="14",[0.70]="15",[0.75]="16",[0.80]="17",[0.85]="18",[0.90]="19",[0.95]="20",[1.00]="01"}
|
||||
ExportScript.genericRadioConf[1]['Preset']['Step'] = 0.05 -- minimal step for preset change
|
||||
-- ExportScript.genericRadioConf[1]['Preset']['Step2'] = -0.05 -- minimal step for preset change
|
||||
ExportScript.genericRadioConf[1]['Squelch'] = {} -- squelch switch active
|
||||
ExportScript.genericRadioConf[1]['Squelch']['ArgumentID'] = 170 -- ManualPreset argument id from cklickable.lua
|
||||
ExportScript.genericRadioConf[1]['Squelch']['ButtonID'] = 3010 -- squelch button id from cklickable.lua
|
||||
ExportScript.genericRadioConf[1]['Squelch']['ValueOn'] = 0.0 -- squelch on value from cklickable.lua
|
||||
ExportScript.genericRadioConf[1]['Squelch']['ValueOff'] = 1.0 -- squelch off value from cklickable.lua
|
||||
ExportScript.genericRadioConf[1]['Load'] = {} -- load button preset
|
||||
ExportScript.genericRadioConf[1]['Load']['ButtonID'] = 3015 -- load button id from cklickable.lua
|
||||
ExportScript.genericRadioConf[1]['ManualPreset'] = {} -- switch manual or preset active
|
||||
ExportScript.genericRadioConf[1]['ManualPreset']['ArgumentID'] = 167 -- ManualPreset argument id from cklickable.lua
|
||||
ExportScript.genericRadioConf[1]['ManualPreset']['ButtonID'] = 3007 -- ManualPreset button id from cklickable.lua
|
||||
ExportScript.genericRadioConf[1]['ManualPreset']['ValueManual'] = 0.0-- ManualPreset Manual value from cklickable.lua
|
||||
ExportScript.genericRadioConf[1]['ManualPreset']['ValuePreset'] = 0.1-- ManualPreset Preset value from cklickable.lua
|
||||
|
||||
...
|
||||
|
||||
ExportScript.genericRadio(nil, nil)]]
|
||||
|
||||
function ExportScript.genericRadio(key, value)
|
||||
--ExportScript.Tools.WriteToLog('genericRadioConf: '..ExportScript.Tools.dump(ExportScript.genericRadioConf))
|
||||
if type(ExportScript.genericRadioConf) ~= "table" then
|
||||
ExportScript.Tools.WriteToLog("No Radio defined.")
|
||||
return
|
||||
end
|
||||
|
||||
local lRotaryFrequency_1, lRotaryFrequency_2, lVolume, lPreset, lLoad, lSquelch, lManualPreset, lPower, lDevice, lClickAction, lSetFrequency = nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil
|
||||
local lMainPanelDevice = GetDevice(0)
|
||||
|
||||
if ExportScript.AF.genericRadio == nil then
|
||||
ExportScript.AF.genericRadio = 0
|
||||
end
|
||||
if ExportScript.AF.genericRadioFrequency1 == nil then
|
||||
ExportScript.AF.genericRadioFrequency1 = 0.0
|
||||
end
|
||||
if ExportScript.AF.genericRadioFrequency2 == nil then
|
||||
ExportScript.AF.genericRadioFrequency2 = 0.0
|
||||
end
|
||||
if ExportScript.AF.genericRadioPower == nil then
|
||||
ExportScript.AF.genericRadioPower = {}
|
||||
end
|
||||
if ExportScript.AF.genericRadioPresetManual == nil then
|
||||
ExportScript.AF.genericRadioPresetManual = {}
|
||||
end
|
||||
if ExportScript.AF.genericRadioSquelch == nil then
|
||||
ExportScript.AF.genericRadioSquelch = {}
|
||||
end
|
||||
if ExportScript.AF.genericRadioPreset == nil then
|
||||
ExportScript.AF.genericRadioPreset = {}
|
||||
end
|
||||
|
||||
if key == "3001" then
|
||||
ExportScript.AF.genericRadio = tonumber(value)
|
||||
end
|
||||
if key == "3002" then
|
||||
lRotaryFrequency_1 = tonumber(value)
|
||||
end
|
||||
if key == "3003" then
|
||||
lRotaryFrequency_2 = tonumber(value)
|
||||
end
|
||||
if key == "3004" then
|
||||
lVolume = tonumber(value)
|
||||
end
|
||||
if key == "3005" then
|
||||
lPreset = tonumber(value)
|
||||
end
|
||||
if key == "3006" then
|
||||
lLoad = tonumber(value)
|
||||
end
|
||||
if key == "3007" then
|
||||
lSquelch = tonumber(value)
|
||||
end
|
||||
if key == "3008" then
|
||||
lManualPreset = tonumber(value)
|
||||
end
|
||||
if key == "3009" then
|
||||
lPower = tonumber(value)
|
||||
end
|
||||
|
||||
local lPresetChannelFrequency = "-" -- ID 3000
|
||||
local lPresetChannel = "-" -- ID 3001
|
||||
local lFrequency = "-" -- ID 3002
|
||||
|
||||
if ExportScript.AF.genericRadio == 0 or ExportScript.AF.genericRadio > ExportScript.genericRadioConf['maxRadios'] then
|
||||
if ExportScript.AF.genericRadio ~= 0 then
|
||||
ExportScript.Tools.WriteToLog("Radio Nr. "..ExportScript.AF.genericRadio.." not defined.")
|
||||
end
|
||||
ExportScript.Tools.SendDataDAC("3000", lPresetChannelFrequency)
|
||||
ExportScript.Tools.SendDataDAC("3001", lPresetChannel)
|
||||
ExportScript.Tools.SendDataDAC("3002", lFrequency)
|
||||
ExportScript.Tools.SendDataDAC("3010", 0)
|
||||
ExportScript.Tools.SendDataDAC("3011", 0)
|
||||
ExportScript.Tools.SendDataDAC("3012", 0)
|
||||
ExportScript.Tools.SendDataDAC("3013", 0)
|
||||
return
|
||||
end
|
||||
|
||||
---------------------------------------------------
|
||||
local lRADIO = GetDevice(ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['DeviceID'])
|
||||
|
||||
-- check status of the radio
|
||||
if ExportScript.AF.genericRadioPower[ExportScript.AF.genericRadio] == nil then
|
||||
if lRADIO:is_on() then
|
||||
ExportScript.AF.genericRadioPower[ExportScript.AF.genericRadio] = 1.0
|
||||
else
|
||||
ExportScript.AF.genericRadioPower[ExportScript.AF.genericRadio] = 0.0
|
||||
end
|
||||
end
|
||||
|
||||
-- check Manual/Preset switch
|
||||
if ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['ManualPreset'] ~= nil then
|
||||
if ExportScript.AF.genericRadioPresetManual[ExportScript.AF.genericRadio] == nil then
|
||||
ExportScript.AF.genericRadioPresetManual[ExportScript.AF.genericRadio] = ((ExportScript.Tools.round(lMainPanelDevice:get_argument_value(ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['ManualPreset']['ArgumentID']), 1) == ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['ManualPreset']['ValueOn']) and 1 or 0)
|
||||
end
|
||||
else
|
||||
ExportScript.AF.genericRadioPresetManual[ExportScript.AF.genericRadio] = 0
|
||||
end
|
||||
|
||||
-- check Squelch switch
|
||||
if ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Squelch'] ~= nil then
|
||||
if ExportScript.AF.genericRadioSquelch[ExportScript.AF.genericRadio] == nil then
|
||||
ExportScript.AF.genericRadioSquelch[ExportScript.AF.genericRadio] = ((ExportScript.Tools.round(lMainPanelDevice:get_argument_value(ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Squelch']['ArgumentID']), 1) == ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Squelch']['ValueOn']) and 1 or 0)
|
||||
end
|
||||
else
|
||||
ExportScript.AF.genericRadioSquelch[ExportScript.AF.genericRadio] = 0
|
||||
end
|
||||
|
||||
if ExportScript.AF.genericRadioPreset[ExportScript.AF.genericRadio] == nil then
|
||||
ExportScript.AF.genericRadioPreset[ExportScript.AF.genericRadio] = 0
|
||||
end
|
||||
|
||||
if lRADIO:is_on() then
|
||||
if ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset'] ~= nil then
|
||||
--lPresetChannel = string.format("%s", ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset']['List'][ExportScript.Tools.round(lMainPanelDevice:get_argument_value(ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset']['ArgumentID']), 2)])
|
||||
--ExportScript.Tools.WriteToLog('Preset index: '..ExportScript.Tools.dump(ExportScript.Tools.round(lMainPanelDevice:get_argument_value(ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset']['ArgumentID']), string.match(string.reverse(ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset']['Step']), '.'))))
|
||||
lPresetChannel = string.format("%s", ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset']['List'][ExportScript.Tools.round(lMainPanelDevice:get_argument_value(ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset']['ArgumentID']), string.match(string.reverse(ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset']['Step']), '.'))])
|
||||
end
|
||||
|
||||
lFrequency = ExportScript.Tools.round(lRADIO:get_frequency()/ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['FrequencyMultiplicator'] , 3, "floor")
|
||||
lFrequency = string.format(ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['FrequencyFormat'], lFrequency)
|
||||
|
||||
lPresetChannelFrequency = string.format("%s%s", lPresetChannel, lFrequency)
|
||||
lPresetChannelFrequency = lPresetChannelFrequency:gsub(" ", "0")
|
||||
lPresetChannelFrequency = lPresetChannelFrequency:gsub("-", "")
|
||||
--ExportScript.Tools.WriteToLog('lPresetChannel: '..ExportScript.Tools.dump(lPresetChannel))
|
||||
--ExportScript.Tools.WriteToLog('lFrequency: '..ExportScript.Tools.dump(lFrequency))
|
||||
--ExportScript.Tools.WriteToLog('lPresetChannelFrequency: '..ExportScript.Tools.dump(lPresetChannelFrequency))
|
||||
-- setFrequency == true
|
||||
if ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['setFrequency'] then
|
||||
-- minimal frequency, for example lMinFrequency1=220, lMinFrequency2=0 from 220.000
|
||||
local lMinFrequency1, lMinFrequency2 = math.modf(ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['minFrequency'])
|
||||
lMinFrequency2 = lMinFrequency2 * 1000
|
||||
-- maximal frequency, for example lMaxFrequency1=314, lMaxFrequency2=975 from 314.975
|
||||
local lMaxFrequency1, lMaxFrequency2 = math.modf(ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['maxFrequency'])
|
||||
lMaxFrequency2 = lMaxFrequency2 * 1000
|
||||
|
||||
if lRotaryFrequency_1 ~= nil and (lRotaryFrequency_1 >= 0.0 and lRotaryFrequency_1 <= 2.0) then
|
||||
|
||||
local lTmpFrequency = ExportScript.Tools.StrSplit(lFrequency, "%.") -- %. um den Punkt als Punkt zu suchen
|
||||
|
||||
if type(lTmpFrequency) == "table" and lTmpFrequency[1] ~= nil then
|
||||
lTmpFrequency[1] = tonumber(lTmpFrequency[1])
|
||||
if lTmpFrequency[2] == nil then
|
||||
lTmpFrequency[2] = 0
|
||||
else
|
||||
lTmpFrequency[2] = tonumber(lTmpFrequency[2])
|
||||
local ltmp = string.format("%.0f", lTmpFrequency[2] / ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['FrequencyStep'])
|
||||
lTmpFrequency[2] = ltmp * ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['FrequencyStep']
|
||||
end
|
||||
if lRotaryFrequency_1 < ExportScript.AF.genericRadioFrequency1 or lRotaryFrequency_1 == 0.0 or lRotaryFrequency_1 == 2.0 then
|
||||
lTmpFrequency[1] = lTmpFrequency[1] - 1
|
||||
if lTmpFrequency[1] == (lMinFrequency1 - 1) then
|
||||
lTmpFrequency[1] = lMaxFrequency1
|
||||
end
|
||||
ExportScript.AF.genericRadioFrequency1 = lRotaryFrequency_1
|
||||
else
|
||||
lTmpFrequency[1] = lTmpFrequency[1] + 1
|
||||
if lTmpFrequency[1] == (lMaxFrequency1 + 1) then
|
||||
lTmpFrequency[1] = lMinFrequency1
|
||||
end
|
||||
ExportScript.AF.genericRadioFrequency1 = lRotaryFrequency_1
|
||||
end
|
||||
|
||||
lTmpFrequency[2] = string.format("%.3f", lTmpFrequency[2] / 1000)
|
||||
lTmpFrequency = string.format("%.3f", lTmpFrequency[1] + lTmpFrequency[2])
|
||||
lTmpFrequency = tonumber(lTmpFrequency)
|
||||
lSetFrequency = {DeviceID = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['DeviceID'],
|
||||
Frequency = lTmpFrequency * 1000000}
|
||||
|
||||
else
|
||||
ExportScript.Tools.WriteToLog("1. generic "..ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Name'].." Radio, don't split frequency: "..lFrequency)
|
||||
end
|
||||
end
|
||||
|
||||
if lRotaryFrequency_2 ~= nil and (lRotaryFrequency_2 >= 0.0 and lRotaryFrequency_2 <= 2.0) then
|
||||
|
||||
local lTmpFrequency = ExportScript.Tools.StrSplit(lFrequency, "%.")
|
||||
|
||||
if type(lTmpFrequency) == "table" and lTmpFrequency[1] ~= nil then
|
||||
lTmpFrequency[1] = tonumber(lTmpFrequency[1])
|
||||
if lTmpFrequency[2] == nil then
|
||||
lTmpFrequency[2] = 0
|
||||
else
|
||||
lTmpFrequency[2] = tonumber(lTmpFrequency[2])
|
||||
local ltmp = string.format("%.0f", lTmpFrequency[2] / ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['FrequencyStep'])
|
||||
lTmpFrequency[2] = ltmp * ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['FrequencyStep']
|
||||
end
|
||||
if lRotaryFrequency_2 < ExportScript.AF.genericRadioFrequency2 or lRotaryFrequency_2 == 0.0 or lRotaryFrequency_2 == 2.0 then
|
||||
lTmpFrequency[2] = lTmpFrequency[2] - ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['FrequencyStep']
|
||||
if lTmpFrequency[2] == (ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['FrequencyStep'] * -1) then
|
||||
lTmpFrequency[2] = lMaxFrequency2
|
||||
end
|
||||
ExportScript.AF.genericRadioFrequency2 = lRotaryFrequency_2
|
||||
else
|
||||
lTmpFrequency[2] = lTmpFrequency[2] + ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['FrequencyStep']
|
||||
if lTmpFrequency[2] == (lMaxFrequency2 + ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['FrequencyStep']) then
|
||||
lTmpFrequency[2] = 0
|
||||
end
|
||||
ExportScript.AF.genericRadioFrequency2 = lRotaryFrequency_2
|
||||
end
|
||||
|
||||
lTmpFrequency[2] = string.format("%.3f", lTmpFrequency[2] / 1000)
|
||||
lTmpFrequency = string.format("%.3f", lTmpFrequency[1] + lTmpFrequency[2])
|
||||
lTmpFrequency = tonumber(lTmpFrequency)
|
||||
lSetFrequency = {DeviceID = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['DeviceID'],
|
||||
Frequency = lTmpFrequency * 1000000}
|
||||
|
||||
else
|
||||
ExportScript.Tools.WriteToLog("2. generic "..ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Name'].." Radio, don't split frequency: "..lFrequency)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset'] ~= nil then
|
||||
if lPreset ~= nil and (lPreset >= 0.0 and lPreset <= 2.0) then
|
||||
if ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset']['ButtonID2'] == nil and ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset']['Step2'] == nil then
|
||||
local lTempPresetKeys = {}
|
||||
for k,v in pairs(ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset']['List']) do
|
||||
table.insert(lTempPresetKeys, k)
|
||||
end
|
||||
|
||||
local lMinKey = math.min(unpack(lTempPresetKeys))
|
||||
local lMaxKey = math.max(unpack(lTempPresetKeys))
|
||||
|
||||
if lPreset > ExportScript.AF.genericRadioPreset[ExportScript.AF.genericRadio] then
|
||||
ExportScript.AF.genericRadioPreset[ExportScript.AF.genericRadio] = ExportScript.AF.genericRadioPreset[ExportScript.AF.genericRadio] + ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset']['Step']
|
||||
if ExportScript.AF.genericRadioPreset[ExportScript.AF.genericRadio] > lMaxKey then
|
||||
ExportScript.AF.genericRadioPreset[ExportScript.AF.genericRadio] = lMinKey
|
||||
end
|
||||
else
|
||||
ExportScript.AF.genericRadioPreset[ExportScript.AF.genericRadio] = ExportScript.AF.genericRadioPreset[ExportScript.AF.genericRadio] - ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset']['Step']
|
||||
if ExportScript.AF.genericRadioPreset[ExportScript.AF.genericRadio] < lMinKey then
|
||||
ExportScript.AF.genericRadioPreset[ExportScript.AF.genericRadio] = lMaxKey
|
||||
end
|
||||
end
|
||||
lClickAction = {DeviceID = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['DeviceID'],
|
||||
ButtonID = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset']['ButtonID'],
|
||||
Value = ExportScript.AF.genericRadioPreset[ExportScript.AF.genericRadio]}
|
||||
else
|
||||
if lPreset < ExportScript.AF.genericRadioPreset[ExportScript.AF.genericRadio] or lPreset == 0.0 or lPreset == 2.0 then
|
||||
lClickAction = {DeviceID = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['DeviceID'],
|
||||
ButtonID = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset']['ButtonID'],
|
||||
Value = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset']['Step']}
|
||||
ExportScript.AF.genericRadioPreset[ExportScript.AF.genericRadio] = lPreset
|
||||
else
|
||||
lClickAction = {DeviceID = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['DeviceID'],
|
||||
ButtonID = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset']['ButtonID2'],
|
||||
Value = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Preset']['Step2']}
|
||||
ExportScript.AF.genericRadioPreset[ExportScript.AF.genericRadio] = lPreset
|
||||
end
|
||||
ExportScript.AF.genericRadioPreset[ExportScript.AF.genericRadio] = lPreset
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Volume'] ~= nil then
|
||||
if lVolume ~= nil and (lVolume >= 0.0 and lVolume <= 2.0) then
|
||||
lVolume = lVolume / 2
|
||||
lClickAction = {DeviceID = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['DeviceID'],
|
||||
ButtonID = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Volume']['ButtonID'],
|
||||
Value = lVolume}
|
||||
end
|
||||
end
|
||||
|
||||
if ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Load'] ~= nil then
|
||||
if ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Load']['ButtonID'] ~= nil then
|
||||
if lLoad ~= nil and (lLoad == 0.0 or lLoad <= 1.0) then
|
||||
lClickAction = {DeviceID = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['DeviceID'],
|
||||
ButtonID = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Load']['ButtonID'],
|
||||
Value = lLoad}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Squelch'] ~= nil then
|
||||
if lSquelch ~= nil and (lSquelch == 0.0 or lSquelch <= 1.0) then
|
||||
if lSquelch == 1.0 and ExportScript.AF.genericRadioSquelch[ExportScript.AF.genericRadio] == 1.0 then
|
||||
-- Squelch off
|
||||
lSquelch = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Squelch']['ValueOff']
|
||||
ExportScript.AF.genericRadioSquelch[ExportScript.AF.genericRadio] = 0
|
||||
elseif lSquelch == 1.0 and ExportScript.AF.genericRadioSquelch[ExportScript.AF.genericRadio] == 0 then
|
||||
-- Squelch on
|
||||
lSquelch = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Squelch']['ValueOn']
|
||||
ExportScript.AF.genericRadioSquelch[ExportScript.AF.genericRadio] = 1.0
|
||||
end
|
||||
lClickAction = {DeviceID = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['DeviceID'],
|
||||
ButtonID = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Squelch']['ButtonID'],
|
||||
Value = lSquelch}
|
||||
end
|
||||
end
|
||||
|
||||
if ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['ManualPreset'] ~= nil then
|
||||
if lManualPreset ~= nil and (lManualPreset == 0.0 or lManualPreset <= 1.0) then
|
||||
if lManualPreset == 1.0 and ExportScript.AF.genericRadioPresetManual[ExportScript.AF.genericRadio] == 1.0 then
|
||||
-- Manual
|
||||
lManualPreset = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['ManualPreset']['ValueManual']
|
||||
ExportScript.AF.genericRadioPresetManual[ExportScript.AF.genericRadio] = 0
|
||||
elseif lManualPreset == 1.0 and ExportScript.AF.genericRadioPresetManual[ExportScript.AF.genericRadio] == 0 then
|
||||
-- Preset
|
||||
lManualPreset = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['ManualPreset']['ValuePreset']
|
||||
ExportScript.AF.genericRadioPresetManual[ExportScript.AF.genericRadio] = 1.0
|
||||
end
|
||||
lClickAction = {DeviceID = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['DeviceID'],
|
||||
ButtonID = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['ManualPreset']['ButtonID'],
|
||||
Value = lManualPreset}
|
||||
end
|
||||
end
|
||||
|
||||
if ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Power'] ~= nil then
|
||||
if lPower ~= nil and (lPower == 0.0 or lPower <= 1.0) then
|
||||
if lPower == 1.0 and ExportScript.AF.genericRadioPower[ExportScript.AF.genericRadio] == 1.0 then
|
||||
-- Power off
|
||||
lPower = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Power']['ValueOff']
|
||||
ExportScript.AF.genericRadioPower[ExportScript.AF.genericRadio] = 0
|
||||
elseif lPower == 1.0 and ExportScript.AF.genericRadioPower[ExportScript.AF.genericRadio] == 0 then
|
||||
--Power on
|
||||
lPower = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Power']['ValueOn']
|
||||
ExportScript.AF.genericRadioPower[ExportScript.AF.genericRadio] = 1.0
|
||||
end
|
||||
lClickAction = {DeviceID = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['DeviceID'],
|
||||
ButtonID = ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Power']['ButtonID'],
|
||||
Value = lPower}
|
||||
end
|
||||
end
|
||||
|
||||
ExportScript.Tools.SendDataDAC("3000", lPresetChannelFrequency)
|
||||
ExportScript.Tools.SendDataDAC("3001", lPresetChannel)
|
||||
ExportScript.Tools.SendDataDAC("3002", lFrequency)
|
||||
ExportScript.Tools.SendDataDAC("3010", ExportScript.AF.genericRadioPower[ExportScript.AF.genericRadio])
|
||||
ExportScript.Tools.SendDataDAC("3011", ExportScript.AF.genericRadioPresetManual[ExportScript.AF.genericRadio])
|
||||
ExportScript.Tools.SendDataDAC("3012", ExportScript.AF.genericRadioSquelch[ExportScript.AF.genericRadio])
|
||||
-- is only for radios with a lamp for Load button, for example Ka-50 Load Button is Autotune with lamp
|
||||
if ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Load'] ~= nil and ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Load']['ArgumentID'] ~= nil then
|
||||
ExportScript.Tools.SendDataDAC("3013", lMainPanelDevice:get_argument_value(ExportScript.genericRadioConf[ExportScript.AF.genericRadio]['Load']['ArgumentID']))
|
||||
else
|
||||
ExportScript.Tools.SendDataDAC("3013", 0)
|
||||
end
|
||||
|
||||
if lClickAction ~= nil then
|
||||
lDevice = GetDevice(lClickAction.DeviceID)
|
||||
if type(lDevice) == "table" then
|
||||
--ExportScript.Tools.WriteToLog("GetDevice("..lClickAction.DeviceID.."):performClickableAction("..lClickAction.ButtonID..", "..lClickAction.Value..") ")
|
||||
lDevice:performClickableAction(lClickAction.ButtonID, lClickAction.Value)
|
||||
end
|
||||
elseif lSetFrequency ~= nil then
|
||||
lDevice = GetDevice(lSetFrequency.DeviceID)
|
||||
if type(lDevice) == "table" and lDevice:is_on() then
|
||||
--ExportScript.Tools.WriteToLog("GetDevice("..lSetFrequency.DeviceID.."):set_frequency("..lSetFrequency.Frequency..") ")
|
||||
lDevice:set_frequency(lSetFrequency.Frequency)
|
||||
else
|
||||
ExportScript.Tools.WriteToLog("GetDevice("..lSetFrequency.DeviceID..") is no table or Radio is not on")
|
||||
end
|
||||
end
|
||||
end
|
||||
161
lib/utf8.lua
Normal file
161
lib/utf8.lua
Normal file
@@ -0,0 +1,161 @@
|
||||
-- Provides UTF-8 aware string functions implemented in pure lua:
|
||||
-- * string.utf8len(s)
|
||||
-- * string.utf8sub(s, i, j)
|
||||
--
|
||||
-- All functions behave as their non UTF-8 aware counterparts with the exception
|
||||
-- that UTF-8 characters are used instead of bytes for all units.
|
||||
--
|
||||
-- Note: all validations had been removed due to awesome usage specifics.
|
||||
--[[
|
||||
Copyright (c) 2006-2007, Kyle Smith
|
||||
Modified by Alexander Yakushev, 2010-2013.
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the author nor the names of its contributors may be
|
||||
used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
--]]
|
||||
|
||||
-- ABNF from RFC 3629
|
||||
--
|
||||
-- UTF8-octets = *( UTF8-char )
|
||||
-- UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
|
||||
-- UTF8-1 = %x00-7F
|
||||
-- UTF8-2 = %xC2-DF UTF8-tail
|
||||
-- UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
|
||||
-- %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
|
||||
-- UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
|
||||
-- %xF4 %x80-8F 2( UTF8-tail )
|
||||
-- UTF8-tail = %x80-BF
|
||||
--
|
||||
|
||||
-- returns the number of bytes used by the UTF-8 character at byte i in s
|
||||
-- also doubles as a UTF-8 character validator
|
||||
|
||||
local utf8 = {}
|
||||
|
||||
function utf8.charbytes (s, i)
|
||||
-- argument defaults
|
||||
i = i or 1
|
||||
local c = string.byte(s, i)
|
||||
|
||||
-- determine bytes needed for character, based on RFC 3629
|
||||
if c > 0 and c <= 127 then
|
||||
-- UTF8-1
|
||||
return 1
|
||||
elseif c >= 194 and c <= 223 then
|
||||
-- UTF8-2
|
||||
local c2 = string.byte(s, i + 1)
|
||||
return 2
|
||||
elseif c >= 224 and c <= 239 then
|
||||
-- UTF8-3
|
||||
local c2 = s:byte(i + 1)
|
||||
local c3 = s:byte(i + 2)
|
||||
return 3
|
||||
elseif c >= 240 and c <= 244 then
|
||||
-- UTF8-4
|
||||
local c2 = s:byte(i + 1)
|
||||
local c3 = s:byte(i + 2)
|
||||
local c4 = s:byte(i + 3)
|
||||
return 4
|
||||
end
|
||||
end
|
||||
|
||||
-- returns the number of characters in a UTF-8 string
|
||||
function utf8.len (s)
|
||||
local pos = 1
|
||||
local bytes = string.len(s)
|
||||
local len = 0
|
||||
|
||||
while pos <= bytes and len ~= chars do
|
||||
local c = string.byte(s,pos)
|
||||
len = len + 1
|
||||
|
||||
pos = pos + utf8.charbytes(s, pos)
|
||||
end
|
||||
|
||||
if chars ~= nil then
|
||||
return pos - 1
|
||||
end
|
||||
|
||||
return len
|
||||
end
|
||||
|
||||
-- functions identically to string.sub except that i and j are UTF-8 characters
|
||||
-- instead of bytes
|
||||
function utf8.sub (s, i, j)
|
||||
j = j or -1
|
||||
|
||||
if i == nil then
|
||||
return ""
|
||||
end
|
||||
|
||||
local pos = 1
|
||||
local bytes = string.len(s)
|
||||
local len = 0
|
||||
|
||||
-- only set l if i or j is negative
|
||||
local l = (i >= 0 and j >= 0) or utf8.len(s)
|
||||
local startChar = (i >= 0) and i or l + i + 1
|
||||
local endChar = (j >= 0) and j or l + j + 1
|
||||
|
||||
-- can't have start before end!
|
||||
if startChar > endChar then
|
||||
return ""
|
||||
end
|
||||
|
||||
-- byte offsets to pass to string.sub
|
||||
local startByte, endByte = 1, bytes
|
||||
|
||||
while pos <= bytes do
|
||||
len = len + 1
|
||||
|
||||
if len == startChar then
|
||||
startByte = pos
|
||||
end
|
||||
|
||||
pos = pos + utf8.charbytes(s, pos)
|
||||
|
||||
if len == endChar then
|
||||
endByte = pos - 1
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return string.sub(s, startByte, endByte)
|
||||
end
|
||||
|
||||
-- replace UTF-8 characters based on a mapping table
|
||||
function utf8.replace (s, mapping)
|
||||
local pos = 1
|
||||
local bytes = string.len(s)
|
||||
local charbytes
|
||||
local newstr = ""
|
||||
|
||||
while pos <= bytes do
|
||||
charbytes = utf8.charbytes(s, pos)
|
||||
local c = string.sub(s, pos, pos + charbytes - 1)
|
||||
newstr = newstr .. (mapping[c] or c)
|
||||
pos = pos + charbytes
|
||||
end
|
||||
|
||||
return newstr
|
||||
end
|
||||
|
||||
return utf8
|
||||
Reference in New Issue
Block a user