Terminating application after time/condition is met

Hello,

I am a biomechanical engineer in need of some help with code modification.

The application I recieved from a hardware manufacturer receives UDP datagrams from their software and displays that data as legible information in a commmand window. It runs indefinitely and does not terminate at all unless the window is closed by the user.

Please see the following google drive folder for the application, as well as the corresponding source code:

https://drive.google.com/drive/folders/0BxIClEmQisqFNDRMQ1BmSUJISDA?usp=sharing

I want the application to self terminate. This can be either after a set number of seconds of running, or after exactly one (1) sample has been received. Please see the example outputs jointangledata.txt and jointangledata_appended.txt. The former is what the output looks like when the program is allowed to open and run indefinitely until terminated by the user. The second is the output I want from the program per time it is opened. The data collection was performed in a MatLab environment, where the application was called using system() and then the output in the MatLab command window saved to a text file using the diary function.

Any insight or possible solutions would be greatly appreciated.

Thank you,
Kevin

Here is main.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "udpserver.h"
#include "streamer.h"
#include <conio.h>
#include <xsens/xstime.h>

int main(int argc, char *argv[])
{
	std::string hostDestinationAddress = "localhost";
	int port = 9763;

	UdpServer udpServer(hostDestinationAddress, (uint16_t)port);

	while (!_kbhit())
		XsTime::msleep(10);

	return 0;
}

if doing it all in main,
if(time_is_up)
{
shut stuff down as needed, print a friendly exit message maybe?
return(0)
}

depending on how complex you want to get with time, it could be as simple as

int start = clock();

...

int now = clock;

double secs = (now-start)/(double)CLOCKS_PER_SEC;

this is uber crude, but its also only 3 lines of code and generally solves the problem.

Last edited on
Topic archived. No new replies allowed.