From: John Hodge Date: Sat, 4 Dec 2010 08:09:42 +0000 (+0800) Subject: Snack handler added X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=142d8dc0b172eac2e1a735df4bd0fe3461e41252;p=tpg%2Fopendispense2.git Snack handler added --- diff --git a/src/server/handler_coke.c b/src/server/handler_coke.c index 13f25c0..978e3f5 100644 --- a/src/server/handler_coke.c +++ b/src/server/handler_coke.c @@ -36,7 +36,11 @@ regex_t gCoke_StatusRegex; // == CODE === int Coke_InitHandler() { + printf("connecting to coke machine...\n"); giCoke_SerialFD = open(gsCoke_SerialPort, O_RDWR); + if( giCoke_SerialFD == -1 ) { + fprintf(stderr, "ERROR: Unable to open coke serial port ('%s')\n", gsCoke_SerialPort); + } regcomp(&gCoke_StatusRegex, "^slot\\s+(\\d)\\s+([^:]+):([a-zA-Z]+)\\s*", REG_EXTENDED); return 0; } diff --git a/src/server/itemdb.c b/src/server/itemdb.c index 87ced4e..97c64e4 100644 --- a/src/server/itemdb.c +++ b/src/server/itemdb.c @@ -16,6 +16,7 @@ // === IMPORTS === extern tHandler gCoke_Handler; +extern tHandler gSnack_Handler; // === PROTOTYPES === void Load_Itemlist(void); @@ -25,7 +26,7 @@ char *trim(char *__str); int giNumItems = 0; tItem *gaItems = NULL; tHandler gPseudo_Handler = {Name:"pseudo"}; -tHandler *gaHandlers[] = {&gPseudo_Handler, &gCoke_Handler}; +tHandler *gaHandlers[] = {&gPseudo_Handler, &gCoke_Handler, &gSnack_Handler}; int giNumHandlers = sizeof(gaHandlers)/sizeof(gaHandlers[0]); char *gsItemListFile = DEFAULT_ITEM_FILE; diff --git a/src/server/main.c b/src/server/main.c index 5022fd6..80183ba 100644 --- a/src/server/main.c +++ b/src/server/main.c @@ -21,6 +21,7 @@ extern void Server_Start(void); extern int giServer_Port; extern char* gsItemListFile; extern char* gsCoke_SerialPort; +extern char* gsSnack_SerialPort; // === GLOBALS === int giDebugLevel = 0; @@ -59,9 +60,12 @@ int main(int argc, char *argv[]) if( strcmp(arg, "--itemsfile") == 0 ) { gsItemListFile = argv[++i]; } - if( strcmp(arg, "--cokeport") == 0 ) { + else if( strcmp(arg, "--cokeport") == 0 ) { gsCoke_SerialPort = argv[++i]; } + else if( strcmp(arg, "--snackport") == 0 ) { + gsSnack_SerialPort = argv[++i]; + } else { // Usage error? }