[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-mdb] 04/23: mdb communication working (test integration)
From: |
gnunet |
Subject: |
[taler-taler-mdb] 04/23: mdb communication working (test integration) |
Date: |
Wed, 04 Dec 2019 14:15:50 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository taler-mdb.
commit 40e04ead2d83d4c73a49c1ac80d184e2eeec70e9
Author: Dominik Hofer <address@hidden>
AuthorDate: Mon Dec 2 16:25:27 2019 +0100
mdb communication working (test integration)
---
src/main.c | 77 +++++++++++++++++++++++++++++++++++-------------------
src/mdb/mdb_uart.c | 15 ++++++-----
2 files changed, 58 insertions(+), 34 deletions(-)
diff --git a/src/main.c b/src/main.c
index 229cd8a..41e91c4 100644
--- 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
index c323fe4..1d92d47 100644
--- 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)
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [taler-taler-mdb] branch master updated (b18e966 -> 9065ce5), gnunet, 2019/12/04
- [taler-taler-mdb] 03/23: Some corrections, gnunet, 2019/12/04
- [taler-taler-mdb] 13/23: fix shutdown, gnunet, 2019/12/04
- [taler-taler-mdb] 05/23: some little bugfixes, gnunet, 2019/12/04
- [taler-taler-mdb] 09/23: neg cond, gnunet, 2019/12/04
- [taler-taler-mdb] 08/23: neg cond, gnunet, 2019/12/04
- [taler-taler-mdb] 04/23: mdb communication working (test integration),
gnunet <=
- [taler-taler-mdb] 10/23: parse filenames from config, gnunet, 2019/12/04
- [taler-taler-mdb] 01/23: Added mdb communication module, gnunet, 2019/12/04
- [taler-taler-mdb] 02/23: integration mdb first try, gnunet, 2019/12/04
- [taler-taler-mdb] 06/23: major mdb refactoring, gnunet, 2019/12/04
- [taler-taler-mdb] 23/23: add TODO, gnunet, 2019/12/04
- [taler-taler-mdb] 15/23: config, gnunet, 2019/12/04
- [taler-taler-mdb] 21/23: fix NPE, gnunet, 2019/12/04
- [taler-taler-mdb] 22/23: logging, gnunet, 2019/12/04
- [taler-taler-mdb] 17/23: invert checks, gnunet, 2019/12/04
- [taler-taler-mdb] 19/23: fix end session handling, gnunet, 2019/12/04