forked from g0orx/pihpsdr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscovery.c
619 lines (547 loc) · 21.2 KB
/
discovery.c
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
/* Copyright (C)
* 2015 - John Melton, G0ORX/N6LYT
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <math.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <semaphore.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#ifdef MIDI
#include <sys/stat.h>
#endif
#include "discovered.h"
#include "old_discovery.h"
#include "new_discovery.h"
#ifdef SOAPYSDR
#include "soapy_discovery.h"
#endif
#include "main.h"
#include "radio.h"
#ifdef USBOZY
#include "ozyio.h"
#endif
#ifdef REMOTE
#include "remote_radio.h"
#endif
#ifdef STEMLAB_DISCOVERY
#include "stemlab_discovery.h"
#endif
#include "ext.h"
#ifdef GPIO
#include "gpio.h"
#include "configure.h"
#endif
#include "protocols.h"
static GtkWidget *discovery_dialog;
static DISCOVERED *d;
#ifdef STEMLAB_DISCOVERY
static GtkWidget *apps_combobox[MAX_DEVICES];
#endif
GtkWidget *tcpaddr;
#define IPADDR_LEN 20
static char ipaddr_tcp_buf[IPADDR_LEN] = "10.10.10.10";
char *ipaddr_tcp = &ipaddr_tcp_buf[0];
#ifdef SERVER
GtkWidget *connect_addr_entry;
static char connect_addr_buffer[30]="0.0.0.0:50000";
char *connect_addr = &connect_addr_buffer[0];
#endif
static gboolean delete_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data) {
_exit(0);
}
static gboolean start_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
radio=(DISCOVERED *)data;
#ifdef STEMLAB_DISCOVERY
// We need to start the STEMlab app before destroying the dialog, since
// we otherwise lose the information about which app has been selected.
if (radio->protocol == STEMLAB_PROTOCOL) {
const int device_id = radio - discovered;
int ret;
if (radio->software_version & BARE_REDPITAYA) {
// Start via the simple web interface
ret=alpine_start_app(gtk_combo_box_get_active_id(GTK_COMBO_BOX(apps_combobox[device_id])));
} else {
// Start via the STEMlab "bazaar" interface
ret=stemlab_start_app(gtk_combo_box_get_active_id(GTK_COMBO_BOX(apps_combobox[device_id])));
}
//
// We have started the SDR app on the RedPitaya, but may need to fill
// in information necessary for starting the radio, including the
// MAC address and the interface listening to. Even when using AVAHI,
// we miss some information.
// To get all required info, we do a "fake" discovery on the RedPitaya IP address.
// Here we also try TCP if UDP does not work, such that we can work with STEMlabs
// in remote subnets.
//
if (ret == 0) {
ret=stemlab_get_info(device_id);
}
// At this point, if stemlab_start_app failed, we cannot recover
if (ret != 0) exit(-1);
}
stemlab_cleanup();
#endif
gtk_widget_destroy(discovery_dialog);
start_radio();
return TRUE;
}
#ifdef MIDI
//
// This is a file open dialog. If we choose a readable file here, it is just copied
// to file "midi.props" in the local directory
//
static gboolean midi_cb(GtkWidget *widget, GdkEventButton *event, gpointer data) {
GtkWidget *opfile,*message;
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
gint res;
int fdin, fdout;
size_t len,bytes_read,bytes_written;
opfile = gtk_file_chooser_dialog_new ("Import MIDI description",
GTK_WINDOW(top_window),
action,
"Cancel",
GTK_RESPONSE_CANCEL,
"Open",
GTK_RESPONSE_ACCEPT,
NULL);
res = gtk_dialog_run (GTK_DIALOG (opfile));
if (res == GTK_RESPONSE_ACCEPT) {
char *filename, *cp;
struct stat statbuf;
GtkFileChooser *chooser = GTK_FILE_CHOOSER (opfile);
char *contents = NULL;
filename = gtk_file_chooser_get_filename (chooser);
fdin =open(filename, O_RDONLY);
bytes_read = bytes_written = 0;
if (fdin >= 0) {
fstat(fdin, &statbuf);
len=statbuf.st_size;
//
// Now first read the whole contents of the file, and then write it out.
// This is for new-bees trying to import the midi.props in the working dir
//
contents=g_new(char, len);
bytes_read = bytes_written = 0;
if (contents) {
bytes_read=read(fdin, contents, len);
}
close(fdin);
}
fdout=0;
if (contents && bytes_read == len) {
// should this file exist as a link or symlink, or should it
// be read-only, remove it first
unlink("midi.props");
fdout=open("midi.props", O_WRONLY | O_CREAT, 0644);
if (fdout >= 0) {
bytes_written=write(fdout, contents, len);
close(fdout);
g_free(contents);
}
}
if (fdin < 0 || bytes_read < len) {
message = gtk_message_dialog_new (GTK_WINDOW(top_window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Cannot read input file!\n");
gtk_dialog_run (GTK_DIALOG (message));
gtk_widget_destroy(message);
} else if (fdout < 0 || bytes_written < len) {
message = gtk_message_dialog_new (GTK_WINDOW(top_window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Cannot write MIDI settings!\n");
gtk_dialog_run (GTK_DIALOG (message));
gtk_widget_destroy(message);
} else {
// only show basename in the message
cp = filename + strlen(filename);
while (cp >= filename) {
if (*cp == '/') {
cp++;
break;
}
cp--;
}
message = gtk_message_dialog_new (GTK_WINDOW(top_window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"MIDI import: %ld Bytes read from file %s\n",len,cp);
gtk_dialog_run (GTK_DIALOG (message));
gtk_widget_destroy(message);
}
g_free(filename);
}
gtk_widget_destroy (opfile);
return TRUE;
}
#endif
static gboolean protocols_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
configure_protocols(discovery_dialog);
return TRUE;
}
#ifdef GPIO
static gboolean gpio_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
configure_gpio(discovery_dialog);
return TRUE;
}
static void gpio_changed_cb(GtkWidget *widget, gpointer data) {
controller=gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
gpio_set_defaults(controller);
gpio_save_state();
}
#endif
static gboolean discover_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
gtk_widget_destroy(discovery_dialog);
g_idle_add(ext_discovery,NULL);
return TRUE;
}
static gboolean exit_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
gtk_widget_destroy(discovery_dialog);
_exit(0);
return TRUE;
}
static gboolean tcp_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
strncpy(ipaddr_tcp, gtk_entry_get_text(GTK_ENTRY(tcpaddr)), IPADDR_LEN);
ipaddr_tcp[IPADDR_LEN-1]=0;
// remove possible trailing newline chars in ipaddr_tcp
int len=strnlen(ipaddr_tcp,IPADDR_LEN);
while (--len >= 0) {
if (ipaddr_tcp[len] != '\n') break;
ipaddr_tcp[len]=0;
}
//fprintf(stderr,"New TCP addr = %s.\n", ipaddr_tcp);
// save this value to config file
FILE *fp = fopen("ip.addr", "w");
if (fp) {
fprintf(fp,"%s\n",ipaddr_tcp);
fclose(fp);
}
gtk_widget_destroy(discovery_dialog);
g_idle_add(ext_discovery,NULL);
return TRUE;
}
#ifdef SERVER
static gboolean connect_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
// connect to remote host running piHPSDR
strncpy(connect_addr, gtk_entry_get_text(GTK_ENTRY(connect_addr_entry)), 30);
g_print("connect_cb: %s\n",connect_addr);
return TRUE;
}
#endif
void discovery() {
//fprintf(stderr,"discovery\n");
protocols_restore_state();
selected_device=0;
devices=0;
// Try to locate IP addr
FILE *fp=fopen("ip.addr","r");
if (fp) {
fgets(ipaddr_tcp, IPADDR_LEN,fp);
fclose(fp);
ipaddr_tcp[IPADDR_LEN-1]=0;
// remove possible trailing newline char in ipaddr_tcp
int len=strnlen(ipaddr_tcp,IPADDR_LEN);
while (--len >= 0) {
if (ipaddr_tcp[len] != '\n') break;
ipaddr_tcp[len]=0;
}
}
#ifdef USBOZY
//
// first: look on USB for an Ozy
//
fprintf(stderr,"looking for USB based OZY devices\n");
if (ozy_discover() != 0)
{
discovered[devices].protocol = ORIGINAL_PROTOCOL;
discovered[devices].device = DEVICE_OZY;
discovered[devices].software_version = 10; // we can't know yet so this isn't a real response
discovered[devices].status = STATE_AVAILABLE;
strcpy(discovered[devices].name,"Ozy on USB");
strcpy(discovered[devices].info.network.interface_name,"USB");
devices++;
}
#endif
#ifdef STEMLAB_DISCOVERY
if(enable_stemlab) {
#ifdef NO_AVAHI
status_text("Looking for STEMlab WEB apps");
#else
status_text("STEMlab (Avahi) ... Discovering Devices");
#endif
stemlab_discovery();
}
#endif
if(enable_protocol_1) {
status_text("Protocol 1 ... Discovering Devices");
old_discovery();
}
if(enable_protocol_2) {
status_text("Protocol 2 ... Discovering Devices");
new_discovery();
}
#ifdef SOAPYSDR
if(enable_soapy_protocol) {
status_text("SoapySDR ... Discovering Devices");
soapy_discovery();
}
#endif
status_text("Discovery");
if(devices==0) {
gdk_window_set_cursor(gtk_widget_get_window(top_window),gdk_cursor_new(GDK_ARROW));
discovery_dialog = gtk_dialog_new();
gtk_window_set_transient_for(GTK_WINDOW(discovery_dialog),GTK_WINDOW(top_window));
gtk_window_set_title(GTK_WINDOW(discovery_dialog),"piHPSDR - Discovery");
//gtk_window_set_decorated(GTK_WINDOW(discovery_dialog),FALSE);
//gtk_widget_override_font(discovery_dialog, pango_font_description_from_string("FreeMono 16"));
g_signal_connect(discovery_dialog, "delete_event", G_CALLBACK(delete_event_cb), NULL);
GdkRGBA color;
color.red = 1.0;
color.green = 1.0;
color.blue = 1.0;
color.alpha = 1.0;
gtk_widget_override_background_color(discovery_dialog,GTK_STATE_FLAG_NORMAL,&color);
GtkWidget *content;
content=gtk_dialog_get_content_area(GTK_DIALOG(discovery_dialog));
GtkWidget *grid=gtk_grid_new();
gtk_grid_set_row_homogeneous(GTK_GRID(grid),TRUE);
gtk_grid_set_column_homogeneous(GTK_GRID(grid),TRUE);
gtk_grid_set_row_spacing (GTK_GRID(grid),10);
GtkWidget *label=gtk_label_new("No devices found!");
gtk_grid_attach(GTK_GRID(grid),label,0,0,2,1);
GtkWidget *exit_b=gtk_button_new_with_label("Exit");
g_signal_connect (exit_b, "button-press-event", G_CALLBACK(exit_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),exit_b,0,1,1,1);
GtkWidget *discover_b=gtk_button_new_with_label("Retry Discovery");
g_signal_connect (discover_b, "button-press-event", G_CALLBACK(discover_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),discover_b,1,1,1,1);
GtkWidget *tcp_b=gtk_button_new_with_label("Use new TCP Addr:");
g_signal_connect (tcp_b, "button-press-event", G_CALLBACK(tcp_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),tcp_b,0,2,1,1);
tcpaddr=gtk_entry_new();
gtk_entry_set_max_length(GTK_ENTRY(tcpaddr), 20);
gtk_grid_attach(GTK_GRID(grid),tcpaddr,1,2,1,1);
gtk_entry_set_text(GTK_ENTRY(tcpaddr), ipaddr_tcp);
gtk_container_add (GTK_CONTAINER (content), grid);
gtk_widget_show_all(discovery_dialog);
} else {
fprintf(stderr,"discovery: found %d devices\n", devices);
gdk_window_set_cursor(gtk_widget_get_window(top_window),gdk_cursor_new(GDK_ARROW));
discovery_dialog = gtk_dialog_new();
gtk_window_set_transient_for(GTK_WINDOW(discovery_dialog),GTK_WINDOW(top_window));
gtk_window_set_title(GTK_WINDOW(discovery_dialog),"piHPSDR - Discovery");
//gtk_window_set_decorated(GTK_WINDOW(discovery_dialog),FALSE);
//gtk_widget_override_font(discovery_dialog, pango_font_description_from_string("FreeMono 16"));
g_signal_connect(discovery_dialog, "delete_event", G_CALLBACK(delete_event_cb), NULL);
GdkRGBA color;
color.red = 1.0;
color.green = 1.0;
color.blue = 1.0;
color.alpha = 1.0;
gtk_widget_override_background_color(discovery_dialog,GTK_STATE_FLAG_NORMAL,&color);
GtkWidget *content;
content=gtk_dialog_get_content_area(GTK_DIALOG(discovery_dialog));
GtkWidget *grid=gtk_grid_new();
gtk_grid_set_row_homogeneous(GTK_GRID(grid),TRUE);
//gtk_grid_set_column_homogeneous(GTK_GRID(grid),TRUE);
gtk_grid_set_row_spacing (GTK_GRID(grid),10);
int row;
char version[16];
char text[256];
for(row=0;row<devices;row++) {
d=&discovered[row];
fprintf(stderr,"%p Protocol=%d name=%s\n",d,d->protocol,d->name);
sprintf(version,"v%d.%d",
d->software_version/10,
d->software_version%10);
switch(d->protocol) {
case ORIGINAL_PROTOCOL:
case NEW_PROTOCOL:
#ifdef USBOZY
if(d->device==DEVICE_OZY) {
sprintf(text,"%s (%s) on USB /dev/ozy", d->name, d->protocol==ORIGINAL_PROTOCOL?"Protocol 1":"Protocol 2");
} else {
#endif
sprintf(text,"%s (%s %s) %s (%02X:%02X:%02X:%02X:%02X:%02X) on %s: ",
d->name,
d->protocol==ORIGINAL_PROTOCOL?"Protocol 1":"Protocol 2",
version,
inet_ntoa(d->info.network.address.sin_addr),
d->info.network.mac_address[0],
d->info.network.mac_address[1],
d->info.network.mac_address[2],
d->info.network.mac_address[3],
d->info.network.mac_address[4],
d->info.network.mac_address[5],
d->info.network.interface_name);
#ifdef USBOZY
}
#endif
break;
#ifdef SOAPYSDR
case SOAPYSDR_PROTOCOL:
sprintf(text,"%s (Protocol SOAPY_SDR %s) on USB",d->name,d->info.soapy.version);
break;
#endif
#ifdef STEMLAB_DISCOVERY
case STEMLAB_PROTOCOL:
#ifdef NO_AVAHI
sprintf(text,"Choose RedPitaya App from %s and start radio: ",inet_ntoa(d->info.network.address.sin_addr));
#else
sprintf(text, "STEMlab (%02X:%02X:%02X:%02X:%02X:%02X) on %s",
d->info.network.mac_address[0],
d->info.network.mac_address[1],
d->info.network.mac_address[2],
d->info.network.mac_address[3],
d->info.network.mac_address[4],
d->info.network.mac_address[5],
d->info.network.interface_name);
#endif
#endif
}
GtkWidget *label=gtk_label_new(text);
gtk_widget_override_font(label, pango_font_description_from_string("Sans 11"));
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_widget_show(label);
gtk_grid_attach(GTK_GRID(grid),label,0,row,3,1);
GtkWidget *start_button=gtk_button_new_with_label("Start");
gtk_widget_override_font(start_button, pango_font_description_from_string("Sans 16"));
gtk_widget_show(start_button);
gtk_grid_attach(GTK_GRID(grid),start_button,3,row,1,1);
g_signal_connect(start_button,"button_press_event",G_CALLBACK(start_cb),(gpointer)d);
// if not available then cannot start it
if(d->status!=STATE_AVAILABLE) {
gtk_button_set_label(GTK_BUTTON(start_button),"In Use");
gtk_widget_set_sensitive(start_button, FALSE);
}
#ifdef SOAPYSDR
if(d->device!=SOAPYSDR_USB_DEVICE) {
#endif
// if not on the same subnet then cannot start it
if((d->info.network.interface_address.sin_addr.s_addr&d->info.network.interface_netmask.sin_addr.s_addr) != (d->info.network.address.sin_addr.s_addr&d->info.network.interface_netmask.sin_addr.s_addr)) {
gtk_button_set_label(GTK_BUTTON(start_button),"Subnet!");
gtk_widget_set_sensitive(start_button, FALSE);
}
#ifdef SOAPYSDR
}
#endif
#ifdef STEMLAB_DISCOVERY
if (d->protocol == STEMLAB_PROTOCOL) {
if (d->software_version == 0) {
gtk_button_set_label(GTK_BUTTON(start_button), "Not installed");
gtk_widget_set_sensitive(start_button, FALSE);
} else {
apps_combobox[row] = gtk_combo_box_text_new();
gtk_widget_override_font(apps_combobox[row], pango_font_description_from_string("Sans 11"));
// We want the default selection priority for the STEMlab app to be
// RP-Trx > HAMlab-Trx > Pavel-Trx > Pavel-Rx, so we add in decreasing order and
// always set the newly added entry to be active.
if ((d->software_version & STEMLAB_PAVEL_RX) != 0) {
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(apps_combobox[row]),
"sdr_receiver_hpsdr", "Pavel-Rx");
gtk_combo_box_set_active_id(GTK_COMBO_BOX(apps_combobox[row]),
"sdr_receiver_hpsdr");
}
if ((d->software_version & STEMLAB_PAVEL_TRX) != 0) {
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(apps_combobox[row]),
"sdr_transceiver_hpsdr", "Pavel-Trx");
gtk_combo_box_set_active_id(GTK_COMBO_BOX(apps_combobox[row]),
"sdr_transceiver_hpsdr");
}
if ((d->software_version & HAMLAB_RP_TRX) != 0) {
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(apps_combobox[row]),
"hamlab_sdr_transceiver_hpsdr", "HAMlab-Trx");
gtk_combo_box_set_active_id(GTK_COMBO_BOX(apps_combobox[row]),
"hamlab_sdr_transceiver_hpsdr");
}
if ((d->software_version & STEMLAB_RP_TRX) != 0) {
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(apps_combobox[row]),
"stemlab_sdr_transceiver_hpsdr", "STEMlab-Trx");
gtk_combo_box_set_active_id(GTK_COMBO_BOX(apps_combobox[row]),
"stemlab_sdr_transceiver_hpsdr");
}
gtk_widget_show(apps_combobox[row]);
gtk_grid_attach(GTK_GRID(grid), apps_combobox[row], 4, row, 1, 1);
}
}
#endif
}
#ifdef GPIO
controller=CONTROLLER2_V2;
gpio_set_defaults(controller);
gpio_restore_state();
GtkWidget *gpio=gtk_combo_box_text_new();
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(gpio),NULL,"No Controller");
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(gpio),NULL,"Controller1");
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(gpio),NULL,"Controller2 V1");
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(gpio),NULL,"Controller2 V2");
gtk_grid_attach(GTK_GRID(grid),gpio,0,row,1,1);
gtk_combo_box_set_active(GTK_COMBO_BOX(gpio),controller);
g_signal_connect(gpio,"changed",G_CALLBACK(gpio_changed_cb),NULL);
#endif
GtkWidget *discover_b=gtk_button_new_with_label("Discover");
g_signal_connect (discover_b, "button-press-event", G_CALLBACK(discover_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),discover_b,1,row,1,1);
GtkWidget *protocols_b=gtk_button_new_with_label("Protocols");
g_signal_connect (protocols_b, "button-press-event", G_CALLBACK(protocols_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),protocols_b,2,row,1,1);
#ifdef MIDI
GtkWidget *midi_b=gtk_button_new_with_label("ImportMIDI");
g_signal_connect (midi_b, "button-press-event", G_CALLBACK(midi_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),midi_b,3,row,1,1);
#endif
row++;
#ifdef GPIO
GtkWidget *gpio_b=gtk_button_new_with_label("Configure GPIO");
g_signal_connect (gpio_b, "button-press-event", G_CALLBACK(gpio_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),gpio_b,0,row,1,1);
#endif
GtkWidget *tcp_b=gtk_button_new_with_label("Use new TCP Addr:");
g_signal_connect (tcp_b, "button-press-event", G_CALLBACK(tcp_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),tcp_b,1,row,1,1);
tcpaddr=gtk_entry_new();
gtk_entry_set_max_length(GTK_ENTRY(tcpaddr), 20);
gtk_grid_attach(GTK_GRID(grid),tcpaddr,2,row,1,1);
gtk_entry_set_text(GTK_ENTRY(tcpaddr), ipaddr_tcp);
GtkWidget *exit_b=gtk_button_new_with_label("Exit");
g_signal_connect (exit_b, "button-press-event", G_CALLBACK(exit_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),exit_b,3,row,1,1);
#ifdef SERVER
row++;
GtkWidget *connect_b=gtk_button_new_with_label("Connect (Addr:Port)");
g_signal_connect (connect_b, "button-press-event", G_CALLBACK(connect_cb), NULL);
gtk_grid_attach(GTK_GRID(grid),connect_b,0,row,1,1);
connect_addr_entry=gtk_entry_new();
gtk_entry_set_max_length(GTK_ENTRY(connect_addr_entry), 30);
gtk_grid_attach(GTK_GRID(grid),connect_addr_entry,1,row,1,1);
gtk_entry_set_text(GTK_ENTRY(connect_addr_entry), connect_addr);
#endif
gtk_container_add (GTK_CONTAINER (content), grid);
gtk_widget_show_all(discovery_dialog);
fprintf(stderr,"showing device dialog\n");
}
}