--[[ ======================================== LUA BLOCK FUNCTION - DOCUMENTATION ======================================== This Lua function processes input tag vectors and returns output tag vectors. The system expects the following structure: INPUT FORMAT: input = { ["1"] = { -- Tag index as string key { value = 123.45, quality = 1, timestamp = 1714567890 }, { value = 124.56, quality = 1, timestamp = 1714567891 }, -- ... more vector elements }, ["2"] = { ... }, -- ... more tags (up to 16) } OUTPUT FORMAT: output = { ["1"] = { -- Tag index as string key { value = 123.45, quality = 1, timestamp = 1714567890 }, { value = 124.56, quality = 1, timestamp = 1714567891 }, -- ... more vector elements }, ["2"] = { ... }, -- ... more tags (matching output count) } DATA STRUCTURE: Each vector element is a table with: - value: number (the actual tag value) - quality: integer (quality indicator - see IEC 60870-5-104 standard) - timestamp: integer (Unix timestamp in milliseconds) IMPORTANT: - Input tag indices start from 1 and go up to 16 - Output tag indices should match your output configuration - Always return a table, even if empty - Handle nil/missing input data gracefully - The system calls this function periodically with buffered data - Click the Help button for detailed documentation on quality flags and examples ======================================== ]] function DirectMap(input) -- Handle nil input if input == nil then return {} end local output = {} -- ------------------------------------------------- -- Process 16 input tags -- Each tag is indexed as a string: "1", "2", etc. -- ------------------------------------------------- for tag = 1, 16 do local key = tostring(tag) local inVec = input[key] -- Handle missing/nil input vector if inVec == nil then local outVec = {} -- Optionally: output[key] = outVec -- Handle invalid input type elseif type(inVec) ~= "table" then local outVec = {} -- Optionally: output[key] = outVec -- Process valid input vector else local outVec = {} -- Copy/process each element in the input vector for i, v in ipairs(inVec) do local d = { value = v.value or 0, -- Default to 0 if missing quality = v.quality or 0, -- Default to 0 if missing timestamp = v.timestamp or 0 -- Default to 0 if missing } -- ADD YOUR CUSTOM PROCESSING LOGIC HERE -- Example: d.value = d.value * 2 -- Double the value -- Example: d.value = math.floor(d.value) -- Round down table.insert(outVec, d) end -- Assign processed vector to output output[key] = outVec end end return output end