--[[
  helper.lua
  A place for some helper functions for the DscKnxAppPrgNG and ist modules.
]]--

local m = {}

function m.AddAssociatedCoToMap(co, flags, dpt, urn)
    if co ~= 0 and GroupValueService:IsGroupAddressAssociated(co) then
            Logger:Debug(string.format("-- helper.lua: add CO %d with flags '%s', dpt '%s' and urn '%s'", co, flags, dpt, urn))
            CoMapping:AddEntry(co, flags, dpt, urn)
    end
end

function m.GetAppPrg1Version()
	local downloadVersion = PropertyService:GetInterfaceObjectByTypeAndInstance(3, 1):GetPropertyById(13):GetValue():GetAsUInt(4,1)
	local downloadVersion2 = PropertyService:GetInterfaceObjectByTypeAndInstance(3, 1):GetPropertyById(13):GetValue():GetAsUInt(0,5)
	local downloadVersionMajor = downloadVersion >> 4
	local downloadVersionMinor = downloadVersion & 15 -- 15 -> 4bit
	return downloadVersionMajor,downloadVersionMinor
end

function m.GetAppPrg2Version()
	local downloadVersion = PropertyService:GetInterfaceObjectByTypeAndInstance(4, 1):GetPropertyById(13):GetValue():GetAsUInt(4,1)
	local downloadVersionMajor = downloadVersion >> 4
	local downloadVersionMinor = downloadVersion & 15 -- 15 -> 4bit
	return downloadVersionMajor,downloadVersionMinor
end

function m.LogConfiguration(title, config)
	Logger:Debug(title)
		for k,v in pairs(config) do
			Logger:Debug("	" .. k .. " - " .. tostring(v))
		end
end
		
return m
