RS232CTerminal.java
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13: package xeij;
14:
15: import java.awt.datatransfer.*;
16: import java.awt.event.*;
17: import java.io.*;
18: import java.net.*;
19: import java.nio.*;
20: import java.nio.channels.*;
21: import java.nio.charset.*;
22: import java.util.*;
23: import java.util.concurrent.*;
24: import java.util.zip.*;
25: import javax.swing.*;
26: import javax.swing.event.*;
27:
28: import com.fazecast.jSerialComm.*;
29:
30: public class RS232CTerminal {
31:
32: public static final int TRM_MAX_OUTPUT_LENGTH = 1024 * 256;
33: public static final int TRM_CUT_OUTPUT_LENGTH = TRM_MAX_OUTPUT_LENGTH + 1024 * 16;
34:
35:
36: public static JFrame trmFrame;
37: public static ScrollTextArea trmBoard;
38: public static JPopupMenu trmPopupMenu;
39: public static JMenuItem trmPopupCutMenuItem;
40: public static JMenuItem trmPopupCopyMenuItem;
41: public static JMenuItem trmPopupPasteMenuItem;
42: public static JMenuItem trmPopupSelectAllMenuItem;
43: public static JMenuItem trmPopupSendCtrlCMenuItem;
44: public static StringBuilder trmOutputBuilder;
45: public static int trmOutputEnd;
46: public static int trmOutputSJIS1;
47:
48:
49: public static SerialPort[] trmPortArray;
50: public static int trmNumberOfPorts;
51:
52: public static int trmTcpipRow;
53:
54: public static int trmPppRow;
55:
56:
57:
58:
59:
60:
61:
62: public static int trmRows;
63: public static String[] trmRowName;
64: public static int[] trmRowToCol;
65:
66: public static int trmNumberOfAUXs;
67:
68:
69: public static int trmCols;
70: public static String[] trmColName;
71: public static int[] trmColToRow;
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102: static class Connection implements SerialPortDataListener {
103: int row;
104: int col;
105: int index;
106: String text;
107: boolean connected;
108: JCheckBox checkBox;
109: Box box;
110:
111:
112: ByteQueue row2colQueue;
113: ByteQueue col2rowQueue;
114: boolean row2colReset;
115: boolean col2rowReset;
116:
117:
118: boolean cts;
119: boolean dcd;
120: boolean dsr;
121: boolean ri;
122:
123:
124: @Override public int getListeningEvents () {
125: return (SerialPort.LISTENING_EVENT_DATA_AVAILABLE |
126:
127: SerialPort.LISTENING_EVENT_CARRIER_DETECT |
128: SerialPort.LISTENING_EVENT_DSR |
129: SerialPort.LISTENING_EVENT_RING_INDICATOR);
130: }
131: @Override public void serialEvent (SerialPortEvent spe) {
132: SerialPort port = spe.getSerialPort ();
133: int type = spe.getEventType ();
134: if ((type & SerialPort.LISTENING_EVENT_DATA_AVAILABLE) != 0) {
135: for (;;) {
136: int k = Math.min (port.bytesAvailable (),
137: row2colQueue.unused ());
138: if (k == 0) {
139: break;
140: }
141: byte[] b = new byte[k];
142: port.readBytes (b, k);
143: row2colQueue.write (b, 0, k);
144: }
145: }
146:
147:
148:
149:
150: if ((type & SerialPort.LISTENING_EVENT_CARRIER_DETECT) != 0) {
151: dcd = port.getDCD ();
152: }
153: if ((type & SerialPort.LISTENING_EVENT_DSR) != 0) {
154: dsr = port.getDSR ();
155: }
156: if ((type & SerialPort.LISTENING_EVENT_RING_INDICATOR) != 0) {
157: ri = port.getRI ();
158: }
159: }
160:
161:
162: boolean polling;
163: Thread row2colThread;
164: Thread col2rowThread;
165:
166:
167: class TerminalThread extends Thread {
168: @Override public void run () {
169: ByteQueue queue = (col == 0 ? row2colQueue : col2rowQueue);
170: while (polling) {
171: if (col == 0 ? row2colReset : col2rowReset) {
172: if (col == 0) {
173: row2colReset = false;
174: } else {
175: col2rowReset = false;
176: }
177: queue.clear ();
178: } else {
179: for (int k = queue.used (); k != 0; k = queue.used ()) {
180: byte[] b = new byte[k];
181: queue.read (b, 0, k);
182: for (int i = 0; i < k; i++) {
183: trmPrintSJIS (b[i] & 0xff);
184: }
185: }
186: }
187: try {
188: Thread.sleep (100);
189: } catch (InterruptedException ie) {
190: }
191: }
192: }
193: }
194:
195:
196: class SerialPortThread extends Thread {
197: @Override public void run () {
198: SerialPort port = trmPortArray[row - 1];
199: ByteQueue queue = col2rowQueue;
200: while (polling) {
201: if (col2rowReset) {
202: col2rowReset = false;
203: queue.clear ();
204: port.flushIOBuffers ();
205: } else {
206: for (int k = queue.used (); k != 0; k = queue.used ()) {
207: byte[] b = new byte[k];
208: queue.read (b, 0, k);
209: port.writeBytes (b, k);
210: }
211: }
212: try {
213: Thread.sleep (10);
214: } catch (InterruptedException ie) {
215: }
216: }
217: }
218: }
219:
220:
221: class TCPIPThread extends Thread {
222: @Override public void run () {
223: ByteQueue queue = col2rowQueue;
224: while (polling) {
225: if (col2rowReset) {
226: col2rowReset = false;
227: queue.clear ();
228: } else {
229: for (int k = queue.used (); k != 0; k = queue.used ()) {
230: byte[] b = new byte[k];
231: queue.read (b, 0, k);
232: trmTcpipWrite (b, 0, k);
233: }
234: }
235: try {
236: Thread.sleep (10);
237: } catch (InterruptedException ie) {
238: }
239: }
240: }
241: }
242:
243:
244: class PPPThread extends Thread {
245: @Override public void run () {
246: ByteQueue queue = col2rowQueue;
247: try {
248: while (polling) {
249: if (col2rowReset) {
250: col2rowReset = false;
251: queue.clear ();
252: } else {
253: for (int k = queue.used (); k != 0; k = queue.used ()) {
254: byte[] b = new byte[k];
255: queue.read (b, 0, k);
256: int i = 0;
257: while (trmPppModemLayer && i < k) {
258: int c = b[i++] & 0xff;
259: if (c != '\r') {
260: trmPppModemCommand.append ((char) c);
261: } else {
262: String s = trmPppModemCommand.toString ();
263: trmPppModemCommand.delete (0, trmPppModemCommand.length ());
264: byte[] bb;
265: if (false) {
266: bb = "NO CARRIER\r\n".getBytes ();
267: } else if (s.startsWith ("ATDT")) {
268: bb = "CONNECT\r\n".getBytes ();
269: trmPppModemLayer = false;
270: if (trmPppDebug) {
271: System.out.println ("modem layer ended");
272: }
273: } else if (s.startsWith ("AT")) {
274: bb = "OK\r\n".getBytes ();
275: } else {
276: bb = "ERROR\r\n".getBytes ();
277: }
278: row2colQueue.write (bb, 0, bb.length);
279: }
280: }
281: if (i < k) {
282: if (trmPppDebug) {
283: System.out.print ("pppd stdin");
284: for (int j = i; j < k; j++) {
285: System.out.printf (" %02X", b[j] & 0xff);
286: }
287: System.out.println ();
288: }
289: trmPppStdinStream.write (b, i, k - i);
290: trmPppStdinStream.flush ();
291: }
292: }
293: }
294: try {
295: Thread.sleep (10);
296: } catch (InterruptedException ie) {
297: }
298: }
299: } catch (IOException ioe) {
300: }
301: }
302: }
303:
304: }
305:
306:
307:
308:
309:
310:
311:
312: public static final String TRM_TCPIP_DEFAULT_HOST = "0.0.0.0";
313: public static final int TRM_TCPIP_DEFAULT_PORT = 54321;
314: public static final boolean TRM_TCPIP_DEFAULT_UTF8 = false;
315: public static String trmTcpipHost;
316: public static int trmTcpipPort;
317: public static boolean trmTcpipUTF8;
318: public static DecimalSpinner trmTcpipSpinner;
319: public static JCheckBox trmTcpipCheckBox;
320: public static ByteBuffer trmTcpipReadBuffer;
321: public static CompletionHandler<Integer, Void> trmTcpipReadHander;
322: public static CompletionHandler<AsynchronousSocketChannel, Void> trmTcpipAcceptHandler;
323: public static ByteQueue trmTcpipReadQueue;
324: public static SocketAddress trmTcpipPortAddress;
325: public static AsynchronousServerSocketChannel trmTcpipPortChannel;
326: public static final int TRM_TCPIP_BUFFER_SIZE = 4096;
327: public static AsynchronousSocketChannel trmTcpipSessionChannel;
328: public static SocketAddress trmTcpipClientAddress;
329: public static int trmTcpipToUTF8Pool;
330: public static int trmTcpipToSJISPool;
331:
332:
333:
334: public static void trmTcpipInit () {
335:
336: trmTcpipHost = Settings.sgsGetString ("tcpiphost", TRM_TCPIP_DEFAULT_HOST);
337: trmTcpipPort = Settings.sgsGetInt ("tcpipport", TRM_TCPIP_DEFAULT_PORT, 0, 65535);
338: trmTcpipUTF8 = Settings.sgsGetOnOff ("tcpiputf8", TRM_TCPIP_DEFAULT_UTF8);
339:
340: trmTcpipSpinner = ComponentFactory.createDecimalSpinner (
341: trmTcpipPort, 0, 65535, 1, 0,
342: new ChangeListener () {
343: @Override public void stateChanged (ChangeEvent ce) {
344: trmTcpipPort = trmTcpipSpinner.getIntValue ();
345: }
346: });
347:
348: trmTcpipCheckBox = ComponentFactory.createCheckBox (
349: trmTcpipUTF8, "UTF-8",
350: new ActionListener () {
351: @Override public void actionPerformed (ActionEvent ae) {
352: trmTcpipUTF8 = trmTcpipCheckBox.isSelected ();
353: }
354: });
355:
356: trmTcpipReadBuffer = ByteBuffer.allocate (TRM_TCPIP_BUFFER_SIZE);
357:
358: trmTcpipReadHander = new CompletionHandler<Integer, Void> () {
359:
360: @Override public void completed (Integer bytesRead, Void a) {
361: int l = (int) bytesRead;
362: if (l == -1) {
363: trmTcpipCloseSession (true);
364: return;
365: }
366: byte[] b = new byte[l];
367: int o = 0;
368: trmTcpipReadBuffer.flip ();
369: trmTcpipReadBuffer.get (b, o, l);
370: if (false) {
371: for (int i = 0; i < l; i++) {
372: System.out.printf ("%02x ", 0xff & b[o + i]);
373: }
374: System.out.println ();
375: }
376: byte[] bb = b;
377: int ll = l;
378: if (trmTcpipUTF8) {
379:
380: int pool = trmTcpipToSJISPool;
381: bb = new byte[2 * l];
382: ll = 0;
383: for (int i = 0; i < l; i++) {
384: int u = (pool << 8) | (0xff & b[o + i]);
385: if ((u & 0xffffffe0) == 0x000000c0 ||
386: (u & 0xfffffff0) == 0x000000e0 ||
387: (u & 0xfffff0c0) == 0x0000e080 ||
388: (u & 0xfffffff8) == 0x000000f0 ||
389: (u & 0xfffff8c0) == 0x0000f080 ||
390: (u & 0xfff8c0c0) == 0x00f08080) {
391: pool = u;
392: continue;
393: }
394: pool = 0;
395: if ((u & 0xffffff80) == 0x00000000) {
396: } else if ((u & 0xffffe0c0) == 0x0000c080) {
397: u = ((u & 0x00001f00) >> 2) | (u & 0x0000003f);
398: } else if ((u & 0xfff0c0c0) == 0x00e08080) {
399: u = ((u & 0x000f0000) >> 4) | ((u & 0x00003f00) >> 2) | (u & 0x0000003f);
400: } else if ((u & 0xf8c0c0c0) == 0xf0808080) {
401: u = ((u & 0x07000000) >> 6) | ((u & 0x003f0000) >> 4) | ((u & 0x00003f00) >> 2) | (u & 0x0000003f);
402: if (0x10ffff < u) {
403: u = '※';
404: } else if (0x00ffff < u) {
405:
406:
407:
408:
409:
410: u = '※';
411: }
412: } else {
413: u = '※';
414: }
415: int s = CharacterCode.chrCharToSJIS[u];
416: if (s == 0 && u != 0) {
417: s = 0x81a6;
418: }
419: if (0x00ff < s) {
420: bb[ll++] = (byte) (s >> 8);
421: }
422: bb[ll++] = (byte) s;
423: }
424: trmTcpipToSJISPool = pool;
425: }
426: trmTcpipReadQueue.write (bb, 0, ll);
427:
428: if (trmTcpipSessionChannel != null) {
429: trmTcpipReadBuffer.clear ();
430: trmTcpipSessionChannel.read (trmTcpipReadBuffer, null, trmTcpipReadHander);
431: }
432: }
433:
434: @Override public void failed (Throwable t, Void a) {
435: String message = t.getMessage ();
436: if (message != null) {
437: System.err.println (message);
438: }
439: trmTcpipCloseSession (true);
440: }
441: };
442:
443: trmTcpipAcceptHandler = new CompletionHandler<AsynchronousSocketChannel, Void> () {
444:
445: @Override public void completed (AsynchronousSocketChannel sessionChannel, Void a) {
446: trmTcpipSessionChannel = sessionChannel;
447:
448: trmTcpipToUTF8Pool = 0;
449: trmTcpipToSJISPool = 0;
450: try {
451: trmTcpipClientAddress = trmTcpipSessionChannel.getRemoteAddress ();
452: } catch (IOException ioe) {
453: ioe.printStackTrace ();
454: }
455: System.out.println (Multilingual.mlnJapanese ?
456: trmTcpipClientAddress + " と接続しました" :
457: trmTcpipClientAddress + " connected");
458:
459: if (trmTcpipSessionChannel != null) {
460: trmTcpipReadBuffer.clear ();
461: trmTcpipSessionChannel.read (trmTcpipReadBuffer, null, trmTcpipReadHander);
462: }
463: }
464:
465: @Override public void failed (Throwable t, Void a) {
466: String message = t.getMessage ();
467: if (message != null) {
468: System.err.println (message);
469: }
470: trmTcpipClosePort ();
471: }
472: };
473: }
474:
475:
476:
477: public static void trmTcpipTini () {
478:
479: Settings.sgsPutString ("tcpiphost", trmTcpipHost);
480: Settings.sgsPutInt ("tcpipport", trmTcpipPort);
481: Settings.sgsPutOnOff ("tcpiputf8", trmTcpipUTF8);
482: }
483:
484:
485:
486:
487: public static boolean trmTcpipOpenPort (ByteQueue readQueue) {
488: trmTcpipReadQueue = readQueue;
489: trmTcpipPortAddress = new InetSocketAddress (trmTcpipHost, trmTcpipPort);
490:
491: try {
492: trmTcpipPortChannel = AsynchronousServerSocketChannel.open ().bind (trmTcpipPortAddress);
493: } catch (IOException ioe) {
494: ioe.printStackTrace ();
495: System.out.println (Multilingual.mlnJapanese ?
496: trmTcpipPortAddress + " を開けません" :
497: trmTcpipPortAddress + " not opened");
498: return false;
499: }
500: System.out.println (Multilingual.mlnJapanese ?
501: trmTcpipPortAddress + " を開きました" :
502: trmTcpipPortAddress + " opened");
503:
504: if (trmTcpipPortChannel != null) {
505: trmTcpipPortChannel.accept (null, trmTcpipAcceptHandler);
506: }
507: return true;
508: }
509:
510:
511:
512: public static void trmTcpipClosePort () {
513: if (trmTcpipPortAddress != null) {
514: System.out.println (Multilingual.mlnJapanese ?
515: trmTcpipPortAddress + " を閉じました" :
516: trmTcpipPortAddress + " closed");
517: trmTcpipPortAddress = null;
518: }
519:
520: if (trmTcpipPortChannel != null &&
521: trmTcpipPortChannel.isOpen ()) {
522: try {
523: trmTcpipPortChannel.close ();
524: } catch (IOException ioe) {
525: ioe.printStackTrace ();
526: }
527: }
528: trmTcpipPortChannel = null;
529:
530: trmTcpipCloseSession (false);
531: }
532:
533:
534:
535:
536:
537:
538: public static void trmTcpipWrite (byte[] b, int o, int l) {
539: if (trmTcpipSessionChannel != null) {
540: byte[] bb = b;
541: int ll = l;
542: if (trmTcpipUTF8) {
543:
544: int pool = trmTcpipToUTF8Pool;
545: bb = new byte[3 * l];
546: ll = 0;
547: for (int i = 0; i < l; i++) {
548: int s = (pool << 8) | (0xff & b[o + i]);
549: if ((0x0080 <= s && s <= 0x009f) || (0x00e0 <= s && s <= 0x00ff)) {
550: pool = s;
551: continue;
552: }
553: pool = 0;
554: int u = CharacterCode.chrSJISToChar[s];
555: if (u == 0 && s != 0) {
556: u = '\ufffd';
557: }
558: if (u <= 0x007f) {
559: bb[ll++] = (byte) u;
560: } else if (u <= 0x07ff) {
561: bb[ll++] = (byte) (0xc0 | (u >> 6));
562: bb[ll++] = (byte) (0x80 | (u & 0x3f));
563: } else {
564: bb[ll++] = (byte) (0xe0 | (u >> 12));
565: bb[ll++] = (byte) (0x80 | ((u >> 6) & 0x3f));
566: bb[ll++] = (byte) (0x80 | (u & 0x3f));
567: }
568: }
569: trmTcpipToUTF8Pool = pool;
570: }
571: ByteBuffer buffer = ByteBuffer.allocate (ll);
572: buffer.put (bb, 0, ll);
573: buffer.flip ();
574: try {
575: trmTcpipSessionChannel.write (buffer).get ();
576: } catch (Throwable t) {
577: String message = t.getMessage ();
578: if (message != null) {
579: System.err.println (message);
580: }
581: trmTcpipCloseSession (true);
582: }
583: }
584: }
585:
586:
587:
588:
589: public static void trmTcpipCloseSession (boolean reconnect) {
590: if (trmTcpipSessionChannel == null) {
591: return;
592: }
593: if (trmTcpipClientAddress != null) {
594: System.out.println (Multilingual.mlnJapanese ?
595: trmTcpipClientAddress + " との接続を閉じました" :
596: trmTcpipClientAddress + " disconnected");
597: trmTcpipClientAddress = null;
598: }
599:
600: try {
601: trmTcpipSessionChannel.close ();
602: } catch (IOException ioe) {
603: ioe.printStackTrace ();
604: }
605: trmTcpipSessionChannel = null;
606: if (reconnect) {
607:
608: if (trmTcpipPortChannel != null) {
609: trmTcpipPortChannel.accept (null, trmTcpipAcceptHandler);
610: }
611: }
612: }
613:
614:
615:
616:
617:
618:
619:
620:
621:
622:
623:
624: public static String trmPppAddress;
625: public static boolean trmPppDebug;
626: public static boolean trmPppDirect;
627: public static boolean trmPppLog;
628: public static boolean trmPppServer;
629:
630: public static boolean trmPppAvailable;
631: public static ByteQueue trmPppReadQueue;
632: public static Process trmPppProcess;
633: public static OutputStream trmPppStdinStream;
634: public static Thread trmPppStdoutGobbler;
635: public static Thread trmPppStderrGobbler;
636: public static boolean trmPppModemLayer;
637: public static StringBuilder trmPppModemCommand;
638:
639:
640:
641: public static void trmPppInit () {
642:
643: trmPppAddress = Settings.sgsGetString ("pppaddress", "192.168.10.1:192.168.10.2");
644: trmPppDebug = Settings.sgsGetOnOff ("pppdebug", false);
645: trmPppDirect = Settings.sgsGetOnOff ("pppdirect", false);
646: trmPppLog = Settings.sgsGetOnOff ("ppplog", false);
647: trmPppServer = Settings.sgsGetOnOff ("pppserver", false);
648:
649: trmPppAvailable = trmPppServer && new File ("/usr/sbin/pppd").exists ();
650: }
651:
652:
653:
654: public static void trmPppTini () {
655:
656: Settings.sgsPutString ("pppaddress", trmPppAddress);
657: Settings.sgsPutOnOff ("pppdebug", trmPppDebug);
658: Settings.sgsPutOnOff ("pppdirect", trmPppDirect);
659: Settings.sgsPutOnOff ("ppplog", trmPppLog);
660: Settings.sgsPutOnOff ("pppserver", trmPppServer);
661: }
662:
663:
664:
665:
666: public static boolean trmPppOpenPort (ByteQueue readQueue) {
667:
668: trmPppReadQueue = readQueue;
669: trmPppProcess = null;
670: trmPppStdinStream = null;
671: trmPppModemLayer = false;
672: if (!trmPppDirect) {
673: trmPppModemLayer = true;
674: if (trmPppDebug) {
675: System.out.println ("modem layer started");
676: }
677: }
678: trmPppModemCommand = new StringBuilder ();
679: try {
680: trmPppProcess = new ProcessBuilder (
681: "sudo", "pppd",
682: trmPppAddress,
683: "asyncmap", "0",
684: "default-asyncmap",
685: "local",
686: "mru", "1500",
687: "mtu", "1500",
688: "noaccomp",
689: "noauth",
690: "nobsdcomp",
691: "noccp",
692: "nodeflate",
693: "nodeflatedraft",
694: "nodetach",
695: "noipv6",
696: "nopcomp",
697: "nopredictor1",
698: "notty",
699: "novj",
700: "novjccomp",
701: "passive",
702: "silent"
703: ).start ();
704: System.out.println ("pppd started");
705: trmPppStdinStream = trmPppProcess.getOutputStream ();
706: } catch (IOException ioe) {
707: ioe.printStackTrace ();
708: return false;
709: }
710:
711: trmPppStdoutGobbler = new Thread (() -> {
712: if (trmPppDebug) {
713: System.out.println ("pppd stdout gobbler started");
714: }
715: try (var is = trmPppProcess.getInputStream ()) {
716: byte[] b = new byte[1024];
717: while (trmPppProcess != null) {
718: int k = is.read (b);
719: if (0 < k) {
720: if (trmPppDebug) {
721: System.out.print ("pppd stdout");
722: for (int i = 0; i < k; i++) {
723: System.out.printf (" %02X", b[i] & 0xff);
724: }
725: System.out.println ();
726: }
727: trmPppReadQueue.write (b, 0, k);
728: }
729: }
730: } catch (IOException ioe) {
731: }
732: if (trmPppDebug) {
733: System.out.println ("pppd stdout gobbler ended");
734: }
735: });
736: trmPppStdoutGobbler.start ();
737:
738: trmPppStderrGobbler = new Thread (() -> {
739: if (trmPppDebug) {
740: System.out.println ("pppd stderr gobbler started");
741: }
742: try (var is = trmPppProcess.getErrorStream ()) {
743: byte[] b = new byte[1024];
744: while (trmPppProcess != null) {
745: int k = is.read (b);
746: if (0 < k && trmPppLog) {
747: System.out.print ("pppd stderr ");
748: for (int i = 0; i < k; i++) {
749: System.out.printf ("%c", b[i] & 0xff);
750: }
751: }
752: }
753: } catch (IOException ioe) {
754: }
755: if (trmPppDebug) {
756: System.out.println ("pppd stderr gobbler ended");
757: }
758: });
759: trmPppStderrGobbler.start ();
760: return true;
761: }
762:
763:
764:
765: public static void trmPppClosePort () {
766:
767: trmPppProcess.destroy ();
768: trmPppProcess = null;
769: System.out.println ("pppd destroyed");
770:
771: try {
772: trmPppStdoutGobbler.join (100L);
773: } catch (InterruptedException ie) {
774: }
775:
776: try {
777: trmPppStderrGobbler.join (100L);
778: } catch (InterruptedException ie) {
779: }
780: }
781:
782:
783:
784:
785:
786:
787:
788:
789:
790:
791:
792:
793:
794:
795:
796: public static boolean trmAUXFlowControlRTS;
797: public static boolean trmAUXFlowControlXON;
798: public static boolean trmAUXNotReceiving;
799:
800:
801: public static int trmAUXDataBuffer;
802: public static boolean trmAUXDataAvailable;
803:
804:
805:
806: public static int trmAUXReadData () {
807: trmAUXDataAvailable = false;
808: return trmAUXDataBuffer;
809: }
810:
811:
812:
813: public static void trmAUXWriteData (int data) {
814: int col = 1;
815: int row = trmColToRow[col];
816: if (row < 0) {
817: return;
818: }
819: data &= 0xff;
820: if (trmAUXFlowControlXON) {
821: if (data == 0x11) {
822: trmAUXNotReceiving = false;
823: return;
824: } else if (data == 0x13) {
825: trmAUXNotReceiving = true;
826: return;
827: }
828: }
829: trmConnectionArray[trmCols * row + col - 1].col2rowQueue.write (data);
830:
831: trmAUXSendEmpty = false;
832: TickerQueue.tkqAdd (trmAUXSendTicker, XEiJ.mpuClockTime + Z8530.scc1aInterval);
833: }
834:
835:
836:
837:
838: public static void trmAUXSetNotReceiving (boolean notReceiving) {
839: trmAUXNotReceiving = notReceiving;
840: }
841:
842:
843:
844: public static boolean trmAUXDTR;
845: public static void trmAUXSetDTR (boolean dtr) {
846: if (trmAUXDTR != dtr) {
847: trmAUXDTR = dtr;
848: if (trmAUXConnection != null) {
849: int row = trmAUXConnection.row;
850: SerialPort port = row < 1 || trmNumberOfPorts < row ? null : trmPortArray[row - 1];
851: if (port != null) {
852: if (dtr) {
853: port.setDTR ();
854: } else {
855: port.clearDTR ();
856: }
857: }
858: }
859: }
860: }
861:
862:
863:
864:
865:
866:
867:
868:
869:
870:
871:
872:
873:
874:
875:
876:
877:
878:
879:
880:
881:
882:
883: public static int trmAUXReadRR0 () {
884: return (trmAUXConnection == null ? 0 :
885: (trmAUXConnection.cts ? 1 << 5 : 0 << 5) |
886: (trmAUXConnection.dsr ? 1 << 3 : 0 << 3) |
887: (trmAUXSendEmpty ? 1 << 2 : 0 << 2) |
888: (trmAUXDataAvailable ? 1 << 0 : 0 << 0));
889: }
890:
891:
892:
893: public static int trmMUSReadRR0 () {
894: return (trmAUXConnection == null ? 0 :
895: (trmAUXConnection.ri ? 1 << 5 : 0 << 5) |
896: (trmAUXConnection.dcd ? 1 << 3 : 0 << 3));
897: }
898:
899:
900:
901:
902:
903:
904:
905:
906:
907:
908:
909: public static boolean trmAUXSendEmpty;
910: public static final TickerQueue.Ticker trmAUXSendTicker = new TickerQueue.Ticker () {
911: @Override protected void tick () {
912: trmAUXSendEmpty = true;
913: if ((Z8530.sccMIE & Z8530.scc1aSendMask) != 0) {
914: Z8530.scc1aSendRR3 = Z8530.SCC_1A_SEND_MASK;
915: Z8530.scc1aSendRequest = Z8530.SCC_1A_SEND_MASK;
916: XEiJ.mpuIRR |= XEiJ.MPU_SCC_INTERRUPT_MASK;
917: }
918: }
919: };
920:
921:
922: public static Connection trmAUXConnection;
923: public static final TickerQueue.Ticker trmAUXTicker = new TickerQueue.Ticker () {
924: @Override protected void tick () {
925: long interval = XEiJ.TMR_FREQ / 1000 * 1;
926: ByteQueue queue = trmAUXConnection.row2colQueue;
927: if (trmAUXConnection.row2colReset) {
928: trmAUXConnection.row2colReset = false;
929: queue.clear ();
930: } else if (!trmAUXNotReceiving &&
931: queue.used () != 0) {
932: trmAUXDataBuffer = queue.read ();
933: trmAUXDataAvailable = true;
934: if ((Z8530.sccMIE & Z8530.scc1aReceiveMask) != 0 &&
935: Z8530.scc1aReceiveRR3 == 0) {
936: Z8530.scc1aReceiveRR3 = Z8530.SCC_1A_RECEIVE_MASK;
937: Z8530.scc1aReceiveRequest = Z8530.SCC_1A_RECEIVE_MASK;
938: XEiJ.mpuIRR |= XEiJ.MPU_SCC_INTERRUPT_MASK;
939: }
940: interval = Z8530.scc1aInterval;
941: }
942: TickerQueue.tkqAdd (trmAUXTicker, XEiJ.mpuClockTime + interval);
943: }
944: };
945:
946: public static int trmRSDRV202Head;
947: public static int trmTMSIO031Head;
948: public static int trmBSIO021Head;
949:
950:
951:
952:
953:
954:
955:
956:
957: public static final TickerQueue.Ticker trmAUXFlowControlTicker = new TickerQueue.Ticker () {
958: @Override protected void tick () {
959: int set232c = MC68060.mmuPeekLongData (0x04c0, 1);
960: int modeAddress = (0x00fc0000 <= set232c && set232c < 0x01000000 ? 0x0926 :
961: set232c == trmRSDRV202Head + 0x03ba ? trmRSDRV202Head + 0x0ab2 :
962: set232c == trmTMSIO031Head + 0x0210 ? trmTMSIO031Head + 0x0a42 :
963: set232c == trmBSIO021Head + 0x013A ? trmBSIO021Head + 0x074a :
964: 0);
965: if (modeAddress == 0) {
966: return;
967: }
968: int mode = MC68060.mmuPeekWordZeroData (modeAddress, 1);
969: if (mode == 0x0000 || mode == 0xffff) {
970: return;
971: }
972: boolean rts = (mode & 0x0080) != 0;
973: boolean xon = !rts && (mode & 0x0200) != 0;
974: if (trmAUXFlowControlRTS == rts &&
975: trmAUXFlowControlXON == xon) {
976: return;
977: }
978: trmAUXFlowControlRTS = rts;
979: trmAUXFlowControlXON = xon;
980: if (false) {
981: System.out.printf ("flowcontrol=%s\n", rts ? "rts" : xon ? "xon" : "none");
982: }
983: int row = trmColToRow[1];
984: SerialPort port = row < 1 || trmNumberOfPorts < row ? null : trmPortArray[row - 1];
985: if (port != null) {
986: port.setFlowControl (rts ? (SerialPort.FLOW_CONTROL_RTS_ENABLED |
987: SerialPort.FLOW_CONTROL_CTS_ENABLED) :
988: xon ? (SerialPort.FLOW_CONTROL_XONXOFF_IN_ENABLED |
989: SerialPort.FLOW_CONTROL_XONXOFF_OUT_ENABLED) :
990: SerialPort.FLOW_CONTROL_DISABLED);
991: }
992: }
993: };
994:
995:
996:
997: public static void trmAUXReset () {
998: if (trmAUXConnection != null) {
999: TickerQueue.tkqRemove (trmAUXFlowControlTicker);
1000:
1001: trmAUXConnection.row2colReset = true;
1002: trmAUXConnection.col2rowReset = true;
1003: }
1004: }
1005:
1006:
1007: public static Connection[] trmConnectionArray;
1008: public static Box trmConnectionBox;
1009: public static ActionListener trmConnectionListener;
1010: public static boolean trmRefreshEnabled;
1011: public static JButton trmRefreshButton;
1012:
1013: public static boolean trmSettingsEnabled;
1014: public static String[] trmBaudRateArray;
1015: public static int trmBaudRateIndex;
1016: public static String[] trmDataBitsArray;
1017: public static int trmDataBitsIndex;
1018: public static String[] trmParityArray;
1019: public static int trmParityIndex;
1020: public static String[] trmStopBitsArray;
1021: public static int trmStopBitsIndex;
1022: public static String[] trmFlowControlArray;
1023: public static int trmFlowControlIndex;
1024: public static JComboBox<String> trmBaudRateComboBox;
1025: public static JComboBox<String> trmDataBitsComboBox;
1026: public static JComboBox<String> trmParityComboBox;
1027: public static JComboBox<String> trmStopBitsComboBox;
1028: public static JComboBox<String> trmFlowControlComboBox;
1029:
1030: public static boolean trmSendEnabled;
1031: public static JButton trmSendButton;
1032: public static JFileChooser trmSendFileChooser;
1033: public static JDialog trmSendDialog;
1034: public static SendThread trmSendThread;
1035:
1036: public static JButton trmSetClockButton;
1037: public static ScheduledExecutorService trmScheduler;
1038:
1039: public static JTextField trmAdditionalTextField;
1040:
1041:
1042:
1043: public static void trmInitConnection () {
1044:
1045: trmBaudRateArray = new String[] { "75", "150", "300", "600", "1200", "2400", "4800", "9600", "19200", "31250", "38400", "50000", "57600", "76800", "115200", "230400" };
1046: trmBaudRateIndex = 10;
1047: trmDataBitsArray = new String[] { "B5", "B6", "B7", "B8" };
1048: trmDataBitsIndex = 3;
1049: trmParityArray = new String[] { "PN", "PO", "PE" };
1050: trmParityIndex = 0;
1051: trmStopBitsArray = new String[] { "S1", "S1.5", "S2" };
1052: trmStopBitsIndex = 0;
1053: trmFlowControlArray = new String[] { "NONE", "XON", "RTS" };
1054: trmFlowControlIndex = 2;
1055: trmBaudRateComboBox = null;
1056: trmDataBitsComboBox = null;
1057: trmParityComboBox = null;
1058: trmStopBitsComboBox = null;
1059: trmFlowControlComboBox = null;
1060:
1061: for (String keyword : Settings.sgsGetString ("terminalsettings").split ("/")) {
1062: for (int i = 0; i < trmBaudRateArray.length; i++) {
1063: if (trmBaudRateArray[i].equals (keyword)) {
1064: trmBaudRateIndex = i;
1065: break;
1066: }
1067: }
1068: for (int i = 0; i < trmDataBitsArray.length; i++) {
1069: if (trmDataBitsArray[i].equals (keyword)) {
1070: trmDataBitsIndex = i;
1071: break;
1072: }
1073: }
1074: for (int i = 0; i < trmParityArray.length; i++) {
1075: if (trmParityArray[i].equals (keyword)) {
1076: trmParityIndex = i;
1077: break;
1078: }
1079: }
1080: for (int i = 0; i < trmStopBitsArray.length; i++) {
1081: if (trmStopBitsArray[i].equals (keyword)) {
1082: trmStopBitsIndex = i;
1083: break;
1084: }
1085: }
1086: for (int i = 0; i < trmFlowControlArray.length; i++) {
1087: if (trmFlowControlArray[i].equals (keyword)) {
1088: trmFlowControlIndex = i;
1089: break;
1090: }
1091: }
1092: }
1093:
1094: trmSendButton = null;
1095: trmSendFileChooser = null;
1096: trmSendDialog = null;
1097: trmSendThread = null;
1098:
1099: trmSetClockButton = null;
1100: trmScheduler = Executors.newSingleThreadScheduledExecutor ();
1101:
1102: trmPortArray = new SerialPort[0];
1103: trmNumberOfPorts = 0;
1104:
1105: trmTcpipRow = -1;
1106:
1107: trmPppRow = -1;
1108:
1109: trmRows = 1;
1110: trmRowName = new String[1];
1111: trmRowName[0] = "Terminal";
1112: trmRowToCol = new int[1];
1113: Arrays.fill (trmRowToCol, -1);
1114:
1115: trmNumberOfAUXs = 0;
1116:
1117: trmCols = 1;
1118: trmColName = new String[1];
1119: trmColName[0] = "Terminal";
1120: trmColToRow = new int[1];
1121: Arrays.fill (trmColToRow, -1);
1122:
1123: {
1124: String text = Settings.sgsGetString ("additionalport");
1125: try {
1126: text = URLDecoder.decode (text, "UTF-8");
1127: } catch (UnsupportedEncodingException uee) {
1128: text = "";
1129: }
1130: trmAdditionalTextField = ComponentFactory.createTextField (text, 15);
1131: }
1132:
1133: trmTcpipInit ();
1134:
1135: trmPppInit ();
1136:
1137: trmConnectionArray = new Connection[0];
1138: trmConnectionBox = ComponentFactory.createVerticalBox (
1139: Box.createVerticalGlue (),
1140: ComponentFactory.createHorizontalBox (
1141: Multilingual.mlnText (
1142: ComponentFactory.createLabel ("Additional port "),
1143: "ja", "追加ポート "
1144: ),
1145: trmAdditionalTextField,
1146: Multilingual.mlnText (
1147: ComponentFactory.createLabel (" TCP/IP port "),
1148: "ja", " TCP/IP ポート "
1149: ),
1150: trmTcpipSpinner,
1151: Box.createHorizontalStrut (5),
1152: trmTcpipCheckBox,
1153: Box.createHorizontalGlue ()
1154: )
1155: );
1156: trmConnectionListener = new ActionListener () {
1157: @Override public void actionPerformed (ActionEvent ae) {
1158: String command = ae.getActionCommand ();
1159: for (Connection connection : trmConnectionArray) {
1160: if (connection.text.equals (command)) {
1161: if (connection.connected) {
1162: trmDisconnect (connection);
1163: } else {
1164: trmConnect (connection);
1165: }
1166: break;
1167: }
1168: }
1169: }
1170: };
1171: trmRefreshEnabled = false;
1172: trmRefreshButton = null;
1173: trmSettingsEnabled = false;
1174: trmSendEnabled = false;
1175:
1176: trmUpdateConnection ();
1177:
1178: HashSet<String> map = new HashSet<String> ();
1179: for (String encodedText : Settings.sgsGetString ("rs232cconnection").split ("/")) {
1180: try {
1181: map.add (URLDecoder.decode (encodedText, "UTF-8"));
1182: } catch (UnsupportedEncodingException uee) {
1183: }
1184: }
1185: for (Connection connection : trmConnectionArray) {
1186: if (map.contains (connection.text)) {
1187: trmConnect (connection);
1188: }
1189: }
1190: }
1191:
1192:
1193:
1194: public static void trmTiniConnection () {
1195:
1196: trmScheduler.shutdownNow ();
1197:
1198: {
1199: StringBuilder sb = new StringBuilder ();
1200: for (Connection connection : trmConnectionArray) {
1201: if (connection.connected) {
1202: if (sb.length () != 0) {
1203: sb.append ('/');
1204: }
1205: try {
1206: sb.append (URLEncoder.encode (connection.text, "UTF-8"));
1207: } catch (UnsupportedEncodingException uee) {
1208: }
1209: }
1210: }
1211: Settings.sgsPutString ("rs232cconnection", sb.toString ());
1212: }
1213:
1214: {
1215: String text = trmAdditionalTextField.getText ();
1216: try {
1217: text = URLEncoder.encode (text, "UTF-8");
1218: } catch (UnsupportedEncodingException uee) {
1219: text = "";
1220: }
1221: Settings.sgsPutString ("additionalport", text);
1222: }
1223:
1224: trmTcpipTini ();
1225:
1226: trmPppTini ();
1227:
1228: {
1229: StringBuilder sb = new StringBuilder ();
1230: sb.append (trmBaudRateArray[trmBaudRateIndex]);
1231: sb.append ('/');
1232: sb.append (trmDataBitsArray[trmDataBitsIndex]);
1233: sb.append ('/');
1234: sb.append (trmParityArray[trmParityIndex]);
1235: sb.append ('/');
1236: sb.append (trmStopBitsArray[trmStopBitsIndex]);
1237: sb.append ('/');
1238: sb.append (trmFlowControlArray[trmFlowControlIndex]);
1239: Settings.sgsPutString ("terminalsettings", sb.toString ());
1240: }
1241:
1242: for (Connection connection : trmConnectionArray) {
1243: trmDisconnect (connection);
1244: }
1245: }
1246:
1247:
1248:
1249: public static boolean trmIsConnectionUpdatable () {
1250: for (Connection connection : trmConnectionArray) {
1251: if (connection.row != 0 &&
1252: connection.connected) {
1253: return false;
1254: }
1255: }
1256: return true;
1257: }
1258:
1259:
1260:
1261: public static void trmUpdateConnection () {
1262:
1263: if (!trmIsConnectionUpdatable ()) {
1264: return;
1265: }
1266:
1267: ArrayList<SerialPort> portList = new ArrayList<SerialPort> ();
1268: try {
1269: for (SerialPort port : SerialPort.getCommPorts ()) {
1270: portList.add (port);
1271: }
1272: } catch (Throwable t) {
1273:
1274: }
1275: for (String descriptor : trmAdditionalTextField.getText ().split (",")) {
1276: descriptor = descriptor.trim ();
1277: if (!descriptor.equals ("")) {
1278: try {
1279: SerialPort port = SerialPort.getCommPort (descriptor);
1280: if (port != null) {
1281: if (false) {
1282: for (SerialPort anotherPort : portList) {
1283: if (port.getDescriptivePortName ().equals (anotherPort.getDescriptivePortName ())) {
1284: port = null;
1285: break;
1286: }
1287: }
1288: }
1289: if (port != null) {
1290: portList.add (port);
1291: }
1292: } else {
1293: System.out.println (descriptor + " not found");
1294: }
1295: } catch (SerialPortInvalidPortException spipe) {
1296: System.out.println (spipe.toString ());
1297: }
1298: }
1299: }
1300: trmNumberOfPorts = portList.size ();
1301: trmPortArray = portList.toArray (new SerialPort[trmNumberOfPorts]);
1302:
1303: trmTcpipRow = (1 +
1304: trmNumberOfPorts);
1305:
1306: if (trmPppAvailable) {
1307: trmPppRow = (1 +
1308: trmNumberOfPorts +
1309: (0 <= trmTcpipRow ? 1 : 0));
1310: } else {
1311: trmPppRow = -1;
1312: }
1313:
1314: trmRows = (1 +
1315: trmNumberOfPorts +
1316: (0 <= trmTcpipRow ? 1 : 0) +
1317: (0 <= trmPppRow ? 1 : 0));
1318: trmRowName = new String[trmRows];
1319:
1320: trmRowName[0] = "Terminal";
1321:
1322: for (int row = 1; row <= trmNumberOfPorts; row++) {
1323: SerialPort port = trmPortArray[row - 1];
1324: trmRowName[row] = port.getSystemPortName () + "(" + port.getPortDescription () + ")";
1325: }
1326:
1327: if (0 <= trmTcpipRow) {
1328: trmRowName[trmTcpipRow] = "TCP/IP";
1329: }
1330:
1331: if (0 <= trmPppRow) {
1332: trmRowName[trmPppRow] = "PPP server";
1333: }
1334: trmRowToCol = new int[trmRows];
1335: Arrays.fill (trmRowToCol, -1);
1336:
1337: trmNumberOfAUXs = 1;
1338:
1339: trmCols = (1 +
1340: trmNumberOfAUXs);
1341: trmColName = new String[trmCols];
1342: trmColName[0] = "Terminal";
1343: for (int col = 1; col < trmCols; col++) {
1344: trmColName[col] = col == 1 ? "AUX" : "AUX" + col;
1345: }
1346: trmColToRow = new int[trmCols];
1347: Arrays.fill (trmColToRow, -1);
1348:
1349: for (int index = trmConnectionArray.length - 1; 0 <= index; index--) {
1350: trmConnectionBox.remove (index);
1351: }
1352: trmConnectionArray = new Connection[trmCols * trmRows - 1];
1353: for (int row = 0; row < trmRows; row++) {
1354: for (int col = 0; col < trmCols; col++) {
1355: if (col == 0 && row == 0) {
1356: continue;
1357: }
1358: Connection connection = new Connection ();
1359: connection.row = row;
1360: connection.col = col;
1361: connection.index = trmCols * row + col - 1;
1362: connection.text = trmRowName[row] + " ⇔ " + trmColName[col];
1363: connection.connected = false;
1364: connection.checkBox =
1365: ComponentFactory.createCheckBox (connection.connected, connection.text, trmConnectionListener);
1366: connection.box =
1367: ComponentFactory.createHorizontalBox (
1368: connection.checkBox,
1369: Box.createHorizontalGlue ());
1370: trmConnectionArray[connection.index] = connection;
1371: trmConnectionBox.add (connection.box, connection.index);
1372: }
1373: }
1374: trmUpdateComponents ();
1375: trmConnectionBox.validate ();
1376: }
1377:
1378:
1379:
1380:
1381:
1382: public static void trmUpdateComponents () {
1383: boolean updatable = true;
1384: boolean configurable = false;
1385: boolean transferable = false;
1386: for (Connection connection : trmConnectionArray) {
1387: if (connection.connected) {
1388: connection.checkBox.setEnabled (true);
1389: if (1 <= connection.row && connection.row <= trmNumberOfPorts) {
1390: updatable = false;
1391: if (connection.col == 0) {
1392: configurable = true;
1393: }
1394: }
1395: if (connection.row == 0 ||
1396: connection.col == 0) {
1397: transferable = true;
1398: }
1399: } else {
1400: connection.checkBox.setEnabled (trmIsConnectable (connection));
1401: }
1402: }
1403: trmRefreshEnabled = updatable;
1404: if (trmRefreshButton != null) {
1405: trmRefreshButton.setEnabled (updatable);
1406: }
1407: trmSettingsEnabled = configurable;
1408: trmSendEnabled = transferable;
1409: if (trmBaudRateComboBox != null) {
1410: trmBaudRateComboBox.setEnabled (configurable);
1411: trmDataBitsComboBox.setEnabled (configurable);
1412: trmParityComboBox.setEnabled (configurable);
1413: trmStopBitsComboBox.setEnabled (configurable);
1414: trmFlowControlComboBox.setEnabled (configurable);
1415: trmSendButton.setEnabled (transferable);
1416: trmSetClockButton.setEnabled (transferable);
1417: }
1418: }
1419:
1420:
1421:
1422: public static boolean trmIsConnectable (Connection connection) {
1423: if (!connection.connected) {
1424: for (Connection connection2 : trmConnectionArray) {
1425: if (connection != connection2 &&
1426: connection2.connected &&
1427: (((connection.row == 0 || connection.col == 0) &&
1428: (connection2.row == 0 || connection2.col == 0)) ||
1429: connection.row == connection2.row ||
1430: connection.col == connection2.col)) {
1431: return false;
1432: }
1433: }
1434: }
1435: return true;
1436: }
1437:
1438:
1439:
1440: public static void trmConnect (Connection connection) {
1441:
1442: if (connection.connected ||
1443: !trmIsConnectable (connection)) {
1444: return;
1445: }
1446:
1447: connection.connected = true;
1448: connection.checkBox.setSelected (true);
1449: trmRowToCol[connection.row] = connection.col;
1450: trmColToRow[connection.col] = connection.row;
1451: trmUpdateComponents ();
1452:
1453: connection.row2colQueue = new ByteQueue ();
1454: connection.col2rowQueue = new ByteQueue ();
1455:
1456: connection.cts = true;
1457: connection.dcd = true;
1458: connection.dsr = false;
1459: connection.ri = false;
1460: if (1 <= connection.row && connection.row <= trmNumberOfPorts) {
1461:
1462: SerialPort port = trmPortArray[connection.row - 1];
1463: port.openPort ();
1464: System.out.println (Multilingual.mlnJapanese ?
1465: connection.text + " を開きました" :
1466: connection.text + " opened");
1467: port.setComPortTimeouts (SerialPort.TIMEOUT_WRITE_BLOCKING | SerialPort.TIMEOUT_READ_BLOCKING, 0, 0);
1468: port.setFlowControl (SerialPort.FLOW_CONTROL_DISABLED);
1469:
1470: trmReflectSettings (connection.col);
1471:
1472: if (trmAUXDTR) {
1473: port.setDTR ();
1474: } else {
1475: port.clearDTR ();
1476: }
1477:
1478:
1479: connection.dcd = port.getDCD ();
1480: connection.dsr = port.getDSR ();
1481: connection.ri = port.getRI ();
1482:
1483: port.addDataListener (connection);
1484: } else if (connection.row == trmTcpipRow) {
1485:
1486: if (!trmTcpipOpenPort (connection.row2colQueue)) {
1487:
1488:
1489: }
1490:
1491:
1492:
1493:
1494:
1495: } else if (connection.row == trmPppRow) {
1496:
1497: if (!trmPppOpenPort (connection.row2colQueue)) {
1498:
1499:
1500: }
1501:
1502:
1503:
1504:
1505:
1506: }
1507:
1508: connection.polling = true;
1509: connection.row2colThread = (connection.col == 0 ? connection.new TerminalThread () :
1510: null);
1511: connection.col2rowThread = (connection.row == 0 ? connection.new TerminalThread () :
1512: connection.row == trmTcpipRow ? connection.new TCPIPThread () :
1513: connection.row == trmPppRow ? connection.new PPPThread () :
1514: connection.new SerialPortThread ());
1515: for (int i = 0; i < 2; i++) {
1516: Thread thread = (i == 0 ? connection.row2colThread : connection.col2rowThread);
1517: if (thread != null) {
1518: thread.start ();
1519: }
1520: }
1521:
1522: if (connection.col == 1) {
1523: trmAUXNotReceiving = false;
1524: trmAUXDataBuffer = 0;
1525: trmAUXDataAvailable = false;
1526: trmAUXConnection = connection;
1527: TickerQueue.tkqAdd (trmAUXTicker, XEiJ.mpuClockTime + XEiJ.TMR_FREQ / 1000 * 1);
1528:
1529: trmAUXSendEmpty = true;
1530: }
1531: }
1532:
1533:
1534:
1535: public static void trmDisconnect (Connection connection) {
1536:
1537: if (!connection.connected) {
1538: return;
1539: }
1540:
1541: connection.connected = false;
1542: connection.checkBox.setSelected (connection.connected);
1543: trmRowToCol[connection.row] = -1;
1544: trmColToRow[connection.col] = -1;
1545: trmUpdateComponents ();
1546:
1547: if (trmAUXConnection != null) {
1548: TickerQueue.tkqRemove (trmAUXTicker);
1549: trmAUXConnection = null;
1550: }
1551:
1552: connection.polling = false;
1553: for (int i = 0; i < 2; i++) {
1554: Thread thread = (i == 0 ? connection.row2colThread : connection.col2rowThread);
1555: if (thread != null) {
1556: connection.row2colThread = null;
1557: if (thread.isAlive ()) {
1558: thread.interrupt ();
1559: try {
1560: thread.join (100L);
1561: } catch (InterruptedException ie) {
1562: }
1563: }
1564: }
1565: }
1566:
1567: if (connection.col == 1) {
1568: TickerQueue.tkqRemove (trmAUXSendTicker);
1569: }
1570:
1571: connection.cts = false;
1572: connection.dcd = false;
1573: connection.dsr = false;
1574: connection.ri = false;
1575: if (1 <= connection.row && connection.row <= trmNumberOfPorts) {
1576: SerialPort port = trmPortArray[connection.row - 1];
1577:
1578: port.removeDataListener ();
1579:
1580: port.closePort ();
1581: System.out.println (Multilingual.mlnJapanese ?
1582: connection.text + " を閉じました" :
1583: connection.text + " closed");
1584: } else if (connection.row == trmTcpipRow) {
1585:
1586: trmTcpipClosePort ();
1587: } else if (connection.row == trmPppRow) {
1588:
1589: trmPppClosePort ();
1590: }
1591:
1592: connection.row2colQueue.clear ();
1593: connection.col2rowQueue.clear ();
1594: connection.row2colQueue = null;
1595: connection.col2rowQueue = null;
1596: }
1597:
1598:
1599:
1600: public static void trmSetBaudRate (int index) {
1601: if (0 <= index && index < trmBaudRateArray.length) {
1602: trmBaudRateIndex = index;
1603: trmReflectSettings (0);
1604: }
1605: }
1606:
1607:
1608:
1609: public static void trmSetDataBits (int index) {
1610: if (0 <= index && index < trmDataBitsArray.length) {
1611: trmDataBitsIndex = index;
1612: trmReflectSettings (0);
1613: }
1614: }
1615:
1616:
1617:
1618: public static void trmSetParity (int index) {
1619: if (0 <= index && index < trmParityArray.length) {
1620: trmParityIndex = index;
1621: trmReflectSettings (0);
1622: }
1623: }
1624:
1625:
1626:
1627: public static void trmSetStopBits (int index) {
1628: if (0 <= index && index < trmStopBitsArray.length) {
1629: trmStopBitsIndex = index;
1630: trmReflectSettings (0);
1631: }
1632: }
1633:
1634:
1635:
1636: public static void trmSetFlowControl (int index) {
1637: if (0 <= index && index < trmFlowControlArray.length) {
1638: trmFlowControlIndex = index;
1639: trmReflectSettings (0);
1640: }
1641: }
1642:
1643:
1644:
1645: public static void trmReflectSettings (int col) {
1646: int row = trmColToRow[col];
1647: SerialPort port = row < 1 || trmNumberOfPorts < row ? null : trmPortArray[row - 1];
1648: if (col == 0) {
1649: String baudRate = trmBaudRateArray[trmBaudRateIndex];
1650: String dataBits = trmDataBitsArray[trmDataBitsIndex];
1651: String stopBits = trmStopBitsArray[trmStopBitsIndex];
1652: String parity = trmParityArray[trmParityIndex];
1653: String flowControl = trmFlowControlArray[trmFlowControlIndex];
1654: if (port != null) {
1655: port.setComPortParameters (Integer.parseInt (baudRate, 10),
1656: Integer.parseInt (dataBits.substring (1), 10),
1657: stopBits.equals ("S1.5") ? SerialPort.ONE_POINT_FIVE_STOP_BITS :
1658: stopBits.equals ("S2") ? SerialPort.TWO_STOP_BITS : SerialPort.ONE_STOP_BIT,
1659: parity.equals ("PO") ? SerialPort.ODD_PARITY :
1660: parity.equals ("PE") ? SerialPort.EVEN_PARITY : SerialPort.NO_PARITY);
1661: port.setFlowControl (flowControl.equals ("RTS") ? (SerialPort.FLOW_CONTROL_RTS_ENABLED |
1662: SerialPort.FLOW_CONTROL_CTS_ENABLED) :
1663: flowControl.equals ("XON") ? (SerialPort.FLOW_CONTROL_XONXOFF_IN_ENABLED |
1664: SerialPort.FLOW_CONTROL_XONXOFF_OUT_ENABLED) :
1665: SerialPort.FLOW_CONTROL_DISABLED);
1666: }
1667: } else if (col == 1) {
1668: double rate = Z8530.sccFreq / (double) ((Z8530.scc1aBaudRateGen + 2) << (Z8530.scc1aClockModeShift + 1));
1669: double bits = (1.0 +
1670: (Z8530.scc1aRxBits == 0 ? 5.0 :
1671: Z8530.scc1aRxBits == 1 ? 7.0 :
1672: Z8530.scc1aRxBits == 2 ? 6.0 : 8.0) +
1673: ((Z8530.scc1aParity & 1) == 0 ? 0.0 : 1.0) +
1674: (Z8530.scc1aStop == 0 ? 0.0 :
1675: Z8530.scc1aStop == 1 ? 1.0 :
1676: Z8530.scc1aStop == 2 ? 1.5 : 2.0));
1677: double interval = bits / rate;
1678: if (false) {
1679: System.out.printf ("%08x baudrate=%.3fbps interval=%.3fus\n", XEiJ.regPC0, rate, interval * 1e+6);
1680: }
1681: Z8530.scc1aInterval = Math.round (interval * (double) XEiJ.TMR_FREQ);
1682:
1683: if (port != null) {
1684: port.setComPortParameters ((int) Math.round (rate),
1685: Z8530.scc1aRxBits == 0b00 ? 5 :
1686: Z8530.scc1aRxBits == 0b01 ? 7 :
1687: Z8530.scc1aRxBits == 0b10 ? 6 : 8,
1688: Z8530.scc1aStop == 0b10 ? SerialPort.ONE_POINT_FIVE_STOP_BITS :
1689: Z8530.scc1aStop == 0b11 ? SerialPort.TWO_STOP_BITS : SerialPort.ONE_STOP_BIT,
1690: Z8530.scc1aParity == 0b01 ? SerialPort.ODD_PARITY :
1691: Z8530.scc1aParity == 0b11 ? SerialPort.EVEN_PARITY : SerialPort.NO_PARITY);
1692: }
1693:
1694:
1695: TickerQueue.tkqAdd (trmAUXFlowControlTicker, XEiJ.mpuClockTime + XEiJ.TMR_FREQ * 500 / 1000000);
1696: } else {
1697:
1698: }
1699: }
1700:
1701:
1702:
1703:
1704: public static void trmInit () {
1705: trmFrame = null;
1706: trmBoard = null;
1707: trmPopupMenu = null;
1708: trmPopupCutMenuItem = null;
1709: trmPopupCopyMenuItem = null;
1710: trmPopupPasteMenuItem = null;
1711: trmPopupSelectAllMenuItem = null;
1712: trmPopupSendCtrlCMenuItem = null;
1713: trmOutputBuilder = new StringBuilder ();
1714: trmOutputEnd = 0;
1715: trmOutputSJIS1 = 0;
1716:
1717: trmInitConnection ();
1718: trmReset ();
1719: }
1720:
1721: public static void trmReset () {
1722: trmRSDRV202Head = 0;
1723: trmTMSIO031Head = 0;
1724: trmBSIO021Head = 0;
1725: trmAUXFlowControlXON = false;
1726: trmAUXFlowControlRTS = false;
1727: }
1728:
1729:
1730:
1731: public static void trmTini () {
1732: trmTiniConnection ();
1733: }
1734:
1735:
1736:
1737:
1738: public static void trmMake () {
1739:
1740:
1741: trmBoard = ComponentFactory.createScrollTextArea (
1742: trmOutputBuilder.toString (),
1743: 650, 350,
1744: true);
1745: trmOutputBuilder = null;
1746: trmBoard.setUnderlineCursorOn (true);
1747: trmBoard.setLineWrap (true);
1748: trmBoard.addDocumentListener (new DocumentListener () {
1749: @Override public void changedUpdate (DocumentEvent de) {
1750: }
1751: @Override public void insertUpdate (DocumentEvent de) {
1752: if (de.getOffset () < trmOutputEnd) {
1753: trmOutputEnd += de.getLength ();
1754: }
1755: }
1756: @Override public void removeUpdate (DocumentEvent de) {
1757: if (de.getOffset () < trmOutputEnd) {
1758: trmOutputEnd -= Math.min (de.getLength (), trmOutputEnd - de.getOffset ());
1759: }
1760: }
1761: });
1762: trmBoard.addKeyListener (new KeyAdapter () {
1763: @Override public void keyPressed (KeyEvent ke) {
1764: int keyCode = ke.getKeyCode ();
1765: if (keyCode == KeyEvent.VK_ENTER) {
1766: ke.consume ();
1767: trmEnter ();
1768: } else if (keyCode == KeyEvent.VK_PAUSE) {
1769: ke.consume ();
1770: trmSendString ("\u0003");
1771: }
1772: }
1773: });
1774:
1775:
1776: ActionListener popupActionListener = new ActionListener () {
1777: @Override public void actionPerformed (ActionEvent ae) {
1778: switch (ae.getActionCommand ()) {
1779: case "Cut":
1780: trmCut ();
1781: break;
1782: case "Copy":
1783: trmCopy ();
1784: break;
1785: case "Paste":
1786: trmPaste ();
1787: break;
1788: case "Select All":
1789: trmSelectAll ();
1790: break;
1791: case "Send ^C":
1792: trmSendString ("\u0003");
1793: break;
1794: }
1795: }
1796: };
1797: trmPopupMenu = ComponentFactory.createPopupMenu (
1798: trmPopupCutMenuItem = Multilingual.mlnText (
1799: ComponentFactory.createMenuItem ("Cut", 'T', popupActionListener),
1800: "ja", "切り取り"),
1801: trmPopupCopyMenuItem = Multilingual.mlnText (
1802: ComponentFactory.createMenuItem ("Copy", 'C', popupActionListener),
1803: "ja", "コピー"),
1804: trmPopupPasteMenuItem = Multilingual.mlnText (
1805: ComponentFactory.createMenuItem ("Paste", 'P', popupActionListener),
1806: "ja", "貼り付け"),
1807: ComponentFactory.createHorizontalSeparator (),
1808: trmPopupSelectAllMenuItem = Multilingual.mlnText (
1809: ComponentFactory.createMenuItem ("Select All", 'A', popupActionListener),
1810: "ja", "すべて選択"),
1811: ComponentFactory.createHorizontalSeparator (),
1812: trmPopupSendCtrlCMenuItem = Multilingual.mlnText (
1813: ComponentFactory.createMenuItem ("Send ^C", popupActionListener),
1814: "ja", "^C 送信")
1815: );
1816: trmBoard.addMouseListener (new MouseAdapter () {
1817: @Override public void mousePressed (MouseEvent me) {
1818: trmShowPopup (me);
1819: }
1820: @Override public void mouseReleased (MouseEvent me) {
1821: trmShowPopup (me);
1822: }
1823: });
1824:
1825:
1826: ActionListener listener = new ActionListener () {
1827: @Override public void actionPerformed (ActionEvent ae) {
1828: Object source = ae.getSource ();
1829: String command = ae.getActionCommand ();
1830: switch (command) {
1831: case "Refresh":
1832: trmUpdateConnection ();
1833: break;
1834: case "Baud rate":
1835: trmSetBaudRate (((JComboBox) source).getSelectedIndex ());
1836: break;
1837: case "Data bits":
1838: trmSetDataBits (((JComboBox) source).getSelectedIndex ());
1839: break;
1840: case "Parity":
1841: trmSetParity (((JComboBox) source).getSelectedIndex ());
1842: break;
1843: case "Stop bits":
1844: trmSetStopBits (((JComboBox) source).getSelectedIndex ());
1845: break;
1846: case "Flow control":
1847: trmSetFlowControl (((JComboBox) source).getSelectedIndex ());
1848: break;
1849: case "Send file":
1850: trmSendFile ();
1851: break;
1852: case "Set clock":
1853: trmSetClock ();
1854: break;
1855: default:
1856: System.out.println ("unknown action command " + command);
1857: }
1858: }
1859: };
1860:
1861:
1862: trmRefreshButton =
1863: ComponentFactory.setEnabled (
1864: Multilingual.mlnText (
1865: ComponentFactory.createButton ("Refresh", listener),
1866: "ja", "更新"),
1867: trmRefreshEnabled);
1868: trmBaudRateComboBox =
1869: ComponentFactory.setEnabled (
1870: Multilingual.mlnToolTipText (
1871: ComponentFactory.createComboBox (
1872: trmBaudRateIndex, "Baud rate", listener, trmBaudRateArray),
1873: "ja", "ボーレート"),
1874: trmSettingsEnabled);
1875: trmDataBitsComboBox =
1876: ComponentFactory.setEnabled (
1877: Multilingual.mlnToolTipText (
1878: ComponentFactory.createComboBox (
1879: trmDataBitsIndex, "Data bits", listener, trmDataBitsArray),
1880: "ja", "データビット"),
1881: trmSettingsEnabled);
1882: trmParityComboBox =
1883: ComponentFactory.setEnabled (
1884: Multilingual.mlnToolTipText (
1885: ComponentFactory.createComboBox (
1886: trmParityIndex, "Parity", listener, trmParityArray),
1887: "ja", "パリティ"),
1888: trmSettingsEnabled);
1889: trmStopBitsComboBox =
1890: ComponentFactory.setEnabled (
1891: Multilingual.mlnToolTipText (
1892: ComponentFactory.createComboBox (
1893: trmStopBitsIndex, "Stop bits", listener, trmStopBitsArray),
1894: "ja", "ストップビット"),
1895: trmSettingsEnabled);
1896: trmFlowControlComboBox =
1897: ComponentFactory.setEnabled (
1898: Multilingual.mlnToolTipText (
1899: ComponentFactory.createComboBox (
1900: trmFlowControlIndex, "Flow control", listener, trmFlowControlArray),
1901: "ja", "フロー制御"),
1902: trmSettingsEnabled);
1903: trmSendButton =
1904: ComponentFactory.setEnabled (
1905: Multilingual.mlnText (
1906: ComponentFactory.createButton ("Send file", listener),
1907: "ja", "ファイル送信"),
1908: trmSendEnabled);
1909: trmSetClockButton =
1910: ComponentFactory.setEnabled (
1911: Multilingual.mlnText (
1912: ComponentFactory.createButton ("Set clock", listener),
1913: "ja", "時計合わせ"),
1914: trmSendEnabled);
1915:
1916:
1917:
1918:
1919:
1920:
1921:
1922:
1923:
1924:
1925:
1926:
1927:
1928:
1929:
1930:
1931:
1932:
1933:
1934:
1935: Box connectionBox = Multilingual.mlnTitledBorder (
1936: ComponentFactory.setTitledLineBorder (
1937: ComponentFactory.createHorizontalBox (
1938: Box.createHorizontalStrut (5),
1939: ComponentFactory.createVerticalBox (
1940: Box.createVerticalGlue (),
1941: trmRefreshButton,
1942: Box.createVerticalGlue ()
1943: ),
1944: Box.createHorizontalStrut (10),
1945: trmConnectionBox,
1946: Box.createHorizontalGlue ()
1947: ),
1948: "Connection"),
1949: "ja", "接続");
1950:
1951: Box settingsBox = Multilingual.mlnTitledBorder (
1952: ComponentFactory.setTitledLineBorder (
1953: ComponentFactory.createHorizontalBox (
1954: Box.createHorizontalStrut (5),
1955: trmBaudRateComboBox,
1956: trmDataBitsComboBox,
1957: trmParityComboBox,
1958: trmStopBitsComboBox,
1959: trmFlowControlComboBox,
1960: Box.createHorizontalStrut (5)
1961: ),
1962: "Communication Settings"),
1963: "ja", "通信設定");
1964:
1965: Box commandxBox = Multilingual.mlnTitledBorder (
1966: ComponentFactory.setTitledLineBorder (
1967: ComponentFactory.createHorizontalBox (
1968: Box.createHorizontalStrut (5),
1969: trmSendButton,
1970: trmSetClockButton,
1971: Box.createHorizontalStrut (5)
1972: ),
1973: "Command"),
1974: "ja", "コマンド");
1975:
1976: trmFrame = Multilingual.mlnTitle (
1977: ComponentFactory.createRestorableSubFrame (
1978: Settings.SGS_TRM_FRAME_KEY,
1979: "RS-232C and terminal",
1980: null,
1981: ComponentFactory.createVerticalSplitPane (
1982: ComponentFactory.createScrollPane (
1983: ComponentFactory.createBorderPanel (
1984: ComponentFactory.createHorizontalBox (
1985: Box.createHorizontalGlue ()
1986: ),
1987: connectionBox
1988: )
1989: ),
1990: ComponentFactory.createBorderPanel (
1991: Multilingual.mlnTitledBorder (
1992: ComponentFactory.setTitledLineBorder (
1993: trmBoard,
1994: "Terminal"),
1995: "ja", "ターミナル"),
1996: ComponentFactory.createHorizontalBox (
1997: settingsBox,
1998: commandxBox,
1999: Box.createHorizontalGlue ()
2000: )
2001: )
2002: )
2003: ),
2004: "ja", "RS-232C とターミナル");
2005:
2006: }
2007:
2008:
2009:
2010:
2011: public static void trmShowPopup (MouseEvent me) {
2012: if (me.isPopupTrigger ()) {
2013:
2014: boolean enableCutAndCopy = XEiJ.clpClipboard != null && trmBoard.getSelectionStart () != trmBoard.getSelectionEnd ();
2015: ComponentFactory.setEnabled (trmPopupCutMenuItem, enableCutAndCopy);
2016: ComponentFactory.setEnabled (trmPopupCopyMenuItem, enableCutAndCopy);
2017:
2018: ComponentFactory.setEnabled (trmPopupPasteMenuItem, XEiJ.clpClipboard != null && XEiJ.clpClipboard.isDataFlavorAvailable (DataFlavor.stringFlavor));
2019:
2020: ComponentFactory.setEnabled (trmPopupSelectAllMenuItem, XEiJ.clpClipboard != null);
2021:
2022: ComponentFactory.setEnabled (trmPopupSendCtrlCMenuItem,
2023: trmRowToCol[0] == 1 ||
2024: 0 < trmColToRow[0]);
2025:
2026: trmPopupMenu.show (me.getComponent (), me.getX (), me.getY ());
2027: }
2028: }
2029:
2030:
2031:
2032: public static void trmCut () {
2033: if (XEiJ.clpClipboard != null) {
2034:
2035: XEiJ.clpClipboardString = trmBoard.getSelectedText ();
2036: try {
2037: XEiJ.clpClipboard.setContents (XEiJ.clpStringContents, XEiJ.clpClipboardOwner);
2038: XEiJ.clpIsClipboardOwner = true;
2039: } catch (Exception e) {
2040: return;
2041: }
2042:
2043: trmBoard.replaceRange ("", trmBoard.getSelectionStart (), trmBoard.getSelectionEnd ());
2044: }
2045: }
2046:
2047:
2048:
2049: public static void trmCopy () {
2050: if (XEiJ.clpClipboard != null) {
2051:
2052: String selectedText = trmBoard.getSelectedText ();
2053: if (selectedText != null) {
2054: XEiJ.clpClipboardString = selectedText;
2055: try {
2056: XEiJ.clpClipboard.setContents (XEiJ.clpStringContents, XEiJ.clpClipboardOwner);
2057: XEiJ.clpIsClipboardOwner = true;
2058: } catch (Exception e) {
2059: return;
2060: }
2061: }
2062: }
2063: }
2064:
2065:
2066:
2067: public static void trmPaste () {
2068: if (XEiJ.clpClipboard != null) {
2069:
2070: String string = null;
2071: try {
2072: string = (String) XEiJ.clpClipboard.getData (DataFlavor.stringFlavor);
2073: } catch (Exception e) {
2074: return;
2075: }
2076:
2077: trmBoard.replaceRange (string, trmBoard.getSelectionStart (), trmBoard.getSelectionEnd ());
2078: }
2079: }
2080:
2081:
2082:
2083: public static void trmSelectAll () {
2084: if (XEiJ.clpClipboard != null) {
2085:
2086: trmBoard.selectAll ();
2087: }
2088: }
2089:
2090:
2091: public static void trmStart () {
2092: if (RestorableFrame.rfmGetOpened (Settings.SGS_TRM_FRAME_KEY)) {
2093: trmOpen ();
2094: }
2095: }
2096:
2097:
2098:
2099: public static void trmOpen () {
2100: if (trmFrame == null) {
2101: trmMake ();
2102: }
2103: XEiJ.pnlExitFullScreen (false);
2104: trmFrame.setVisible (true);
2105: }
2106:
2107:
2108:
2109:
2110: public static void trmPrintSJIS (int d) {
2111: d &= 0xff;
2112: if (trmOutputSJIS1 != 0) {
2113: if (0x40 <= d && d != 0x7f && d <= 0xfc) {
2114: int c = CharacterCode.chrSJISToChar[trmOutputSJIS1 << 8 | d];
2115: if (c != 0) {
2116: trmPrintChar (c);
2117: } else {
2118:
2119: trmPrintChar ('[');
2120: trmPrintChar (XEiJ.fmtHexc (trmOutputSJIS1 >> 4));
2121: trmPrintChar (XEiJ.fmtHexc (trmOutputSJIS1 & 15));
2122: trmPrintChar (XEiJ.fmtHexc (d >> 4));
2123: trmPrintChar (XEiJ.fmtHexc (d & 15));
2124: trmPrintChar (']');
2125: }
2126: trmOutputSJIS1 = 0;
2127: return;
2128: }
2129:
2130:
2131: trmPrintChar ('[');
2132: trmPrintChar (XEiJ.fmtHexc (trmOutputSJIS1 >> 4));
2133: trmPrintChar (XEiJ.fmtHexc (trmOutputSJIS1 & 15));
2134: trmPrintChar (']');
2135: trmOutputSJIS1 = 0;
2136: }
2137: if (0x81 <= d && d <= 0x9f || 0xe0 <= d && d <= 0xef) {
2138: trmOutputSJIS1 = d;
2139: } else {
2140: int c = CharacterCode.chrSJISToChar[d];
2141: if (c != 0) {
2142: trmPrintChar (c);
2143: } else {
2144:
2145: trmPrintChar ('[');
2146: trmPrintChar (XEiJ.fmtHexc (d >> 4));
2147: trmPrintChar (XEiJ.fmtHexc (d & 15));
2148: trmPrintChar (']');
2149: }
2150: }
2151: }
2152:
2153:
2154:
2155: public static void trmPrintChar (int c) {
2156: if (c == 0x08) {
2157: if (trmOutputEnd > 0) {
2158: if (trmBoard != null) {
2159: trmBoard.replaceRange ("", trmOutputEnd - 1, trmOutputEnd);
2160: trmOutputEnd--;
2161: trmBoard.setCaretPosition (trmOutputEnd);
2162: } else {
2163: trmOutputBuilder.delete (trmOutputEnd - 1, trmOutputEnd);
2164: trmOutputEnd--;
2165: }
2166: }
2167: } else if (c >= 0x20 && c != 0x7f || c == 0x09 || c == 0x0a) {
2168: if (trmBoard != null) {
2169: trmBoard.insert (String.valueOf ((char) c), trmOutputEnd);
2170: trmOutputEnd++;
2171: if (trmOutputEnd >= TRM_CUT_OUTPUT_LENGTH) {
2172: trmBoard.replaceRange ("", 0, trmOutputEnd - TRM_MAX_OUTPUT_LENGTH);
2173: trmOutputEnd = TRM_MAX_OUTPUT_LENGTH;
2174: }
2175: trmBoard.setCaretPosition (trmOutputEnd);
2176: } else {
2177: trmOutputBuilder.append ((char) c);
2178: trmOutputEnd++;
2179: if (trmOutputEnd >= TRM_CUT_OUTPUT_LENGTH) {
2180: trmOutputBuilder.delete (0, trmOutputEnd - TRM_MAX_OUTPUT_LENGTH);
2181: trmOutputEnd = TRM_MAX_OUTPUT_LENGTH;
2182: }
2183: }
2184: }
2185: }
2186:
2187:
2188:
2189:
2190:
2191: public static void trmPrint (String s) {
2192: if (s == null) {
2193: return;
2194: }
2195: if (trmFrame != null) {
2196: trmBoard.insert (s, trmOutputEnd);
2197: trmOutputEnd += s.length ();
2198: if (trmOutputEnd >= TRM_CUT_OUTPUT_LENGTH) {
2199: trmBoard.replaceRange ("", 0, trmOutputEnd - TRM_MAX_OUTPUT_LENGTH);
2200: trmOutputEnd = TRM_MAX_OUTPUT_LENGTH;
2201: }
2202: trmBoard.setCaretPosition (trmOutputEnd);
2203: } else {
2204: trmOutputBuilder.append (s);
2205: trmOutputEnd += s.length ();
2206: if (trmOutputEnd >= TRM_CUT_OUTPUT_LENGTH) {
2207: trmOutputBuilder.delete (0, trmOutputEnd - TRM_MAX_OUTPUT_LENGTH);
2208: trmOutputEnd = TRM_MAX_OUTPUT_LENGTH;
2209: }
2210: }
2211: }
2212:
2213:
2214:
2215:
2216:
2217: public static void trmPrintln (String s) {
2218: trmPrint (s);
2219: trmPrintChar ('\n');
2220: }
2221:
2222:
2223:
2224: public static void trmEnter () {
2225: String text = trmBoard.getText ();
2226: int length = text.length ();
2227: int outputLineStart = text.lastIndexOf ('\n', trmOutputEnd - 1) + 1;
2228: int caretLineStart = text.lastIndexOf ('\n', trmBoard.getCaretPosition () - 1) + 1;
2229: if (outputLineStart <= caretLineStart) {
2230: trmBoard.replaceRange ("", trmOutputEnd, length);
2231: trmSendString (text.substring (trmOutputEnd, length) + "\r");
2232: } else if (outputLineStart < trmOutputEnd) {
2233: String prompt = text.substring (outputLineStart, trmOutputEnd);
2234: int caretLineEnd = text.indexOf ('\n', caretLineStart);
2235: if (caretLineEnd == -1) {
2236: caretLineEnd = length;
2237: }
2238: String line = text.substring (caretLineStart, caretLineEnd);
2239: int start = line.indexOf (prompt);
2240: if (start >= 0) {
2241: trmOutputEnd = length;
2242: if (text.charAt (trmOutputEnd - 1) != '\n') {
2243: trmBoard.insert ("\n", trmOutputEnd);
2244: trmOutputEnd++;
2245: if (trmOutputEnd >= TRM_CUT_OUTPUT_LENGTH) {
2246: trmBoard.replaceRange ("", 0, trmOutputEnd - TRM_MAX_OUTPUT_LENGTH);
2247: trmOutputEnd = TRM_MAX_OUTPUT_LENGTH;
2248: }
2249: }
2250: trmBoard.setCaretPosition (trmOutputEnd);
2251: trmSendString (line.substring (start + prompt.length ()) + "\r");
2252: }
2253: }
2254: }
2255:
2256:
2257:
2258: public static void trmSendString (String s) {
2259: int l = s.length ();
2260: if (l == 0) {
2261: return;
2262: }
2263: byte[] b = new byte[l * 2];
2264: int k = 0;
2265: for (int i = 0; i < l; i++) {
2266: int c = CharacterCode.chrCharToSJIS[s.charAt (i)];
2267: if (0x00ff < c) {
2268: b[k++] = (byte) (c >> 8);
2269: }
2270: b[k++] = (byte) c;
2271: }
2272: if (trmRowToCol[0] == 1) {
2273: int row = 0;
2274: int col = 1;
2275: trmConnectionArray[trmCols * row + col - 1].row2colQueue.write (b, 0, k);
2276: } else if (0 < trmColToRow[0]) {
2277: int row = trmColToRow[0];
2278: int col = 0;
2279: trmConnectionArray[trmCols * row + col - 1].col2rowQueue.write (b, 0, k);
2280: }
2281: }
2282:
2283:
2284:
2285:
2286:
2287: public static void trmSetClock () {
2288: String[] options = new String[] {
2289: Multilingual.mlnJapanese ? "送信" : "Send",
2290: Multilingual.mlnJapanese ? "キャンセル" : "Cancel",
2291: };
2292: if (JOptionPane.showOptionDialog (
2293: trmFrame,
2294: Multilingual.mlnJapanese ?
2295: "DATE と TIME を送信して時計を大まかに合わせます。\n" +
2296: "COMMAND.X を CTTY AUX で準備してください。":
2297: "Sending DATE and TIME to set clock roughly.\n" +
2298: "Prepare COMMAND.X with CTTY AUX.",
2299: Multilingual.mlnJapanese ? "時計合わせ" : "Set clock",
2300: JOptionPane.OK_CANCEL_OPTION,
2301: JOptionPane.PLAIN_MESSAGE,
2302: null,
2303: options,
2304: options[0]) == 0) {
2305: trmScheduler.schedule (
2306: () -> {
2307: long dttm = DnT.dntDttmCmil (System.currentTimeMillis () + RP5C15.rtcCmilGap);
2308: trmSendString (
2309: String.format ("date %04d-%02d-%02d\rtime %02d:%02d:%02d\r",
2310: DnT.dntYearDttm (dttm),
2311: DnT.dntMontDttm (dttm),
2312: DnT.dntMdayDttm (dttm),
2313: DnT.dntHourDttm (dttm),
2314: DnT.dntMinuDttm (dttm),
2315: DnT.dntSecoDttm (dttm))
2316: );
2317: },
2318: 0L, TimeUnit.MILLISECONDS);
2319: }
2320: }
2321:
2322:
2323:
2324:
2325:
2326: public static void trmSendFile () {
2327: if (trmSendDialog == null) {
2328: ActionListener listener = new ActionListener () {
2329: @Override public void actionPerformed (ActionEvent ae) {
2330: switch (ae.getActionCommand ()) {
2331: case JFileChooser.APPROVE_SELECTION:
2332: case "Send":
2333: trmSendDialog.setVisible (false);
2334: File file = trmSendFileChooser.getSelectedFile ();
2335: if (file != null) {
2336: trmSendThread = new SendThread (file);
2337: trmSendThread.start ();
2338: }
2339: break;
2340: case JFileChooser.CANCEL_SELECTION:
2341: case "Cancel":
2342: trmSendDialog.setVisible (false);
2343: break;
2344: }
2345: }
2346: };
2347: trmSendFileChooser = new JFileChooser (new File ("a.txt"));
2348: trmSendFileChooser.setMultiSelectionEnabled (false);
2349: trmSendFileChooser.setControlButtonsAreShown (false);
2350: trmSendFileChooser.addActionListener (listener);
2351: trmSendDialog =
2352: Multilingual.mlnTitle (
2353: ComponentFactory.createModalDialog (
2354: trmFrame,
2355: "Send file",
2356: ComponentFactory.createBorderPanel (
2357: 0, 0,
2358: ComponentFactory.createVerticalBox (
2359: trmSendFileChooser,
2360: ComponentFactory.createHorizontalBox (
2361: Box.createHorizontalStrut (12),
2362: Box.createHorizontalGlue (),
2363: Multilingual.mlnText (
2364: ComponentFactory.createLabel (
2365: "Prepare COMMAND.X with CTTY AUX"),
2366: "ja", "COMMAND.X を CTTY AUX で準備して"),
2367: Box.createHorizontalStrut (12),
2368: Multilingual.mlnText (
2369: ComponentFactory.createButton ("Send", KeyEvent.VK_S, listener),
2370: "ja", "送信"),
2371: Box.createHorizontalStrut (12),
2372: Multilingual.mlnText (
2373: ComponentFactory.createButton ("Cancel", KeyEvent.VK_C, listener),
2374: "ja", "キャンセル"),
2375: Box.createHorizontalStrut (12)
2376: ),
2377: Box.createVerticalStrut (12)
2378: )
2379: )
2380: ),
2381: "ja", "ファイル送信");
2382: }
2383: XEiJ.pnlExitFullScreen (true);
2384: trmSendDialog.setVisible (true);
2385: }
2386:
2387:
2388:
2389:
2390:
2391:
2392:
2393: static class SendThread extends Thread {
2394: File file;
2395: SendThread (File file) {
2396: this.file = file;
2397: }
2398: @Override public void run () {
2399: trmSendProcess (file);
2400: }
2401: }
2402:
2403:
2404:
2405: static byte[] load (File file) {
2406: if (!file.isFile ()) {
2407: return null;
2408: }
2409: int len = (int) file.length ();
2410: if (len == 0) {
2411: return null;
2412: }
2413: byte[] buf = new byte[len];
2414: try (BufferedInputStream bis = new BufferedInputStream (new FileInputStream (file))) {
2415: if (bis.read (buf) != len) {
2416: return null;
2417: }
2418: } catch (IOException ioe) {
2419: return null;
2420: }
2421: return buf;
2422: }
2423:
2424:
2425:
2426: static class BitWriter {
2427:
2428: byte[] buffer;
2429: int byteIndex;
2430: int bitIndex;
2431: int bitCount;
2432:
2433:
2434:
2435: BitWriter () {
2436: buffer = new byte[16];
2437: byteIndex = 0;
2438: bitIndex = -1;
2439: bitCount = 0;
2440: }
2441:
2442:
2443:
2444:
2445: void writeByte (int data) {
2446: if (byteIndex == buffer.length) {
2447: byte[] temporary = new byte[byteIndex * 2];
2448: System.arraycopy (buffer, 0,
2449: temporary, 0,
2450: byteIndex);
2451: buffer = temporary;
2452: }
2453: buffer[byteIndex++] = (byte) data;
2454: }
2455:
2456:
2457:
2458:
2459:
2460: void writeBits (int width, int data) {
2461: while (width != 0) {
2462: if (bitCount == 0) {
2463: if (byteIndex == buffer.length) {
2464: byte[] temporary = new byte[byteIndex * 2];
2465: System.arraycopy (buffer, 0,
2466: temporary, 0,
2467: byteIndex);
2468: buffer = temporary;
2469: }
2470: bitIndex = byteIndex;
2471: bitCount = 8;
2472: buffer[byteIndex++] = 0;
2473: }
2474: data &= (1 << width) - 1;
2475: int n = Math.min (bitCount, width);
2476: bitCount -= n;
2477: width -= n;
2478: buffer[bitIndex] |= (byte) ((data >>> width) << bitCount);
2479: }
2480: }
2481:
2482:
2483:
2484: byte[] getBuffer () {
2485: return buffer;
2486: }
2487:
2488:
2489:
2490: int getLength () {
2491: return byteIndex;
2492: }
2493:
2494: }
2495:
2496: static class DIC {
2497: int ptr;
2498: int len;
2499: }
2500:
2501:
2502:
2503:
2504:
2505: static byte[] compress (byte[] inpbuf, int dicbit) {
2506: int dicsiz = 1 << dicbit;
2507:
2508: DIC[] dicbuf = new DIC[dicsiz];
2509: for (int pag = 0; pag < dicsiz; pag++) {
2510: dicbuf[pag] = new DIC ();
2511: dicbuf[pag].ptr = 0;
2512: dicbuf[pag].len = 0;
2513: }
2514: int dicent = 0;
2515:
2516: int inplen = inpbuf.length;
2517: BitWriter bw = new BitWriter ();
2518: bw.writeBits (24, inplen);
2519:
2520: bw.writeBits (4, dicbit);
2521:
2522: int inpptr = 0;
2523: while (inpptr < inplen) {
2524:
2525: int dicpag = -1;
2526: int dicptr = -1;
2527: int diclen = 0;
2528: int fstchr = inpbuf[inpptr] & 255;
2529: for (int pag = 0; pag < dicsiz; pag++) {
2530: int len = dicbuf[pag].len;
2531: if (diclen < len &&
2532: inpptr + len + 1 <= inplen) {
2533: int ptr = dicbuf[pag].ptr;
2534: cmp:
2535: if (fstchr == (inpbuf[ptr] & 255)) {
2536: for (int i = 1; i < len; i++) {
2537: if (inpbuf[inpptr + i] != inpbuf[ptr + i]) {
2538: break cmp;
2539: }
2540: }
2541: dicpag = pag;
2542: dicptr = ptr;
2543: diclen = len;
2544: }
2545: }
2546: }
2547: if (diclen == 0) {
2548: bw.writeBits (1, 0);
2549: } else {
2550: bw.writeBits (1, 1);
2551: bw.writeBits (dicbit, dicpag);
2552: }
2553: int chr = inpbuf[inpptr + diclen] & 255;
2554:
2555: bw.writeByte (chr);
2556:
2557: diclen++;
2558:
2559: dicbuf[dicent].ptr = inpptr;
2560: dicbuf[dicent].len = diclen;
2561: dicent++;
2562: if (dicent == dicsiz) {
2563: dicent = 0;
2564: }
2565:
2566: inpptr += diclen;
2567: }
2568:
2569: byte[] outbuf = bw.getBuffer ();
2570: int outlen = bw.getLength ();
2571: if (outbuf.length != outlen) {
2572: byte[] tmpbuf = new byte[outlen];
2573: System.arraycopy (outbuf, 0, tmpbuf, 0, outlen);
2574: outbuf = tmpbuf;
2575: }
2576: return outbuf;
2577: }
2578:
2579:
2580:
2581:
2582:
2583:
2584:
2585:
2586:
2587:
2588: public static byte[] encode (byte[] src) {
2589: int r = src.length;
2590: int q = r / 62;
2591: r -= 62 * q;
2592: if (r != 0) {
2593: r = ((r + 2 + 3) & -4) - 2;
2594: if (src.length < 62 * q + r) {
2595: byte[] tmp = new byte[62 * q + r];
2596: System.arraycopy (src, 0, tmp, 0, src.length);
2597: src = tmp;
2598: }
2599: }
2600: byte[] dst = new byte[64 * q + (r == 0 ? 0 : r + 2)];
2601: int[] w = new int[16];
2602: for (int i = 0; 64 * i < dst.length; i++) {
2603: int n = Math.min (64, dst.length - 64 * i) / 4;
2604:
2605: for (int k = 0; k < n - 1; k++) {
2606: w[k] = ((src[62 * i + 4 * k + 0] & 255) << 24 |
2607: (src[62 * i + 4 * k + 1] & 255) << 16 |
2608: (src[62 * i + 4 * k + 2] & 255) << 8 |
2609: (src[62 * i + 4 * k + 3] & 255));
2610: }
2611: w[n - 1] = ((src[62 * i + 4 * (n - 1) + 0] & 255) << 24 |
2612: (src[62 * i + 4 * (n - 1) + 1] & 255) << 16);
2613:
2614: for (int k = 0; k < n; k++) {
2615: if ((w[k] & 0x80000000) != 0) {
2616: w[k] &= 0x7fffffff;
2617: w[n - 1] |= 1 << (15 - k);
2618: }
2619: }
2620:
2621: for (int k = 0; k < n; k++) {
2622: int t3 = w[k];
2623: int t2 = t3 / 224;
2624: t3 -= 224 * t2;
2625: int t1 = t2 / 224;
2626: t2 -= 224 * t1;
2627: int t0 = t1 / 224;
2628: t1 -= 224 * t0;
2629: dst[64 * i + 4 * k + 0] = (byte) (32 + t0);
2630: dst[64 * i + 4 * k + 1] = (byte) (32 + t1);
2631: dst[64 * i + 4 * k + 2] = (byte) (32 + t2);
2632: dst[64 * i + 4 * k + 3] = (byte) (32 + t3);
2633: }
2634: }
2635: return dst;
2636: }
2637:
2638:
2639:
2640: public static void trmSendProcess (File file) {
2641:
2642: byte[] fileData = load (file);
2643: if (fileData == null) {
2644: return;
2645: }
2646: if (0x00ffff00 < fileData.length) {
2647: return;
2648: }
2649:
2650:
2651:
2652: byte[] step3Data = new byte[adotr3.length +
2653: 24 +
2654: 4 +
2655: 4 +
2656: 4 +
2657: fileData.length];
2658: int index3 = 0;
2659:
2660: System.arraycopy (adotr3, 0,
2661: step3Data, index3,
2662: adotr3.length);
2663: index3 += adotr3.length;
2664:
2665:
2666:
2667:
2668:
2669: String name = file.getName ();
2670: {
2671: byte[] b = new byte[2 * name.length ()];
2672: int k = 0;
2673: int p = -1;
2674: for (int i = 0; i < name.length (); i++) {
2675: int c = CharacterCode.chrCharToSJIS[name.charAt (i)];
2676: if (c == 0) {
2677: return;
2678: }
2679: if (c <= ' ' || c == ':' || c == '*' || c == '?' ||
2680: c == '\\' || c == '/' || (c == '-' && k == 0) ||
2681: c == '"' || c == '\'' || c == '+' || c == ';' ||
2682: c == '<' || c == '=' || c == '>' ||
2683: c == '[' || c == ']' || c == '|') {
2684: return;
2685: }
2686: if (c == '.') {
2687: if (p < 0) {
2688: p = k;
2689: } else {
2690: return;
2691: }
2692: }
2693: if (0x00ff < c) {
2694: b[k++] = (byte) (c >> 8);
2695: }
2696: b[k++] = (byte) c;
2697: if (p < 0 ? 18 < k : p + 1 + 3 < k) {
2698: return;
2699: }
2700: }
2701: for (int i = 0; i < k; i++) {
2702: step3Data[index3++] = b[i];
2703: }
2704: for (int i = k; i < 24; i++) {
2705: step3Data[index3++] = 0;
2706: }
2707: }
2708:
2709: {
2710: long dttm = DnT.dntDttmCmil (file.lastModified () + RP5C15.rtcCmilGap);
2711: int date = DnT.dntYearDttm (dttm) - 1980 << 9 | DnT.dntMontDttm (dttm) << 5 | DnT.dntMdayDttm (dttm);
2712: int time = DnT.dntHourDttm (dttm) << 11 | DnT.dntMinuDttm (dttm) << 5 | DnT.dntSecoDttm (dttm) >> 1;
2713: step3Data[index3++] = (byte) (date >> 8);
2714: step3Data[index3++] = (byte) date;
2715: step3Data[index3++] = (byte) (time >> 8);
2716: step3Data[index3++] = (byte) time;
2717: }
2718:
2719: {
2720: CRC32 crc32 = new CRC32 ();
2721: crc32.update (fileData, 0, fileData.length);
2722: int t = (int) crc32.getValue ();
2723: step3Data[index3++] = (byte) (t >> 24);
2724: step3Data[index3++] = (byte) (t >> 16);
2725: step3Data[index3++] = (byte) (t >> 8);
2726: step3Data[index3++] = (byte) (t);
2727: }
2728:
2729: {
2730: int t = fileData.length;
2731: step3Data[index3++] = (byte) (t >> 24);
2732: step3Data[index3++] = (byte) (t >> 16);
2733: step3Data[index3++] = (byte) (t >> 8);
2734: step3Data[index3++] = (byte) (t);
2735: }
2736:
2737: System.arraycopy (fileData, 0,
2738: step3Data, index3,
2739: fileData.length);
2740: index3 += fileData.length;
2741:
2742:
2743:
2744: byte[] step3DataCompressed = null;
2745: int dicbit = 0;
2746:
2747:
2748:
2749:
2750: for (int i = 8; i <= 10; i++) {
2751: byte[] t = compress (step3Data, i);
2752: if (step3DataCompressed == null ||
2753: t.length < step3DataCompressed.length) {
2754: step3DataCompressed = t;
2755: dicbit = i;
2756: }
2757: }
2758: byte[] step2Data = new byte[adotr2.length + step3DataCompressed.length];
2759: int index2 = 0;
2760:
2761: System.arraycopy (adotr2, 0,
2762: step2Data, index2,
2763: adotr2.length);
2764: index2 += adotr2.length;
2765:
2766: System.arraycopy (step3DataCompressed, 0,
2767: step2Data, index2,
2768: step3DataCompressed.length);
2769: index2 += step3DataCompressed.length;
2770:
2771:
2772:
2773: byte[] step3DataEncoded = encode (step3Data);
2774: byte[] step2DataEncoded = encode (step2Data);
2775: byte[] step1Data;
2776: if (step3DataEncoded.length <= step2DataEncoded.length) {
2777: step1Data = new byte[adotr1.length + step3DataEncoded.length + 1];
2778: int index1 = 0;
2779: System.arraycopy (adotr1, 0,
2780: step1Data, index1,
2781: adotr1.length);
2782: index1 += adotr1.length;
2783: System.arraycopy (step3DataEncoded, 0,
2784: step1Data, index1,
2785: step3DataEncoded.length);
2786: index1 += step3DataEncoded.length;
2787: step1Data[index1++] = 0x1a;
2788: if (false) {
2789: System.out.printf (" original: %d bytes (%.1f%%)\n",
2790: fileData.length,
2791: 100.0);
2792: System.out.printf (" generator concatenated: %d bytes (%.1f%%)\n",
2793: step3Data.length,
2794: 100.0 * (double) step3Data.length / (double) fileData.length);
2795: System.out.printf (" encoded: %d bytes (%.1f%%)\n",
2796: step3DataEncoded.length,
2797: 100.0 * (double) step3DataEncoded.length / (double) fileData.length);
2798: System.out.printf (" decoder concatenated: %d bytes (%.1f%%)\n",
2799: step1Data.length,
2800: 100.0 * (double) step1Data.length / (double) fileData.length);
2801: }
2802: } else {
2803: step1Data = new byte[adotr1.length + step2DataEncoded.length + 1];
2804: int index1 = 0;
2805: System.arraycopy (adotr1, 0,
2806: step1Data, index1,
2807: adotr1.length);
2808: index1 += adotr1.length;
2809: System.arraycopy (step2DataEncoded, 0,
2810: step1Data, index1,
2811: step2DataEncoded.length);
2812: index1 += step2DataEncoded.length;
2813: step1Data[index1++] = 0x1a;
2814: if (false) {
2815: System.out.printf (" original: %d bytes (%.1f%%)\n",
2816: fileData.length,
2817: 100.0);
2818: System.out.printf (" generator concatenated: %d bytes (%.1f%%)\n",
2819: step3Data.length,
2820: 100.0 * (double) step3Data.length / (double) fileData.length);
2821: System.out.printf (" compressed: %d bytes (%.1f%%) (%d bits dictionary)\n",
2822: step3DataCompressed.length,
2823: 100.0 * (double) step3DataCompressed.length / (double) fileData.length,
2824: dicbit);
2825: System.out.printf ("decompressor concatenated: %d bytes (%.1f%%)\n",
2826: step2Data.length,
2827: 100.0 * (double) step2Data.length / (double) fileData.length);
2828: System.out.printf (" encoded: %d bytes (%.1f%%)\n",
2829: step2DataEncoded.length,
2830: 100.0 * (double) step2DataEncoded.length / (double) fileData.length);
2831: System.out.printf (" decoder concatenated: %d bytes (%.1f%%)\n",
2832: step1Data.length,
2833: 100.0 * (double) step1Data.length / (double) fileData.length);
2834: }
2835: }
2836: if (false) {
2837: int l = step1Data.length;
2838: System.out.printf ("step1Data %d bytes\n", l);
2839: for (int i = 0; i < l; i++) {
2840: if ((i & 15) == 0) {
2841: System.out.printf ("%08x", i);
2842: }
2843: System.out.printf (" %02x", step1Data[i] & 255);
2844: if ((i & 15) == 15) {
2845: System.out.println ();
2846: }
2847: }
2848: if ((l & 15) != 0) {
2849: System.out.println ();
2850: }
2851: }
2852:
2853: trmSendString (String.format (
2854: "rem a.r/%s %d/%d %.1f%%\rcopy aux a.r\r",
2855: name, step1Data.length, fileData.length,
2856: 100.0 * (double) step1Data.length / (double) fileData.length));
2857: try {
2858: Thread.sleep (1000);
2859: } catch (InterruptedException ie) {
2860: }
2861: if (trmRowToCol[0] == 1) {
2862: int row = 0;
2863: int col = 1;
2864: trmConnectionArray[trmCols * row + col - 1].row2colQueue.write (step1Data, 0, step1Data.length);
2865: } else if (0 < trmColToRow[0]) {
2866: int row = trmColToRow[0];
2867: int col = 0;
2868: trmConnectionArray[trmCols * row + col - 1].col2rowQueue.write (step1Data, 0, step1Data.length);
2869: }
2870: try {
2871: Thread.sleep (1000);
2872: } catch (InterruptedException ie) {
2873: }
2874: trmSendString ("a.r\r");
2875: }
2876:
2877:
2878: public static final byte[] adotr1 = "B\202G\373 h\324\211\304|\377\374(B\"Kx@\330\213B\200\320\214\220\204\223\201\300\201\330\200$I\"<\337\337\337\340\322\233B\200v( @\347\210\220\210\353\210\341\231\320\201Q\301\220\201\342Kd\354\"\300\267\304e\3322!B\200\322A\342\220\321\232\265\311e\364\267\314e\266A\372\377\370t\370N\360\" BAVAp\254NO".getBytes (XEiJ.ISO_8859_1);
2879:
2880: public static final byte[] adotr2 = "p\1\320\211\300|\377\376\"@|\0~\0E\372\0\372r\30a\0\0\322&\0\326\211p\1\320\203\300|\377\376*@r\4a\0\0\276g\0\0\246\30\0z\b\351\255\332\215\377\201\"\5\222\200/\1/\0\377JP\217J\200ktp\0 M \300 \300\261\305e\370(I,M\265\311dvr\1a\0\0\206f\b,\314p\1,\300`0\22\4av\347\210 u\b\0 5\b\4gVR\200\"\0\322\214\262\203bL,\314,\300U\200H@H@\30\330Q\310\377\374H@Q\310\377\364\30\332\275\305f\2,M\271\303e\260p\372N\373\2\16r\3p\254NO IN\320\377\t\377\0Hz\0\4`\366out of memory\r\n\0Hz\0\4`\340data error\r\n\0\0p\0J\7f\4\34\32P\7\24\1\264\7c\2\24\7\20\6\345\250\345.\236\2\222\2f\344\340\210Nu".getBytes (XEiJ.ISO_8859_1);
2881:
2882: public static final byte[] adotr3 = "E\372\1\2&*\0 G\352\0$ \13\320\203R\200\300|\377\376(@K\354\4\0\377\201\"\r\222\200/\1/\0\377JP\217J\200k\0\0\230 Lr\0 \1t\7\342\210d\6\n\200\355\270\203 Q\312\377\364 \300R\1d\350\"Lp\0\"\3 KF\200`\22HAt\0\24\30\261\2\340\210\345J$1(\0\265\200Q\311\377\356HAQ\311\377\346F\200\260\252\0\34f`?<\0 /\n\377<\\\217J\200kd/\3/\13?\0\377@\"\0/j\0\30\0\2\377\207\377>O\357\0\n\262\203g\b/\n\377AX\217`@/\n\377\tHz\0\6\377\t\377\0 created\r\n\0\0Hz\0\4`\352out of memory\r\n\0Hz\0\4`\324crc error\r\n\0Hz\0\4`\302cannot write\r\n\0\0".getBytes (XEiJ.ISO_8859_1);
2883:
2884: }