Пример #1
0
        /// <summary>
        /// Parses the APDU of a ACTION response </summary>
        /// <param name="att"> LnDescriptor describing the object accessed </param>
        /// <returns> true if the parse if finished, false if more apdu's are necessary (data block transfer) </returns>
        /// <exception cref="DlmsException"> </exception>
        public bool parseActionResponse(LnDescriptor att, byte[] data)
        {
            data = unpackFrame(Constants.xDlmsApdu.NoCiphering.ACTION_RESPONSE, Constants.xDlmsApdu.GlobalCiphering.ACTION_RESPONSE, data);

            if (data.Length > 6)
            {
                att.setResponseData(helper.extensions.copyOfRange(data, 5, data.Length));
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Parses the APDU of a GET response </summary>
        /// <param name="att"> LnDescriptor describing the object accessed </param>
        /// <returns> true if the parse if finished, false if more apdu's are necessary (data block transfer) </returns>
        /// <exception cref="DlmsException"> </exception>
        public bool parseGetResponse(LnDescriptor att, byte[] data)
        {
            try
            {
                data = unpackFrame(Constants.xDlmsApdu.NoCiphering.GET_RESPONSE, Constants.xDlmsApdu.GlobalCiphering.GET_RESPONSE, data);

                if (data.Length < 4)
                {
                    throw new DlmsException(DlmsException.DlmsExceptionReason.RECEIVED_INVALID_GET_RESPONSE);
                }

                if (data[0] == Constants.GetResponse.NORMAL)
                {
                    verifyDataAccessResult(data[2]);
                    connection.datablock.lastBlock = true;
                    data = helper.extensions.copyOfRange(data, 3, data.Length);
                }
                else if (data[0] == Constants.GetResponse.DATA_BLOCK)
                {
                    if (data.Length < 10 || data[7] != 0)
                    {                     //TODO only supports raw-data for now
                        throw new DlmsException(DlmsException.DlmsExceptionReason.RECEIVED_INVALID_GET_RESPONSE);
                    }
                    connection.datablock.lastBlock = data[2] != 0;
                    //connection.datablock.blockNum = ByteBuffer.allocate(4).put(data,3,4).getInt(0);
                    connection.datablock.blockNum = BitConverter.ToInt32(new byte[] { data[6], data[5], data[4], data[3] }, 0);
                    data = getPayload(data, 8);
                }
                else
                {
                    throw new DlmsException(DlmsException.DlmsExceptionReason.RECEIVED_INVALID_GET_RESPONSE);
                }
                //Array.Reverse(data);
                connection.datablock.data.Write(data, 0, data.Length);

                if (connection.datablock.lastBlock)
                {
                    att.setResponseData(connection.datablock.data.ToArray());
                    connection.datablock.reset();
                    return(true);
                }

                return(false);
            }
            catch (IOException)
            {
                throw new DlmsException(DlmsException.DlmsExceptionReason.INTERNAL_ERROR);
            }
        }