cash2ecash

cash2ecash: cash acceptor that issues digital cash (experimental)
Log | Files | Refs | Submodules | README | LICENSE

dg600f.hpp (1443B)


      1 #ifndef DG600F_H
      2 #define DG600F_H
      3 
      4 #include <cstdlib>
      5 #include <cstring>
      6 #include <errno.h>
      7 #include <fcntl.h>
      8 #include <iostream>
      9 #include <termios.h>
     10 #include <unistd.h>
     11 #include <thread>
     12 #include <mutex>
     13 #include <gpiod.hpp>
     14 #include <filesystem>
     15 
     16 
     17 #define DG600FCHF0_1 1
     18 #define DG600FCHF0_2 2
     19 #define DG600FCHF0_5 5
     20 #define DG600FCHF1 10
     21 #define DG600FCHF2 20
     22 #define DG600FCHF5 50
     23 
     24 #define GPIO_CHIP "gpiochip0"
     25 #define GPIO_LINE "GPIO16"
     26 
     27 
     28 
     29 
     30 #include "cashacceptor.hpp"
     31 
     32 
     33 class DG600F : public Cashaccepor {
     34 private:
     35   char *portPath;
     36   char currency[12] = "KUDOS";
     37   int fd;
     38   volatile bool flagSerialListenRun = false;
     39   std::mutex fifo_mutex, accumulatedAmount_mutex;
     40 
     41   ::gpiod::chip *gpioChip;
     42   ::gpiod::line gpioInhibitLine;
     43 
     44   
     45 
     46   int configSerial(int fd, int baudrate);
     47   int configGPIO();
     48   int releaseHardware();
     49   void serialListenThread(int fd);
     50   TALER_Amount convertAmount(char amount);
     51 
     52 protected:
     53 
     54 public:
     55   DG600F(char * serialPortPath) : Cashaccepor(),
     56 				  portPath(serialPortPath)			  
     57   {
     58     fd = open(portPath, O_RDWR | O_NOCTTY | O_SYNC);
     59     if (0 > fd){
     60       std::cerr << "Error opening" << portPath << ": " << strerror(errno) << std::endl;
     61     }
     62 
     63     configSerial(fd, B4800);
     64     configGPIO();
     65   };
     66   int clearAccumulatedAmount();
     67   int startMoneyAcceptance();
     68   int stopMoneyAcceptance();
     69   int readAccumulated(TALER_Amount *retval);
     70   int readFIFO(TALER_Amount *retval);
     71   
     72   
     73 
     74 
     75   
     76 };
     77 
     78 #endif //DG600F_H