Hi,

at that line is moteIF.send(1,msg). Actually it is always at that point no
matter what I do. I didn't intend any infinite loop. All I wanted to do is to
send the received message, that is 1 message, back to my motes, after I have
received it. Haven't tried your suggestion yet.
Thanks

Nicole
> Hi Nicole,
> 
> Which line is at line 109 in your original ConvCast.java file? This is 
> where apparently there is a NullPointerException.
> 
> In the anonymous class for handling received UpflowResultMsg messages 
> you seem to have an infinite loop. Is this intended? Or would you rather 
> want to start sending some messages once you received the first 
> UpflowResultMsg message? With your current solution you probably block 
> the receive thread in MoteIF, so this could cause all sorts of errors. 
> You should rather start a new thread there.
> 
> In the code below there is an inner class (should be declared within the 
> ConvCast class) called UpflowPhase2. In the handlerType1() method an 
> instance of this class is created to send the messages in a separate 
> thread. Note that private members (such as the constructor) are 
> accessible from ConvCast since ConvCast.UpflowPhase2 is an inner class.
> 
> Cheers,
> Urs
> 
> public void init(String source) {
>      PhoenixSource phoenix;
> 
>      if (source == null) {
>          phoenix = BuildSource.makePhoenix(PrintStreamMessenger.err);
>      } else {
>          phoenix = BuildSource.makePhoenix(source, 
> PrintStreamMessenger.err);
>      }
> 
>      MoteIF mif = new MoteIF(phoenix);
>      mif.registerListener(new UpflowResultMsg(), new MessageListener() {
>          public void messageReceived(int to, Message msg) {
>              handlerType1(to,msg);
>          }
>      });
> 
>      mif.registerListener(new VerificationResultMsg(), new 
> MessageListener() {
>          public void messageReceived(int to, Message msg) {
>              handlerType2(to,msg);
>          }
>      });
>    }
> 
> private void handlerType1(int to, Message msg) {
>      if (msg instanceof UpflowResultMsg) {
>          UpflowResultMsg rmsg = (UpflowResultMsg)msg;
>          System.out.println("UpflowResultMessage received. Nonce = " +
>                  rmsg.get_rndNonce() + " aggregated data " +
>                  rmsg.get_aggregatedData() + " ");
>          UpflowPhase2 thread = new UpflowPhase2(msg);
>          thread.start();
>      }
> }
> 
> private class UpflowPhase2 extends Thread {
>      private Message msg;
> 
>      private UpflowPhase2(Message msg) {
>          this.msg = msg;
>      }
> 
>      public void run() {
>          try {
>              while (true) {
>                  moteIF.send(1,msg);
>                  System.out.println("Sending UpflowResult starting 
> 2.Phase");
>                  try { Thread.sleep(1000);}
>                  catch (InterruptedException exception){}
>              }
>          } catch (IOException exception) {
>              System.err.println("Exception thrown when sending packets. 
> Exiting.");
>              System.err.println(exception);
>          }
>      }
> }
> 
> Nicole Neureiter wrote:
> > Hi my code at the moment is as follows:
> > [..]
> > 
> > what I get out is:
> > UpflowResultMessage received. Nonce = 14190152 aggregated data 1629520098 
> > Exception in thread "Thread-1" java.lang.NullPointerException
> >         at ConvCast$1.messageReceived(ConvCast.java:109)
> >         at net.tinyos.message.Receiver.packetReceived(Receiver.java:210)
> >         at net.tinyos.packet.PhoenixSource.dispatch(PhoenixSource.java:160)
> >         at
> > net.tinyos.packet.PhoenixSource.packetDipatchLoop(PhoenixSource.java:152)
> >         at net.tinyos.packet.PhoenixSource.run(PhoenixSource.java:169)
> > 
> 

_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to