aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2018-10-04 12:57:55 +0200
committerHans Verkuil <hans.verkuil@cisco.com>2018-10-04 12:57:55 +0200
commitc926790d303bdf85c0b829e89a05ba40e9e795fd (patch)
tree11c2ab94fefa87d3cefe9c07bc69ff0c10f108f4 /utils
parent71806d6cbfad009e2b5f5b98ae75dff9eda91bf0 (diff)
cec: move status2s functions to cec-info.cpp
All three cec utilities used the same code to construct a string with the message status. Move this code to cec-info.cpp and use it in all three utilities. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Diffstat (limited to 'utils')
-rw-r--r--utils/cec-compliance/cec-compliance.cpp68
-rw-r--r--utils/cec-ctl/cec-ctl.cpp68
-rw-r--r--utils/cec-follower/cec-follower.cpp68
-rw-r--r--utils/common/cec-info.cpp68
-rw-r--r--utils/common/cec-info.h1
-rw-r--r--utils/common/cec-log.cpp69
6 files changed, 70 insertions, 272 deletions
diff --git a/utils/cec-compliance/cec-compliance.cpp b/utils/cec-compliance/cec-compliance.cpp
index ad6c5744..990c38bf 100644
--- a/utils/cec-compliance/cec-compliance.cpp
+++ b/utils/cec-compliance/cec-compliance.cpp
@@ -242,74 +242,6 @@ static std::string ts2s(__u64 ts)
return s + "." + buf;
}
-static std::string tx_status2s(const struct cec_msg &msg)
-{
- std::string s;
- char num[4];
- unsigned stat = msg.tx_status;
-
- if (stat)
- s += "Tx";
- if (stat & CEC_TX_STATUS_OK)
- s += ", OK";
- if (stat & CEC_TX_STATUS_ARB_LOST) {
- sprintf(num, "%u", msg.tx_arb_lost_cnt);
- s += ", Arbitration Lost";
- if (msg.tx_arb_lost_cnt)
- s += " (" + std::string(num) + ")";
- }
- if (stat & CEC_TX_STATUS_NACK) {
- sprintf(num, "%u", msg.tx_nack_cnt);
- s += ", Not Acknowledged";
- if (msg.tx_nack_cnt)
- s += " (" + std::string(num) + ")";
- }
- if (stat & CEC_TX_STATUS_LOW_DRIVE) {
- sprintf(num, "%u", msg.tx_low_drive_cnt);
- s += ", Low Drive";
- if (msg.tx_low_drive_cnt)
- s += " (" + std::string(num) + ")";
- }
- if (stat & CEC_TX_STATUS_ERROR) {
- sprintf(num, "%u", msg.tx_error_cnt);
- s += ", Error";
- if (msg.tx_error_cnt)
- s += " (" + std::string(num) + ")";
- }
- if (stat & CEC_TX_STATUS_MAX_RETRIES)
- s += ", Max Retries";
- return s;
-}
-
-static std::string rx_status2s(unsigned stat)
-{
- std::string s;
-
- if (stat)
- s += "Rx";
- if (stat & CEC_RX_STATUS_OK)
- s += ", OK";
- if (stat & CEC_RX_STATUS_TIMEOUT)
- s += ", Timeout";
- if (stat & CEC_RX_STATUS_FEATURE_ABORT)
- s += ", Feature Abort";
- return s;
-}
-
-std::string status2s(const struct cec_msg &msg)
-{
- std::string s;
-
- if (msg.tx_status)
- s = tx_status2s(msg);
- if (msg.rx_status) {
- if (!s.empty())
- s += ", ";
- s += rx_status2s(msg.rx_status);
- }
- return s;
-}
-
const char *power_status2s(__u8 power_status)
{
switch (power_status) {
diff --git a/utils/cec-ctl/cec-ctl.cpp b/utils/cec-ctl/cec-ctl.cpp
index 10c5b27a..126cfa08 100644
--- a/utils/cec-ctl/cec-ctl.cpp
+++ b/utils/cec-ctl/cec-ctl.cpp
@@ -359,74 +359,6 @@ static unsigned parse_phys_addr(const char *value)
static char options[512];
-static std::string tx_status2s(const struct cec_msg &msg)
-{
- std::string s;
- char num[4];
- unsigned stat = msg.tx_status;
-
- if (stat)
- s += "Tx";
- if (stat & CEC_TX_STATUS_OK)
- s += ", OK";
- if (stat & CEC_TX_STATUS_ARB_LOST) {
- sprintf(num, "%u", msg.tx_arb_lost_cnt);
- s += ", Arbitration Lost";
- if (msg.tx_arb_lost_cnt)
- s += " (" + std::string(num) + ")";
- }
- if (stat & CEC_TX_STATUS_NACK) {
- sprintf(num, "%u", msg.tx_nack_cnt);
- s += ", Not Acknowledged";
- if (msg.tx_nack_cnt)
- s += " (" + std::string(num) + ")";
- }
- if (stat & CEC_TX_STATUS_LOW_DRIVE) {
- sprintf(num, "%u", msg.tx_low_drive_cnt);
- s += ", Low Drive";
- if (msg.tx_low_drive_cnt)
- s += " (" + std::string(num) + ")";
- }
- if (stat & CEC_TX_STATUS_ERROR) {
- sprintf(num, "%u", msg.tx_error_cnt);
- s += ", Error";
- if (msg.tx_error_cnt)
- s += " (" + std::string(num) + ")";
- }
- if (stat & CEC_TX_STATUS_MAX_RETRIES)
- s += ", Max Retries";
- return s;
-}
-
-static std::string rx_status2s(unsigned stat)
-{
- std::string s;
-
- if (stat)
- s += "Rx";
- if (stat & CEC_RX_STATUS_OK)
- s += ", OK";
- if (stat & CEC_RX_STATUS_TIMEOUT)
- s += ", Timeout";
- if (stat & CEC_RX_STATUS_FEATURE_ABORT)
- s += ", Feature Abort";
- return s;
-}
-
-static std::string status2s(const struct cec_msg &msg)
-{
- std::string s;
-
- if (msg.tx_status)
- s = tx_status2s(msg);
- if (msg.rx_status) {
- if (!s.empty())
- s += ", ";
- s += rx_status2s(msg.rx_status);
- }
- return s;
-}
-
static void log_arg(const struct arg *arg, const char *arg_name, __u32 val)
{
unsigned i;
diff --git a/utils/cec-follower/cec-follower.cpp b/utils/cec-follower/cec-follower.cpp
index ca275dbb..9dbcd227 100644
--- a/utils/cec-follower/cec-follower.cpp
+++ b/utils/cec-follower/cec-follower.cpp
@@ -80,74 +80,6 @@ static void usage(void)
);
}
-static std::string tx_status2s(const struct cec_msg &msg)
-{
- std::string s;
- char num[4];
- unsigned stat = msg.tx_status;
-
- if (stat)
- s += "Tx";
- if (stat & CEC_TX_STATUS_OK)
- s += ", OK";
- if (stat & CEC_TX_STATUS_ARB_LOST) {
- sprintf(num, "%u", msg.tx_arb_lost_cnt);
- s += ", Arbitration Lost";
- if (msg.tx_arb_lost_cnt)
- s += " (" + std::string(num) + ")";
- }
- if (stat & CEC_TX_STATUS_NACK) {
- sprintf(num, "%u", msg.tx_nack_cnt);
- s += ", Not Acknowledged";
- if (msg.tx_nack_cnt)
- s += " (" + std::string(num) + ")";
- }
- if (stat & CEC_TX_STATUS_LOW_DRIVE) {
- sprintf(num, "%u", msg.tx_low_drive_cnt);
- s += ", Low Drive";
- if (msg.tx_low_drive_cnt)
- s += " (" + std::string(num) + ")";
- }
- if (stat & CEC_TX_STATUS_ERROR) {
- sprintf(num, "%u", msg.tx_error_cnt);
- s += ", Error";
- if (msg.tx_error_cnt)
- s += " (" + std::string(num) + ")";
- }
- if (stat & CEC_TX_STATUS_MAX_RETRIES)
- s += ", Max Retries";
- return s;
-}
-
-static std::string rx_status2s(unsigned stat)
-{
- std::string s;
-
- if (stat)
- s += "Rx";
- if (stat & CEC_RX_STATUS_OK)
- s += ", OK";
- if (stat & CEC_RX_STATUS_TIMEOUT)
- s += ", Timeout";
- if (stat & CEC_RX_STATUS_FEATURE_ABORT)
- s += ", Feature Abort";
- return s;
-}
-
-std::string status2s(const struct cec_msg &msg)
-{
- std::string s;
-
- if (msg.tx_status)
- s = tx_status2s(msg);
- if (msg.rx_status) {
- if (!s.empty())
- s += ", ";
- s += rx_status2s(msg.rx_status);
- }
- return s;
-}
-
void sad_encode(const struct short_audio_desc *sad, __u32 *descriptor)
{
__u8 b1, b2, b3 = 0;
diff --git a/utils/common/cec-info.cpp b/utils/common/cec-info.cpp
index b2fe933d..00cd6c16 100644
--- a/utils/common/cec-info.cpp
+++ b/utils/common/cec-info.cpp
@@ -279,6 +279,74 @@ std::string dev_feat2s(unsigned feat, const std::string &prefix)
return s;
}
+static std::string tx_status2s(const struct cec_msg &msg)
+{
+ std::string s;
+ char num[4];
+ unsigned stat = msg.tx_status;
+
+ if (stat)
+ s += "Tx";
+ if (stat & CEC_TX_STATUS_OK)
+ s += ", OK";
+ if (stat & CEC_TX_STATUS_ARB_LOST) {
+ sprintf(num, "%u", msg.tx_arb_lost_cnt);
+ s += ", Arbitration Lost";
+ if (msg.tx_arb_lost_cnt)
+ s += " (" + std::string(num) + ")";
+ }
+ if (stat & CEC_TX_STATUS_NACK) {
+ sprintf(num, "%u", msg.tx_nack_cnt);
+ s += ", Not Acknowledged";
+ if (msg.tx_nack_cnt)
+ s += " (" + std::string(num) + ")";
+ }
+ if (stat & CEC_TX_STATUS_LOW_DRIVE) {
+ sprintf(num, "%u", msg.tx_low_drive_cnt);
+ s += ", Low Drive";
+ if (msg.tx_low_drive_cnt)
+ s += " (" + std::string(num) + ")";
+ }
+ if (stat & CEC_TX_STATUS_ERROR) {
+ sprintf(num, "%u", msg.tx_error_cnt);
+ s += ", Error";
+ if (msg.tx_error_cnt)
+ s += " (" + std::string(num) + ")";
+ }
+ if (stat & CEC_TX_STATUS_MAX_RETRIES)
+ s += ", Max Retries";
+ return s;
+}
+
+static std::string rx_status2s(unsigned stat)
+{
+ std::string s;
+
+ if (stat)
+ s += "Rx";
+ if (stat & CEC_RX_STATUS_OK)
+ s += ", OK";
+ if (stat & CEC_RX_STATUS_TIMEOUT)
+ s += ", Timeout";
+ if (stat & CEC_RX_STATUS_FEATURE_ABORT)
+ s += ", Feature Abort";
+ return s;
+}
+
+std::string status2s(const struct cec_msg &msg)
+{
+ std::string s;
+
+ if (msg.tx_status)
+ s = tx_status2s(msg);
+ if (msg.rx_status) {
+ if (!s.empty())
+ s += ", ";
+ s += rx_status2s(msg.rx_status);
+ }
+ return s;
+}
+
void cec_driver_info(const struct cec_caps &caps,
const struct cec_log_addrs &laddrs, __u16 phys_addr)
{
diff --git a/utils/common/cec-info.h b/utils/common/cec-info.h
index 18f2b94a..a086ece0 100644
--- a/utils/common/cec-info.h
+++ b/utils/common/cec-info.h
@@ -21,6 +21,7 @@ const char *vendor2s(unsigned vendor);
std::string all_dev_types2s(unsigned types);
std::string rc_src_prof2s(unsigned prof, const std::string &prefix);
std::string dev_feat2s(unsigned feat, const std::string &prefix);
+std::string status2s(const struct cec_msg &msg);
void cec_driver_info(const struct cec_caps &caps,
const struct cec_log_addrs &laddrs, __u16 phys_addr);
diff --git a/utils/common/cec-log.cpp b/utils/common/cec-log.cpp
index b115449e..9ac59431 100644
--- a/utils/common/cec-log.cpp
+++ b/utils/common/cec-log.cpp
@@ -12,80 +12,13 @@
#include <string>
#include <linux/cec-funcs.h>
#include "cec-htng-funcs.h"
+#include "cec-info.h"
#define CEC_MAX_ARGS 16
#define xstr(s) str(s)
#define str(s) #s
-static std::string tx_status2s(const struct cec_msg &msg)
-{
- std::string s;
- char num[4];
- unsigned stat = msg.tx_status;
-
- if (stat)
- s += "Tx";
- if (stat & CEC_TX_STATUS_OK)
- s += ", OK";
- if (stat & CEC_TX_STATUS_ARB_LOST) {
- sprintf(num, "%u", msg.tx_arb_lost_cnt);
- s += ", Arbitration Lost";
- if (msg.tx_arb_lost_cnt)
- s += " (" + std::string(num) + ")";
- }
- if (stat & CEC_TX_STATUS_NACK) {
- sprintf(num, "%u", msg.tx_nack_cnt);
- s += ", Not Acknowledged";
- if (msg.tx_nack_cnt)
- s += " (" + std::string(num) + ")";
- }
- if (stat & CEC_TX_STATUS_LOW_DRIVE) {
- sprintf(num, "%u", msg.tx_low_drive_cnt);
- s += ", Low Drive";
- if (msg.tx_low_drive_cnt)
- s += " (" + std::string(num) + ")";
- }
- if (stat & CEC_TX_STATUS_ERROR) {
- sprintf(num, "%u", msg.tx_error_cnt);
- s += ", Error";
- if (msg.tx_error_cnt)
- s += " (" + std::string(num) + ")";
- }
- if (stat & CEC_TX_STATUS_MAX_RETRIES)
- s += ", Max Retries";
- return s;
-}
-
-static std::string rx_status2s(unsigned stat)
-{
- std::string s;
-
- if (stat)
- s += "Rx";
- if (stat & CEC_RX_STATUS_OK)
- s += ", OK";
- if (stat & CEC_RX_STATUS_TIMEOUT)
- s += ", Timeout";
- if (stat & CEC_RX_STATUS_FEATURE_ABORT)
- s += ", Feature Abort";
- return s;
-}
-
-static std::string status2s(const struct cec_msg &msg)
-{
- std::string s;
-
- if (msg.tx_status)
- s = tx_status2s(msg);
- if (msg.rx_status) {
- if (!s.empty())
- s += ", ";
- s += rx_status2s(msg.rx_status);
- }
- return s;
-}
-
struct cec_enum_values {
const char *type_name;
__u8 value;

Privacy Policy