-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
177 lines (163 loc) · 6.17 KB
/
main.cpp
File metadata and controls
177 lines (163 loc) · 6.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "gui.h"
#include <QApplication>
#include <sys/ioctl.h>
#include <linux/serial.h>
#include <fcntl.h>
#include <signal.h>
#include <QDebug>
#define VERBOSE_PRINTF(...) if (verbose_flag > 0) { \
printf("%s:%i: ",__FILE__,__LINE__);\
printf(__VA_ARGS__);\
}
int verbose_flag = 1;
void termination_handler (int signum);
PCMdekoder* myDekoder = NULL;
int main( int argc, char* argv[])
{
signal (SIGINT, termination_handler);
QApplication a(argc, argv);
QString devicename("/dev/ttyUSB0");
QString basename;
QString jointId("seven");
QString filterId("fir_massive");
int pwm = 0;
int record_sample_number = 16384;
int baudrate = 230400;
bool start_gui = true;
//-------------------
// parsing of cmdline-options
//-------------------
int c;
while ((c = getopt (argc, argv, "nvt:f:p:b:m:j:r:")) != -1) {
/* getopt... see http://www.gnu.org/s/libc/manual/html_node/Example-of-Getopt.html#Example-of-Getopt */
switch (c) {
case 'm':
pwm = atoi(optarg);
VERBOSE_PRINTF("-m pwm-value set to %i\n",pwm);
break;
case 'r':
filterId = optarg;
VERBOSE_PRINTF("-r filterId set to %s\n",filterId.toAscii().data());
break;
case 'j':
jointId = optarg;
VERBOSE_PRINTF("-j: jointId set to %s\n",jointId.toAscii().data());
break;
case 'v':
verbose_flag = 1;
printf("-v: Will be verbose\n");
break;
case 'n':
start_gui = false;
VERBOSE_PRINTF("starting/showing gui disabled, cmd-line-only version\n");
break;
case 'p':
VERBOSE_PRINTF("-p: Devicename given for serialport: %s !!!NOT SUPPORTED WITH GUI!!! trying to open...\n",optarg);
struct serial_struct serinfo;
int fd;
fd = ::open(optarg, O_RDWR | O_NONBLOCK );
if (fd >= 0) {
if (ioctl (fd, TIOCSSERIAL, &serinfo)) {
// serial device is a serial device, indeed
// see http://stackoverflow.com/questions/2530096/linux-how-to-find-all-serial-devices-ttys-ttyusb-without-opening-them
devicename = QString::fromAscii(optarg);
VERBOSE_PRINTF("\t\tsucessfully opened serial port %s, given device is valid...\n",devicename.toAscii().data());
} else {
printf("\t\tcould not access serial port, exiting\n");
::close(fd);
exit(EXIT_FAILURE);
}
::close(fd);
} else {
printf("\t\tcould not open serial port, exiting\n");
exit(EXIT_FAILURE);
}
break;
case 'f':
basename = optarg;
VERBOSE_PRINTF("-f: Basename for Outputfiles: %s\n",basename.toAscii().data());
break;
case 't':
record_sample_number = atoi(optarg);
VERBOSE_PRINTF("-t: Usergiven number of samples to record detected, will record %i samples\n",record_sample_number);
break;
case 'b':
baudrate = atoi(optarg);
VERBOSE_PRINTF("-b: Baudrate of serialport set to %i Baud\n",baudrate);
break;
case '?':
printf("guibabel: Clientsoftware to access PCM14S data from MEMS Microphone inside a FPGA over serial port.\n");
printf("usage:\n");
printf("\t-v - Boolean switch to be more verbose, used for debugging\n");
printf("\t-n - Boolean switch to disable GUI, used to access commandline mode\n");
printf("\t-f - Basename for the files used for logging/writing. Appropriate ending will be applied\n");
printf("\t-p - Devicename of serial port to use, like /dev/ttyUSB0\n");
printf("\t-b - Baudrate to use. Default is 230400\n");
printf("\t-t - Length of Samples to record. Mainly used in CMD-line mode. Set to -1 to preset infinite recording in GUI\n");
printf("\t-m - Set PWM-value of running motor. Used to log value in *.mat for later access\n");
printf("\t-j - Set JointID of used motor. Used to log value in *.mat for later access\n");
printf("\t-r - Set FilterID of used motor. Used to log value in *.mat for later access\n");
printf("\n");
printf("Guibabel will save recorded data as PCM16S *.wav file and custom Octave compatible *.mat file, containing some more informations\n");
exit(EXIT_FAILURE);
break;
default:
exit(EXIT_FAILURE);
}
}
if (optind < argc) {
printf("Non-supported cmdline arguments detected...\n");
exit(EXIT_FAILURE);
}
//-------------------
// hello world
//-------------------
printf("\n\tWelcome to guibabel\n\n");
VERBOSE_PRINTF("compiled on %s, at %s, running with threadID %i\n",__DATE__,__TIME__,(int)QThread::currentThreadId());
if (start_gui) {
gui w;
w.setBaudrate(baudrate);
w.setVerbosity(verbose_flag);
if (!basename.isEmpty())
w.setBasename(basename);
w.show();
return a.exec();
} else {
// myDekoder = new PCMdekoder();
// myDekoder->Set_baudrate(baudrate);
// myDekoder->Set_portname(devicename);
// myDekoder->Set_verbosity(verbose_flag);
// myDekoder->init();
// myDekoder->start();//now, serial port is beeing read
//
// myDekoder->drain = new sequenceRecorder();
// myDekoder->drain->setVerbosity(verbose_flag);
// myDekoder->drain->setpwmspeedtorque(pwm, -1, -1);
// myDekoder->drain->setfilterId( filterId );
// myDekoder->drain->setjointId( jointId );
// if (!basename.isEmpty())
// myDekoder->drain->setBasename(basename.toAscii().data());
//
// if (!myDekoder->drain->open()){
// printf("Error opening recorder, can't record\n");
// delete myDekoder->drain;
// return EXIT_FAILURE;
// }
// myDekoder->Set_sample_down_counter(record_sample_number);
// myDekoder->start_recording();
// while (myDekoder->is_recording) {
// usleep(100);
// }
// myDekoder->uninit();
// delete myDekoder;
// return EXIT_SUCCESS;
}
}
void termination_handler (int signum) {
VERBOSE_PRINTF("received signal %i, exiting\n",signum);
if (myDekoder) {
myDekoder->uninit();
delete myDekoder;
}
_exit(0);
}