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