3 * UCC (University [of WA] Computer Club) Electronic Accounting System
5 * handler_doror.c - Door Relay code
7 * This file is licenced under the 3-clause BSD Licence. See the file
8 * COPYING for full details.
17 #define DOOR_UNLOCKED_DELAY 10 // 10 seconds before it re-locks
22 int Door_InitHandler();
23 int Door_CanDispense(int User, int Item);
24 int Door_DoDispense(int User, int Item);
27 tHandler gDoor_Handler = {
33 char *gsDoor_Password;
35 // int giDoor_SerialFD;
38 int Door_InitHandler(void)
40 gsDoor_Command = malloc(sizeof("llogin door -w ")+strlen(gsDoor_Password));
41 sprintf(gsDoor_Command, "llogin door -w %s", gsDoor_Password);
48 int Door_CanDispense(int User, int Item)
51 if( Item == 0 ) return -1;
53 if( !(Bank_GetFlags(User) & USER_FLAG_DOORGROUP) )
60 * \brief Actually do a dispense from the coke machine
62 int Door_DoDispense(int User, int Item)
66 if( Item != 0 ) return -1;
68 // Check if user is in door
69 if( !(Bank_GetFlags(User) & USER_FLAG_DOORGROUP) )
73 //pipe = popen(gsDoor_Command, "w");
74 pipe = popen("llogin door -w -", "w");
75 if( !pipe || pipe == (void*)-1 )
78 fputs(gsDoor_Password, pipe); fputs("\n", pipe);
79 fputs("ATH1\n", pipe);
80 sleep(DOOR_UNLOCKED_DELAY);
81 fputs("ATH0\n", pipe);