public static SmlListEntry Create(SmlBase a_baseNode) { var list = a_baseNode as SmlList; if (list == null || list.Length != 7) { return(null); } var objName = list.GetElement(0) as SmlString; if (objName == null) { return(null); } var obis = GenerateObis(objName); if (obis == null) { return(null); } UInt64?status = null; switch (list.GetElement(1).SmlFieldType) { case SmlFieldType.Optional: break; case SmlFieldType.Unsigned8: status = (list.GetElement(1) as SmlUnsigned8).Value; break; case SmlFieldType.Unsigned16: status = (list.GetElement(1) as SmlUnsigned16).Value; break; case SmlFieldType.Unsigned32: status = (list.GetElement(1) as SmlUnsigned32).Value; break; case SmlFieldType.Unsigned64: status = (list.GetElement(1) as SmlUnsigned64).Value; break; default: return(null); } SmlTime valTime = null; if (!list.GetElement(2).IsOptional) { valTime = SmlTime.Create(list.GetElement(2)); if (valTime == null) { return(null); } } uint?unit = (list.GetElement(3) as SmlUnsigned8)?.Value; if (list.GetElement(3).IsOptional) { unit = null; } int?scaler = (list.GetElement(4) as SmlSigned8)?.Value; if (scaler == null && !list.GetElement(4).IsOptional) { return(null); } var value = list.GetElement(5); if (list.GetElement(5).IsOptional) { return(null); } var smlSignature = list.GetElement(6); if (list.GetElement(6).IsOptional) { smlSignature = null; } return(new SmlListEntry(obis, status, valTime, unit, scaler, value, smlSignature)); }
internal static SmlMessageBody Create(SmlBase a_baseNode) { var list = a_baseNode as SmlList; if (list == null || list.Length != 7) { return(null); } var clientId = list.GetElement(0) as SmlString; if (clientId == null && !list.GetElement(0).IsOptional) { return(null); } var serverId = list.GetElement(1) as SmlString; if (serverId == null) { return(null); } var listName = list.GetElement(2) as SmlString; if (listName == null && !list.GetElement(2).IsOptional) { return(null); } SmlTime actSensorTime = null; if (!list.GetElement(3).IsOptional) { actSensorTime = SmlTime.Create(list.GetElement(3)); if (actSensorTime == null) { return(null); } } var valListNode = list.GetElement(4) as SmlList; if (valListNode == null) { return(null); } var valList = new List <SmlListEntry>(valListNode.Length); for (int i = 0; i < valListNode.Length; i++) { var listEntry = SmlListEntry.Create(valListNode.GetElement(i)); if (listEntry == null) { return(null); } valList.Add(listEntry); } var smlSignature = list.GetElement(5); SmlTime actGatewayTime = null; if (!list.GetElement(6).IsOptional) { actGatewayTime = SmlTime.Create(list.GetElement(6)); if (actGatewayTime == null) { return(null); } } return(new SmlGetListResponse(clientId, serverId, listName, actSensorTime, valList, smlSignature, actGatewayTime)); }
internal static SmlMessageBody Create(SmlBase a_baseNode) { var list = a_baseNode as SmlList; if (list == null || list.Length != 6) { return(null); } var codePage = list.GetElement(0) as SmlString; if (codePage == null && !list.GetElement(0).IsOptional) { return(null); } var encoding = codePage != null?Encoding.GetEncoding(codePage.ValueString) : null; var clientId = list.GetElement(1) as SmlString; if (clientId == null && !list.GetElement(1).IsOptional) { return(null); } var requestFileId = list.GetElement(2) as SmlString; if (requestFileId == null) { return(null); } var serverId = list.GetElement(3) as SmlString; if (serverId == null) { return(null); } var refTime = list.GetElement(4); SmlTime time; if (refTime.IsOptional) { time = null; } else { time = SmlTime.Create(refTime); if (time == null) { return(null); } } var version = list.GetElement(5) as SmlUnsigned8; if (version == null && !list.GetElement(1).IsOptional) { return(null); } return(new SmlOpenResponse(codePage, clientId, requestFileId, serverId, time, version)); }