#include #include #include #include #include #include #include #include #include #include #include #include //#include //#include //#include #include #include #include #include #include #define IRQ 4 #define SIZE_BUFFER 2048 int read_port(int fdin_proto, int imu_socket_proto, char *buffer); int main(int argc, char *argv[]) { /*argc and argv are command line operators*/ int fdin; int imu_socket; char buffer[SIZE_BUFFER]; //buffer where data from IMU stored //buffer[166]= '\r'; //buffer[167]= '\n' ; //buffer[168]= '\0' ; //imu_socket = open_pico(); /*opens ethernet port to send and receive data to/from pico station */ fdin = open_port(); read_port(fdin,imu_socket, buffer); /* while(1) { read_port(fdin,imu_socket, buffer); }*/ close_port(fdin); return 0; } int read_port(int fd,int hsocket, char *buffer) { int numRead=0; //numRead will tell us how many bytes have been read int outfd; //file descriptor for the file that is created int privity_err; int intr_id; struct sigevent event; //event will cause an interrupt ssize_t rssize; /* Give this thread root permissions to access the hardware */ privity_err = ThreadCtl( _NTO_TCTL_IO, NULL ); if ( privity_err == -1 ) { printf( "Can't get root permissions\n" ); return -1; } /* Tell the kernel to attach an interrupt signal event to this thread */ event.sigev_notify = SIGEV_INTR; /* Attaches IRQ line 4 to the event */ intr_id = InterruptAttachEvent(IRQ, &event, _NTO_INTR_FLAGS_TRK_MSK ); if ( intr_id == -1 ) { printf( "Couldn't attach event to IRQ %d\n", IRQ ); return EXIT_FAILURE; } //create a file called new.txt under the folder where the qnx partition is mounted outfd = creat("/usr/hdd/new1.txt",O_WRONLY |O_NOCTTY | O_NDELAY | O_NONBLOCK); while(1){ rssize = read(fd, buffer, SIZE_BUFFER); // this will block until SIZE_BUFFER bytes has been received, no need to use if ( rssize != SIZE_BUFFER ) { // handle error or the fact that not all data has bee received printf("\n numREAD %d\n",rssize); } else { printf("\n numREAD %d\n",rssize); /*WRITE*/ printf("%s",buffer); write(outfd,buffer,SIZE_BUFFER); //writing to file on PC/104 } } /* Remove the attachment from this thread */ /*WILL NEVER REACH THIS*/ //InterruptDetach( intr_id ); /*WILL NEVER REACH THIS*/ return EXIT_SUCCESS; }