simplified main for different tests

master
Ondřej Hruška 6 years ago
parent 737700a157
commit f3113492a9
  1. 29
      main.c

@ -2,8 +2,9 @@
#include <stdlib.h>
#include <signal.h>
#include <assert.h>
#include <utils/hexdump.h>
#include <unistd.h>
#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);

Loading…
Cancel
Save