X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2Fserver%2Fhandler_coke.c;h=58e3b790be4fc6042158c24a076017a178e755bd;hb=32b161c885d90286f7d4a72b9d05e947c96069e5;hp=12e24315b98c442ea0d441dc9f355ebc7d1d6c33;hpb=24654ef0078320798912a273508e37f9ce921ba7;p=tpg%2Fopendispense2.git diff --git a/src/server/handler_coke.c b/src/server/handler_coke.c index 12e2431..58e3b79 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 1 +#define TRACE_COKE 0 #if TRACE_COKE # define TRACE(v...) do{printf("%s: ",__func__);printf(v);}while(0) @@ -53,6 +53,7 @@ char *gsCoke_SerialPort = "/dev/ttyS0"; regex_t gCoke_StatusRegex; int gaCoke_CachedStatus[7]; pthread_mutex_t gCoke_Mutex = PTHREAD_MUTEX_INITIALIZER; +time_t gtCoke_LastDispenseTime; // == CODE === int Coke_InitHandler() @@ -199,6 +200,14 @@ int Coke_DoDispense(int UNUSED(User), int Item) // Can't dispense if the machine is not connected if( giCoke_SerialFD == -1 ) return -2; + + // Make sure there are not two dispenses within n seconds + if( time(NULL) - gtCoke_LastDispenseTime < 10 ) + { + printf("Wait %li seconds?\n", 10 - (time(NULL) - gtCoke_LastDispenseTime)); + sleep( 10 - (time(NULL) - gtCoke_LastDispenseTime) ); + printf("wait done\n"); + } // LOCK pthread_mutex_lock(&gCoke_Mutex); @@ -266,6 +275,8 @@ int Coke_DoDispense(int UNUSED(User), int Item) char buf[512]; read(giCoke_SerialFD, buf, 512); // Flush } + + gtCoke_LastDispenseTime = time(NULL); // Release and return pthread_mutex_unlock(&gCoke_Mutex);