extern int DispenseUpdateItem(int User, tItem *Item, const char *NewName, int NewPrice);
// --- Logging ---
+// to syslog
extern void Log_Error(const char *Format, ...);
extern void Log_Info(const char *Format, ...);
+// To stdout
+#define Debug_Notice(msg, v...) fprintf(stderr, "%08llun: "msg"\n", (unsigned long long)time(NULL) ,##v)
+#define Debug_Debug(msg, v...) fprintf(stderr, "%08llud: "msg"\n", (unsigned long long)time(NULL) ,##v)
// --- Config Database ---
extern void Config_ParseFile(const char *Filename);
if( time(NULL) - gtCoke_LastDispenseTime < ciCoke_MinPeriod )
{
int delay = ciCoke_MinPeriod - (time(NULL) - gtCoke_LastDispenseTime);
- printf("Wait %i seconds?\n", delay);
+ Debug_Debug("Waiting for %i seconds (rate limit)", delay);
sleep( delay );
- printf("wait done\n");
+ Debug_Debug("wait done");
}
gtCoke_LastDispenseTime = time(NULL);
return 1;
}
}
- printf("Connecting to coke PLC machine on '%s'\n", gsCoke_ModbusAddress);
- fprintf(stderr, "Connecting to coke PLC machine on '%s'\n", gsCoke_ModbusAddress);
+ else {
+ // Preven resource leaks
+ modbus_close(gCoke_Modbus);
+ }
+ Debug_Notice("Connecting to coke PLC machine on '%s'\n", gsCoke_ModbusAddress);
if( modbus_connect(gCoke_Modbus) )
{
if( res == 0 )
{
// Oops!, no drink
- printf("Drink dispense failed, bit lowered too quickly\n");
+ Log_Error("Drink dispense failed, bit lowered too quickly");
+ Debug_Notice("Drink dispense failed, bit lowered too quickly");
return 1;
}
return -1;
if( modbus_write_bit( gCoke_Modbus, BitNum, Value != 0 ) >= 0 )
return 0;
+ // Error case
if( Coke_int_ConnectToPLC() )
return -1;
if( modbus_write_bit( gCoke_Modbus, BitNum, Value != 0 ) >= 0 )
#define PIDFILE "/var/run/dispsrv.pid"
-#define Debug_Notice(msg, v...) printf("%08llun: "msg"\n", (unsigned long long)time(NULL) ,##v)
-#define Debug_Debug(msg, v...) printf("%08llud: "msg"\n", (unsigned long long)time(NULL) ,##v)
-
// Statistics
#define MAX_CONNECTION_QUEUE 5
#define INPUT_BUFFER_SIZE 256