Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cristina-suteu committed Nov 27, 2024
1 parent fbd5aa5 commit 1a67750
Show file tree
Hide file tree
Showing 18 changed files with 1,084 additions and 963 deletions.
17 changes: 11 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ add_definitions(-D_GNU_SOURCE

add_compile_options(-Wall -Wextra -Werror
-Wno-unused-parameter
-Wno-error=unused-variable
-Wno-error=unused-but-set-variable
-Wno-error=unused-function
-Wno-error=deprecated
Expand All @@ -104,10 +105,14 @@ if(UNIX)
add_definitions(-Dlinux -DFRU_FILES="${CMAKE_PREFIX_PATH}/lib/fmc-tools/")
endif()

set(OSC_SRC osc.c oscplot.c datatypes.c iio_widget.c iio_utils.c
fru.c dialogs.c trigger_dialog.c xml_utils.c libini/libini.c
libini2.c phone_home.c plugins/dac_data_manager.c
plugins/fir_filter.c eeprom.c osc_preferences.c cJSON/cJSON.c)
#set(OSC_SRC osc.c oscplot.c datatypes.c iio_widget.c iio_utils.c
# fru.c dialogs.c trigger_dialog.c xml_utils.c libini/libini.c
# libini2.c phone_home.c plugins/dac_data_manager.c
# plugins/fir_filter.c eeprom.c osc_preferences.c cJSON/cJSON.c)
set(OSC_SRC osc.c datatypes.c iio_widget.c iio_utils.c
fru.c dialogs.c trigger_dialog.c xml_utils.c libini/libini.c
libini2.c phone_home.c plugins/dac_data_manager.c
plugins/fir_filter.c eeprom.c osc_preferences.c cJSON/cJSON.c)

find_package(PkgConfig)
pkg_check_modules(GLIB REQUIRED glib-2.0)
Expand All @@ -121,7 +126,7 @@ pkg_check_modules(JANSSON REQUIRED jansson)
pkg_check_modules(MATIO REQUIRED matio)

find_library(LIBIIO_LIBRARIES iio)
find_path(LIBIIO_INCLUDE_DIRS iio.h)
find_path(LIBIIO_INCLUDE_DIRS iio/iio.h)

find_library(LIBAD9361_LIBRARIES ad9361)
find_path(LIBAD9361_INCLUDE_DIRS ad9361.h)
Expand Down Expand Up @@ -301,7 +306,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/256x256/apps)
install(FILES icons/osc.svg RENAME adi-osc.svg
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps)

install(FILES ./styles.css DESTINATION ${SHARE_DEST})

# This is a bit "ugly". It makes sure that the hicolor theme directory updates
Expand Down
2 changes: 1 addition & 1 deletion datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <stdbool.h>
#include <fftw3.h>

#include <iio.h>
#include <iio/iio.h>

#define INITIAL_UPDATE TRUE
#define NORMAL_UPDATE FALSE
Expand Down
84 changes: 47 additions & 37 deletions dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <dirent.h>
#include <limits.h>

#include <iio.h>
#include <iio/iio.h>

#include "compat.h"
#include "fru.h"
Expand Down Expand Up @@ -347,10 +347,11 @@ static struct iio_context * get_context(Dialogs *data)
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialogs.connect_net))) {
const char *hostname = gtk_entry_get_text(GTK_ENTRY(dialogs.net_ip));
struct iio_context *ctx = get_context_from_osc();
const struct iio_attr *uri_attr = iio_context_find_attr(ctx, "uri");

if (ctx && !g_strcmp0(hostname, iio_context_get_attr_value(ctx, "uri")))
if (ctx && !g_strcmp0(hostname, iio_attr_get_static_value(uri_attr)))
return ctx;
return iio_create_context_from_uri(hostname);
return iio_create_context(NULL, hostname);
} else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialogs.connect_usb))) {
struct iio_context *ctx, *ctx2;
char *uri , *uri2, *uri3;
Expand Down Expand Up @@ -385,12 +386,13 @@ static struct iio_context * get_context(Dialogs *data)

/* are we the same URI? */
ctx2 = get_context_from_osc();
if (ctx2 && !g_strcmp0(uri2, iio_context_get_attr_value(ctx2, "uri"))) {
const struct iio_attr *uri_attr = iio_context_find_attr(ctx2, "uri");
if (ctx2 && !g_strcmp0(uri2, iio_attr_get_static_value(uri_attr))) {
g_free(uri);
return ctx2;
}

ctx = iio_create_context_from_uri(uri2);
ctx = iio_create_context(NULL, uri2);
/* If you are looking up ip: with zeroconf, without bonjour installed,
* try the IP number too
*/
Expand All @@ -400,7 +402,7 @@ static struct iio_context * get_context(Dialogs *data)
if (strchr(uri3, ' ')) {
uri2 = strchr(uri3, ' ');
*uri2 = 0;
ctx = iio_create_network_context(uri3);
ctx = iio_create_context(NULL, uri3);
}
free(uri3);
}
Expand All @@ -420,33 +422,34 @@ static struct iio_context * get_context(Dialogs *data)
g_free(port);
g_free(baud_rate);

ctx = iio_create_context_from_uri(result);
ctx = iio_create_context(NULL, result);
g_free(result);
if (!ctx && errno == EBUSY &&
!strcmp("serial", iio_context_get_name(get_context_from_osc()))) {
return get_context_from_osc();
}
return ctx;
} else {
return iio_create_local_context();
return iio_create_context(NULL, "local:");
}
}


