/// <summary> /// Check authentication. /// </summary> protected override SourceDiagnostic ValidateAuthentication(Authentication authentication, byte[] password) { if (this.UseLogicalNameReferencing) { GXDLMSAssociationLogicalName target = null; foreach (GXDLMSAssociationLogicalName it in Items.GetObjects(ObjectType.AssociationLogicalName)) { if (it.AuthenticationMechanismName.MechanismId == authentication) { target = it; break; } } if (target != null) { if (authentication != Authentication.Low) { //Other authentication levels are check later. return(SourceDiagnostic.None); } if (GXCommon.EqualBytes(target.Secret, password)) { return(SourceDiagnostic.None); } } } return(SourceDiagnostic.AuthenticationFailure); }
/// <summary> /// This method is used to update meter firmware. /// </summary> /// <param name="target"></param> public void ImageUpdate(GXDLMSImageTransfer target, byte[] identification, byte[] data) { //Check that image transfer ia enabled. GXReplyData reply = new GXReplyData(); ReadDataBlock(Client.Read(target, 5), reply); Client.UpdateValue(target, 5, reply.Value); if (!target.ImageTransferEnabled) { throw new Exception("Image transfer is not enabled"); } //Step 1: Read image block size. ReadDataBlock(Client.Read(target, 2), reply); Client.UpdateValue(target, 2, reply.Value); // Step 2: Initiate the Image transfer process. ReadDataBlock(target.ImageTransferInitiate(Client, identification, data.Length), reply); // Step 3: Transfers ImageBlocks. int imageBlockCount; ReadDataBlock(target.ImageBlockTransfer(Client, data, out imageBlockCount), reply); //Step 4: Check the completeness of the Image. ReadDataBlock(Client.Read(target, 3), reply); Client.UpdateValue(target, 3, reply.Value); // Step 5: The Image is verified; ReadDataBlock(target.ImageVerify(Client), reply); // Step 6: Before activation, the Image is checked; //Get list to images to activate. ReadDataBlock(Client.Read(target, 7), reply); Client.UpdateValue(target, 7, reply.Value); bool bFound = false; foreach (GXDLMSImageActivateInfo it in target.ImageActivateInfo) { if (GXCommon.EqualBytes(it.Identification, identification)) { bFound = true; break; } } //Read image transfer status. ReadDataBlock(Client.Read(target, 6), reply); Client.UpdateValue(target, 6, reply.Value); if (target.ImageTransferStatus != Gurux.DLMS.Objects.Enums.ImageTransferStatus.VerificationSuccessful) { throw new Exception("Image transfer status is " + target.ImageTransferStatus.ToString()); } if (!bFound) { throw new Exception("Image not found."); } //Step 7: Activate image. ReadDataBlock(target.ImageActivate(Client), reply); }