Snack handler added
authorJohn Hodge <[email protected]>
Sat, 4 Dec 2010 08:09:42 +0000 (16:09 +0800)
committerJohn Hodge <[email protected]>
Sat, 4 Dec 2010 08:09:42 +0000 (16:09 +0800)
src/server/handler_coke.c
src/server/itemdb.c
src/server/main.c

index 13f25c0..978e3f5 100644 (file)
@@ -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;
 }
index 87ced4e..97c64e4 100644 (file)
@@ -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;
 
index 5022fd6..80183ba 100644 (file)
@@ -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?
                        }

UCC git Repository :: git.ucc.asn.au