public int getImageBlockSize(DlmsClient dlms, PhyLayer phy) { LnDescriptor att = createDesc(attBlockSize); dlms.get(phy, att); return(DlmsParser.getInteger(att.getResponseData())); }
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 execute(DlmsClient dlms, PhyLayer phy, ImageInformation imageInfo) { /// Precondition: image transfer must be enabled if (!isTransferEnabled(dlms, phy)) { throw new ImageTransferException(ImageTransferExceptionReason.TRANSFER_DISABLED); } /// Step 1: if image block size is unknown, get block size if (imageInfo.getBlockSize() == 0) { imageInfo.setBlockSize(getImageBlockSize(dlms, phy)); } /// Step 2: Initiate image transfer initiateImageTransfer(dlms, phy, imageInfo); /// Step 3: Transfer image blocks transferBlocks(dlms, phy, imageInfo); /// Step 4: Check completeness of the image checkCompleteness(dlms, phy, imageInfo); /// Step 5: Verifies the image verifyImage(dlms, phy); /// Step 6: Check information of image to activate if (!checkImageInformation(dlms, phy, imageInfo)) { throw new ImageTransferException(ImageTransferExceptionReason.INVALID_IMAGE_TO_ACTIVATE); } /// Step 7: Activates image activateImage(dlms, phy); }
public bool isTransferEnabled(DlmsClient dlms, PhyLayer phy) { LnDescriptor att = createDesc(attTransferEnabled); dlms.get(phy, att); return(DlmsParser.getBoolean(att.getResponseData())); }
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 bool checkImageInformation(DlmsClient dlms, PhyLayer phy, ImageInformation info) { return(false); }
public void verifyImage(DlmsClient dlms, PhyLayer phy) { dlms.action(phy, createDesc(mtdImageVerify, new byte[] { 0x0F, 0x00 })); }
public void checkCompleteness(DlmsClient dlms, PhyLayer phy, ImageInformation info) { //TODO }