[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-mdb] branch master updated: -ca draft
From: |
gnunet |
Subject: |
[taler-taler-mdb] branch master updated: -ca draft |
Date: |
Fri, 22 Jul 2022 12:54:28 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository taler-mdb.
The following commit(s) were added to refs/heads/master by this push:
new 3c5d8d4 -ca draft
3c5d8d4 is described below
commit 3c5d8d40c75700cd96c14cb2f93b12d4bb2e7aa3
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Fri Jul 22 12:54:25 2022 +0200
-ca draft
---
README | 22 +++--
configure.ac | 8 +-
src/Makefile.am | 11 ++-
src/taler-coin-acceptor.c | 222 ++++++++++++++++++++++++++++++++++++++++++++
src/{main.c => taler-mdb.c} | 0
5 files changed, 251 insertions(+), 12 deletions(-)
diff --git a/README b/README
index 3280379..1aff695 100644
--- a/README
+++ b/README
@@ -1,14 +1,14 @@
-# GNU Taler snack machine
+# GNU Taler hardware integrations
-#### Author(s)
- * BOSS Marco
- * HOFER Dominik
- * GROTHOFF Christian
+* snack machine (taler-mdb)
+* coin acceptor (taler-coin-acceptor)
+* cash acceptor (TBD)
#### Prerequisites
* GNU gcc tool-chain
* C standard libraries
* libnfc
+ * libusb
* libcurl/libgnurl
* libjansson
* GNU make
@@ -27,10 +27,13 @@
* Adafruit PiTFT 3.5" display
#### Description
-This is a app to run a snack machine as Taler merchant with NFC payment
interface.
-Optionally there can a QRCode be shown on a display to get the payment link.
+
+taler-mdb is a app to run a snack machine as Taler merchant with NFC
+payment interface. Optionally there can a QRCode be shown on a
+display to get the payment link.
#### Remarks
+
* When using an ACR122 device there may be problems with libnfc.
[see here](https://github.com/nfc-tools/libnfc) for further information
* At the moment there is no option to cross compile
@@ -45,5 +48,6 @@ Building should be easily done with the following three
commands:
```
#### Configuration
-To configure the merchants backend and the product numbers of the snack
machine edit
-taler.conf file.
+
+To configure the merchants backend and the product numbers of the
+snack machine edit taler.conf file.
diff --git a/configure.ac b/configure.ac
index 7c9c084..1b9d517 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,7 +3,7 @@
AC_PREREQ([2.69])
AC_INIT([taler-mdb], [0.8.2], [taler@gnu.org])
-AC_CONFIG_SRCDIR([src/main.c])
+AC_CONFIG_SRCDIR([src/taler-mdb.c])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
@@ -13,9 +13,15 @@ AC_PROG_CC
# Checks for libraries.
AC_CHECK_LIB([nfc], [nfc_open])
+# Checks for libraries.
+AC_CHECK_LIB([usb], [libusb_init])
+
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h string.h unistd.h sys/un.h netinet/in.h
netinet/ip.h])
+# Checks for header files.
+AC_CHECK_HEADERS([libusb-1.0/libusb.h])
+
# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL
AC_TYPE_SIZE_T
diff --git a/src/Makefile.am b/src/Makefile.am
index f018f6d..86ddd3b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,7 @@
# This Makefile.am is in the public domain
-bin_PROGRAMS = taler-mdb
+bin_PROGRAMS = \
+ taler-coin-acceptor \
+ taler-mdb
if HAVE_QR
bin_PROGRAMS += qr-show
@@ -10,8 +12,13 @@ if USE_COVERAGE
XLIB = -lgcov
endif
+taler_coin_acceptor_SOURCES = \
+ taler-coin-acceptor.c
+taler_coin_acceptor_LDADD = \
+ -lusb-1.0
+
taler_mdb_SOURCES = \
- main.c
+ taler-mdb.c
taler_mdb_LDADD = \
-ltalermerchant \
-ltalerjson \
diff --git a/src/taler-coin-acceptor.c b/src/taler-coin-acceptor.c
new file mode 100644
index 0000000..fde4a8a
--- /dev/null
+++ b/src/taler-coin-acceptor.c
@@ -0,0 +1,222 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER 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 3, or (at your option) any later version.
+
+ TALER 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
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @brief Program to talk to the coin acceptor via USB-RS232.
+ *
+ * @author Christian Grothoff
+ */
+#include "config.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <arpa/inet.h>
+#include <libusb-1.0/libusb.h>
+
+// FIXME: make this configurable later...
+/* future technology devices international */
+#define VENDOR_ID 0x0403
+/* FT232 Serial UART IC */
+#define PRODUCT_ID 0x6001
+
+#define USB_CTL_REQ_SET_LINE_CODING 0x20
+
+#define LEO_ONE_STOP_BIT 0x00
+#define LEO_ONEHALF_STOP_BIT 0x01
+#define LEO_TWO_STOP_BIT 0x02
+
+#define LEO_PARITY_NONE 0x00
+#define LEO_PARITY_ODD 0x01
+#define LEO_PARITY_EVEN 0x02
+#define LEO_PARITY_MARK 0x03
+#define LEO_PARITY_SPACE 0x04
+
+
+#define ACM_CTRL_DTR 0x01
+#define ACM_CTRL_RTS 0x02
+
+/**
+ * Handle to USB device.
+ */
+static struct libusb_device_handle *device_handle;
+
+/* The Endpoint address are hard coded. You should use lsusb -v to find
+ * the values corresponding to your device.
+ */
+static int ep_in_addr = 0x83;
+static int ep_out_addr = 0x02;
+
+
+static int
+read_char (void)
+{
+ int actual_length;
+ unsigned char data;
+ int rc;
+
+ rc = libusb_bulk_transfer (device_handle,
+ ep_in_addr,
+ &data,
+ sizeof (data),
+ &actual_length,
+ 1000 /* timeout? */);
+ if (rc == LIBUSB_ERROR_TIMEOUT)
+ {
+ fprintf (stderr,
+ "TIMEOUT\n");
+ return EOF;
+ }
+ if (rc < 0)
+ {
+ fprintf (stderr,
+ "Error %s while waiting for char\n",
+ libusb_error_name (rc));
+ return EOF;
+ }
+ return data;
+}
+
+
+int
+main (int argc,
+ char **argv)
+{
+ int rc;
+
+ rc = libusb_init (NULL);
+ if (rc < 0)
+ {
+ fprintf (stderr,
+ "Error initializing usb: %s\n",
+ libusb_error_name (rc));
+ return 1;
+ }
+
+ libusb_set_debug (NULL,
+ 3);
+ device_handle = libusb_open_device_with_vid_pid (NULL,
+ VENDOR_ID,
+ PRODUCT_ID);
+ if (NULL == device_handle)
+ {
+ fprintf (stderr,
+ "Error finding USB device\n");
+ libusb_exit (NULL);
+ return 1;
+ }
+
+ /* Maybe there is someone else attached, detach other drivers from
+ all the USB interfaces. NOTE: not sure if there are *2*! */
+ for (int if_num = 0; if_num < 2; if_num++)
+ {
+ if (libusb_kernel_driver_active (device_handle,
+ if_num))
+ {
+ libusb_detach_kernel_driver (device_handle,
+ if_num);
+ }
+ rc = libusb_claim_interface (device_handle,
+ if_num);
+ if (rc < 0)
+ {
+ fprintf (stderr,
+ "Error claiming interface: %s\n",
+ libusb_error_name (rc));
+ libusb_close (device_handle);
+ libusb_exit (NULL);
+ return 1;
+ }
+ }
+#if 1
+ rc = libusb_control_transfer (device_handle,
+ 0x21,
+ 0x22,
+ ACM_CTRL_DTR | ACM_CTRL_RTS,
+ 0,
+ NULL,
+ 0,
+ 0);
+ if (rc < 0)
+ {
+ fprintf (stderr,
+ "Error during control transfer: %s\n",
+ libusb_error_name (rc));
+ libusb_close (device_handle);
+ libusb_exit (NULL);
+ return 1;
+ }
+#endif
+
+ /* - set line encoding: here 9600 8N1
+ * 9600 = 0x2580 ~> 0x80, 0x25 in little endian
+ */
+ {
+ struct LineEncodingOptions
+ {
+ /**
+ * In *little* endian.
+ */
+ uint32_t baud_rate;
+ uint8_t b_char_format;
+ uint8_t b_parity_type;
+ uint8_t b_data_bits;
+ } leo = {
+ .baud_rate = __builtin_bswap32 (htonl (4800)),
+ .b_char_format = LEO_ONE_STOP_BIT,
+ .b_parity_type = LEO_PARITY_ODD,
+ .b_data_bits = 0x08
+ };
+
+ rc = libusb_control_transfer (device_handle,
+ 0x21,
+ USB_CTL_REQ_SET_LINE_CODING,
+ 0,
+ 0,
+ (unsigned char *) &leo,
+ sizeof(leo),
+ 0);
+ if (rc < 0)
+ {
+ fprintf (stderr,
+ "Error during control transfer: %s\n",
+ libusb_error_name (rc));
+ libusb_close (device_handle);
+ libusb_exit (NULL);
+ return 1;
+ }
+ }
+
+ /* FIXME: proper event loop... */
+ while (1)
+ {
+ int in = read_char ();
+
+ if (-1 != in)
+ fprintf (stdout,
+ "Received: %d\n",
+ in);
+ }
+
+ libusb_release_interface (device_handle,
+ 0);
+ libusb_close (device_handle);
+ libusb_exit (NULL);
+ return 0;
+}
diff --git a/src/main.c b/src/taler-mdb.c
similarity index 100%
rename from src/main.c
rename to src/taler-mdb.c
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-taler-mdb] branch master updated: -ca draft,
gnunet <=