>Greetings,
>
>I am a newbie currently working on a project which uses TelosB motes to
send packets back and forth. Now I am >connecting one of the motes to an
another microcontroller through UART - RS232 connection. Now the question
is, >I want the microcontroller to be able to call command moteIF.send()
similar to the java version one to send >packets back to the other mote. I
used the java version and I manually turn on the serial forwarder with the
>right ports to run the application (on a PC). However, I will not be able
to do the same for this >microcontroller since the microcontroller is not
connected to a PC at all. My question is how will I be able to >achieve
that? Upon receiving packets from the other side, I want the microcontroller
to call the send function >to the connected mote and send packets back. Any
help will be appreciated,
>
>Thank you in advance...
>
I do not know if this will help you in this situation but it might provide
something to look into. There is a serial API written in C for TinyOS 2.0.2
located under $TOSROOT/support/sdk/c
Installing C SDK:
- cd $TOSROOT/support/sdk/c
- ./bootstrap
- ./configure --prefix=$TOSROOT/support/sdk/c
- ./make install
The following are C functions that will open a connection, send and receive
from a mote. I'm using this code currently with SerialActiveMessage.
//Open/Close connection Function:
#define AM_BROADCAST_ADDR 65535
#define MAX_BUFFER_LENGTH 29
uint16_t NODE_ID=0; //65535 is broadcast
unsigned char GROUP=0;
unsigned char TYPE=1;
serial_source src;
//Message IDs returned from CC2420 Radio
static char *msgs[] = {
"unknown_packet_type",
"ack_timeout" ,
"sync" ,
"too_long" ,
"too_short" ,
"bad_sync" ,
"bad_crc" ,
"closed" ,
"no_memory" ,
"unix_error"
};
//Port: /dev/ttyUSB0, rates: 115200 off
http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForw
arder
int OpenConnection(char* port, unsigned int rate){
char *buf = malloc(sizeof(char) * 5);
sprintf(buf, "%d", rate);
src = open_serial_source(port, platform_baud_rate(buf), 0,
stderr_msg);
if (!src)
return -1;
return 0;
}
int CloseConnection(){
close_serial_source(src);
return 0;
}
//Send Function:
int Send(unsigned int addr, unsigned char* msg, unsigned int len){
int i;
unsigned char buffer[MAX_BUFFER_LENGTH];
//Get a tmsg_t structure to fill the header
tmsg_t* message = new_tmsg(buffer + 1, sizeof(buffer)-1);
memset(buffer, 0, sizeof(buffer));
if (len > (MAX_BUFFER_LENGTH - SPACKET_SIZE))
return -1;
//Setup the header based on global variables
spacket_header_dest_set(message, addr);
spacket_header_src_set(message, NODE_ID);
spacket_header_length_set(message, len);
spacket_header_group_set(message, GROUP);
spacket_header_type_set(message, TYPE);
//Copy data into packet structure
for (i=0; i < len; i++)
spacket_data_set(message, i, msg[i]);
//Send Packet out remember to use the original buffer tmsg_t will
not work
//The first byte in the buffer must be 0 or the system will drop the
packet
if (write_serial_packet(src, buffer, (SPACKET_SIZE+len+1)) != 0)
return 1;
return 0;
}
//Blocking Receive Function:
message_t RecieveB(){
int len, i;
unsigned char *packet;
tmsg_t *msg;
message_t newmsg;
do{
//Wait for packet and read it off the open port
packet = read_serial_packet(src, &len);
//Put it in the tmsg_t format to get the information out
msg = new_tmsg(packet + 1, len -1);
//Transfer all the information over to the message_t struct
newmsg.header.dest = spacket_header_dest_get(msg);
newmsg.header.src = spacket_header_src_get(msg);
newmsg.header.length = spacket_header_length_get(msg);
newmsg.header.group = spacket_header_group_get(msg);
newmsg.header.type = spacket_header_type_get(msg);
//Copy the data section
for (i=0; i < newmsg.header.length; i++)
newmsg.data[i] = spacket_data_get(msg,i);
while (newmsg.header.type != TYPE)
return newmsg;
}
CHIMO,
Raymond
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help