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