static void refresh_usb_thread(void)
{
struct iio_scan_context *ctxs;
struct iio_context_info **info;
struct iio_scan *ctxs;
//struct iio_context_info **info;
GtkListStore *liststore;
ssize_t ret;
//ssize_t ret;
unsigned int i = 0;
gint index = 0;
gchar *tmp, *tmp1, *pid, *buf;
char *current = NULL;
char filter[sizeof("local:ip:usb:")];
char filter[sizeof("local:,ip:,usb:")];
char *p;
bool scan = false;
gchar *active_uri = NULL;
size_t ctxs_nb = 0;

gdk_threads_enter();
widget_set_cursor(dialogs.connect, GDK_WATCH);
Expand Down Expand Up @@ -477,35 +480,39 @@ static void refresh_usb_thread(void)

p = filter;
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialogs.filter_local))) {
p += sprintf(p, "local:");
p += sprintf(p, "local,");
scan = true;
}
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialogs.filter_usb))) {
p += sprintf(p, "usb:");
p += sprintf(p, "usb,");
scan = true;
}
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialogs.filter_ip))) {
p += sprintf(p, "ip:");
p += sprintf(p, "ip,");
scan = true;
}

i = 0;
if (!scan)
goto nope;

ctxs = iio_create_scan_context(filter, 0);
ctxs = iio_scan(NULL, filter);
if (!ctxs)
goto nope;

ret = iio_scan_context_get_info_list(ctxs, &info);
ctxs_nb = iio_scan_get_results_count(ctxs);

/*ret = iio_scan_context_get_info_list(ctxs, &info);
if (ret < 0)
goto err_free_ctxs;
if (!ret)
goto err_free_info_list;
goto err_free_info_list;*/

