Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package dongfang.mkt.main;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import javax.swing.JFrame;
import dongfang.mkt.comm.FrameQueue;
import dongfang.mkt.comm.MKConnection;
import dongfang.mkt.comm.serial.RXTXSerialPort;
import dongfang.mkt.comm.tcp.MKTCPConnection;
import dongfang.mkt.frames.OSDDataRequestFrame;
import dongfang.mkt.frames.OSDDataResponseFrame;
import dongfang.mkt.ui.offscreendisplay.MapImageView;
import dongfang.mkt.ui.offscreendisplay.OSDDataConsumer;
import dongfang.mkt.ui.offscreendisplay.SimpleOSDView;
public class SimpleOSDTool
{
private static final PrintStream STDERR =
System.
out;
private void osd
(final FrameQueue q,
final OSDDataConsumer consumer,
final int interval
) throws IOException {
long timer =
0;
OSDDataRequestFrame f =
new OSDDataRequestFrame
();
f.
setAutoSendInterval(interval
);
BufferedReader in =
new BufferedReader(new InputStreamReader(System.
in));
Long firsttimestamp =
null;
while (!in.
ready())
try {
long now =
System.
currentTimeMillis();
if (now - timer
> 3000) {
timer = now
;
q.
sendRequest(f
);
}
OSDDataResponseFrame rf =
(OSDDataResponseFrame
) q.
getResponseFor(f,
5000);
long timestamp =
System.
currentTimeMillis();
if (firsttimestamp ==
null) {
firsttimestamp = timestamp
;
timestamp =
0;
} else {
timestamp -= firsttimestamp
;
}
consumer.
update(rf, timestamp
);
} catch (IOException ex
) {
STDERR.
println(ex
);
}
}
public static void main
(String[] args
) throws IOException {
SimpleOSDTool test =
new SimpleOSDTool
();
MKConnection _port =
new MKTCPConnection
(); // new RXTXSerialPort();
_port.
init("8080");
FrameQueue q =
new FrameQueue
(_port
);
SimpleOSDView v =
new SimpleOSDView
();
v.
init();
JFrame f =
new JFrame();
f.
getContentPane().
add(v
);
f.
setSize(v.
getSize());
f.
setVisible(true);
v.
setThatWidth();
test.
osd(q, v,
20);
}
}