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.
20 int Door_InitHandler();
21 int Door_CanDispense(int User, int Item);
22 int Door_DoDispense(int User, int Item);
25 tHandler gDoor_Handler = {
31 char *gsDoor_Password;
33 // int giDoor_SerialFD;
36 int Door_InitHandler(void)
38 // printf("connecting to door...\n");
39 // giDoor_SerialFD = open(gsDoor_SerialPort, O_RDWR);
40 // if( giDoor_SerialFD == -1 ) {
41 // fprintf(stderr, "ERROR: Unable to open coke serial port ('%s')\n", gsDoor_SerialPort);
48 int Door_CanDispense(int User, int Item)
51 if( Item == 0 ) return -1;
53 if( !(Bank_GetFlags(User) & USER_FLAG_DOORGROUP) )
56 gsDoor_Command = malloc(sizeof("llogin door -w ")+strlen(gsDoor_Password));
57 sprintf(gsDoor_Command, "llogin door -w %s", gsDoor_Password);
63 * \brief Actually do a dispense from the coke machine
65 int Door_DoDispense(int User, int Item)
69 if( Item != 0 ) return -1;
71 // Check if user is in door
72 if( !(Bank_GetFlags(User) & USER_FLAG_DOORGROUP) )
76 pipe = popen(gsDoor_Command, "w");
77 if( !pipe || pipe == (void*)-1 )