[git:v4l-utils/master] cec-ctl: improve cec pin analyzer

2017-12-15 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: cec-ctl: improve cec pin analyzer
Author:  Hans Verkuil 
Date:Fri Dec 15 10:13:06 2017 +0100

Correctly detect and handle spurious bytes (more data after an EOM or
more than 16 bytes payload) and pauses in the bit stream (should reset
state to waiting for a start bit).

Signed-off-by: Hans Verkuil 

 utils/cec-ctl/cec-pin.cpp | 28 +---
 1 file changed, 21 insertions(+), 7 deletions(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=f34fff10facfe8da466468e3caab2552828eac17
diff --git a/utils/cec-ctl/cec-pin.cpp b/utils/cec-ctl/cec-pin.cpp
index 1f62a82c94c5..401890e5a967 100644
--- a/utils/cec-ctl/cec-pin.cpp
+++ b/utils/cec-ctl/cec-pin.cpp
@@ -113,6 +113,7 @@ static __u64 low_usecs;
 static unsigned int rx_bit;
 static __u8 byte;
 static bool eom;
+static bool eom_reached;
 static __u8 byte_cnt;
 static bool bcast;
 static bool cdc;
@@ -143,6 +144,7 @@ static void cec_pin_rx_start_bit_was_high(__u64 usecs, 
__u64 usecs_min, bool sho
rx_bit = 0;
byte = 0;
eom = false;
+   eom_reached = false;
byte_cnt = 0;
bcast = false;
cdc = false;
@@ -188,6 +190,9 @@ static void cec_pin_rx_data_bit_was_high(bool is_high, 
__u64 ev_ts,
printf("%10.06f: data bit %d: total period too short (%.2f 
ms)\n",
ts, rx_bit, (low_usecs + usecs) / 1000.0);
 
+   if (usecs > CEC_TIM_DATA_BIT_TOTAL_MAX)
+   eom_reached = true;
+
bit = low_usecs < CEC_TIM_DATA_BIT_1_LOW_MAX + CEC_TIM_MARGIN;
if (rx_bit <= 7) {
byte |= bit << (7 - rx_bit);
@@ -206,9 +211,10 @@ static void cec_pin_rx_data_bit_was_high(bool is_high, 
__u64 ev_ts,
s = find_cdc_opcode_name(byte);
}
if (show)
-   printf("%10.06f: rx 0x%02x%s%s%s%s\n", ts, byte,
+   printf("%10.06f: rx 0x%02x%s%s%s%s%s\n", ts, byte,
   eom ? " EOM" : "", (bcast ^ bit) ? " NACK" : " 
ACK",
   bcast ? " (broadcast)" : "",
+  eom_reached ? " (spurious byte)" : "",
   s.c_str());
if (show_info && show)
printf("\n");
@@ -216,16 +222,25 @@ static void cec_pin_rx_data_bit_was_high(bool is_high, 
__u64 ev_ts,
if (byte_cnt == 1 && byte == CEC_MSG_CDC_MESSAGE)
cdc = true;
byte_cnt++;
+   if (byte_cnt >= CEC_MAX_MSG_SIZE)
+   eom_reached = true;
}
rx_bit++;
+   if (usecs > CEC_TIM_DATA_BIT_TOTAL_MAX) {
+   if (show)
+   printf("\n");
+   eom_reached = false;
+   state = is_high ? CEC_ST_IDLE : CEC_ST_RECEIVE_START_BIT;
+   return;
+   }
if (rx_bit == 10) {
if ((!eom && ack) && low_usecs + usecs_min > 
CEC_TIM_DATA_BIT_TOTAL_MAX && show)
printf("%10.06f: data bit %d: total period too long 
(%.2f ms)\n",
ts, rx_bit - 1, (low_usecs + usecs_min) / 
1000.0);
-   if (eom || is_high || low_usecs + usecs_min > 
CEC_TIM_DATA_BIT_TOTAL_MAX)
+   if (eom)
+   eom_reached = true;
+   if (is_high || low_usecs + usecs_min > 
CEC_TIM_DATA_BIT_TOTAL_MAX)
state = is_high ? CEC_ST_IDLE : 
CEC_ST_RECEIVE_START_BIT;
-   if (state == CEC_ST_IDLE && show)
-   printf("\n");
rx_bit = 0;
byte = 0;
eom = false;
@@ -292,6 +307,7 @@ static void cec_pin_debug(__u64 ev_ts, __u64 usecs, bool 
was_high, bool is_high,
 
switch (state) {
case CEC_ST_RECEIVE_START_BIT:
+   eom_reached = false;
if (was_high)
cec_pin_rx_start_bit_was_high(usecs, usecs_min, show);
else
@@ -306,13 +322,11 @@ static void cec_pin_debug(__u64 ev_ts, __u64 usecs, bool 
was_high, bool is_high,
break;
 
case CEC_ST_IDLE:
+   eom_reached = false;
if (!is_high)
state = CEC_ST_RECEIVE_START_BIT;
break;
}
-
-   if (was_high && is_high)
-   state = CEC_ST_IDLE;
 }
 
 void log_event_pin(bool is_high, __u64 ev_ts, bool show)

___
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

[git:v4l-utils/master] cec-ctl: improve cec pin analyzer code

2017-12-03 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: cec-ctl: improve cec pin analyzer code
Author:  Hans Verkuil 
Date:Sun Dec 3 16:44:48 2017 +0100

Greatly improve the cec pin analyzer code, making the output
more readable and fixing various bugs.

Signed-off-by: Hans Verkuil 

 utils/cec-ctl/cec-ctl.cpp |  42 --
 utils/cec-ctl/cec-pin.cpp | 138 ++
 2 files changed, 102 insertions(+), 78 deletions(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=288451ca1d032f14f09dcd1d2a7c6a15e04204bc
diff --git a/utils/cec-ctl/cec-ctl.cpp b/utils/cec-ctl/cec-ctl.cpp
index e442431b3e3e..5b1873a12194 100644
--- a/utils/cec-ctl/cec-ctl.cpp
+++ b/utils/cec-ctl/cec-ctl.cpp
@@ -1329,6 +1329,26 @@ static inline unsigned response_time_ms(const struct 
cec_msg )
return 0;
 }
 
+static void generate_eob_event(__u64 ts, FILE *fstore)
+{
+   if (!eob_ts || eob_ts_max >= ts)
+   return;
+
+   struct cec_event ev_eob = {
+   eob_ts,
+   CEC_EVENT_PIN_CEC_HIGH
+   };
+
+   if (fstore) {
+   fprintf(fstore, "%llu.%09llu %d\n",
+   ev_eob.ts / 10, ev_eob.ts % 10,
+   ev_eob.event - CEC_EVENT_PIN_CEC_LOW);
+   fflush(fstore);
+   }
+   if (fstore != stdout)
+   log_event(ev_eob);
+}
+
 static void monitor(struct node , __u32 monitor_time, const char 
*store_pin)
 {
__u32 monitor = CEC_MODE_MONITOR;
@@ -1437,37 +1457,23 @@ static void monitor(struct node , __u32 
monitor_time, const char *store_pin
ev.event == CEC_EVENT_PIN_HPD_LOW ||
ev.event == CEC_EVENT_PIN_HPD_HIGH)
pin_event = true;
+   generate_eob_event(ev.ts, fstore);
if (pin_event && fstore) {
fprintf(fstore, "%llu.%09llu %d\n",
ev.ts / 10, ev.ts % 10,
ev.event - CEC_EVENT_PIN_CEC_LOW);
fflush(fstore);
}
-   if ((!pin_event || options[OptMonitorPin]) &&
-   fstore != stdout)
+   if ((!pin_event || options[OptMonitorPin]) && fstore != 
stdout)
log_event(ev);
}
-   if (!pin_event && eob_ts && fstore != stdout) {
+   if (eob_ts) {
struct timespec ts;
__u64 ts64;
 
clock_gettime(CLOCK_MONOTONIC, );
ts64 = ts.tv_sec * 10ULL + ts.tv_nsec;
-   if (ts64 >= eob_ts_max) {
-   struct cec_event ev = {
-   eob_ts,
-   CEC_EVENT_PIN_CEC_HIGH
-   };
-
-   if (fstore) {
-   fprintf(fstore, "%llu.%09llu %d\n",
-   ev.ts / 10, ev.ts % 
10,
-   ev.event - 
CEC_EVENT_PIN_CEC_LOW);
-   fflush(fstore);
-   }
-   if (options[OptMonitorPin])
-   log_event(ev);
-   }
+   generate_eob_event(ts64, fstore);
}
}
if (fstore && fstore != stdout)
diff --git a/utils/cec-ctl/cec-pin.cpp b/utils/cec-ctl/cec-pin.cpp
index 3b7f1d95c514..97f70a5e1f00 100644
--- a/utils/cec-ctl/cec-pin.cpp
+++ b/utils/cec-ctl/cec-pin.cpp
@@ -47,19 +47,19 @@
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 
-static const char *find_opcode_name(__u8 opcode)
+static std::string find_opcode_name(__u8 opcode)
 {
for (unsigned i = 0; i < ARRAY_SIZE(msgtable); i++)
if (msgtable[i].opcode == opcode)
-   return msgtable[i].name;
+   return std::string(": ") + msgtable[i].name;
return "";
 }
 
-static const char *find_cdc_opcode_name(__u8 opcode)
+static std::string find_cdc_opcode_name(__u8 opcode)
 {
for (unsigned i = 0; i < ARRAY_SIZE(cdcmsgtable); i++)
if (cdcmsgtable[i].opcode == opcode)
-   return cdcmsgtable[i].name;
+   return std::string(": ") + cdcmsgtable[i].name;
return "";
 }
 
@@ -120,18 +120,24 @@ static bool cdc;
 static void cec_pin_rx_start_bit_was_high(__u64 usecs, __u64 usecs_min)
 {
if (low_usecs + usecs_min >