Beispiel #1
0
        /// <summary>
        /// return HeartBeat or null
        /// </summary>
        /// <returns></returns>
        public override object ToValue()
        {
            if (LanDiDef.HEAD.IsMatch(_bytes, 0))
            {
                DataField dfTail = new DataField(
                    _bytes.Length - 2,
                    2,
                    LanDiDef.TAIL.Values
                    );
                if (dfTail.IsMatch(_bytes, 0))
                {
                    int ipstrPos = LanDiDef.IPSTR.SearchBeginPos(_bytes);
                    if (ipstrPos != -1)
                    {
                        DataField dfSimNumber = new DataField(
                            LanDiDef.HEAD_LENGTH,
                            ipstrPos - LanDiDef.HEAD_LENGTH
                            );
                        byte[] simBytes = dfSimNumber.GetMatch(_bytes);

                        DataField dfIP = new DataField(
                            ipstrPos + LanDiDef.IPSTR.DataLength,
                            _bytes.Length - (ipstrPos + LanDiDef.IPSTR.DataLength + LanDiDef.TAIL_LENGTH)
                            );
                        byte[] ipBytes = dfIP.GetMatch(_bytes);

                        string sim = ASCIIEncoding.ASCII.GetString(simBytes);
                        string ip  = ASCIIEncoding.ASCII.GetString(ipBytes);

                        return(new HeartBeat(sim, ip));
                    }
                }
            }
            return(null);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        public byte[][] Picker(byte[] datas)
        {
            if (datas == null || datas.Length < _minLen)
            {
                return(null);
            }

            ArrayList al = new ArrayList();

            for (int i = 0; i < datas.Length - _minLen; i++)
            {
                if (_head.IsMatch(datas, i) &&
                    _devType.IsMatch(datas, i))
                {
                    byte[] bs = _innerDataLen.GetMatch(datas, i);

                    // idl - inner data length
                    int idl = bs[0];
                    if (idl + _minLen + i <= datas.Length)
                    {
                        DataField df      = new DataField(0, idl + _minLen);
                        byte[]    aGrData = df.GetMatch(datas, i);

                        al.Add(aGrData);
                    }
                }
            }
            return(ArraylistToByteDim2(al));
        }