#!/bin/sh
-ARGS="--itemsfile items.cfg -p 11020 --cokeport /dev/ttyUSB0"
+ARGS="--itemsfile items.cfg -p 11020"
+ARGS=$ARGS" --cokeport /dev/ttyUSB0"
if [ "x$1" != "x" ]; then
LD_LIBRARY_PATH=. gdb --args ./dispsrv $ARGS
// --- Helpers --
extern void CompileRegex(regex_t *Regex, const char *Pattern, int Flags);
extern int RunRegex(regex_t *regex, const char *string, int nMatches, regmatch_t *matches, const char *errorMessage);
+extern void InitSerial(int FD, int BaudRate);
// --- Dispense ---
extern int DispenseItem(int User, tItem *Item);
int Coke_InitHandler()
{
printf("connecting to coke machine...\n");
- giCoke_SerialFD = open(gsCoke_SerialPort, O_RDWR);
+ giCoke_SerialFD = open(gsCoke_SerialPort, O_RDWR | O_NOCTTY | O_NONBLOCK);
if( giCoke_SerialFD == -1 ) {
fprintf(stderr, "ERROR: Unable to open coke serial port ('%s')\n", gsCoke_SerialPort);
}
+
+ InitSerial(giCoke_SerialFD, 9600);
+
CompileRegex(&gCoke_StatusRegex, "^slot\\s+(\\d)\\s+([^:]+):([a-zA-Z]+)\\s*", REG_EXTENDED);
return 0;
}
// == CODE ===
int Snack_InitHandler()
{
- giSnack_SerialFD = open(gsSnack_SerialPort, O_RDWR);
+ giSnack_SerialFD = open(gsSnack_SerialPort, O_RDWR | O_NOCTTY | O_NONBLOCK);
+ if( giSnack_SerialFD == -1 ) {
+ fprintf(stderr, "ERROR: Unable to open snack serial port ('%s')\n", gsSnack_SerialPort);
+ }
+
+ InitSerial(giSnack_SerialFD, 9600);
+
regcomp(&gSnack_ResponseRegex, "^(\\d\\d\\d)(.*)$", REG_EXTENDED);
return 0;
}
#include <string.h>
#include <signal.h>
#include "common.h"
+#include <termios.h>
// === IMPORTS ===
extern void Init_Cokebank(const char *Argument); // cokebank.c
}
}
+// Serial helper
+void InitSerial(int FD, int BaudRate)
+{
+ struct termios info;
+ int baud;
+
+ switch(BaudRate)
+ {
+ case 9600: baud = B9600; break;
+ default: return ;
+ }
+
+ cfmakeraw(&info); // Sets 8N1
+ cfsetspeed(&info, baud);
+
+ tcsetattr(FD, TCSANOW, &info);
+}
+