comparison core/default_main.cpp @ 67:472e892c6e41

Merge newapi into default
author Andrew McPherson <a.mcpherson@qmul.ac.uk>
date Fri, 17 Jul 2015 15:28:18 +0100
parents b89dd0c97a04
children 9bfe04d184fb e4392164b458
comparison
equal deleted inserted replaced
21:0d80ff9e2227 67:472e892c6e41
1 /*
2 * default_main.cpp
3 *
4 * Created on: Oct 24, 2014
5 * Author: parallels
6 */
7 #include <unistd.h>
8 #include <iostream>
9 #include <cstdlib>
10 #include <libgen.h>
11 #include <signal.h>
12 #include <getopt.h>
13 #include "../include/BeagleRT.h"
14
15 using namespace std;
16
17 // Handle Ctrl-C by requesting that the audio rendering stop
18 void interrupt_handler(int var)
19 {
20 gShouldStop = true;
21 }
22
23 // Print usage information
24 void usage(const char * processName)
25 {
26 cerr << "Usage: " << processName << " [options]" << endl;
27
28 BeagleRT_usage();
29
30 cerr << " --help [-h]: Print this menu\n";
31 }
32
33 int main(int argc, char *argv[])
34 {
35 BeagleRTInitSettings settings; // Standard audio settings
36
37 struct option customOptions[] =
38 {
39 {"help", 0, NULL, 'h'},
40 {NULL, 0, NULL, 0}
41 };
42
43 // Set default settings
44 BeagleRT_defaultSettings(&settings);
45
46 // Parse command-line arguments
47 while (1) {
48 int c;
49 if ((c = BeagleRT_getopt_long(argc, argv, "h", customOptions, &settings)) < 0)
50 break;
51 switch (c) {
52 case 'h':
53 usage(basename(argv[0]));
54 exit(0);
55 case '?':
56 default:
57 usage(basename(argv[0]));
58 exit(1);
59 }
60 }
61
62 // Initialise the PRU audio device
63 if(BeagleRT_initAudio(&settings, 0) != 0) {
64 cout << "Error: unable to initialise audio" << endl;
65 return -1;
66 }
67
68 // Start the audio device running
69 if(BeagleRT_startAudio()) {
70 cout << "Error: unable to start real-time audio" << endl;
71 return -1;
72 }
73
74 // Set up interrupt handler to catch Control-C and SIGTERM
75 signal(SIGINT, interrupt_handler);
76 signal(SIGTERM, interrupt_handler);
77
78 // Run until told to stop
79 while(!gShouldStop) {
80 usleep(100000);
81 }
82
83 // Stop the audio device
84 BeagleRT_stopAudio();
85
86 // Clean up any resources allocated for audio
87 BeagleRT_cleanupAudio();
88
89 // All done!
90 return 0;
91 }