From cfcb64f05e77195d3a5d9a8a058012cf0f128580 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 17 Apr 2015 15:59:29 +0800 Subject: [PATCH] Server/Coke - Improved logging --- src/server/handler_coke.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/server/handler_coke.c b/src/server/handler_coke.c index b499387..2b7d0f8 100644 --- a/src/server/handler_coke.c +++ b/src/server/handler_coke.c @@ -48,12 +48,14 @@ tHandler gCoke_Handler = { Coke_CanDispense, Coke_DoDispense }; +// - Config const char *gsCoke_ModbusAddress = "130.95.13.73"; int giCoke_ModbusPort = 502; +bool gbCoke_DummyMode = false; +// - State modbus_t *gCoke_Modbus; time_t gtCoke_LastDispenseTime; time_t gtCoke_LastReconnectTime; -bool gbCoke_DummyMode = 1; int giCoke_NextCokeSlot = 0; // == CODE === @@ -118,8 +120,12 @@ int Coke_DoDispense(int UNUSED(User), int Item) int Coke_int_ConnectToPLC(void) { // Ratelimit - if( time(NULL) - gtCoke_LastReconnectTime < COKE_RECONNECT_RATELIMIT ) + time_t elapsed = time(NULL) - gtCoke_LastReconnectTime; + if( elapsed < COKE_RECONNECT_RATELIMIT ) { + Debug_Notice("Not reconnecting, only %llis have pased, %i limit", (long long)elapsed, COKE_RECONNECT_RATELIMIT); + errno = EAGAIN; return -1; + } if( !gCoke_Modbus ) { @@ -135,7 +141,7 @@ int Coke_int_ConnectToPLC(void) // Preven resource leaks modbus_close(gCoke_Modbus); } - Debug_Notice("Connecting to coke PLC machine on '%s'\n", gsCoke_ModbusAddress); + Debug_Notice("Connecting to coke PLC machine on '%s':%i", gsCoke_ModbusAddress, giCoke_ModbusPort); if( modbus_connect(gCoke_Modbus) ) { -- 2.20.1