added serial output for MicaZ

This commit is contained in:
joxe 2009-03-19 18:58:19 +00:00
parent 9ea19b4e81
commit 29f6ee7e98
3 changed files with 53 additions and 23 deletions

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: MicaZMote.java,v 1.5 2009/03/19 14:47:36 joxe Exp $
* $Id: MicaZMote.java,v 1.6 2009/03/19 18:58:19 joxe Exp $
*/
package se.sics.cooja.avrmote;
@ -43,6 +43,7 @@ import se.sics.cooja.MoteMemory;
import se.sics.cooja.MoteType;
import se.sics.cooja.Simulation;
import se.sics.cooja.avrmote.interfaces.MicaClock;
import se.sics.cooja.avrmote.interfaces.MicaSerial;
import se.sics.cooja.avrmote.interfaces.MicaZLED;
import se.sics.cooja.avrmote.interfaces.MicaZRadio;
import se.sics.cooja.interfaces.Position;
@ -273,8 +274,10 @@ public class MicaZMote implements Mote {
moteInterfaceHandler.addInterface(new MicaZLED(micaZ));
// Add Radio interface
moteInterfaceHandler.addInterface(new MicaZRadio(this));
// Add Radio interface
// Add Clock interface
moteInterfaceHandler.addInterface(new MicaClock(this));
// Add Serial interface
moteInterfaceHandler.addInterface(new MicaSerial(this));
return moteInterfaceHandler;

View file

@ -0,0 +1,47 @@
package se.sics.cooja.avrmote.interfaces;
import avrora.sim.mcu.AtmelMicrocontroller;
import avrora.sim.platform.MicaZ;
import se.sics.cooja.Mote;
import se.sics.cooja.avrmote.MicaZMote;
import se.sics.cooja.dialogs.SerialUI;
public class MicaSerial extends SerialUI {
Mote mote;
public MicaSerial(MicaZMote micaZMote) {
mote = micaZMote;
MicaZ micaZ = micaZMote.getMicaZ();
/* this should go into some other piece of code for serial data */
AtmelMicrocontroller mcu = (AtmelMicrocontroller) micaZ.getMicrocontroller();
avrora.sim.mcu.USART usart = (avrora.sim.mcu.USART) mcu.getDevice("usart0");
if (usart != null) {
usart.connect( new avrora.sim.mcu.USART.USARTDevice() {
public avrora.sim.mcu.USART.Frame transmitFrame() {
return null;
// return new avrora.sim.mcu.USART.Frame((byte)'a', false, 8);
}
public void receiveFrame(avrora.sim.mcu.USART.Frame frame) {
dataReceived(frame.value);
}
});
} else {
System.out.println("*** Warning MicaZ: could not find usart1 interface...");
}
}
public Mote getMote() {
return mote;
}
/* not yet implemented ...*/
public void writeArray(byte[] s) {
}
public void writeByte(byte b) {
}
public void writeString(String s) {
}
}

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: MicaZLED.java,v 1.2 2009/03/19 14:47:37 joxe Exp $
* $Id: MicaZLED.java,v 1.3 2009/03/19 18:58:19 joxe Exp $
*/
package se.sics.cooja.avrmote.interfaces;
@ -65,26 +65,6 @@ public class MicaZLED extends LED {
avrora.sim.platform.LED.LEDGroup leds =
(avrora.sim.platform.LED.LEDGroup) micaZ.getDevice("leds");
/* this should go into some other piece of code for serial data */
AtmelMicrocontroller mcu = (AtmelMicrocontroller) micaZ.getMicrocontroller();
avrora.sim.mcu.USART usart = (avrora.sim.mcu.USART) mcu.getDevice("usart0");
if (usart != null) {
System.out.println("MicaZ: connecting to USART1");
usart.connect( new avrora.sim.mcu.USART.USARTDevice() {
char[] stream = {'h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd'};
int count;
public avrora.sim.mcu.USART.Frame transmitFrame() {
System.out.println("MicaZ: transmitting to micaz...");
return new avrora.sim.mcu.USART.Frame((byte)stream[count++ % stream.length], false, 8);
}
public void receiveFrame(avrora.sim.mcu.USART.Frame frame) {
System.out.println("MicaZ: usart output: " + frame.toString());
}
});
} else {
System.out.println("MicaZ: could not find usart1 interface...");
}
leds.leds[0].getFSM().insertProbe(new FiniteStateMachine.Probe() {
public void fireAfterTransition(int old, int newstate) {
redOn = newstate > 0;