[Tinyos-2-commits] CVS: tinyos-2.x/apps/AntiTheft/java .cvsignore, NONE, 1.1 AntiTheftGui.java, 1.1, 1.2

David Gay idgay at users.sourceforge.net
Wed Apr 4 15:06:24 PDT 2007


Update of /cvsroot/tinyos/tinyos-2.x/apps/AntiTheft/java
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv7208/java

Modified Files:
	AntiTheftGui.java 
Added Files:
	.cvsignore 
Log Message:
antitheft gui


--- NEW FILE: .cvsignore ---
AlertMsg.java
Constants.java
SettingsMsg.java
antitheft.jar

Index: AntiTheftGui.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/apps/AntiTheft/java/AntiTheftGui.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** AntiTheftGui.java	4 Apr 2007 21:01:11 -0000	1.1
--- AntiTheftGui.java	4 Apr 2007 22:06:22 -0000	1.2
***************
*** 42,48 ****
  import java.awt.*;
  import java.awt.event.*;
  import net.tinyos.packet.*;
  
! public class AntiTheftGui {
      JTextArea mssgArea;
      JTextField fieldInterval;
--- 42,53 ----
  import java.awt.*;
  import java.awt.event.*;
+ import java.io.*;
+ import net.tinyos.message.*;
  import net.tinyos.packet.*;
+ import net.tinyos.util.*;
  
! public class AntiTheftGui implements MessageListener, Messenger {
!     MoteIF mote;
!     JFrame frame;
      JTextArea mssgArea;
      JTextField fieldInterval;
***************
*** 53,56 ****
--- 58,63 ----
  	try {
  	    guiInit();
+ 	    mote = new MoteIF(this);
+ 	    mote.registerListener(new AlertMsg(), this);
  	}
  	catch(Exception e) {
***************
*** 113,117 ****
  
  	// The frame part
! 	JFrame frame = new JFrame("AntiTheft");
  	frame.setSize(mainPanel.getPreferredSize());
  	frame.getContentPane().add(mainPanel);
--- 120,124 ----
  
  	// The frame part
! 	frame = new JFrame("AntiTheft");
  	frame.setSize(mainPanel.getPreferredSize());
  	frame.getContentPane().add(mainPanel);
***************
*** 122,134 ****
      }
  
!     public synchronized void theft(String mssg) {
! 	mssgArea.append(mssg + "\n");
! 	mssgArea.setCaretPosition(mssgArea.getDocument().getLength());
      }
  
!     public void updateSettings() { }
  
      public static void main(String[] args) {
  	AntiTheftGui me = new AntiTheftGui();
      }
  }
--- 129,207 ----
      }
  
!     void error(String msg) {
! 	JOptionPane.showMessageDialog(frame, msg, "Error",
! 				      JOptionPane.ERROR_MESSAGE);
      }
  
!     public void updateSettings() { 
! 	SettingsMsg smsg = new SettingsMsg();
! 	short alert = 0;
! 	short detect = 0;
! 	int checkInterval = Constants.DEFAULT_CHECK_INTERVAL;
! 
! 	/* Extract current interval value, ignoring bad values */
! 	String intervalS = fieldInterval.getText().trim();
! 	try {
! 	    int newInterval = Integer.parseInt(intervalS);
! 	    if (newInterval < 10) throw new NumberFormatException();
! 	    checkInterval = newInterval;
! 	}
! 	catch (NumberFormatException e) { 
! 	    /* Reset field when value is bad */
! 	    fieldInterval.setText("" + checkInterval);
! 	}
! 
! 	if (repLedCb.isSelected())
! 	    alert |= Constants.ALERT_LEDS;
! 	if (repSirenCb.isSelected())
! 	    alert |= Constants.ALERT_SOUND;
! 	if (repNeighboursCb.isSelected())
! 	    alert |= Constants.ALERT_RADIO;
! 	if (repServerCb.isSelected())
! 	    alert |= Constants.ALERT_ROOT;
! 	if (alert == 0) {
! 	    /* If nothing select, force-select LEDs */
! 	    alert = Constants.ALERT_LEDS;
! 	    repLedCb.setSelected(true);
! 	}
! 
! 	if (detDarkCb.isSelected())
! 	    detect |= Constants.DETECT_DARK;
! 	if (detAccelCb.isSelected())
! 	    detect |= Constants.DETECT_ACCEL;
! 	if (detect == 0) {
! 	    /* If no detection selected, force-select dark */
! 	    detect = Constants.DETECT_DARK;
! 	    detDarkCb.setSelected(true);
! 	}
! 
! 	smsg.set_alert(alert);
! 	smsg.set_detect(detect);
! 	smsg.set_checkInterval(checkInterval);
! 
! 	try {
! 	    mote.send(MoteIF.TOS_BCAST_ADDR, smsg);
! 	}
! 	catch (IOException e) {
! 	    error("Cannot send message to mote");
! 	}
!     }
  
      public static void main(String[] args) {
  	AntiTheftGui me = new AntiTheftGui();
      }
+ 
+     synchronized public void messageReceived(int dest_addr, Message msg) {
+ 	if (msg instanceof AlertMsg) {
+ 	    AlertMsg alertMsg = (AlertMsg)msg;
+ 
+ 	    String warning = "Theft of " + alertMsg.get_stolenId() + "\n";
+ 	    mssgArea.append(warning);
+ 	    mssgArea.setCaretPosition(mssgArea.getDocument().getLength());
+ 	}
+     }
+ 
+     public void message(String s) {
+ 	error(s);
+     }
  }



More information about the Tinyos-2-commits mailing list