robert@269: /* robert@269: * default_main.cpp robert@269: * robert@269: * Created on: Oct 24, 2014 robert@269: * Author: parallels robert@269: */ robert@269: //#include robert@269: #include robert@269: #include robert@269: #include robert@269: #include robert@269: #include robert@269: #include "../include/BeagleRT.h" robert@269: robert@269: using namespace std; robert@269: robert@269: int returnCode = 0; robert@269: robert@269: // Handle Ctrl-C by requesting that the audio rendering stop robert@269: void interrupt_handler(int var) robert@269: { robert@269: gShouldStop = true; robert@269: // allows other process to monitor why beagleRT has exited robert@269: // var=15, returnCode = 143 if terminated with SIGTERM robert@269: returnCode = var + 128; robert@269: } robert@269: robert@269: // Print usage information robert@269: void usage(const char * processName) robert@269: { robert@269: cerr << "Usage: " << processName << " [options]" << endl; robert@269: robert@269: BeagleRT_usage(); robert@269: robert@269: cerr << " --help [-h]: Print this menu\n"; robert@269: } robert@269: robert@269: int main(int argc, char *argv[]) robert@269: { robert@269: BeagleRTInitSettings settings; // Standard audio settings robert@269: robert@269: struct option customOptions[] = robert@269: { robert@269: {"help", 0, NULL, 'h'}, robert@269: {NULL, 0, NULL, 0} robert@269: }; robert@269: robert@269: // Set default settings robert@269: BeagleRT_defaultSettings(&settings); robert@269: robert@269: // Parse command-line arguments robert@269: while (1) { robert@269: int c; robert@269: if ((c = BeagleRT_getopt_long(argc, argv, "h", customOptions, &settings)) < 0) robert@269: break; robert@269: switch (c) { robert@269: case 'h': robert@269: usage(basename(argv[0])); robert@269: exit(0); robert@269: case '?': robert@269: default: robert@269: usage(basename(argv[0])); robert@269: exit(1); robert@269: } robert@269: } robert@269: robert@269: // Initialise the PRU audio device robert@269: if(BeagleRT_initAudio(&settings, 0) != 0) { robert@269: cout << "Error: unable to initialise audio" << endl; robert@269: return -1; robert@269: } robert@269: robert@269: // Start the audio device running robert@269: if(BeagleRT_startAudio()) { robert@269: cout << "Error: unable to start real-time audio" << endl; robert@269: return -1; robert@269: } robert@269: robert@269: // Set up interrupt handler to catch Control-C and SIGTERM robert@269: signal(SIGINT, interrupt_handler); robert@269: signal(SIGTERM, interrupt_handler); robert@269: robert@269: // Run until told to stop robert@269: while(!gShouldStop) { robert@269: usleep(100000); robert@269: } robert@269: robert@269: // Stop the audio device robert@269: BeagleRT_stopAudio(); robert@269: robert@269: // Clean up any resources allocated for audio robert@269: BeagleRT_cleanupAudio(); robert@269: robert@269: // All done! robert@269: return returnCode; robert@269: }