Beispiel #1
0
        /// <summary>
        /// Get the content of a TLV value part
        /// </summary>
        /// <param name="buffer">Buffer to extract the TLV from.
        /// This buffer must contain ONLY TLV fields as it will rely on the available siez to stop searching TLVs.
        /// If the buffer contains something else than TLV fields, the function won't notice it.</param>
        /// <param name="start">Start position inside the buffer to retrieve the TLV</param>
        /// <param name="offset">Offset after the TLV</param>
        public static CTLV ExtractTLV(byte[] buffer, int start, out int offset)
        {
            CTLV tlv = null;

            offset = start;
            if (buffer.Length - offset > CTLV.TLV_SIZE_T + CTLV.TLV_SIZE_L + 1)
            {
                byte[]     rawdata;
                int        mystart   = start;
                CEncoderAN encoderAN = new CEncoderAN();
                // enough room for T+L+V (1 byte at least)

                //get T
                string T = (encoderAN.Decode(buffer, offset, CTLV.TLV_SIZE_T, CTLV.TLV_SIZE_T, out offset, out rawdata)).ToString();
                // get L
                short L = (short)CMisc.StrToLong(encoderAN.ToString(encoderAN.Decode(buffer, offset, CTLV.TLV_SIZE_L, CTLV.TLV_SIZE_L, out offset, out rawdata)));
                if (0 != tlv.L)
                {
                    if (buffer.Length - offset >= L)
                    {
                        byte[] V = new byte[L];
                        // get V
                        Buffer.BlockCopy(buffer, offset, V, 0, L);
                        offset += tlv.L;
                        tlv     = new CTLV(T, L, FieldType.NONE);
                        tlv.SetV(V);
                        return(tlv);
                    }
                    else
                    {
                        throw new CInvalidDataSizeException("TAG " + T, L, buffer.Length - offset);
                    }
                }
                else
                {
                    throw new CInvalidValueException("TAG " + T, L.ToString());
                }
            }
            else
            {
                throw new CInvalidDataSizeException("TLV", CTLV.TLV_SIZE_T + CTLV.TLV_SIZE_L + 1, buffer.Length - offset);
            }
        }
Beispiel #2
0
 private void SetButtons()
 {
     pbReadCheck.Enabled = pbWriteCheck.Enabled = Elc.Opened;
     pbSendIPDU.Enabled  = (0 != CMisc.StrToLong(F4.Text)) && (0 == F43_POS1.Text.Length || F43_POS1.MaskCompleted) && (0 == F43_POS6.Text.Length || F43_POS6.MaskCompleted);
 }