+/**
+ * \brief Update the status of all coke slots
+ * \note Uses goto to reduce the chance of the lock being kept
+ */
+void Coke_int_UpdateSlotStatuses(void)
+{
+ int i, len;
+ char tmp[40];
+
+ if( giCoke_SerialFD == -1 ) return ;
+
+ 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 ++ )
+ {
+ len = ReadLine(sizeof tmp, tmp);
+ if( len == -1 ) {
+ TRACE("Read failed on slot %i\n", i);
+ goto ret; // I give up :(
+ }
+ TRACE("tmp = '%s'\n", tmp);
+ Coke_int_GetSlotStatus(tmp, i);
+ }
+ // Eat blank line
+ len = ReadLine(sizeof tmp, tmp);
+ if( len == -1 ) {
+ TRACE("Read failed on blank line\n");
+ }