The point of the "locked" variable is to prevent two sends
from being done at the same time. You should not use a second
"locked2" variable in your second send. Although I would
expect some to most of the messages would not overlap.
I didn't work through your random timer calculation,
but maybe just try some convenient fixed time that
is less likely to interfere.
You didn't include your config file and there is only
one AM message type, AM_RADIO_COUNT_MSG, defined in the
header. Do you really have two message types?
Also, in TOS1, sendDone() should return SUCCESS. Perhaps
it is void in T2?
MS
Ibrahim Abbas wrote:
> Hi,
>
> First of all sorry for english..
>
> I am Ibrahim Abbas. I am doing graduation from NUST Pakistan. I am
> having the following problem in TinyOS.
>
> I am trying to send two different types of packets from node 1 to node
> 2 , where timers for both sendings fire at different intervals, but it
> is only sending one type, when I try to send another type of packet then
> Data2.send not returns success.
>
> Please see the code below...
>
> In module file..
>
> module RadioCountToLedsC {
> uses {
> interface Leds;
> interface Boot;
> interface Receive as Data1;
> interface AMSend as data1;
> //interface Receive as Data2;
>
> interface AMSend as data2;
> interface Timer<TMilli> as MilliTimer;
> interface Timer<TMilli> as MilliTimer2;
>
> interface SplitControl as AMControl;
> interface Packet as Packet1;
> interface Packet as Packet2;
> interface Random;
> interface LocalTime<TMilli>;
> }
> }
> implementation {
>
> message_t packet;
> message_t packet2;
> bool locked = FALSE;
> bool locked2 = FALSE;
> uint16_t i=0;
> uint16_t j=0;
>
> event void Boot.booted()
> {
> call AMControl.start();
> }
>
> event void AMControl.startDone(error_t err)
> {
> if (err == SUCCESS)
> {
> /* call MilliTimer2.startPeriodic(25);*/
>
> call MilliTimer.startPeriodic(250);
> call MilliTimer2.startOneShot((call Random.rand32() %
> SEND_INTERVAL)+(SEND_INTERVAL >> 1));
> printf("Timers are Started \n");
> }
> else
> {
> call AMControl.start();
> }
> }
>
> event void AMControl.stopDone(error_t err)
> {
> // do nothing
> }
>
> event void MilliTimer2.fired()
> {
> if(TOS_NODE_ID==1)
> {
> dbg("2","MilliTimer2 is Fired After If and Time is %d\n",call
> LocalTime.get());
> if (locked2)
> {
> return;
> }
> else
> {
> ///I think some where here is the problem it does not return
> success
>
> other_msg_t* rcm = (other_msg_t*)call Packet2.getPayload(&packet2,
> NULL);
> call MilliTimer2.startOneShot((call Random.rand32() %
> SEND_INTERVAL)+(SEND_INTERVAL >> 1));
> dbg("3","MilliTimer2 is Fired After If After If \n");
> j = j+2;
> rcm->seq = j;
> printf("Sending.................\n\n");
> if (call data2.send(2, &packet2, sizeof(other_msg_t)) == SUCCESS)
> {
> dbg("Send2","Sending Data2 Packet To 2 %hhu.\n",rcm->seq);
> locked2 = TRUE;
> }
>
> }
> }
> }
>
>
> event void MilliTimer.fired()
> {
> if(TOS_NODE_ID==1)
> {
> printf("MilliTimer is and Time is %d\n",call LocalTime.get());
> if (locked)
> {
> return;
> }
> else
> {
> radio_count_msg_t* rcm = (radio_count_msg_t*)call
> Packet1.getPayload(&packet, NULL);
> i++;
> rcm->seq_num = i;
> rcm->data = 10;
>
>
> if (call data1.send(2, &packet, sizeof(radio_count_msg_t)) == SUCCESS)
> {
> dbg("Send1","Sending Data1 Packet To 2 %hhu.\n",rcm->seq_num);
> locked = TRUE;
> }
>
> }
> }
> }
>
> /*event message_t* Data2.receive(message_t* bufPtr, void* payload,
> uint8_t len)
> {
> if(TOS_NODE_ID==2)
> {
> other_msg_t* rcm = (other_msg_t*)payload;
>
> dbg("Rcvd2","Received Data2 %hhu.\n\n", rcm->seq);
> }
> return bufPtr;
> }
> */
> event message_t* Data1.receive(message_t* bufPtr, void* payload,
> uint8_t len)
> {
> if(TOS_NODE_ID==2)
> {
> radio_count_msg_t* rcm = (radio_count_msg_t*)payload;
>
> dbg("Rcvd1","Received Data1 packet %hhu.\n\n", rcm->seq_num);
> }
> return bufPtr;
> }
>
> event void data1.sendDone(message_t* bufPtr, error_t error)
> {
> if (&packet == bufPtr)
> {
> locked = FALSE;
> }
> }
> event void data2.sendDone(message_t* bufPtr, error_t error)
> {
> if (&packet2 == bufPtr)
> {
> locked2 = FALSE;
> }
> }
> }
>
>
> /////////////////////////////////////////in header file
>
> #ifndef RADIO_COUNT_TO_LEDS_H
> #define RADIO_COUNT_TO_LEDS_H
>
> typedef nx_struct radio_count_msg
> {
> nx_uint16_t seq_num;
> nx_uint16_t data;
>
> } radio_count_msg_t;
>
> typedef nx_struct other_msg
> {
> nx_uint16_t seq;
>
> } other_msg_t;
> enum {
> AM_RADIO_COUNT_MSG = 6,
> SEND_INTERVAL = 8000
> };
> Please help me .. I am stuck here..
> --
> Regards
> Ibrahim Abbas
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help