X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2Fserver%2Fhandler_coke.c;h=c937756583c9bac0a7bbf1f9b65d03aface5d3f2;hb=3e7700e1b9b652bb3ed7daaff76cf891907a63b3;hp=53cbd0fd7d3be7afecefdd8cd97f84125fdd5953;hpb=dfa4eb21fc9e7cc2bfa912581d38aaee04f3b990;p=tpg%2Fopendispense2.git diff --git a/src/server/handler_coke.c b/src/server/handler_coke.c index 53cbd0f..c937756 100644 --- a/src/server/handler_coke.c +++ b/src/server/handler_coke.c @@ -37,13 +37,12 @@ regex_t gCoke_StatusRegex; int Coke_InitHandler() { printf("connecting to coke machine...\n"); - giCoke_SerialFD = open(gsCoke_SerialPort, O_RDWR | O_NOCTTY | O_NONBLOCK); + + giCoke_SerialFD = InitSerial(gsCoke_SerialPort, 9600); if( giCoke_SerialFD == -1 ) { fprintf(stderr, "ERROR: Unable to open coke serial port ('%s')\n", gsCoke_SerialPort); } - InitSerial(giCoke_SerialFD, 9600); - CompileRegex(&gCoke_StatusRegex, "^slot\\s+(\\d)\\s+([^:]+):([a-zA-Z]+)\\s*", REG_EXTENDED); return 0; } @@ -61,6 +60,9 @@ int Coke_CanDispense(int User, int Item) sprintf(tmp, "s%i\n", Item); write(giCoke_SerialFD, tmp, 2); + // Wait a little + sleep(250); + // Read the response tmp[0] = '\0'; ret = read(giCoke_SerialFD, tmp, sizeof(tmp)-1); @@ -99,6 +101,9 @@ int Coke_DoDispense(int User, int Item) // Dispense sprintf(tmp, "d%i\n", Item); write(giCoke_SerialFD, tmp, 2); + + // Wait a little + sleep(250); // Get status read(giCoke_SerialFD, tmp, sizeof(tmp)-1);