(bugfix) Insufficient warning level to catch that bug
[tpg/opendispense2.git] / src / server / handler_snack.c
1 /*
2  * OpenDispense 2 
3  * UCC (University [of WA] Computer Club) Electronic Accounting System
4  * - Dispense Server
5  *
6  * handler_snack.c - Snack machine code
7  *
8  * This file is licenced under the 3-clause BSD Licence. See the file
9  * COPYING for full details.
10  */
11 #include "common.h"
12 #include <stdio.h>
13 #include <string.h>
14 #include <unistd.h>
15 #include <sys/stat.h>
16 #include <fcntl.h>
17 #include <regex.h>
18
19 // === IMPORTS ===
20
21 // === PROTOTYPES ===
22  int    Snack_InitHandler();
23  int    Snack_CanDispense(int User, int Item);
24  int    Snack_DoDispense(int User, int Item);
25
26 // === GLOBALS ===
27 tHandler        gSnack_Handler = {
28         "snack",
29         Snack_InitHandler,
30         Snack_CanDispense,
31         Snack_DoDispense
32 };
33 char    *gsSnack_SerialPort = "/dev/ttyS1";
34 #if 0
35  int    giSnack_SerialFD;
36 regex_t gSnack_ResponseRegex;
37 #endif
38
39 // == CODE ===
40 int Snack_InitHandler()
41 {
42 #if 0
43         giSnack_SerialFD = InitSerial(gsSnack_SerialPort, 9600);
44         if( giSnack_SerialFD == -1 ) {
45                 fprintf(stderr, "ERROR: Unable to open snack serial port ('%s')\n", gsSnack_SerialPort);
46         }
47         
48         regcomp(&gSnack_ResponseRegex, "^(\\d\\d\\d)(.*)$", REG_EXTENDED);
49 #endif
50         return 0;
51 }
52
53 int Snack_CanDispense(int UNUSED(User), int Item)
54 {
55         // Sanity please
56         if( Item < 0 || Item > 99 )     return -1;
57         
58         // Hmm... could we implement slot statuses?
59         
60         return 0;
61 }
62
63 /**
64  * \brief Actually do a dispense from the coke machine
65  */
66 int Snack_DoDispense(int UNUSED(User), int Item)
67 {
68         // Sanity please
69         if( Item < 0 || Item > 99 )     return -1;
70
71 #if 0
72         char    tmp[32];
73         regmatch_t      matches[4];
74
75         // Dispense
76         sprintf(tmp, "V%02i\n", Item);
77         write(giSnack_SerialFD, tmp, 2);
78
79         // Get status
80         read(giSnack_SerialFD, tmp, sizeof(tmp)-1);
81         regexec(&gSnack_ResponseRegex, tmp, sizeof(matches)/sizeof(matches[0]), matches, 0);
82 #endif
83
84         return 0;
85 }

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