Actually it won't work that way.
Configuration file is static. Once you wire it, you wire it.
you can not put "if" statement in conf.
 TOS_LOCAL_ADDRESS need to be judged in StdControl.ini() in the wrapper
module.
I think I figure out the solution. Take CntToRfm & RfmToLeds for an exmaple.

configuration CntToRfm {
}
implementation {
  components Main, Counter, IntToRfm, TimerC;

  Main.StdControl -> Counter.StdControl;
  Main.StdControl -> IntToRfm.StdControl;
  Counter.Timer -> TimerC.Timer[unique("Timer")];
  Counter.IntOutput -> IntToRfm.IntOutput;
}
--------
configuration RfmToLeds {
}
implementation {
  components Main, RfmToInt, IntToLeds;

  Main.StdControl -> IntToLeds.StdControl;
  Main.StdControl -> RfmToInt.StdControl;
  RfmToInt.IntOutput -> IntToLeds.IntOutput;
}
------
above are original conf. files
I changed them to:

configuration CntToRfm {
    provides interface StdControl;
}
implementation {
  components Counter, IntToRfm, TimerC;

  StdControl = Counter.StdControl;
  StdControl = IntToRfm.StdControl;
  Counter.Timer -> TimerC.Timer[unique("Timer")];
  Counter.IntOutput -> IntToRfm.IntOutput;
}
-------
configuration RfmToLeds {
        provides interface StdControl;
}
implementation {
  components RfmToInt, IntToLeds;

  StdControl = IntToLeds.StdControl;
  StdControl = RfmToInt.StdControl;
  RfmToInt.IntOutput -> IntToLeds.IntOutput;
}
-------
In the wrapper conf. file, I put:

configuration Wrapper
{}
implementation
{ components Main, WrapperM, CntToRfm, RfmToLeds;
Main.StdControl->WrapperM.StdControl;
WrapperM.FstControl->CntToRfm.StdControl;
WrapperM.SndControl->RfmToLeds.StdControl;
}
----------
The WrapperM module is the real place where different components are
initialized at run time according to local_addr:

module WrapperM
{provides
        { interface StdControl;

        }
     uses
        {interface StdControl as FstControl;
         interface StdControl as SndControl;
        // interface StdControl as TrdControl;
        }
}
implementation
{


  command result_t StdControl.init()
    {


                dbg(DBG_USR1, "WrapperM initializing.\n");
                     if (TOS_LOCAL_ADDRESS==0)
                  return (call FstControl.init());
                else if ((TOS_LOCAL_ADDRESS==1))
                  return (call SndControl.init());
        //        else if ((TOS_LOCAL_ADDRESS==2))
        //          return (call TrdControl.init());
                else
                  {dbg(DBG_USR1, "local addr=%i, initializ nothing\n",
TOS_LOCAL_ADDRESS);
                  //return 0;
                  }


     return SUCCESS;
    }

   command result_t StdControl.start()
    {


                dbg(DBG_USR1, "WrapperM initializing.\n");
                     if (TOS_LOCAL_ADDRESS==0)
                  return (call FstControl.start());
                else if ((TOS_LOCAL_ADDRESS==1))
                  return (call SndControl.start());
        //        else if ((TOS_LOCAL_ADDRESS==2))
        //          return (call TrdControl.start());
                else
                  {dbg(DBG_USR1, "local addr=%i, initializ nothing\n",
TOS_LOCAL_ADDRESS);
                  //return 0;
                  }


     return SUCCESS;
    }
       command result_t StdControl.stop()
    {


                dbg(DBG_USR1, "WrapperM initializing.\n");
                     if (TOS_LOCAL_ADDRESS==0)
                  return (call FstControl.stop());
                else if ((TOS_LOCAL_ADDRESS==1))
                  return (call SndControl.stop());
        //        else if ((TOS_LOCAL_ADDRESS==2))
        //          return (call TrdControl.stop());
                else
                  {dbg(DBG_USR1, "local addr=%i, initializ nothing\n",
TOS_LOCAL_ADDRESS);
                  //return 0;
                  }


     return SUCCESS;
    }
}
-------
Because it is for 2 aplications simulation, so I commented out
TOS_LOCAL_ADDRESS==2 part, which is for more applications.
Just put new CntToRfm, RfmToLeds, Wrapper, WrapperM in one folder with
"COMPONENT=Wrapper"in the makefile. It will do.
Many thanks to Joe for the hint in previous post.
comments are welcomed.

Happy Valentine!

Leo



> This is probably more of a style question than anythign else.  I am
> curious if this makes sense.  I figured before spending a few hours
> and trying to implement my project this way, i'd run it by the
> experts.
>
> If I want to have 2(probably not more) components running in the same
> TOSSIM simulation like stated above, would it make sense to make these
> components basically autonomous in that they just need to be linked to
> Main.StdControl.  I was thinking something like this:
>
>
> file1:
>
> configuration Wrap{
> }
> implementation{
>    components CHOICE1, CHOICE2;
>
>    if(TOS_LOCAL_ADDRESS == 0){
>      Main.StdControl -> CHOICE1;
>   }
>   else{
>      Main.StdControl-> CHOICE2;
>   }
> }
>
>
> but then CHOICE1 and 2 would be configurations instead of Modules that
> take care of all of their wirings to other Modules, and interfaces.
> This way the wrapper file is clean, and the two separate components
> can each do their own thing and there will be less confusion if they
> need to provide or use interfaces.
>
> Does that make sense?
>
>
>



_______________________________________________
Tinyos-users mailing list
[email protected]
http://mail.Millennium.Berkeley.EDU/mailman/listinfo/tinyos-users

Reply via email to