#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 167 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 /* 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){ InterruptWait( 0, NULL ); while (tcischars(fd)<(SIZE_BUFFER)) { InterruptUnmask( IRQ, intr_id ); InterruptWait(0,NULL); } numRead = read(fd, buffer, SIZE_BUFFER); printf("\n numREAD %d\n",numRead); /*WRITE*/ printf("%s",buffer); //write(hsocket, buffer, SIZE_BUFFER); //writing to ethernet port //pico_send("SENT BUFFER AND 1","si",buffer,1); // send_pico("SENT BUFFER AND 1","si",buffer,numRead); // sleep(0.5); write(outfd,buffer,SIZE_BUFFER); //writing to file on PC/104 /* Reenable this interrupt since writing is finished */ InterruptUnmask( IRQ, intr_id ); // sleep(1); } /* Remove the attachment from this thread */ /*WILL NEVER REACH THIS*/ InterruptDetach( intr_id ); /*WILL NEVER REACH THIS*/ return EXIT_SUCCESS; }