- // Ask the coke machine
- sprintf(tmp, "s%i\r\n", Item);
- write(giCoke_SerialFD, tmp, 4);
-
- #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 );
- printf("ret = %i, tmp = '%s'\n", ret, tmp);
- // Read back-echoed lines
- while( tmp[0] == ':' || tmp[1] != 'l' )
+ pthread_mutex_lock(&gCoke_Mutex);
+
+ while( ReadLine(sizeof tmp, tmp) >= 0 ) ;
+ TRACE("send d7\n");
+ Writef("d7\r\n"); // Update slot statuses
+ if( WaitForColon() ) goto ret;
+ TRACE("send s\n");
+ Writef("s\r\n");
+ do {
+ i = ReadLine(sizeof tmp, tmp); // Read back what we just said
+ if( i == -1 ) {
+ TRACE("Eat read failed");
+ goto ret;
+ }
+ } while(tmp[0] != ':' && tmp[1] != 's');
+
+ for( i = 0; i <= 6; i ++ )