#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
-#include <openssl/sha.h> // SHA1
+//#include <openssl/sha.h> // SHA1
#define USE_NCURSES_INTERFACE 0
#define DEBUG_TRACE_SERVER 0
#include <pthread.h>
#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)
{
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 ) {
Coke_int_UpdateSlotStatuses();
}
+ else
+ fprintf(stderr, "Coke machine timed out.\n");
}
AddPeriodicFunction(Coke_int_UpdateSlotStatuses);
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 :(
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