Hi All

I am developing a C/C++ (Windows) based Listener to capture the tinyos packets 
from COM port (provide BaseStation is attached to my COM port). My purpose is 
to receive the data just as "java.net.tinyos.tools.Listen" captures the data 
from BaseStation and use it then after. please guide If somebody can help in 
this regard.

I have developed a small program in windows that can capture the packets from 
serial port but the data received is not correct or same as java Listener. I am 
attaching the program so that someone can have a look.

Please, if anyone have done work in this regard, please provide guidance.

Thanks in Advance
Yasir Javed Kiani
Research Engineer 
R-TRACK project
# include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#include<iostream>
# include<dos.h>
# include<time.h>
# include<fstream>


using namespace std;
using std::ofstream;

int main()
{
        unsigned char chin[30];
        char data[30];
        ofstream outData;       
        outData.open("bbc.txt",ios::out | ios::app); // opens the file
                        if( !outData ) 
                        { 
                                // file couldn't be opened
                                 cerr << "Error: file could not be opened" << 
endl;
                                 exit(1);
                        }
        HANDLE hUSB = 0;
        hUSB = CreateFileA("\\\\.\\COM8",GENERIC_READ|GENERIC_WRITE,
                      0,                          /* no share  */
    
                                          NULL,                       /* no 
security */
                      OPEN_EXISTING,
                      0,                          /* no threads */
                      NULL);                      /* no templates */
        
        if(hUSB==INVALID_HANDLE_VALUE)  {  printf("unable to open comport\n");  
 return(1);     }

                cout << "The Handle number is :- "<< hUSB <<endl;
                //Initialize a configuration structure and get default 
attributes 
                DCB dcbSerialParams = {0}; 
                dcbSerialParams.DCBlength=sizeof(dcbSerialParams); 
                GetCommState(hUSB, &dcbSerialParams); //You should treat error 
here. Check Comments section. 
                //Setting attributes of our interest 
                dcbSerialParams.BaudRate=CBR_115200;  //If you don’t use 
Telosb, you might have to change here. 
                dcbSerialParams.ByteSize=8; 
                dcbSerialParams.StopBits=ONESTOPBIT; 
                dcbSerialParams.Parity=NOPARITY;
                //Setting back the configuration to the serial port
                SetCommState(hUSB, &dcbSerialParams); //Another place to treat 
a possible failure.

int count =0; 
DWORD dwBytesRead; 
while(1) 
{  
   
  ReadFile(hUSB, &chin,30, &dwBytesRead,NULL );
  
          for(int i=0;i<21;i++){
                        printf("%x ",(int)chin[i]);
                        data[i]=chin[i];
                        outData << (int)chin[i];
                          }
                                
                
                printf("\n");
                outData << endl;

                
                Sleep(500);             
                cout<<count++<<":-  ";
}
return 0;
}
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to