Hi,I am a new in tinyos. Now I have some questions about the motetest thing. If 
you have time, could you please help me out?I have one motetest program running 
on the stargate, one TOSBase runs on one mote (this mote is connected to 
stargate), another mote have program named CntToLedAndRfm. I try to get 
received data printed out. But it never happened. I couldn't figure it out what 
was wrong. Could you please tell me what goes wrong here? 
The following is the motetest.c, I only comment out the create packet and write 
packet out. Also I set the groupid with 0x33. I don't know why. More infor: If 
I unplug the mote (have TOSBase) with the stargate, the green night blink. If I 
plug it with stargate, no night is on. And nothing was printout when I run 
motetest. Thanks a lot a lot~~Xiaodan#include <sys/types.h>#include 
<sys/stat.h>#include <fcntl.h>#include <termios.h>#include <stdio.h>#include 
<string.h>#include <unistd.h>#include <sys/time.h>#include <stdlib.h>/* Serial 
port information for talking to the mote */#define TOS_PACKET_LENGTH 36         
    /* Default TOS packet length */#define SERIAL_PORT "/dev/tts/2"         /* 
Default serial port to use *///#define SERIAL_PORT "/dev/ttyS2"       /* 
Default serial port to use */#define MICA1_BAUDRATE B19200           /* MICA1 
baudrate */#define MICA2_BAUDRATE B57600           /* MICA2 baudrate */#define 
DEFAULT_BAUDRATE B57600         /* Default is MICA2 *//* Funct!
 ions */void usage (char *);void parse_opts (int, char **); /* Parse command 
line options */void open_serial (void);        /* Open a serial channel to mote 
*/void read_packet (void);        /* Read a packet from the mote */void 
create_packet(char *);     /* Create TOS packet */void write_packet(void);      
  /* Write a packet to the mote */void print_packet (char *);     /* Print mote 
packet to stdout *//* Global variables */int inout_stream;char 
input_buffer[TOS_PACKET_LENGTH];char output_buffer[TOS_PACKET_LENGTH];char 
*serial_port = SERIAL_PORT;char mote = 2, charflag = 0;void usage(char *name) { 
 fprintf(stderr,"Usage: %s [-h] [-c] [-m 1|2] [-p /dev/ttySXXX]\n",name);  
fprintf(stderr,"       -c              : Print packet data as char (default is 
int)\n");  fprintf(stderr,"       -m 1            : Use BAUDRATE settings for 
MICA1\n");  fprintf(stderr,"       -m 2            : Use BAUDRATE settings for 
MICA2 (default)\n");  fprintf(stderr,"       -p /dev/ttySXXX : Talk to !
 mote on /dev/ttySXXX (default is /dev/ttyS2)\n");  fprintf(stderr,"   

    -h              : Print usage information\n");  exit(-1);}void 
parse_opts(int argc,char **argv) {  int opt;  while ((opt = 
getopt(argc,argv,"hcm:p:")) != EOF) {    switch(opt) {    case 'h':      
usage(argv[0]);      break;    case 'c':      charflag = 1;      break;    case 
'm':      mote = atoi(optarg);      if ((mote != 1) && (mote != 2))        
usage(argv[0]);      break;    case 'p':      serial_port = optarg;      break; 
   default:      usage(argv[0]);    }  }}int main(int argc, char ** argv) {  
int index = 0, count = 10;  /* Parse command line arguments */  
parse_opts(argc,argv);  /* Open serial channel to mote */  open_serial();  
while (index < count) {    /* Create the TOS packet. */   // create_packet("The 
first (TOS_PACKET_LENGTH-7) characters of this string form the outgoing TOS 
packet data");        /* Write the output buffer to the mote */    
//write_packet();        /* Read packet from mote into input buffer */    /* 
Note: The read blocks till a mote pack!
 et is received.        An alternative is to use "poll" to check for incoming 
data */    read_packet();         /* Dump packet onto stdout */    
print_packet(input_buffer);    index++;  }  exit(0);}/* Open serial channel to 
mote */ void open_serial() {  struct termios tio;  inout_stream = 
open(serial_port, O_RDWR|O_NOCTTY);  if (inout_stream < 0) {    
fprintf(stderr,"Cannot open serial device %s\n", serial_port);    exit(-1);  }  
/* Serial port setting */  bzero(&tio, sizeof(tio));  tio.c_iflag &= ~(IGNPAR | 
BRKINT | PARMRK | ISTRIP                    | INLCR | IGNCR | ICRNL | IXON);    
tio.c_cflag &= ~(CSIZE | PARENB);  if (mote == 1)    tio.c_cflag |= 
MICA1_BAUDRATE | CS8 | CLOCAL | CREAD;  else if (mote == 2)    tio.c_cflag |= 
MICA2_BAUDRATE | CS8 | CLOCAL | CREAD;  else    tio.c_cflag |= DEFAULT_BAUDRATE 
| CS8 | CLOCAL | CREAD;  /* Raw output_file */  tio.c_oflag &= ~OPOST;  
tio.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);    /* Flush buffer; 
parameters take effect imme!
 diately */  tcflush(inout_stream, TCIFLUSH);  tcsetattr(inout_stream, 

TCSANOW, &tio);  /* Enable non-blocking IO */  fcntl(inout_stream, F_SETFL, 
O_NONBLOCK);}/* Read TOS packet from mote */void read_packet() {  int count;  
bzero(input_buffer, TOS_PACKET_LENGTH);  //Find start of packet  
while(input_buffer[0] != (char)(0x7E)){    while(1 != read(inout_stream, 
input_buffer, 1)){};  }   count = 1;  //Read packet contents  while(count < 
TOS_PACKET_LENGTH)    count += read(inout_stream, input_buffer + count, 
TOS_PACKET_LENGTH - count);        }/* Print packet to stdout */void 
print_packet(char *packet) {  int i;  printf("Raw TOS packet contents: ");  
for(i = 0; i < TOS_PACKET_LENGTH; i ++) {    if (charflag)      printf("%c ", 
(char) (packet[i] & 0xff));    else      printf("%d ", (char) (packet[i] & 
0xff));  }  printf("\n");}
_________________________________________________________________
Windows Live Photo gallery 数码相机的超级伴侣,轻松管理和编辑照片,还能制作全景美图!
http://get.live.cn/product/photo.html
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to