@@ -203,7 +203,7 @@ local function getDatatypeBitlength(datatypeInfo)
203203 elseif datatypeInfo .type == " StringT" or datatypeInfo .type == " OctetStringT" then
204204 return tonumber (datatypeInfo .fixedLength )
205205 elseif datatypeInfo .type == " ArrayT" then
206- return tonumber (datatypeInfo .count )* getDatatypeBitlength (datatypeInfo .Datatype )
206+ return tonumber (datatypeInfo .count )* getDatatypeBitlength (datatypeInfo .SimpleDatatype )
207207 end
208208end
209209
@@ -218,122 +218,121 @@ local defaultValueForSimpleType = {
218218
219219local function makeExpectedPayload (compiledTable )
220220 local expectedTable = {}
221- for _ , dataPointInfo in pairs (compiledTable ) do
222- dataPointInfo = renameDatatype (dataPointInfo )
223- if dataPointInfo .Datatype .type == ' ArrayT' then
224- expectedTable [dataPointInfo .Name ] = {}
225- for i = 1 , dataPointInfo .Datatype .count do
226- expectedTable [dataPointInfo .Name ][" element_" .. tostring (i )] = {}
227- expectedTable [dataPointInfo .Name ][" element_" .. tostring (i )].value = defaultValueForSimpleType [dataPointInfo .Datatype .Datatype .type ]
228- end
229- elseif dataPointInfo .Datatype .type == ' RecordT' then
230- expectedTable [dataPointInfo .Name ] = {}
231- local repeatedNames = {}
232- for _ , recordInfo in ipairs (dataPointInfo .Datatype .RecordItem ) do
233- local recordName = recordInfo .Name
234- if expectedTable [dataPointInfo .Name ][recordInfo .Name ] then
235- table.insert (repeatedNames , recordInfo .Name )
236- expectedTable [dataPointInfo .Name ][recordInfo .Name .. ' _1' ] = copy (expectedTable [dataPointInfo .Name ][recordInfo .Name ])
237- local repeatedIndex = 2
238- recordName = recordInfo .Name .. ' _' .. tostring (repeatedIndex )
239- while expectedTable [dataPointInfo .Name ][recordName ] do
240- recordName = recordInfo .Name .. ' _' .. tostring (repeatedIndex )
241- repeatedIndex = repeatedIndex + 1
242- end
243- end
244- expectedTable [dataPointInfo .Name ][recordName ] = {}
245- expectedTable [dataPointInfo .Name ][recordName ].value = defaultValueForSimpleType [recordInfo .Datatype .type ]
246- end
247- for i , recordName in ipairs (repeatedNames ) do
248- expectedTable [dataPointInfo .Name ][recordName ] = nil
221+ for dataPointId , dataPointInfo in pairs (compiledTable ) do
222+ if dataPointInfo .subindeces then
223+ expectedTable [dataPointId ] = {}
224+ for subindexId , subindexInfo in pairs (dataPointInfo .subindeces ) do
225+ expectedTable [dataPointId ][subindexId ] = {
226+ value = defaultValueForSimpleType [subindexInfo .info .type ]
227+ }
249228 end
250229 else
251- expectedTable [dataPointInfo .Name ] = {}
252- if dataPointInfo .Datatype then
253- expectedTable [dataPointInfo .Name ].value = defaultValueForSimpleType [dataPointInfo .Datatype .type ]
254- elseif dataPointInfo .Datatype then
255- expectedTable [dataPointInfo .Name ].value = defaultValueForSimpleType [dataPointInfo .Datatype .type ]
256- end
230+ expectedTable [dataPointId ] = {
231+ value = defaultValueForSimpleType [dataPointInfo .info .type ]
232+ }
257233 end
258234 end
259235 return expectedTable
260236end
261237funcs .makeExpectedPayload = makeExpectedPayload
262238
263- local function compileProcessDataTable (processDataInfo , selectedTable )
239+ local function getSingleInfoTable (rawInfoTable )
240+ local info = copy (rawInfoTable )
241+ if rawInfoTable .Datatype then
242+ for key , value in pairs (rawInfoTable .Datatype ) do
243+ info [key ] = value
244+ end
245+ end
246+ if rawInfoTable .SimpleDatatype then
247+ for key , value in pairs (rawInfoTable .SimpleDatatype ) do
248+ info [key ] = value
249+ end
250+ end
251+ info .type = info [" xsi:type" ]
252+ info [" xsi:type" ] = nil
253+ info .RecordItem = nil
254+ info .Datatype = nil
255+ info .SimpleDatatype = nil
256+ return info
257+ end
258+
259+ local function compileDataPointTable (dataInfo , selectedTable )
260+ if not dataInfo then
261+ return nil
262+ end
264263 local compiledTable = {}
265- if selectedTable [" 0" ] == true then
266- local singleProcessData = copy (processDataInfo )
267- singleProcessData .bitOffset = 0
268- singleProcessData .Frequency = 0
269- singleProcessData .requested = false
270- compiledTable [singleProcessData .Name ] = singleProcessData
271- -- table.insert(compiledTable, singleProcessData)
272- elseif selectedTable [" 1" ] ~= nil then
264+ if dataInfo .Datatype [" xsi:type" ] == " ArrayT" or dataInfo .Datatype [" xsi:type" ] == " RecordT" then
273265 for subindex , selected in pairs (selectedTable ) do
274266 if selected == true and subindex ~= " 0" and subindex ~= " subindexAccessSupported" then
275- if processDataInfo .Datatype [" xsi:type" ] == " ArrayT" then
276- local singleProcessData = copy (processDataInfo .Datatype )
277- singleProcessData .subindex = subindex
278- singleProcessData .bitOffset = tonumber (subindex ) * getDatatypeBitlength (singleProcessData .SimpleDatatype )
279- singleProcessData .Frequency = 0
280- singleProcessData .requested = false
281- singleProcessData .Name = processDataInfo .Name .. ' _element' .. tostring (subindex )
282- compiledTable [singleProcessData .Name ] = singleProcessData
283- -- table.insert(compiledTable, singleProcessData)
284- elseif processDataInfo .Datatype [" xsi:type" ] == " RecordT" then
267+ if not compiledTable [dataInfo .Name ] then
268+ local info = copy (dataInfo )
269+ for key , value in pairs (dataInfo .Datatype ) do
270+ info [key ] = value
271+ end
272+ info .type = info [" xsi:type" ]
273+ info [" xsi:type" ] = nil
274+ if dataInfo .Datatype [" xsi:type" ] == " ArrayT" then
275+ info .SimpleDatatype .type = info .SimpleDatatype [" xsi:type" ]
276+ end
277+ info .BitLength = getDatatypeBitlength (info )
278+ info .RecordItem = nil
279+ info .SimpleDatatype = nil
280+ compiledTable [dataInfo .Name ] = {
281+ info = info ,
282+ subindeces = {}
283+ }
284+ end
285+ if dataInfo .Datatype [" xsi:type" ] == " ArrayT" then
286+ local singleProcessDatatype = copy (dataInfo .Datatype .SimpleDatatype )
287+ singleProcessDatatype .subindex = subindex
288+ singleProcessDatatype .type = singleProcessDatatype [" xsi:type" ]
289+ singleProcessDatatype .bitOffset = (tonumber (subindex )- 1 ) * getDatatypeBitlength (singleProcessDatatype )
290+ singleProcessDatatype .Name = dataInfo .Name .. ' _element' .. tostring (subindex )
291+ compiledTable [dataInfo .Name ].subindeces [singleProcessDatatype .Name ] = {
292+ info = singleProcessDatatype
293+ }
294+
295+ elseif dataInfo .Datatype [" xsi:type" ] == " RecordT" then
285296 local subindexMap = {}
286- for i , subindexInfo in ipairs (processDataInfo .Datatype .RecordItem ) do
297+ for i , subindexInfo in ipairs (dataInfo .Datatype .RecordItem ) do
287298 subindexMap [subindexInfo .subindex ] = i
288299 end
289- local singleProcessData = copy (processDataInfo .Datatype .RecordItem [subindexMap [subindex ]])
290- singleProcessData .Frequency = 0
291- singleProcessData .requested = false
292- compiledTable [singleProcessData .Name ] = singleProcessData
293- -- table.insert(compiledTable, singleProcessData)
300+ local singleProcessDatatype = copy (dataInfo .Datatype .RecordItem [subindexMap [subindex ]])
301+ singleProcessDatatype .subindex = subindex
302+ if not singleProcessDatatype .Name then
303+ singleProcessDatatype .Name = " Null parameter"
304+ end
305+ compiledTable [dataInfo .Name ].subindeces [singleProcessDatatype .Name ] = {
306+ info = getSingleInfoTable (singleProcessDatatype )
307+ }
294308 end
295309 end
296310 end
311+ elseif selectedTable [" 0" ] == true then
312+ compiledTable [dataInfo .Name ] = {
313+ info = getSingleInfoTable (dataInfo )
314+ }
297315 end
298316 if getTableSize (compiledTable ) == 0 then
299317 return nil
300318 end
301319 return compiledTable
302320end
303- funcs .compileProcessDataTable = compileProcessDataTable
321+ funcs .compileProcessDataTable = compileDataPointTable
304322
305323local function compileParametersTable (iodd , selectedTable )
306324 local compiledTable = {}
307325 for index , subindeces in pairs (selectedTable ) do
308- if subindeces [" 0" ] == true then
309- local ioddIndexdata = iodd :getParameterInfoFromIndex (index )
310- ioddIndexdata .subindex = " 0"
311- ioddIndexdata .Frequency = 0
312- ioddIndexdata .requested = false
313- compiledTable [ioddIndexdata .Name ] = ioddIndexdata
314- -- table.insert(compiledTable, ioddIndexdata)
315- elseif subindeces [" 1" ] ~= nil then
316- for subindex , selected in pairs (subindeces ) do
317- if selected == true and subindex ~= " 0" and subindex ~= " subindexAccessSupported" then
318- local ioddIndexdata = iodd :getParameterInfoFromIndex (index )
319- if ioddIndexdata .Datatype [" xsi:type" ] == " ArrayT" then
320- local ioddSubIndexdata = ioddIndexdata .Datatype
321- ioddSubIndexdata .index = index
322- ioddSubIndexdata .subindex = subindex
323- ioddSubIndexdata .Frequency = 0
324- ioddSubIndexdata .requested = false
325- ioddSubIndexdata .Name = ioddIndexdata .Name .. ' _element' .. tostring (subindex )
326- -- table.insert(compiledTable, ioddSubIndexdata)
327- compiledTable [ioddIndexdata .Name ] = ioddSubIndexdata
328- elseif ioddIndexdata .Datatype [" xsi:type" ] == " RecordT" then
329- local ioddSubIndexdata = iodd :getSubIndexParameter (index , subindex )
330- ioddSubIndexdata .index = index
331- ioddSubIndexdata .Frequency = 0
332- ioddSubIndexdata .requested = false
333- -- table.insert(compiledTable, ioddSubIndexdata)
334- compiledTable [ioddSubIndexdata .Name ] = ioddSubIndexdata
326+ for subindex , selected in pairs (subindeces ) do
327+ if selected == true then
328+ local ioddIndexdata = iodd :getParameterInfoFromIndex (index )
329+ local compiledDataPointTable = compileDataPointTable (ioddIndexdata , subindeces )
330+ if compiledDataPointTable then
331+ for key , value in pairs (compiledDataPointTable ) do
332+ compiledTable [key ] = value
335333 end
336334 end
335+ break
337336 end
338337 end
339338 end
0 commit comments