Mercurial > 510Connectbot
annotate app/src/main/java/com/five_ten_sg/connectbot/service/TerminalMonitor.java @ 459:a3239022798d
compile 32 and 64 bit arch, bump version
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Sun, 28 Apr 2019 17:06:20 -0700 |
parents | 105815cce146 |
children | 4776062555f3 |
rev | line source |
---|---|
0 | 1 package com.five_ten_sg.connectbot.service; |
2 | |
3 import android.content.ComponentName; | |
4 import android.content.Context; | |
5 import android.content.Intent; | |
6 import android.content.ServiceConnection; | |
155 | 7 import android.net.Uri; |
0 | 8 import android.os.IBinder; |
9 import android.util.Log; | |
10 import android.view.View; | |
11 import de.mud.terminal.vt320; | |
12 import java.io.IOException; | |
13 import java.io.InputStream; | |
14 import java.io.OutputStream; | |
15 import java.net.InetAddress; | |
16 import java.net.Socket; | |
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 | 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 | 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 | 28 public class TerminalMonitor { |
457
105815cce146
minimum version android 5, target and compile version api 28
Carl Byington <carl@five-ten-sg.com>
parents:
438
diff
changeset
|
29 public final static String TAG = "ConnectBot.TermMonitor"; |
0 | 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; |
459
a3239022798d
compile 32 and 64 bit arch, bump version
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
44 public static final char MONITOR_CMD_SAYSTRING = 12; |
0 | 45 |
424
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
46 public static final String[] commands = { |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
47 "cmd_init", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
48 "cmd_activate", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
49 "cmd_keystate", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
50 "cmd_cursormove", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
51 "cmd_screenchange", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
52 "cmd_fieldvalue/setfield", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
53 "cmd_getfield", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
54 "cmd_screenwatch", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
55 "cmd_depress", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
56 "cmd_showurl", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
57 "cmd_switchsession", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
58 "cmd_cursorrequest" |
459
a3239022798d
compile 32 and 64 bit arch, bump version
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
59 "cmd_saystring" |
424
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
60 }; |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
61 |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
62 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
|
63 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
|
64 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
|
65 |
0 | 66 private static final int MONITORPORT = 6000; |
67 private static final String LOCALHOST = "127.0.0.1"; | |
68 | |
69 private Context parent = null; | |
70 private vt320 buffer = null; | |
71 private View view = null; | |
174
b010f9dc801f
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
173
diff
changeset
|
72 private HostBean host = null; |
0 | 73 private String init = null; |
74 private int start_line = 0; // monitor part of the screen for changes | |
75 private int end_line = 500; // "" | |
76 private int start_column = 0; // "" | |
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 private HashMap<Integer, Integer> keymap = null; // map MS VK_ keys to vt320 virtual keys |
0 | 83 private IBinder bound = null; |
84 private Socket monitor_socket = null; | |
85 private InputStream monitor_in = null; | |
86 private OutputStream monitor_out = null; | |
87 private MyReader monitor_reader = null; | |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
88 private BlockingQueue<char[]> pending_commands = new ArrayBlockingQueue<char[]>(100); |
0 | 89 private MyServiceConnection monitor_connection = new MyServiceConnection(); |
90 | |
91 class MyReader extends Thread { | |
92 private InputStream monitor_in; | |
93 private byte[] b; | |
94 private boolean is_closing = false; | |
95 | |
96 public MyReader(InputStream monitor_in) { | |
97 this.monitor_in = monitor_in; | |
98 b = new byte[100]; | |
99 Log.i(TAG, "MyReader constructor"); | |
100 } | |
101 | |
102 public void closing() { | |
103 is_closing = true; | |
104 } | |
105 | |
106 private char[] forceRead(int len) throws IOException { | |
107 int len2 = len * 2; | |
108 int off = 0; | |
109 | |
110 if (b.length < len2) b = new byte[len2]; | |
111 | |
112 while (off < len2) { | |
113 int l = monitor_in.read(b, off, len2 - off); | |
114 | |
115 if (l < 0) throw new IOException("eof"); | |
116 | |
117 off += l; | |
118 } | |
119 | |
120 return bytesToChars(b, len2); | |
121 } | |
122 | |
123 public void run() { | |
124 while (true) { | |
125 try { | |
126 char[] len = forceRead(1); | |
127 char[] packet = forceRead(len[0]); | |
128 char cmd = packet[0]; | |
425 | 129 Log.i(TAG, String.format("received %s", commands[cmd])); |
0 | 130 |
131 switch (cmd) { | |
132 case MONITOR_CMD_SETFIELD: | |
153
3ca280646f2d
allow zero length setfield
Carl Byington <carl@five-ten-sg.com>
parents:
148
diff
changeset
|
133 if (packet.length >= 3) |
0 | 134 setField(packet[1], packet[2], packet, 3); |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
135 |
0 | 136 break; |
137 | |
138 case MONITOR_CMD_GETFIELD: | |
139 if (packet.length == 4) | |
140 getField(packet[1], packet[2], packet[3]); | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
141 |
0 | 142 break; |
143 | |
144 case MONITOR_CMD_SCREENWATCH: | |
145 if (packet.length == 4) | |
146 screenWatch(packet[1], packet[2], packet[3]); | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
147 |
0 | 148 break; |
149 | |
150 case MONITOR_CMD_DEPRESS: | |
151 if (packet.length == 2) | |
152 depress(packet[1]); | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
153 |
0 | 154 break; |
155 | |
155 | 156 case MONITOR_CMD_SHOWURL: |
157 if (packet.length > 1) | |
158 showUrl(packet, 1); | |
159 | |
160 break; | |
161 | |
173
5f26d0ba6abd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
162 case MONITOR_CMD_SWITCHSESSION: |
172
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
163 if (packet.length == 1) |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
164 switchSession(); |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
165 |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
166 break; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
167 |
205
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
168 case MONITOR_CMD_CURSORREQUEST: |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
169 if (packet.length == 1) |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
170 cursorRequest(); |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
171 |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
172 break; |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
173 |
0 | 174 default: |
175 break; | |
176 } | |
177 } | |
178 catch (IOException e) { | |
179 if (!is_closing) Log.e(TAG, "exception in MyReader.run()", e); | |
180 | |
181 break; | |
182 } | |
183 } | |
184 } | |
185 } | |
186 | |
187 class MyServiceConnection implements ServiceConnection { | |
188 public void onServiceConnected(ComponentName className, IBinder service) { | |
189 bound = service; | |
190 Log.i(TAG, "bound to service"); | |
191 | |
192 try { | |
193 InetAddress serverAddr = InetAddress.getByName(LOCALHOST); | |
410
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
194 int tries = 0; |
411
8bff0bfaec3a
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
410
diff
changeset
|
195 while (tries < 10) { |
410
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
196 try { |
411
8bff0bfaec3a
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
410
diff
changeset
|
197 Thread.sleep(100); |
410
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
198 monitor_socket = new Socket(serverAddr, MONITORPORT); |
421
660ac2d2003b
break out of infinite loop
Carl Byington <carl@five-ten-sg.com>
parents:
418
diff
changeset
|
199 break; |
410
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
200 } |
412
057854c77217
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
411
diff
changeset
|
201 catch (Exception e) { |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
202 monitor_socket = null; |
410
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
203 Log.e(TAG, "exception connecting to monitor socket", e); |
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
204 tries = tries + 1; |
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
205 } |
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
206 } |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
207 if (monitor_socket != null) { |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
208 Log.i(TAG, "connected to monitor socket, send init " + init); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
209 monitor_in = monitor_socket.getInputStream(); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
210 monitor_out = monitor_socket.getOutputStream(); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
211 monitor_reader = new MyReader(monitor_in); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
212 monitor_reader.start(); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
213 String x = " " + init; |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
214 monitorWrite(MONITOR_CMD_INIT, x.toCharArray()); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
215 char [] c; |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
216 |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
217 while (true) { |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
218 c = pending_commands.poll(); |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
219 |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
220 if (c == null) break; |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
221 |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
222 monitorWrite(c[1], c); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
223 } |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
224 } |
0 | 225 } |
226 catch (IOException e) { | |
227 Log.e(TAG, "exception in onServiceConnected()", e); | |
228 } | |
229 } | |
230 public void onServiceDisconnected(ComponentName classNam) { | |
231 bound = null; | |
232 Log.i(TAG, "unbound from service"); | |
233 } | |
234 }; | |
235 | |
236 | |
172
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
237 public TerminalMonitor(Context parent, vt320 buffer, View view, HostBean host, String init) { |
0 | 238 this.parent = parent; |
239 this.buffer = buffer; | |
240 this.view = view; | |
172
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
241 this.host = host; |
0 | 242 this.init = init; |
243 // 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
|
244 // 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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 keymap.put(0x7b, vt320.KEY_F12); // vk_f12 |
176 | 272 keymap.put(0x7c, vt320.KEY_F13); // vk_f13 |
273 keymap.put(0x7d, vt320.KEY_F14); // vk_f14 | |
274 keymap.put(0x7e, vt320.KEY_F15); // vk_f15 | |
275 keymap.put(0x7f, vt320.KEY_F16); // vk_f16 | |
276 keymap.put(0x80, vt320.KEY_F17); // vk_f17 | |
277 keymap.put(0x81, vt320.KEY_F18); // vk_f18 | |
278 keymap.put(0x82, vt320.KEY_F19); // vk_f19 | |
279 keymap.put(0x83, vt320.KEY_F20); // vk_f20 | |
280 keymap.put(0x84, vt320.KEY_F21); // vk_f21 | |
281 keymap.put(0x85, vt320.KEY_F22); // vk_f22 | |
282 keymap.put(0x86, vt320.KEY_F23); // vk_f23 | |
283 keymap.put(0x87, vt320.KEY_F24); // vk_f24 | |
0 | 284 // bind to the monitor service |
285 Intent intent = new Intent("com.five_ten_sg.connectbot.monitor.MonitorService"); | |
457
105815cce146
minimum version android 5, target and compile version api 28
Carl Byington <carl@five-ten-sg.com>
parents:
438
diff
changeset
|
286 intent.setPackage("com.five_ten_sg.connectbot.monitor"); |
0 | 287 parent.bindService(intent, monitor_connection, Context.BIND_AUTO_CREATE); |
288 Log.i(TAG, "constructor"); | |
289 } | |
290 | |
291 | |
292 public void Disconnect() { | |
293 if (monitor_reader != null) monitor_reader.closing(); | |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
294 |
0 | 295 try { |
296 if (monitor_out != null) monitor_out.close(); | |
297 | |
298 if (monitor_in != null) monitor_in.close(); | |
299 | |
300 if (monitor_socket != null) monitor_socket.close(); | |
301 | |
302 Log.i(TAG, "disconnected from monitor socket"); | |
303 } | |
304 catch (IOException e) { | |
305 Log.e(TAG, "exception in Disconnect() closing sockets", e); | |
306 } | |
307 | |
308 monitor_reader = null; | |
309 monitor_out = null; | |
310 monitor_in = null; | |
311 monitor_socket = null; | |
312 | |
313 if (bound != null) parent.unbindService(monitor_connection); | |
314 | |
315 monitor_connection = null; | |
316 } | |
317 | |
318 | |
319 public char[] bytesToChars(byte[] b, int len) { | |
320 char[] c = new char[len >> 1]; | |
321 int bp = 0; | |
322 | |
323 for (int i = 0; i < c.length; i++) { | |
324 byte b1 = b[bp++]; | |
325 byte b2 = b[bp++]; | |
326 c[i] = (char)(((b1 & 0x00FF) << 8) + (b2 & 0x00FF)); | |
327 } | |
328 | |
329 return c; | |
330 } | |
331 | |
332 | |
333 public byte[] charsToBytes(char[] c) { | |
334 byte[] b = new byte[c.length << 1]; | |
335 int bp = 0; | |
336 | |
337 for (int i = 0; i < c.length; i++) { | |
338 b[bp++] = (byte)((c[i] & 0xff00) >> 8); | |
339 b[bp++] = (byte)(c[i] & 0x00ff); | |
340 } | |
341 | |
342 return b; | |
343 } | |
344 | |
345 | |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
346 public synchronized void monitorWrite(char cmd, char[] c) { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
347 try { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
348 if (monitor_out != null) { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
349 c[0] = (char)(c.length - 1); // number of chars following |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
350 c[1] = cmd; |
424
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
351 Log.i(TAG, String.format("sending %s", commands[cmd])); |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
352 monitor_out.write(charsToBytes(c)); |
424
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
353 monitor_out.flush(); |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
354 } |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
355 else { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
356 c[1] = cmd; |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
357 pending_commands.offer(c); |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
358 } |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
359 } |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
360 catch (IOException e) { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
361 Log.i(TAG, "exception in monitorWrite(), monitor died or closed the socket", e); |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
362 |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
363 try { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
364 monitor_out.close(); |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
365 } |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
366 catch (IOException ee) { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
367 Log.e(TAG, "exception in monitorWrite() closing output stream", ee); |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
368 } |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
369 |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
370 monitor_out = null; |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
371 } |
0 | 372 }; |
373 | |
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
|
374 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
|
375 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
|
376 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
|
377 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
|
378 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
|
379 }; |
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
|
380 |
0 | 381 public void sendScreen(char cmd) { |
382 char lines = (char)(buffer.height & 0x0000ffff); | |
383 char columns = (char)(buffer.width & 0x0000ffff); | |
384 char[] arg = new char[4 + lines * columns]; | |
385 arg[2] = lines; | |
386 arg[3] = columns; | |
387 int base = 4; | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
388 |
0 | 389 for (int i = 0; i < lines; i++) { |
390 System.arraycopy(buffer.charArray[buffer.screenBase + i], 0, arg, base, columns); | |
391 base += columns; | |
392 } | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
393 |
0 | 394 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
|
395 resetWatch(); |
0 | 396 } |
397 | |
398 public synchronized void activate() { | |
399 sendScreen(MONITOR_CMD_ACTIVATE); | |
235
ea49747c5447
activate needs to send a cursor update
Carl Byington <carl@five-ten-sg.com>
parents:
229
diff
changeset
|
400 cursorMoved(CURSOR_SCREEN_CHANGE); |
0 | 401 } |
402 | |
148
69333ca1563c
add ptt button p2 preference
Carl Byington <carl@five-ten-sg.com>
parents:
147
diff
changeset
|
403 public synchronized void keyState(boolean down) { |
0 | 404 char[] arg = new char[3]; |
148
69333ca1563c
add ptt button p2 preference
Carl Byington <carl@five-ten-sg.com>
parents:
147
diff
changeset
|
405 arg[2] = (char)((down) ? 1 : 0); |
147
1350adb077b1
monitor key state tracking
Carl Byington <carl@five-ten-sg.com>
parents:
145
diff
changeset
|
406 monitorWrite(MONITOR_CMD_KEYSTATE, arg); |
0 | 407 } |
408 | |
409 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
|
410 if ((to_line != l) || (to_column != c)) moved = true; |
307 | 411 |
17
02717d15de9b
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
16
diff
changeset
|
412 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
|
413 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
|
414 } |
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
415 |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
416 public void cursorMoved(char why) { |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
417 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
|
418 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
|
419 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
|
420 arg[4] = why; |
0 | 421 monitorWrite(MONITOR_CMD_CURSORMOVE, arg); |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
422 moved = false; |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
423 } |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
424 |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
425 public void testMoved() { |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
426 if (moved) cursorMoved(CURSOR_USER_KEY); |
0 | 427 } |
428 | |
429 public synchronized void testChanged() { | |
430 if (modified) { | |
431 modified = false; | |
432 sendScreen(MONITOR_CMD_SCREENCHANGE); | |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
433 cursorMoved(CURSOR_SCREEN_CHANGE); |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
434 } |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
435 else { |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
436 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
|
437 } |
0 | 438 } |
439 | |
440 public synchronized void screenChanged(int llow, int lhigh, int clow, int chigh) { | |
441 if ((start_line <= lhigh) && (llow <= end_line) && (start_column <= chigh) && (clow <= end_column)) { | |
442 modified = true; | |
443 } | |
444 } | |
445 | |
446 public synchronized void screenChanged(int l, int c) { | |
447 screenChanged(l, l, c, c); | |
448 } | |
449 | |
450 public synchronized void setField(int l, int c, char[] data, int offset) { | |
250
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
451 int len = data.length - offset; |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
452 char[] da = new char[len]; |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
453 System.arraycopy(data, offset, da, 0, len); |
422
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
421
diff
changeset
|
454 Log.i(TAG, String.format("setField(line %d, col %d, value %s)", l, c, new String(da))); |
307 | 455 |
250
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
456 if ((l > 60000) || (c > 60000)) { |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
457 l = -1; |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
458 c = -1; |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
459 } |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
460 else { |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
461 // ignore setfield outside screen boundaries |
405
d3c5480e8441
fix broken fillRegenerationBuffer/fillScreenArray attempt to handle missing attributes; fix setfield outside screen boundaries
Carl Byington <carl@five-ten-sg.com>
parents:
404
diff
changeset
|
462 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
|
463 } |
307 | 464 |
100 | 465 buffer.setField(l, c, da); |
0 | 466 } |
467 | |
155 | 468 public synchronized void showUrl(char [] data, int offset) { |
469 char[] da = new char[data.length - offset]; | |
307 | 470 System.arraycopy(data, offset, da, 0, data.length - offset); |
155 | 471 String url = new String(da); |
472 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); | |
473 parent.startActivity(intent); | |
474 } | |
475 | |
0 | 476 public synchronized void getField(int l, int c, int len) { |
422
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
421
diff
changeset
|
477 Log.i(TAG, String.format("getField(line %d, col %d, len %d)", l, c, len)); |
0 | 478 char[] arg2 = new char[4 + len]; |
479 arg2[2] = (char)(l & 0x0000ffff); | |
480 arg2[3] = (char)(c & 0x0000ffff); | |
481 int base = 4; | |
307 | 482 |
404
ec74f347ab5f
fix bad args to arrays.fill(); bump version number
Carl Byington <carl@five-ten-sg.com>
parents:
402
diff
changeset
|
483 if ((l >= buffer.height) || (c + len > buffer.width)) { |
ec74f347ab5f
fix bad args to arrays.fill(); bump version number
Carl Byington <carl@five-ten-sg.com>
parents:
402
diff
changeset
|
484 Arrays.fill(arg2, base, base + len, ' '); |
250
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
485 } |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
486 else { |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
487 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
|
488 } |
307 | 489 |
422
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
421
diff
changeset
|
490 char[] da = new char[len]; |
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
421
diff
changeset
|
491 System.arraycopy(arg2, base, da, 0, len); |
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
421
diff
changeset
|
492 Log.i(TAG, String.format("getField value %s", new String(da))); |
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
421
diff
changeset
|
493 |
0 | 494 monitorWrite(MONITOR_CMD_FIELDVALUE, arg2); |
495 } | |
496 | |
497 public synchronized void screenWatch(int l, int c, int len) { | |
425 | 498 Log.i(TAG, String.format("screenWatch(line %d, col %d, len %d)", l, c, len)); |
0 | 499 start_line = l; |
500 end_line = l; | |
501 start_column = c; | |
502 end_column = c + len - 1; | |
503 } | |
504 | |
505 public synchronized void depress(int vk_key) { | |
425 | 506 Log.i(TAG, String.format("depress(%d)", vk_key)); |
0 | 507 Integer x = keymap.get(new Integer(vk_key)); |
307 | 508 |
175
2a7199ad90be
send cursor movement caused by user keystrokes to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
174
diff
changeset
|
509 if (x != null) buffer.keyDepressed(x, ' ', 0); |
0 | 510 } |
172
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
511 |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
512 public synchronized void switchSession() { |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
513 Log.i(TAG, "switchSession()"); |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
514 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
|
515 intent.setAction(Intent.ACTION_VIEW); |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
516 intent.setData(host.getUri()); |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
517 parent.startActivity(intent); |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
518 } |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
519 |
205
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
520 |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
521 public synchronized void cursorRequest() { |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
522 cursorMoved(CURSOR_REQUESTED); |
205
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
523 } |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
524 |
0 | 525 } |