/// <summary> /// Parse application context name. /// </summary> /// <param name="settings">DLMS settings.</param> /// <param name="buff">Received data.</param> private static bool ParseApplicationContextName(GXDLMSSettings settings, GXByteBuffer buff) { //Get length. int len = buff.GetUInt8(); if (buff.Size - buff.Position < len) { throw new Exception("Encoding failed. Not enough data."); } if (buff.GetUInt8() != 0x6) { throw new Exception("Encoding failed. Not an Object ID."); } if (settings.IsServer) { settings.Cipher.Security = Security.None; } //Object ID length. len = buff.GetUInt8(); if (settings.UseLogicalNameReferencing) { if (buff.Compare(GXCommon.LogicalNameObjectID)) { return(true); } // If ciphering is used. return(buff.Compare(GXCommon.LogicalNameObjectIdWithCiphering)); } if (buff.Compare(GXCommon.ShortNameObjectID)) { return(true); } // If ciphering is used. return(buff.Compare(GXCommon.ShortNameObjectIdWithCiphering)); }
/// <summary> /// Parse application context name. /// </summary> /// <param name="settings">DLMS settings.</param> /// <param name="buff">Received data.</param> private static bool ParseApplicationContextName(GXDLMSSettings settings, GXByteBuffer buff, GXDLMSTranslatorStructure xml) { //Get length. int len = buff.GetUInt8(); if (buff.Size - buff.Position < len) { throw new Exception("Encoding failed. Not enough data."); } if (buff.GetUInt8() != 0x6) { throw new Exception("Encoding failed. Not an Object ID."); } if (settings.IsServer && settings.Cipher != null) { settings.Cipher.Security = Gurux.DLMS.Enums.Security.None; } //Object ID length. len = buff.GetUInt8(); if (xml != null) { if (buff.Compare(GXCommon.LogicalNameObjectID)) { if (xml.OutputType == TranslatorOutputType.SimpleXml) { xml.AppendLine(TranslatorGeneralTags.ApplicationContextName, "Value", "LN"); } else { xml.AppendLine( TranslatorGeneralTags.ApplicationContextName, null, "1"); } settings.UseLogicalNameReferencing = true; } else if (buff.Compare(GXCommon.LogicalNameObjectIdWithCiphering)) { if (xml.OutputType == TranslatorOutputType.SimpleXml) { xml.AppendLine(TranslatorGeneralTags.ApplicationContextName, "Value", "LN_WITH_CIPHERING"); } else { xml.AppendLine( TranslatorGeneralTags.ApplicationContextName, null, "3"); } settings.UseLogicalNameReferencing = true; } else if (buff.Compare(GXCommon.ShortNameObjectID)) { if (xml.OutputType == TranslatorOutputType.SimpleXml) { xml.AppendLine(TranslatorGeneralTags.ApplicationContextName, "Value", "SN"); } else { xml.AppendLine( TranslatorGeneralTags.ApplicationContextName, null, "2"); } settings.UseLogicalNameReferencing = false; } else if (buff.Compare(GXCommon.ShortNameObjectIdWithCiphering)) { if (xml.OutputType == TranslatorOutputType.SimpleXml) { xml.AppendLine(TranslatorGeneralTags.ApplicationContextName, "Value", "SN_WITH_CIPHERING"); } else { xml.AppendLine( TranslatorGeneralTags.ApplicationContextName, null, "4"); } settings.UseLogicalNameReferencing = false; } else { return false; } return true; } if (settings.UseLogicalNameReferencing) { if (buff.Compare(GXCommon.LogicalNameObjectID)) { return true; } // If ciphering is used. return buff.Compare(GXCommon.LogicalNameObjectIdWithCiphering); } if (buff.Compare(GXCommon.ShortNameObjectID)) { return true; } // If ciphering is used. return buff.Compare(GXCommon.ShortNameObjectIdWithCiphering); }