summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dpmcgee@gmail.com>2011-11-14 15:26:56 -0600
committerDan McGee <dpmcgee@gmail.com>2011-11-14 15:26:56 -0600
commitf660bec1459cc7d55cffcf024381c9e8af4bc0f2 (patch)
tree3ba9b29dd30bbd8fd6f8b95c37819ad60758699e
parent5df32e5af7ab4520c7ed24484ad8024880f232e7 (diff)
downloadonkyocontrol-f660bec1459cc7d55cffcf024381c9e8af4bc0f2.tar.gz
onkyocontrol-f660bec1459cc7d55cffcf024381c9e8af4bc0f2.zip
Keep track of sent command and received message count
This is an easy stat to show in the USR1 signal output dump. Signed-off-by: Dan McGee <dpmcgee@gmail.com>
-rw-r--r--onkyo.c4
-rw-r--r--onkyo.h4
-rw-r--r--receiver.c6
3 files changed, 10 insertions, 4 deletions
diff --git a/onkyo.c b/onkyo.c
index 3a1c809..498165d 100644
--- a/onkyo.c
+++ b/onkyo.c
@@ -273,6 +273,8 @@ static void show_status(void)
r->power & ZONE3_POWER ? "ON" : "off");
printf("sleep: : zone2 (%ld) zone3 (%ld)\n",
r->zone2_sleep.tv_sec, r->zone3_sleep.tv_sec);
+ printf("cmds sent : %lu\n", r->cmds_sent);
+ printf("msgs received : %lu\n", r->msgs_received);
r = r->next;
}
@@ -1011,7 +1013,7 @@ int main(int argc, char *argv[])
}
/* check if we have a status message from the receivers */
if(FD_ISSET(r->fd, &readfds)) {
- char *msg = process_incoming_message(r->fd, logfd);
+ char *msg = process_incoming_message(r, logfd);
write_to_connections(r, msg);
free(msg);
}
diff --git a/onkyo.h b/onkyo.h
index 718ee5b..c986d26 100644
--- a/onkyo.h
+++ b/onkyo.h
@@ -58,6 +58,8 @@ struct receiver {
int fd;
int type;
enum power power;
+ unsigned long cmds_sent;
+ unsigned long msgs_received;
struct timeval last_cmd;
struct timeval zone2_sleep;
struct timeval zone3_sleep;
@@ -73,7 +75,7 @@ int write_to_connections(struct receiver *r, const char *msg);
void init_statuses(void);
void free_statuses(void);
int rcvr_send_command(struct receiver *rcvr);
-char *process_incoming_message(int serialfd, int logfd);
+char *process_incoming_message(struct receiver *rcvr, int logfd);
enum power initial_power_status(void);
void update_power_status(struct receiver *rcvr, const char *msg);
diff --git a/receiver.c b/receiver.c
index 01c9869..9e31525 100644
--- a/receiver.c
+++ b/receiver.c
@@ -101,6 +101,7 @@ int rcvr_send_command(struct receiver *rcvr)
}
/* set our last sent time */
gettimeofday(&(rcvr->last_cmd), NULL);
+ rcvr->cmds_sent++;
}
return 0;
}
@@ -540,13 +541,13 @@ void update_power_status(struct receiver *rcvr, const char *msg)
* @param logfd the fd used for logging raw status messages
* @return the human readable status message, must be freed
*/
-char *process_incoming_message(int serialfd, int logfd)
+char *process_incoming_message(struct receiver *rcvr, int logfd)
{
int size;
char *msg, *status = NULL;
/* get the output from the receiver */
- size = rcvr_handle_status(serialfd, &status);
+ size = rcvr_handle_status(rcvr->fd, &status);
if(size != -1) {
/* log the message if we have a logfd */
if(logfd > 0) {
@@ -554,6 +555,7 @@ char *process_incoming_message(int serialfd, int logfd)
}
/* parse the return and output a status message */
msg = parse_status(size, status);
+ rcvr->msgs_received++;
} else {
msg = strdup(rcvr_err);
}