diff options
author | Hans Verkuil <hverkuil-cisco@xs4all.nl> | 2020-09-08 16:16:44 +0200 |
---|---|---|
committer | Hans Verkuil <hverkuil-cisco@xs4all.nl> | 2020-09-08 16:16:44 +0200 |
commit | 364da216e3f8750b037fde0f83d64ced0f94a1aa (patch) | |
tree | a7d9c12bcbe4f512839b8e645028e3d9f7a20747 | |
parent | 79918a591a9ad362f107795ee4046d39e6dfcb67 (diff) |
cec-follower: add --standby and --toggle-power-status
Add the --standby option to start the follower with the device
in Standby status.
Add the --toggle-power-status <secs> option to let the follower
toggle the emulated power status every <secs> seconds. This helps
testing power status transtions.
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
-rw-r--r-- | utils/cec-follower/cec-follower.1.in | 7 | ||||
-rw-r--r-- | utils/cec-follower/cec-follower.cpp | 17 | ||||
-rw-r--r-- | utils/cec-follower/cec-follower.h | 1 | ||||
-rw-r--r-- | utils/cec-follower/cec-processing.cpp | 10 |
4 files changed, 34 insertions, 1 deletions
diff --git a/utils/cec-follower/cec-follower.1.in b/utils/cec-follower/cec-follower.1.in index 61c591b3..281651ea 100644 --- a/utils/cec-follower/cec-follower.1.in +++ b/utils/cec-follower/cec-follower.1.in @@ -85,6 +85,13 @@ Show state changes from the emulated device. \fB\-\-service\-by\-dig\-id\fR Report digital services by digital ID instead of by channel. .TP +\fB\-\-standby\fR +Start the follower in the Standby status. +.TP +\fB\-\-toggle\-power\-status\fR \fI<secs>\fR +Toggle the power status every <secs> seconds. Only supported if the follower +is emulating a TV. +.TP \fB\-i\fR, \fB\-\-ignore\fR \fI<la>,<opcode>\fR Ignore messages from logical address \fI<la>\fR and opcode \fI<opcode>\fR. 'all' can be used for \fI<la>\fR or \fI<opcode>\fR to match diff --git a/utils/cec-follower/cec-follower.cpp b/utils/cec-follower/cec-follower.cpp index 673c6e31..9e049ef1 100644 --- a/utils/cec-follower/cec-follower.cpp +++ b/utils/cec-follower/cec-follower.cpp @@ -43,6 +43,8 @@ enum Option { OptShowState = 's', OptWallClock = 'w', OptServiceByDigID = 128, + OptStandby, + OptTogglePowerStatus, OptVersion, OptLast = 256 }; @@ -67,6 +69,8 @@ static struct option long_options[] = { { "show-state", no_argument, 0, OptShowState }, { "wall-clock", no_argument, 0, OptWallClock }, { "service-by-dig-id", no_argument, 0, OptServiceByDigID }, + { "standby", no_argument, 0, OptStandby }, + { "toggle-power-status", required_argument, 0, OptTogglePowerStatus }, { "ignore", required_argument, 0, OptIgnore }, { "version", no_argument, 0, OptVersion }, @@ -91,6 +95,9 @@ static void usage() " -m, --show-msgs Show received messages\n" " -s, --show-state Show state changes from the emulated device\n" " --service-by-dig-id Report digital services by digital ID instead of by channel\n" + " --standby Start in Standby state\n" + " --toggle-power-status <secs>\n" + " Toggle the power status every <secs> seconds\n" " -i, --ignore <la>,<opcode>\n" " Ignore messages from logical address <la> and opcode\n" " <opcode>. 'all' can be used for <la> or <opcode> to match\n" @@ -300,7 +307,10 @@ int cec_named_ioctl(int fd, const char *name, void state_init(struct node &node) { - node.state.power_status = CEC_OP_POWER_STATUS_ON; + if (options[OptStandby]) + node.state.power_status = CEC_OP_POWER_STATUS_STANDBY; + else + node.state.power_status = CEC_OP_POWER_STATUS_ON; node.state.old_power_status = CEC_OP_POWER_STATUS_ON; node.state.power_status_changed_time = 0; strcpy(node.state.menu_language, "eng"); @@ -321,6 +331,7 @@ int main(int argc, char **argv) struct node node = { }; const char *driver = NULL; const char *adapter = NULL; + unsigned toggle_power_status = 0; char short_options[26 * 2 * 2 + 1]; int idx = 0; int fd = -1; @@ -388,6 +399,9 @@ int main(int argc, char **argv) case OptShowState: show_state = true; break; + case OptTogglePowerStatus: + toggle_power_status = strtoul(optarg, NULL, 0); + break; case OptIgnore: { bool all_la = !strncmp(optarg, "all", 3); bool all_opcodes = true; @@ -480,6 +494,7 @@ int main(int argc, char **argv) node.caps = caps.capabilities; node.available_log_addrs = caps.available_log_addrs; node.state.service_by_dig_id = options[OptServiceByDigID]; + node.state.toggle_power_status = toggle_power_status; state_init(node); printf("cec-follower SHA : %s\n", STRING(GIT_SHA)); diff --git a/utils/cec-follower/cec-follower.h b/utils/cec-follower/cec-follower.h index 222342e7..380bd480 100644 --- a/utils/cec-follower/cec-follower.h +++ b/utils/cec-follower/cec-follower.h @@ -57,6 +57,7 @@ struct state { bool service_by_dig_id; bool tuner_report_changes; bool deck_report_changes; + unsigned toggle_power_status; }; struct node { diff --git a/utils/cec-follower/cec-processing.cpp b/utils/cec-follower/cec-processing.cpp index 074e245d..e5021aa3 100644 --- a/utils/cec-follower/cec-processing.cpp +++ b/utils/cec-follower/cec-processing.cpp @@ -871,6 +871,7 @@ void testProcessing(struct node *node, bool wallclock) unsigned me; unsigned last_poll_la = 15; __u8 last_pwr_state = current_power_state(node); + time_t last_pwr_status_toggle = time(NULL); clock_gettime(CLOCK_MONOTONIC, &start_monotonic); gettimeofday(&start_timeofday, NULL); @@ -972,6 +973,15 @@ void testProcessing(struct node *node, bool wallclock) last_pwr_state = pwr_state; } + if (node->state.toggle_power_status && cec_has_tv(1 << me) && + (time(NULL) - last_pwr_status_toggle > node->state.toggle_power_status)) { + last_pwr_status_toggle = time(NULL); + if (pwr_state & 1) // standby or to-standby + exit_standby(node); + else + enter_standby(node); + } + __u64 ts_now = get_ts(); unsigned poll_la = ts_to_s(ts_now) % 16; |