1 package diku
.distlab
.motecontrolclientlib
.client
;
2 import diku
.distlab
.motecontrolclientlib
.protocols
.*;
6 public class SimpleMote
extends Mote
{
8 protected SimpleMoteStatus status
;
9 protected SimpleMoteManager moteManager
;
10 protected PipedOutputStream dataOutput
;
11 protected Thread dataThread
;
13 protected SimpleMote(long id
,SimpleMoteManager moteManager
) {
15 this.moteManager
= moteManager
;
16 this.status
= new SimpleMoteStatus(this);
19 public SimpleMoteStatus
getStatus() {
23 protected void dataOut(MsgPayload data
)
25 if (dataOutput
!= null)
29 byte[] buf
= data
.getData();
30 dataOutput
.write(buf
);
35 //e.printStackTrace();
40 catch (IOException e2
){ e2
.printStackTrace();}
51 public void connectDataSource(final InputStream dataInput
)
53 // create a thread reading from the stream and creating data output
54 Runnable r
= new Runnable() {
56 BufferedInputStream input
= new BufferedInputStream(dataInput
);
63 skipped
= input
.skip(199);
64 bytes
= new byte[(int)skipped
];
67 moteManager
.sendData(id
,bytes
);
77 dataThread
= new Thread(r
);
81 public void connectDataSource(final PipedOutputStream source
)
83 // create a thread reading from the stream and creating data output
84 Runnable r
= new Runnable() {
87 PipedInputStream dataInput
= new PipedInputStream(source
);
88 BufferedInputStream input
= new BufferedInputStream(dataInput
);
94 skipped
= input
.skip(199);
95 bytes
= new byte[(int)skipped
];
98 moteManager
.sendData(id
,bytes
);
101 catch (Exception e
) {e
.printStackTrace();}
105 dataThread
= new Thread(r
);
109 public void connectDataSink(PipedInputStream sink
) throws IOException
113 if (this.dataOutput
!= null) this.dataOutput
.close();
115 catch (Exception e
) {e
.printStackTrace();}
118 this.dataOutput
= new PipedOutputStream(sink
);