Hello,
I have a problem while sending messages to the PC from the motes. The
UARTSend.send function returns SUCCESS, but the message is not send to the
PC. I couldn't figure out where the bug is?
I'm posting parts of the code from my application and also from the java
program.
/*****Part of the code on the Tmotes*****/
//define SOURCE_ID 1
//define TARGET_ID 21
/***Structure of the Data message***/
typedef nx_struct
{
nx_uint8_t source;
nx_uint8_t destination;
nx_uint16_t sequence_no;
nx_uint8_t payload[PAYLOAD];
} DataMsg;
//Structure of the message sent to the PC
typedef struct uart_msg
{
char data[PAYLOAD];
} uart_msg_t;
/*****The Source node sends a Data Msg(of size 54bytes) over the network for
every 100millisec, when the destination receives this message, it sends just
the payload(uart_msg_t) to the PC*****/
SendPalyoadmsg()
{
am_id_t pmsg_type;
int i;
DataMsg* datamsg_sent;
sequence_counter+= 1;
//create a new data msg with some dummy payload
datamsg_sent = (DataMsg*)call RadioPacket.getPayload(&payloadmsg,NULL);
datamsg_sent->source = SOURCE_ID;
datamsg_sent->destination = TARGET_ID;
datamsg_sent->sequence_no = sequence_counter;
for(i=0; i<PAYLOAD; i++)
{
datamsg_sent->payload[i] = 'A' + (i % 10);
}
pmsg_type = 'p';
if(sequence_counter == 1000)
{
call PayloadTimer.stop();
}
if(call RadioSend.send[pmsg_type](AM_BROADCAST_ADDR, &payloadmsg,
sizeof(DataMsg)) == SUCCESS)
{
busy_radio = TRUE;
call Leds.led2Toggle();
}
}
//Inside the RadioReceive function, Destination sends the payload to the PC
event message_t* RadioReceive.receive[am_id_t id](message_t* msg,void*
payload, uint8_t len)
{
if(TOS_NODE_ID == TARGET_ID)
{
call Leds.led1Toggle();
uartmsg_sent = (uart_msg_t*)call
RadioPacket.getPayload(&uartmsg,NULL);
for(i=0; i < PAYLOAD; i++)
{
uartmsg_sent->data[i] = dataMsg_rcvd->payload[i];
}
pcmsg_type = 'm';
if(call UartSend.send[pcmsg_type](AM_BROADCAST_ADDR, &uartmsg,
sizeof(uart_msg_t)) == SUCCESS)
{
call Leds.led2Toggle();
busy_uart = TRUE;
}
}
return msg;
}
/*******part of the code on the PC side(java program)*********/
//we write the received msg from the destination node to a file
public void messageReceived(int to, Message message)
{
if(message instanceof UartMsg)
{
byte[] datamsg = new byte[50];
UartMsg msg = (UartMsg)message;
datamsg = msg.get_data();
datamsg_counter++;
try
{
FileOutputStream fos = new
FileOutputStream(datafilename,true);
fos.write(datamsg, 0, 50);
}
catch (IOException e)
{
e.printStackTrace();
}
System.out.print("Rcvd msg no:"+datamsg_counter+"\t");
for(int i=0; i<50; i++)
{
System.out.printf("%c", datamsg[i]);
}
System.out.println("");
}
}
If you understood my problem, please do reply........
with regards
--
Siva Sankar Gupta Guggilum
Schubertstraße 19
Klagenfurt,9020
Austria
Ph:- 0043 6606871071
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help