gint host_port=45000;
#endif
+//
+// This is a variable for the second phase of STEMlab discovery.
+// Here we know we have a stemlab and will re-discover only P1
+//
+static int discover_only_p1 = 0;
+
static gboolean delete_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data) {
_exit(0);
}
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.
+ // To make this bullet-proof, we do another "discover" now
+ // and proceeding this way is the only way to choose between UDP and TCP connection
+ // Since we have just started the app, we temporarily deactivate STEMlab detection
//
- 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();
+ discover_only_p1=1;
+ gtk_widget_destroy(discovery_dialog);
+ g_idle_add(ext_discovery,NULL);
+ return TRUE;
}
- stemlab_cleanup();
#endif
gtk_widget_destroy(discovery_dialog);
start_radio();
#endif
#ifdef STEMLAB_DISCOVERY
- if(enable_stemlab) {
+ if(enable_stemlab && ! discover_only_p1) {
#ifdef NO_AVAHI
status_text("Looking for STEMlab WEB apps");
#else
old_discovery();
}
- if(enable_protocol_2) {
+ if(enable_protocol_2 && ! discover_only_p1) {
status_text("Protocol 2 ... Discovering Devices");
new_discovery();
}
#ifdef SOAPYSDR
- if(enable_soapy_protocol) {
+ if(enable_soapy_protocol && ! discover_only_p1) {
status_text("SoapySDR ... Discovering Devices");
soapy_discovery();
}
#endif
+ // subsequent discoveries check all protocols enabled.
+ discover_only_p1=0;
+
status_text("Discovery");
fprintf(stderr,"discovery: found %d devices\n", devices);
#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));
+ sprintf(text,"Choose RedPitaya App from %s and re-discover: ",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],
}
-#ifdef STEMLAB_DISCOVERY
-//
-// We have just started the SDR app on the RedPitaya without using AVAHI.
-// Therefore we must send a discovery packet and analyze its response
-// to have all information to start the radio.
-// Since this essentially what happens in the original discovery process,
-// we put this function HERE and not into stemlab_discovery.c
-//
-int stemlab_get_info(int id) {
- int ret;
- unsigned char buffer[1032];
- int optval,i;
-
- // Allow RP app to come up
- sleep(2);
-
- devices=id;
-
- discovery_socket = socket(AF_INET, SOCK_DGRAM, 0);
- if (discovery_socket < 0) {
- perror("stemlab_get_info socket():");
- return(1);
- }
-
- optval = 1;
- setsockopt(discovery_socket, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
- setsockopt(discovery_socket, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval));
-
- memset(&discovery_addr, 0, sizeof(discovery_addr));
- discovery_addr.sin_family=AF_INET;
- discovery_addr.sin_addr.s_addr=htonl(INADDR_ANY);
- // use system-assigned port in case 1024 is in use
- // e.g. by an HPSDR simulator
- discovery_addr.sin_port=htons(0);
- ret=bind(discovery_socket, (struct sockaddr *)&discovery_addr, sizeof(discovery_addr));
- if (ret < 0) {
- perror("stemlab_get_info bind():");
- return 1;
- }
- setsockopt(discovery_socket, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval));
-
- // start a receive thread to collect discovery response packets
- discover_thread_id = g_thread_new( "old discover receive", discover_receive_thread, NULL);
- if( ! discover_thread_id )
- {
- fprintf(stderr,"g_thread_new failed on discover_receive_thread\n");
- return 1;
- }
-
- // send discovery packet
- buffer[0]=0xEF;
- buffer[1]=0xFE;
- buffer[2]=0x02;
- for(i=3;i<63;i++) {
- buffer[i]=0x00;
- }
-
- ret=sendto(discovery_socket,buffer,63,0,
- (struct sockaddr*)&(discovered[id].info.network.address),
- sizeof(discovered[id].info.network.address));
- if (ret < 63) {
- perror("stemlab_get_info UDP sendto():");
- return -1;
- }
-
- // wait for receive thread to complete
- g_thread_join(discover_thread_id);
-
- close(discovery_socket);
-
- // if all went well, we have now filled in data for exactly
- // one device.
- if (devices == id+1) return 0;
-
- if (devices > id+1) return 1;
-
- // If we have not received an answer, then possibly the STEMlab is located
- // on a different subnet and UDP packets are not correctly routed through.
- // In this case, we try to open a connection using TCP.
-
- discovery_socket = socket(AF_INET, SOCK_STREAM, 0);
- if (discovery_socket < 0) {
- perror("stemlab_get_info socket():");
- return 1;
- }
-
- optval = 1;
- setsockopt(discovery_socket, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
- setsockopt(discovery_socket, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval));
- ret=connect(discovery_socket, (struct sockaddr*)&(discovered[id].info.network.address),
- sizeof(discovered[id].info.network.address));
- if (ret < 0) {
- perror("stemlab_get_info connect():");
- return 1;
- }
-
- // send discovery packet
- buffer[0]=0xEF;
- buffer[1]=0xFE;
- buffer[2]=0x02;
- for(i=3;i<1032;i++) {
- buffer[i]=0x00;
- }
-
- // start a receive thread to collect discovery response packets
- discover_thread_id = g_thread_new( "old discover receive", discover_receive_thread, NULL);
- if( ! discover_thread_id )
- {
- fprintf(stderr,"g_thread_new failed on discover_receive_thread\n");
- return 1;
- }
-
- ret=sendto(discovery_socket,buffer,1032,0,
- (struct sockaddr*)&(discovered[id].info.network.address),
- sizeof(discovered[id].info.network.address));
- if (ret < 1032) {
- perror("stemlab_get_info TCP sendto():");
- return -1;
- }
-
- // wait for receive thread to complete
- g_thread_join(discover_thread_id);
-
- close(discovery_socket);
-
- // if all went well, we have now filled in data for exactly
- // one device. We must set a flag that this one can ONLY do
- // TCP
- if (devices == id+1) {
- fprintf(stderr,"UDP did not work, but TCP does!\n");
- discovered[id].use_tcp=1;
- return 0;
- }
- return 1;
-}
-#endif
-
-//static void *discover_receive_thread(void* arg) {
static gpointer discover_receive_thread(gpointer data) {
struct sockaddr_in addr;
socklen_t len;