Example #1
0
 protected override void _Empty()
 {
     _Confirmed    = 0;
     _Date         = null;
     _Time         = null;
     _NrStatements = 0;
     _Statements   = null;
 }
Example #2
0
        protected override int _Read(byte[] buffer, int offset)
        {
            int startsize = Marshal.SizeOf(_Confirmed) + SCPDate.Size + SCPTime.Size + Marshal.SizeOf(_NrStatements);
            int end       = offset - Size + Length;

            if ((offset + startsize) > end)
            {
                return(0x1);
            }

            _Confirmed = (byte)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(_Confirmed), true);
            offset    += Marshal.SizeOf(_Confirmed);
            _Date      = new SCPDate();
            _Date.Read(buffer, offset);
            offset += SCPDate.Size;
            _Time   = new SCPTime();
            _Time.Read(buffer, offset);
            offset       += SCPTime.Size;
            _NrStatements = (byte)BytesTool.readBytes(buffer, offset, Marshal.SizeOf(_NrStatements), true);
            offset       += Marshal.SizeOf(_NrStatements);

            if (_NrStatements > 0)
            {
                _Statements = new SCPStatement[_NrStatements];
                int loper = 0;
                for (; loper < _NrStatements; loper++)
                {
                    _Statements[loper] = new SCPStatement();
                    int err = _Statements[loper].Read(buffer, offset);
                    if (err != 0)
                    {
                        return(0x2);
                    }
                    offset += _Statements[loper].getLength();
                }
                if (loper != _NrStatements)
                {
                    _NrStatements = (byte)loper;
                    return(0x4);
                }
            }

            return(0x0);
        }
Example #3
0
        // setting diagnositc information.
        public int setDiagnosticStatements(Statements stat)
        {
            if ((stat != null) &&
                (stat.time.Year > 1000) &&
                (stat.statement != null) &&
                (stat.statement.Length > 0))
            {
                Empty();
                _Confirmed = (byte)(stat.confirmed ? 1 : 0);

                if (stat.time == DateTime.MinValue)
                {
                    _Date = new SCPDate();
                    _Time = new SCPTime();
                }
                else
                {
                    _Date = new SCPDate(stat.time.Year, stat.time.Month, stat.time.Day);
                    _Time = new SCPTime(stat.time.Hour, stat.time.Minute, stat.time.Second);
                }

                _NrStatements = (byte)stat.statement.Length;
                _Statements   = new SCPStatement[_NrStatements];
                for (int loper = 0; loper < _NrStatements; loper++)
                {
                    _Statements[loper]            = new SCPStatement();
                    _Statements[loper].SequenceNr = (byte)(loper + 1);
                    if (stat.statement[loper] != null)
                    {
                        _Statements[loper].Length = (ushort)(stat.statement[loper].Length + 1);
                        _Statements[loper].Field  = new byte[_Statements[loper].Length];
                        BytesTool.writeString(_Encoding, stat.statement[loper], _Statements[loper].Field, 0, _Statements[loper].Length);
                    }
                    else
                    {
                        _Statements[loper].Length = 1;
                        _Statements[loper].Field  = new byte[_Statements[loper].Length];
                    }
                }
                return(0);
            }
            return(1);
        }