Commit c71159c3 authored by Ivan Tyagov's avatar Ivan Tyagov

Coupler should know its state thus keep it accordingly.

parent 4678ad35
......@@ -5,6 +5,15 @@ char *NETWORK_ADDRESS_URL_DATA_TYPE = "opc.udp://224.0.0.22:4840/";
// global HEART BEATs of coupler
static unsigned int HEART_BEATS = 0;
// handling coupler's state
static unsigned int CURRENT_STATE;
const int STATE_UP =1;
const int STATE_DOWN = 0;
const int STATE_NO_INITIAL_HEART_BEAT = 2;
// number of times the coupler was in SAFE mode
static unsigned int SAFE_MODE_STATE_COUNTER = 0;
// the heart beat interval (in ms)
const int DEFAULT_HEART_BEAT_INTERVAL = 250;
static int HEART_BEAT_INTERVAL = DEFAULT_HEART_BEAT_INTERVAL;
......
......@@ -300,15 +300,25 @@ void callbackCheckHeartBeat() {
timestamp_delta = milli_seconds - last_seen_timestamp_int;
is_down = (timestamp_delta > HEART_BEAT_TIMEOUT_INTERVAL);
if (is_down) {
UA_LOG_INFO(UA_Log_Stdout, \
UA_LOGCATEGORY_USERLAND, \
"DOWN: %s (delta=%d)", coupler_id_str, timestamp_delta);
// go to safe mode as a dependant coupler is DOWN.
gotoSafeMode();
// count for stats the switch to SAFE mode
if (CURRENT_STATE != STATE_DOWN) {
CURRENT_STATE = STATE_DOWN;
SAFE_MODE_STATE_COUNTER += 1;
UA_LOG_INFO(UA_Log_Stdout, \
UA_LOGCATEGORY_USERLAND, \
"DOWN: %s (delta=%d)", coupler_id_str, timestamp_delta);
// go to safe mode as a dependant coupler is DOWN.
gotoSafeMode();
}
}
else {
// all good, we received a keep alive in time
CURRENT_STATE = STATE_UP;
}
}
else {
// still no hear beat from this coupler ...
CURRENT_STATE = STATE_NO_INITIAL_HEART_BEAT;
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "NO INITIAL HEART BEAT: %s", coupler_id_str);
}
}
......
......@@ -185,5 +185,10 @@ int main(int argc, char **argv)
// always leave attached slaves to a known safe shutdown state
safeShutdownI2CSlaveList();
// print statistics
UA_LOG_INFO(UA_Log_Stdout, \
UA_LOGCATEGORY_USERLAND, \
"SAFE mode counter=%d", SAFE_MODE_STATE_COUNTER);
return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment