commit 7068fc81328e6647091d37b19e2648debb4f2196
parent 23a6e476b74aabe39e58109a18cce6ae25602bbb
Author: Manuel Geissbühler <manuel@debian>
Date: Fri, 20 Dec 2024 16:58:22 +0100
added some lines for testing cashacceptor in main
Diffstat:
15 files changed, 298 insertions(+), 28 deletions(-)
diff --git a/build/CMakeCache.txt b/build/CMakeCache.txt
@@ -221,6 +221,9 @@ cash2ecash_IS_TOP_LEVEL:STATIC=ON
//Value Computed by CMake
cash2ecash_SOURCE_DIR:STATIC=/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src
+//Dependencies for the target
+cashacceptor_LIB_DEPENDS:STATIC=general;gnunetutil;general;talerutil;
+
########################
# INTERNAL cache entries
@@ -326,7 +329,7 @@ CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_NM
CMAKE_NM-ADVANCED:INTERNAL=1
//number of local generators
-CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=6
+CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=7
//ADVANCED property for variable: CMAKE_OBJCOPY
CMAKE_OBJCOPY-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_OBJDUMP
diff --git a/build/Makefile b/build/Makefile
@@ -142,6 +142,19 @@ cashacceptor/fast:
$(MAKE) $(MAKESILENT) -f cashacceptor/CMakeFiles/cashacceptor.dir/build.make cashacceptor/CMakeFiles/cashacceptor.dir/build
.PHONY : cashacceptor/fast
+#=============================================================================
+# Target rules for targets named utils
+
+# Build rule for target.
+utils: cmake_check_build_system
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 utils
+.PHONY : utils
+
+# fast build rule for target.
+utils/fast:
+ $(MAKE) $(MAKESILENT) -f utils/CMakeFiles/utils.dir/build.make utils/CMakeFiles/utils.dir/build
+.PHONY : utils/fast
+
cash2ecash.o: cash2ecash.cpp.o
.PHONY : cash2ecash.o
@@ -176,6 +189,7 @@ help:
@echo "... rebuild_cache"
@echo "... cash2ecash"
@echo "... cashacceptor"
+ @echo "... utils"
@echo "... cash2ecash.o"
@echo "... cash2ecash.i"
@echo "... cash2ecash.s"
diff --git a/build/cash2ecash b/build/cash2ecash
Binary files differ.
diff --git a/build/compile_commands.json b/build/compile_commands.json
@@ -13,5 +13,10 @@
"directory": "/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build/cashacceptor",
"command": "/usr/bin/c++ -I/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src/include -g -o CMakeFiles/cashacceptor.dir/dg600f.cpp.o -c /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src/cashacceptor/dg600f.cpp",
"file": "/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src/cashacceptor/dg600f.cpp"
+},
+{
+ "directory": "/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build/utils",
+ "command": "/usr/bin/c++ -I/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src/include -g -o CMakeFiles/utils.dir/timer.cpp.o -c /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src/utils/timer.cpp",
+ "file": "/home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src/utils/timer.cpp"
}
]
\ No newline at end of file
diff --git a/build/utils/Makefile b/build/utils/Makefile
@@ -0,0 +1,182 @@
+# CMAKE generated file: DO NOT EDIT!
+# Generated by "Unix Makefiles" Generator, CMake Version 3.25
+
+# Default target executed when no arguments are given to make.
+default_target: all
+.PHONY : default_target
+
+# Allow only one "make -f Makefile2" at a time, but pass parallelism.
+.NOTPARALLEL:
+
+#=============================================================================
+# Special targets provided by cmake.
+
+# Disable implicit rules so canonical targets will work.
+.SUFFIXES:
+
+# Disable VCS-based implicit rules.
+% : %,v
+
+# Disable VCS-based implicit rules.
+% : RCS/%
+
+# Disable VCS-based implicit rules.
+% : RCS/%,v
+
+# Disable VCS-based implicit rules.
+% : SCCS/s.%
+
+# Disable VCS-based implicit rules.
+% : s.%
+
+.SUFFIXES: .hpux_make_needs_suffix_list
+
+# Command-line flag to silence nested $(MAKE).
+$(VERBOSE)MAKESILENT = -s
+
+#Suppress display of executed commands.
+$(VERBOSE).SILENT:
+
+# A target that is always out of date.
+cmake_force:
+.PHONY : cmake_force
+
+#=============================================================================
+# Set environment variables for the build.
+
+# The shell in which to execute make rules.
+SHELL = /bin/sh
+
+# The CMake executable.
+CMAKE_COMMAND = /usr/bin/cmake
+
+# The command to remove a file.
+RM = /usr/bin/cmake -E rm -f
+
+# Escaping for special characters.
+EQUALS = =
+
+# The top-level source directory on which CMake was run.
+CMAKE_SOURCE_DIR = /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/src
+
+# The top-level build directory on which CMake was run.
+CMAKE_BINARY_DIR = /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build
+
+#=============================================================================
+# Targets provided globally by CMake.
+
+# Special rule for the target edit_cache
+edit_cache:
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..."
+ /usr/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available.
+.PHONY : edit_cache
+
+# Special rule for the target edit_cache
+edit_cache/fast: edit_cache
+.PHONY : edit_cache/fast
+
+# Special rule for the target rebuild_cache
+rebuild_cache:
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
+ /usr/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
+.PHONY : rebuild_cache
+
+# Special rule for the target rebuild_cache
+rebuild_cache/fast: rebuild_cache
+.PHONY : rebuild_cache/fast
+
+# The main all target
+all: cmake_check_build_system
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(CMAKE_COMMAND) -E cmake_progress_start /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build/CMakeFiles /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build/utils//CMakeFiles/progress.marks
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 utils/all
+ $(CMAKE_COMMAND) -E cmake_progress_start /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build/CMakeFiles 0
+.PHONY : all
+
+# The main clean target
+clean:
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 utils/clean
+.PHONY : clean
+
+# The main clean target
+clean/fast: clean
+.PHONY : clean/fast
+
+# Prepare targets for installation.
+preinstall: all
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 utils/preinstall
+.PHONY : preinstall
+
+# Prepare targets for installation.
+preinstall/fast:
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 utils/preinstall
+.PHONY : preinstall/fast
+
+# clear depends
+depend:
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
+.PHONY : depend
+
+# Convenience name for target.
+utils/CMakeFiles/utils.dir/rule:
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 utils/CMakeFiles/utils.dir/rule
+.PHONY : utils/CMakeFiles/utils.dir/rule
+
+# Convenience name for target.
+utils: utils/CMakeFiles/utils.dir/rule
+.PHONY : utils
+
+# fast build rule for target.
+utils/fast:
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(MAKE) $(MAKESILENT) -f utils/CMakeFiles/utils.dir/build.make utils/CMakeFiles/utils.dir/build
+.PHONY : utils/fast
+
+timer.o: timer.cpp.o
+.PHONY : timer.o
+
+# target to build an object file
+timer.cpp.o:
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(MAKE) $(MAKESILENT) -f utils/CMakeFiles/utils.dir/build.make utils/CMakeFiles/utils.dir/timer.cpp.o
+.PHONY : timer.cpp.o
+
+timer.i: timer.cpp.i
+.PHONY : timer.i
+
+# target to preprocess a source file
+timer.cpp.i:
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(MAKE) $(MAKESILENT) -f utils/CMakeFiles/utils.dir/build.make utils/CMakeFiles/utils.dir/timer.cpp.i
+.PHONY : timer.cpp.i
+
+timer.s: timer.cpp.s
+.PHONY : timer.s
+
+# target to generate assembly for a file
+timer.cpp.s:
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(MAKE) $(MAKESILENT) -f utils/CMakeFiles/utils.dir/build.make utils/CMakeFiles/utils.dir/timer.cpp.s
+.PHONY : timer.cpp.s
+
+# Help Target
+help:
+ @echo "The following are some of the valid targets for this Makefile:"
+ @echo "... all (the default if no target is provided)"
+ @echo "... clean"
+ @echo "... depend"
+ @echo "... edit_cache"
+ @echo "... rebuild_cache"
+ @echo "... utils"
+ @echo "... timer.o"
+ @echo "... timer.i"
+ @echo "... timer.s"
+.PHONY : help
+
+
+
+#=============================================================================
+# Special targets to cleanup operation of make.
+
+# Special rule to run CMake to check the build system integrity.
+# No rule that depends on this can have commands that come from listfiles
+# because they might be regenerated.
+cmake_check_build_system:
+ cd /home/manuel/Dokumente/Studium/BTE5512_Projektarbeit/cash2ecash/build && $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
+.PHONY : cmake_check_build_system
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
@@ -1,10 +1,13 @@
cmake_minimum_required(VERSION 3.2)
project(cash2ecash)
add_compile_options(-g)
+
+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_executable(cash2ecash cash2ecash.cpp)
+
include_directories(include)
add_subdirectory(cashacceptor)
@@ -12,6 +15,8 @@ add_subdirectory(bank)
add_subdirectory(extern)
add_subdirectory(gui)
add_subdirectory(identification)
+add_subdirectory(utils)
target_link_libraries(cash2ecash PRIVATE cashacceptor)
+target_link_libraries(cash2ecash PRIVATE utils)
diff --git a/src/cash2ecash.cpp b/src/cash2ecash.cpp
@@ -3,36 +3,61 @@
#include <iostream>
#include <ostream>
+
+
#include "cashacceptors.hpp"
+#include "utils.hpp"
// Global Definitions
-enum state_e { INIT, SLEEP, IDLE, CONNECTION, ACCEPTCASH, CONFIRMATION, DONE };
+enum state_e { INIT, SLEEP, IDLE, CONNECTION, ACCEPTCASH, DONE };
enum state_e state = INIT;
-
+char test;
+char *string;
int main(int argc, char *argv[]){
+ char serialpath[] = "/dev/ttyAMA3";
std::cout << "The Program is running" <<std::endl;
+ DG600F cashacceptor(serialpath);
+ Timer timer1;
+ timer1.setTimeMillis(10000);
+ TALER_Amount testamount;
- switch (state) {
- case INIT:
- break;
- case SLEEP:
- break;
- case IDLE:
- break;
- case CONNECTION:
- break;
- case ACCEPTCASH:
- break;
- case CONFIRMATION:
- break;
- case DONE:
- break;
- default:
- std::cout << "ERROR: unhandeled state" << std::endl;
- break;
+ while (true) {
+ switch (state) {
+ case INIT:
+ state = ACCEPTCASH;
+ timer1.start();
+ break;
+ case SLEEP:
+ break;
+ case IDLE:
+ break;
+ case CONNECTION:
+ break;
+ case ACCEPTCASH:
+ cashacceptor.startMoneyAcceptance();
+ if (timer1.over()) {
+ cashacceptor.stopMoneyAcceptance();
+ cashacceptor.readAccumulated(&testamount);
+ string = TALER_amount_to_string(&testamount);
+ printf("%s\n",string);
+ free(string);
+ cashacceptor.readFIFO(&testamount);
+ string = TALER_amount_to_string(&testamount);
+ printf("%s", string);
+
+ }
+
+ break;
+ case DONE:
+ break;
+ default:
+ std::cout << "ERROR: unhandeled state" << std::endl;
+ break;
+ }
}
+
}
diff --git a/src/cashacceptor/CMakeLists.txt b/src/cashacceptor/CMakeLists.txt
@@ -1,3 +1,9 @@
+set(CMAKE_CXX_EXTENSIONS ON)
+
+
add_library(cashacceptor cashacceptor.cpp
dg600f.cpp)
+target_link_libraries(cashacceptor PRIVATE
+ gnunetutil
+ talerutil)
diff --git a/src/cashacceptor/cashacceptor.hpp b/src/cashacceptor/cashacceptor.hpp
@@ -1,8 +1,14 @@
#ifndef CASHACCEPTOR_H
#define CASHACCEPTOR_H
+// Exclude some headers to avoid errors compiling in cpp
+//#define GNUNET_STRINGS_LIB_H
+//#define TALER_CRYPTO_LIB_H
+
+//Allow to directly include amount lib, might lead to other bugs..
+#define __TALER_UTIL_LIB_H_INSIDE__
extern "C" {
-#include <taler/taler_util.h>
+#include <taler/taler_amount_lib.h>
}
#include <vector>
diff --git a/src/cashacceptor/dg600f.cpp b/src/cashacceptor/dg600f.cpp
@@ -94,7 +94,7 @@ int DG600F::startMoneyAcceptance(){
//TODO stop Inhibiting
//Start thread which waits for chars...
flagSerialListenRun = true;
- std::thread tr(&DG600F::serialListenThread, fd);
+ std::thread tr(&DG600F::serialListenThread, this, fd);
return 0;
}
diff --git a/src/cashacceptor/dg600f.hpp b/src/cashacceptor/dg600f.hpp
@@ -21,9 +21,7 @@
-extern "C" {
-#include <taler/taler_util.h>
-}
+
#include "cashacceptor.hpp"
@@ -38,6 +36,8 @@ private:
int configSerial(int fd, int baudrate);
+ void serialListenThread(int fd);
+ TALER_Amount convertAmount(char amount);
protected:
@@ -57,8 +57,7 @@ public:
int stopMoneyAcceptance();
int readAccumulated(TALER_Amount *retval);
int readFIFO(TALER_Amount *retval);
- void serialListenThread(int fd);
- TALER_Amount convertAmount(char amount);
+
diff --git a/src/include/utils.hpp b/src/include/utils.hpp
@@ -0,0 +1 @@
+#include "../utils/timer.hpp"
diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt
@@ -0,0 +1 @@
+add_library(utils timer.cpp)
diff --git a/src/utils/timer.cpp b/src/utils/timer.cpp
@@ -0,0 +1 @@
+#include "timer.hpp"
diff --git a/src/utils/timer.hpp b/src/utils/timer.hpp
@@ -0,0 +1,22 @@
+#include <chrono>
+#include <ratio>
+
+
+class Timer{
+ private:
+ std::chrono::duration<int, std::ratio<1,1000>> duration_ms;
+ std::chrono::time_point<std::chrono::steady_clock> timepoint;
+ protected:
+ public:
+ void setTimeMillis(int time){
+ duration_ms = std::chrono::milliseconds(time);
+ }
+
+ void start(){
+ timepoint = std::chrono::steady_clock::now();
+ }
+
+ bool over(){
+ return duration_ms >= (std::chrono::steady_clock::now() - timepoint);
+ }
+};