3
|
1 /**
|
|
2 * Title: tnvt.java
|
|
3 * Copyright: Copyright (c) 2001 Company:
|
|
4 *
|
|
5 * @author Kenneth J. Pouncey
|
|
6 * @version 0.5
|
|
7 *
|
|
8 * Description:
|
|
9 *
|
|
10 * This program is free software; you can redistribute it and/or modify it under
|
|
11 * the terms of the GNU General Public License as published by the Free Software
|
|
12 * Foundation; either version 2, or (at your option) any later version.
|
|
13 *
|
|
14 * This program is distributed in the hope that it will be useful, but WITHOUT
|
|
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
17 * details.
|
|
18 *
|
|
19 * You should have received a copy of the GNU General Public License along with
|
|
20 * this software; see the file COPYING. If not, write to the Free Software
|
|
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
22 *
|
|
23 */
|
|
24 package org.tn5250j.framework.tn5250;
|
|
25
|
|
26 import static org.tn5250j.TN5250jConstants.AID_HELP;
|
|
27 import static org.tn5250j.TN5250jConstants.AID_PRINT;
|
|
28 import static org.tn5250j.TN5250jConstants.CMD_CLEAR_FORMAT_TABLE;
|
|
29 import static org.tn5250j.TN5250jConstants.CMD_CLEAR_UNIT;
|
|
30 import static org.tn5250j.TN5250jConstants.CMD_CLEAR_UNIT_ALTERNATE;
|
|
31 import static org.tn5250j.TN5250jConstants.CMD_READ_INPUT_FIELDS;
|
|
32 import static org.tn5250j.TN5250jConstants.CMD_READ_MDT_FIELDS;
|
|
33 import static org.tn5250j.TN5250jConstants.CMD_READ_MDT_IMMEDIATE_ALT;
|
|
34 import static org.tn5250j.TN5250jConstants.CMD_READ_SCREEN_IMMEDIATE;
|
|
35 import static org.tn5250j.TN5250jConstants.CMD_READ_SCREEN_TO_PRINT;
|
|
36 import static org.tn5250j.TN5250jConstants.CMD_RESTORE_SCREEN;
|
|
37 import static org.tn5250j.TN5250jConstants.CMD_ROLL;
|
|
38 import static org.tn5250j.TN5250jConstants.CMD_SAVE_SCREEN;
|
|
39 import static org.tn5250j.TN5250jConstants.CMD_WRITE_ERROR_CODE;
|
|
40 import static org.tn5250j.TN5250jConstants.CMD_WRITE_ERROR_CODE_TO_WINDOW;
|
|
41 import static org.tn5250j.TN5250jConstants.CMD_WRITE_STRUCTURED_FIELD;
|
|
42 import static org.tn5250j.TN5250jConstants.CMD_WRITE_TO_DISPLAY;
|
|
43 import static org.tn5250j.TN5250jConstants.NR_REQUEST_ERROR;
|
|
44 import static org.tn5250j.TN5250jConstants.PF1;
|
|
45 import static org.tn5250j.TN5250jConstants.PF10;
|
|
46 import static org.tn5250j.TN5250jConstants.PF11;
|
|
47 import static org.tn5250j.TN5250jConstants.PF12;
|
|
48 import static org.tn5250j.TN5250jConstants.PF13;
|
|
49 import static org.tn5250j.TN5250jConstants.PF14;
|
|
50 import static org.tn5250j.TN5250jConstants.PF15;
|
|
51 import static org.tn5250j.TN5250jConstants.PF16;
|
|
52 import static org.tn5250j.TN5250jConstants.PF17;
|
|
53 import static org.tn5250j.TN5250jConstants.PF18;
|
|
54 import static org.tn5250j.TN5250jConstants.PF19;
|
|
55 import static org.tn5250j.TN5250jConstants.PF2;
|
|
56 import static org.tn5250j.TN5250jConstants.PF20;
|
|
57 import static org.tn5250j.TN5250jConstants.PF21;
|
|
58 import static org.tn5250j.TN5250jConstants.PF22;
|
|
59 import static org.tn5250j.TN5250jConstants.PF23;
|
|
60 import static org.tn5250j.TN5250jConstants.PF24;
|
|
61 import static org.tn5250j.TN5250jConstants.PF3;
|
|
62 import static org.tn5250j.TN5250jConstants.PF4;
|
|
63 import static org.tn5250j.TN5250jConstants.PF5;
|
|
64 import static org.tn5250j.TN5250jConstants.PF6;
|
|
65 import static org.tn5250j.TN5250jConstants.PF7;
|
|
66 import static org.tn5250j.TN5250jConstants.PF8;
|
|
67 import static org.tn5250j.TN5250jConstants.PF9;
|
|
68
|
|
69 import java.io.BufferedInputStream;
|
|
70 import java.io.BufferedOutputStream;
|
|
71 import java.io.ByteArrayOutputStream;
|
|
72 import java.io.IOException;
|
|
73 import java.io.InputStream;
|
|
74 import java.io.OutputStream;
|
|
75 import java.net.Socket;
|
|
76 import java.util.Arrays;
|
|
77 import java.util.Properties;
|
|
78 import java.util.concurrent.ArrayBlockingQueue;
|
|
79 import java.util.concurrent.BlockingQueue;
|
|
80
|
|
81 import javax.net.ssl.SSLSocket;
|
|
82
|
8
|
83 import com.five_ten_sg.connectbot.service.TerminalBridge;
|
|
84 import com.five_ten_sg.connectbot.service.TerminalManager;
|
13
|
85 import android.content.Intent;
|
|
86 import android.net.Uri;
|
8
|
87
|
3
|
88 import org.tn5250j.TN5250jConstants;
|
|
89 import org.tn5250j.encoding.CharMappings;
|
|
90 import org.tn5250j.encoding.ICodePage;
|
|
91 import org.tn5250j.framework.transport.SocketConnector;
|
|
92 import org.tn5250j.tools.logging.TN5250jLogFactory;
|
|
93 import org.tn5250j.tools.logging.TN5250jLogger;
|
|
94
|
|
95 public final class tnvt implements Runnable {
|
|
96 // negotiating commands
|
|
97 private static final byte IAC = (byte) -1; // 255 FF
|
|
98 private static final byte DONT = (byte) -2; //254 FE
|
|
99 private static final byte DO = (byte) -3; //253 FD
|
|
100 private static final byte WONT = (byte) -4; //252 FC
|
|
101 private static final byte WILL = (byte) -5; //251 FB
|
|
102 private static final byte SB = (byte) -6; //250 Sub Begin FA
|
|
103 private static final byte SE = (byte) -16; //240 Sub End F0
|
|
104 private static final byte EOR = (byte) -17; //239 End of Record EF
|
|
105 private static final byte TERMINAL_TYPE = (byte) 24; // 18
|
|
106 private static final byte OPT_END_OF_RECORD = (byte) 25; // 19
|
|
107 private static final byte TRANSMIT_BINARY = (byte) 0; // 0
|
|
108 private static final byte QUAL_IS = (byte) 0; // 0
|
|
109 private static final byte TIMING_MARK = (byte) 6; // 6
|
|
110 private static final byte NEW_ENVIRONMENT = (byte) 39; // 27
|
|
111 private static final byte IS = (byte) 0; // 0
|
|
112 private static final byte SEND = (byte) 1; // 1
|
|
113 private static final byte INFO = (byte) 2; // 2
|
|
114 private static final byte VAR = (byte) 0; // 0
|
|
115 private static final byte VALUE = (byte) 1; // 1
|
|
116 private static final byte NEGOTIATE_ESC = (byte) 2; // 2
|
|
117 private static final byte USERVAR = (byte) 3; // 3
|
|
118
|
|
119 // miscellaneous
|
|
120 private static final byte ESC = 0x04; // 04
|
|
121
|
|
122 private Socket sock;
|
11
|
123 public BufferedInputStream bin;
|
|
124 public BufferedOutputStream bout;
|
3
|
125 private final BlockingQueue<Object> dsq = new ArrayBlockingQueue<Object>(25);
|
|
126 private Stream5250 bk;
|
|
127 private DataStreamProducer producer;
|
|
128 protected Screen5250 screen52;
|
|
129 private boolean waitingForInput;
|
|
130 private boolean invited;
|
|
131 private boolean negotiated = false;
|
|
132 private Thread me;
|
|
133 private Thread pthread;
|
|
134 private int readType;
|
|
135 private boolean enhanced = true;
|
|
136 private boolean cursorOn = false;
|
10
|
137 private String hostname = "";
|
3
|
138 private int port = 23;
|
|
139 private boolean connected = false;
|
|
140 private boolean support132 = true;
|
|
141 private ByteArrayOutputStream baosp = null;
|
|
142 private ByteArrayOutputStream baosrsp = null;
|
|
143 private int devSeq = -1;
|
|
144 private String devName;
|
|
145 private String devNameUsed;
|
|
146 private KbdTypesCodePages kbdTypesCodePage;
|
|
147 // WVL - LDC : TR.000300 : Callback scenario from 5250
|
|
148 private boolean scan; // = false;
|
|
149 private static int STRSCAN = 1;
|
|
150 // WVL - LDC : 05/08/2005 : TFX.006253 - support STRPCCMD
|
|
151 private boolean strpccmd; // = false;
|
|
152 private String user;
|
|
153 private String password;
|
|
154 private String library;
|
|
155 private String initialMenu;
|
|
156 private String program;
|
|
157 private boolean keepTrucking = true;
|
|
158 private boolean pendingUnlock = false;
|
|
159 private boolean[] dataIncluded;
|
|
160 protected ICodePage codePage;
|
|
161 private boolean firstScreen;
|
|
162 private String sslType;
|
|
163 private WTDSFParser sfParser;
|
8
|
164 private TerminalBridge bridge;
|
|
165 private TerminalManager manager;
|
3
|
166
|
|
167 private final TN5250jLogger log = TN5250jLogFactory.getLogger(this.getClass());
|
|
168
|
|
169 /**
|
|
170 * @param screen52
|
10
|
171 * @param enhanced
|
3
|
172 * @param support132
|
10
|
173 * @param bridge
|
|
174 * @param manager
|
3
|
175 */
|
8
|
176 public tnvt(Screen5250 screen52, boolean enhanced, boolean support132, TerminalBridge bridge, TerminalManager manager) {
|
|
177 this.screen52 = screen52;
|
3
|
178 this.support132 = support132;
|
8
|
179 this.enhanced = enhanced;
|
|
180 this.bridge = bridge;
|
|
181 this.manager = manager;
|
3
|
182 setCodePage("37");
|
|
183 dataIncluded = new boolean[24];
|
|
184
|
|
185 if (System.getProperties().containsKey("SESSION_CONNECT_USER")) {
|
|
186 user = System.getProperties().getProperty("SESSION_CONNECT_USER");
|
|
187 if (System.getProperties().containsKey("SESSION_CONNECT_PASSWORD"))
|
|
188 password = System.getProperties().getProperty(
|
|
189 "SESSION_CONNECT_PASSWORD");
|
|
190 if (System.getProperties().containsKey("SESSION_CONNECT_LIBRARY"))
|
|
191 library = System.getProperties().getProperty(
|
|
192 "SESSION_CONNECT_LIBRARY");
|
|
193 if (System.getProperties().containsKey("SESSION_CONNECT_MENU"))
|
|
194 initialMenu = System.getProperties().getProperty(
|
|
195 "SESSION_CONNECT_MENU");
|
|
196 if (System.getProperties().containsKey("SESSION_CONNECT_PROGRAM"))
|
|
197 program = System.getProperties().getProperty(
|
|
198 "SESSION_CONNECT_PROGRAM");
|
|
199 }
|
|
200
|
|
201 baosp = new ByteArrayOutputStream();
|
|
202 baosrsp = new ByteArrayOutputStream();
|
|
203 }
|
|
204
|
10
|
205 public void showURL(String url) {
|
|
206 if (url.indexOf("://") < 0) url = "http://" + url;
|
|
207 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
|
208 manager.startActivity(intent);
|
|
209 }
|
|
210
|
3
|
211 public String getHostName() {
|
|
212
|
10
|
213 return hostname;
|
3
|
214 }
|
|
215
|
|
216 public void setSSLType(String type) {
|
|
217 sslType = type;
|
|
218 }
|
|
219
|
|
220 public void setDeviceName(String name) {
|
|
221 devName = name;
|
|
222 }
|
|
223
|
|
224 public String getDeviceName() {
|
|
225 return devName;
|
|
226 }
|
|
227
|
|
228 public String getAllocatedDeviceName() {
|
|
229 return devNameUsed;
|
|
230 }
|
|
231
|
|
232 public boolean isConnected() {
|
|
233 return connected;
|
|
234 }
|
|
235
|
|
236 /**
|
|
237 * @return true when SSL is used and socket is connected.
|
|
238 * @see {@link #isConnected()}
|
|
239 */
|
|
240 public boolean isSslSocket() {
|
|
241 if (this.connected && this.sock != null && this.sock instanceof SSLSocket) {
|
|
242 return true;
|
|
243 } else {
|
|
244 return false;
|
|
245 }
|
|
246 }
|
|
247
|
|
248 public final void setProxy(String proxyHost, String proxyPort) {
|
|
249
|
|
250 Properties systemProperties = System.getProperties();
|
|
251 systemProperties.put("socksProxySet", "true");
|
|
252 systemProperties.put("socksProxyHost", proxyHost);
|
|
253 systemProperties.put("socksProxyPort", proxyPort);
|
|
254
|
|
255 System.setProperties(systemProperties);
|
|
256 log.info(" socks set ");
|
|
257 }
|
|
258
|
|
259 public final boolean connect() {
|
|
260
|
10
|
261 return connect(hostname, port);
|
3
|
262
|
|
263 }
|
|
264
|
|
265
|
10
|
266 public final boolean connect(String hostname, int port) {
|
3
|
267
|
20
|
268 //// We will now see if there are any bypass signon parameters to be
|
|
269 //// processed. The system properties override these parameters so
|
|
270 //// have precidence if specified.
|
|
271 //Properties props = controller.getConnectionProperties();
|
|
272 //if (user == null && props.containsKey("SESSION_CONNECT_USER")) {
|
|
273 // user = props.getProperty("SESSION_CONNECT_USER");
|
|
274 // log.info(" user -> " + user + " " + controller.getSessionName());
|
|
275 // if (props.containsKey("SESSION_CONNECT_PASSWORD"))
|
|
276 // password = props.getProperty("SESSION_CONNECT_PASSWORD");
|
|
277 // if (props.containsKey("SESSION_CONNECT_LIBRARY"))
|
|
278 // library = props.getProperty("SESSION_CONNECT_LIBRARY");
|
|
279 // if (props.containsKey("SESSION_CONNECT_MENU"))
|
|
280 // initialMenu = props.getProperty("SESSION_CONNECT_MENU");
|
|
281 // if (props.containsKey("SESSION_CONNECT_PROGRAM"))
|
|
282 // program = props.getProperty("SESSION_CONNECT_PROGRAM");
|
|
283 //}
|
3
|
284
|
|
285 try {
|
10
|
286 this.hostname = hostname;
|
|
287 this.port = port;
|
3
|
288
|
|
289 try {
|
6
|
290 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,
|
3
|
291 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED,"X - Connecting");
|
|
292 } catch (Exception exc) {
|
|
293 log.warn("setStatus(ON) " + exc.getMessage());
|
|
294 }
|
|
295
|
|
296 // sock = new Socket(s, port);
|
|
297 //smk - For SSL compability
|
|
298 SocketConnector sc = new SocketConnector();
|
8
|
299 if (sslType != null) sc.setSSLType(sslType);
|
10
|
300 sock = sc.createSocket(hostname, port, bridge, manager);
|
3
|
301
|
|
302 if (sock == null) {
|
|
303 log.warn("I did not get a socket");
|
|
304 disconnect();
|
|
305 return false;
|
|
306 }
|
|
307
|
|
308 connected = true;
|
|
309 // used for JDK1.3
|
|
310 sock.setKeepAlive(true);
|
|
311 sock.setTcpNoDelay(true);
|
|
312 sock.setSoLinger(false, 0);
|
|
313 InputStream in = sock.getInputStream();
|
|
314 OutputStream out = sock.getOutputStream();
|
|
315
|
|
316 bin = new BufferedInputStream(in, 8192);
|
|
317 bout = new BufferedOutputStream(out);
|
|
318
|
|
319 byte abyte0[];
|
|
320 while (negotiate(abyte0 = readNegotiations()));
|
|
321 negotiated = true;
|
|
322 try {
|
|
323 screen52.setCursorActive(false);
|
|
324 } catch (Exception excc) {
|
|
325 log.warn("setCursorOff " + excc.getMessage());
|
|
326
|
|
327 }
|
|
328
|
|
329 producer = new DataStreamProducer(this, bin, dsq, abyte0);
|
|
330 pthread = new Thread(producer);
|
|
331 // pthread.setPriority(pthread.MIN_PRIORITY);
|
|
332 pthread.setPriority(Thread.NORM_PRIORITY);
|
|
333 // pthread.setPriority(Thread.NORM_PRIORITY / 2);
|
|
334 pthread.start();
|
|
335
|
|
336 try {
|
6
|
337 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_NOTINHIBITED,
|
3
|
338 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED);
|
|
339 } catch (Exception exc) {
|
|
340 log.warn("setStatus(OFF) " + exc.getMessage());
|
|
341 }
|
|
342
|
|
343 keepTrucking = true;
|
|
344 me = new Thread(this);
|
|
345 me.start();
|
|
346
|
|
347 } catch (Exception exception) {
|
|
348 if (exception.getMessage() == null)
|
|
349 exception.printStackTrace();
|
|
350 log.warn("connect() " + exception.getMessage());
|
|
351
|
|
352 if (sock == null)
|
|
353 log.warn("I did not get a socket");
|
|
354
|
|
355 disconnect();
|
|
356 return false;
|
|
357 }
|
|
358 return true;
|
|
359
|
|
360 }
|
|
361
|
|
362 public final boolean disconnect() {
|
|
363
|
|
364 // Added by LUC - LDC to fix a null pointer exception.
|
|
365 if (!connected) {
|
|
366 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,
|
|
367 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED,"X - Disconnected");
|
|
368 return false;
|
|
369 }
|
|
370
|
|
371 if (me != null && me.isAlive()) {
|
|
372 me.interrupt();
|
|
373 keepTrucking = false;
|
|
374 pthread.interrupt();
|
|
375 }
|
|
376
|
|
377 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,
|
|
378 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED,"X - Disconnected");
|
|
379 screen52.getOIA().setKeyBoardLocked(false);
|
|
380 pendingUnlock = false;
|
|
381
|
|
382 try {
|
|
383 if (sock != null) {
|
|
384 log.info("Closing socket");
|
|
385 sock.close();
|
|
386 }
|
8
|
387 if (bin != null) bin.close();
|
|
388 if (bout != null) bout.close();
|
|
389 connected = false;
|
3
|
390 firstScreen = false;
|
|
391
|
|
392 // WVL - LDC : TR.000345 : properly disconnect and clear screen
|
|
393 // Is this the right place to set screen realestate on disconnect?
|
|
394 //controller.getScreen().clearAll();
|
|
395 screen52.goto_XY(0);
|
|
396 screen52.setCursorActive(false);
|
|
397 screen52.clearAll();
|
|
398 screen52.restoreScreen();
|
|
399 } catch (Exception exception) {
|
|
400 log.warn(exception.getMessage());
|
|
401 connected = false;
|
|
402 devSeq = -1;
|
|
403 return false;
|
|
404
|
|
405 }
|
|
406 devSeq = -1;
|
|
407 return true;
|
|
408 }
|
|
409
|
|
410 private final ByteArrayOutputStream appendByteStream(byte abyte0[]) {
|
|
411 ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
|
|
412 for (int i = 0; i < abyte0.length; i++) {
|
|
413 bytearrayoutputstream.write(abyte0[i]);
|
|
414 if (abyte0[i] == -1)
|
|
415 bytearrayoutputstream.write(-1);
|
|
416 }
|
|
417
|
|
418 return bytearrayoutputstream;
|
|
419 }
|
|
420
|
|
421 private final byte[] readNegotiations() throws IOException {
|
|
422 int i = bin.read();
|
|
423 if (i < 0) {
|
|
424 throw new IOException("Connection closed.");
|
|
425 } else {
|
|
426 int j = bin.available();
|
|
427 byte abyte0[] = new byte[j + 1];
|
|
428 abyte0[0] = (byte) i;
|
|
429 bin.read(abyte0, 1, j);
|
|
430 return abyte0;
|
|
431 }
|
|
432 }
|
|
433
|
|
434 private final void writeByte(byte abyte0[]) throws IOException {
|
|
435
|
|
436 bout.write(abyte0);
|
|
437 bout.flush();
|
|
438 }
|
|
439
|
|
440 // private final void writeByte(byte byte0) throws IOException {
|
|
441 //
|
|
442 // bout.write(byte0);
|
|
443 // bout.flush();
|
|
444 // }
|
|
445
|
|
446 public final void sendHeartBeat() throws IOException {
|
|
447
|
|
448 byte[] b = { (byte) 0xff, (byte) 0xf1 };
|
|
449 bout.write(b);
|
|
450 bout.flush();
|
|
451 }
|
|
452
|
|
453 private final void readImmediate(int readType) {
|
|
454
|
|
455 if (screen52.isStatusErrorCode()) {
|
|
456 screen52.restoreErrorLine();
|
|
457 screen52.setStatus(Screen5250.STATUS_ERROR_CODE,
|
|
458 Screen5250.STATUS_VALUE_OFF, null);
|
|
459 }
|
|
460
|
|
461 if (!enhanced) {
|
|
462 screen52.setCursorActive(false);
|
|
463 }
|
|
464 // screen52.setStatus(Screen5250.STATUS_SYSTEM,
|
|
465 // Screen5250.STATUS_VALUE_ON, null);
|
|
466 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,
|
|
467 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED);
|
|
468
|
|
469 screen52.getOIA().setKeyBoardLocked(true);
|
|
470 pendingUnlock = false;
|
|
471 invited = false;
|
|
472
|
|
473 screen52.getScreenFields().readFormatTable(baosp, readType, codePage);
|
|
474
|
|
475 try {
|
|
476
|
|
477 writeGDS(0, 3, baosp.toByteArray());
|
|
478 } catch (IOException ioe) {
|
|
479
|
|
480 log.warn(ioe.getMessage());
|
|
481 baosp.reset();
|
|
482 }
|
|
483 baosp.reset();
|
|
484
|
|
485 }
|
|
486
|
|
487 public final boolean sendAidKey(int aid) {
|
|
488
|
|
489 if (screen52.isStatusErrorCode()) {
|
|
490 screen52.restoreErrorLine();
|
|
491 screen52.setStatus(Screen5250.STATUS_ERROR_CODE,
|
|
492 Screen5250.STATUS_VALUE_OFF, null);
|
|
493 }
|
|
494
|
|
495 if (!enhanced) {
|
|
496 screen52.setCursorActive(false);
|
|
497 }
|
|
498 // screen52.setStatus(Screen5250.STATUS_SYSTEM,
|
|
499 // Screen5250.STATUS_VALUE_ON, null);
|
|
500 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,
|
|
501 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED);
|
|
502
|
|
503 screen52.getOIA().setKeyBoardLocked(true);
|
|
504 pendingUnlock = false;
|
|
505 invited = false;
|
|
506 baosp.write(screen52.getCurrentRow());
|
|
507 baosp.write(screen52.getCurrentCol());
|
|
508 baosp.write(aid);
|
|
509
|
|
510 if (dataIncluded(aid))
|
|
511
|
|
512 screen52.getScreenFields().readFormatTable(baosp, readType,
|
|
513 codePage);
|
|
514
|
|
515 try {
|
|
516
|
|
517 writeGDS(0, 3, baosp.toByteArray());
|
|
518 } catch (IOException ioe) {
|
|
519
|
|
520 log.warn(ioe.getMessage());
|
|
521 baosp.reset();
|
|
522 return false;
|
|
523 }
|
|
524 baosp.reset();
|
|
525 return true;
|
|
526
|
|
527 }
|
|
528
|
|
529 private boolean dataIncluded(int aid) {
|
|
530
|
|
531 switch (aid) {
|
|
532
|
|
533 case PF1:
|
|
534 return !dataIncluded[0];
|
|
535 case PF2:
|
|
536 return !dataIncluded[1];
|
|
537 case PF3:
|
|
538 return !dataIncluded[2];
|
|
539 case PF4:
|
|
540 return !dataIncluded[3];
|
|
541 case PF5:
|
|
542 return !dataIncluded[4];
|
|
543 case PF6:
|
|
544 return !dataIncluded[5];
|
|
545 case PF7:
|
|
546 return !dataIncluded[6];
|
|
547 case PF8:
|
|
548 return !dataIncluded[7];
|
|
549 case PF9:
|
|
550 return !dataIncluded[8];
|
|
551 case PF10:
|
|
552 return !dataIncluded[9];
|
|
553 case PF11:
|
|
554 return !dataIncluded[10];
|
|
555 case PF12:
|
|
556 return !dataIncluded[11];
|
|
557 case PF13:
|
|
558 return !dataIncluded[12];
|
|
559 case PF14:
|
|
560 return !dataIncluded[13];
|
|
561 case PF15:
|
|
562 return !dataIncluded[14];
|
|
563 case PF16:
|
|
564 return !dataIncluded[15];
|
|
565 case PF17:
|
|
566 return !dataIncluded[16];
|
|
567 case PF18:
|
|
568 return !dataIncluded[17];
|
|
569 case PF19:
|
|
570 return !dataIncluded[18];
|
|
571 case PF20:
|
|
572 return !dataIncluded[19];
|
|
573 case PF21:
|
|
574 return !dataIncluded[20];
|
|
575 case PF22:
|
|
576 return !dataIncluded[21];
|
|
577 case PF23:
|
|
578 return !dataIncluded[22];
|
|
579 case PF24:
|
|
580 return !dataIncluded[23];
|
|
581
|
|
582 default:
|
|
583 return true;
|
|
584
|
|
585 }
|
|
586
|
|
587 }
|
|
588
|
|
589 /**
|
|
590 * Help request -
|
|
591 *
|
|
592 *
|
|
593 * See notes inside method
|
|
594 */
|
|
595 public final void sendHelpRequest() {
|
|
596
|
|
597 // Client sends header 000D12A0000004000003####F3FFEF
|
|
598 // operation code 3
|
|
599 // row - first ##
|
|
600 // column - second ##
|
|
601 // F3 - Help Aid Key
|
|
602 // System.out.println("Help request sent");
|
|
603 baosp.write(screen52.getCurrentRow());
|
|
604 baosp.write(screen52.getCurrentCol());
|
|
605 baosp.write(AID_HELP);
|
|
606
|
|
607 try {
|
|
608 writeGDS(0, 3, baosp.toByteArray());
|
|
609 } catch (IOException ioe) {
|
|
610
|
|
611 log.warn(ioe.getMessage());
|
|
612 }
|
|
613 baosp.reset();
|
|
614 }
|
|
615
|
|
616 /**
|
|
617 * Attention Key -
|
|
618 *
|
|
619 *
|
|
620 * See notes inside method
|
|
621 */
|
|
622 public final void sendAttentionKey() {
|
|
623
|
|
624 // Client sends header 000A12A000004400000FFEF
|
|
625 // 0x40 -> 01000000
|
|
626 //
|
|
627 // flags
|
|
628 // bit 0 - ERR
|
|
629 // bit 1 - ATN Attention
|
|
630 // bits 2-4 - reserved
|
|
631 // bit 5 - SRQ system request
|
|
632 // bit 6 - TRQ Test request key
|
|
633 // bit 7 - HLP
|
|
634
|
|
635 // System.out.println("Attention key sent");
|
|
636
|
|
637 try {
|
|
638 writeGDS(0x40, 0, null);
|
|
639 } catch (IOException ioe) {
|
|
640
|
|
641 log.warn(ioe.getMessage());
|
|
642 }
|
|
643 }
|
|
644
|
|
645 /**
|
|
646 * Opens a dialog and asks the user before sending a request
|
|
647 *
|
|
648 * @see {@link #systemRequest(String)}
|
|
649 */
|
|
650 public final void systemRequest() {
|
|
651 final String sysreq = this.controller.showSystemRequest();
|
|
652 systemRequest(sysreq);
|
|
653 }
|
|
654
|
|
655 /**
|
|
656 * @param sr - system request option
|
|
657 * @see {@link #systemRequest(String)}
|
|
658 */
|
|
659 public final void systemRequest(char sr) {
|
|
660 systemRequest(Character.toString(sr));
|
|
661 }
|
|
662
|
|
663 /**
|
|
664 * System request, taken from the rfc1205, 5250 Telnet interface section 4.3
|
|
665 *
|
|
666 * @param sr system request option (allowed to be null, but than nothing happens)
|
|
667 */
|
|
668 public final void systemRequest(String sr) {
|
|
669 byte[] bytes = null;
|
|
670
|
|
671 if ( (sr != null) && (sr.length() > 0)) {
|
|
672 // XXX: Not sure, if this is a sufficient check for 'clear dataq'
|
|
673 if (sr.charAt(0) == '2') {
|
|
674 dsq.clear();
|
|
675 }
|
|
676 for (int i = 0, l = sr.length(); i < l; i++) {
|
|
677 baosp.write(codePage.uni2ebcdic(sr.charAt(i)));
|
|
678 }
|
|
679 bytes = baosp.toByteArray();
|
|
680 }
|
|
681
|
|
682 try {
|
|
683 writeGDS(4, 0, bytes);
|
|
684 } catch (IOException ioe) {
|
|
685 log.info(ioe.getMessage());
|
|
686 }
|
|
687 baosp.reset();
|
|
688 }
|
|
689
|
|
690 /**
|
|
691 * Cancel Invite - taken from the rfc1205 - 5250 Telnet interface section
|
|
692 * 4.3
|
|
693 *
|
|
694 * See notes inside method
|
|
695 */
|
|
696 public final void cancelInvite() {
|
|
697
|
|
698 // screen52.setStatus(Screen5250.STATUS_SYSTEM,
|
|
699 // Screen5250.STATUS_VALUE_ON, null);
|
|
700 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,
|
|
701 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED);
|
|
702
|
|
703 // from rfc1205 section 4.3
|
|
704 // Server: Sends header with the 000A12A0 00000400 000AFFEF
|
|
705 // Opcode = Cancel Invite.
|
|
706
|
|
707 // Client: sends header with the 000A12A0 00000400 000AFFEF
|
|
708 // Opcode = Cancel Invite to
|
|
709 // indicate that the work station is
|
|
710 // no longer invited.
|
|
711 try {
|
|
712 writeGDS(0, 10, null);
|
|
713 } catch (IOException ioe) {
|
|
714
|
|
715 log.warn(ioe.getMessage());
|
|
716 }
|
|
717
|
|
718 }
|
|
719
|
|
720 public final void hostPrint(int aid) {
|
|
721
|
|
722 if (screen52.isStatusErrorCode()) {
|
|
723 screen52.restoreErrorLine();
|
|
724 screen52.setStatus(Screen5250.STATUS_ERROR_CODE,
|
|
725 Screen5250.STATUS_VALUE_OFF, null);
|
|
726 }
|
|
727
|
|
728 screen52.setCursorActive(false);
|
|
729 // screen52.setStatus(Screen5250.STATUS_SYSTEM,
|
|
730 // Screen5250.STATUS_VALUE_ON, null);
|
|
731 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,
|
|
732 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED);
|
|
733
|
|
734 // From client access ip capture
|
|
735 // it seems to use an operation code of 3 and 4
|
|
736 // also note that the flag field that says reserved is being sent as
|
|
737 // well
|
|
738 // with a value of 0x80
|
|
739 //
|
|
740 // I have tried with not setting these flags and sending with 3 or 1
|
|
741 // there is no effect and I still get a host print screen. Go figure
|
|
742 //0000: 000D 12A0 0000 0400 8003 1407 F6FFEF
|
|
743 //0000: 000D 12A0 0000 0400 8001 110E F6FFEF
|
|
744 //
|
|
745 // Client sends header 000D12A0000004000003####F6FFEF
|
|
746 // operation code 3
|
|
747 // row - first ##
|
|
748 // column - second ##
|
|
749 // F6 - Print Aid Key
|
|
750
|
|
751 baosp.write(screen52.getCurrentRow());
|
|
752 baosp.write(screen52.getCurrentCol());
|
|
753 baosp.write(AID_PRINT); // aid key
|
|
754
|
|
755 try {
|
|
756 writeGDS(0, 3, baosp.toByteArray());
|
|
757 } catch (IOException ioe) {
|
|
758
|
|
759 log.warn(ioe.getMessage());
|
|
760 }
|
|
761 baosp.reset();
|
|
762 }
|
|
763
|
|
764 public final void toggleDebug() {
|
|
765 producer.toggleDebug(codePage);
|
|
766 }
|
|
767
|
|
768 // write gerneral data stream
|
|
769 private final void writeGDS(int flags, int opcode, byte abyte0[])
|
|
770 throws IOException {
|
|
771
|
|
772 // Added to fix for JDK 1.4 this was null coming from another method.
|
|
773 // There was a weird keyRelease event coming from another panel when
|
|
774 // using a key instead of the mouse to select button.
|
|
775 // The other method was fixed as well but this check should be here
|
|
776 // anyway.
|
|
777 if (bout == null)
|
|
778 return;
|
|
779
|
|
780 int length;
|
|
781 if (abyte0 != null)
|
|
782 length = abyte0.length + 10;
|
|
783 else
|
|
784 length = 10;
|
|
785
|
|
786 // refer to rfc1205 - 5250 Telnet interface
|
|
787 // Section 3. Data Stream Format
|
|
788
|
|
789 // Logical Record Length - 16 bits
|
|
790 baosrsp.write(length >> 8); // Length LL
|
|
791 baosrsp.write(length & 0xff); // LL
|
|
792
|
|
793 // Record Type - 16 bits
|
|
794 // It should always be set to '12A0'X to indicate the
|
|
795 // General Data Stream (GDS) record type.
|
|
796 baosrsp.write(18); // 0x12
|
|
797 baosrsp.write(160); // 0xA0
|
|
798
|
|
799 // the next 16 bits are not used
|
|
800 baosrsp.write(0); // 0x00
|
|
801 baosrsp.write(0); // 0x00
|
|
802
|
|
803 // The second part is meant to be variable in length
|
|
804 // currently this portion is 4 octets long (1 byte or 8 bits for us ;-O)
|
|
805 baosrsp.write(4); // 0x04
|
|
806
|
|
807 baosrsp.write(flags); // flags
|
|
808 // bit 0 - ERR
|
|
809 // bit 1 - ATN Attention
|
|
810 // bits 2-4 - reserved
|
|
811 // bit 5 - SRQ system request
|
|
812 // bit 6 - TRQ Test request key
|
|
813 // bit 7 - HLP
|
|
814 baosrsp.write(0); // reserved - set to 0x00
|
|
815 baosrsp.write(opcode); // opcode
|
|
816
|
|
817 if (abyte0 != null)
|
|
818 baosrsp.write(abyte0, 0, abyte0.length);
|
|
819
|
|
820 baosrsp = appendByteStream(baosrsp.toByteArray());
|
|
821
|
|
822 // make sure we indicate no more to be sent
|
|
823 baosrsp.write(IAC);
|
|
824 baosrsp.write(EOR);
|
|
825
|
|
826 baosrsp.writeTo(bout);
|
|
827
|
|
828 // byte[] b = new byte[baosrsp.size()];
|
|
829 // b = baosrsp.toByteArray();
|
|
830 // dump(b);
|
|
831 bout.flush();
|
|
832 // baos = null;
|
|
833 baosrsp.reset();
|
|
834 }
|
|
835
|
|
836 protected final int getOpCode() {
|
|
837
|
|
838 return bk.getOpCode();
|
|
839 }
|
|
840
|
|
841 // private final void sendNotify() throws IOException {
|
|
842 //
|
|
843 // writeGDS(0, 0, null);
|
|
844 // }
|
|
845
|
|
846 protected boolean[] getActiveAidKeys() {
|
|
847 boolean aids[] = new boolean[dataIncluded.length];
|
|
848 System.arraycopy(dataIncluded,0,aids,0,dataIncluded.length);
|
|
849 return aids;
|
|
850 }
|
|
851
|
|
852 private final void setInvited() {
|
|
853
|
|
854 log.debug("invited");
|
|
855 if (!screen52.isStatusErrorCode())
|
|
856 screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_NOTINHIBITED,
|
|
857 ScreenOIA.OIA_LEVEL_INPUT_INHIBITED);
|
|
858
|
|
859 invited = true;
|
|
860 }
|
|
861
|
|
862 // WVL - LDC : 05/08/2005 : TFX.006253 - Support STRPCCMD
|
|
863 private void strpccmd()
|
|
864 {
|
|
865 try
|
|
866 {
|
|
867 int str = 11;
|
|
868 char c;
|
|
869 ScreenPlanes planes = screen52.getPlanes();
|
|
870 c = planes.getChar(str);
|
|
871 boolean waitFor = !(c == 'a');
|
|
872
|
|
873 StringBuffer command = new StringBuffer();
|
|
874 for (int i = str+1; i < 132; i++)
|
|
875 {
|
|
876 c = planes.getChar(i);
|
|
877 if (Character.isISOControl(c))
|
|
878 c = ' ';
|
|
879 command.append(c);
|
|
880 }
|
|
881
|
|
882 String cmd = command.toString().trim();
|
|
883
|
|
884 run(cmd, waitFor);
|
|
885 }
|
|
886 finally
|
|
887 {
|
|
888 strpccmd = false;
|
|
889 screen52.sendKeys(TN5250jConstants.MNEMONIC_ENTER);
|
|
890 }
|
|
891 }
|
|
892
|
|
893 // WVL - LDC : 05/08/2005 : TFX.006253 - Support STRPCCMD
|
|
894 private void run(String cmd, boolean waitFor)
|
|
895 {
|
|
896 try
|
|
897 {
|
|
898 log.debug("RUN cmd = " + cmd);
|
|
899 log.debug("RUN wait = " + waitFor);
|
|
900
|
|
901 Runtime r = Runtime.getRuntime();
|
|
902 Process p = r.exec(cmd);
|
|
903 if (waitFor)
|
|
904 {
|
|
905 int result = p.waitFor();
|
|
906 log.debug("RUN result = " + result);
|
|
907 }
|
|
908 }
|
|
909 catch (Throwable t)
|
|
910 {
|
|
911 log.error(t);
|
|
912 }
|
|
913 }
|
|
914
|
|
915
|
|
916 // WVL - LDC : TR.000300 : Callback scenario from 5250
|
|
917 /**
|
|
918 * Activate or deactivate the command scanning behaviour.
|
|
919 *
|
|
920 * @param scan
|
|
921 * if true, scanning is enabled; disabled otherwise.
|
|
922 *
|
|
923 * @see scan4Cmd()
|
|
924 */
|
|
925 public void setScanningEnabled(boolean scan) {
|
|
926 this.scan = scan;
|
|
927 }
|
|
928
|
|
929 // WVL - LDC : TR.000300 : Callback scenario from 5250
|
|
930 /**
|
|
931 * Checks whether command scanning is enabled.
|
|
932 *
|
|
933 * @return true is command scanning is enabled; false otherwise.
|
|
934 */
|
|
935 public boolean isScanningEnabled() {
|
|
936 return this.scan;
|
|
937 }
|
|
938
|
|
939 // WVL - LDC : TR.000300 : Callback scenario from 5250
|
|
940 /**
|
|
941 * When command scanning is activated, the terminal reads the first and
|
|
942 * second character in the datastream (the zero position allows to
|
|
943 * devisualize the scan stream). If the sequence <code>#!</code> is
|
|
944 * encountered and if this sequence is <strong>not </strong> followed by a
|
|
945 * blank character, the {@link parseCommand(ScreenChar[])}is called.
|
|
946 */
|
|
947 private void scan() {
|
|
948 // System.out.println("Checking command : " +
|
|
949 // screen52.screen[1].getChar() + screen52.screen[2].getChar());
|
|
950
|
|
951 // ScreenChar[] screen = screen52.screen;
|
|
952 ScreenPlanes planes = screen52.getPlanes();
|
|
953
|
|
954 if ((planes.getChar(STRSCAN) == '#')
|
|
955 && (planes.getChar(STRSCAN + 1) == '!')
|
|
956 && (planes.getChar(STRSCAN + 2) != ' ')) {
|
|
957 try {
|
|
958 parseCommand();
|
|
959 } catch (Throwable t) {
|
|
960 log.info("Exec cmd: " + t.getMessage());
|
|
961 t.printStackTrace();
|
|
962 }
|
|
963 }
|
|
964 }
|
|
965
|
|
966 // WVL - LDC : TR.000300 : Callback scenario from 5250
|
|
967 /**
|
|
968 * The screen is parsed starting from second position until a white space is
|
|
969 * encountered. When found the Session#execCommand(String, int) is
|
|
970 * called with the parsed string. The position immediately following the
|
|
971 * encountered white space, separating the command from the rest of the
|
|
972 * screen, is passed as starting index.
|
|
973 *
|
|
974 * Note that the character at the starting position can potentially be a
|
|
975 * white space itself. The starting position in <code>execCommand</code>
|
|
976 * provided to make the scanning sequence more flexible. We'd like for
|
|
977 * example to embed also a <code>+</code> or <code>-</code> sign to
|
|
978 * indicate whether the tnvt should trigger a repaint or not. This would
|
|
979 * allow the flashing of command sequences without them becoming visible.
|
|
980 *
|
|
981 * <ul>
|
|
982 * <li><strong>PRE </strong> The screen character at position
|
|
983 * <code>STRSCAN + 2</code> is not a white space.</li>
|
|
984 * </ul>
|
|
985 */
|
|
986 private void parseCommand() {
|
|
987 // Search for the command i.e. the first token in the stream
|
|
988 // after the #! sequence separated by a space from the rest
|
|
989 // of the screen.
|
|
990 char[] screen = screen52.getScreenAsAllChars();
|
|
991 for (int s = STRSCAN + 2, i = s; i < screen.length; i++) {
|
|
992 if (screen[i] == ' ') {
|
|
993 String command = new String(screen, s, i - s);
|
|
994
|
|
995 // Skip all white spaces between the command and the rest of
|
|
996 // the screen.
|
|
997 //for (; (i < screen.length) && (screen[i] == ' '); i++);
|
|
998
|
|
999 String remainder = new String(screen, i + 1, screen.length
|
|
1000 - (i + 1));
|
|
1001 // System.out.println("Sensing action command in the input! = "
|
|
1002 // + command);
|
|
1003 controller.fireScanned(command, remainder);
|
|
1004 break;
|
|
1005 }
|
|
1006 }
|
|
1007 }
|
|
1008
|
|
1009 public void run() {
|
|
1010
|
|
1011 if (enhanced)
|
|
1012 sfParser = new WTDSFParser(this);
|
|
1013
|
|
1014 bk = new Stream5250();
|
|
1015
|
|
1016 while (keepTrucking) {
|
|
1017
|
|
1018 try {
|
|
1019 bk.initialize((byte[]) dsq.take());
|
|
1020 } catch (InterruptedException ie) {
|
|
1021 log.warn(" vt thread interrupted and stopping ");
|
|
1022 keepTrucking = false;
|
|
1023 continue;
|
|
1024 }
|
|
1025
|
|
1026 // lets play nicely with the others on the playground
|
|
1027 // me.yield();
|
|
1028
|
|
1029 Thread.yield();
|
|
1030
|
|
1031 invited = false;
|
|
1032
|
|
1033 screen52.setCursorActive(false);
|
|
1034
|
|
1035 // System.out.println("operation code: " + bk.getOpCode());
|
|
1036 if (bk == null)
|
|
1037 continue;
|
|
1038
|
|
1039 switch (bk.getOpCode()) {
|
|
1040 case 00:
|
|
1041 log.debug("No operation");
|
|
1042 break;
|
|
1043 case 1:
|
|
1044 log.debug("Invite Operation");
|
|
1045 parseIncoming();
|
|
1046 // screen52.setKeyboardLocked(false);
|
|
1047 pendingUnlock = true;
|
|
1048 cursorOn = true;
|
|
1049 setInvited();
|
|
1050 break;
|
|
1051 case 2:
|
|
1052 log.debug("Output Only");
|
|
1053 parseIncoming();
|
|
1054 // System.out.println(screen52.dirty);
|
|
1055 screen52.updateDirty();
|
|
1056
|
|
1057 // invited = true;
|
|
1058
|
|
1059 break;
|
|
1060 case 3:
|
|
1061 log.debug("Put/Get Operation");
|
|
1062 parseIncoming();
|
|
1063 // inviteIt =true;
|
|
1064 setInvited();
|
|
1065 if (!firstScreen) {
|
|
1066 firstScreen = true;
|
|
1067 controller.fireSessionChanged(TN5250jConstants.STATE_CONNECTED);
|
|
1068 }
|
|
1069 break;
|
|
1070 case 4:
|
|
1071 log.debug("Save Screen Operation");
|
|
1072 parseIncoming();
|
|
1073 break;
|
|
1074
|
|
1075 case 5:
|
|
1076 log.debug("Restore Screen Operation");
|
|
1077 parseIncoming();
|
|
1078 break;
|
|
1079 case 6:
|
|
1080 log.debug("Read Immediate");
|
|
1081 sendAidKey(0);
|
|
1082 break;
|
|
1083 case 7:
|
|
1084 log.debug("Reserved");
|
|
1085 break;
|
|
1086 case 8:
|
|
1087 log.debug("Read Screen Operation");
|
|
1088 try {
|
|
1089 readScreen();
|
|
1090 } catch (IOException ex) {
|
|
1091 log.warn(ex.getMessage());
|
|
1092 }
|
|
1093 break;
|
|
1094
|
|
1095 case 9:
|
|
1096 log.debug("Reserved");
|
|
1097 break;
|
|
1098
|
|
1099 case 10:
|
|
1100 log.debug("Cancel Invite Operation");
|
|
1101 cancelInvite();
|
|
1102 break;
|
|
1103
|
|
1104 case 11:
|
|
1105 log.debug("Turn on message light");
|
|
1106 screen52.getOIA().setMessageLightOn();
|
|
1107 screen52.setCursorActive(true);
|
|
1108
|
|
1109 break;
|
|
1110 case 12:
|
|
1111 log.debug("Turn off Message light");
|
|
1112 screen52.getOIA().setMessageLightOff();
|
|
1113 screen52.setCursorActive(true);
|
|
1114
|
|
1115 break;
|
|
1116 default:
|
|
1117 break;
|
|
1118 }
|
|
1119
|
|
1120 if (screen52.isUsingGuiInterface())
|
|
1121 screen52.drawFields();
|
|
1122
|
|
1123 try {
|
|
1124 if (!strpccmd) {
|
|
1125 screen52.updateDirty();
|
|
1126 } else {
|
|
1127 strpccmd();
|
|
1128 }
|
|
1129 } catch (Exception exd) {
|
|
1130 log.warn(" tnvt.run: " + exd.getMessage());
|
|
1131 exd.printStackTrace();
|
|
1132 }
|
|
1133
|
|
1134 if (pendingUnlock && !screen52.isStatusErrorCode()) {
|
|
1135 screen52.getOIA().setKeyBoardLocked(false);
|
|
1136 pendingUnlock = false;
|
|
1137 }
|
|
1138
|
|
1139 if (cursorOn && !screen52.getOIA().isKeyBoardLocked()) {
|
|
1140 screen52.setCursorActive(true);
|
|
1141 cursorOn = false;
|
|
1142 }
|
|
1143
|
|
1144 // lets play nicely with the others on the playground
|
|
1145 //me.yield();
|
|
1146 Thread.yield();
|
|
1147
|
|
1148 }
|
|
1149 }
|
|
1150
|
|
1151 public void dumpStuff() {
|
|
1152
|
|
1153 if (log.isDebugEnabled()) {
|
|
1154 log.debug(" Pending unlock " + pendingUnlock);
|
|
1155 log.debug(" Status Error " + screen52.isStatusErrorCode());
|
|
1156 log.debug(" Keyboard Locked " + screen52.getOIA().isKeyBoardLocked());
|
|
1157 log.debug(" Cursor On " + cursorOn);
|
|
1158 log.debug(" Cursor Active " + screen52.cursorActive);
|
|
1159 }
|
|
1160
|
|
1161 }
|
|
1162
|
|
1163
|
|
1164 private final void readScreen() throws IOException {
|
|
1165 int rows = screen52.getRows();
|
|
1166 int cols = screen52.getColumns();
|
|
1167 byte abyte0[] = new byte[rows * cols];
|
|
1168 fillScreenArray(abyte0, rows, cols);
|
|
1169 writeGDS(0, 0, abyte0);
|
|
1170 abyte0 = null;
|
|
1171 }
|
|
1172
|
|
1173 private final void fillScreenArray(byte[] sa, int rows, int cols) {
|
|
1174 int la = 32;
|
|
1175 int sac = 0;
|
|
1176 int len = rows * cols;
|
|
1177
|
|
1178 ScreenPlanes planes = screen52.planes;
|
|
1179
|
|
1180 for (int y = 0; y < len; y++) { // save the screen data
|
|
1181
|
|
1182 if (planes.isAttributePlace(y)) {
|
|
1183 la = planes.getCharAttr(y);
|
|
1184 sa[sac++] = (byte) la;
|
|
1185 } else {
|
|
1186 if (planes.getCharAttr(y) != la) {
|
|
1187 la = planes.getCharAttr(y);
|
|
1188 sac--;
|
|
1189 sa[sac++] = (byte) la;
|
|
1190 }
|
|
1191 //LDC: Check to see if it is an displayable character. If not,
|
|
1192 // do not convert the character.
|
|
1193 // The characters on screen are in unicode
|
|
1194 //sa[sac++] =
|
|
1195 // (byte)codePage.uni2ebcdic(screen52.screen[y].getChar());
|
|
1196 char ch = planes.getChar(y);
|
|
1197 byte byteCh = (byte) ch;
|
|
1198 if (isDataUnicode(ch))
|
|
1199 byteCh = codePage.uni2ebcdic(ch);
|
|
1200 sa[sac++] = byteCh;
|
|
1201 }
|
|
1202 }
|
|
1203 }
|
|
1204
|
|
1205 private final void fillRegenerationBuffer(ByteArrayOutputStream sc, int rows, int cols)
|
|
1206 throws IOException {
|
|
1207
|
|
1208 int la = 32;
|
|
1209 int sac = 0;
|
|
1210 int len = rows * cols;
|
|
1211
|
|
1212 ScreenPlanes planes = screen52.planes;
|
|
1213 byte[] sa = new byte[len];
|
|
1214
|
|
1215 try {
|
|
1216 boolean guiExists = sfParser != null && sfParser.isGuisExists();
|
|
1217
|
|
1218
|
|
1219 for (int y = 0; y < len; y++) { // save the screen data
|
|
1220
|
|
1221 if (guiExists) {
|
|
1222
|
|
1223 byte[] guiSeg = sfParser.getSegmentAtPos(y);
|
|
1224 if (guiSeg != null) {
|
|
1225 //log.info(" gui saved at " + y + " - " + screen52.getRow(y) + "," +
|
|
1226 // screen52.getCol(y));
|
|
1227
|
|
1228 byte[] gsa = new byte[sa.length + guiSeg.length + 2];
|
|
1229 System.arraycopy(sa,0,gsa,0,sa.length);
|
|
1230 System.arraycopy(guiSeg,0,gsa,sac+2,guiSeg.length);
|
|
1231 sa = new byte[gsa.length];
|
|
1232 System.arraycopy(gsa,0,sa,0,gsa.length);
|
|
1233 sa[sac++] = (byte)0x04;
|
|
1234 sa[sac++] = (byte)0x11;
|
|
1235 sac += guiSeg.length;
|
|
1236 //y--;
|
|
1237 // continue;
|
|
1238 }
|
|
1239 }
|
|
1240 if (planes.isAttributePlace(y)) {
|
|
1241 la = planes.getCharAttr(y);
|
|
1242 sa[sac++] = (byte) la;
|
|
1243 } else {
|
|
1244 if (planes.getCharAttr(y) != la) {
|
|
1245 la = planes.getCharAttr(y);
|
|
1246 sac--;
|
|
1247 sa[sac++] = (byte) la;
|
|
1248 }
|
|
1249 //LDC: Check to see if it is an displayable character. If not,
|
|
1250 // do not convert the character.
|
|
1251 // The characters on screen are in unicode
|
|
1252 //sa[sac++] =
|
|
1253 // (byte)codePage.uni2ebcdic(screen52.screen[y].getChar());
|
|
1254 char ch = planes.getChar(y);
|
|
1255 byte byteCh = (byte) ch;
|
|
1256 if (isDataUnicode(ch))
|
|
1257 byteCh = codePage.uni2ebcdic(ch);
|
|
1258 sa[sac++] = byteCh;
|
|
1259 }
|
|
1260 }
|
|
1261 }
|
|
1262 catch(Exception exc) {
|
|
1263
|
|
1264 log.info(exc.getMessage());
|
|
1265 exc.printStackTrace();
|
|
1266 }
|
|
1267 sc.write(sa);
|
|
1268 }
|
|
1269
|
|
1270 public final void saveScreen() throws IOException {
|
|
1271
|
|
1272 ByteArrayOutputStream sc = new ByteArrayOutputStream();
|
|
1273 sc.write(4);
|
|
1274 sc.write(0x12); // 18
|
|
1275 sc.write(0); // 18
|
|
1276 sc.write(0); // 18
|
|
1277
|
|
1278 sc.write((byte) screen52.getRows()); // store the current size
|
|
1279 sc.write((byte) screen52.getColumns()); // ""
|
|
1280
|
|
1281 int cp = screen52.getCurrentPos(); // save off current position
|
|
1282 // fix below submitted by Mitch Blevins
|
|
1283 //int cp = screen52.getScreenFields().getCurrentFieldPos();
|
|
1284 // save off current position
|
|
1285 sc.write((byte) (cp >> 8 & 0xff)); // ""
|
|
1286 sc.write((byte) (cp & 0xff)); // ""
|
|
1287
|
|
1288 sc.write((byte) (screen52.homePos >> 8 & 0xff)); // save home pos
|
|
1289 sc.write((byte) (screen52.homePos & 0xff)); // ""
|
|
1290
|
|
1291 int rows = screen52.getRows(); // store the current size
|
|
1292 int cols = screen52.getColumns(); // ""
|
|
1293
|
|
1294 // byte[] sa = new byte[rows * cols];
|
|
1295 fillRegenerationBuffer(sc,rows,cols);
|
|
1296 // fillScreenArray(sa, rows, cols);
|
|
1297 //
|
|
1298 // sc.write(sa);
|
|
1299 // sa = null;
|
|
1300 int sizeFields = screen52.getScreenFields().getSize();
|
|
1301 sc.write((byte) (sizeFields >> 8 & 0xff)); // ""
|
|
1302 sc.write((byte) (sizeFields & 0xff)); // ""
|
|
1303
|
|
1304 if (sizeFields > 0) {
|
|
1305 int x = 0;
|
|
1306 int s = screen52.getScreenFields().getSize();
|
|
1307 ScreenField sf = null;
|
|
1308 while (x < s) {
|
|
1309 sf = screen52.getScreenFields().getField(x);
|
|
1310 sc.write((byte) sf.getAttr()); // attribute
|
|
1311 int sp = sf.startPos();
|
|
1312 sc.write((byte) (sp >> 8 & 0xff)); // ""
|
|
1313 sc.write((byte) (sp & 0xff)); // ""
|
|
1314 if (sf.mdt)
|
|
1315 sc.write((byte) 1);
|
|
1316 else
|
|
1317 sc.write((byte) 0);
|
|
1318 sc.write((byte) (sf.getLength() >> 8 & 0xff)); // ""
|
|
1319 sc.write((byte) (sf.getLength() & 0xff)); // ""
|
|
1320 sc.write((byte) sf.getFFW1() & 0xff);
|
|
1321 sc.write((byte) sf.getFFW2() & 0xff);
|
|
1322 sc.write((byte) sf.getFCW1() & 0xff);
|
|
1323 sc.write((byte) sf.getFCW2() & 0xff);
|
|
1324 log.debug("Saved ");
|
|
1325 log.debug(sf.toString());
|
|
1326
|
|
1327 x++;
|
|
1328 }
|
|
1329 sf = null;
|
|
1330 }
|
|
1331
|
|
1332 // The following two lines of code looks to have caused all sorts of
|
|
1333 // problems so for now we have commented them out.
|
|
1334 // screen52.getScreenFields().setCurrentField(null); // set it to null
|
|
1335 // for GC ?
|
|
1336 // screen52.clearTable();
|
|
1337
|
|
1338 try {
|
|
1339 writeGDS(0, 3, sc.toByteArray());
|
|
1340 } catch (IOException ioe) {
|
|
1341
|
|
1342 log.warn(ioe.getMessage());
|
|
1343 }
|
|
1344
|
|
1345 sc = null;
|
|
1346 log.debug("Save Screen end ");
|
|
1347 }
|
|
1348
|
|
1349 /**
|
|
1350 *
|
|
1351 * @throws IOException
|
|
1352 */
|
|
1353 public final void restoreScreen() throws IOException {
|
|
1354 int which = 0;
|
|
1355
|
|
1356 ScreenPlanes planes = screen52.planes;
|
|
1357
|
|
1358 try {
|
|
1359 log.debug("Restore ");
|
|
1360
|
|
1361 bk.getNextByte();
|
|
1362 bk.getNextByte();
|
|
1363
|
|
1364 int rows = bk.getNextByte() & 0xff;
|
|
1365 int cols = bk.getNextByte() & 0xff;
|
|
1366 int pos = bk.getNextByte() << 8 & 0xff00; // current position
|
|
1367 pos |= bk.getNextByte() & 0xff;
|
|
1368 int hPos = bk.getNextByte() << 8 & 0xff00; // home position
|
|
1369 hPos |= bk.getNextByte() & 0xff;
|
|
1370 if (rows != screen52.getRows())
|
|
1371 screen52.setRowsCols(rows, cols);
|
|
1372 screen52.clearAll(); // initialize what we currenty have
|
|
1373 if (sfParser != null && sfParser.isGuisExists())
|
|
1374 sfParser.clearGuiStructs();
|
|
1375
|
|
1376 int b = 32;
|
|
1377 int la = 32;
|
|
1378 int len = rows * cols;
|
|
1379 for (int y = 0; y < len; y++) {
|
|
1380
|
|
1381 b = bk.getNextByte();
|
|
1382 if (b == 0x04) {
|
|
1383
|
|
1384 log.info(" gui restored at " + y + " - " + screen52.getRow(y) + "," +
|
|
1385 screen52.getCol(y));
|
|
1386 int command = bk.getNextByte();
|
|
1387 byte[] seg = bk.getSegment();
|
|
1388
|
|
1389 if (seg.length > 0) {
|
|
1390 screen52.goto_XY(y);
|
|
1391 sfParser.parseWriteToDisplayStructuredField(seg);
|
|
1392 }
|
|
1393 y--;
|
|
1394 // screen52.goto_XY(y);
|
|
1395 }
|
|
1396 else {
|
|
1397 // b = bk.getNextByte();
|
|
1398 if (planes.isUseGui(y))
|
|
1399 continue;
|
|
1400 if (isAttribute(b)) {
|
|
1401 planes.setScreenCharAndAttr(y, planes.getChar(y), b, true);
|
|
1402 la = b;
|
|
1403
|
|
1404 }
|
|
1405 else {
|
|
1406 //LDC - 12/02/2003 - Check to see if it is an displayable
|
|
1407 // character. If not,
|
|
1408 // do not convert the character.
|
|
1409 // The characters on screen are in unicode
|
|
1410 char ch = (char) b;
|
|
1411 if (isDataEBCDIC(b))
|
|
1412 ch = codePage.ebcdic2uni(b);
|
|
1413
|
|
1414 planes.setScreenCharAndAttr(y, ch, la, false);
|
|
1415 }
|
|
1416 }
|
|
1417 }
|
|
1418
|
|
1419 int numFields = bk.getNextByte() << 8 & 0xff00;
|
|
1420 numFields |= bk.getNextByte() & 0xff;
|
|
1421 log.debug("number of fields " + numFields);
|
|
1422
|
|
1423 if (numFields > 0) {
|
|
1424 int x = 0;
|
|
1425 int attr = 0;
|
|
1426 int fPos = 0;
|
|
1427 int fLen = 0;
|
|
1428 int ffw1 = 0;
|
|
1429 int ffw2 = 0;
|
|
1430 int fcw1 = 0;
|
|
1431 int fcw2 = 0;
|
|
1432 boolean mdt = false;
|
|
1433
|
|
1434 ScreenField sf = null;
|
|
1435 while (x < numFields) {
|
|
1436
|
|
1437 attr = bk.getNextByte();
|
|
1438 fPos = bk.getNextByte() << 8 & 0xff00;
|
|
1439 fPos |= bk.getNextByte() & 0xff;
|
|
1440 if (bk.getNextByte() == 1)
|
|
1441 mdt = true;
|
|
1442 else
|
|
1443 mdt = false;
|
|
1444 fLen = bk.getNextByte() << 8 & 0xff00;
|
|
1445 fLen |= bk.getNextByte() & 0xff;
|
|
1446 ffw1 = bk.getNextByte();
|
|
1447 ffw2 = bk.getNextByte();
|
|
1448 fcw1 = bk.getNextByte();
|
|
1449 fcw2 = bk.getNextByte();
|
|
1450
|
|
1451 sf = screen52.getScreenFields().setField(attr,
|
|
1452 screen52.getRow(fPos), screen52.getCol(fPos), fLen,
|
|
1453 ffw1, ffw2, fcw1, fcw2);
|
|
1454
|
|
1455 while (fLen-- > 0) {
|
|
1456
|
|
1457 // now we set the field plane attributes
|
|
1458 planes.setScreenFieldAttr(fPos++,ffw1);
|
|
1459
|
|
1460 }
|
|
1461
|
|
1462 if (mdt) {
|
|
1463 sf.setMDT();
|
|
1464 screen52.getScreenFields().setMasterMDT();
|
|
1465 }
|
|
1466 if (log.isDebugEnabled()) {
|
|
1467 log.debug("/nRestored ");
|
|
1468 log.debug(sf.toString());
|
|
1469 }
|
|
1470 x++;
|
|
1471 }
|
|
1472 }
|
|
1473
|
|
1474 // Redraw the gui fields if we are in gui mode
|
|
1475 if (screen52.isUsingGuiInterface())
|
|
1476 screen52.drawFields();
|
|
1477
|
|
1478 screen52.restoreScreen(); // display the screen
|
|
1479
|
|
1480 // The position was saved with currentPos which 1,1 offset of the
|
|
1481 // screen position.
|
|
1482 // The setPendingInsert is the where the cursor position will be
|
|
1483 // displayed after the restore.
|
|
1484 screen52.setPendingInsert(true, screen52.getRow(pos + cols), screen52
|
|
1485 .getCol(pos + cols));
|
|
1486 // We need to offset the pos by -1 since the position is 1,1 based
|
|
1487 // and the goto_XY is 0,0 based.
|
|
1488 screen52.goto_XY(pos - 1);
|
|
1489 screen52.isInField();
|
|
1490 // // Redraw the gui fields if we are in gui mode
|
|
1491 // if (screen52.isUsingGuiInterface())
|
|
1492 // screen52.drawFields();
|
|
1493 } catch (Exception e) {
|
|
1494 log.warn("error restoring screen " + which + " with "
|
|
1495 + e.getMessage());
|
|
1496 }
|
|
1497 }
|
|
1498
|
|
1499 public final boolean waitingForInput() {
|
|
1500
|
|
1501 return waitingForInput;
|
|
1502 }
|
|
1503
|
|
1504 private void parseIncoming() {
|
|
1505
|
|
1506 boolean done = false;
|
|
1507 boolean error = false;
|
|
1508
|
|
1509 try {
|
|
1510 while (bk.hasNext() && !done) {
|
|
1511 byte b = bk.getNextByte();
|
|
1512
|
|
1513 switch (b) {
|
|
1514 case 0:
|
|
1515 case 1:
|
|
1516 break;
|
|
1517 case CMD_SAVE_SCREEN: // 0x02 2 Save Screen
|
|
1518 case 3: // 0x03 3 Save Partial Screen
|
|
1519 log.debug("save screen partial");
|
|
1520 saveScreen();
|
|
1521 break;
|
|
1522
|
|
1523 case ESC: // ESCAPE
|
|
1524 break;
|
|
1525 case 7: // audible bell
|
|
1526 controller.signalBell();
|
|
1527 bk.getNextByte();
|
|
1528 bk.getNextByte();
|
|
1529 break;
|
|
1530 case CMD_WRITE_TO_DISPLAY: // 0x11 17 write to display
|
|
1531 error = writeToDisplay(true);
|
|
1532 // WVL - LDC : TR.000300 : Callback scenario from 5250
|
|
1533 // Only scan when WRITE_TO_DISPLAY operation (i.e. refill
|
|
1534 // screen buffer)
|
|
1535 // has been issued!
|
|
1536 if (scan)
|
|
1537 scan();
|
|
1538
|
|
1539 break;
|
|
1540 case CMD_RESTORE_SCREEN: // 0x12 18 Restore Screen
|
|
1541 case 13: // 0x13 19 Restore Partial Screen
|
|
1542 log.debug("restore screen partial");
|
|
1543 restoreScreen();
|
|
1544 break;
|
|
1545
|
|
1546 case CMD_CLEAR_UNIT_ALTERNATE: // 0x20 32 clear unit alternate
|
|
1547 int param = bk.getNextByte();
|
|
1548 if (param != 0) {
|
|
1549 log.debug(" clear unit alternate error "
|
|
1550 + Integer.toHexString(param));
|
|
1551 sendNegResponse(NR_REQUEST_ERROR, 03, 01, 05,
|
|
1552 " clear unit alternate not supported");
|
|
1553 done = true;
|
|
1554 } else {
|
|
1555 if (screen52.getRows() != 27)
|
|
1556 screen52.setRowsCols(27, 132);
|
|
1557
|
|
1558 screen52.clearAll();
|
|
1559 if (sfParser != null && sfParser.isGuisExists())
|
|
1560 sfParser.clearGuiStructs();
|
|
1561
|
|
1562
|
|
1563 }
|
|
1564 break;
|
|
1565
|
|
1566 case CMD_WRITE_ERROR_CODE: // 0x21 33 Write Error Code
|
|
1567 writeErrorCode();
|
|
1568 error = writeToDisplay(false);
|
|
1569 break;
|
|
1570 case CMD_WRITE_ERROR_CODE_TO_WINDOW: // 0x22 34
|
|
1571 // Write Error Code to window
|
|
1572 writeErrorCodeToWindow();
|
|
1573 error = writeToDisplay(false);
|
|
1574 break;
|
|
1575
|
|
1576 case CMD_READ_SCREEN_IMMEDIATE: // 0x62 98
|
|
1577 case CMD_READ_SCREEN_TO_PRINT: // 0x66 102 read screen to print
|
|
1578 readScreen();
|
|
1579 break;
|
|
1580
|
|
1581 case CMD_CLEAR_UNIT: // 64 0x40 clear unit
|
|
1582 if (screen52.getRows() != 24)
|
|
1583 screen52.setRowsCols(24, 80);
|
|
1584 screen52.clearAll();
|
|
1585 if (sfParser != null && sfParser.isGuisExists())
|
|
1586 sfParser.clearGuiStructs();
|
|
1587
|
|
1588 break;
|
|
1589
|
|
1590 case CMD_CLEAR_FORMAT_TABLE: // 80 0x50 Clear format table
|
|
1591 screen52.clearTable();
|
|
1592 break;
|
|
1593
|
|
1594 case CMD_READ_INPUT_FIELDS: //0x42 66 read input fields
|
|
1595 case CMD_READ_MDT_FIELDS: // 0x52 82 read MDT Fields
|
|
1596 bk.getNextByte();
|
|
1597 bk.getNextByte();
|
|
1598 readType = b;
|
|
1599 screen52.goHome();
|
|
1600 // do nothing with the cursor here it is taken care of
|
|
1601 // in the main loop.
|
|
1602 //////////////// screen52.setCursorOn();
|
|
1603 waitingForInput = true;
|
|
1604 pendingUnlock = true;
|
|
1605 // screen52.setKeyboardLocked(false);
|
|
1606 break;
|
|
1607 case CMD_READ_MDT_IMMEDIATE_ALT: // 0x53 83
|
|
1608 readType = b;
|
|
1609 // screen52.goHome();
|
|
1610 // waitingForInput = true;
|
|
1611 // screen52.setKeyboardLocked(false);
|
|
1612 readImmediate(readType);
|
|
1613 break;
|
|
1614 case CMD_WRITE_STRUCTURED_FIELD: // 243 0xF3 -13 Write
|
|
1615 // structured field
|
|
1616 writeStructuredField();
|
|
1617 break;
|
|
1618 case CMD_ROLL: // 0x23 35 Roll Not sure what it does right now
|
|
1619 int updown = bk.getNextByte();
|
|
1620 int topline = bk.getNextByte();
|
|
1621 int bottomline = bk.getNextByte();
|
|
1622 screen52.rollScreen(updown, topline, bottomline);
|
|
1623 break;
|
|
1624
|
|
1625 default:
|
|
1626 done = true;
|
|
1627 sendNegResponse(NR_REQUEST_ERROR, 03, 01, 01,
|
|
1628 "parseIncoming");
|
|
1629 break;
|
|
1630 }
|
|
1631
|
|
1632 if (error)
|
|
1633 done = true;
|
|
1634 }
|
|
1635 // BEGIN FRAMEWORK
|
|
1636 // I took this out for debugging a problem
|
|
1637 // ScreenField[] a = this.screen52.getScreenFields().getFields();
|
|
1638 // if (log.isDebugEnabled()) {
|
|
1639 // for (int x = 0; x < a.length; x++) {
|
|
1640 // log.debug(a[x].toString());
|
|
1641 // }
|
|
1642 // }
|
|
1643 //
|
|
1644 // String strokes = this.screen52.getKeys();
|
|
1645 // if (!strokes.equals("")) {
|
|
1646 // Tn5250jKeyEvents e = new Tn5250jKeyEvents(this.screen52,
|
|
1647 // strokes);
|
|
1648 // //from the previous screen.
|
|
1649 // Tn5250jController.getCurrent().handleEvent(e);
|
|
1650 // }
|
|
1651 //
|
|
1652 // Tn5250jEvent event = new Tn5250jEvent(screen52);
|
|
1653 // Tn5250jController.getCurrent().handleEvent(event);
|
|
1654 //
|
|
1655 // //END FRAMEWORK
|
|
1656 } catch (Exception exc) {
|
|
1657 log.warn("incoming " + exc.getMessage());
|
|
1658 }
|
|
1659 ;
|
|
1660 }
|
|
1661
|
|
1662 /**
|
|
1663 * This routine handles sending negative responses back to the host.
|
|
1664 *
|
|
1665 * You can find a description of the types of responses to be sent back by
|
|
1666 * looking at section 12.4 of the 5250 Functions Reference manual
|
|
1667 *
|
|
1668 *
|
|
1669 * @param cat
|
|
1670 * @param modifier
|
|
1671 * @param uByte1
|
|
1672 * @param uByte2
|
|
1673 * @param from
|
|
1674 *
|
|
1675 */
|
|
1676 protected void sendNegResponse(int cat, int modifier, int uByte1,
|
|
1677 int uByte2, String from) {
|
|
1678
|
|
1679 try {
|
|
1680
|
|
1681 int os = bk.getByteOffset(-1) & 0xf0;
|
|
1682 int cp = (bk.getCurrentPos() - 1);
|
|
1683 log.info("invalid " + from + " command " + os
|
|
1684 + " at pos " + cp);
|
|
1685 } catch (Exception e) {
|
|
1686
|
|
1687 log.warn("Send Negative Response error " + e.getMessage());
|
|
1688 }
|
|
1689
|
|
1690 baosp.write(cat);
|
|
1691 baosp.write(modifier);
|
|
1692 baosp.write(uByte1);
|
|
1693 baosp.write(uByte2);
|
|
1694
|
|
1695 try {
|
|
1696 writeGDS(128, 0, baosp.toByteArray());
|
|
1697 } catch (IOException ioe) {
|
|
1698
|
|
1699 log.warn(ioe.getMessage());
|
|
1700 }
|
|
1701 baosp.reset();
|
|
1702
|
|
1703 }
|
|
1704
|
|
1705 public void sendNegResponse2(int ec) {
|
|
1706
|
|
1707 screen52.setPrehelpState(true, true, false);
|
|
1708 baosp.write(0x00);
|
|
1709 baosp.write(ec);
|
|
1710
|
|
1711 try {
|
|
1712 writeGDS(1, 0, baosp.toByteArray());
|
|
1713 } catch (IOException ioe) {
|
|
1714
|
|
1715 log.warn(ioe.getMessage());
|
|
1716 }
|
|
1717
|
|
1718 baosp.reset();
|
|
1719 }
|
|
1720
|
|
1721 private boolean writeToDisplay(boolean controlsExist) {
|
|
1722
|
|
1723 boolean error = false;
|
|
1724 boolean done = false;
|
|
1725 int attr;
|
|
1726 byte control0 = 0;
|
|
1727 byte control1 = 0;
|
|
1728 int saRows = screen52.getRows();
|
|
1729 int saCols = screen52.getColumns();
|
|
1730
|
|
1731 try {
|
|
1732 if (controlsExist) {
|
|
1733 control0 = bk.getNextByte();
|
|
1734 control1 = bk.getNextByte();
|
|
1735 processCC0(control0);
|
|
1736 }
|
|
1737 while (bk.hasNext() && !done) {
|
|
1738 // pos = bk.getCurrentPos();
|
|
1739
|
|
1740 // int rowc = screen52.getCurrentRow();
|
|
1741 // int colc = screen52.getCurrentCol();
|
|
1742
|
|
1743 byte bytebk = bk.getNextByte();
|
|
1744
|
|
1745 switch (bytebk) {
|
|
1746
|
|
1747 case 1: // SOH - Start of Header Order
|
|
1748 log.debug("SOH - Start of Header Order");
|
|
1749 error = processSOH();
|
|
1750
|
|
1751 break;
|
|
1752 case 02: // RA - Repeat to address
|
|
1753 log.debug("RA - Repeat to address");
|
|
1754 int row = screen52.getCurrentRow();
|
|
1755 int col = screen52.getCurrentCol();
|
|
1756
|
|
1757 int toRow = bk.getNextByte();
|
|
1758 int toCol = bk.getNextByte() & 0xff;
|
|
1759 if (toRow >= row) {
|
|
1760 int repeat = bk.getNextByte();
|
|
1761
|
|
1762 // a little intelligence here I hope
|
|
1763 if (row == 1 && col == 2 && toRow == screen52.getRows()
|
|
1764 && toCol == screen52.getColumns())
|
|
1765
|
|
1766 screen52.clearScreen();
|
|
1767 else {
|
|
1768 if (repeat != 0) {
|
|
1769 //LDC - 13/02/2003 - convert it to unicode
|
|
1770 repeat = codePage.ebcdic2uni(repeat);
|
|
1771 //repeat = getASCIIChar(repeat);
|
|
1772 }
|
|
1773
|
|
1774 int times = ((toRow * screen52.getColumns()) + toCol)
|
|
1775 - ((row * screen52.getColumns()) + col);
|
|
1776 while (times-- >= 0) {
|
|
1777 screen52.setChar(repeat);
|
|
1778 }
|
|
1779
|
|
1780 }
|
|
1781 } else {
|
|
1782 sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x23,
|
|
1783 " RA invalid");
|
|
1784 error = true;
|
|
1785 }
|
|
1786 break;
|
|
1787
|
|
1788 case 03: // EA - Erase to address
|
|
1789 log.debug("EA - Erase to address");
|
|
1790 int EArow = screen52.getCurrentRow();
|
|
1791 int EAcol = screen52.getCurrentCol();
|
|
1792
|
|
1793 int toEARow = bk.getNextByte();
|
|
1794 int toEACol = bk.getNextByte() & 0xff;
|
|
1795 int EALength = bk.getNextByte() & 0xff;
|
|
1796 while (--EALength > 0) {
|
|
1797
|
|
1798 bk.getNextByte();
|
|
1799
|
|
1800 }
|
|
1801 char EAAttr = (char) 0;
|
|
1802
|
|
1803 // a little intelligence here I hope
|
|
1804 if (EArow == 1 && EAcol == 2
|
|
1805 && toEARow == screen52.getRows()
|
|
1806 && toEACol == screen52.getColumns())
|
|
1807
|
|
1808 screen52.clearScreen();
|
|
1809 else {
|
|
1810 int times = ((toEARow * screen52.getColumns()) + toEACol)
|
|
1811 - ((EArow * screen52.getColumns()) + EAcol);
|
|
1812 while (times-- >= 0) {
|
|
1813 screen52.setChar(EAAttr);
|
|
1814 }
|
|
1815 }
|
|
1816 break;
|
|
1817 case 04: // Command - Escape
|
|
1818 log.debug("Command - Escape");
|
|
1819 done = true;
|
|
1820 break;
|
|
1821
|
|
1822 case 16: // TD - Transparent Data
|
|
1823 log.debug("TD - Transparent Data");
|
|
1824 int j = (bk.getNextByte() & 0xff) << 8 | bk.getNextByte()
|
|
1825 & 0xff; // length
|
|
1826 break;
|
|
1827
|
|
1828 case 17: // SBA - set buffer address order (row column)
|
|
1829 log.debug("SBA - set buffer address order (row column)");
|
|
1830 int saRow = bk.getNextByte();
|
|
1831 int saCol = bk.getNextByte() & 0xff;
|
|
1832 // make sure it is in bounds
|
|
1833 if (saRow >= 0 && saRow <= screen52.getRows() && saCol >= 0
|
|
1834 && saCol <= screen52.getColumns()) {
|
|
1835 screen52.setCursor(saRow, saCol); // now set screen
|
|
1836 // position for output
|
|
1837
|
|
1838 } else {
|
|
1839
|
|
1840 sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x22,
|
|
1841 "invalid row/col order" + " saRow = " + saRow
|
|
1842 + " saRows = " + screen52.getRows()
|
|
1843 + " saCol = " + saCol);
|
|
1844
|
|
1845 error = true;
|
|
1846
|
|
1847 }
|
|
1848 break;
|
|
1849
|
|
1850 case 18: // WEA - Extended Attribute
|
|
1851 log.debug("WEA - Extended Attribute");
|
|
1852 bk.getNextByte();
|
|
1853 bk.getNextByte();
|
|
1854 break;
|
|
1855
|
|
1856 case 19: // IC - Insert Cursor
|
|
1857 log.debug("IC - Insert Cursor");
|
|
1858 int icX = bk.getNextByte();
|
|
1859 int icY = bk.getNextByte() & 0xff;
|
|
1860 if (icX >= 0 && icX <= saRows && icY >= 0 && icY <= saCols) {
|
|
1861
|
|
1862 log.debug(" IC " + icX + " " + icY);
|
|
1863 screen52.setPendingInsert(true, icX, icY);
|
|
1864 } else {
|
|
1865 sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x22,
|
|
1866 " IC/IM position invalid ");
|
|
1867 error = true;
|
|
1868 }
|
|
1869
|
|
1870 break;
|
|
1871
|
|
1872 case 20: // MC - Move Cursor
|
|
1873 log.debug("MC - Move Cursor");
|
|
1874 int imcX = bk.getNextByte();
|
|
1875 int imcY = bk.getNextByte() & 0xff;
|
|
1876 if (imcX >= 0 && imcX <= saRows && imcY >= 0
|
|
1877 && imcY <= saCols) {
|
|
1878
|
|
1879 log.debug(" MC " + imcX + " " + imcY);
|
|
1880 screen52.setPendingInsert(false, imcX, imcY);
|
|
1881 } else {
|
|
1882 sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x22,
|
|
1883 " IC/IM position invalid ");
|
|
1884 error = true;
|
|
1885 }
|
|
1886
|
|
1887 break;
|
|
1888
|
|
1889 case 21: // WTDSF - Write To Display Structured Field order
|
8
|
1890 log.debug("WTDSF - Write To Display Structured Field order");
|
3
|
1891 byte[] seg = bk.getSegment();
|
|
1892 error = sfParser.parseWriteToDisplayStructuredField(seg);
|
|
1893 break;
|
|
1894
|
|
1895 case 29: // SF - Start of Field
|
|
1896 log.debug("SF - Start of Field");
|
|
1897 int fcw1 = 0;
|
|
1898 int fcw2 = 0;
|
|
1899 int ffw1 = 0;
|
|
1900 int ffw0 = bk.getNextByte() & 0xff; // FFW
|
|
1901
|
|
1902 if ((ffw0 & 0x40) == 0x40) {
|
|
1903 ffw1 = bk.getNextByte() & 0xff; // FFW 1
|
|
1904
|
|
1905 fcw1 = bk.getNextByte() & 0xff; // check for field
|
|
1906 // control word
|
|
1907
|
|
1908 // check if the first fcw1 is an 0x81 if it is then get
|
8
|
1909 // the next pair for checking
|
3
|
1910 if (fcw1 == 0x81) {
|
|
1911 bk.getNextByte();
|
|
1912 fcw1 = bk.getNextByte() & 0xff; // check for field
|
|
1913 // control word
|
|
1914 }
|
|
1915
|
|
1916 if (!isAttribute(fcw1)) {
|
|
1917
|
|
1918 fcw2 = bk.getNextByte() & 0xff; // FCW 2
|
|
1919 attr = bk.getNextByte() & 0xff; // attribute field
|
|
1920
|
|
1921 while (!isAttribute(attr)) {
|
|
1922 log.info(Integer.toHexString(fcw1) + " "
|
|
1923 + Integer.toHexString(fcw2)
|
|
1924 + " ");
|
|
1925 log.info(Integer.toHexString(attr)
|
|
1926 + " "
|
|
1927 + Integer.toHexString(bk
|
|
1928 .getNextByte() & 0xff));
|
8
|
1929 attr = bk.getNextByte() & 0xff; // attribute field
|
3
|
1930 }
|
|
1931 } else {
|
|
1932 attr = fcw1; // attribute of field
|
|
1933 fcw1 = 0;
|
|
1934 }
|
|
1935 } else {
|
|
1936 attr = ffw0;
|
|
1937 }
|
|
1938
|
|
1939 int fLength = (bk.getNextByte() & 0xff) << 8
|
|
1940 | bk.getNextByte() & 0xff;
|
|
1941 screen52.addField(attr, fLength, ffw0, ffw1, fcw1, fcw2);
|
|
1942
|
|
1943 break;
|
|
1944 // WVL - LDC : 05/08/2005 : TFX.006253 - Support STRPCCMD
|
|
1945 case -128: //STRPCCMD
|
|
1946 // if (screen52.getCurrentPos() == 82) {
|
|
1947 log.debug("STRPCCMD got a -128 command at " + screen52.getCurrentPos());
|
|
1948 StringBuffer value = new StringBuffer();
|
|
1949 int b;
|
|
1950 char c;
|
|
1951 int[] pco = new int[9];
|
|
1952 int[] pcoOk = {0xfc, 0xd7, 0xc3, 0xd6, 0x40, 0x83, 0x80, 0xa1, 0x80};
|
|
1953
|
|
1954 for (int i = 0; i < 9; i++)
|
|
1955 {
|
|
1956 b = bk.getNextByte();
|
|
1957 pco[i] = ((b & 0xff));
|
|
1958 c = codePage.ebcdic2uni(b);
|
|
1959 value.append(c);
|
|
1960 }
|
|
1961
|
|
1962 // Check "PCO-String"
|
|
1963 if (Arrays.equals(pco, pcoOk)) {
|
|
1964 strpccmd = true;
|
|
1965 }
|
|
1966 // we return in the stream to have all chars
|
|
1967 // arrive at the screen for later processing
|
|
1968 for (int i = 0; i < 9; i++)
|
|
1969 bk.setPrevByte();
|
|
1970 //}
|
|
1971 // no break: so every chars arrives
|
|
1972 // on the screen for later parsing
|
|
1973 //break;
|
|
1974
|
|
1975 default: // all others must be output to screen
|
|
1976 log.debug("all others must be output to screen");
|
|
1977 byte byte0 = bk.getByteOffset(-1);
|
|
1978 if (isAttribute(byte0)) {
|
|
1979 screen52.setAttr(byte0);
|
|
1980 } else {
|
|
1981 if (!screen52.isStatusErrorCode()) {
|
|
1982 if (!isDataEBCDIC(byte0)) {
|
|
1983 // if (byte0 == 255) {
|
|
1984 // sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x42,
|
|
1985 // " Attempt to send FF to screen");
|
|
1986 // }
|
|
1987 // else
|
|
1988
|
|
1989 screen52.setChar(byte0);
|
|
1990 } else
|
|
1991 //LDC - 13/02/2003 - Convert it to unicode
|
|
1992 //screen52.setChar(getASCIIChar(byte0));
|
|
1993 screen52.setChar(codePage.ebcdic2uni(byte0));
|
|
1994 } else {
|
|
1995 if (byte0 == 0)
|
|
1996 screen52.setChar(byte0);
|
|
1997 else
|
|
1998 //LDC - 13/02/2003 - Convert it to unicode
|
|
1999 //screen52.setChar(getASCIIChar(byte0));
|
|
2000 screen52.setChar(codePage.ebcdic2uni(byte0));
|
|
2001 }
|
|
2002 }
|
|
2003
|
|
2004 break;
|
|
2005 }
|
|
2006
|
|
2007 if (error)
|
|
2008 done = true;
|
|
2009 }
|
|
2010 }
|
|
2011
|
|
2012 catch (Exception e) {
|
|
2013 log.warn("write to display " + e.getMessage());
|
|
2014 e.printStackTrace();
|
|
2015 }
|
|
2016 ;
|
|
2017
|
|
2018 processCC1(control1);
|
|
2019
|
|
2020 return error;
|
|
2021
|
|
2022 }
|
|
2023
|
|
2024 private boolean processSOH() throws Exception {
|
|
2025
|
|
2026 int l = bk.getNextByte(); // length
|
|
2027 log.debug(" byte 0 " + l);
|
|
2028
|
|
2029 if (l > 0 && l <= 7) {
|
|
2030 bk.getNextByte(); // flag byte 2
|
|
2031 bk.getNextByte(); // reserved
|
|
2032 bk.getNextByte(); // resequence fields
|
|
2033
|
|
2034 screen52.clearTable();
|
|
2035
|
|
2036 // well that is the first time I have seen this. This fixes a
|
8
|
2037 // problem with S/36 command line. Finally got it.
|
|
2038 if (l <= 3) return false;
|
3
|
2039
|
|
2040 screen52.setErrorLine(bk.getNextByte()); // error row
|
|
2041
|
|
2042 int byte1 = 0;
|
|
2043 if (l >= 5) {
|
|
2044 byte1 = bk.getNextByte();
|
|
2045 dataIncluded[23] = (byte1 & 0x80) == 0x80;
|
|
2046 dataIncluded[22] = (byte1 & 0x40) == 0x40;
|
|
2047 dataIncluded[21] = (byte1 & 0x20) == 0x20;
|
|
2048 dataIncluded[20] = (byte1 & 0x10) == 0x10;
|
|
2049 dataIncluded[19] = (byte1 & 0x8) == 0x8;
|
|
2050 dataIncluded[18] = (byte1 & 0x4) == 0x4;
|
|
2051 dataIncluded[17] = (byte1 & 0x2) == 0x2;
|
|
2052 dataIncluded[16] = (byte1 & 0x1) == 0x1;
|
|
2053 }
|
|
2054
|
|
2055 if (l >= 6) {
|
|
2056 byte1 = bk.getNextByte();
|
|
2057 dataIncluded[15] = (byte1 & 0x80) == 0x80;
|
|
2058 dataIncluded[14] = (byte1 & 0x40) == 0x40;
|
|
2059 dataIncluded[13] = (byte1 & 0x20) == 0x20;
|
|
2060 dataIncluded[12] = (byte1 & 0x10) == 0x10;
|
|
2061 dataIncluded[11] = (byte1 & 0x8) == 0x8;
|
|
2062 dataIncluded[10] = (byte1 & 0x4) == 0x4;
|
|
2063 dataIncluded[9] = (byte1 & 0x2) == 0x2;
|
|
2064 dataIncluded[8] = (byte1 & 0x1) == 0x1;
|
|
2065 }
|
|
2066
|
|
2067 if (l >= 7) {
|
|
2068 byte1 = bk.getNextByte();
|
|
2069 dataIncluded[7] = (byte1 & 0x80) == 0x80;
|
|
2070 dataIncluded[6] = (byte1 & 0x40) == 0x40;
|
|
2071 dataIncluded[5] = (byte1 & 0x20) == 0x20;
|
|
2072 dataIncluded[4] = (byte1 & 0x10) == 0x10;
|
|
2073 dataIncluded[3] = (byte1 & 0x8) == 0x8;
|
|
2074 dataIncluded[2] = (byte1 & 0x4) == 0x4;
|
|
2075 dataIncluded[1] = (byte1 & 0x2) == 0x2;
|
|
2076 dataIncluded[0] = (byte1 & 0x1) == 0x1;
|
|
2077 }
|
|
2078 return false;
|
|
2079 } else {
|
|
2080 sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x2B,
|
|
2081 "invalid SOH length");
|
|
2082 return true;
|
|
2083 }
|
|
2084
|
|
2085 }
|
|
2086
|
|
2087 private void processCC0(byte byte0) {
|
|
2088 log.debug(" Control byte0 " + Integer.toBinaryString(byte0 & 0xff));
|
|
2089 boolean lockKeyboard = true;
|
|
2090 boolean resetMDT = false;
|
|
2091 boolean resetMDTAll = false;
|
|
2092 boolean nullMDT = false;
|
|
2093 boolean nullAll = false;
|
|
2094
|
|
2095 // Bits 3 to 6 are reserved and should be set to '0000'
|
|
2096 // 0xE0 = '11100000' - only the first 3 bits are tested
|
|
2097 if ((byte0 & 0xE0) == 0x00) {
|
|
2098 lockKeyboard = false;
|
|
2099 }
|
|
2100
|
|
2101 // '00100000' = 0x20 /32 -- just lock keyboard
|
|
2102 // '01000000' = 0x40 /64
|
|
2103 // '01100000' = 0x60 /96
|
|
2104 // '10000000' = 0x80 /128
|
|
2105 // '10100000' = 0xA0 /160
|
|
2106 // '11000000' = 0xC0 /192
|
|
2107 // '11100000' = 0xE0 /224
|
|
2108
|
|
2109 switch (byte0 & 0xE0) {
|
|
2110
|
|
2111 case 0x40:
|
|
2112 resetMDT = true;
|
|
2113 break;
|
|
2114 case 0x60:
|
|
2115 resetMDTAll = true;
|
|
2116 break;
|
|
2117 case 0x80:
|
|
2118 nullMDT = true;
|
|
2119 break;
|
|
2120 case 0xA0:
|
|
2121 resetMDT = true;
|
|
2122 nullAll = true;
|
|
2123 break;
|
|
2124 case 0xC0:
|
|
2125 resetMDT = true;
|
|
2126 nullMDT = true;
|
|
2127 break;
|
|
2128
|
|
2129 case 0xE0:
|
|
2130 resetMDTAll = true;
|
|
2131 nullAll = true;
|
|
2132 break;
|
|
2133
|
|
2134 }
|
|
2135
|
|
2136 if (lockKeyboard) {
|
|
2137 screen52.getOIA().setKeyBoardLocked(true);
|
|
2138 pendingUnlock = false;
|
|
2139 } else
|
|
2140 pendingUnlock = false;
|
|
2141
|
|
2142 if (resetMDT || resetMDTAll || nullMDT || nullAll) {
|
|
2143 ScreenField sf;
|
|
2144
|
|
2145 int f = screen52.getScreenFields().getSize();
|
|
2146 for (int x = 0; x < f; x++) {
|
|
2147 sf = screen52.getScreenFields().getField(x);
|
|
2148
|
|
2149 if (!sf.isBypassField()) {
|
|
2150 if ((nullMDT && sf.mdt) || nullAll) {
|
|
2151 sf.setFieldChar((char) 0x0);
|
|
2152 screen52.drawField(sf);
|
|
2153 }
|
|
2154 }
|
|
2155 if (resetMDTAll || (resetMDT && !sf.isBypassField()))
|
|
2156 sf.resetMDT();
|
|
2157
|
|
2158 }
|
|
2159 sf = null;
|
|
2160 }
|
|
2161
|
|
2162 }
|
|
2163
|
|
2164 private void processCC1(byte byte1) {
|
|
2165 log.debug(" Control byte1 " + Integer.toBinaryString(byte1 & 0xff));
|
|
2166
|
|
2167 if ((byte1 & 0x04) == 0x04) {
|
|
2168 controller.signalBell();
|
|
2169 }
|
|
2170 if ((byte1 & 0x02) == 0x02) {
|
|
2171 screen52.getOIA().setMessageLightOff();
|
|
2172 }
|
|
2173 if ((byte1 & 0x01) == 0x01) {
|
|
2174 screen52.getOIA().setMessageLightOn();
|
|
2175 }
|
|
2176
|
|
2177 if ((byte1 & 0x01) == 0x01 && (byte1 & 0x02) == 0x02) {
|
|
2178 screen52.getOIA().setMessageLightOn();
|
|
2179 }
|
|
2180
|
|
2181 // reset blinking cursor seems to control whether to set or not set the
|
|
2182 // the cursor position. No documentation for this just testing and
|
|
2183 // looking at the bit settings of this field. This was a pain in the
|
|
2184 // ass!
|
|
2185 //
|
|
2186 // if it is off '0' then keep existing cursor positioning information
|
|
2187 // if it is on '1' then reset the cursor positioning information
|
|
2188 // *** Note *** unless we receive bit 4 on at the same time
|
|
2189 // this seems to work so far
|
|
2190 if ((byte1 & 0x20) == 0x20 && (byte1 & 0x08) == 0x00) {
|
|
2191 screen52.setPendingInsert(false);
|
|
2192 log.debug(" WTD position no move");
|
|
2193 } else {
|
|
2194
|
|
2195 screen52.setPendingInsert(true);
|
|
2196 log.debug(" WTD position move to home" + screen52.homePos + " row "
|
|
2197 + screen52.getRow(screen52.homePos) + " col "
|
|
2198 + screen52.getCol(screen52.homePos));
|
|
2199
|
|
2200 }
|
|
2201 // in enhanced mode we sometimes only receive bit 6 turned on which
|
|
2202 // is reset blinking cursor
|
|
2203 if ((byte1 & 0x20) == 0x20 && enhanced) {
|
|
2204 cursorOn = true;
|
|
2205 }
|
|
2206
|
|
2207 if (!screen52.isStatusErrorCode() && (byte1 & 0x08) == 0x08) {
|
|
2208
|
|
2209 // screen52.setStatus(screen52.STATUS_SYSTEM,screen52.STATUS_VALUE_OFF,null);
|
|
2210 cursorOn = true;
|
|
2211 }
|
|
2212
|
|
2213 if ((byte1 & 0x20) == 0x20 && (byte1 & 0x08) == 0x00) {
|
|
2214 screen52.setPendingInsert(false, 1, 1);
|
|
2215 }
|
|
2216
|
|
2217 }
|
|
2218
|
|
2219 private boolean isAttribute(int byte0) {
|
|
2220 int byte1 = byte0 & 0xff;
|
|
2221 return (byte1 & 0xe0) == 0x20;
|
|
2222 }
|
|
2223
|
|
2224 //LDC - 12/02/2003 - Function name changed from isData to isDataEBCDIC
|
|
2225 private boolean isDataEBCDIC(int byte0) {
|
|
2226 int byte1 = byte0 & 0xff;
|
|
2227 // here it should always be less than 255
|
|
2228 if (byte1 >= 64 && byte1 < 255)
|
|
2229
|
|
2230 return true;
|
|
2231 else
|
|
2232 return false;
|
|
2233
|
|
2234 }
|
|
2235
|
|
2236 //LDC - 12/02/2003 - Test if the unicode character is a displayable
|
|
2237 // character.
|
|
2238 // The first 32 characters are non displayable characters
|
|
2239 // This is normally the inverse of isDataEBCDIC (That's why there is a
|
|
2240 // check on 255 -> 0xFFFF
|
|
2241 private boolean isDataUnicode(int byte0) {
|
|
2242 return (((byte0 < 0) || (byte0 >= 32)) && (byte0 != 0xFFFF));
|
|
2243 }
|
|
2244
|
|
2245 private void writeStructuredField() {
|
|
2246
|
|
2247 boolean done = false;
|
|
2248 try {
|
|
2249 int length = ((bk.getNextByte() & 0xff) << 8 | (bk.getNextByte() & 0xff));
|
|
2250 while (bk.hasNext() && !done) {
|
|
2251 switch (bk.getNextByte()) {
|
|
2252
|
|
2253 case -39: // SOH - Start of Header Order
|
|
2254
|
|
2255 switch (bk.getNextByte()) {
|
|
2256 case 112: // 5250 Query
|
|
2257 bk.getNextByte(); // get null required field
|
|
2258 sendQueryResponse();
|
|
2259 break;
|
|
2260 default:
|
|
2261 log.debug("invalid structured field sub command "
|
|
2262 + bk.getByteOffset(-1));
|
|
2263 break;
|
|
2264 }
|
|
2265 break;
|
|
2266 default:
|
|
2267 log.debug("invalid structured field command "
|
|
2268 + bk.getByteOffset(-1));
|
|
2269 break;
|
|
2270 }
|
|
2271 }
|
|
2272 } catch (Exception e) {
|
|
2273 }
|
|
2274 ;
|
|
2275
|
|
2276 }
|
|
2277
|
|
2278 private final void writeErrorCode() throws Exception {
|
|
2279 screen52.setCursor(screen52.getErrorLine(), 1); // Skip the control byte
|
|
2280 screen52.setStatus(Screen5250.STATUS_ERROR_CODE,
|
|
2281 Screen5250.STATUS_VALUE_ON, null);
|
|
2282 screen52.saveErrorLine();
|
|
2283 cursorOn = true;
|
|
2284
|
|
2285 }
|
|
2286
|
|
2287 private final void writeErrorCodeToWindow() throws Exception {
|
|
2288 int fromCol = bk.getNextByte() & 0xff; // from column
|
|
2289 int toCol = bk.getNextByte() & 0xff; // to column
|
|
2290 screen52.setCursor(screen52.getErrorLine(), fromCol); // Skip the control
|
|
2291 // byte
|
|
2292 screen52.setStatus(Screen5250.STATUS_ERROR_CODE,
|
|
2293 Screen5250.STATUS_VALUE_ON, null);
|
|
2294 screen52.saveErrorLine();
|
|
2295 cursorOn = true;
|
|
2296
|
|
2297 }
|
|
2298
|
|
2299 /**
|
|
2300 * Method sendQueryResponse
|
|
2301 *
|
|
2302 * The query command is used to obtain information about the capabilities of
|
|
2303 * the 5250 display.
|
|
2304 *
|
|
2305 * The Query command must follow an Escape (0x04) and Write Structured Field
|
|
2306 * command (0xF3).
|
|
2307 *
|
|
2308 * This section is modeled after the rfc1205 - 5250 Telnet Interface section
|
|
2309 * 5.3
|
|
2310 *
|
|
2311 * @throws IOException
|
|
2312 */
|
|
2313 private final void sendQueryResponse() throws IOException {
|
|
2314
|
|
2315 log.info("sending query response");
|
|
2316 byte abyte0[] = new byte[64];
|
|
2317 abyte0[0] = 0; // Cursor Row/column (set to zero)
|
|
2318 abyte0[1] = 0; // ""
|
|
2319 abyte0[2] = -120; // X'88' inbound write structure Field aid
|
|
2320 if (enhanced == true) {
|
|
2321 abyte0[3] = 0; // 0x003D (61) length of query response
|
|
2322 abyte0[4] = 64; // "" see note below ?????????
|
|
2323 } else {
|
|
2324 abyte0[3] = 0; // 0x003A (58) length of query response
|
|
2325 abyte0[4] = 58; // ""
|
|
2326 // the length between 58 and 64 seems to cause
|
|
2327 // different formatting codes to be sent from
|
|
2328 // the host ???????????????? why ???????
|
|
2329 // Well the why can be found in the manual if
|
|
2330 // read a little more ;-)
|
|
2331 }
|
|
2332 abyte0[5] = -39; // command class 0xD9
|
|
2333 abyte0[6] = 112; // Command type query 0x70
|
|
2334 abyte0[7] = -128; // 0x80 Flag byte
|
|
2335 abyte0[8] = 6; // Controller Hardware Class
|
|
2336 abyte0[9] = 0; // 0x0600 - Other WSF or another 5250 Emulator
|
|
2337 abyte0[10] = 1; // Controller Code Level
|
|
2338 abyte0[11] = 1; // Version 1 Rel 1.0
|
|
2339 abyte0[12] = 0; // ""
|
|
2340
|
|
2341 abyte0[13] = 0; // 13 - 28 are reserved so set to 0x00
|
|
2342 abyte0[14] = 0; // ""
|
|
2343 abyte0[15] = 0; // ""
|
|
2344 abyte0[16] = 0; // ""
|
|
2345 abyte0[17] = 0; // ""
|
|
2346 abyte0[18] = 0; // ""
|
|
2347 abyte0[19] = 0; // ""
|
|
2348 abyte0[20] = 0; // ""
|
|
2349 abyte0[21] = 0; // ""
|
|
2350 abyte0[22] = 0; // ""
|
|
2351 abyte0[23] = 0; // ""
|
|
2352 abyte0[24] = 0; // ""
|
|
2353 abyte0[25] = 0; // ""
|
|
2354 abyte0[26] = 0; // ""
|
|
2355 abyte0[27] = 0; // ""
|
|
2356 abyte0[28] = 0; // ""
|
|
2357 abyte0[29] = 1; // Device type - 0x01 5250 Emulator
|
|
2358 abyte0[30] = codePage.uni2ebcdic('5'); // Device type character
|
|
2359 abyte0[31] = codePage.uni2ebcdic('2'); // ""
|
|
2360 abyte0[32] = codePage.uni2ebcdic('5'); // ""
|
|
2361 abyte0[33] = codePage.uni2ebcdic('1'); // ""
|
|
2362 abyte0[34] = codePage.uni2ebcdic('0'); // ""
|
|
2363 abyte0[35] = codePage.uni2ebcdic('1'); // ""
|
|
2364 abyte0[36] = codePage.uni2ebcdic('1'); // ""
|
|
2365
|
|
2366 abyte0[37] = 2; // Keyboard Id - 0x02 Standard Keyboard
|
|
2367 abyte0[38] = 0; // extended keyboard id
|
|
2368 abyte0[39] = 0; // reserved
|
|
2369
|
|
2370 abyte0[40] = 0; // 40 - 43 Display Serial Number
|
|
2371 abyte0[41] = 36; //
|
|
2372 abyte0[42] = 36; //
|
|
2373 abyte0[43] = 0; //
|
|
2374
|
|
2375 abyte0[44] = 1; // Maximum number of display fields - 256
|
|
2376 abyte0[45] = 0; // 0x0100
|
|
2377 abyte0[46] = 0; // 46 -48 Reserved set to 0x00
|
|
2378 abyte0[47] = 0;
|
|
2379 abyte0[48] = 0;
|
|
2380 abyte0[49] = 1; // 49 - 53 Controller Display Capability
|
|
2381 abyte0[50] = 17; // see rfc - tired of typing :-)
|
|
2382 abyte0[51] = 0; // ""
|
|
2383 abyte0[52] = 0; // ""
|
|
2384
|
|
2385 // 53
|
|
2386 // Bit 0-2: B'000' - no graphics capability
|
|
2387 // B'001' - 5292-2 style graphics
|
|
2388 // Bit 3-7: B '00000' = reserved (it seems for Client access)
|
|
2389
|
|
2390 if (enhanced == true) {
|
|
2391 // abyte0[53] = 0x5E; // 0x5E turns on ehnhanced mode
|
|
2392 // abyte0[53] = 0x27; // 0x5E turns on ehnhanced mode
|
|
2393 abyte0[53] = 0x7; // 0x5E turns on ehnhanced mode
|
|
2394 log.info("enhanced options");
|
|
2395 } else
|
|
2396 abyte0[53] = 0x0; // 0x0 is normal emulation
|
|
2397
|
|
2398 abyte0[54] = 24; // 54 - 60 Reserved set to 0x00
|
|
2399 // 54 - I found out is used for enhanced user
|
|
2400 // interface level 3. Bit 4 allows headers
|
|
2401 // and footers for windows
|
|
2402 abyte0[54] = 8; // 54 - 60 Reserved set to 0x00
|
|
2403 // 54 - I found out is used for enhanced user
|
|
2404 // interface level 3. Bit 4 allows headers
|
|
2405 // and footers for windows
|
|
2406 abyte0[55] = 0;
|
|
2407 abyte0[56] = 0;
|
|
2408 abyte0[57] = 0;
|
|
2409 abyte0[58] = 0;
|
|
2410 abyte0[59] = 0;
|
|
2411 abyte0[60] = 0;
|
|
2412 abyte0[61] = 0; // gridlines are not supported
|
|
2413 abyte0[62] = 0; // gridlines are not supported
|
|
2414 abyte0[63] = 0;
|
|
2415 writeGDS(0, 0, abyte0); // now tell them about us
|
|
2416 abyte0 = null;
|
|
2417
|
|
2418 }
|
|
2419
|
|
2420 protected final boolean negotiate(byte abyte0[]) throws IOException {
|
|
2421 int i = 0;
|
|
2422
|
|
2423
|
|
2424 // from server negotiations
|
|
2425 if(abyte0[i] == IAC) { // -1
|
|
2426
|
|
2427 while(i < abyte0.length && abyte0[i++] == -1)
|
|
2428 // while(i < abyte0.length && (abyte0[i] == -1 || abyte0[i++] == 0x20))
|
|
2429 switch(abyte0[i++]) {
|
|
2430
|
|
2431 // we will not worry about what it WONT do
|
|
2432 case WONT: // -4
|
|
2433 default:
|
|
2434 break;
|
|
2435
|
|
2436 case DO: //-3
|
|
2437
|
|
2438 // not sure why but since moving to V5R2 we are receiving a
|
|
2439 // DO with no option when connecting a second session with
|
|
2440 // device name. Can not find the cause at all. If anybody
|
|
2441 // is interested please debug this until then this works.
|
|
2442 if (i < abyte0.length) {
|
|
2443 switch(abyte0[i]) {
|
|
2444 case TERMINAL_TYPE: // 24
|
|
2445 baosp.write(IAC);
|
|
2446 baosp.write(WILL);
|
|
2447 baosp.write(TERMINAL_TYPE);
|
|
2448 writeByte(baosp.toByteArray());
|
|
2449 baosp.reset();
|
|
2450
|
|
2451 break;
|
|
2452
|
|
2453 case OPT_END_OF_RECORD: // 25
|
|
2454
|
|
2455 baosp.write(IAC);
|
|
2456 baosp.write(WILL);
|
|
2457 baosp.write(OPT_END_OF_RECORD);
|
|
2458 writeByte(baosp.toByteArray());
|
|
2459 baosp.reset();
|
|
2460 break;
|
|
2461
|
|
2462 case TRANSMIT_BINARY: // 0
|
|
2463
|
|
2464 baosp.write(IAC);
|
|
2465 baosp.write(WILL);
|
|
2466 baosp.write(TRANSMIT_BINARY);
|
|
2467 writeByte(baosp.toByteArray());
|
|
2468 baosp.reset();
|
|
2469
|
|
2470 break;
|
|
2471
|
|
2472 case TIMING_MARK: // 6 rfc860
|
|
2473 // System.out.println("Timing Mark Received and notifying " +
|
|
2474 // "the server that we will not do it");
|
|
2475 baosp.write(IAC);
|
|
2476 baosp.write(WONT);
|
|
2477 baosp.write(TIMING_MARK);
|
|
2478 writeByte(baosp.toByteArray());
|
|
2479 baosp.reset();
|
|
2480
|
|
2481 break;
|
|
2482
|
|
2483 case NEW_ENVIRONMENT: // 39 rfc1572, rfc4777
|
|
2484 // allways send new environment vars ...
|
|
2485 baosp.write(IAC);
|
|
2486 baosp.write(WILL);
|
|
2487 baosp.write(NEW_ENVIRONMENT);
|
|
2488 writeByte(baosp.toByteArray());
|
|
2489 baosp.reset();
|
|
2490 break;
|
|
2491
|
|
2492 default: // every thing else we will not do at this time
|
|
2493 baosp.write(IAC);
|
|
2494 baosp.write(WONT);
|
|
2495 baosp.write(abyte0[i]); // either
|
|
2496 writeByte(baosp.toByteArray());
|
|
2497 baosp.reset();
|
|
2498
|
|
2499 break;
|
|
2500 }
|
|
2501 }
|
|
2502
|
|
2503 i++;
|
|
2504 break;
|
|
2505
|
|
2506 case WILL:
|
|
2507
|
|
2508 switch(abyte0[i]) {
|
|
2509 case OPT_END_OF_RECORD: // 25
|
|
2510 baosp.write(IAC);
|
|
2511 baosp.write(DO);
|
|
2512 baosp.write(OPT_END_OF_RECORD);
|
|
2513 writeByte(baosp.toByteArray());
|
|
2514 baosp.reset();
|
|
2515
|
|
2516 break;
|
|
2517
|
|
2518 case TRANSMIT_BINARY: // '\0'
|
|
2519 baosp.write(IAC);
|
|
2520 baosp.write(DO);
|
|
2521 baosp.write(TRANSMIT_BINARY);
|
|
2522 writeByte(baosp.toByteArray());
|
|
2523 baosp.reset();
|
|
2524
|
|
2525 break;
|
|
2526 }
|
|
2527 i++;
|
|
2528 break;
|
|
2529
|
|
2530 case SB: // -6
|
|
2531
|
|
2532 if(abyte0[i] == NEW_ENVIRONMENT && abyte0[i + 1] == 1) {
|
|
2533 negNewEnvironment();
|
|
2534
|
|
2535 while (++i < abyte0.length && abyte0[i + 1] != IAC);
|
|
2536 }
|
|
2537
|
|
2538 if(abyte0[i] == TERMINAL_TYPE && abyte0[i + 1] == 1) {
|
|
2539 baosp.write(IAC);
|
|
2540 baosp.write(SB);
|
|
2541 baosp.write(TERMINAL_TYPE);
|
|
2542 baosp.write(QUAL_IS);
|
|
2543 if(!support132)
|
|
2544 baosp.write("IBM-3179-2".getBytes());
|
|
2545 else
|
|
2546 baosp.write("IBM-3477-FC".getBytes());
|
|
2547 baosp.write(IAC);
|
|
2548 baosp.write(SE);
|
|
2549 writeByte(baosp.toByteArray());
|
|
2550 baosp.reset();
|
|
2551
|
|
2552 i++;
|
|
2553 }
|
|
2554 i++;
|
|
2555 break;
|
|
2556 }
|
|
2557 return true;
|
|
2558 }
|
|
2559 else {
|
|
2560 return false;
|
|
2561 }
|
|
2562 }
|
|
2563
|
|
2564 /**
|
|
2565 * Negotiate new environment string for device name
|
|
2566 *
|
|
2567 * @throws IOException
|
|
2568 */
|
|
2569 private void negNewEnvironment() throws IOException {
|
|
2570
|
|
2571 baosp.write(IAC);
|
|
2572 baosp.write(SB);
|
|
2573 baosp.write(NEW_ENVIRONMENT);
|
|
2574 baosp.write(IS);
|
|
2575
|
|
2576 // http://tools.ietf.org/html/rfc4777
|
|
2577
|
|
2578 if (kbdTypesCodePage != null) {
|
|
2579 baosp.write(USERVAR);
|
|
2580 baosp.write("KBDTYPE".getBytes());
|
|
2581 baosp.write(VALUE);
|
|
2582 baosp.write(kbdTypesCodePage.kbdType.getBytes());
|
|
2583
|
|
2584 baosp.write(USERVAR);
|
|
2585 baosp.write("CODEPAGE".getBytes());
|
|
2586 baosp.write(VALUE);
|
|
2587 baosp.write(kbdTypesCodePage.codepage.getBytes());
|
|
2588
|
|
2589 baosp.write(USERVAR);
|
|
2590 baosp.write("CHARSET".getBytes());
|
|
2591 baosp.write(VALUE);
|
|
2592 baosp.write(kbdTypesCodePage.charset.getBytes());
|
|
2593 }
|
|
2594
|
|
2595 if (devName != null) {
|
|
2596 baosp.write(USERVAR);
|
|
2597
|
|
2598 baosp.write("DEVNAME".getBytes());
|
|
2599
|
|
2600 baosp.write(VALUE);
|
|
2601
|
|
2602 baosp.write(negDeviceName().getBytes());
|
|
2603 }
|
|
2604
|
|
2605 if (user != null) {
|
|
2606
|
|
2607 baosp.write(VAR);
|
|
2608 baosp.write("USER".getBytes());
|
|
2609 baosp.write(VALUE);
|
|
2610 baosp.write(user.getBytes());
|
|
2611
|
|
2612 if (password != null) {
|
|
2613 baosp.write(USERVAR);
|
|
2614 baosp.write("IBMRSEED".getBytes());
|
|
2615 baosp.write(VALUE);
|
|
2616 baosp.write(NEGOTIATE_ESC);
|
|
2617 baosp.write(0x0);
|
|
2618 baosp.write(0x0);
|
|
2619 baosp.write(0x0);
|
|
2620 baosp.write(0x0);
|
|
2621 baosp.write(0x0);
|
|
2622 baosp.write(0x0);
|
|
2623 baosp.write(0x0);
|
|
2624 baosp.write(0x0);
|
|
2625 baosp.write(USERVAR);
|
|
2626 baosp.write("IBMSUBSPW".getBytes());
|
|
2627 baosp.write(VALUE);
|
|
2628 baosp.write(password.getBytes());
|
|
2629 }
|
|
2630
|
|
2631 if (library != null) {
|
|
2632 baosp.write(USERVAR);
|
|
2633 baosp.write("IBMCURLIB".getBytes());
|
|
2634 baosp.write(VALUE);
|
|
2635 baosp.write(library.getBytes());
|
|
2636 }
|
|
2637
|
|
2638 if (initialMenu != null) {
|
|
2639 baosp.write(USERVAR);
|
|
2640 baosp.write("IBMIMENU".getBytes());
|
|
2641 baosp.write(VALUE);
|
|
2642 baosp.write(initialMenu.getBytes());
|
|
2643 }
|
|
2644
|
|
2645 if (program != null) {
|
|
2646 baosp.write(USERVAR);
|
|
2647 baosp.write("IBMPROGRAM".getBytes());
|
|
2648 baosp.write(VALUE);
|
|
2649 baosp.write(program.getBytes());
|
|
2650 }
|
|
2651 }
|
|
2652 baosp.write(IAC);
|
|
2653 baosp.write(SE);
|
|
2654
|
|
2655 writeByte(baosp.toByteArray());
|
|
2656 baosp.reset();
|
|
2657
|
|
2658 }
|
|
2659
|
|
2660 /**
|
|
2661 * This will negotiate a device name with controller. if the sequence is
|
|
2662 * less than zero then it will send the device name as specified. On each
|
|
2663 * unsuccessful attempt a sequential number is appended until we find one or
|
|
2664 * the controller says no way.
|
|
2665 *
|
|
2666 * @return String
|
|
2667 */
|
|
2668 private String negDeviceName() {
|
|
2669
|
|
2670 if (devSeq++ == -1) {
|
|
2671 devNameUsed = devName;
|
|
2672 return devName;
|
|
2673 } else {
|
|
2674 StringBuffer sb = new StringBuffer(devName + devSeq);
|
|
2675 int ei = 1;
|
|
2676 while (sb.length() > 10) {
|
|
2677
|
|
2678 sb.setLength(0);
|
|
2679 sb.append(devName.substring(0, devName.length() - ei++));
|
|
2680 sb.append(devSeq);
|
|
2681
|
|
2682 }
|
|
2683 devNameUsed = sb.toString();
|
|
2684 return devNameUsed;
|
|
2685 }
|
|
2686 }
|
|
2687
|
|
2688 public final void setCodePage(String cp) {
|
|
2689 codePage = CharMappings.getCodePage(cp);
|
|
2690 cp = cp.toLowerCase();
|
|
2691 for (KbdTypesCodePages kbdtyp : KbdTypesCodePages.values()) {
|
|
2692 if (("cp"+kbdtyp.codepage).equals(cp) || kbdtyp.ccsid.equals(cp)) {
|
|
2693 kbdTypesCodePage = kbdtyp;
|
|
2694 break;
|
|
2695 }
|
|
2696 }
|
|
2697 if (log.isInfoEnabled()) {
|
|
2698 log.info("Choosed keyboard mapping " + kbdTypesCodePage.toString() + " for code page " + cp);
|
|
2699 }
|
|
2700 }
|
|
2701
|
|
2702 public final ICodePage getCodePage() {
|
|
2703 return codePage;
|
|
2704 }
|
|
2705
|
|
2706 /**
|
|
2707 * @see org.tn5250j.Session5250#signalBell()
|
|
2708 */
|
|
2709 public void signalBell() {
|
|
2710 controller.signalBell();
|
|
2711 }
|
|
2712
|
|
2713 }
|