fixed the bug with corrupted 13rd message

master
Ondřej Hruška 7 years ago
parent cd479d2dfe
commit c3e4c91e2d
  1. 2
      gex/gex_client.c
  2. 28
      gex/serial/serial.c
  3. 37
      main.c

@ -175,7 +175,7 @@ GexClient *GEX_Init(const char *device, int timeout_ms)
/** Try to read from the serial port and process any received bytes with TF */ /** Try to read from the serial port and process any received bytes with TF */
void GEX_Poll(GexClient *gex) void GEX_Poll(GexClient *gex)
{ {
uint8_t pollbuffer[TF_MAX_PAYLOAD_RX]; static uint8_t pollbuffer[TF_MAX_PAYLOAD_RX];
assert(gex != NULL); assert(gex != NULL);

@ -8,7 +8,7 @@
#include <termios.h> #include <termios.h>
#include <unistd.h> #include <unistd.h>
static int set_interface_attribs(int fd, int speed, int parity) static int set_interface_attribs(int fd)
{ {
struct termios tty; struct termios tty;
memset(&tty, 0, sizeof tty); memset(&tty, 0, sizeof tty);
@ -17,28 +17,16 @@ static int set_interface_attribs(int fd, int speed, int parity)
return -1; return -1;
} }
cfsetospeed(&tty, (speed_t) speed); cfsetospeed(&tty, (speed_t) __MAX_BAUD);
cfsetispeed(&tty, (speed_t) speed); cfsetispeed(&tty, (speed_t) __MAX_BAUD);
tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars tty.c_cflag = CLOCAL | CREAD | CS8; // 8-bit chars
// disable IGNBRK for mismatched speed tests; otherwise receive break tty.c_iflag = 0;
// as \000 chars tty.c_lflag = 0;
tty.c_iflag &= ~IGNBRK; // disable break processing tty.c_oflag = 0;
tty.c_lflag = 0; // no signaling chars, no echo,
// no canonical processing
tty.c_oflag = 0; // no remapping, no delays
tty.c_cc[VMIN] = 0; // read doesn't block tty.c_cc[VMIN] = 0; // read doesn't block
tty.c_cc[VTIME] = 2; // 0.2 seconds read timeout tty.c_cc[VTIME] = 2; // 0.2 seconds read timeout
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl
tty.c_cflag |= (CLOCAL | CREAD);// ignore modem controls,
// enable reading
tty.c_cflag &= ~(PARENB | PARODD); // shut off parity
tty.c_cflag |= parity;
tty.c_cflag &= ~CSTOPB;
tty.c_cflag &= ~CRTSCTS;
if (tcsetattr(fd, TCSANOW, &tty) != 0) { if (tcsetattr(fd, TCSANOW, &tty) != 0) {
printf("error %d from tcsetattr\n", errno); printf("error %d from tcsetattr\n", errno);
return -1; return -1;
@ -55,7 +43,7 @@ int serial_open(const char *device)
return -1; return -1;
} }
set_interface_attribs(fd, B115200, 0); set_interface_attribs(fd);
return fd; return fd;
} }

@ -35,7 +35,7 @@ int main(void)
// Bind ^C handler for safe shutdown // Bind ^C handler for safe shutdown
signal(SIGINT, sigintHandler); signal(SIGINT, sigintHandler);
gex = GEX_Init("/dev/ttyACM0", 100); gex = GEX_Init("/dev/ttyACM0", 200);
if (!gex) exit(1); if (!gex) exit(1);
TF_AddGenericListener(GEX_GetTF(gex), hdl_default); TF_AddGenericListener(GEX_GetTF(gex), hdl_default);
@ -49,23 +49,9 @@ int main(void)
// the "PING" command // the "PING" command
GexMsg msg; GexMsg msg;
#if 1
// Simple response
// 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<30; i++) {
fprintf(stderr, "\n%d \"PING\"\n", i);
msg = GEX_Query0(test, 0);
assert(msg.type == MSG_SUCCESS);
fprintf(stderr, "\"PING\" OK!\n");
usleep(100000);
}
#endif
#if 1 #if 1
// Test a echo command that returns back what was sent to it as useful payload // 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 " const char *s = "I am \r\nreturning this otherwise good typing paper to you because someone "
"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 " "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"; "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)); msg = GEX_Query(test, 1, (const uint8_t *) s, (uint32_t) strlen(s));
@ -73,6 +59,23 @@ int main(void)
assert(0==strncmp((char*)msg.payload, s, strlen(s))); assert(0==strncmp((char*)msg.payload, s, strlen(s)));
#endif #endif
#if 1
// Simple response
int failures = 0;
for(int i=0; i<20; i++) {
fprintf(stderr, "\nSending \"PING\" #%d\n", i);
msg = GEX_Query0(test, 0);
fprintf(stderr, "\"PING\" resp = %d\n", msg.type);
if (msg.type != 0) {
fprintf(stderr, "---------------------ERRR-------------------\n");
if (msg.type == 2) fprintf(stderr, "%.*s\n", msg.len, msg.payload);
failures++;
}
//usleep(20000);
}
fprintf(stderr, "FAILURES = %d\n", failures);
#endif
#if 0 #if 0
// Read the communist manifesto via bulk transfer // Read the communist manifesto via bulk transfer
uint8_t buffr[10000]; uint8_t buffr[10000];
@ -88,7 +91,7 @@ int main(void)
fprintf(stderr, "%.*s", actuallyRead, buffr); fprintf(stderr, "%.*s", actuallyRead, buffr);
#endif #endif
fprintf(stderr, "ALL OK, ending.\n"); fprintf(stderr, "ALL done, ending.\n");
GEX_DeInit(gex); GEX_DeInit(gex);
return 0; return 0;
} }

Loading…
Cancel
Save