- int read_child_output()
- {
- char buf[1024];
- int len;
- if( giDoor_ChildStatus || (len = read(child_stdin_fd, buf, sizeof buf)) < 0)
- {
- #if DEBUG
- printf("Door_DoDispense: fread fail\n");
- #endif
- return -1;
- }
- buf[len] = '\0';
-
- #if DEBUG > 1
- printf("Door_DoDispense: buf = %i '%s'\n", len, buf);
- #endif
- return 0;
- }
-
- if( read_child_output() ) return -1;
-
- // Send password
- if( giDoor_ChildStatus || fputs(gsDoor_Password, child_stdin) <= 0 ) {
- printf("Door_DoDispense: fputs password fail\n");
- return -1;
- }
- fputs("\n", child_stdin);
- fflush(child_stdin);
-
- if( read_child_output() ) return -1;
-
- #if DEBUG
- printf("Door_DoDispense: Door unlock\n");
- #endif
- // ATH1 - Unlock door
- if( giDoor_ChildStatus || fputs("ATH1\n", child_stdin) == 0) {
- #if DEBUG
- printf("Door_DoDispense: fputs unlock failed (or child terminated)\n");
- #endif
+ if( write(door_serial_handle, "ATH1\n", 5) != 5 ) {
+ fprintf(stderr, "Unable to open door (sending ATH1)\n");
+ perror("Sending ATH1");