/// <summary>
        /// build the entire 5250 query response stream. Starting from data stream header
        /// and concluding with IAC EOR.
        /// </summary>
        /// <returns></returns>
        public static byte[] BuildQuery5250Response()
        {
            var ra = new ByteArrayBuilder();

            // data stream header.
            {
                var buf = DataStreamHeader.Build(50, DataStreamOpcode.Noop, 0, 0);
                ra.Append(buf);
            }

            // response header.  send the special AID code - 0x88.
            {
                var buf = ResponseHeader.Build(0, 0, AidKey.Query5250Reply);
                ra.Append(buf);
            }

            // build the 5250 query response.
            {
                byte byteZero = 0x00;
                ra.AppendBigEndianShort(58);                            // LL. total length of structured field.
                ra.Append(new byte[] { 0xd9, 0x70, 0x80 });             // 5250 query response
                ra.Append(new byte[] { 0x06, 0x00 });                   // control unit code.
                ra.Append(new byte[] { 0x01, 0x03, 0x00 });             // code release level.
                ra.Append(byteZero.Repeat(16));                         // 16 bytes of null
                ra.Append(0x01);                                        // 01 - display station
                ra.Append("3180002".ToEbcdicBytes());                   // machine type and model.
                ra.Append(0x02);                                        // keyboard id
                ra.Append(0x00);                                        // extended keyboard id
                ra.Append(0x00);                                        // reserve
                ra.Append(new byte[] { 0x00, 0x61, 0x50, 0x00 });       // device serial number.
                ra.AppendBigEndianShort(256);                           // max number input fields.
                ra.Append(0x00);                                        // control unit customization
                ra.Append(new byte[] { 0x00, 0x00 });                   // reserved
                ra.Append(new byte[] { 0x18, 0x11, 0x00, 0x00, 0x00 }); //
                ra.Append(byteZero.Repeat(7));                          // 7 bytes of null.
            }

            // update length of response data stream.
            {
                var wk = new ByteArrayBuilder();
                wk.AppendBigEndianShort((short)ra.Length);
                ra.CopyToBuffer(wk.ToByteArray(), 0);
            }

            // IAC EOR
            {
                ra.Append(EOR_Command.Build());
            }

            return(ra.ToByteArray());
        }
Esempio n. 2
0
        public static byte[] BuildReadScreenResponse(ScreenContent ScreenContent)
        {
            var ra = new ByteArrayBuilder();

            // data stream header.
            {
                var buf = DataStreamHeader.Build(50, TerminalOpcode.ReadScreen, 0, 0);
                ra.Append(buf);
            }

            // screen regeneration buffer. each byte on the screen.
            {
                var buf = ScreenContent.GetRegenerationBuffer();
                ra.Append(buf);
            }

            // update length of response data stream.
            {
                var wk = new ByteArrayBuilder();
                wk.AppendBigEndianShort((short)ra.Length);
                ra.CopyToBuffer(wk.ToByteArray(), 0);
            }

            // IAC EOR
            {
                ra.Append(EOR_Command.Build());
            }

            return(ra.ToByteArray());
        }
        public override byte[] ToBytes()
        {
            var ba = new ByteArrayBuilder();

            ba.Append((byte)this.OrderCode.Value);
            ba.AppendBigEndianShort(this.MajorLength);
            ba.Append(this.ClassByte);
            ba.Append(this.TypeByte);

            return(ba.ToByteArray());
        }
        public static byte[] BuildSaveScreenResponse(ScreenContent ScreenContent)
        {
            var ra = new ByteArrayBuilder();

            // data stream header.
            {
                var buf = DataStreamHeader.Build(50, TerminalOpcode.SaveScreen, 0, 0);
                ra.Append(buf);
            }

            // restore screen workstation command.
            {
                var cmd = new RestoreScreenCommand();
                ra.Append(cmd.ToBytes());
            }

            // clear unit command.
            if (ScreenContent.ScreenDim.GetIsWideScreen( ) == true)
            {
                var cmd = new ClearUnitAlternateCommand(0x00);
                ra.Append(cmd.ToBytes());
            }
            else
            {
                var cmd = new ClearUnitCommand();
                ra.Append(cmd.ToBytes());
            }

            // WTD command.
            {
                var ordersByteStream = ScreenContent.BuildOrderStream( );
                var buf = WriteToDisplayCommand.Build(0x00, 0x18, ordersByteStream);
                ra.Append(buf);
            }

            // update length of response data stream.
            {
                var wk = new ByteArrayBuilder();
                wk.AppendBigEndianShort((short)ra.Length);
                ra.CopyToBuffer(wk.ToByteArray(), 0);
            }

            // IAC EOR
            {
                ra.Append(EOR_Command.Build());
            }

            return(ra.ToByteArray());
        }
        public override byte[] ToBytes()
        {
            var ba = new ByteArrayBuilder();

            ba.Append((byte)this.OrderCode.Value);
            ba.Append(this.FFW_Bytes);
            if (this.FCW_Bytes != null)
            {
                ba.Append(this.FCW_Bytes);
            }
            ba.Append(this.AttrByte);
            ba.AppendBigEndianShort(this.LL_Length);

            return(ba.ToByteArray());
        }
        /// <summary>
        /// build a data stream header. Return byte array containing the header bytes.
        /// </summary>
        /// <param name="Length"></param>
        /// <param name="Opcode"></param>
        /// <param name="Flag1"></param>
        /// <param name="Flag2"></param>
        /// <returns></returns>
        public static byte[] Build(
            int Length, TerminalOpcode Opcode,
            byte Flag1 = 0x00, byte Flag2 = 0x00)
        {
            var ba = new ByteArrayBuilder();

            ba.AppendBigEndianShort((short)Length);
            ba.Append(0x12);
            ba.Append(0xa0);
            ba.Append(new byte[] { 0x00, 0x00 });
            ba.Append(0x04);
            ba.Append(new byte[] { Flag1, Flag2 });
            ba.Append((byte)Opcode);

            return(ba.ToByteArray());
        }
        /// <summary>
        /// no longer used. called WorkstationCommandListExt.ProcessAndPaint, which
        /// itself is not used.
        /// </summary>
        /// <param name="VisualItems"></param>
        /// <param name="Caret"></param>
        /// <returns></returns>
        public static byte[] BuildSaveScreenResponse(
            ScreenVisualItems VisualItems, CanvasPositionCursor Caret)
        {
            var ra = new ByteArrayBuilder();

            // data stream header.
            {
                var buf = DataStreamHeader.Build(50, TerminalOpcode.SaveScreen, 0, 0);
                ra.Append(buf);
            }

            // restore screen workstation command.
            {
                var cmd = new RestoreScreenCommand();
                ra.Append(cmd.ToBytes());
            }

            // clear unit command.
            {
                var cmd = new ClearUnitCommand();
                ra.Append(cmd.ToBytes());
            }

            // WTD command.
            {
                var ordersByteStream = VisualItems.BuildOrderStream(Caret);
                var buf = WriteToDisplayCommand.Build(0x00, 0x18, ordersByteStream);
                ra.Append(buf);
            }

            // update length of response data stream.
            {
                var wk = new ByteArrayBuilder();
                wk.AppendBigEndianShort((short)ra.Length);
                ra.CopyToBuffer(wk.ToByteArray(), 0);
            }

            // IAC EOR
            {
                ra.Append(EOR_Command.Build());
            }

            return(ra.ToByteArray());
        }
