From: Mipo01 <Mi...@gm...> - 2012-12-16 18:42:37
|
Hi everyone, I would like to ask for some suggestions. I have looping code where i am using function for reading GPS data from Gallop43 board ttyO0 port. I have problem that when i try to close port it takes too long. Usually around 20 - 30 seconds. First few times immediately and than this problem occurred. Code: int gps (float* lat1, float* lon1){ int fd, round = 0; int size,longitude_deg,lattitude_deg,UTC; char buff[70],temp_buff[7]; float longitude_min, lattitude_min; fd = open("/dev/ttyO0", O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1){ printf("Can't open port for GPS!\n"); return 1; } else { fcntl(fd, F_SETFL, 0); do{ memset(temp_buff,0,sizeof(temp_buff)); //reset the buffer size = read(fd, buff, 70); if (buff[4]=='M'&&buff[5]=='C'&&buff[17]=='A') { close(fd); printf ("OK\n"); memset(temp_buff,0,sizeof(temp_buff)); temp_buff[0]=buff[19]; temp_buff[1]=buff[20]; lattitude_deg = atof (temp_buff); memset(temp_buff,0,sizeof(temp_buff)); temp_buff[0]=buff[21]; temp_buff[1]=buff[22]; temp_buff[2]=buff[23]; temp_buff[3]=buff[24]; temp_buff[4]=buff[25]; temp_buff[5]=buff[26]; temp_buff[6]=buff[27]; temp_buff[7]=buff[28]; lattitude_min = atof (temp_buff); memset(temp_buff,0,sizeof(temp_buff)); temp_buff[0]=buff[32]; temp_buff[1]=buff[33]; temp_buff[2]=buff[34]; longitude_deg = atof (temp_buff); memset(temp_buff,0,sizeof(temp_buff)); temp_buff[0]=buff[35]; temp_buff[1]=buff[36]; temp_buff[2]=buff[37]; temp_buff[3]=buff[38]; temp_buff[4]=buff[39]; temp_buff[5]=buff[40]; temp_buff[6]=buff[41]; temp_buff[7]=buff[42]; longitude_min = atof (temp_buff); memset(temp_buff,0,sizeof(temp_buff)); temp_buff[0]=buff[7]; temp_buff[1]=buff[8]; temp_buff[2]=buff[9]; temp_buff[3]=buff[10]; temp_buff[4]=buff[11]; temp_buff[5]=buff[12]; UTC = atof (temp_buff); memset(buff,0,sizeof(buff)); *lat1=lattitude_deg+(lattitude_min/60); *lon1=longitude_deg+(longitude_min/60); return 0; } round++; }while(round<300); close(fd); return 0; } Thank you very much. -- View this message in context: http://gumstix.8.n6.nabble.com/close-fd-takes-too-long-tp4966259.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: hiCountryCowboy <ste...@ya...> - 2012-12-16 19:52:29
|
I am running an OveroEarth on a Gallop43 and am logging the GPS output plus another sensor connected via USB/Serial dongle. My code is very similar to what was posted, but I do an fopen(fd) followed by fprintf() followed by a fflush(fd) then finally a fclose(fd) without issues. I do not call fcntl(). I am opening/writing/flushing/closing the GPS file once a second while the serial sensor is opening/writing/flushing/closing its data file about 8-10 times per second. The application has been running for sometime without incident. >Hi everyone, >I would like to ask for some suggestions. >I have looping code where i am using function for reading GPS data from Gallop43 board ttyO0 port. >I have problem that when i try to close port it takes too long. Usually around 20 - 30 seconds. First few >times immediately and than this problem occurred. -- View this message in context: http://gumstix.8.n6.nabble.com/close-fd-takes-too-long-tp4966259p4966260.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: Mipo01 <Mi...@gm...> - 2012-12-17 13:08:09
|
Thank you very much for the response. I tried to change it but the same issue occurred. It gets stuck on the same point. Code: int gps (float* lat1, float* lon1){ FILE* fd; int round = 0; int longitude_deg,lattitude_deg,UTC; char buff[44],temp_buff[7]; float longitude_min, lattitude_min; fd = fopen("/dev/ttyO0", "r+"); if (fd == NULL){ printf("Can't open port for GPS!\n"); return 1; } else { do{ memset(temp_buff,0,sizeof(temp_buff)); //reset the buffer fgets (buff,44,fd); if (buff[4]=='M'&&buff[5]=='C'&&buff[17]=='A') { printf ("In the loop \n"); fflush(fd); printf ("flushed \n"); fclose(fd); printf ("OK\n"); memset(temp_buff,0,sizeof(temp_buff)); temp_buff[0]=buff[19]; temp_buff[1]=buff[20]; lattitude_deg = atof (temp_buff); ... -- View this message in context: http://gumstix.8.n6.nabble.com/close-fd-takes-too-long-tp4966259p4966263.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: Miner, J. W (US SSA) <jon...@ba...> - 2012-12-17 13:51:40
|
Hi - Without knowing how your entire application works, it seems odd to open/close the GPS port each time you need GPS data. You would expect that this should not cause a resource problem, but there is also additional time involved with executing the open/close calls, and associated resource management. Why not use a daemon like gpsd to manage the interface with the GPS and then use the gpsd API to poll for the current location? I'll admit that I've worked with USB and serial GPS devices, but never with a Gumstix or Gallop board; so maybe my answer doesn't work in this particular situation. ________________________________________ From: Mipo01 [Mi...@gm...] Sent: Monday, December 17, 2012 08:08 To: gum...@li... Subject: Re: [Gumstix-users] close(fd) takes too long Thank you very much for the response. I tried to change it but the same issue occurred. It gets stuck on the same point. Code: int gps (float* lat1, float* lon1){ FILE* fd; int round = 0; int longitude_deg,lattitude_deg,UTC; char buff[44],temp_buff[7]; float longitude_min, lattitude_min; fd = fopen("/dev/ttyO0", "r+"); if (fd == NULL){ printf("Can't open port for GPS!\n"); return 1; } else { do{ memset(temp_buff,0,sizeof(temp_buff)); //reset the buffer fgets (buff,44,fd); if (buff[4]=='M'&&buff[5]=='C'&&buff[17]=='A') { printf ("In the loop \n"); fflush(fd); printf ("flushed \n"); fclose(fd); printf ("OK\n"); memset(temp_buff,0,sizeof(temp_buff)); temp_buff[0]=buff[19]; temp_buff[1]=buff[20]; lattitude_deg = atof (temp_buff); ... -- View this message in context: http://gumstix.8.n6.nabble.com/close-fd-takes-too-long-tp4966259p4966263.html Sent from the Gumstix mailing list archive at Nabble.com. ------------------------------------------------------------------------------ LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial Remotely access PCs and mobile devices and provide instant support Improve your efficiency, and focus on delivering more value-add services Discover what IT Professionals Know. Rescue delivers http://p.sf.net/sfu/logmein_12329d2d _______________________________________________ gumstix-users mailing list gum...@li... https://lists.sourceforge.net/lists/listinfo/gumstix-users |
From: qmay123 <dk...@ar...> - 2012-12-17 13:59:44
|
Do you need to open and close for every call of the gps function? Can you leave the stream open and read when needed? Also fscanf might provide a cleaner (not sure about faster) version of the temp buffer code you have shown. I saw Jonathan's message while writing this, I agree with him. I'm not familiar with gpsd, but you could also make a class to handle gps data. Look around I'm sure there are already a lot of gps examples (which I'm sure gpsd is probably a good one). -- View this message in context: http://gumstix.8.n6.nabble.com/close-fd-takes-too-long-tp4966259p4966265.html Sent from the Gumstix mailing list archive at Nabble.com. |