From f3113492a928825e3f10a1b3ff2bd48c1840b52d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sat, 23 Dec 2017 09:22:41 +0100 Subject: [PATCH] simplified main for different tests --- main.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index b65e400..84ca146 100644 --- a/main.c +++ b/main.c @@ -2,8 +2,9 @@ #include #include #include -#include +#include +#include "utils/hexdump.h" #include "gex.h" static GexClient *gex; @@ -34,7 +35,7 @@ int main(void) // Bind ^C handler for safe shutdown signal(SIGINT, sigintHandler); - gex = GEX_Init("/dev/ttyACM0", 200); + gex = GEX_Init("/dev/ttyACM0", 300); if (!gex) exit(1); TF_AddGenericListener(GEX_GetTF(gex), hdl_default); @@ -48,15 +49,30 @@ int main(void) // the "PING" command GexMsg msg; - msg = GEX_Query0(test, 0); - assert(msg.type == MSG_SUCCESS); - fprintf(stderr, "\"PING\" cmd: OK.\n"); +#if 1 + // Simple response - const char *s = "BLOCKCHAIN BUT FOR COWS"; + // It looks like the ID listeners are not being freed! + // May be a bug both here and on the GEX side. + for(int i=0; i<40; i++) { + msg = GEX_Query0(test, 0); + assert(msg.type == MSG_SUCCESS); + fprintf(stderr, "\"PING\" cmd: OK.\n"); + usleep(50000); + } +#endif + +#if 1 + // Test a echo command that returns back what was sent to it as useful payload + const char *s = "I am returning this otherwise good typing paper to you because someone " + ;//"has printed gibberish all over it and put your name at the top."; msg = GEX_Query(test, 1, (const uint8_t *) s, (uint32_t) strlen(s)); fprintf(stderr, "\"ECHO\" cmd resp: %d, len %d, pld: %.*s\n", msg.type, (int) msg.len, (int) msg.len, (char *) msg.payload); assert(0==strncmp((char*)msg.payload, s, strlen(s))); +#endif +#if 0 + // Read the communist manifesto via bulk transfer uint8_t buffr[10000]; GexBulk br = { .buffer = buffr, @@ -68,6 +84,7 @@ int main(void) uint32_t actuallyRead = GEX_BulkRead(test, &br); fprintf(stderr, "Read %d bytes:\n", actuallyRead); fprintf(stderr, "%.*s", actuallyRead, buffr); +#endif fprintf(stderr, "ALL OK, ending.\n"); GEX_DeInit(gex);