fixed some bugs

master
Ondřej Hruška 6 years ago
parent 95cc7e3af5
commit cd479d2dfe
  1. 4
      gex/TF_Integration.c
  2. 20
      gex/gex_client.c
  3. 5
      gex/protocol/TF_Config.h
  4. 12
      main.c

@ -15,11 +15,13 @@ void TF_WriteImpl(TinyFrame *tf, const uint8_t *buff, size_t len)
GexClient *gc = tf->userdata;
assert(gc->acm_fd != 0);
// hexDump("TF_Write", buff, (uint32_t)len);
hexDump("TF_Write", buff, (uint32_t)len);
ssize_t rv = write(gc->acm_fd, buff, len);
if (rv != (ssize_t)len) {
fprintf(stderr, "ERROR %d in TF write: %s\n", errno, strerror(errno));
} else {
fprintf(stderr, "Written %d bytes.\n", (int)rv);
}
}

@ -181,6 +181,9 @@ void GEX_Poll(GexClient *gex)
bool first = true;
#define MAX_RETRIES 10
int cycle = 0;
do {
if (first) serial_shouldwait(gex->acm_fd, gex->ser_timeout);
ssize_t len = read(gex->acm_fd, pollbuffer, TF_MAX_PAYLOAD_RX);
@ -195,12 +198,21 @@ void GEX_Poll(GexClient *gex)
}
else {
if (len == 0) {
// fprintf(stderr,"No more data to read.\n");
break;
fprintf(stderr,"No more data to read.\n");
if (gex->tf->state != 0) {
if (cycle < MAX_RETRIES) {
cycle++;
first=true;
} else {
break;
}
} else {
break;
}
}
else {
// fprintf(stderr, "rx %d bytes\n", (int) len);
// hexDump("TF_Receive", pollbuffer, (uint32_t) len);
fprintf(stderr, "rx %d bytes\n", (int) len);
hexDump("TF_Receive", pollbuffer, (uint32_t) len);
TF_Accept(gex->tf, pollbuffer, (size_t) len);
}

@ -5,6 +5,9 @@
#ifndef TF_CONFIG_H
#define TF_CONFIG_H
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
//#include <esp8266.h> // when using with esphttpd
@ -59,7 +62,7 @@ typedef uint8_t TF_COUNT;
// Frame ID listeners (wait for response / multi-part message)
#define TF_MAX_ID_LST 5
// Frame Type listeners (wait for frame with a specific first payload byte)
#define TF_MAX_TYPE_LST 5
#define TF_MAX_TYPE_LST 16
// Generic listeners (fallback if no other listener catches it)
#define TF_MAX_GEN_LST 1

@ -35,7 +35,7 @@ int main(void)
// Bind ^C handler for safe shutdown
signal(SIGINT, sigintHandler);
gex = GEX_Init("/dev/ttyACM0", 300);
gex = GEX_Init("/dev/ttyACM0", 100);
if (!gex) exit(1);
TF_AddGenericListener(GEX_GetTF(gex), hdl_default);
@ -54,18 +54,20 @@ int main(void)
// 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++) {
for(int i=0; i<30; i++) {
fprintf(stderr, "\n%d \"PING\"\n", i);
msg = GEX_Query0(test, 0);
assert(msg.type == MSG_SUCCESS);
fprintf(stderr, "\"PING\" cmd: OK.\n");
//usleep(20000);
fprintf(stderr, "\"PING\" OK!\n");
usleep(100000);
}
#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.";
"has printed gibberish all over it and put your name at the top. Read the communist manifesto via bulk transfer. Read the communist manifesto via bulk transfer. Technology is a constand battle between manufacturers producing bigger and "
"more idiot-proof systems and nature producing bigger and better idiots. END";
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)));

Loading…
Cancel
Save