public StartFieldOrder(InputByteArray InputArray) : base(InputArray, WtdOrder.StartField) { if (InputArray.RemainingLength < 8) { this.Errmsg = "Start field order. end of stream."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(8); var wtdOrder = buf[0].ToWtdOrder(); this.FFW_Bytes = buf.SubArray(1, 2); this.FCW_Bytes = null; // fcw may or may not be present. if (buf[3] >= 0x80) { this.FCW_Bytes = buf.SubArray(3, 2); this.AttrByte = buf[5]; this.LL_Length = buf.BigEndianBytesToShort(6); this.BytesLength += 7; InputArray.AdvanceIndex(8); } else { this.AttrByte = buf[3]; this.LL_Length = buf.BigEndianBytesToShort(4); this.BytesLength += 5; InputArray.AdvanceIndex(6); } } }
public static TextDataOrder Factory(InputByteArray InputArray) { byte? attrByte = null; string displayText = null; // scan forward in the input array for a non text character. int ix = ScanNonTextDataByte(InputArray); int remLx = ix - InputArray.Index; // first byte is the attribute byte. { var b1 = InputArray.PeekByte(0); if ((b1 >= 0x20) && (b1 <= 0x2f)) { attrByte = b1; InputArray.AdvanceIndex(1); remLx -= 1; } } // remaining bytes are text characters in ebcdic. if (remLx > 0) { System.Text.Encoding encoding = System.Text.Encoding.GetEncoding(37); // 37 = ebcdic displayText = InputArray.GetEbcdicBytes(remLx); } TextDataOrder tdOrder = new TextDataOrder(attrByte, displayText); return(tdOrder); }
public static Tuple <TerminalVt100Statement, Vt100OutputText> Factory( InputByteArray InputArray) { TerminalVt100Statement stmt = null; Vt100OutputText otStmt = null; var escapeCmd = InputArray.PeekNextByte().ToTelnetCommand(); Vt100Command?cmd = null; if ((escapeCmd != null) && (escapeCmd.Value == TelnetCommand.ESCAPE) && (InputArray.RemainingLength > 1)) { InputArray.AdvanceIndex(1); var rv = InputArray.GetBytesUntilCode(new byte[] { 0x1b }); var buf = rv.Item1; int rx = 0; var stmtText = buf.ToAscii(); stmt = Factory_FromStmtText(stmtText); // process any output text that follows the stmt text. { int lx = stmt.StmtText.Length; if (stmtText.Length > lx) { stmtText = stmtText.Substring(lx); otStmt = new Vt100OutputText(stmtText); } } } return(new Tuple <TerminalVt100Statement, Vt100OutputText>(stmt, otStmt)); }
public static IBM5250DataStreamCommand Factory(InputByteArray InputArray) { IBM5250DataStreamCommand dsCmd = null; if (InputArray.RemainingLength >= 2) { var buf = InputArray.PeekBytes(2); if (buf[0] == 0x04) { var cmdCode = buf[1].ToCommandCode(); if (cmdCode != null) { if (cmdCode.Value == CommandCode.ClearUnit) { dsCmd = new ClearUnitCommand(); } else if (cmdCode.Value == CommandCode.WTD) { dsCmd = WriteToDisplayCommand.Factory(InputArray); } if (dsCmd != null) { InputArray.AdvanceIndex(dsCmd.GetDataStreamLength()); } } } } return(dsCmd); }
public WriteStructuredFieldCommand(InputByteArray InputArray) : base(InputArray, WorkstationCode.WriteStructuredField) { byte[] buf = null; // advance past the 0x04 and 0xf3. InputArray.AdvanceIndex(2); // first 2 bytes are the LL length bytes. this.llLength = InputArray.PeekBigEndianShort(0); // make sure enough length remaining in the input array if (this.llLength > InputArray.RemainingLength) { this.Errmsg = "LL length " + this.llLength.ToString() + " exceeds remaining length of input array."; } // setup c field and t field if (this.Errmsg == null) { buf = InputArray.GetBytes(this.llLength); this.cField = buf[2]; this.tField = buf[3]; this.RequestCode = this.tField.ToRequestCode(); } if (this.Errmsg == null) { this.BytesLength += this.llLength; this.FormatFlags = null; this.FormatFlags = buf.SubArray(4, 1); } }
public static DataStreamHeader Factory(InputByteArray InputArray) { DataStreamHeader dsHeader = null; if (InputArray.RemainingLength >= 10) { var buf = InputArray.PeekBytes(10); var rcdLgth = buf.BigEndianBytesToShort(0); byte[] rcdType = new byte[2]; Array.Copy(buf, 2, rcdType, 0, 2); byte[] reserved = new byte[2]; Array.Copy(buf, 4, reserved, 0, 2); if ((rcdType[0] == 0x12) && (rcdType[1] == 0xa0) && (rcdLgth >= 10)) { byte varHdrLgth = buf[6]; byte[] flags = new byte[2]; Array.Copy(buf, 7, flags, 0, 2); var dsOpcode = buf[9].ToDataStreamOpcode(); if ((varHdrLgth == 4) && (dsOpcode != null)) { dsHeader = new DataStreamHeader( rcdLgth, rcdType, reserved, varHdrLgth, flags, dsOpcode.Value); InputArray.AdvanceIndex(10); } } } return(dsHeader); }
public TransparentDataOrder(InputByteArray InputArray) : base(InputArray, WtdOrder.TransparentData) { if (InputArray.RemainingLength < 3) { this.Errmsg = "Transparent data order. end of stream."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(3); this.LLBytes = buf.SubArray(1, 2); // this is all wrong. was a bug workaround. should instead process the // LLBytes as a big endian length value. // throw new Exception("TransparentDataOrder order does not handle LL length correctly"); // advance past order code and LL bytes. this.BytesLength += 2; InputArray.AdvanceIndex(3); // bytes after the LL byte pair are bytes to show on the display ?? var rv = Common5250.ScanNonTextDataByte(InputArray); int textLx = rv.Item2; this.BytesLength += textLx; this.TransparentData = InputArray.GetEbcdicBytes(textLx); } }
public Query5250Response(InputByteArray InputArray) { InputByteArray buf = null; if (InputArray.RemainingLength < 58) { this.Errmsg = "Insufficient bytes in byte stream for 5250 query response."; } if (this.Errmsg == null) { this.Length = InputArray.PeekBigEndianShort(0); if (InputArray.RemainingLength < this.Length) { this.Errmsg = "response length exceeds byte stream."; } } if (this.Errmsg == null) { this.RawBytes = InputArray.PeekBytes(this.Length); buf = new InputByteArray(this.RawBytes); buf.AdvanceIndex(2); // the length this.cField = buf.GetByte(); var tField = buf.GetByte(); this.RequestCode = tField.ToRequestCode(); this.ResponseByte = buf.GetByte(); // 0x80 fixed code if ((cField != 0xd9) || (this.RequestCode == null) || (this.ResponseByte != 0x80)) { this.Errmsg = "invalid c Field, t Field or response byte in 5250 " + "query response."; } } // isolate other 5250 query response fields. if (this.Errmsg == null) { this.ControlUnitCode = buf.GetBytes(2); this.CodeLevel = buf.GetBytes(3); this.Reserve1 = buf.GetBytes(16); this.WorkstationByte = buf.GetByte(); this.MachineType = buf.GetEbcdicBytes(7); this.KeyboardId = buf.GetByte(); buf.AdvanceIndex(2); this.SerialNumber = buf.GetBytes(4); this.MaxInputFields = buf.GetBigEndianShort(); this.Reserve2 = buf.GetBytes(3); this.Capabilities = buf.GetBytes(5); } // is a valid query 5250 response byte stream. Advance index of input bytes. if (this.Errmsg == null) { InputArray.AdvanceIndex(this.Length); } }
public WriteToDisplayCommand(InputByteArray InputArray) : base(InputArray, WorkstationCode.WTD) { this.OrderList = new List <WtdOrderBase>(); if (InputArray.RemainingLength < 4) { this.Errmsg = "Byte stream too short. Missing control chars."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(4); this.ControlChars = buf.SubArray(2, 2); InputArray.AdvanceIndex(4); this.BytesLength = 4; // gather WTD orders and display characters. while (true) { WtdOrderBase orderBase = null; if (InputArray.RemainingLength == 0) { break; } orderBase = WtdOrderBase.Factory(InputArray); // not an explicit WTD order. Check that is a text data order. if (orderBase == null) { var b1 = InputArray.PeekByte(0); if (Common5250.IsTextDataChar(b1) == true) { orderBase = new TextDataOrder(InputArray); } } // current input stream bytes are not WTD order. End of WTD command. if (orderBase == null) { break; } // got an order but some sort of form error. if (orderBase.Errmsg != null) { throw new Exception("invalid WTD order"); } // Append to list of orders of the WTD command. this.OrderList.Add(orderBase); this.BytesLength += orderBase.GetDataStreamLength(); } } }
public TextDataOrder(InputByteArray InputArray) : base(InputArray, "TextData") { var b1 = InputArray.PeekByte(0); if (Common5250.IsTextDataChar(b1) == false) { this.Errmsg = "Invalid text data order. Order must begin with data character."; } if (this.Errmsg == null) { // scan forward in the input array for a non text character. var rv = Common5250.ScanNonTextDataByte(InputArray); this.DataStreamLength = rv.Item2; // the actual data stream bytes. var rawBytes = InputArray.PeekBytes(this.DataStreamLength); int rawLx = rawBytes.Length; // first byte is the attribute byte. if (Common5250.IsAttributeByte(b1)) { this.AttrByte = b1; } // last text byte is an attribute byte. if ((rawLx > 1) && (rawBytes[rawLx - 1].IsAttributeByte( ) == true)) { this.TailAttrByte = rawBytes[rawLx - 1]; } // bytes the attrByte and tailAttrByte are textBytes. { int fx = 0; int lx = rawLx; if (this.AttrByte != null) { fx += 1; lx -= 1; } if (this.TailAttrByte != null) { lx -= 1; } if (lx > 0) { this.TextBytes = rawBytes.SubArray(fx, lx); } } this.RawBytes = rawBytes; this.BytesLength = rawLx; InputArray.AdvanceIndex(rawLx); } }
public UndocumentedControlFunction( InputByteArray InputArray, ControlFunctionCode FunctionCode, int ParmLength) : base(InputArray, FunctionCode) { InputArray.AdvanceIndex(1); // isolate the parm bytes. if (ParmLength > 0) { this.ParmBytes = InputArray.GetBytes(ParmLength); } }
public EraseToAddressOrder(InputByteArray InputArray) : base(InputArray, WtdOrder.EraseToAddress) { if (InputArray.RemainingLength < 5) { this.Errmsg = "erase address order. end of stream."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(4); this.RowAddress = buf[1]; this.ColumnAddress = buf[2]; this.AttrTypesLength = buf[3]; this.BytesLength += 3; InputArray.AdvanceIndex(4); } // attr types length between 2 and 5. if ((this.Errmsg == null) && ((this.AttrTypesLength < 2) || (this.AttrTypesLength > 5))) { this.Errmsg = "attribute types length not between 2 and 5."; } // isolate the list of attr type bytes. if (this.Errmsg == null) { // the count of attrType bytes. int lx = 0; if (this.AttrTypesLength == 0xff) { lx = 1; } else { lx = this.AttrTypesLength - 1; } if (InputArray.RemainingLength < lx) { this.Errmsg = "attribute types length not valid"; } else { this.AttrTypesArray = InputArray.GetBytes(lx); } } }
public ClearUnitAlternateCommand(InputByteArray InputArray) : base(InputArray, WorkstationCode.ClearUnitAlternate) { if (InputArray.RemainingLength < 3) { this.Errmsg = "too few bytes in input stream"; } if (this.Errmsg == null) { InputArray.AdvanceIndex(2); this.RequestByte = InputArray.GetByte(); } }
public WriteErrorCodeCommand(InputByteArray InputArray) : base(InputArray, WorkstationCode.WriteErrorCode) { if (InputArray.RemainingLength < 4) { this.Errmsg = "Byte stream too short. Missing control chars."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(4); this.BytesLength += 2; InputArray.AdvanceIndex(this.BytesLength); } }
public WriteStructuredFieldCommand(InputByteArray InputArray) : base(InputArray, WorkstationCode.WriteStructuredField) { // advance past the 0x04 and 0xf3. InputArray.AdvanceIndex(2); // first 2 bytes are the LL length bytes. this.llLength = InputArray.PeekBigEndianShort(0); // make sure enough length remaining in the input array if (this.llLength > InputArray.RemainingLength) { this.Errmsg = "LL length " + this.llLength.ToString( ) + " exceeds remaining length of input array."; } if (this.Errmsg == null) { this.BytesLength += this.llLength; var buf = InputArray.GetBytes(this.llLength); this.FormatFlags = null; // isolate cField and tField this.cField = buf[2]; this.tField = buf[3]; // 5250 query. format flags are 1 byte. if (this.cField == 0xd9) { if (this.tField == 0x30) { this.RequestCode = WSF_RequestCode.DefineAuditWindow; } else if (this.tField == 0x31) { this.RequestCode = WSF_RequestCode.DefineCmdKeyFunc; } else if (this.tField == 0x70) { this.FormatFlags = buf.SubArray(4, 1); this.RequestCode = WSF_RequestCode.Query5250; } } } }
public ReadMdtFieldsCommand(InputByteArray InputArray) : base(InputArray, WorkstationCode.ReadMdtFields) { if (InputArray.RemainingLength < 4) { this.Errmsg = "Byte stream too short. Missing control chars."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(4); this.ControlChars = buf.SubArray(2, 2); this.BytesLength += 2; InputArray.AdvanceIndex(this.BytesLength); } }
public SetBufferAddressOrder(InputByteArray InputArray) : base(InputArray, WtdOrder.SetBufferAddress) { if (InputArray.RemainingLength < 3) { this.Errmsg = "SBA order. end of stream."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(3); this.RowNum = buf[1]; this.ColNum = buf[2]; this.BytesLength += 2; InputArray.AdvanceIndex(3); } }
public InsertCursorOrder(InputByteArray InputArray) : base(InputArray, WtdOrder.InsertCursor) { if (InputArray.RemainingLength < 3) { this.Errmsg = "Insert cursor order. end of stream."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(3); this.RowAddress = buf[1]; this.ColumnAddress = buf[2]; this.BytesLength += 2; InputArray.AdvanceIndex(3); } }
public static WriteToDisplayCommand Factory(InputByteArray InputArray) { WriteToDisplayCommand wtdCmd = null; if (InputArray.RemainingLength >= 4) { var buf = InputArray.PeekBytes(4); if ((buf[0] == 0x04) && (buf[1] == 0x11)) { byte[] controlChars = new byte[2]; Array.Copy(buf, 3, controlChars, 0, 2); wtdCmd = new WriteToDisplayCommand(InputArray, controlChars); InputArray.AdvanceIndex(4); // gather WTD orders and display characters. while (true) { if (InputArray.RemainingLength == 0) { break; } var b1 = InputArray.PeekByte(0); var wtdOrder = b1.ToWtdOrder(); if (wtdOrder != null) { } else if (TextDataOrder.IsTextDataChar(b1)) { var tdOrder = TextDataOrder.Factory(InputArray); wtdCmd.OrderList.Add(tdOrder); } else { break; } } } } return(wtdCmd); }
public ResponseHeader(InputByteArray InputArray) : base(InputArray, "ResponseHeader") { if (InputArray.RemainingLength < 3) { this.Errmsg = "input array shortage"; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(3); this.RowNum = buf[0]; this.ColNum = buf[1]; this.AidByte = buf[2]; this.AidKey = buf[2].ToAidKey(); this.BytesLength = 3; InputArray.AdvanceIndex(3); } }
public WriteSingleStructuredFieldCommand(InputByteArray InputArray) : base(InputArray, WorkstationCode.WriteSingleStructuredField) { byte[] buf = null; // advance past the 0x04 and 0xf4. InputArray.AdvanceIndex(2); // first 2 bytes are the LL length bytes. this.llLength = InputArray.PeekBigEndianShort(0); // make sure enough length remaining in the input array if (this.llLength > InputArray.RemainingLength) { this.Errmsg = "LL length " + this.llLength.ToString() + " exceeds remaining length of input array."; } // setup c field and t field if (this.Errmsg == null) { buf = InputArray.GetBytes(this.llLength); this.cField = buf[2]; this.tField = buf[3]; this.f1Field = buf[4]; this.f2Field = buf[5]; // command contains minor structure. if (this.llLength > 8) { this.minor_ll = buf[6]; this.minor_t = buf[7]; this.minor_f = buf[8]; } } if (this.Errmsg == null) { this.BytesLength += this.llLength; } }
public TextControlFunction(InputByteArray InputArray) : base(InputArray, ControlFunctionCode.Text) { var ba = new ByteArrayBuilder(); // isolate the series of printable bytes. while (InputArray.IsEof() == false) { var b1 = InputArray.PeekByte(0); if (Array.IndexOf(ControlFunctionCodeExt.TextBytes, b1) == -1) { break; } // is a printable byte. accum to array of text bytes. ba.Append(b1); InputArray.AdvanceIndex(1); } this.TextBytes = ba.ToByteArray(); }
public NullControlFunction(InputByteArray InputArray) : base(InputArray, ControlFunctionCode.Null) { var ba = new ByteArrayBuilder(); // isolate the series of null bytes. while (InputArray.IsEof() == false) { var b1 = InputArray.PeekByte(0); if (b1 != 0x00) { break; } // accum to array of null bytes. ba.Append(b1); InputArray.AdvanceIndex(1); } this.NullBytes = ba.ToByteArray(); }
public RepeatToAddressOrder(InputByteArray InputArray) : base(InputArray, WtdOrder.RepeatToAddress) { if (InputArray.RemainingLength < 4) { this.Errmsg = "Repeat to address order. end of stream."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(4); this.RowAddress = buf[1]; this.ColumnAddress = buf[2]; // the repeat character. this.RepeatTextByte = buf[3]; this.BytesLength += 3; InputArray.AdvanceIndex(this.BytesLength); } }
public StartHeaderOrder(InputByteArray InputArray) : base(InputArray, WtdOrder.StartHeader) { // at least 3 bytes remaining. ( command code, length byte and length must be from // 1 to 7. if (InputArray.RemainingLength < 3) { this.Errmsg = "SOH not long enough"; } if (this.Errmsg == null) { var buf2 = InputArray.PeekBytes(2); this.LengthByte = buf2[1]; // invalid start of header order length. if ((this.LengthByte < 1) || (this.LengthByte > 7)) { this.Errmsg = "SOH length not valid"; } } if (this.Errmsg == null) { int actualOrderLength = CalcActualOrderLength(this.LengthByte); var buf = InputArray.PeekBytesPad(this.BytesLength, 9, 0x00); this.FlagByte = buf[2]; this.ReservedByte = buf[3]; this.FirstResponseFieldNumber = buf[4]; this.ErrRow = buf[5]; this.CmdKeySwitches = buf.SubArray(6, 3); // advance current pos in input array by the actual length of the order. InputArray.AdvanceIndex(this.BytesLength); } }
public PresentationPositionControlFunction(InputByteArray InputArray) : base(InputArray, ControlFunctionCode.PresentationPosition) { if (InputArray.RemainingLength < 3) { this.Errmsg = "need 3 bytes"; } else { var buf = InputArray.PeekBytes(3); if (buf[0] == 0x34) { var dir = buf[1].ToPresentationPositionDirection(); if (dir != null) { this.Direction = dir.Value; this.PositionValue = buf[2]; } else { this.Errmsg = "invalid direction code"; } } else { this.Errmsg = "invalid function code"; } } // valid control function. advance in input stream. if (this.Errmsg == null) { InputArray.AdvanceIndex(3); } }
public VariableLengthControlFunction( InputByteArray InputArray, ControlFunctionCode ControlCode) : base(InputArray, ControlCode) { // first 3 bytes contain control code and then length byte. { var buf = InputArray.PeekBytes(3); this.ByteCount = buf[2]; } // byte count from 1 to 50 if ((this.ByteCount < 1) || (this.ByteCount > InputArray.RemainingLength) || (this.ByteCount > 20)) { this.Errmsg = "invalid byte count"; } // isolate function parameter bytes. if (this.Errmsg == null) { InputArray.AdvanceIndex(3); this.ParmBytes = InputArray.GetBytes(this.ByteCount - 1); } }
public SingleByteControlFunction( InputByteArray InputArray, ControlFunctionCode FunctionCode) : base(InputArray, FunctionCode) { InputArray.AdvanceIndex(1); }
public RestoreScreenCommand(InputByteArray InputArray) : base(InputArray, WorkstationCode.RestoreScreen) { InputArray.AdvanceIndex(2); }
public ClearUnitCommand(InputByteArray InputArray) : base(InputArray, WorkstationCode.ClearUnit) { InputArray.AdvanceIndex(2); }