taler-mdb

GNU Taler Extensions and Integrations
Log | Files | Refs | Submodules | README | LICENSE

commit 40e04ead2d83d4c73a49c1ac80d184e2eeec70e9
parent 94d6cfb064877fee719c41727e6d8442800883cf
Author: Dominik Hofer <dominik.hofer@bfh.ch>
Date:   Mon,  2 Dec 2019 16:25:27 +0100

mdb communication working (test integration)

Diffstat:
Msrc/main.c | 77++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
Msrc/mdb/mdb_uart.c | 15++++++++-------
2 files changed, 58 insertions(+), 34 deletions(-)

diff --git a/src/main.c b/src/main.c @@ -336,12 +336,11 @@ static struct Product *products; static unsigned int products_length; static struct mdbHandle mdb; - +struct mdbCmd *readerConfigData; struct mdbCmd *beginSession; +struct mdbCmd *denyVend; struct mdbCmd *approveVend; struct mdbCmd *endSession; -struct mdbCmd *denyVend; -struct mdbCmd *readerConfigData; /** * Handle for the framebuffer device @@ -461,10 +460,10 @@ cleanup_payment (struct PaymentActivity *pa) GNUNET_SCHEDULER_cancel (pa->task); if (NULL != pa->delay_task) GNUNET_SCHEDULER_cancel (pa->delay_task); - if (NULL != mdb.cmd) + if (0 < mdb.uartfd) { mdb.cmd = NULL; - mdb.session_running = GNUNET_NO; + sendMdbCmd(endSession, mdb.uartfd); } if (NULL != pa->taler_pay_uri) { @@ -515,6 +514,9 @@ shutdown_task (void *cls) GNUNET_SCHEDULER_cancel (mdb_task); mdb_task = NULL; } + if (0 < mdb.uartfd){ + sendMdbCmd(endSession, mdb.uartfd); + } if (NULL != ctx) { GNUNET_CURL_fini (ctx); @@ -1000,6 +1002,8 @@ read_keyboard_command (void *cls) { if (NULL != payment_activity) { + sendMdbCmd(denyVend, mdb.uartfd); + sleep(2); cleanup_payment (payment_activity); payment_activity = NULL; } @@ -1059,7 +1063,7 @@ static void read_mdb_command (void *cls) { (void) cls; - char*input; + char* input; mdb_task = NULL; input = receiveMdbCmd (mdb.uartfd); @@ -1070,16 +1074,15 @@ read_mdb_command (void *cls) { if (0 == strcmp ("Config Data", input)) { - mdb.cmd = readerConfigData; + printf("%s\n", input); + mdb.cmd = readerConfigData; } else if (0 == strcmp ("Reader Enable", input)) { - mdb.session_running = GNUNET_YES; mdb.cmd = beginSession; } else if (0 == strcmp ("Command out of Sequence", input)) { - mdb.session_running = GNUNET_YES; mdb.cmd = beginSession; } else if (0 == strcmp ("Resend previous data", input)) @@ -1088,14 +1091,20 @@ read_mdb_command (void *cls) } else if (0 == strncmp ("Vend Request", input, strlen ("Vend Request"))) { - for (unsigned int i = 0; i < products_length; i++) - if (0 == strcmp (&input[strlen ("Vend Request for : ")], - products[i].number)) + mdb.cmd = NULL; + printf("%s\n", input); + printf("%s", &input[strlen("Vend request for: ")]); + for (unsigned int i = 0; i < products_length; i++){ + if (0 == strncmp (&input[strlen ("Vend Request for: ")], + products[i].number,1)) { payment_activity = launch_payment (&products[i]); start_read_mdb (); return; } + } + mdb.cmd = denyVend; + } else if (0 == strcmp ("Vend Success", input)) { @@ -1123,6 +1132,11 @@ read_mdb_command (void *cls) free (input); input = NULL; } + else + { + mdb.cmd = NULL; + } + start_read_mdb (); } @@ -1130,13 +1144,7 @@ static void start_read_mdb () { struct GNUNET_DISK_FileHandle fh = { mdb.uartfd }; - if (NULL == mdb.cmd) - { - mdb.session_running = GNUNET_YES; - mdb.cmd = beginSession; - sendMdbCmd (mdb.cmd, mdb.uartfd); - } - else if (GNUNET_NO == mdb.session_running) + if (NULL != mdb.cmd) { sendMdbCmd (mdb.cmd, mdb.uartfd); } @@ -1420,13 +1428,9 @@ run (void *cls, #endif - readerConfigData = newMdbCmd ("Reader Config", "0101", "19780A02FF0C"); - beginSession = newMdbCmd ("Begin Session", "03", "FFFF"); - denyVend = newMdbCmd ("Deny Vend", "06", NULL); - approveVend = newMdbCmd ("Approve Vend", "05", "0001"); - endSession = newMdbCmd ("End Session", "07", NULL); + + start_read_keyboard (); start_read_mdb (); - start_read_keyboard (); } int @@ -1494,8 +1498,8 @@ main (int argc, uart_opts_raw.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); uart_opts_raw.c_iflag = IGNPAR; uart_opts_raw.c_oflag &= ~OPOST; - uart_opts_raw.c_cc[VMIN] = 14; - uart_opts_raw.c_cc[VTIME] = 10; + uart_opts_raw.c_cc[VMIN] = 0; + uart_opts_raw.c_cc[VTIME] = 50; tcflush (mdb.uartfd,TCIOFLUSH); if (0 != tcsetattr (mdb.uartfd, TCSAFLUSH, @@ -1505,6 +1509,25 @@ main (int argc, return EXIT_FAILURE; } + readerConfigData = newMdbCmd ("Reader Config", "0101", "19780A02FF0C"); + beginSession = newMdbCmd ("Begin Session", "03", "FFFF"); + denyVend = newMdbCmd ("Deny Vend", "06", NULL); + approveVend = newMdbCmd ("Approve Vend", "05", "0001"); + endSession = newMdbCmd ("End Session", "07", NULL); + + char* input; + + input = receiveMdbCmd(mdb.uartfd); + + if(NULL != input && 0 == strcmp(input, "Config Data")) + { + mdb.cmd = readerConfigData; + } + else + { + mdb.cmd = beginSession; + } + ret = GNUNET_PROGRAM_run (argc, argv, "taler-mdb", diff --git a/src/mdb/mdb_uart.c b/src/mdb/mdb_uart.c @@ -121,8 +121,8 @@ receiveMdbCmd (int filestream) int nrOfReceivedBytes = 0; nrOfReceivedBytes = read (filestream, rxBuffer, MAX_SIZE_RX_BUFFER); - - if (nrOfReceivedBytes < 4) + + if (nrOfReceivedBytes < 4) { return NULL; } @@ -135,7 +135,7 @@ receiveMdbCmd (int filestream) return NULL; } } - // printf("Received Bytes: %d\n", nrOfReceivedBytes); + printf("Received Bytes: %d\n", nrOfReceivedBytes); char *retVal = malloc (30 * sizeof(char) + sizeof(uint16_t)); if (! retVal) @@ -147,7 +147,7 @@ receiveMdbCmd (int filestream) rxBuffer[ cmdStartIdx + 2]))); - printf ("Received Command: %X\n", cmd); + //printf ("Received Command: %X\n", cmd); switch (cmd) { @@ -197,7 +197,7 @@ receiveMdbCmd (int filestream) rxBuffer[ cmdStartIdx + 4]))) == - 0x01) + 0x01) { sprintf (retVal, "Reader Enable"); } @@ -337,10 +337,11 @@ sendMdbCmd (struct mdbCmd*cmdToSend, int filestream) printf ("Send command: %s\n", cmdToSend->name); + nrOfSentBytes = uartSendBytes (filestream, txBuffer, cmdToSend->cmdLength + + cmdToSend->dataLength + 1); + while (! receivedMdbCmd) { - nrOfSentBytes = uartSendBytes (filestream, txBuffer, cmdToSend->cmdLength - + cmdToSend->dataLength + 1); receivedMdbCmd = receiveMdbCmd (filestream); if (receivedMdbCmd)