comparison src/org/tn5250j/framework/tn5250/tnvt.java @ 112:77ac18bc1b2f

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