BowlerKernel
java-bowler
src
main
java
com
neuronrobotics
sdk
dyio
DyIOInputStream.java
Go to the documentation of this file.
1
/*******************************************************************************
2
* Copyright 2010 Neuron Robotics, LLC
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
6
*
7
* http://www.apache.org/licenses/LICENSE-2.0
8
*
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
14
******************************************************************************/
15
package
com.neuronrobotics.sdk.dyio;
16
17
import
java.io.IOException;
18
import
java.io.InputStream;
19
20
import
com.neuronrobotics.sdk.common.ByteList;
21
22
// TODO: Auto-generated Javadoc
26
public
class
DyIOInputStream
extends
InputStream {
27
29
private
ByteList
buffer
=
new
ByteList
();
30
32
DyIOChannel
chan;
33
39
public
DyIOInputStream
(
DyIOChannel
channel) {
40
chan = channel;
41
}
42
48
public
void
write
(
ByteList
data) {
49
synchronized
(
buffer
) {
50
buffer
.
add
(data);
51
}
52
}
53
54
/* (non-Javadoc)
55
* @see java.io.InputStream#read()
56
*/
57
@Override
58
public
int
read
() throws IOException {
59
while
(chan.
getMode
() ==
DyIOChannelMode
.
USART_RX
) {
60
if
(
available
() > 0) {
61
// cast the poped byte as an int to make sure its positive
62
Byte val =
buffer
.
pop
();
63
64
if
(val ==
null
) {
65
continue
;
66
}
67
68
return
(
int
) val;
69
}
70
}
71
72
return
-1;
73
}
74
75
/* (non-Javadoc)
76
* @see java.io.InputStream#available()
77
*/
78
@Override
79
public
int
available
() {
80
return
buffer
.
size
();
81
}
82
}
com.neuronrobotics.sdk.common.ByteList
Definition:
ByteList.java:32
com.neuronrobotics.sdk.common.ByteList.pop
Byte pop(int index)
Definition:
ByteList.java:492
com.neuronrobotics.sdk.common.ByteList.add
synchronized boolean add(byte data)
Definition:
ByteList.java:149
com.neuronrobotics.sdk.common.ByteList.size
int size()
Definition:
ByteList.java:478
com.neuronrobotics.sdk.dyio.DyIOChannel
Definition:
DyIOChannel.java:39
com.neuronrobotics.sdk.dyio.DyIOChannel.getMode
DyIOChannelMode getMode(boolean resync)
Definition:
DyIOChannel.java:238
com.neuronrobotics.sdk.dyio.DyIOInputStream
Definition:
DyIOInputStream.java:26
com.neuronrobotics.sdk.dyio.DyIOInputStream.available
int available()
Definition:
DyIOInputStream.java:79
com.neuronrobotics.sdk.dyio.DyIOInputStream.DyIOInputStream
DyIOInputStream(DyIOChannel channel)
Definition:
DyIOInputStream.java:39
com.neuronrobotics.sdk.dyio.DyIOInputStream.read
int read()
Definition:
DyIOInputStream.java:58
com.neuronrobotics.sdk.dyio.DyIOInputStream.write
void write(ByteList data)
Definition:
DyIOInputStream.java:48
com.neuronrobotics.sdk.dyio.DyIOInputStream.buffer
ByteList buffer
Definition:
DyIOInputStream.java:29
com.neuronrobotics.sdk.dyio.DyIOChannelMode
Definition:
DyIOChannelMode.java:29
com.neuronrobotics.sdk.dyio.DyIOChannelMode.USART_RX
USART_RX
Definition:
DyIOChannelMode.java:59
Generated by
1.9.1