From 56fd3452da7838efb6efee8e06b1903bea1624dc Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan Date: Sat, 7 Dec 2024 22:28:09 +0530 Subject: [PATCH] call rust ffi function for discovery from C Fixes a bunch of types. Also, we don't use the generated header anymore. Instead use the one used by the rest of the code (DISCOVERED) which matches the type we defined earlier. Still helpful to generate the header and verify that it is indeed the one we are expecting. --- discovered.h | 5 +---- discovery.c | 9 +++++---- rust/discovery/src/discovery.rs | 8 ++++---- rust/discovery/src/ffi.rs | 22 +++++++++++----------- rust/discovery/src/types.rs | 10 +++++----- 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/discovered.h b/discovered.h index fe2308e..a57ccf7 100644 --- a/discovered.h +++ b/discovered.h @@ -59,14 +59,10 @@ struct _DISCOVERED { int protocol; int device; - int use_tcp; // use TCP rather than UDP to connect to radio char name[64]; int software_version; int status; int supported_receivers; - int supported_transmitters; - int adcs; - int dacs; double frequency_min; double frequency_max; struct network { @@ -76,6 +72,7 @@ struct _DISCOVERED { struct sockaddr_in interface_netmask; char interface_name[64]; } network; + int use_tcp; }; typedef struct _DISCOVERED DISCOVERED; diff --git a/discovery.c b/discovery.c index c3875de..e327fba 100644 --- a/discovery.c +++ b/discovery.c @@ -37,7 +37,6 @@ #endif #include "discovered.h" -#include "p1_discovery.h" #include "main.h" #include "radio.h" #ifdef USBOZY @@ -58,6 +57,7 @@ static GtkWidget *discovery_dialog; static DISCOVERED *d; +extern int discover_devices_ffi(DISCOVERED *devices, int); GtkWidget *tcpaddr; #define IPADDR_LEN 20 @@ -301,8 +301,9 @@ void discovery(void) { #endif if(enable_protocol_1) { - status_text("Protocol 1 ... Discovering Devices"); - p1_discovery(); + log_info("Protocol 1 ... Discovering Devices"); + // p1_discovery(); + devices = discover_devices_ffi(discovered, MAX_DEVICES); } /* if(enable_protocol_2) { */ @@ -310,7 +311,7 @@ void discovery(void) { /* new_discovery(); */ /* } */ - status_text("Discovery"); + log_info("Discovery"); log_info("discovery: found %d devices", devices); gdk_window_set_cursor(gtk_widget_get_window(top_window),gdk_cursor_new(GDK_ARROW)); diff --git a/rust/discovery/src/discovery.rs b/rust/discovery/src/discovery.rs index dd319ca..afc3b45 100644 --- a/rust/discovery/src/discovery.rs +++ b/rust/discovery/src/discovery.rs @@ -54,7 +54,7 @@ fn parse_discovery_response(data: &[u8], addr: SocketAddr) -> Option ("Metis", 0.0, 61440000.0), 0x01 => ("Hermes", 0.0, 61440000.0), @@ -67,11 +67,11 @@ fn parse_discovery_response(data: &[u8], addr: SocketAddr) -> Option CFfiDiscoveredDevice { let name_c = CString::new(device.name.clone()).unwrap(); - let mut name_arr = [0i8; 32]; + let mut name_arr = [0i8; 64]; for (i, &b) in name_c.as_bytes().iter().enumerate().take(31) { name_arr[i] = b as i8; } diff --git a/rust/discovery/src/types.rs b/rust/discovery/src/types.rs index ed08914..b157e55 100644 --- a/rust/discovery/src/types.rs +++ b/rust/discovery/src/types.rs @@ -11,12 +11,12 @@ pub struct NetworkInfo { #[derive(Debug, Clone)] pub struct DiscoveredDevice { - pub protocol: u32, - pub device: u8, + pub protocol: i32, + pub device: i32, pub name: String, - pub software_version: u8, - pub status: u32, - pub supported_receivers: u32, + pub software_version: i32, + pub status: i32, + pub supported_receivers: i32, pub frequency_min: f64, pub frequency_max: f64, pub network: NetworkInfo, -- 2.45.2