- // Can't dispense if the machine is not connected
- if( giCoke_SerialFD == -1 )
- return -2;
-
- #if TRACE_COKE
- printf("Coke_CanDispense: Flushing\n");
- #endif
-
-
- // Wait for a prompt
- ret = 0;
- while( WaitForColon() && ret < 3 )
- {
- // Flush the input buffer
- char tmpbuf[512];
- read(giCoke_SerialFD, tmpbuf, sizeof(tmpbuf));
- #if TRACE_COKE
- printf("Coke_CanDispense: sending 'd7'\n");
- #endif
- Writef("d7\r\n");
- ret ++;
- }
- // Check for a timeout error
- if( !(ret < 3) ) {
- fprintf(stderr, "Coke machine timed out\n");
- return -2; // -EMYBAD
+ // Parse status response
+ ret = RunRegex(&gCoke_StatusRegex, Buffer, sizeof(matches)/sizeof(matches[0]), matches, "Bad Response");
+ if( ret ) {
+ return -1;