annotate src/com/five_ten_sg/connectbot/service/TerminalMonitor.java @ 401:977815f990ec

Backed out changeset 2a416391ffc3
author Carl Byington <carl@five-ten-sg.com>
date Mon, 20 Oct 2014 19:14:10 -0700
parents e856ecf87b10
children 14aa0621aa7d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
1 package com.five_ten_sg.connectbot.service;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
2
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
3 import android.content.ComponentName;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
4 import android.content.Context;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
5 import android.content.Intent;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
6 import android.content.ServiceConnection;
155
156b53fc4815 add showurl command
Carl Byington <carl@five-ten-sg.com>
parents: 153
diff changeset
7 import android.net.Uri;
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
8 import android.os.IBinder;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
9 import android.util.Log;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
10 import android.view.View;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
11 import de.mud.terminal.vt320;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
12 import java.io.IOException;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
13 import java.io.InputStream;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
14 import java.io.OutputStream;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
15 import java.net.InetAddress;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
16 import java.net.Socket;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
17 import java.nio.charset.Charset;
252
932e34a11e9e add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents: 251
diff changeset
18 import java.util.Arrays;
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
19 import java.util.HashMap;
15
1588e359a972 queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents: 0
diff changeset
20 import java.util.concurrent.ArrayBlockingQueue;
1588e359a972 queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents: 0
diff changeset
21 import java.util.concurrent.BlockingQueue;
1588e359a972 queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents: 0
diff changeset
22 import java.util.concurrent.ConcurrentHashMap;
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
23
174
b010f9dc801f add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 173
diff changeset
24 import com.five_ten_sg.connectbot.ConsoleActivity;
b010f9dc801f add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 173
diff changeset
25 import com.five_ten_sg.connectbot.bean.HostBean;
b010f9dc801f add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 173
diff changeset
26
b010f9dc801f add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 173
diff changeset
27
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
28 public class TerminalMonitor {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
29 public final static String TAG = "ConnectBot.TerminalMonitor";
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
30
172
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
31 public static final char MONITOR_CMD_INIT = 0;
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
32 public static final char MONITOR_CMD_ACTIVATE = 1;
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
33 public static final char MONITOR_CMD_KEYSTATE = 2;
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
34 public static final char MONITOR_CMD_CURSORMOVE = 3;
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
35 public static final char MONITOR_CMD_SCREENCHANGE = 4;
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
36 public static final char MONITOR_CMD_FIELDVALUE = 5;
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
37 public static final char MONITOR_CMD_SETFIELD = 5;
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
38 public static final char MONITOR_CMD_GETFIELD = 6;
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
39 public static final char MONITOR_CMD_SCREENWATCH = 7;
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
40 public static final char MONITOR_CMD_DEPRESS = 8;
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
41 public static final char MONITOR_CMD_SHOWURL = 9;
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
42 public static final char MONITOR_CMD_SWITCHSESSION = 10;
205
f86f1e37b504 add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
43 public static final char MONITOR_CMD_CURSORREQUEST = 11;
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
44
229
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
45 public static final char CURSOR_REQUESTED = 0;
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
46 public static final char CURSOR_SCREEN_CHANGE = 1;
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
47 public static final char CURSOR_USER_KEY = 2;
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
48
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
49 private static final int MONITORPORT = 6000;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
50 private static final String LOCALHOST = "127.0.0.1";
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
51
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
52 private Context parent = null;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
53 private vt320 buffer = null;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
54 private View view = null;
174
b010f9dc801f add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 173
diff changeset
55 private HostBean host = null;
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
56 private String init = null;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
57 private int start_line = 0; // monitor part of the screen for changes
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
58 private int end_line = 500; // ""
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
59 private int start_column = 0; // ""
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
60 private int end_column = 500; // ""
16
48a8daea9221 delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents: 15
diff changeset
61 private boolean modified = false; // used to delay screen change notifications
229
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
62 private boolean moved = false; // used to delay cursor moved notifications
16
48a8daea9221 delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents: 15
diff changeset
63 private int to_line = 0; // ""
48a8daea9221 delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents: 15
diff changeset
64 private int to_column = 0; // ""
113
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
65 private HashMap<Integer, Integer> keymap = null; // map MS VK_ keys to vt320 virtual keys
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
66 private IBinder bound = null;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
67 private Socket monitor_socket = null;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
68 private InputStream monitor_in = null;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
69 private OutputStream monitor_out = null;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
70 private MyReader monitor_reader = null;
397
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
71 private MyWriter monitor_writer = null;
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
72 private BlockingQueue<char[]> pending_commands = new ArrayBlockingQueue<char[]>(10000);
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
73 private MyServiceConnection monitor_connection = new MyServiceConnection();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
74
397
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
75 class MyWriter extends Thread {
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
76 private OutputStream monitor_out;
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
77 private boolean is_closing = false;
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
78
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
79 public MyWriter(OutputStream monitor_out) {
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
80 this.monitor_out = monitor_out;
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
81 }
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
82
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
83 public void closing() {
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
84 is_closing = true;
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
85 this.interrupt();
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
86 }
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
87
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
88 public void run() {
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
89 char [] c;
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
90 try {
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
91 while (!is_closing) {
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
92 c = pending_commands.take();
401
977815f990ec Backed out changeset 2a416391ffc3
Carl Byington <carl@five-ten-sg.com>
parents: 400
diff changeset
93 c[0] = (char)(c.length - 1); // number of chars following
977815f990ec Backed out changeset 2a416391ffc3
Carl Byington <carl@five-ten-sg.com>
parents: 400
diff changeset
94 c[1] = cmd;
977815f990ec Backed out changeset 2a416391ffc3
Carl Byington <carl@five-ten-sg.com>
parents: 400
diff changeset
95 //Log.i(TAG, String.format("sending %d command", (int)cmd));
397
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
96 monitor_out.write(charsToBytes(c));
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
97 }
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
98 }
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
99 catch (InterruptedException e) {
400
e856ecf87b10 Backed out changeset aeb8c2e6d83a
Carl Byington <carl@five-ten-sg.com>
parents: 399
diff changeset
100 if (!is_closing) Log.e(TAG, "exception in monitorWrite()", e);
397
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
101 }
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
102 catch (IOException e) {
400
e856ecf87b10 Backed out changeset aeb8c2e6d83a
Carl Byington <carl@five-ten-sg.com>
parents: 399
diff changeset
103 Log.i(TAG, "exception in monitorWrite(), monitor died or closed the socket", e);
397
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
104 }
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
105
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
106 try {
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
107 monitor_out.close();
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
108 }
400
e856ecf87b10 Backed out changeset aeb8c2e6d83a
Carl Byington <carl@five-ten-sg.com>
parents: 399
diff changeset
109 catch (IOException ee) {
e856ecf87b10 Backed out changeset aeb8c2e6d83a
Carl Byington <carl@five-ten-sg.com>
parents: 399
diff changeset
110 Log.e(TAG, "exception in monitorWrite() closing output stream", ee);
397
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
111 }
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
112 monitor_out = null;
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
113 }
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
114 }
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
115
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
116
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
117 class MyReader extends Thread {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
118 private InputStream monitor_in;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
119 private byte[] b;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
120 private boolean is_closing = false;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
121
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
122 public MyReader(InputStream monitor_in) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
123 this.monitor_in = monitor_in;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
124 b = new byte[100];
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
125 Log.i(TAG, "MyReader constructor");
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
126 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
127
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
128 public void closing() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
129 is_closing = true;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
130 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
131
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
132 private char[] forceRead(int len) throws IOException {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
133 int len2 = len * 2;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
134 int off = 0;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
135
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
136 if (b.length < len2) b = new byte[len2];
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
137
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
138 while (off < len2) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
139 int l = monitor_in.read(b, off, len2 - off);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
140
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
141 if (l < 0) throw new IOException("eof");
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
142
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
143 off += l;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
144 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
145
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
146 return bytesToChars(b, len2);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
147 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
148
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
149 public void run() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
150 while (true) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
151 try {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
152 char[] len = forceRead(1);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
153 char[] packet = forceRead(len[0]);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
154 char cmd = packet[0];
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
155 Log.i(TAG, String.format("received %d command", (int)cmd));
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
156
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
157 switch (cmd) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
158 case MONITOR_CMD_SETFIELD:
153
3ca280646f2d allow zero length setfield
Carl Byington <carl@five-ten-sg.com>
parents: 148
diff changeset
159 if (packet.length >= 3)
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
160 setField(packet[1], packet[2], packet, 3);
112
77ac18bc1b2f cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 101
diff changeset
161
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
162 break;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
163
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
164 case MONITOR_CMD_GETFIELD:
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
165 if (packet.length == 4)
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
166 getField(packet[1], packet[2], packet[3]);
112
77ac18bc1b2f cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 101
diff changeset
167
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
168 break;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
169
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
170 case MONITOR_CMD_SCREENWATCH:
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
171 if (packet.length == 4)
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
172 screenWatch(packet[1], packet[2], packet[3]);
112
77ac18bc1b2f cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 101
diff changeset
173
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
174 break;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
175
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
176 case MONITOR_CMD_DEPRESS:
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
177 if (packet.length == 2)
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
178 depress(packet[1]);
112
77ac18bc1b2f cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 101
diff changeset
179
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
180 break;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
181
155
156b53fc4815 add showurl command
Carl Byington <carl@five-ten-sg.com>
parents: 153
diff changeset
182 case MONITOR_CMD_SHOWURL:
156b53fc4815 add showurl command
Carl Byington <carl@five-ten-sg.com>
parents: 153
diff changeset
183 if (packet.length > 1)
156b53fc4815 add showurl command
Carl Byington <carl@five-ten-sg.com>
parents: 153
diff changeset
184 showUrl(packet, 1);
156b53fc4815 add showurl command
Carl Byington <carl@five-ten-sg.com>
parents: 153
diff changeset
185
156b53fc4815 add showurl command
Carl Byington <carl@five-ten-sg.com>
parents: 153
diff changeset
186 break;
156b53fc4815 add showurl command
Carl Byington <carl@five-ten-sg.com>
parents: 153
diff changeset
187
173
5f26d0ba6abd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 172
diff changeset
188 case MONITOR_CMD_SWITCHSESSION:
172
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
189 if (packet.length == 1)
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
190 switchSession();
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
191
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
192 break;
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
193
205
f86f1e37b504 add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
194 case MONITOR_CMD_CURSORREQUEST:
f86f1e37b504 add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
195 if (packet.length == 1)
f86f1e37b504 add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
196 cursorRequest();
f86f1e37b504 add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
197
f86f1e37b504 add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
198 break;
f86f1e37b504 add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
199
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
200 default:
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
201 break;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
202 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
203 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
204 catch (IOException e) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
205 if (!is_closing) Log.e(TAG, "exception in MyReader.run()", e);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
206
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
207 break;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
208 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
209 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
210 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
211 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
212
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
213 class MyServiceConnection implements ServiceConnection {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
214 public void onServiceConnected(ComponentName className, IBinder service) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
215 bound = service;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
216 Log.i(TAG, "bound to service");
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
217
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
218 try {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
219 InetAddress serverAddr = InetAddress.getByName(LOCALHOST);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
220 monitor_socket = new Socket(serverAddr, MONITORPORT);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
221 monitor_in = monitor_socket.getInputStream();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
222 monitor_out = monitor_socket.getOutputStream();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
223 Log.i(TAG, "connected to monitor socket, send init " + init);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
224 monitor_reader = new MyReader(monitor_in);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
225 monitor_reader.start();
397
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
226 monitor_writer = new MyWriter(monitor_out);
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
227 monitor_writer.start();
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
228
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
229 String x = " " + init;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
230 monitorWrite(MONITOR_CMD_INIT, x.toCharArray());
112
77ac18bc1b2f cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 101
diff changeset
231
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
232 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
233 catch (IOException e) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
234 Log.e(TAG, "exception in onServiceConnected()", e);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
235 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
236 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
237 public void onServiceDisconnected(ComponentName classNam) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
238 bound = null;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
239 Log.i(TAG, "unbound from service");
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
240 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
241 };
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
242
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
243
172
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
244 public TerminalMonitor(Context parent, vt320 buffer, View view, HostBean host, String init) {
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
245 this.parent = parent;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
246 this.buffer = buffer;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
247 this.view = view;
172
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
248 this.host = host;
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
249 this.init = init;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
250 // setup the windows->android keymapping
19
b3d0d806cbe2 cleaner url for MS vk_ key documentation
Carl Byington <carl@five-ten-sg.com>
parents: 18
diff changeset
251 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731
112
77ac18bc1b2f cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 101
diff changeset
252 keymap = new HashMap<Integer, Integer>();
113
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
253 keymap.put(0x08, vt320.KEY_BACK_SPACE); // vk_back
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
254 keymap.put(0x09, vt320.KEY_TAB); // vk_tab
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
255 keymap.put(0x0d, vt320.KEY_ENTER); // vk_return
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
256 keymap.put(0x1b, vt320.KEY_ESCAPE); // vk_escape
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
257 keymap.put(0x21, vt320.KEY_PAGE_UP); // vk_prior
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
258 keymap.put(0x22, vt320.KEY_PAGE_DOWN); // vk_next
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
259 keymap.put(0x23, vt320.KEY_END); // vk_end
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
260 keymap.put(0x24, vt320.KEY_HOME); // vk_home
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
261 keymap.put(0x25, vt320.KEY_LEFT); // vk_left
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
262 keymap.put(0x26, vt320.KEY_UP); // vk_up
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
263 keymap.put(0x27, vt320.KEY_RIGHT); // vk_right
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
264 keymap.put(0x28, vt320.KEY_DOWN); // vk_down
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
265 keymap.put(0x2d, vt320.KEY_INSERT); // vk_insert
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
266 keymap.put(0x2e, vt320.KEY_DELETE); // vk_delete
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
267 keymap.put(0x70, vt320.KEY_F1); // vk_f1
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
268 keymap.put(0x71, vt320.KEY_F2); // vk_f2
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
269 keymap.put(0x72, vt320.KEY_F3); // vk_f3
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
270 keymap.put(0x73, vt320.KEY_F4); // vk_f4
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
271 keymap.put(0x74, vt320.KEY_F5); // vk_f5
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
272 keymap.put(0x75, vt320.KEY_F6); // vk_f6
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
273 keymap.put(0x76, vt320.KEY_F7); // vk_f7
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
274 keymap.put(0x77, vt320.KEY_F8); // vk_f8
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
275 keymap.put(0x78, vt320.KEY_F9); // vk_f9
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
276 keymap.put(0x79, vt320.KEY_F10); // vk_f10
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
277 keymap.put(0x7a, vt320.KEY_F11); // vk_f11
cb3b9b660b3d depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents: 112
diff changeset
278 keymap.put(0x7b, vt320.KEY_F12); // vk_f12
176
6e07ea418b90 add f13 thru f24 keys
Carl Byington <carl@five-ten-sg.com>
parents: 175
diff changeset
279 keymap.put(0x7c, vt320.KEY_F13); // vk_f13
6e07ea418b90 add f13 thru f24 keys
Carl Byington <carl@five-ten-sg.com>
parents: 175
diff changeset
280 keymap.put(0x7d, vt320.KEY_F14); // vk_f14
6e07ea418b90 add f13 thru f24 keys
Carl Byington <carl@five-ten-sg.com>
parents: 175
diff changeset
281 keymap.put(0x7e, vt320.KEY_F15); // vk_f15
6e07ea418b90 add f13 thru f24 keys
Carl Byington <carl@five-ten-sg.com>
parents: 175
diff changeset
282 keymap.put(0x7f, vt320.KEY_F16); // vk_f16
6e07ea418b90 add f13 thru f24 keys
Carl Byington <carl@five-ten-sg.com>
parents: 175
diff changeset
283 keymap.put(0x80, vt320.KEY_F17); // vk_f17
6e07ea418b90 add f13 thru f24 keys
Carl Byington <carl@five-ten-sg.com>
parents: 175
diff changeset
284 keymap.put(0x81, vt320.KEY_F18); // vk_f18
6e07ea418b90 add f13 thru f24 keys
Carl Byington <carl@five-ten-sg.com>
parents: 175
diff changeset
285 keymap.put(0x82, vt320.KEY_F19); // vk_f19
6e07ea418b90 add f13 thru f24 keys
Carl Byington <carl@five-ten-sg.com>
parents: 175
diff changeset
286 keymap.put(0x83, vt320.KEY_F20); // vk_f20
6e07ea418b90 add f13 thru f24 keys
Carl Byington <carl@five-ten-sg.com>
parents: 175
diff changeset
287 keymap.put(0x84, vt320.KEY_F21); // vk_f21
6e07ea418b90 add f13 thru f24 keys
Carl Byington <carl@five-ten-sg.com>
parents: 175
diff changeset
288 keymap.put(0x85, vt320.KEY_F22); // vk_f22
6e07ea418b90 add f13 thru f24 keys
Carl Byington <carl@five-ten-sg.com>
parents: 175
diff changeset
289 keymap.put(0x86, vt320.KEY_F23); // vk_f23
6e07ea418b90 add f13 thru f24 keys
Carl Byington <carl@five-ten-sg.com>
parents: 175
diff changeset
290 keymap.put(0x87, vt320.KEY_F24); // vk_f24
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
291 // bind to the monitor service
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
292 Intent intent = new Intent("com.five_ten_sg.connectbot.monitor.MonitorService");
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
293 parent.bindService(intent, monitor_connection, Context.BIND_AUTO_CREATE);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
294 Log.i(TAG, "constructor");
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
295 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
296
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
297
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
298 public void Disconnect() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
299 if (monitor_reader != null) monitor_reader.closing();
397
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
300 if (monitor_writer != null) monitor_writer.closing();
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
301 try {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
302 if (monitor_out != null) monitor_out.close();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
303
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
304 if (monitor_in != null) monitor_in.close();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
305
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
306 if (monitor_socket != null) monitor_socket.close();
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
307
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
308 Log.i(TAG, "disconnected from monitor socket");
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
309 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
310 catch (IOException e) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
311 Log.e(TAG, "exception in Disconnect() closing sockets", e);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
312 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
313
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
314 monitor_reader = null;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
315 monitor_out = null;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
316 monitor_in = null;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
317 monitor_socket = null;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
318
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
319 if (bound != null) parent.unbindService(monitor_connection);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
320
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
321 monitor_connection = null;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
322 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
323
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
324
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
325 public char[] bytesToChars(byte[] b, int len) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
326 char[] c = new char[len >> 1];
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
327 int bp = 0;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
328
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
329 for (int i = 0; i < c.length; i++) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
330 byte b1 = b[bp++];
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
331 byte b2 = b[bp++];
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
332 c[i] = (char)(((b1 & 0x00FF) << 8) + (b2 & 0x00FF));
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
333 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
334
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
335 return c;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
336 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
337
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
338
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
339 public byte[] charsToBytes(char[] c) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
340 byte[] b = new byte[c.length << 1];
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
341 int bp = 0;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
342
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
343 for (int i = 0; i < c.length; i++) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
344 b[bp++] = (byte)((c[i] & 0xff00) >> 8);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
345 b[bp++] = (byte)(c[i] & 0x00ff);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
346 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
347
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
348 return b;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
349 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
350
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
351
397
2f2b5a244a4d add queue to buffer monitor socket writes to prevent blocking on socket output stream write
Carl Byington <carl@five-ten-sg.com>
parents: 307
diff changeset
352 public void monitorWrite(char cmd, char[] c) {
400
e856ecf87b10 Backed out changeset aeb8c2e6d83a
Carl Byington <carl@five-ten-sg.com>
parents: 399
diff changeset
353 c[1] = cmd;
e856ecf87b10 Backed out changeset aeb8c2e6d83a
Carl Byington <carl@five-ten-sg.com>
parents: 399
diff changeset
354 pending_commands.put(c);
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
355 };
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
356
227
2dd627df4dfb delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents: 212
diff changeset
357 public void resetWatch() {
2dd627df4dfb delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents: 212
diff changeset
358 start_line = 0;
2dd627df4dfb delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents: 212
diff changeset
359 end_line = 500;
2dd627df4dfb delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents: 212
diff changeset
360 start_column = 0;
2dd627df4dfb delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents: 212
diff changeset
361 end_column = 500;
2dd627df4dfb delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents: 212
diff changeset
362 };
2dd627df4dfb delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents: 212
diff changeset
363
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
364 public void sendScreen(char cmd) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
365 char lines = (char)(buffer.height & 0x0000ffff);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
366 char columns = (char)(buffer.width & 0x0000ffff);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
367 char[] arg = new char[4 + lines * columns];
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
368 arg[2] = lines;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
369 arg[3] = columns;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
370 int base = 4;
112
77ac18bc1b2f cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 101
diff changeset
371
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
372 for (int i = 0; i < lines; i++) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
373 System.arraycopy(buffer.charArray[buffer.screenBase + i], 0, arg, base, columns);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
374 base += columns;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
375 }
112
77ac18bc1b2f cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 101
diff changeset
376
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
377 monitorWrite(cmd, arg);
227
2dd627df4dfb delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents: 212
diff changeset
378 resetWatch();
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
379 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
380
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
381 public synchronized void activate() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
382 sendScreen(MONITOR_CMD_ACTIVATE);
235
ea49747c5447 activate needs to send a cursor update
Carl Byington <carl@five-ten-sg.com>
parents: 229
diff changeset
383 cursorMoved(CURSOR_SCREEN_CHANGE);
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
384 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
385
148
69333ca1563c add ptt button p2 preference
Carl Byington <carl@five-ten-sg.com>
parents: 147
diff changeset
386 public synchronized void keyState(boolean down) {
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
387 char[] arg = new char[3];
148
69333ca1563c add ptt button p2 preference
Carl Byington <carl@five-ten-sg.com>
parents: 147
diff changeset
388 arg[2] = (char)((down) ? 1 : 0);
147
1350adb077b1 monitor key state tracking
Carl Byington <carl@five-ten-sg.com>
parents: 145
diff changeset
389 monitorWrite(MONITOR_CMD_KEYSTATE, arg);
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
390 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
391
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
392 public synchronized void cursorMove(int l, int c) {
229
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
393 if ((to_line != l) || (to_column != c)) moved = true;
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 252
diff changeset
394
17
02717d15de9b delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents: 16
diff changeset
395 to_line = l;
16
48a8daea9221 delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents: 15
diff changeset
396 to_column = c;
48a8daea9221 delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents: 15
diff changeset
397 }
48a8daea9221 delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents: 15
diff changeset
398
229
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
399 public void cursorMoved(char why) {
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
400 char[] arg = new char[5];
18
49fc5fba28f3 delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents: 17
diff changeset
401 arg[2] = (char)(to_line & 0x0000ffff);
49fc5fba28f3 delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents: 17
diff changeset
402 arg[3] = (char)(to_column & 0x0000ffff);
229
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
403 arg[4] = why;
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
404 monitorWrite(MONITOR_CMD_CURSORMOVE, arg);
229
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
405 moved = false;
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
406 }
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
407
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
408 public void testMoved() {
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
409 if (moved) cursorMoved(CURSOR_USER_KEY);
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
410 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
411
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
412 public synchronized void testChanged() {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
413 if (modified) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
414 modified = false;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
415 sendScreen(MONITOR_CMD_SCREENCHANGE);
229
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
416 cursorMoved(CURSOR_SCREEN_CHANGE);
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
417 }
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
418 else {
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
419 if (moved) cursorMoved(CURSOR_SCREEN_CHANGE);
16
48a8daea9221 delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents: 15
diff changeset
420 }
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
421 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
422
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
423 public synchronized void screenChanged(int llow, int lhigh, int clow, int chigh) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
424 if ((start_line <= lhigh) && (llow <= end_line) && (start_column <= chigh) && (clow <= end_column)) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
425 modified = true;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
426 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
427 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
428
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
429 public synchronized void screenChanged(int l, int c) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
430 screenChanged(l, l, c, c);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
431 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
432
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
433 public synchronized void setField(int l, int c, char[] data, int offset) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
434 Log.i(TAG, "setField()");
250
2bf2724d8610 add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents: 235
diff changeset
435 int len = data.length - offset;
2bf2724d8610 add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents: 235
diff changeset
436 char[] da = new char[len];
2bf2724d8610 add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents: 235
diff changeset
437 System.arraycopy(data, offset, da, 0, len);
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 252
diff changeset
438
250
2bf2724d8610 add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents: 235
diff changeset
439 if ((l > 60000) || (c > 60000)) {
2bf2724d8610 add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents: 235
diff changeset
440 l = -1;
2bf2724d8610 add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents: 235
diff changeset
441 c = -1;
2bf2724d8610 add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents: 235
diff changeset
442 }
2bf2724d8610 add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents: 235
diff changeset
443 else {
2bf2724d8610 add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents: 235
diff changeset
444 // ignore setfield outside screen boundaries
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 252
diff changeset
445 if ((l >= buffer.height) || (c + len >= buffer.width)) return;
250
2bf2724d8610 add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents: 235
diff changeset
446 }
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 252
diff changeset
447
100
9204fe526e65 finish setField()
Carl Byington <carl@five-ten-sg.com>
parents: 79
diff changeset
448 buffer.setField(l, c, da);
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
449 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
450
155
156b53fc4815 add showurl command
Carl Byington <carl@five-ten-sg.com>
parents: 153
diff changeset
451 public synchronized void showUrl(char [] data, int offset) {
156b53fc4815 add showurl command
Carl Byington <carl@five-ten-sg.com>
parents: 153
diff changeset
452 Log.i(TAG, "setField()");
156b53fc4815 add showurl command
Carl Byington <carl@five-ten-sg.com>
parents: 153
diff changeset
453 char[] da = new char[data.length - offset];
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 252
diff changeset
454 System.arraycopy(data, offset, da, 0, data.length - offset);
155
156b53fc4815 add showurl command
Carl Byington <carl@five-ten-sg.com>
parents: 153
diff changeset
455 String url = new String(da);
156b53fc4815 add showurl command
Carl Byington <carl@five-ten-sg.com>
parents: 153
diff changeset
456 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
156b53fc4815 add showurl command
Carl Byington <carl@five-ten-sg.com>
parents: 153
diff changeset
457 parent.startActivity(intent);
156b53fc4815 add showurl command
Carl Byington <carl@five-ten-sg.com>
parents: 153
diff changeset
458 }
156b53fc4815 add showurl command
Carl Byington <carl@five-ten-sg.com>
parents: 153
diff changeset
459
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
460 public synchronized void getField(int l, int c, int len) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
461 Log.i(TAG, "getField()");
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
462 char[] arg2 = new char[4 + len];
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
463 arg2[2] = (char)(l & 0x0000ffff);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
464 arg2[3] = (char)(c & 0x0000ffff);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
465 int base = 4;
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 252
diff changeset
466
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 252
diff changeset
467 if ((l >= buffer.height) || (c + len >= buffer.width)) {
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 252
diff changeset
468 Arrays.fill(arg2, base, len - 1, ' ');
250
2bf2724d8610 add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents: 235
diff changeset
469 }
2bf2724d8610 add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents: 235
diff changeset
470 else {
2bf2724d8610 add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents: 235
diff changeset
471 System.arraycopy(buffer.charArray[buffer.screenBase + l], c, arg2, base, len);
2bf2724d8610 add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents: 235
diff changeset
472 }
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 252
diff changeset
473
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
474 monitorWrite(MONITOR_CMD_FIELDVALUE, arg2);
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
475 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
476
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
477 public synchronized void screenWatch(int l, int c, int len) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
478 Log.i(TAG, "screenWatch()");
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
479 start_line = l;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
480 end_line = l;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
481 start_column = c;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
482 end_column = c + len - 1;
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
483 }
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
484
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
485 public synchronized void depress(int vk_key) {
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
486 Log.i(TAG, String.format("depress() %d", vk_key));
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
487 Integer x = keymap.get(new Integer(vk_key));
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 252
diff changeset
488
175
2a7199ad90be send cursor movement caused by user keystrokes to the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 174
diff changeset
489 if (x != null) buffer.keyDepressed(x, ' ', 0);
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
490 }
172
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
491
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
492 public synchronized void switchSession() {
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
493 Log.i(TAG, "switchSession()");
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
494 Intent intent = new Intent(parent, ConsoleActivity.class);
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
495 intent.setAction(Intent.ACTION_VIEW);
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
496 intent.setData(host.getUri());
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
497 parent.startActivity(intent);
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
498 }
cb9e359ea2bd add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents: 155
diff changeset
499
205
f86f1e37b504 add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
500
f86f1e37b504 add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
501 public synchronized void cursorRequest() {
f86f1e37b504 add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
502 Log.i(TAG, "cursorRequest()");
229
594101a0876a add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents: 227
diff changeset
503 cursorMoved(CURSOR_REQUESTED);
205
f86f1e37b504 add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
504 }
f86f1e37b504 add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
505
0
0ce5cc452d02 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
506 }