- // Ask the coke machine
- sprintf(tmp, "s%i\r\n", Item);
- write(giCoke_SerialFD, tmp, 4);
-
- // Read from the machine (ignoring empty lines)
- while( (ret = ReadLine(sizeof(tmp)-1, tmp)) == 0 );
- printf("ret = %i, tmp = '%s'\n", ret, tmp);
- if( tmp[0] == ':' ) {
- ret = ReadLine(sizeof(tmp)-1, tmp);
- 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;
- }
-
- // Eat rest of response
- WaitForColon();
-
- // Parse status response
- ret = RunRegex(&gCoke_StatusRegex, tmp, sizeof(matches)/sizeof(matches[0]), matches, "Bad Response");
- if( ret ) {
- return -1;
- }
-
- // Get slot status
- tmp[ matches[3].rm_eo ] = '\0';
- status = &tmp[ matches[3].rm_so ];
-
- printf("Machine responded slot status '%s'\n", status);
-
- if( strcmp(status, "full") == 0 )