Esempio n. 8
0
        private byte[] BuildResponseByteStream(
            ScreenContent ScreenContent,
            AidKey AidKey, OneRowCol CaretRowCol, HowReadScreen?HowRead = null)
        {
            var ba = new ByteArrayBuilder();

            // what to read from the screen.
            HowReadScreen howRead = HowReadScreen.ReadAllInput;

            if (HowRead != null)
            {
                howRead = HowRead.Value;
            }

            {
                var buf = DataStreamHeader.Build(99, TerminalOpcode.PutGet);
                ba.Append(buf);
            }

            // location of caret on the canvas.
            {
                var rowCol = CaretRowCol.ToParentRelative(ScreenContent);
                var buf    = ResponseHeader.Build(rowCol as OneRowCol, AidKey);
                ba.Append(buf);
            }

            foreach (var dictItem in ScreenContent.FieldDict)
            {
                ContentField responseField = null;
                var          contentItem   = dictItem.Value;

                // process only ContentField.
                if (contentItem is ContentField)
                {
                    var contentField = contentItem as ContentField;
                    responseField = contentField;
                }

                // only process the first of a continued entry field.
                if ((responseField != null) && (responseField is ContinuedContentField))
                {
                    var contContentField = responseField as ContinuedContentField;
                    if (contContentField.ContinuedFieldSegmentCode != ContinuedFieldSegmentCode.First)
                    {
                        responseField = null;
                    }
                }

                if ((howRead == HowReadScreen.ReadMdt) &&
                    (responseField != null) && (responseField.GetModifiedFlag(ScreenContent) == false))
                {
                    responseField = null;
                }

                if (responseField != null)
                {
                    IRowCol rowCol = responseField.RowCol.ToOneRowCol().AdvanceRight();
                    {
                        rowCol = rowCol.ToParentRelative(ScreenContent);
                        var buf = SetBufferAddressOrder.Build(rowCol as OneRowCol);
                        ba.Append(buf);
                    }
                    {
                        var buf = TextDataOrder.Build(responseField.GetFieldShowText(ScreenContent));
                        ba.Append(buf);
                    }
                }
            }

            // update length of response data stream.
            var ra = ba.ToByteArray();

            {
                var wk = new ByteArrayBuilder();
                wk.AppendBigEndianShort((short)ra.Length);
                Array.Copy(wk.ToByteArray(), ra, 2);
            }

            return(ra);
        }