- // Disabled in favor of caching
- #if 0
- char tmp[40], *status;
- regmatch_t matches[4];
- int ret;
-
- // Sanity please
- if( Item < 0 || Item > 6 ) return -1; // -EYOURBAD
-
- // 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
- }
-
- // You need to do a 'd7' before reading the status
- // - Otherwise it sometimes reports a full slot as empty
- // [TPG] (2011-02-19)
- if( ret == 0 )
- {
- Writef("d7\r\n");
- WaitForColon();
- }
-
- // TODO: Handle "not ok" response to D7
-
- #if TRACE_COKE
- printf("Coke_CanDispense: sending 's%i'\n", Item);
- #endif
-
- // Ask the coke machine
- Writef("s%i\r\n", Item);
-
- #if TRACE_COKE
- printf("Coke_CanDispense: reading response\n");
- #endif
- // Read from the machine (ignoring empty lines)
- while( (ret = ReadLine(sizeof(tmp)-1, tmp)) == 0 );
- #if TRACE_COKE
- printf("ret = %i, tmp = '%s'\n", ret, tmp);
- #endif
- // Read back-echoed lines
- while( tmp[0] == ':' || tmp[1] != 'l' )
- {
- ret = ReadLine(sizeof(tmp)-1, tmp);
- if( ret == -1 ) return -1;
- printf("ret = %i, tmp = '%s'\n", ret, tmp);
- }
-
- // Catch an error
- if( ret <= 0 ) {
- fprintf(stderr, "Coke machine is not being chatty (read = %i)\n", ret);
- if( ret == -1 ) {
- perror("Coke Machine");
- }
- return -1;
- }
-
- #if TRACE_COKE
- printf("Coke_CanDispense: wait for the prompt again\n");
- #endif
-
- // Eat rest of response
- WaitForColon();
-
- return Coke_GetSlotStatus(tmp, Item);
- #else