commit a617ef61f2fb5b855054c1fa024b35d1e5708ee9
parent 2ad0dae6add93c588f8fc41563a600e3312db67f
Author: Tellenbach Reto <tellr1@bfh.ch>
Date: Sun, 17 May 2026 21:17:23 +0200
[new] thinker_TalerAPI: GNUNET utilisation
Diffstat:
9 files changed, 255 insertions(+), 261 deletions(-)
diff --git a/thinker/CoinAcceptor/src/gpiod_wrapper.c b/thinker/CoinAcceptor/src/gpiod_wrapper.c
@@ -2,9 +2,6 @@
#define _GNU_SOURCE
#endif
-#include <gpiod.h>
-#include <stdlib.h>
-#include <stdio.h>
#include "gpiod_wrapper.h"
struct gpiod_chip *gpiod_chip_open_by_name(const char *name)
diff --git a/thinker/CoinAcceptor/src/gpiod_wrapper.h b/thinker/CoinAcceptor/src/gpiod_wrapper.h
@@ -5,6 +5,8 @@
//heavily inspired from gpiod source example of Gent Gibson toggle_line_value.c
#include <gpiod.h>
+#include <stdlib.h>
+#include <stdio.h>
struct gpiod_chip *gpiod_chip_open_by_name(const char *name);
diff --git a/thinker/CoinAcceptor/src/main.c b/thinker/CoinAcceptor/src/main.c
@@ -19,158 +19,6 @@ enum command{
};
static char keyInput = down;
-//GPIOD Wrapers
-typedef struct {
- struct gpiod_line_request* request;
- unsigned int offset;
-} gpiod_line;
-
-struct gpiod_chip *gpiod_chip_open_by_name(const char *name)
-{
- struct gpiod_chip *chip;
- char *path;
- int ret;
-
- ret = asprintf(&path, "/dev/%s", name);
- if (ret < 0)
- {
- perror("asprint() memory-allocation failed");
- return NULL;
- }
-
-
- chip = gpiod_chip_open(path);
- free(path);
-
- return chip;
-}
-
-struct gpiod_line_settings* gpiod_make_settings(enum gpiod_line_direction direction,enum gpiod_line_bias bias, enum gpiod_line_drive drive, enum gpiod_line_drive active_low)
-{
- int ret = 0;
- struct gpiod_line_settings* settings = gpiod_line_settings_new();
- if (!settings)
- {
- perror("gpiod_line_settings_new() failed");
- return NULL;
- }
-
- ret |= gpiod_line_settings_set_direction(settings, direction);
- ret |= gpiod_line_settings_set_bias(settings, bias);
- ret |= gpiod_line_settings_set_drive(settings, drive);
- gpiod_line_settings_set_active_low(settings, active_low);
- if (ret)
- {
- perror("gpiod_line_settings_set....() failed");
- return NULL;
- }
-
-
- return settings;
-}
-
-struct gpiod_line_request* gpiod_make_line_request_by_name(const char* chipname, const char* linename, struct gpiod_line_settings* settings)
-{
- struct gpiod_request_config* request_cfg = NULL; //for kernel settings, not used here
- struct gpiod_line_request* request = NULL;
- struct gpiod_line_config* line_cfg;
- struct gpiod_chip* chip;
- int ret = 0;
-
-
- chip = gpiod_chip_open_by_name(chipname);
- if (!chip)
- {
- perror("gpiod_chip_open_by_name() failed");
- goto free_settings;
- }
-
-
- const int line_offset = gpiod_chip_get_line_offset_from_name(chip, linename);
- if(line_offset<0)
- {
- perror("gpiod_chip_get_line_offset_from_name() failed");
- goto close_chip;
- }
-
- const unsigned int u_line_offset = (unsigned int)line_offset;
-
- line_cfg = gpiod_line_config_new();
- if (!line_cfg)
- {
- perror("gpiod_line_config_new() failed");
- goto close_chip;
- }
-
-
- ret = gpiod_line_config_add_line_settings(line_cfg, &u_line_offset, 1, settings);
- if (ret)
- {
- perror("gpiod_line_config_add_line_settings() failed");
- goto free_line_cfg;
- }
-
-
- request = gpiod_chip_request_lines(chip, request_cfg, line_cfg);
-
-free_line_cfg:
- gpiod_line_config_free(line_cfg);
-
-close_chip:
- gpiod_chip_close(chip);
-
-free_settings:
- gpiod_line_settings_free(settings);
-
- return request; //NULL on error
-}
-
-struct gpiod_line_request* gpiod_make_line_request(const char* chip_path, const unsigned int line_offset, struct gpiod_line_settings* settings)
-{
- struct gpiod_request_config* request_cfg = NULL; //for kernel settings, not used here
- struct gpiod_line_request* request = NULL;
- struct gpiod_line_config* line_cfg;
- struct gpiod_chip* chip;
- int ret = 0;
-
- chip = gpiod_chip_open(chip_path);
- if (!chip)
- {
- perror("gpiod_chip_open_by_name() failed");
- goto free_settings;
- }
-
-
- line_cfg = gpiod_line_config_new();
- if (!line_cfg)
- {
- perror("gpiod_line_config_new() failed");
- goto close_chip;
- }
-
-
- ret = gpiod_line_config_add_line_settings(line_cfg, &line_offset, 1, settings);
- if (ret)
- {
- perror("gpiod_line_config_add_line_settings() failed");
- goto free_line_cfg;
- }
-
-
- request = gpiod_chip_request_lines(chip, request_cfg, line_cfg);
-
-free_line_cfg:
- gpiod_line_config_free(line_cfg);
-
-close_chip:
- gpiod_chip_close(chip);
-
-free_settings:
- gpiod_line_settings_free(settings);
-
- return request; //NULL on error
-}
-
int main(void)
{
diff --git a/thinker/taler_api/src/CMakeLists.txt b/thinker/taler_api/src/CMakeLists.txt
@@ -1,6 +1,6 @@
# Add files
-#add_library(wrapper ssss.c
-add_executable(taler-api main.c)
+add_executable(taler-api taler-digitizer.c)
+#add_library(digitizer_utils os_installation.c)
# libs
find_package(CURL REQUIRED)
@@ -9,8 +9,8 @@ pkg_check_modules(GNUNET REQUIRED gnunetutil)
# Manage libs
target_link_libraries(taler-api
- PRIVATE
- CURL::libcurl
- gnunetutil
+ PRIVATE CURL::libcurl gnunetutil
)
+#include <gnunet/gnunet_util_lib.h>
+#include "taler_digitizer_util.h"
+\ No newline at end of file
diff --git a/thinker/taler_api/src/error_codes.h b/thinker/taler_api/src/error_codes.h
@@ -0,0 +1,20 @@
+#ifndef ERROR_CODES_H
+#define ERROR_CODES_H
+
+/**
+ * Taler client Cash Digitizer errors.
+ */
+enum DIGITIZER_ErrorCode
+{
+ /**
+ * indicate success (no error)
+ */
+ DIGITIZER_EC_NONE = 0,
+
+ /**
+ * non specific fail
+ */
+ DIGITIZER_EC_GENERIC = 1,
+};
+
+#endif
+\ No newline at end of file
diff --git a/thinker/taler_api/src/main.c b/thinker/taler_api/src/main.c
@@ -1,101 +0,0 @@
-#include <stdio.h>
-//#include <qrencode.h>
-#include <taler/taler_util.h>
-#include <taler/taler_curl_lib.h>
-#include <curl/curl.h>
-
-//CLI Controlls
-enum command{
- quit = 'q',
- up = 'w',
- down = 's'
-};
-static char keyInput = down;
-
-// CONFIGS
-#define TALER_EXCHANGE_URL "https://exchange.demo.taler.net/config"
-//#define TALER_HTTP_REQUEST_CONTENT_TYPE "application/json"
-
-/**
- * Taler client Cash Digitizer errors.
- */
-enum DIGITIZER_ErrorCode
-{
- /**
- * indicate success (no error)
- */
- DIGITIZER_EC_NONE = 0,
-
- /**
- * non specific fail
- */
- DIGITIZER_EC_GENERIC = 1,
-};
-
-
-/**
- * return from main(). 0 on success, non-zero on errors.
- */
-int main(void)
-{
- printf("Send money to wallet\n");
- enum DIGITIZER_ErrorCode ret = 0;
-
- /*** Init Curl ***/
- CURL *curl;
-
-
- if(curl_global_init(CURL_GLOBAL_ALL)!= CURLE_OK)
- {
- TALER_LOG_ERROR("curl_global_init() failed at %s:%d\n", __FILE__, __LINE__);
- return DIGITIZER_EC_GENERIC;
- }
-
-
- curl = curl_easy_init();
- if(NULL == curl)
- {
- TALER_LOG_ERROR("curl_easy_init() failed at %s:%d\n", __FILE__, __LINE__);
- ret = DIGITIZER_EC_GENERIC;
- }
- else
- {
- // GET /cocnfig
- if(curl_easy_setopt(curl, CURLOPT_URL, TALER_EXCHANGE_URL) != CURLE_OK)
- {
- TALER_LOG_ERROR("curl_easy_setopt() failed at %s:%d\n", __FILE__, __LINE__);
- ret = DIGITIZER_EC_GENERIC;
- }
- else if(curl_easy_perform(curl) != CURLE_OK)
- {
- TALER_LOG_ERROR("curl_easy_perform() failed at %s:%d\n", __FILE__, __LINE__);
- ret = DIGITIZER_EC_GENERIC;
- }
- curl_easy_cleanup(curl);
- }
-
-
- /*** Init HTTP Message
- struct TALER_CURL_PostContext *ctx = {
-
- // JSON encoding of the request to POST.
- char *json_enc;
-
- // Custom headers.
- struct curl_slist *headers;
-
- //Set to true to disable compression of the body.
- bool disable_compression;
- };
- json_t *body;
-
-
- if(TALER_curl_easy_post(ctx, curl, body) != GNUNET_OK)
- {
- TALER_LOG_ERROR("TALER_curl_easy_post() failed at %s:%d\n", __FILE__, __LINE__);
- return 1;
- }
- */
-
- return ret;
-}
diff --git a/thinker/taler_api/src/taler-digitizer.c b/thinker/taler_api/src/taler-digitizer.c
@@ -0,0 +1,150 @@
+#include <gnunet/gnunet_util_lib.h>
+#include "taler_digitizer_util.h"
+
+
+//#include <taler/taler_util.h>
+//#include <taler/taler_curl_lib.h>
+//#include <curl/curl.h>
+
+//#include "error_codes.h"
+
+
+
+#define TALER_EXCHANGE_URL "https://exchange.demo.taler.net"
+
+
+/**
+ * Global return value
+ */
+static int global_ret;
+
+
+struct TALER_DIGITIYER_Config
+{
+
+ union
+ {
+
+ struct
+ {
+ /**
+ * Protocol version of the exchange, libtool-style "current:revision:age".
+ */
+ const char *version;
+
+ /**
+ * Currency supported by this exchange (e.g. "USD" or "EUR").
+ */
+ const char *currency;
+
+
+ /**
+ * NULL-terminated array of supported KYC requirement names.
+ * @deprecated since protocol v24.
+ */
+ const char **supported_kyc_requirements;
+
+ } ok;
+ } details;
+
+};
+
+
+/**
+ * @brief Start the application
+ *
+ * @param cls closure
+ * @param args arguments left
+ * @param cfgfile config file name
+ * @param cfg handle for the configuration
+ */
+static void
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ (void) cls;
+ (void) args;
+ (void) cfgfile;
+
+ printf("GNUNET Client Test\n");
+
+ return;
+}
+
+
+
+int main(int argc, char*const*argv)
+{
+ int ret;
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+ ret = GNUNET_PROGRAM_run (TALER_DIGITIZER_project_data (),
+ argc,
+ argv,
+ "taler-digitizer",
+ "This is an application for the Cash Digitizer. It accepts cash and transfers it to the Taler Wallet.\n",
+ options,
+ &run,
+ NULL);
+
+ if (GNUNET_NO == ret)
+ return 0;
+ if (GNUNET_OK != ret)
+ return 1;
+ return global_ret;
+}
+
+
+// void *TALER_DIGITIZER_CheckExchangeConfigCompadibility(void *DigitizerConfig, const struct TALER_EXCHANGE_GetConfigResponse result)
+// {
+
+// }
+
+
+// /*** Init Curl ***/
+// CURL *curl;
+// enum DIGITIZER_ErrorCode ret = 0;
+
+// struct TALER_EXCHANGE_GetConfigResponse *exchange_config;
+
+
+
+
+// if(curl_global_init(CURL_GLOBAL_ALL)!= CURLE_OK)
+// {
+// TALER_LOG_ERROR("curl_global_init() failed at %s:%d\n", __FILE__, __LINE__);
+// return DIGITIZER_EC_GENERIC;
+// }
+
+
+// curl = curl_easy_init();
+// if(NULL == curl)
+// {
+// TALER_LOG_ERROR("curl_easy_init() failed at %s:%d\n", __FILE__, __LINE__);
+// ret = DIGITIZER_EC_GENERIC;
+// }
+// else
+// {
+
+// curl_easy_cleanup(curl);
+// }
+
+// /*
+// // GET /cocnfig
+// if(curl_easy_setopt(curl, CURLOPT_URL, TALER_EXCHANGE_URL) != CURLE_OK)
+// {
+// TALER_LOG_ERROR("curl_easy_setopt() failed at %s:%d\n", __FILE__, __LINE__);
+// ret = DIGITIZER_EC_GENERIC;
+// }
+// else if(curl_easy_perform(curl) != CURLE_OK)
+// {
+// TALER_LOG_ERROR("curl_easy_perform() failed at %s:%d\n", __FILE__, __LINE__);
+// ret = DIGITIZER_EC_GENERIC;
+// }
+// */
+
+// return ret;
+
+\ No newline at end of file
diff --git a/thinker/taler_api/src/taler_digitizer_util.h b/thinker/taler_api/src/taler_digitizer_util.h
@@ -0,0 +1,41 @@
+/**
+ * @file taler-digitizer_util.h
+ * @brief Interface for common utility functions
+ * @author Reto Tellenbach
+ */
+#ifndef TALER_DIGITIZER_UTIL_H
+#define TALER_DIGITIZER_UTIL_H
+
+#include <gnunet/gnunet_util_lib.h>
+
+/**
+ * Default project data. When shipping use a seperate os_installation.c which sets values at installation.
+ */
+static const struct GNUNET_OS_ProjectData digitizer_pd = {
+ .libname = "libtalerdigitizerutil",
+ .project_dirname = "taler-digitizer",
+ .binary_name = "taler-digitizer",
+ .env_varname = "TALER_DIGITIZER_PREFIX",
+ .base_config_varname = "TALER_BASE_CONFIG",
+ .bug_email = "taler@lists.gnu.org",
+ .homepage = "http://www.gnu.org/s/taler/",
+ .config_file = "taler-digitizer.conf",
+ .user_config_file = "~/.config/taler-digitizer.conf",
+ .version = "0.1.0",
+ .is_gnu = 1,
+ .gettext_domain = "taler-digitizer",
+ .gettext_path = NULL,
+};
+
+/**
+ * Return default project data.
+ */
+const struct GNUNET_OS_ProjectData *
+TALER_DIGITIZER_project_data (void)
+{
+ return &digitizer_pd;
+}
+
+
+
+#endif
diff --git a/thinker/taler_api/taler-digitizer.conf b/thinker/taler_api/taler-digitizer.conf
@@ -0,0 +1,34 @@
+[taler-digitizer]
+BACKEND_BASE_URL = https://exchange.demo.taler.net
+CURRENCY = KUDOS
+
+#BANK_ACCOUNT = sdflksdflsdkjf
+
+# Balance required to start a Transaction
+BANK_MIN_BALANCE = 1000
+
+# Withdrawl limitation per person, for a limited time period.
+# This can only be enforced with KYC functionality
+WITHDRAWLLIMIT = 200
+PERIOS = 10
+
+
+#BACKEND_AUTHORIZATION = Bearer secret-token:sandbox
+KYC_FUNCTIONALITY = NO
+
+# Name of the framebuffer to use for the QR code.
+FRAMEBUFFER_DEVICE = /dev/fb1
+
+# Name of the backlight file for the framebuffer
+FRAMEBUFFER_BACKLIGHT = /sys/class/backlight/soc:backlight/brightness
+
+[coin-acceptor]
+ENABLE = YES
+GPIO_CHIP = /dev/gpiochip0
+GPIO_PIN = 16
+bigest_denomination = 5
+
+
+[bill-acceptor]
+ENABLE = NO
+bigest_denomination = 100