local m = {}

-- default co-mapping based on current PDB
m.CO = {}
m.CO.sdCardErrorCo          = 55
m.CO.sdCardErrorCodeCo      = 56
m.CO.activateCo             = 57
m.CO.loggerStateCo          = 58
m.CO.sdCardBufferStateCo    = 59
m.CO.sdCardBufferValueCo    = 60

function m.AddCosToMap()
    Logger:Info("-- datalogger_module.lua: add COs")
    local urn = deviceUrn_base .. ":DataLogger-App:"
    helper.AddAssociatedCoToMap(m.CO.sdCardErrorCo, "CRT", "1.002", urn .. "SdCardError")
    helper.AddAssociatedCoToMap(m.CO.sdCardErrorCodeCo, "CR", "20.*", urn .. "SdCardErrorCode")
    helper.AddAssociatedCoToMap(m.CO.activateCo, "CRW", "1.001", urn .. "Recording")
    helper.AddAssociatedCoToMap(m.CO.loggerStateCo, "CRT", "1.002", urn .. "RecordingState")
    helper.AddAssociatedCoToMap(m.CO.sdCardBufferStateCo, "CR", "1.002", urn .. "SdCardBufferState")
    helper.AddAssociatedCoToMap(m.CO.sdCardBufferValueCo, "CR", "5.001", urn .. "SdCardBufferValue")
end

function m.Configure(config)
	Logger:Info("-- datalogger_module.lua: configure parameter")
    helper.LogConfiguration("DataLogger-App", config)
    local channel = device:AddChannel("DataLogger-App")
    channel.StartId = 1900
    channel.FieldHandlerName = "DscKnxLoggerAppPrgNG"
    channel.TypeURN = "de.gira.schema.channels.DataLogger.App"    

    channel.Enabled = config.EnabledBool
    if channel.Enabled then
        local loggingFormats = { [0] = "ETS4", [1] = "ETS3" }
        local bufferTypes = { [0] = "Cyclic", [1] = "Static" }
        channel:AddParameterSet("DataLogger", "LoggingFormat", loggingFormats[config.LoggingFormat])
        channel:AddParameterSet("DataLogger", "BufferType", bufferTypes[config.BufferType])
    end
end

return m
