From: John Hodge Date: Sat, 4 Dec 2010 08:18:00 +0000 (+0800) Subject: Door controller code (well, the start of it) X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=99cf95b138082d1c02705682ad0dfd8b67a27ac4;p=tpg%2Fopendispense2.git Door controller code (well, the start of it) --- diff --git a/src/server/handler_door.c b/src/server/handler_door.c new file mode 100644 index 0000000..c132e07 --- /dev/null +++ b/src/server/handler_door.c @@ -0,0 +1,71 @@ +/* + * OpenDispense 2 + * UCC (University [of WA] Computer Club) Electronic Accounting System + * + * handler_doror.c - Door Relay code + * + * This file is licenced under the 3-clause BSD Licence. See the file + * COPYING for full details. + */ +#include "common.h" +#include +#include +#include +#include +#include + +// === IMPORTS === + +// === PROTOTYPES === + int Door_InitHandler(); + int Door_CanDispense(int User, int Item); + int Door_DoDispense(int User, int Item); + +// === GLOBALS === +tHandler gDoor_Handler = { + "door", + Door_InitHandler, + Door_CanDispense, + Door_DoDispense +}; +//char *gsDoor_SerialPort = "/dev/ttyS0"; +// int giDoor_SerialFD; + +// == CODE === +int Door_InitHandler() +{ +// printf("connecting to door...\n"); +// giDoor_SerialFD = open(gsDoor_SerialPort, O_RDWR); +// if( giDoor_SerialFD == -1 ) { +// fprintf(stderr, "ERROR: Unable to open coke serial port ('%s')\n", gsDoor_SerialPort); +// } + return 0; +} + +/** + */ +int Door_CanDispense(int User, int Item) +{ + // Sanity please + if( Item == 0 ) return -1; + + return 0; +} + +/** + * \brief Actually do a dispense from the coke machine + */ +int Door_DoDispense(int User, int Item) +{ + char tmp[32], *status; + regmatch_t matches[4]; + + // Sanity please + if( Item != 0 ) return -1; + + // llogin or other + + return 0; +} + + diff --git a/src/server/handler_snack.c b/src/server/handler_snack.c index 826851e..2e7c4a6 100644 --- a/src/server/handler_snack.c +++ b/src/server/handler_snack.c @@ -47,6 +47,8 @@ int Snack_CanDispense(int User, int Item) // Sanity please if( Item < 0 || Item > 99 ) return -1; + // Hmm... could we implement slot statuses? + return 1; } @@ -71,5 +73,3 @@ int Snack_DoDispense(int User, int Item) return 0; } - - diff --git a/src/server/itemdb.c b/src/server/itemdb.c index 97c64e4..8b494f7 100644 --- a/src/server/itemdb.c +++ b/src/server/itemdb.c @@ -17,6 +17,7 @@ // === IMPORTS === extern tHandler gCoke_Handler; extern tHandler gSnack_Handler; +extern tHandler gDoor_Handler; // === PROTOTYPES === void Load_Itemlist(void); @@ -26,7 +27,7 @@ char *trim(char *__str); int giNumItems = 0; tItem *gaItems = NULL; tHandler gPseudo_Handler = {Name:"pseudo"}; -tHandler *gaHandlers[] = {&gPseudo_Handler, &gCoke_Handler, &gSnack_Handler}; +tHandler *gaHandlers[] = {&gPseudo_Handler, &gCoke_Handler, &gSnack_Handler, &gDoor_Handler}; int giNumHandlers = sizeof(gaHandlers)/sizeof(gaHandlers[0]); char *gsItemListFile = DEFAULT_ITEM_FILE;