for (i = 0; i < (size_t) ret; i++) {
tmp = strdup(iio_context_info_get_description(info[i]));
pid = strdup(iio_context_info_get_description(info[i]));
for (i = 0; i < (size_t) ctxs_nb; i++) {
//tmp = strdup(iio_context_info_get_description(info[i]));
//pid = strdup(iio_context_info_get_description(info[i]));
tmp = strdup(iio_scan_get_description(ctxs, i));
pid = strdup(iio_scan_get_description(ctxs, i));

/* skip the PID/VID or IP Number, example descriptions are:
* 0456:b673 (Analog Devices Inc. PlutoSDR (ADALM-PLUTO)), serial=104473541196000618001900241f1e6931
Expand Down Expand Up @@ -538,10 +545,10 @@ static void refresh_usb_thread(void)

if (!tmp1)
tmp1 = tmp;
buf = malloc(strlen(iio_context_info_get_uri(info[i])) +
buf = malloc(strlen(iio_scan_get_uri(ctxs, i)) +
strlen(tmp1) + 5);
sprintf(buf, "%s [%s]", tmp1,
iio_context_info_get_uri(info[i]));
iio_scan_get_uri(ctxs, i));
tmp1 = NULL;

gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(dialogs.connect_usbd), buf);
Expand All @@ -551,12 +558,11 @@ static void refresh_usb_thread(void)

free(buf);
free(tmp);
}

err_free_info_list:
iio_context_info_list_free(info);
err_free_ctxs:
iio_scan_context_destroy(ctxs);
}
iio_scan_destroy(ctxs);
//err_free_ctxs:
// iio_scan_destroy(ctxs);
nope:

widget_use_parent_cursor(dialogs.connect);
Expand Down Expand Up @@ -682,6 +688,7 @@ static bool connect_fillin(Dialogs *data)
char text[256];
size_t i;
struct iio_context *ctx;
const struct iio_attr *attr;
const char *desc;
unsigned int n_devs, attr_cnt;

Expand Down Expand Up @@ -725,10 +732,12 @@ static bool connect_fillin(Dialogs *data)
attr_cnt = iio_context_get_attrs_count(ctx);
for (i = 0; i < attr_cnt; i++) {
const char *key, *value;
ssize_t ret;
//ssize_t ret;

ret = iio_context_get_attr(ctx, i, &key, &value);
if (!ret) {
attr = iio_context_get_attr(ctx, i);
if (attr) {
key = iio_attr_get_name(attr);
value = iio_attr_get_static_value(attr);
snprintf(text, sizeof(text), "%s = %s\n", key, value);
gtk_text_buffer_insert(buf, &iter, text, -1);
}
Expand Down Expand Up @@ -892,7 +901,8 @@ static gint fru_connect_dialog(Dialogs *data, bool load_profile)
ctx = get_context_from_osc();

if (ctx) {
ip_addr = iio_context_get_attr_value(ctx, "uri");
const struct iio_attr *ctx_uri = iio_context_find_attr(ctx, "uri");
ip_addr = iio_attr_get_static_value(ctx_uri);
if (ip_addr) {
gtk_entry_set_text(GTK_ENTRY(dialogs.net_ip), ip_addr);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialogs.connect_net), true);
Expand Down Expand Up @@ -1330,7 +1340,7 @@ void dialogs_init(GtkBuilder *builder)
gtk_widget_set_sensitive(GTK_WIDGET(gtk_builder_get_object(builder, "connect_usb_label")),
false);

if (iio_has_backend("serial")) {
if (iio_has_backend(NULL, "serial")) {
g_object_bind_property(dialogs.connect_serial, "active",
GTK_WIDGET(gtk_builder_get_object(builder,
"connect_serial_label")), "sensitive", 0);
Expand Down Expand Up @@ -1359,7 +1369,7 @@ void dialogs_init(GtkBuilder *builder)


/* test discoverable backends & hide if it's not supported */
if (iio_has_backend("usb")) {
if (iio_has_backend(NULL, "usb")) {
scan = true;
g_object_bind_property(dialogs.connect_usb, "active", dialogs.filter_usb,
"sensitive", G_BINDING_DEFAULT);
Expand All @@ -1370,7 +1380,7 @@ void dialogs_init(GtkBuilder *builder)
gtk_widget_set_sensitive(dialogs.filter_usb, false);
}

if(iio_has_backend("ip")) {
if(iio_has_backend(NULL, "ip")) {
scan = true;
g_object_bind_property(dialogs.connect_usb, "active", dialogs.filter_ip,
"sensitive", G_BINDING_DEFAULT);
Expand All @@ -1381,8 +1391,8 @@ void dialogs_init(GtkBuilder *builder)
gtk_widget_set_sensitive(dialogs.filter_ip, false);
}

if (iio_has_backend("local")) {
ctx = iio_create_local_context();
if (iio_has_backend(NULL, "local")) {
ctx = iio_create_context(NULL, "local:");
if (ctx) {
scan = true;
iio_context_destroy(ctx);
Expand Down
2 changes: 1 addition & 1 deletion iio_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef __IIO_UTILS__
#define __IIO_UTILS__

#include "iio.h"
#include "iio/iio.h"
#include <gmodule.h>

struct _GtkToggleToolButton;
Expand Down
Loading

0 comments on commit 1a67750

Please sign in to comment.