aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Fjeldtvedt <jaffe1@gmail.com>2016-07-19 14:26:26 +0200
committerHans Verkuil <hans.verkuil@cisco.com>2016-07-19 14:29:16 +0200
commit52ddeaaa2d6a239b572099663fb20c951391d5d8 (patch)
tree396d29229cc22e835dd721ba719f6464026c9bdb
parentcd633bb91c375dd333b5ac0e90c1d9e8b5c07fb8 (diff)
cec-follower: add periodical checks for RC press timeout
This adds a timeout to the select call in the receive loop, so that things can periodically be performed. A check for timing out waiting for User Control Release is added. Signed-off-by: Johan Fjeldtvedt <jaffe1@gmail.com> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
-rw-r--r--utils/cec-follower/cec-follower.h8
-rw-r--r--utils/cec-follower/cec-processing.cpp33
2 files changed, 34 insertions, 7 deletions
diff --git a/utils/cec-follower/cec-follower.h b/utils/cec-follower/cec-follower.h
index e010d02f..452ac537 100644
--- a/utils/cec-follower/cec-follower.h
+++ b/utils/cec-follower/cec-follower.h
@@ -181,6 +181,14 @@ static inline unsigned ts_to_ms(__u64 ts)
return ts / 1000000;
}
+static inline __u64 get_ts()
+{
+ struct timespec timespec;
+
+ clock_gettime(CLOCK_MONOTONIC, &timespec);
+ return timespec.tv_sec * 1000000000ull + timespec.tv_nsec;
+}
+
const char *la2s(unsigned la);
const char *la_type2s(unsigned type);
const char *prim_type2s(unsigned type);
diff --git a/utils/cec-follower/cec-processing.cpp b/utils/cec-follower/cec-processing.cpp
index 79ca9018..98e948c6 100644
--- a/utils/cec-follower/cec-processing.cpp
+++ b/utils/cec-follower/cec-processing.cpp
@@ -386,7 +386,7 @@ static void processMsg(struct node *node, struct cec_msg &msg, unsigned me)
two messages is longer than the maximum Initiator Repetition Time. */
if (duration > MAX_INITIATOR_REP_TIME)
warn("Device waited more than the maximum Initiatior Repetition Time and should have sent a User Control Released message.");
- } else {
+ } else if (duration < FOLLOWER_SAFETY_TIMEOUT) {
/* We have not yet received a User Control Released, but received
another User Control Pressed, with the same UI Command as the
previous, which means that the Press and Hold behavior should
@@ -443,10 +443,16 @@ static void processMsg(struct node *node, struct cec_msg &msg, unsigned me)
rc_press_hold_stop(&node->state);
if (node->state.rc_state == NOPRESS)
- warn("Unexpected User Control Released\n");
- else if (get_duration_ms(msg.rx_ts, node->state.rc_press_rx_ts) > FOLLOWER_SAFETY_TIMEOUT) {
- warn("User Control Released received after Follower Safety Timeout period.\n");
- }
+ dev_info("Button release (unexpected, %ums after last press)\n",
+ ts_to_ms(msg.rx_ts - node->state.rc_press_rx_ts));
+ else if (get_duration_ms(msg.rx_ts, node->state.rc_press_rx_ts) > FOLLOWER_SAFETY_TIMEOUT)
+ dev_info("Button release: %s (after timeout, %ums after last press)\n",
+ get_ui_cmd_string(node->state.rc_ui_cmd),
+ ts_to_ms(msg.rx_ts - node->state.rc_press_rx_ts));
+ else
+ dev_info("Button release: %s (%ums after last press)\n",
+ get_ui_cmd_string(node->state.rc_ui_cmd),
+ ts_to_ms(msg.rx_ts - node->state.rc_press_rx_ts));
node->state.rc_state = NOPRESS;
return;
@@ -684,13 +690,15 @@ void testProcessing(struct node *node)
while (1) {
int res;
+ struct timeval timeval = {};
+ timeval.tv_sec = 1;
FD_ZERO(&rd_fds);
FD_ZERO(&ex_fds);
FD_SET(fd, &rd_fds);
FD_SET(fd, &ex_fds);
- res = select(fd + 1, &rd_fds, NULL, &ex_fds, NULL);
- if (res <= 0)
+ res = select(fd + 1, &rd_fds, NULL, &ex_fds, &timeval);
+ if (res < 0)
break;
if (FD_ISSET(fd, &ex_fds)) {
struct cec_event ev;
@@ -727,6 +735,17 @@ void testProcessing(struct node *node)
if (node->adap_la_mask)
processMsg(node, msg, me);
}
+
+ unsigned ms_since_press = ts_to_ms(get_ts() - node->state.rc_press_rx_ts);
+
+ if (ms_since_press > FOLLOWER_SAFETY_TIMEOUT) {
+ if (node->state.rc_state == PRESS_HOLD)
+ rc_press_hold_stop(&node->state);
+ else if (node->state.rc_state == PRESS) {
+ dev_info("Button timeout: %s\n", get_ui_cmd_string(node->state.rc_ui_cmd));
+ node->state.rc_state = NOPRESS;
+ }
+ }
}
mode = CEC_MODE_INITIATOR;
doioctl(node, CEC_S_MODE, &mode);

Privacy Policy