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); } }
/// <summary> /// Performs a GET operation </summary> /// <param name="phy"> PhyLayer to transmit / receive bytes </param> /// <param name="obj"> Long-name descriptor of the objected to be accessed </param> /// <exception cref="PhyLayerException"> </exception> /// <exception cref="DlmsException"> </exception> /// <exception cref="LinkLayerException"> </exception> public void get(PhyLayer phy, LnDescriptor obj) { do { link.send(phy, cosem.requestGet(obj)); } while (!cosem.parseGetResponse(obj, link.read(phy))); }
/// <summary> /// Performs a ACTION operation </summary> /// <param name="phy"> PhyLayer to transmit / receive bytes </param> /// <param name="obj"> Long-name descriptor of the objected to be accessed </param> /// <exception cref="PhyLayerException"> </exception> /// <exception cref="DlmsException"> </exception> /// <exception cref="LinkLayerException"> </exception> public void action(PhyLayer phy, LnDescriptor obj) { do { link.send(phy, cosem.requestAction(obj)); } while (!cosem.parseActionResponse(obj, link.read(phy))); }
public byte[] getValue(DlmsClient dlms, PhyLayer phy) { LnDescriptor desc = new LnDescriptor(CosemClasses.REGISTER.id, obis, attValue); dlms.get(phy, desc); return(desc.getResponseData()); }
public int getIntegerValue(DlmsClient dlms, PhyLayer phy) { LnDescriptor desc = new LnDescriptor(CosemClasses.REGISTER.id, obis, attValue); dlms.get(phy, desc); return(DlmsParser.getInteger(desc.getResponseData())); }
public string getStringValue(DlmsClient dlms, PhyLayer phy) { LnDescriptor desc = new LnDescriptor(CosemClasses.DATA.id, obis, attValue); dlms.get(phy, desc); return(DlmsParser.getString(desc.getResponseData())); }
public int getImageBlockSize(DlmsClient dlms, PhyLayer phy) { LnDescriptor att = createDesc(attBlockSize); dlms.get(phy, att); return(DlmsParser.getInteger(att.getResponseData())); }
public bool isTransferEnabled(DlmsClient dlms, PhyLayer phy) { LnDescriptor att = createDesc(attTransferEnabled); dlms.get(phy, att); return(DlmsParser.getBoolean(att.getResponseData())); }
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); }
/// <summary> /// Connects to the server </summary> /// <param name="phy"> PhyLayer to transmit / receive bytes </param> /// <exception cref="PhyLayerException"> </exception> /// <exception cref="DlmsException"> </exception> /// <exception cref="LinkLayerException"> </exception> public void connect(PhyLayer phy) { cosem.reset(); link.connect(phy); do { link.send(phy, cosem.connectionRequest()); } while (!cosem.parseConnectionResponse(link.read(phy))); }
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(); } }
/// /// <param name="phy"> PhyLayer to transmit / receive bytes </param> /// <exception cref="PhyLayerException"> </exception> /// <exception cref="DlmsException"> </exception> /// <exception cref="LinkLayerException"> </exception> public void disconnect(PhyLayer phy) { link.disconnect(phy); }
public void reset(DlmsClient dlms, PhyLayer phy) { LnDescriptor desc = new LnDescriptor(CosemClasses.REGISTER.id, obis, mtdReset); dlms.action(phy, desc); }
public void checkCompleteness(DlmsClient dlms, PhyLayer phy, ImageInformation info) { //TODO }
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 })); }