Mercurial > 510Connectbot
diff 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 |
line wrap: on
line diff
--- a/src/org/tn5250j/framework/tn5250/tnvt.java Wed Jun 18 13:00:19 2014 -0700 +++ b/src/org/tn5250j/framework/tn5250/tnvt.java Wed Jun 18 13:03:01 2014 -0700 @@ -98,14 +98,14 @@ public final class tnvt implements Runnable { private static final String TAG = "tnvt"; // negotiating commands - private static final byte IAC = (byte) -1; // 255 FF - private static final byte DONT = (byte) -2; //254 FE - private static final byte DO = (byte) -3; //253 FD - private static final byte WONT = (byte) -4; //252 FC - private static final byte WILL = (byte) -5; //251 FB - private static final byte SB = (byte) -6; //250 Sub Begin FA - private static final byte SE = (byte) -16; //240 Sub End F0 - private static final byte EOR = (byte) -17; //239 End of Record EF + private static final byte IAC = (byte) - 1; // 255 FF + private static final byte DONT = (byte) - 2; //254 FE + private static final byte DO = (byte) - 3; //253 FD + private static final byte WONT = (byte) - 4; //252 FC + private static final byte WILL = (byte) - 5; //251 FB + private static final byte SB = (byte) - 6; //250 Sub Begin FA + private static final byte SE = (byte) - 16; //240 Sub End F0 + private static final byte EOR = (byte) - 17; //239 End of Record EF private static final byte TERMINAL_TYPE = (byte) 24; // 18 private static final byte OPT_END_OF_RECORD = (byte) 25; // 19 private static final byte TRANSMIT_BINARY = (byte) 0; // 0 @@ -189,18 +189,22 @@ if (System.getProperties().containsKey("SESSION_CONNECT_USER")) { user = System.getProperties().getProperty("SESSION_CONNECT_USER"); + if (System.getProperties().containsKey("SESSION_CONNECT_PASSWORD")) password = System.getProperties().getProperty( - "SESSION_CONNECT_PASSWORD"); + "SESSION_CONNECT_PASSWORD"); + if (System.getProperties().containsKey("SESSION_CONNECT_LIBRARY")) library = System.getProperties().getProperty( - "SESSION_CONNECT_LIBRARY"); + "SESSION_CONNECT_LIBRARY"); + if (System.getProperties().containsKey("SESSION_CONNECT_MENU")) initialMenu = System.getProperties().getProperty( - "SESSION_CONNECT_MENU"); + "SESSION_CONNECT_MENU"); + if (System.getProperties().containsKey("SESSION_CONNECT_PROGRAM")) program = System.getProperties().getProperty( - "SESSION_CONNECT_PROGRAM"); + "SESSION_CONNECT_PROGRAM"); } baosp = new ByteArrayOutputStream(); @@ -209,12 +213,12 @@ public void showURL(String url) { if (url.indexOf("://") < 0) url = "http://" + url; + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); manager.startActivity(intent); } public String getHostName() { - return hostname; } @@ -241,20 +245,19 @@ public boolean isSslSocket() { if (this.connected && this.sock != null && this.sock instanceof SSLSocket) { return true; - } else { + } + else { return false; } } public final void setProxy(String proxyHost, String proxyPort) { - Properties systemProperties = System.getProperties(); systemProperties.put("socksProxySet", "true"); systemProperties.put("socksProxyHost", proxyHost); systemProperties.put("socksProxyPort", proxyPort); - System.setProperties(systemProperties); - Log.i(TAG," socks set "); + Log.i(TAG, " socks set "); } public final boolean connect(String hostname, int port, String encryption, String homeDirectory, vt320 buffer) { @@ -265,16 +268,17 @@ try { screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT, - ScreenOIA.OIA_LEVEL_INPUT_INHIBITED,"X - Connecting"); - } catch (Exception exc) { - Log.w(TAG,"setStatus(ON) " + exc.getMessage()); + ScreenOIA.OIA_LEVEL_INPUT_INHIBITED, "X - Connecting"); + } + catch (Exception exc) { + Log.w(TAG, "setStatus(ON) " + exc.getMessage()); } SocketConnector sc = new SocketConnector(); sock = sc.createSocket(hostname, port, encryption, homeDirectory, bridge, manager); if (sock == null) { - Log.w(TAG,"I did not get a socket"); + Log.w(TAG, "I did not get a socket"); disconnect(); return false; } @@ -286,18 +290,19 @@ sock.setSoLinger(false, 0); InputStream in = sock.getInputStream(); OutputStream out = sock.getOutputStream(); - bin = new BufferedInputStream(in, 8192); bout = new BufferedOutputStream(out); - byte abyte0[]; + while (negotiate(abyte0 = readNegotiations())); + negotiated = true; + try { screen52.setCursorActive(false); - } catch (Exception excc) { - Log.w(TAG,"setCursorOff " + excc.getMessage()); - + } + catch (Exception excc) { + Log.w(TAG, "setCursorOff " + excc.getMessage()); } producer = new DataStreamProducer(this, bin, dsq, abyte0); @@ -309,35 +314,36 @@ try { screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_NOTINHIBITED, - ScreenOIA.OIA_LEVEL_INPUT_INHIBITED); - } catch (Exception exc) { - Log.w(TAG,"setStatus(OFF) " + exc.getMessage()); + ScreenOIA.OIA_LEVEL_INPUT_INHIBITED); + } + catch (Exception exc) { + Log.w(TAG, "setStatus(OFF) " + exc.getMessage()); } keepTrucking = true; me = new Thread(this); me.start(); - - } catch (Exception exception) { + } + catch (Exception exception) { if (exception.getMessage() == null) exception.printStackTrace(); - Log.w(TAG,"connect() " + exception.getMessage()); + + Log.w(TAG, "connect() " + exception.getMessage()); if (sock == null) - Log.w(TAG,"I did not get a socket"); + Log.w(TAG, "I did not get a socket"); disconnect(); return false; } + return true; - } public final boolean disconnect() { - if (!connected) { screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT, - ScreenOIA.OIA_LEVEL_INPUT_INHIBITED,"X - Disconnected"); + ScreenOIA.OIA_LEVEL_INPUT_INHIBITED, "X - Disconnected"); return false; } @@ -348,20 +354,22 @@ } screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT, - ScreenOIA.OIA_LEVEL_INPUT_INHIBITED,"X - Disconnected"); + ScreenOIA.OIA_LEVEL_INPUT_INHIBITED, "X - Disconnected"); screen52.getOIA().setKeyBoardLocked(false); pendingUnlock = false; try { if (sock != null) { - Log.i(TAG,"Closing socket"); + Log.i(TAG, "Closing socket"); sock.close(); } + if (bin != null) bin.close(); + if (bout != null) bout.close(); + connected = false; firstScreen = false; - // WVL - LDC : TR.000345 : properly disconnect and clear screen // Is this the right place to set screen realestate on disconnect? //controller.getScreen().clearAll(); @@ -369,21 +377,24 @@ screen52.setCursorActive(false); screen52.clearAll(); screen52.restoreScreen(); - } catch (Exception exception) { - Log.w(TAG,exception.getMessage()); + } + catch (Exception exception) { + Log.w(TAG, exception.getMessage()); connected = false; devSeq = -1; return false; - } + devSeq = -1; return true; } private final ByteArrayOutputStream appendByteStream(byte abyte0[]) { ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(); + for (int i = 0; i < abyte0.length; i++) { bytearrayoutputstream.write(abyte0[i]); + if (abyte0[i] == -1) bytearrayoutputstream.write(-1); } @@ -393,9 +404,11 @@ private final byte[] readNegotiations() throws IOException { int i = bin.read(); + if (i < 0) { throw new IOException("Connection closed."); - } else { + } + else { int j = bin.available(); byte abyte0[] = new byte[j + 1]; abyte0[0] = (byte) i; @@ -405,7 +418,6 @@ } private final void writeByte(byte abyte0[]) throws IOException { - bout.write(abyte0); bout.flush(); } @@ -417,62 +429,57 @@ // } public final void sendHeartBeat() throws IOException { - byte[] b = { (byte) 0xff, (byte) 0xf1 }; bout.write(b); bout.flush(); } private final void readImmediate(int readType) { - if (screen52.isStatusErrorCode()) { screen52.restoreErrorLine(); screen52.setStatus(Screen5250.STATUS_ERROR_CODE, - Screen5250.STATUS_VALUE_OFF, null); + Screen5250.STATUS_VALUE_OFF, null); } if (!enhanced) { screen52.setCursorActive(false); } + // screen52.setStatus(Screen5250.STATUS_SYSTEM, // Screen5250.STATUS_VALUE_ON, null); screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT, - ScreenOIA.OIA_LEVEL_INPUT_INHIBITED); - + ScreenOIA.OIA_LEVEL_INPUT_INHIBITED); screen52.getOIA().setKeyBoardLocked(true); pendingUnlock = false; invited = false; - screen52.getScreenFields().readFormatTable(baosp, readType, codePage); try { - writeGDS(0, 3, baosp.toByteArray()); - } catch (IOException ioe) { - - Log.w(TAG,ioe.getMessage()); + } + catch (IOException ioe) { + Log.w(TAG, ioe.getMessage()); baosp.reset(); } + baosp.reset(); - } public final boolean sendAidKey(int aid) { - if (screen52.isStatusErrorCode()) { screen52.restoreErrorLine(); screen52.setStatus(Screen5250.STATUS_ERROR_CODE, - Screen5250.STATUS_VALUE_OFF, null); + Screen5250.STATUS_VALUE_OFF, null); } if (!enhanced) { screen52.setCursorActive(false); } + // screen52.setStatus(Screen5250.STATUS_SYSTEM, // Screen5250.STATUS_VALUE_ON, null); screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT, - ScreenOIA.OIA_LEVEL_INPUT_INHIBITED); - + ScreenOIA.OIA_LEVEL_INPUT_INHIBITED); screen52.getOIA().setKeyBoardLocked(true); pendingUnlock = false; invited = false; @@ -481,82 +488,99 @@ baosp.write(aid); if (dataIncluded(aid)) - screen52.getScreenFields().readFormatTable(baosp, readType, codePage); try { - writeGDS(0, 3, baosp.toByteArray()); - } catch (IOException ioe) { - - Log.w(TAG,ioe.getMessage()); + } + catch (IOException ioe) { + Log.w(TAG, ioe.getMessage()); baosp.reset(); return false; } + baosp.reset(); return true; - } private boolean dataIncluded(int aid) { - switch (aid) { - - case PF1: - return !dataIncluded[0]; - case PF2: - return !dataIncluded[1]; - case PF3: - return !dataIncluded[2]; - case PF4: - return !dataIncluded[3]; - case PF5: - return !dataIncluded[4]; - case PF6: - return !dataIncluded[5]; - case PF7: - return !dataIncluded[6]; - case PF8: - return !dataIncluded[7]; - case PF9: - return !dataIncluded[8]; - case PF10: - return !dataIncluded[9]; - case PF11: - return !dataIncluded[10]; - case PF12: - return !dataIncluded[11]; - case PF13: - return !dataIncluded[12]; - case PF14: - return !dataIncluded[13]; - case PF15: - return !dataIncluded[14]; - case PF16: - return !dataIncluded[15]; - case PF17: - return !dataIncluded[16]; - case PF18: - return !dataIncluded[17]; - case PF19: - return !dataIncluded[18]; - case PF20: - return !dataIncluded[19]; - case PF21: - return !dataIncluded[20]; - case PF22: - return !dataIncluded[21]; - case PF23: - return !dataIncluded[22]; - case PF24: - return !dataIncluded[23]; - - default: - return true; - + case PF1: + return !dataIncluded[0]; + + case PF2: + return !dataIncluded[1]; + + case PF3: + return !dataIncluded[2]; + + case PF4: + return !dataIncluded[3]; + + case PF5: + return !dataIncluded[4]; + + case PF6: + return !dataIncluded[5]; + + case PF7: + return !dataIncluded[6]; + + case PF8: + return !dataIncluded[7]; + + case PF9: + return !dataIncluded[8]; + + case PF10: + return !dataIncluded[9]; + + case PF11: + return !dataIncluded[10]; + + case PF12: + return !dataIncluded[11]; + + case PF13: + return !dataIncluded[12]; + + case PF14: + return !dataIncluded[13]; + + case PF15: + return !dataIncluded[14]; + + case PF16: + return !dataIncluded[15]; + + case PF17: + return !dataIncluded[16]; + + case PF18: + return !dataIncluded[17]; + + case PF19: + return !dataIncluded[18]; + + case PF20: + return !dataIncluded[19]; + + case PF21: + return !dataIncluded[20]; + + case PF22: + return !dataIncluded[21]; + + case PF23: + return !dataIncluded[22]; + + case PF24: + return !dataIncluded[23]; + + default: + return true; } - } /** @@ -566,7 +590,6 @@ * See notes inside method */ public final void sendHelpRequest() { - // Client sends header 000D12A0000004000003####F3FFEF // operation code 3 // row - first ## @@ -579,10 +602,11 @@ try { writeGDS(0, 3, baosp.toByteArray()); - } catch (IOException ioe) { - - Log.w(TAG,ioe.getMessage()); } + catch (IOException ioe) { + Log.w(TAG, ioe.getMessage()); + } + baosp.reset(); } @@ -593,7 +617,6 @@ * See notes inside method */ public final void sendAttentionKey() { - // Client sends header 000A12A000004400000FFEF // 0x40 -> 01000000 // @@ -606,12 +629,11 @@ // bit 7 - HLP // System.out.println("Attention key sent"); - try { writeGDS(0x40, 0, null); - } catch (IOException ioe) { - - Log.w(TAG,ioe.getMessage()); + } + catch (IOException ioe) { + Log.w(TAG, ioe.getMessage()); } } @@ -642,22 +664,26 @@ public final void systemRequest(String sr) { byte[] bytes = null; - if ( (sr != null) && (sr.length() > 0)) { + if ((sr != null) && (sr.length() > 0)) { // XXX: Not sure, if this is a sufficient check for 'clear dataq' if (sr.charAt(0) == '2') { dsq.clear(); } + for (int i = 0, l = sr.length(); i < l; i++) { baosp.write(codePage.uni2ebcdic(sr.charAt(i))); } + bytes = baosp.toByteArray(); } try { writeGDS(4, 0, bytes); - } catch (IOException ioe) { - Log.i(TAG,ioe.getMessage()); } + catch (IOException ioe) { + Log.i(TAG, ioe.getMessage()); + } + baosp.reset(); } @@ -668,11 +694,10 @@ * See notes inside method */ public final void cancelInvite() { - // screen52.setStatus(Screen5250.STATUS_SYSTEM, // Screen5250.STATUS_VALUE_ON, null); screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT, - ScreenOIA.OIA_LEVEL_INPUT_INHIBITED); + ScreenOIA.OIA_LEVEL_INPUT_INHIBITED); // from rfc1205 section 4.3 // Server: Sends header with the 000A12A0 00000400 000AFFEF @@ -684,27 +709,24 @@ // no longer invited. try { writeGDS(0, 10, null); - } catch (IOException ioe) { - - Log.w(TAG,ioe.getMessage()); } - + catch (IOException ioe) { + Log.w(TAG, ioe.getMessage()); + } } public final void hostPrint(int aid) { - if (screen52.isStatusErrorCode()) { screen52.restoreErrorLine(); screen52.setStatus(Screen5250.STATUS_ERROR_CODE, - Screen5250.STATUS_VALUE_OFF, null); + Screen5250.STATUS_VALUE_OFF, null); } screen52.setCursorActive(false); // screen52.setStatus(Screen5250.STATUS_SYSTEM, // Screen5250.STATUS_VALUE_ON, null); screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT, - ScreenOIA.OIA_LEVEL_INPUT_INHIBITED); - + ScreenOIA.OIA_LEVEL_INPUT_INHIBITED); // From client access ip capture // it seems to use an operation code of 3 and 4 // also note that the flag field that says reserved is being sent as @@ -721,17 +743,17 @@ // row - first ## // column - second ## // F6 - Print Aid Key - baosp.write(screen52.getCurrentRow()); baosp.write(screen52.getCurrentCol()); baosp.write(AID_PRINT); // aid key try { writeGDS(0, 3, baosp.toByteArray()); - } catch (IOException ioe) { - - Log.w(TAG,ioe.getMessage()); } + catch (IOException ioe) { + Log.w(TAG, ioe.getMessage()); + } + baosp.reset(); } @@ -742,7 +764,6 @@ // write gerneral data stream private final void writeGDS(int flags, int opcode, byte abyte0[]) throws IOException { - // Added to fix for JDK 1.4 this was null coming from another method. // There was a weird keyRelease event coming from another panel when // using a key instead of the mouse to select button. @@ -752,6 +773,7 @@ return; int length; + if (abyte0 != null) length = abyte0.length + 10; else @@ -759,25 +781,20 @@ // refer to rfc1205 - 5250 Telnet interface // Section 3. Data Stream Format - // Logical Record Length - 16 bits baosrsp.write(length >> 8); // Length LL baosrsp.write(length & 0xff); // LL - // Record Type - 16 bits // It should always be set to '12A0'X to indicate the // General Data Stream (GDS) record type. baosrsp.write(18); // 0x12 baosrsp.write(160); // 0xA0 - // the next 16 bits are not used baosrsp.write(0); // 0x00 baosrsp.write(0); // 0x00 - // The second part is meant to be variable in length // currently this portion is 4 octets long (1 byte or 8 bits for us ;-O) baosrsp.write(4); // 0x04 - baosrsp.write(flags); // flags // bit 0 - ERR // bit 1 - ATN Attention @@ -792,13 +809,10 @@ baosrsp.write(abyte0, 0, abyte0.length); baosrsp = appendByteStream(baosrsp.toByteArray()); - // make sure we indicate no more to be sent baosrsp.write(IAC); baosrsp.write(EOR); - baosrsp.writeTo(bout); - // byte[] b = new byte[baosrsp.size()]; // b = baosrsp.toByteArray(); // dump(b); @@ -808,7 +822,6 @@ } protected final int getOpCode() { - return bk.getOpCode(); } @@ -819,70 +832,63 @@ protected boolean[] getActiveAidKeys() { boolean aids[] = new boolean[dataIncluded.length]; - System.arraycopy(dataIncluded,0,aids,0,dataIncluded.length); + System.arraycopy(dataIncluded, 0, aids, 0, dataIncluded.length); return aids; } private final void setInvited() { - - Log.d(TAG,"invited"); + Log.d(TAG, "invited"); + if (!screen52.isStatusErrorCode()) screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_NOTINHIBITED, - ScreenOIA.OIA_LEVEL_INPUT_INHIBITED); + ScreenOIA.OIA_LEVEL_INPUT_INHIBITED); invited = true; } // WVL - LDC : 05/08/2005 : TFX.006253 - Support STRPCCMD - private void strpccmd() - { - try - { + private void strpccmd() { + try { int str = 11; char c; ScreenPlanes planes = screen52.getPlanes(); c = planes.getChar(str); boolean waitFor = !(c == 'a'); - StringBuffer command = new StringBuffer(); - for (int i = str+1; i < 132; i++) - { + + for (int i = str + 1; i < 132; i++) { c = planes.getChar(i); + if (Character.isISOControl(c)) c = ' '; + command.append(c); } String cmd = command.toString().trim(); - run(cmd, waitFor); } - finally - { + finally { strpccmd = false; screen52.sendKeys(TN5250jConstants.MNEMONIC_ENTER); } } // WVL - LDC : 05/08/2005 : TFX.006253 - Support STRPCCMD - private void run(String cmd, boolean waitFor) - { - try - { - Log.d(TAG,"RUN cmd = " + cmd); - Log.d(TAG,"RUN wait = " + waitFor); - + private void run(String cmd, boolean waitFor) { + try { + Log.d(TAG, "RUN cmd = " + cmd); + Log.d(TAG, "RUN wait = " + waitFor); Runtime r = Runtime.getRuntime(); Process p = r.exec(cmd); - if (waitFor) - { + + if (waitFor) { int result = p.waitFor(); - Log.d(TAG,"RUN result = " + result); + Log.d(TAG, "RUN result = " + result); } } - catch (Throwable t) - { - Log.e(TAG,"exception",t); + catch (Throwable t) { + Log.e(TAG, "exception", t); } } @@ -921,7 +927,6 @@ private void scan() { // System.out.println("Checking command : " + // screen52.screen[1].getChar() + screen52.screen[2].getChar()); - // ScreenChar[] screen = screen52.screen; ScreenPlanes planes = screen52.getPlanes(); @@ -930,8 +935,9 @@ && (planes.getChar(STRSCAN + 2) != ' ')) { try { parseCommand(); - } catch (Throwable t) { - Log.i(TAG,"Exec cmd: " + t.getMessage()); + } + catch (Throwable t) { + Log.i(TAG, "Exec cmd: " + t.getMessage()); t.printStackTrace(); } } @@ -962,51 +968,48 @@ // after the #! sequence separated by a space from the rest // of the screen. char[] screen = screen52.getScreenAsChars(); + for (int s = STRSCAN + 2, i = s; i < screen.length; i++) { if (screen[i] == ' ') { String command = new String(screen, s, i - s); - // Skip all white spaces between the command and the rest of // the screen. //for (; (i < screen.length) && (screen[i] == ' '); i++); - String remainder = new String(screen, i + 1, screen.length - - (i + 1)); + - (i + 1)); //controller.fireScanned(command, remainder); - Log.i(TAG,"trying to run " + command + " " + remainder); + Log.i(TAG, "trying to run " + command + " " + remainder); break; } } } public void run() { - if (enhanced) sfParser = new WTDSFParser(this); bk = new Stream5250(); while (keepTrucking) { - try { Object e = dsq.poll(0L, TimeUnit.SECONDS); + if (e == null) { buffer.testChanged(); e = dsq.take(); }; + bk.initialize((byte[])e); - } catch (InterruptedException ie) { - Log.w(TAG," vt thread interrupted and stopping "); + } + catch (InterruptedException ie) { + Log.w(TAG, " vt thread interrupted and stopping "); keepTrucking = false; continue; } // lets play nicely with the others on the playground // me.yield(); - Thread.yield(); - invited = false; - screen52.setCursorActive(false); // System.out.println("operation code: " + bk.getOpCode()); @@ -1014,79 +1017,91 @@ continue; switch (bk.getOpCode()) { - case 00: - Log.d(TAG,"No operation"); - break; - case 1: - Log.d(TAG,"Invite Operation"); - parseIncoming(); - // screen52.setKeyboardLocked(false); - pendingUnlock = true; - cursorOn = true; - setInvited(); - break; - case 2: - Log.d(TAG,"Output Only"); - parseIncoming(); - screen52.updateDirty(); - break; - case 3: - Log.d(TAG,"Put/Get Operation"); - parseIncoming(); - setInvited(); - if (!firstScreen) { - firstScreen = true; - //controller.fireSessionChanged(TN5250jConstants.STATE_CONNECTED); - } - break; - case 4: - Log.d(TAG,"Save Screen Operation"); - parseIncoming(); - break; - - case 5: - Log.d(TAG,"Restore Screen Operation"); - parseIncoming(); - break; - case 6: - Log.d(TAG,"Read Immediate"); - sendAidKey(0); - break; - case 7: - Log.d(TAG,"Reserved"); - break; - case 8: - Log.d(TAG,"Read Screen Operation"); - try { - readScreen(); - } catch (IOException ex) { - Log.w(TAG,ex.getMessage()); - } - break; - - case 9: - Log.d(TAG,"Reserved"); - break; - - case 10: - Log.d(TAG,"Cancel Invite Operation"); - cancelInvite(); - break; - - case 11: - Log.d(TAG,"Turn on message light"); - screen52.getOIA().setMessageLightOn(); - screen52.setCursorActive(true); - - break; - case 12: - Log.d(TAG,"Turn off Message light"); - screen52.getOIA().setMessageLightOff(); - screen52.setCursorActive(true); - - break; - default: - break; + case 00: + Log.d(TAG, "No operation"); + break; + + case 1: + Log.d(TAG, "Invite Operation"); + parseIncoming(); + // screen52.setKeyboardLocked(false); + pendingUnlock = true; + cursorOn = true; + setInvited(); + break; + + case 2: + Log.d(TAG, "Output Only"); + parseIncoming(); + screen52.updateDirty(); + break; + + case 3: + Log.d(TAG, "Put/Get Operation"); + parseIncoming(); + setInvited(); + + if (!firstScreen) { + firstScreen = true; + //controller.fireSessionChanged(TN5250jConstants.STATE_CONNECTED); + } + + break; + + case 4: + Log.d(TAG, "Save Screen Operation"); + parseIncoming(); + break; + + case 5: + Log.d(TAG, "Restore Screen Operation"); + parseIncoming(); + break; + + case 6: + Log.d(TAG, "Read Immediate"); + sendAidKey(0); + break; + + case 7: + Log.d(TAG, "Reserved"); + break; + + case 8: + Log.d(TAG, "Read Screen Operation"); + + try { + readScreen(); + } + catch (IOException ex) { + Log.w(TAG, ex.getMessage()); + } + + break; + + case 9: + Log.d(TAG, "Reserved"); + break; + + case 10: + Log.d(TAG, "Cancel Invite Operation"); + cancelInvite(); + break; + + case 11: + Log.d(TAG, "Turn on message light"); + screen52.getOIA().setMessageLightOn(); + screen52.setCursorActive(true); + break; + + case 12: + Log.d(TAG, "Turn off Message light"); + screen52.getOIA().setMessageLightOff(); + screen52.setCursorActive(true); + break; + + default: + break; } if (screen52.isUsingGuiInterface()) @@ -1095,11 +1110,13 @@ try { if (!strpccmd) { screen52.updateDirty(); - } else { + } + else { strpccmd(); } - } catch (Exception exd) { - Log.w(TAG," tnvt.run: " + exd.getMessage()); + } + catch (Exception exd) { + Log.w(TAG, " tnvt.run: " + exd.getMessage()); exd.printStackTrace(); } @@ -1116,16 +1133,15 @@ // lets play nicely with the others on the playground //me.yield(); Thread.yield(); - } } public void dumpStuff() { - Log.d(TAG," Pending unlock " + pendingUnlock); - Log.d(TAG," Status Error " + screen52.isStatusErrorCode()); - Log.d(TAG," Keyboard Locked " + screen52.getOIA().isKeyBoardLocked()); - Log.d(TAG," Cursor On " + cursorOn); - Log.d(TAG," Cursor Active " + screen52.cursorActive); + Log.d(TAG, " Pending unlock " + pendingUnlock); + Log.d(TAG, " Status Error " + screen52.isStatusErrorCode()); + Log.d(TAG, " Keyboard Locked " + screen52.getOIA().isKeyBoardLocked()); + Log.d(TAG, " Cursor On " + cursorOn); + Log.d(TAG, " Cursor Active " + screen52.cursorActive); } @@ -1142,20 +1158,20 @@ int la = 32; int sac = 0; int len = rows * cols; - ScreenPlanes planes = screen52.planes; for (int y = 0; y < len; y++) { // save the screen data - if (planes.isAttributePlace(y)) { la = planes.getCharAttr(y); sa[sac++] = (byte) la; - } else { + } + else { if (planes.getCharAttr(y) != la) { la = planes.getCharAttr(y); sac--; sa[sac++] = (byte) la; } + //LDC: Check to see if it is an displayable character. If not, // do not convert the character. // The characters on screen are in unicode @@ -1163,8 +1179,10 @@ // (byte)codePage.uni2ebcdic(screen52.screen[y].getChar()); char ch = planes.getChar(y); byte byteCh = (byte) ch; + if (isDataUnicode(ch)) byteCh = codePage.uni2ebcdic(ch); + sa[sac++] = byteCh; } } @@ -1172,32 +1190,27 @@ private final void fillRegenerationBuffer(ByteArrayOutputStream sc, int rows, int cols) throws IOException { - int la = 32; int sac = 0; int len = rows * cols; - ScreenPlanes planes = screen52.planes; byte[] sa = new byte[len]; try { boolean guiExists = sfParser != null && sfParser.isGuisExists(); - for (int y = 0; y < len; y++) { // save the screen data - if (guiExists) { - byte[] guiSeg = sfParser.getSegmentAtPos(y); + if (guiSeg != null) { //Log.i(TAG," gui saved at " + y + " - " + screen52.getRow(y) + "," + // screen52.getCol(y)); - byte[] gsa = new byte[sa.length + guiSeg.length + 2]; - System.arraycopy(sa,0,gsa,0,sa.length); - System.arraycopy(guiSeg,0,gsa,sac+2,guiSeg.length); + System.arraycopy(sa, 0, gsa, 0, sa.length); + System.arraycopy(guiSeg, 0, gsa, sac + 2, guiSeg.length); sa = new byte[gsa.length]; - System.arraycopy(gsa,0,sa,0,gsa.length); + System.arraycopy(gsa, 0, sa, 0, gsa.length); sa[sac++] = (byte)0x04; sa[sac++] = (byte)0x11; sac += guiSeg.length; @@ -1205,15 +1218,18 @@ // continue; } } + if (planes.isAttributePlace(y)) { la = planes.getCharAttr(y); sa[sac++] = (byte) la; - } else { + } + else { if (planes.getCharAttr(y) != la) { la = planes.getCharAttr(y); sac--; sa[sac++] = (byte) la; } + //LDC: Check to see if it is an displayable character. If not, // do not convert the character. // The characters on screen are in unicode @@ -1221,79 +1237,78 @@ // (byte)codePage.uni2ebcdic(screen52.screen[y].getChar()); char ch = planes.getChar(y); byte byteCh = (byte) ch; + if (isDataUnicode(ch)) byteCh = codePage.uni2ebcdic(ch); + sa[sac++] = byteCh; } } } - catch(Exception exc) { - - Log.i(TAG,exc.getMessage()); + catch (Exception exc) { + Log.i(TAG, exc.getMessage()); exc.printStackTrace(); } + sc.write(sa); } public final void saveScreen() throws IOException { - ByteArrayOutputStream sc = new ByteArrayOutputStream(); sc.write(4); sc.write(0x12); // 18 sc.write(0); // 18 sc.write(0); // 18 - sc.write((byte) screen52.getRows()); // store the current size sc.write((byte) screen52.getColumns()); // "" - int cp = screen52.getCurrentPos(); // save off current position // fix below submitted by Mitch Blevins //int cp = screen52.getScreenFields().getCurrentFieldPos(); // save off current position - sc.write((byte) (cp >> 8 & 0xff)); // "" - sc.write((byte) (cp & 0xff)); // "" - - sc.write((byte) (screen52.homePos >> 8 & 0xff)); // save home pos - sc.write((byte) (screen52.homePos & 0xff)); // "" - + sc.write((byte)(cp >> 8 & 0xff)); // "" + sc.write((byte)(cp & 0xff)); // "" + sc.write((byte)(screen52.homePos >> 8 & 0xff)); // save home pos + sc.write((byte)(screen52.homePos & 0xff)); // "" int rows = screen52.getRows(); // store the current size int cols = screen52.getColumns(); // "" - // byte[] sa = new byte[rows * cols]; - fillRegenerationBuffer(sc,rows,cols); + fillRegenerationBuffer(sc, rows, cols); // fillScreenArray(sa, rows, cols); // // sc.write(sa); // sa = null; int sizeFields = screen52.getScreenFields().getSize(); - sc.write((byte) (sizeFields >> 8 & 0xff)); // "" - sc.write((byte) (sizeFields & 0xff)); // "" + sc.write((byte)(sizeFields >> 8 & 0xff)); // "" + sc.write((byte)(sizeFields & 0xff)); // "" if (sizeFields > 0) { int x = 0; int s = screen52.getScreenFields().getSize(); ScreenField sf = null; + while (x < s) { sf = screen52.getScreenFields().getField(x); sc.write((byte) sf.getAttr()); // attribute int sp = sf.startPos(); - sc.write((byte) (sp >> 8 & 0xff)); // "" - sc.write((byte) (sp & 0xff)); // "" + sc.write((byte)(sp >> 8 & 0xff)); // "" + sc.write((byte)(sp & 0xff)); // "" + if (sf.mdt) sc.write((byte) 1); else sc.write((byte) 0); - sc.write((byte) (sf.getLength() >> 8 & 0xff)); // "" - sc.write((byte) (sf.getLength() & 0xff)); // "" + + sc.write((byte)(sf.getLength() >> 8 & 0xff)); // "" + sc.write((byte)(sf.getLength() & 0xff)); // "" sc.write((byte) sf.getFFW1() & 0xff); sc.write((byte) sf.getFFW2() & 0xff); sc.write((byte) sf.getFCW1() & 0xff); sc.write((byte) sf.getFCW2() & 0xff); - Log.d(TAG,"Saved "); - Log.d(TAG,sf.toString()); - + Log.d(TAG, "Saved "); + Log.d(TAG, sf.toString()); x++; } + sf = null; } @@ -1305,13 +1320,13 @@ try { writeGDS(0, 3, sc.toByteArray()); - } catch (IOException ioe) { - - Log.w(TAG,ioe.getMessage()); + } + catch (IOException ioe) { + Log.w(TAG, ioe.getMessage()); } sc = null; - Log.d(TAG,"Save Screen end "); + Log.d(TAG, "Save Screen end "); } /** @@ -1320,37 +1335,37 @@ */ public final void restoreScreen() throws IOException { int which = 0; - ScreenPlanes planes = screen52.planes; try { - Log.d(TAG,"Restore "); - + Log.d(TAG, "Restore "); bk.getNextByte(); bk.getNextByte(); - int rows = bk.getNextByte() & 0xff; int cols = bk.getNextByte() & 0xff; int pos = bk.getNextByte() << 8 & 0xff00; // current position pos |= bk.getNextByte() & 0xff; int hPos = bk.getNextByte() << 8 & 0xff00; // home position hPos |= bk.getNextByte() & 0xff; + if ((rows != screen52.getRows()) || (cols != screen52.getColumns())) screen52.setRowsCols(rows, cols); + screen52.clearAll(); // initialize what we currenty have + if (sfParser != null && sfParser.isGuisExists()) sfParser.clearGuiStructs(); int b = 32; int la = 32; int len = rows * cols; + for (int y = 0; y < len; y++) { - b = bk.getNextByte(); + if (b == 0x04) { - - Log.i(TAG," gui restored at " + y + " - " + screen52.getRow(y) + "," + - screen52.getCol(y)); + Log.i(TAG, " gui restored at " + y + " - " + screen52.getRow(y) + "," + + screen52.getCol(y)); int command = bk.getNextByte(); byte[] seg = bk.getSegment(); @@ -1358,6 +1373,7 @@ screen52.goto_XY(y); sfParser.parseWriteToDisplayStructuredField(seg); } + y--; // screen52.goto_XY(y); } @@ -1365,10 +1381,10 @@ // b = bk.getNextByte(); if (planes.isUseGui(y)) continue; + if (isAttribute(b)) { planes.setScreenCharAndAttr(y, planes.getChar(y), b, true); la = b; - } else { //LDC - 12/02/2003 - Check to see if it is an displayable @@ -1376,6 +1392,7 @@ // do not convert the character. // The characters on screen are in unicode char ch = (char) b; + if (isDataEBCDIC(b)) ch = codePage.ebcdic2uni(b); @@ -1386,7 +1403,7 @@ int numFields = bk.getNextByte() << 8 & 0xff00; numFields |= bk.getNextByte() & 0xff; - Log.d(TAG,"number of fields " + numFields); + Log.d(TAG, "number of fields " + numFields); if (numFields > 0) { int x = 0; @@ -1398,41 +1415,40 @@ int fcw1 = 0; int fcw2 = 0; boolean mdt = false; - ScreenField sf = null; + while (x < numFields) { - attr = bk.getNextByte(); fPos = bk.getNextByte() << 8 & 0xff00; fPos |= bk.getNextByte() & 0xff; + if (bk.getNextByte() == 1) mdt = true; else mdt = false; + fLen = bk.getNextByte() << 8 & 0xff00; fLen |= bk.getNextByte() & 0xff; ffw1 = bk.getNextByte(); ffw2 = bk.getNextByte(); fcw1 = bk.getNextByte(); fcw2 = bk.getNextByte(); - sf = screen52.getScreenFields().setField(attr, screen52.getRow(fPos), screen52.getCol(fPos), fLen, ffw1, ffw2, fcw1, fcw2); while (fLen-- > 0) { - // now we set the field plane attributes - planes.setScreenFieldAttr(fPos++,ffw1); - + planes.setScreenFieldAttr(fPos++, ffw1); } if (mdt) { sf.setMDT(); screen52.getScreenFields().setMasterMDT(); } - Log.d(TAG,"/nRestored "); - Log.d(TAG,sf.toString()); + + Log.d(TAG, "/nRestored "); + Log.d(TAG, sf.toString()); x++; } } @@ -1442,13 +1458,12 @@ screen52.drawFields(); screen52.restoreScreen(); // display the screen - // The position was saved with currentPos which 1,1 offset of the // screen position. // The setPendingInsert is the where the cursor position will be // displayed after the restore. screen52.setPendingInsert(true, screen52.getRow(pos + cols), screen52 - .getCol(pos + cols)); + .getCol(pos + cols)); // We need to offset the pos by -1 since the position is 1,1 based // and the goto_XY is 0,0 based. screen52.goto_XY(pos - 1); @@ -1456,19 +1471,18 @@ // // Redraw the gui fields if we are in gui mode // if (screen52.isUsingGuiInterface()) // screen52.drawFields(); - } catch (Exception e) { - Log.w(TAG,"error restoring screen " + which + " with " - + e.getMessage()); + } + catch (Exception e) { + Log.w(TAG, "error restoring screen " + which + " with " + + e.getMessage()); } } public final boolean waitingForInput() { - return waitingForInput; } private void parseIncoming() { - boolean done = false; boolean error = false; @@ -1477,129 +1491,143 @@ byte b = bk.getNextByte(); switch (b) { - case 0: - case 1: - break; - case CMD_SAVE_SCREEN: // 0x02 2 Save Screen - case 3: // 0x03 3 Save Partial Screen - Log.d(TAG,"save screen partial"); - saveScreen(); - break; - - case ESC: // ESCAPE - break; - case 7: // audible bell - manager.playBeep(); - bk.getNextByte(); - bk.getNextByte(); - break; - case CMD_WRITE_TO_DISPLAY: // 0x11 17 write to display - error = writeToDisplay(true); - // WVL - LDC : TR.000300 : Callback scenario from 5250 - // Only scan when WRITE_TO_DISPLAY operation (i.e. refill - // screen buffer) - // has been issued! - if (scan) - scan(); - - break; - case CMD_RESTORE_SCREEN: // 0x12 18 Restore Screen - case 13: // 0x13 19 Restore Partial Screen - Log.d(TAG,"restore screen partial"); - restoreScreen(); - break; - - case CMD_CLEAR_UNIT_ALTERNATE: // 0x20 32 clear unit alternate - int param = bk.getNextByte(); - if (param != 0) { - Log.d(TAG," clear unit alternate error " - + Integer.toHexString(param)); - sendNegResponse(NR_REQUEST_ERROR, 03, 01, 05, - " clear unit alternate not supported"); - done = true; - } else { - if (screen52.getRows() != 27) - screen52.setRowsCols(27, 132); + case 0: + case 1: + break; + + case CMD_SAVE_SCREEN: // 0x02 2 Save Screen + case 3: // 0x03 3 Save Partial Screen + Log.d(TAG, "save screen partial"); + saveScreen(); + break; + + case ESC: // ESCAPE + break; + + case 7: // audible bell + manager.playBeep(); + bk.getNextByte(); + bk.getNextByte(); + break; + + case CMD_WRITE_TO_DISPLAY: // 0x11 17 write to display + error = writeToDisplay(true); + + // WVL - LDC : TR.000300 : Callback scenario from 5250 + // Only scan when WRITE_TO_DISPLAY operation (i.e. refill + // screen buffer) + // has been issued! + if (scan) + scan(); + + break; + + case CMD_RESTORE_SCREEN: // 0x12 18 Restore Screen + case 13: // 0x13 19 Restore Partial Screen + Log.d(TAG, "restore screen partial"); + restoreScreen(); + break; + + case CMD_CLEAR_UNIT_ALTERNATE: // 0x20 32 clear unit alternate + int param = bk.getNextByte(); + + if (param != 0) { + Log.d(TAG, " clear unit alternate error " + + Integer.toHexString(param)); + sendNegResponse(NR_REQUEST_ERROR, 03, 01, 05, + " clear unit alternate not supported"); + done = true; + } + else { + if (screen52.getRows() != 27) + screen52.setRowsCols(27, 132); + + screen52.clearAll(); + + if (sfParser != null && sfParser.isGuisExists()) + sfParser.clearGuiStructs(); + } + + break; + + case CMD_WRITE_ERROR_CODE: // 0x21 33 Write Error Code + writeErrorCode(); + error = writeToDisplay(false); + break; + + case CMD_WRITE_ERROR_CODE_TO_WINDOW: // 0x22 34 + // Write Error Code to window + writeErrorCodeToWindow(); + error = writeToDisplay(false); + break; + + case CMD_READ_SCREEN_IMMEDIATE: // 0x62 98 + case CMD_READ_SCREEN_TO_PRINT: // 0x66 102 read screen to print + readScreen(); + break; + + case CMD_CLEAR_UNIT: // 64 0x40 clear unit + if (screen52.getRows() != 24) + screen52.setRowsCols(24, 80); screen52.clearAll(); + if (sfParser != null && sfParser.isGuisExists()) sfParser.clearGuiStructs(); - - } - break; - - case CMD_WRITE_ERROR_CODE: // 0x21 33 Write Error Code - writeErrorCode(); - error = writeToDisplay(false); - break; - case CMD_WRITE_ERROR_CODE_TO_WINDOW: // 0x22 34 - // Write Error Code to window - writeErrorCodeToWindow(); - error = writeToDisplay(false); - break; - - case CMD_READ_SCREEN_IMMEDIATE: // 0x62 98 - case CMD_READ_SCREEN_TO_PRINT: // 0x66 102 read screen to print - readScreen(); - break; - - case CMD_CLEAR_UNIT: // 64 0x40 clear unit - if (screen52.getRows() != 24) - screen52.setRowsCols(24, 80); - screen52.clearAll(); - if (sfParser != null && sfParser.isGuisExists()) - sfParser.clearGuiStructs(); - - break; - - case CMD_CLEAR_FORMAT_TABLE: // 80 0x50 Clear format table - screen52.clearTable(); - break; - - case CMD_READ_INPUT_FIELDS: //0x42 66 read input fields - case CMD_READ_MDT_FIELDS: // 0x52 82 read MDT Fields - bk.getNextByte(); - bk.getNextByte(); - readType = b; - screen52.goHome(); - // do nothing with the cursor here it is taken care of - // in the main loop. - //////////////// screen52.setCursorOn(); - waitingForInput = true; - pendingUnlock = true; - // screen52.setKeyboardLocked(false); - break; - case CMD_READ_MDT_IMMEDIATE_ALT: // 0x53 83 - readType = b; - // screen52.goHome(); - // waitingForInput = true; - // screen52.setKeyboardLocked(false); - readImmediate(readType); - break; - case CMD_WRITE_STRUCTURED_FIELD: // 243 0xF3 -13 Write - // structured field - writeStructuredField(); - break; - case CMD_ROLL: // 0x23 35 Roll Not sure what it does right now - int updown = bk.getNextByte(); - int topline = bk.getNextByte(); - int bottomline = bk.getNextByte(); - screen52.rollScreen(updown, topline, bottomline); - break; - - default: - done = true; - sendNegResponse(NR_REQUEST_ERROR, 03, 01, 01, - "parseIncoming"); - break; + break; + + case CMD_CLEAR_FORMAT_TABLE: // 80 0x50 Clear format table + screen52.clearTable(); + break; + + case CMD_READ_INPUT_FIELDS: //0x42 66 read input fields + case CMD_READ_MDT_FIELDS: // 0x52 82 read MDT Fields + bk.getNextByte(); + bk.getNextByte(); + readType = b; + screen52.goHome(); + // do nothing with the cursor here it is taken care of + // in the main loop. + //////////////// screen52.setCursorOn(); + waitingForInput = true; + pendingUnlock = true; + // screen52.setKeyboardLocked(false); + break; + + case CMD_READ_MDT_IMMEDIATE_ALT: // 0x53 83 + readType = b; + // screen52.goHome(); + // waitingForInput = true; + // screen52.setKeyboardLocked(false); + readImmediate(readType); + break; + + case CMD_WRITE_STRUCTURED_FIELD: // 243 0xF3 -13 Write + // structured field + writeStructuredField(); + break; + + case CMD_ROLL: // 0x23 35 Roll Not sure what it does right now + int updown = bk.getNextByte(); + int topline = bk.getNextByte(); + int bottomline = bk.getNextByte(); + screen52.rollScreen(updown, topline, bottomline); + break; + + default: + done = true; + sendNegResponse(NR_REQUEST_ERROR, 03, 01, 01, + "parseIncoming"); + break; } if (error) done = true; } - } catch (Exception exc) { - Log.w(TAG,"incoming " + exc.getMessage()); + } + catch (Exception exc) { + Log.w(TAG, "incoming " + exc.getMessage()); } } @@ -1618,17 +1646,15 @@ * */ protected void sendNegResponse(int cat, int modifier, int uByte1, - int uByte2, String from) { - + int uByte2, String from) { try { - int os = bk.getByteOffset(-1) & 0xf0; int cp = (bk.getCurrentPos() - 1); - Log.i(TAG,"invalid " + from + " command " + os - + " at pos " + cp); - } catch (Exception e) { - - Log.w(TAG,"Send Negative Response error " + e.getMessage()); + Log.i(TAG, "invalid " + from + " command " + os + + " at pos " + cp); + } + catch (Exception e) { + Log.w(TAG, "Send Negative Response error " + e.getMessage()); } baosp.write(cat); @@ -1638,32 +1664,30 @@ try { writeGDS(128, 0, baosp.toByteArray()); - } catch (IOException ioe) { - - Log.w(TAG,ioe.getMessage()); } + catch (IOException ioe) { + Log.w(TAG, ioe.getMessage()); + } + baosp.reset(); - } public void sendNegResponse2(int ec) { - screen52.setPrehelpState(true, true, false); baosp.write(0x00); baosp.write(ec); try { writeGDS(1, 0, baosp.toByteArray()); - } catch (IOException ioe) { - - Log.w(TAG,ioe.getMessage()); + } + catch (IOException ioe) { + Log.w(TAG, ioe.getMessage()); } baosp.reset(); } private boolean writeToDisplay(boolean controlsExist) { - boolean error = false; boolean done = false; int attr; @@ -1678,303 +1702,306 @@ control1 = bk.getNextByte(); processCC0(control0); } + while (bk.hasNext() && !done) { // pos = bk.getCurrentPos(); - // int rowc = screen52.getCurrentRow(); // int colc = screen52.getCurrentCol(); - byte bytebk = bk.getNextByte(); switch (bytebk) { - - case 1: // SOH - Start of Header Order - Log.d(TAG,"SOH - Start of Header Order"); - error = processSOH(); - - break; - case 02: // RA - Repeat to address - Log.d(TAG,"RA - Repeat to address"); - int row = screen52.getCurrentRow(); - int col = screen52.getCurrentCol(); - - int toRow = bk.getNextByte(); - int toCol = bk.getNextByte() & 0xff; - if (toRow >= row) { - int repeat = bk.getNextByte(); + case 1: // SOH - Start of Header Order + Log.d(TAG, "SOH - Start of Header Order"); + error = processSOH(); + break; + + case 02: // RA - Repeat to address + Log.d(TAG, "RA - Repeat to address"); + int row = screen52.getCurrentRow(); + int col = screen52.getCurrentCol(); + int toRow = bk.getNextByte(); + int toCol = bk.getNextByte() & 0xff; + + if (toRow >= row) { + int repeat = bk.getNextByte(); + + // a little intelligence here I hope + if (row == 1 && col == 2 && toRow == screen52.getRows() + && toCol == screen52.getColumns()) + screen52.clearScreen(); + else { + if (repeat != 0) { + //LDC - 13/02/2003 - convert it to unicode + repeat = codePage.ebcdic2uni(repeat); + //repeat = getASCIIChar(repeat); + } + + int times = ((toRow * screen52.getColumns()) + toCol) + - ((row * screen52.getColumns()) + col); + + while (times-- >= 0) { + screen52.setChar(repeat); + } + } + } + else { + sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x23, + " RA invalid"); + error = true; + } + + break; + + case 03: // EA - Erase to address + Log.d(TAG, "EA - Erase to address"); + int EArow = screen52.getCurrentRow(); + int EAcol = screen52.getCurrentCol(); + int toEARow = bk.getNextByte(); + int toEACol = bk.getNextByte() & 0xff; + int EALength = bk.getNextByte() & 0xff; + + while (--EALength > 0) { + bk.getNextByte(); + } + + char EAAttr = (char) 0; // a little intelligence here I hope - if (row == 1 && col == 2 && toRow == screen52.getRows() - && toCol == screen52.getColumns()) - + if (EArow == 1 && EAcol == 2 + && toEARow == screen52.getRows() + && toEACol == screen52.getColumns()) screen52.clearScreen(); else { - if (repeat != 0) { - //LDC - 13/02/2003 - convert it to unicode - repeat = codePage.ebcdic2uni(repeat); - //repeat = getASCIIChar(repeat); + int times = ((toEARow * screen52.getColumns()) + toEACol) + - ((EArow * screen52.getColumns()) + EAcol); + + while (times-- >= 0) { + screen52.setChar(EAAttr); } - - int times = ((toRow * screen52.getColumns()) + toCol) - - ((row * screen52.getColumns()) + col); - while (times-- >= 0) { - screen52.setChar(repeat); - } - + } + + break; + + case 04: // Command - Escape + Log.d(TAG, "Command - Escape"); + done = true; + break; + + case 16: // TD - Transparent Data + Log.d(TAG, "TD - Transparent Data"); + int j = (bk.getNextByte() & 0xff) << 8 | bk.getNextByte() + & 0xff; // length + break; + + case 17: // SBA - set buffer address order (row column) + //Log.d(TAG,"SBA - set buffer address order (row column)"); + int saRow = bk.getNextByte(); + int saCol = bk.getNextByte() & 0xff; + + // make sure it is in bounds + if (saRow >= 0 && saRow <= screen52.getRows() && saCol >= 0 + && saCol <= screen52.getColumns()) { + screen52.setCursor(saRow, saCol); // now set screen + // position for output + } + else { + sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x22, + "invalid row/col order" + " saRow = " + saRow + + " saRows = " + screen52.getRows() + + " saCol = " + saCol); + error = true; } - } else { - sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x23, - " RA invalid"); - error = true; - } - break; - - case 03: // EA - Erase to address - Log.d(TAG,"EA - Erase to address"); - int EArow = screen52.getCurrentRow(); - int EAcol = screen52.getCurrentCol(); - - int toEARow = bk.getNextByte(); - int toEACol = bk.getNextByte() & 0xff; - int EALength = bk.getNextByte() & 0xff; - while (--EALength > 0) { - + + break; + + case 18: // WEA - Extended Attribute + Log.d(TAG, "WEA - Extended Attribute"); + bk.getNextByte(); bk.getNextByte(); - - } - char EAAttr = (char) 0; - - // a little intelligence here I hope - if (EArow == 1 && EAcol == 2 - && toEARow == screen52.getRows() - && toEACol == screen52.getColumns()) - - screen52.clearScreen(); - else { - int times = ((toEARow * screen52.getColumns()) + toEACol) - - ((EArow * screen52.getColumns()) + EAcol); - while (times-- >= 0) { - screen52.setChar(EAAttr); + break; + + case 19: // IC - Insert Cursor + Log.d(TAG, "IC - Insert Cursor"); + int icX = bk.getNextByte(); + int icY = bk.getNextByte() & 0xff; + + if (icX >= 0 && icX <= saRows && icY >= 0 && icY <= saCols) { + Log.d(TAG, " IC " + icX + " " + icY); + screen52.setPendingInsert(true, icX, icY); + } + else { + sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x22, + " IC/IM position invalid "); + error = true; + } + + break; + + case 20: // MC - Move Cursor + Log.d(TAG, "MC - Move Cursor"); + int imcX = bk.getNextByte(); + int imcY = bk.getNextByte() & 0xff; + + if (imcX >= 0 && imcX <= saRows && imcY >= 0 + && imcY <= saCols) { + Log.d(TAG, " MC " + imcX + " " + imcY); + screen52.setPendingInsert(false, imcX, imcY); + } + else { + sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x22, + " IC/IM position invalid "); + error = true; } - } - break; - case 04: // Command - Escape - Log.d(TAG,"Command - Escape"); - done = true; - break; - - case 16: // TD - Transparent Data - Log.d(TAG,"TD - Transparent Data"); - int j = (bk.getNextByte() & 0xff) << 8 | bk.getNextByte() - & 0xff; // length - break; - - case 17: // SBA - set buffer address order (row column) - //Log.d(TAG,"SBA - set buffer address order (row column)"); - int saRow = bk.getNextByte(); - int saCol = bk.getNextByte() & 0xff; - // make sure it is in bounds - if (saRow >= 0 && saRow <= screen52.getRows() && saCol >= 0 - && saCol <= screen52.getColumns()) { - screen52.setCursor(saRow, saCol); // now set screen - // position for output - - } else { - - sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x22, - "invalid row/col order" + " saRow = " + saRow - + " saRows = " + screen52.getRows() - + " saCol = " + saCol); - - error = true; - - } - break; - - case 18: // WEA - Extended Attribute - Log.d(TAG,"WEA - Extended Attribute"); - bk.getNextByte(); - bk.getNextByte(); - break; - - case 19: // IC - Insert Cursor - Log.d(TAG,"IC - Insert Cursor"); - int icX = bk.getNextByte(); - int icY = bk.getNextByte() & 0xff; - if (icX >= 0 && icX <= saRows && icY >= 0 && icY <= saCols) { - - Log.d(TAG," IC " + icX + " " + icY); - screen52.setPendingInsert(true, icX, icY); - } else { - sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x22, - " IC/IM position invalid "); - error = true; - } - - break; - - case 20: // MC - Move Cursor - Log.d(TAG,"MC - Move Cursor"); - int imcX = bk.getNextByte(); - int imcY = bk.getNextByte() & 0xff; - if (imcX >= 0 && imcX <= saRows && imcY >= 0 - && imcY <= saCols) { - - Log.d(TAG," MC " + imcX + " " + imcY); - screen52.setPendingInsert(false, imcX, imcY); - } else { - sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x22, - " IC/IM position invalid "); - error = true; - } - - break; - - case 21: // WTDSF - Write To Display Structured Field order - Log.d(TAG,"WTDSF - Write To Display Structured Field order"); - byte[] seg = bk.getSegment(); - error = sfParser.parseWriteToDisplayStructuredField(seg); - break; - - case 29: // SF - Start of Field - Log.d(TAG,"SF - Start of Field"); - int fcw1 = 0; - int fcw2 = 0; - int ffw1 = 0; - int ffw0 = bk.getNextByte() & 0xff; // FFW - - if ((ffw0 & 0x40) == 0x40) { - ffw1 = bk.getNextByte() & 0xff; // FFW 1 - - fcw1 = bk.getNextByte() & 0xff; // check for field - // control word - - // check if the first fcw1 is an 0x81 if it is then get - // the next pair for checking - if (fcw1 == 0x81) { - bk.getNextByte(); + + break; + + case 21: // WTDSF - Write To Display Structured Field order + Log.d(TAG, "WTDSF - Write To Display Structured Field order"); + byte[] seg = bk.getSegment(); + error = sfParser.parseWriteToDisplayStructuredField(seg); + break; + + case 29: // SF - Start of Field + Log.d(TAG, "SF - Start of Field"); + int fcw1 = 0; + int fcw2 = 0; + int ffw1 = 0; + int ffw0 = bk.getNextByte() & 0xff; // FFW + + if ((ffw0 & 0x40) == 0x40) { + ffw1 = bk.getNextByte() & 0xff; // FFW 1 fcw1 = bk.getNextByte() & 0xff; // check for field + // control word + + // check if the first fcw1 is an 0x81 if it is then get + // the next pair for checking + if (fcw1 == 0x81) { + bk.getNextByte(); + fcw1 = bk.getNextByte() & 0xff; // check for field + // control word + } + + if (!isAttribute(fcw1)) { + fcw2 = bk.getNextByte() & 0xff; // FCW 2 + attr = bk.getNextByte() & 0xff; // attribute field + + while (!isAttribute(attr)) { + Log.i(TAG, Integer.toHexString(fcw1) + " " + + Integer.toHexString(fcw2) + + " "); + Log.i(TAG, Integer.toHexString(attr) + + " " + + Integer.toHexString(bk + .getNextByte() & 0xff)); + attr = bk.getNextByte() & 0xff; // attribute field + } + } + else { + attr = fcw1; // attribute of field + fcw1 = 0; + } } - - if (!isAttribute(fcw1)) { - - fcw2 = bk.getNextByte() & 0xff; // FCW 2 - attr = bk.getNextByte() & 0xff; // attribute field - - while (!isAttribute(attr)) { - Log.i(TAG,Integer.toHexString(fcw1) + " " - + Integer.toHexString(fcw2) - + " "); - Log.i(TAG,Integer.toHexString(attr) - + " " - + Integer.toHexString(bk - .getNextByte() & 0xff)); - attr = bk.getNextByte() & 0xff; // attribute field - } - } else { - attr = fcw1; // attribute of field - fcw1 = 0; + else { + attr = ffw0; } - } else { - attr = ffw0; - } - - int fLength = (bk.getNextByte() & 0xff) << 8 - | bk.getNextByte() & 0xff; - screen52.addField(attr, fLength, ffw0, ffw1, fcw1, fcw2); - - break; + + int fLength = (bk.getNextByte() & 0xff) << 8 + | bk.getNextByte() & 0xff; + screen52.addField(attr, fLength, ffw0, ffw1, fcw1, fcw2); + break; + // WVL - LDC : 05/08/2005 : TFX.006253 - Support STRPCCMD - case -128: //STRPCCMD - // if (screen52.getCurrentPos() == 82) { - Log.d(TAG,"STRPCCMD got a -128 command at " + screen52.getCurrentPos()); - StringBuffer value = new StringBuffer(); - int b; - char c; - int[] pco = new int[9]; - int[] pcoOk = {0xfc, 0xd7, 0xc3, 0xd6, 0x40, 0x83, 0x80, 0xa1, 0x80}; - - for (int i = 0; i < 9; i++) - { - b = bk.getNextByte(); - pco[i] = ((b & 0xff)); - c = codePage.ebcdic2uni(b); - value.append(c); - } - - // Check "PCO-String" - if (Arrays.equals(pco, pcoOk)) { - strpccmd = true; - } - // we return in the stream to have all chars - // arrive at the screen for later processing - for (int i = 0; i < 9; i++) - bk.setPrevByte(); + case -128: //STRPCCMD + // if (screen52.getCurrentPos() == 82) { + Log.d(TAG, "STRPCCMD got a -128 command at " + screen52.getCurrentPos()); + StringBuffer value = new StringBuffer(); + int b; + char c; + int[] pco = new int[9]; + int[] pcoOk = {0xfc, 0xd7, 0xc3, 0xd6, 0x40, 0x83, 0x80, 0xa1, 0x80}; + + for (int i = 0; i < 9; i++) { + b = bk.getNextByte(); + pco[i] = ((b & 0xff)); + c = codePage.ebcdic2uni(b); + value.append(c); + } + + // Check "PCO-String" + if (Arrays.equals(pco, pcoOk)) { + strpccmd = true; + } + + // we return in the stream to have all chars + // arrive at the screen for later processing + for (int i = 0; i < 9; i++) + bk.setPrevByte(); + //} // no break: so every chars arrives // on the screen for later parsing //break; - default: // all others must be output to screen - //Log.d(TAG,"all others must be output to screen"); - byte byte0 = bk.getByteOffset(-1); - if (isAttribute(byte0)) { - screen52.setAttr(byte0); - } else { - if (!screen52.isStatusErrorCode()) { - if (!isDataEBCDIC(byte0)) { - // if (byte0 == 255) { - // sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x42, - // " Attempt to send FF to screen"); - // } - // else - - screen52.setChar(byte0); - } else - //LDC - 13/02/2003 - Convert it to unicode - //screen52.setChar(getASCIIChar(byte0)); - screen52.setChar(codePage.ebcdic2uni(byte0)); - } else { - if (byte0 == 0) - screen52.setChar(byte0); - else - //LDC - 13/02/2003 - Convert it to unicode - //screen52.setChar(getASCIIChar(byte0)); - screen52.setChar(codePage.ebcdic2uni(byte0)); + default: // all others must be output to screen + //Log.d(TAG,"all others must be output to screen"); + byte byte0 = bk.getByteOffset(-1); + + if (isAttribute(byte0)) { + screen52.setAttr(byte0); } - } - - break; + else { + if (!screen52.isStatusErrorCode()) { + if (!isDataEBCDIC(byte0)) { + // if (byte0 == 255) { + // sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x42, + // " Attempt to send FF to screen"); + // } + // else + screen52.setChar(byte0); + } + else + //LDC - 13/02/2003 - Convert it to unicode + //screen52.setChar(getASCIIChar(byte0)); + screen52.setChar(codePage.ebcdic2uni(byte0)); + } + else { + if (byte0 == 0) + screen52.setChar(byte0); + else + //LDC - 13/02/2003 - Convert it to unicode + //screen52.setChar(getASCIIChar(byte0)); + screen52.setChar(codePage.ebcdic2uni(byte0)); + } + } + + break; } if (error) done = true; } } - catch (Exception e) { - Log.w(TAG,"write to display " + e.getMessage()); + Log.w(TAG, "write to display " + e.getMessage()); e.printStackTrace(); } + ; processCC1(control1); return error; - } private boolean processSOH() throws Exception { - int l = bk.getNextByte(); // length - Log.d(TAG," byte 0 " + l); + Log.d(TAG, " byte 0 " + l); if (l > 0 && l <= 7) { bk.getNextByte(); // flag byte 2 bk.getNextByte(); // reserved bk.getNextByte(); // resequence fields - screen52.clearTable(); // well that is the first time I have seen this. This fixes a @@ -1982,8 +2009,8 @@ if (l <= 3) return false; screen52.setErrorLine(bk.getNextByte()); // error row - int byte1 = 0; + if (l >= 5) { byte1 = bk.getNextByte(); dataIncluded[23] = (byte1 & 0x80) == 0x80; @@ -2019,17 +2046,18 @@ dataIncluded[1] = (byte1 & 0x2) == 0x2; dataIncluded[0] = (byte1 & 0x1) == 0x1; } + return false; - } else { + } + else { sendNegResponse(NR_REQUEST_ERROR, 0x05, 0x01, 0x2B, - "invalid SOH length"); + "invalid SOH length"); return true; } - } private void processCC0(byte byte0) { - Log.d(TAG," Control byte0 " + Integer.toBinaryString(byte0 & 0xff)); + Log.d(TAG, " Control byte0 " + Integer.toBinaryString(byte0 & 0xff)); boolean lockKeyboard = true; boolean resetMDT = false; boolean resetMDTAll = false; @@ -2051,42 +2079,45 @@ // '11100000' = 0xE0 /224 switch (byte0 & 0xE0) { - - case 0x40: - resetMDT = true; - break; - case 0x60: - resetMDTAll = true; - break; - case 0x80: - nullMDT = true; - break; - case 0xA0: - resetMDT = true; - nullAll = true; - break; - case 0xC0: - resetMDT = true; - nullMDT = true; - break; - - case 0xE0: - resetMDTAll = true; - nullAll = true; - break; - + case 0x40: + resetMDT = true; + break; + + case 0x60: + resetMDTAll = true; + break; + + case 0x80: + nullMDT = true; + break; + + case 0xA0: + resetMDT = true; + nullAll = true; + break; + + case 0xC0: + resetMDT = true; + nullMDT = true; + break; + + case 0xE0: + resetMDTAll = true; + nullAll = true; + break; } if (lockKeyboard) { screen52.getOIA().setKeyBoardLocked(true); pendingUnlock = false; - } else + } + else pendingUnlock = false; if (resetMDT || resetMDTAll || nullMDT || nullAll) { ScreenField sf; - int f = screen52.getScreenFields().getSize(); + for (int x = 0; x < f; x++) { sf = screen52.getScreenFields().getField(x); @@ -2096,24 +2127,26 @@ screen52.drawField(sf); } } + if (resetMDTAll || (resetMDT && !sf.isBypassField())) sf.resetMDT(); - } + sf = null; } - } private void processCC1(byte byte1) { - Log.d(TAG," Control byte1 " + Integer.toBinaryString(byte1 & 0xff)); + Log.d(TAG, " Control byte1 " + Integer.toBinaryString(byte1 & 0xff)); if ((byte1 & 0x04) == 0x04) { manager.playBeep(); } + if ((byte1 & 0x02) == 0x02) { screen52.getOIA().setMessageLightOff(); } + if ((byte1 & 0x01) == 0x01) { screen52.getOIA().setMessageLightOn(); } @@ -2133,15 +2166,15 @@ // this seems to work so far if ((byte1 & 0x20) == 0x20 && (byte1 & 0x08) == 0x00) { screen52.setPendingInsert(false); - Log.d(TAG," WTD position no move"); - } else { - + Log.d(TAG, " WTD position no move"); + } + else { screen52.setPendingInsert(true); - Log.d(TAG," WTD position move to home" + screen52.homePos + " row " - + screen52.getRow(screen52.homePos) + " col " - + screen52.getCol(screen52.homePos)); - + Log.d(TAG, " WTD position move to home" + screen52.homePos + " row " + + screen52.getRow(screen52.homePos) + " col " + + screen52.getCol(screen52.homePos)); } + // in enhanced mode we sometimes only receive bit 6 turned on which // is reset blinking cursor if ((byte1 & 0x20) == 0x20 && enhanced) { @@ -2149,7 +2182,6 @@ } if (!screen52.isStatusErrorCode() && (byte1 & 0x08) == 0x08) { - // screen52.setStatus(screen52.STATUS_SYSTEM,screen52.STATUS_VALUE_OFF,null); cursorOn = true; } @@ -2157,7 +2189,6 @@ if ((byte1 & 0x20) == 0x20 && (byte1 & 0x08) == 0x00) { screen52.setPendingInsert(false, 1, 1); } - } private boolean isAttribute(int byte0) { @@ -2168,13 +2199,12 @@ //LDC - 12/02/2003 - Function name changed from isData to isDataEBCDIC private boolean isDataEBCDIC(int byte0) { int byte1 = byte0 & 0xff; + // here it should always be less than 255 if (byte1 >= 64 && byte1 < 255) - return true; else return false; - } //LDC - 12/02/2003 - Test if the unicode character is a displayable @@ -2187,45 +2217,47 @@ } private void writeStructuredField() { - boolean done = false; + try { int length = ((bk.getNextByte() & 0xff) << 8 | (bk.getNextByte() & 0xff)); + while (bk.hasNext() && !done) { switch (bk.getNextByte()) { - - case -39: // SOH - Start of Header Order - - switch (bk.getNextByte()) { - case 112: // 5250 Query - bk.getNextByte(); // get null required field - sendQueryResponse(); + case -39: // SOH - Start of Header Order + switch (bk.getNextByte()) { + case 112: // 5250 Query + bk.getNextByte(); // get null required field + sendQueryResponse(); + break; + + default: + Log.d(TAG, "invalid structured field sub command " + + bk.getByteOffset(-1)); + break; + } + break; + default: - Log.d(TAG,"invalid structured field sub command " - + bk.getByteOffset(-1)); + Log.d(TAG, "invalid structured field command " + + bk.getByteOffset(-1)); break; - } - break; - default: - Log.d(TAG,"invalid structured field command " - + bk.getByteOffset(-1)); - break; } } - } catch (Exception e) { + } + catch (Exception e) { } + ; - } private final void writeErrorCode() throws Exception { screen52.setCursor(screen52.getErrorLine(), 1); // Skip the control byte screen52.setStatus(Screen5250.STATUS_ERROR_CODE, - Screen5250.STATUS_VALUE_ON, null); + Screen5250.STATUS_VALUE_ON, null); screen52.saveErrorLine(); cursorOn = true; - } private final void writeErrorCodeToWindow() throws Exception { @@ -2234,10 +2266,9 @@ screen52.setCursor(screen52.getErrorLine(), fromCol); // Skip the control // byte screen52.setStatus(Screen5250.STATUS_ERROR_CODE, - Screen5250.STATUS_VALUE_ON, null); + Screen5250.STATUS_VALUE_ON, null); screen52.saveErrorLine(); cursorOn = true; - } /** @@ -2255,16 +2286,17 @@ * @throws IOException */ private final void sendQueryResponse() throws IOException { - - Log.i(TAG,"sending query response"); + Log.i(TAG, "sending query response"); byte abyte0[] = new byte[64]; abyte0[0] = 0; // Cursor Row/column (set to zero) abyte0[1] = 0; // "" abyte0[2] = -120; // X'88' inbound write structure Field aid + if (enhanced == true) { abyte0[3] = 0; // 0x003D (61) length of query response abyte0[4] = 64; // "" see note below ????????? - } else { + } + else { abyte0[3] = 0; // 0x003A (58) length of query response abyte0[4] = 58; // "" // the length between 58 and 64 seems to cause @@ -2273,6 +2305,7 @@ // Well the why can be found in the manual if // read a little more ;-) } + abyte0[5] = -39; // command class 0xD9 abyte0[6] = 112; // Command type query 0x70 abyte0[7] = -128; // 0x80 Flag byte @@ -2281,7 +2314,6 @@ abyte0[10] = 1; // Controller Code Level abyte0[11] = 1; // Version 1 Rel 1.0 abyte0[12] = 0; // "" - abyte0[13] = 0; // 13 - 28 are reserved so set to 0x00 abyte0[14] = 0; // "" abyte0[15] = 0; // "" @@ -2306,16 +2338,13 @@ abyte0[34] = codePage.uni2ebcdic('0'); // "" abyte0[35] = codePage.uni2ebcdic('1'); // "" abyte0[36] = codePage.uni2ebcdic('1'); // "" - abyte0[37] = 2; // Keyboard Id - 0x02 Standard Keyboard abyte0[38] = 0; // extended keyboard id abyte0[39] = 0; // reserved - abyte0[40] = 0; // 40 - 43 Display Serial Number abyte0[41] = 36; // abyte0[42] = 36; // abyte0[43] = 0; // - abyte0[44] = 1; // Maximum number of display fields - 256 abyte0[45] = 0; // 0x0100 abyte0[46] = 0; // 46 -48 Reserved set to 0x00 @@ -2335,8 +2364,9 @@ // abyte0[53] = 0x5E; // 0x5E turns on ehnhanced mode // abyte0[53] = 0x27; // 0x5E turns on ehnhanced mode abyte0[53] = 0x7; // 0x5E turns on ehnhanced mode - Log.i(TAG,"enhanced options"); - } else + Log.i(TAG, "enhanced options"); + } + else abyte0[53] = 0x0; // 0x0 is normal emulation abyte0[54] = 24; // 54 - 60 Reserved set to 0x00 @@ -2358,146 +2388,137 @@ abyte0[63] = 0; writeGDS(0, 0, abyte0); // now tell them about us abyte0 = null; - } protected final boolean negotiate(byte abyte0[]) throws IOException { int i = 0; - // from server negotiations - if(abyte0[i] == IAC) { // -1 - - while(i < abyte0.length && abyte0[i++] == -1) + if (abyte0[i] == IAC) { // -1 + while (i < abyte0.length && abyte0[i++] == -1) + // while(i < abyte0.length && (abyte0[i] == -1 || abyte0[i++] == 0x20)) - switch(abyte0[i++]) { - - // we will not worry about what it WONT do - case WONT: // -4 - default: - break; - - case DO: //-3 - - // not sure why but since moving to V5R2 we are receiving a - // DO with no option when connecting a second session with - // device name. Can not find the cause at all. If anybody - // is interested please debug this until then this works. - if (i < abyte0.length) { - switch(abyte0[i]) { - case TERMINAL_TYPE: // 24 + switch (abyte0[i++]) { + // we will not worry about what it WONT do + case WONT: // -4 + default: + break; + + case DO: //-3 + + // not sure why but since moving to V5R2 we are receiving a + // DO with no option when connecting a second session with + // device name. Can not find the cause at all. If anybody + // is interested please debug this until then this works. + if (i < abyte0.length) { + switch (abyte0[i]) { + case TERMINAL_TYPE: // 24 + baosp.write(IAC); + baosp.write(WILL); + baosp.write(TERMINAL_TYPE); + writeByte(baosp.toByteArray()); + baosp.reset(); + break; + + case OPT_END_OF_RECORD: // 25 + baosp.write(IAC); + baosp.write(WILL); + baosp.write(OPT_END_OF_RECORD); + writeByte(baosp.toByteArray()); + baosp.reset(); + break; + + case TRANSMIT_BINARY: // 0 + baosp.write(IAC); + baosp.write(WILL); + baosp.write(TRANSMIT_BINARY); + writeByte(baosp.toByteArray()); + baosp.reset(); + break; + + case TIMING_MARK: // 6 rfc860 + // System.out.println("Timing Mark Received and notifying " + + // "the server that we will not do it"); + baosp.write(IAC); + baosp.write(WONT); + baosp.write(TIMING_MARK); + writeByte(baosp.toByteArray()); + baosp.reset(); + break; + + case NEW_ENVIRONMENT: // 39 rfc1572, rfc4777 + // allways send new environment vars ... + baosp.write(IAC); + baosp.write(WILL); + baosp.write(NEW_ENVIRONMENT); + writeByte(baosp.toByteArray()); + baosp.reset(); + break; + + default: // every thing else we will not do at this time + baosp.write(IAC); + baosp.write(WONT); + baosp.write(abyte0[i]); // either + writeByte(baosp.toByteArray()); + baosp.reset(); + break; + } + } + + i++; + break; + + case WILL: + switch (abyte0[i]) { + case OPT_END_OF_RECORD: // 25 + baosp.write(IAC); + baosp.write(DO); + baosp.write(OPT_END_OF_RECORD); + writeByte(baosp.toByteArray()); + baosp.reset(); + break; + + case TRANSMIT_BINARY: // '\0' + baosp.write(IAC); + baosp.write(DO); + baosp.write(TRANSMIT_BINARY); + writeByte(baosp.toByteArray()); + baosp.reset(); + break; + } + + i++; + break; + + case SB: // -6 + if (abyte0[i] == NEW_ENVIRONMENT && abyte0[i + 1] == 1) { + negNewEnvironment(); + + while (++i < abyte0.length && abyte0[i + 1] != IAC); + } + + if (abyte0[i] == TERMINAL_TYPE && abyte0[i + 1] == 1) { baosp.write(IAC); - baosp.write(WILL); + baosp.write(SB); baosp.write(TERMINAL_TYPE); - writeByte(baosp.toByteArray()); - baosp.reset(); - - break; - - case OPT_END_OF_RECORD: // 25 + baosp.write(QUAL_IS); + + if (!support132) + baosp.write("IBM-3179-2".getBytes()); + else + baosp.write("IBM-3477-FC".getBytes()); baosp.write(IAC); - baosp.write(WILL); - baosp.write(OPT_END_OF_RECORD); - writeByte(baosp.toByteArray()); - baosp.reset(); - break; - - case TRANSMIT_BINARY: // 0 - - baosp.write(IAC); - baosp.write(WILL); - baosp.write(TRANSMIT_BINARY); - writeByte(baosp.toByteArray()); - baosp.reset(); - - break; - - case TIMING_MARK: // 6 rfc860 - // System.out.println("Timing Mark Received and notifying " + - // "the server that we will not do it"); - baosp.write(IAC); - baosp.write(WONT); - baosp.write(TIMING_MARK); - writeByte(baosp.toByteArray()); - baosp.reset(); - - break; - - case NEW_ENVIRONMENT: // 39 rfc1572, rfc4777 - // allways send new environment vars ... - baosp.write(IAC); - baosp.write(WILL); - baosp.write(NEW_ENVIRONMENT); + baosp.write(SE); writeByte(baosp.toByteArray()); baosp.reset(); - break; - - default: // every thing else we will not do at this time - baosp.write(IAC); - baosp.write(WONT); - baosp.write(abyte0[i]); // either - writeByte(baosp.toByteArray()); - baosp.reset(); - - break; + i++; } - } - - i++; - break; - - case WILL: - - switch(abyte0[i]) { - case OPT_END_OF_RECORD: // 25 - baosp.write(IAC); - baosp.write(DO); - baosp.write(OPT_END_OF_RECORD); - writeByte(baosp.toByteArray()); - baosp.reset(); - - break; - - case TRANSMIT_BINARY: // '\0' - baosp.write(IAC); - baosp.write(DO); - baosp.write(TRANSMIT_BINARY); - writeByte(baosp.toByteArray()); - baosp.reset(); - - break; - } - i++; - break; - - case SB: // -6 - - if(abyte0[i] == NEW_ENVIRONMENT && abyte0[i + 1] == 1) { - negNewEnvironment(); - - while (++i < abyte0.length && abyte0[i + 1] != IAC); - } - - if(abyte0[i] == TERMINAL_TYPE && abyte0[i + 1] == 1) { - baosp.write(IAC); - baosp.write(SB); - baosp.write(TERMINAL_TYPE); - baosp.write(QUAL_IS); - if(!support132) - baosp.write("IBM-3179-2".getBytes()); - else - baosp.write("IBM-3477-FC".getBytes()); - baosp.write(IAC); - baosp.write(SE); - writeByte(baosp.toByteArray()); - baosp.reset(); i++; - } - i++; - break; + break; } + return true; } else { @@ -2511,7 +2532,6 @@ * @throws IOException */ private void negNewEnvironment() throws IOException { - baosp.write(IAC); baosp.write(SB); baosp.write(NEW_ENVIRONMENT); @@ -2524,12 +2544,10 @@ baosp.write("KBDTYPE".getBytes()); baosp.write(VALUE); baosp.write(kbdTypesCodePage.kbdType.getBytes()); - baosp.write(USERVAR); baosp.write("CODEPAGE".getBytes()); baosp.write(VALUE); baosp.write(kbdTypesCodePage.codepage.getBytes()); - baosp.write(USERVAR); baosp.write("CHARSET".getBytes()); baosp.write(VALUE); @@ -2538,16 +2556,12 @@ if (devName != null) { baosp.write(USERVAR); - baosp.write("DEVNAME".getBytes()); - baosp.write(VALUE); - baosp.write(negDeviceName().getBytes()); } if (user != null) { - baosp.write(VAR); baosp.write("USER".getBytes()); baosp.write(VALUE); @@ -2593,12 +2607,11 @@ baosp.write(program.getBytes()); } } + baosp.write(IAC); baosp.write(SE); - writeByte(baosp.toByteArray()); baosp.reset(); - } /** @@ -2610,20 +2623,20 @@ * @return String */ private String negDeviceName() { - if (devSeq++ == -1) { devNameUsed = devName; return devName; - } else { + } + else { StringBuffer sb = new StringBuffer(devName + devSeq); int ei = 1; + while (sb.length() > 10) { - sb.setLength(0); sb.append(devName.substring(0, devName.length() - ei++)); sb.append(devSeq); - } + devNameUsed = sb.toString(); return devNameUsed; } @@ -2632,13 +2645,15 @@ public final void setCodePage(String cp) { codePage = CharMappings.getCodePage(cp); cp = cp.toLowerCase(); + for (KbdTypesCodePages kbdtyp : KbdTypesCodePages.values()) { - if (("cp"+kbdtyp.codepage).equals(cp) || kbdtyp.ccsid.equals(cp)) { + if (("cp" + kbdtyp.codepage).equals(cp) || kbdtyp.ccsid.equals(cp)) { kbdTypesCodePage = kbdtyp; break; } } - Log.i(TAG,"Chose keyboard mapping " + kbdTypesCodePage.toString() + " for code page " + cp); + + Log.i(TAG, "Chose keyboard mapping " + kbdTypesCodePage.toString() + " for code page " + cp); } public final ICodePage getCodePage() {