private SmlGetListResponse(SmlString a_clientId, SmlString a_serverId, SmlString a_listName, SmlTime a_actSensorTime, List <SmlListEntry> a_values, SmlBase a_smlSignature, SmlTime a_actGatewayTime) { ClientId = a_clientId; ServerId = a_serverId; ListName = a_listName; ActSensorTime = a_actSensorTime; Values = a_values; SmlSignature = a_smlSignature; ActGatewayTime = a_actGatewayTime; }
private SmlListEntry(string a_obis, UInt64?a_status, SmlTime a_valTime, uint?a_unit, int?a_scaler, SmlBase a_valueNode, SmlBase a_smlSignature) { Obis = a_obis; Status = a_status; ValTime = a_valTime; Unit = a_unit; Scaler = a_scaler; ValueNode = a_valueNode; SmlSignature = a_smlSignature; Value = null; double factor = 1; if (a_scaler.HasValue) { factor = Math.Pow(10, a_scaler.Value); } switch (a_valueNode.SmlFieldType) { case SmlFieldType.Signed8: Value = (double)((a_valueNode as SmlSigned8).Value) * factor; break; case SmlFieldType.Signed16: Value = (double)((a_valueNode as SmlSigned16).Value) * factor; break; case SmlFieldType.Signed32: Value = (double)((a_valueNode as SmlSigned32).Value) * factor; break; case SmlFieldType.Signed64: Value = (double)((a_valueNode as SmlSigned64).Value) * factor; break; case SmlFieldType.Unsigned8: Value = (double)((a_valueNode as SmlUnsigned8).Value) * factor; break; case SmlFieldType.Unsigned16: Value = (double)((a_valueNode as SmlUnsigned16).Value) * factor; break; case SmlFieldType.Unsigned32: Value = (double)((a_valueNode as SmlUnsigned32).Value) * factor; break; case SmlFieldType.Unsigned64: Value = (double)((a_valueNode as SmlUnsigned64).Value) * factor; break; } }
internal static SmlMessageBody Create(SmlBase a_baseNode) { var list = a_baseNode as SmlList; if (list == null || list.Length != 1) { return(null); } var signature = list.GetElement(0); return(new SmlCloseResponse(signature)); }
internal static SmlMessageBody Create(SmlMessageType a_type, SmlBase a_baseNode) { switch (a_type) { case SmlMessageType.OpenResponse: return(SmlOpenResponse.Create(a_baseNode)); case SmlMessageType.CloseResponse: return(SmlCloseResponse.Create(a_baseNode)); case SmlMessageType.GetListResponse: return(SmlGetListResponse.Create(a_baseNode)); } return(new SmlMessageBody(a_baseNode)); }
public override ParseResult ContinuePopulate(byte a_byte) { try { switch (m_state) { case State.Done: m_state = State.Failed; return(ParseResult.Failed); case State.WaitForNextListElement: var res = m_actElement.ContinuePopulate(a_byte); switch (res) { case ParseResult.Failed: m_elements = null; m_state = State.Failed; return(ParseResult.Failed); case ParseResult.Done: m_elements[m_nbElementsRead] = m_actElement.EndPopulate(); m_nbElementsRead++; if (m_tl.NbListElements == m_nbElementsRead) { m_state = State.Done; return(ParseResult.Done); } m_actElement = new SmlTypeLengthField(m_encoding); m_actElement.BeginPopulate(); return(ParseResult.MoreBytesNeeded); default: return(res); } default: return(ParseResult.Failed); } } catch (Exception ex) { logger.Error(ex); m_state = State.Failed; return(ParseResult.Failed); } }
public SmlList(SmlTypeLengthField a_typeLengthField, Encoding a_encoding) { m_state = State.WaitForNextListElement; m_encoding = a_encoding; if (a_typeLengthField == null) { throw (new ArgumentNullException()); } m_tl = a_typeLengthField; if (a_typeLengthField.SmlFieldType != SmlFieldType.List) { m_state = State.Failed; } else { m_nbElementsRead = 0; m_actElement = new SmlTypeLengthField(m_encoding); m_actElement.BeginPopulate(); m_elements = new SmlBase[m_tl.NbListElements]; m_state = State.WaitForNextListElement; } }
public static SmlTime Create(SmlBase a_baseNode) { var list = a_baseNode as SmlList; if (list == null) { if (a_baseNode.SmlFieldType != SmlFieldType.Unsigned32) { return(null); } return(new SmlTime(TimeSpan.FromSeconds((a_baseNode as SmlUnsigned32).Value))); } else if (list.Length != 2) { return(null); } var choice = list.GetElement(0) as SmlUnsigned8; if (choice == null) { return(null); } switch (choice.Value) { case 0x00: var secIndex = list.GetElement(1) as SmlUnsigned32; if (secIndex == null) { return(null); } return(new SmlTime(TimeSpan.FromSeconds(secIndex.Value))); case 0x01: var secUnixUtc = list.GetElement(1) as SmlUnsigned32; if (secUnixUtc == null) { return(null); } return(new SmlTime(new DateTime(1970, 1, 1).AddSeconds(secUnixUtc.Value))); case 0x02: var localTime = list.GetElement(1) as SmlList; if (localTime == null || localTime.Length != 3) { return(null); } var secUnixLocal = localTime.GetElement(0) as SmlUnsigned32; var localOffsetMins = localTime.GetElement(1) as SmlSigned16; var seasonOffsetMins = localTime.GetElement(2) as SmlSigned16; if (secUnixLocal == null || localOffsetMins == null || seasonOffsetMins == null) { return(null); } var date = new DateTime(1970, 1, 1).AddSeconds(secUnixLocal.Value); date = date.AddMinutes(localOffsetMins.Value + seasonOffsetMins.Value); return(new SmlTime(date)); default: return(null); } }
internal ParseResult CreateParseResult() { ParseResult res = ParseResult.Failed; switch (m_type) { case SmlFieldType.EndOfMessage: m_parseResult = s_eom; res = ParseResult.Done; break; case SmlFieldType.Optional: m_parseResult = s_optional; res = ParseResult.Done; break; case SmlFieldType.Boolean: m_parseResult = new SmlBool(this); res = m_parseResult.BeginPopulate(); break; case SmlFieldType.Signed8: m_parseResult = new SmlSigned8(this); res = m_parseResult.BeginPopulate(); break; case SmlFieldType.Signed16: m_parseResult = new SmlSigned16(this); res = m_parseResult.BeginPopulate(); break; case SmlFieldType.Signed32: m_parseResult = new SmlSigned32(this); res = m_parseResult.BeginPopulate(); break; case SmlFieldType.Signed64: m_parseResult = new SmlSigned64(this); res = m_parseResult.BeginPopulate(); break; case SmlFieldType.Unsigned8: m_parseResult = new SmlUnsigned8(this); res = m_parseResult.BeginPopulate(); break; case SmlFieldType.Unsigned16: m_parseResult = new SmlUnsigned16(this); res = m_parseResult.BeginPopulate(); break; case SmlFieldType.Unsigned32: m_parseResult = new SmlUnsigned32(this); res = m_parseResult.BeginPopulate(); break; case SmlFieldType.Unsigned64: m_parseResult = new SmlUnsigned64(this); res = m_parseResult.BeginPopulate(); break; case SmlFieldType.String: m_parseResult = new SmlString(this, m_encoding); res = m_parseResult.BeginPopulate(); break; case SmlFieldType.List: m_parseResult = new SmlList(this, m_encoding); res = m_parseResult.BeginPopulate(); break; } switch (res) { case ParseResult.Failed: m_state = State.Failed; break; case ParseResult.Done: m_state = State.Done; break; default: m_state = State.ForewardToResult; break; } return(res); }
public override ParseResult BeginPopulate() { m_parseResult = null; return(ParseResult.MoreBytesNeeded); }
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)); }
protected SmlMessageBody(SmlBase a_baseNode) { m_listNode = a_baseNode; }
protected SmlMessageBody() { m_listNode = null; }
private SmlCloseResponse(SmlBase a_signature) : base() { m_signature = a_signature; }
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 != 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)); }