public void initiateImageTransfer(DlmsClient dlms, PhyLayer phy, ImageInformation imageInfo) { try { System.IO.MemoryStream stream = new System.IO.MemoryStream(); stream.WriteByte(DlmsType.STRUCTURE.tag); stream.WriteByte(2); // size stream.WriteByte(DlmsType.OCTET_STRING.tag); stream.WriteByte((byte)(imageInfo.getIdentifier().Length)); //stream.WriteByte(imageInfo.getIdentifier()); byte[] aux = imageInfo.getIdentifier(); //Array.Reverse(aux); stream.Write(aux, 0, aux.Length); stream.WriteByte(DlmsType.UINT32.tag); //stream.WriteByte(ByteBuffer.allocate(4).putInt(imageInfo.getImage().Length).array()); stream.Write(new byte[] { (byte)(imageInfo.getImage().Length >> 24), (byte)(imageInfo.getImage().Length >> 16), (byte)(imageInfo.getImage().Length >> 8), (byte)(imageInfo.getImage().Length) }, 0, imageInfo.getImage().Length); dlms.action(phy, createDesc(mtdTransferInitiate, stream.ToArray())); } catch (IOException) { throw new ImageTransferException(ImageTransferExceptionReason.INTERNAL_ERROR); } }
public void transferBlocks(DlmsClient dlms, PhyLayer phy, ImageInformation imageInfo) { int offset = 0; int nblock = 1; LnDescriptor att = createDesc(mtdImageBlockTransfer); while (offset < imageInfo.getImage().Length) { att.setRequestData(getTransferBlockData(nblock, imageInfo)); dlms.action(phy, att); nblock++; offset += imageInfo.getBlockSize(); } }
public void activateImage(DlmsClient dlms, PhyLayer phy) { dlms.action(phy, createDesc(mtdImageActivate, new byte[] { 0x0F, 0x00 })); }
public void verifyImage(DlmsClient dlms, PhyLayer phy) { dlms.action(phy, createDesc(mtdImageVerify, new byte[] { 0x0F, 0x00 })); }