From: John Hodge Date: Sun, 10 Apr 2011 09:38:48 +0000 (+0800) Subject: [TPG] Fixes to bugs exposed during move X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=135e5ad4cc018ec05d1118e4d40be5c51db3f293;p=tpg%2Fopendispense2.git [TPG] Fixes to bugs exposed during move - Serial Input/Output flags were left unset - Coke debug enabled - Empty line detection added to slot status reads. - Fixed compile issues in client (OpenSSL is no longer needed) --- diff --git a/src/client/Makefile b/src/client/Makefile index fa56d77..748819d 100644 --- a/src/client/Makefile +++ b/src/client/Makefile @@ -1,6 +1,7 @@ CFLAGS := -Wall -Werror -g -LDFLAGS := -g -lncurses -lssl +LDFLAGS := -g -lncurses +# -lssl BIN := ../../dispense OBJ := main.o diff --git a/src/client/main.c b/src/client/main.c index 2c2fb1a..d7a8e49 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -23,7 +23,7 @@ #include #include #include -#include // SHA1 +//#include // SHA1 #define USE_NCURSES_INTERFACE 0 #define DEBUG_TRACE_SERVER 0 diff --git a/src/server/handler_coke.c b/src/server/handler_coke.c index 58e3b79..79d0a46 100644 --- a/src/server/handler_coke.c +++ b/src/server/handler_coke.c @@ -21,7 +21,7 @@ #include #define READ_TIMEOUT 2 // 2 seconds for ReadChar -#define TRACE_COKE 0 +#define TRACE_COKE 1 #if TRACE_COKE # define TRACE(v...) do{printf("%s: ",__func__);printf(v);}while(0) @@ -60,7 +60,7 @@ int Coke_InitHandler() { CompileRegex(&gCoke_StatusRegex, "^slot\\s+([0-9]+)\\s+([^:]+):([a-zA-Z]+)\\s*", REG_EXTENDED); - printf("connecting to coke machine...\n"); + printf("Connecting to coke machine on '%s'\n", gsCoke_SerialPort); giCoke_SerialFD = InitSerial(gsCoke_SerialPort, 9600); if( giCoke_SerialFD == -1 ) { @@ -90,6 +90,8 @@ int Coke_InitHandler() Coke_int_UpdateSlotStatuses(); } + else + fprintf(stderr, "Coke machine timed out.\n"); } AddPeriodicFunction(Coke_int_UpdateSlotStatuses); @@ -154,7 +156,8 @@ void Coke_int_UpdateSlotStatuses(void) for( i = 0; i <= 6; i ++ ) { - len = ReadLine(sizeof tmp, tmp); + // Read until non-blank line + while( (len = ReadLine(sizeof tmp, tmp)) == 0 ) ; if( len == -1 ) { TRACE("Read failed on slot %i\n", i); goto ret; // I give up :( diff --git a/src/server/main.c b/src/server/main.c index a8d8d32..18c02dc 100644 --- a/src/server/main.c +++ b/src/server/main.c @@ -250,6 +250,8 @@ int InitSerial(const char *File, int BaudRate) info.c_lflag = 0; // Non-Canoical, No Echo info.c_cflag = baud | CS8 | CLOCAL | CREAD; // baud, 8N1 + info.c_iflag = IGNCR; // Ignore \r + info.c_oflag = 0; // ??? cfsetspeed(&info, baud); info.c_cc[VTIME] = 0; // No time limit info.c_cc[VMIN] = 1; // Block until 1 char