System information
Appendix D. JAVA Example Code
D-15
private static void log_io(byte val, boolean transmitted)
{
if(io_last_tx != transmitted && io_log_len > 0)
flush_io_log("");
io_log[io_log_len++] = val;
io_last_tx = transmitted;
if(io_log_len == io_log.length)
flush_io_log("");
}
private static void send_byte(byte val) throws IOException
{
log_io(val,true);
out_stream.write(val);
}
private static int read_byte() throws IOException
{
int rtn = in_stream.read();
log_io((byte)rtn,false);
return rtn;
}
protected static class Counter {
private static final int msecPerDay = 86400000;
private int start;
/** <!-- Counter() -->
* Construct and initialize start time to the current time.
*/
public Counter()
{
start = counter();
}
/** <!-- Counter(int) -->
* Construct and initialize start time to the specified value.
*
* @param msec initial value for counter (milliseconds)
*/
public Counter( int msec ) { this.start = msec; }
/** <!-- reset() -->
* Returns elapsed milliseconds and resets start time to now.
*
* @return elapsed milliseconds prior to reset
* @see #elapsed
*/
public int reset() {
int now = counter();
int elapsed = diff( now, start );
start = now;
return elapsed;
}