[tuxdroid-svn] r350 - daemon/trunk/libs
Status: Beta
Brought to you by:
ks156
From: neimad <c2m...@c2...> - 2007-06-05 20:00:14
|
Author: neimad Date: 2007-06-05 22:00:10 +0200 (Tue, 05 Jun 2007) New Revision: 350 Modified: daemon/trunk/libs/USBDaemon_status_table.c daemon/trunk/libs/USBDaemon_tcp_server.c daemon/trunk/libs/USBDaemon_tcp_server.h Log: * Defined macro tcp_frame_zero() to zero a TCP frame and use it everywhere where there was a loop to do that. The macro takes a *pointer* to a TCP frame, which was not strictly necessary, since such a frame is a uchar array, but this may change. * Added the zeroing of the TCP frame in send_daemon_disconnected(), for consistency's sake. Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2007-06-05 19:37:06 UTC (rev 349) +++ daemon/trunk/libs/USBDaemon_status_table.c 2007-06-05 20:00:10 UTC (rev 350) @@ -145,10 +145,8 @@ void update_system_status_table(const unsigned char *new_status) { tcp_frame_t tcp_frame; - unsigned char i; - for (i = 0; i < sizeof(tcp_frame); i++) - tcp_frame[i] = '\0'; + tcp_frame_zero(&tcp_frame); tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; @@ -296,10 +294,8 @@ void pong_event(unsigned char pong_number, unsigned char pong_received) { tcp_frame_t tcp_frame; - unsigned char i; - for (i = 0; i < sizeof(tcp_frame); i++) - tcp_frame[i] = '\0'; + tcp_frame_zero(&tcp_frame); tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; @@ -320,10 +316,8 @@ void portb_changed(unsigned char new_value) { tcp_frame_t tcp_frame; - unsigned char i; - for (i = 0; i < sizeof(tcp_frame); i++) - tcp_frame[i] = '\0'; + tcp_frame_zero(&tcp_frame); tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; @@ -395,10 +389,8 @@ void portc_changed(unsigned char new_value) { tcp_frame_t tcp_frame; - unsigned char i; - for (i = 0; i < sizeof(tcp_frame); i++) - tcp_frame[i] = '\0'; + tcp_frame_zero(&tcp_frame); tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; @@ -444,10 +436,8 @@ void portd_changed(unsigned char new_value) { tcp_frame_t tcp_frame; - unsigned char i; - for (i = 0; i < sizeof(tcp_frame); i++) - tcp_frame[i] = '\0'; + tcp_frame_zero(&tcp_frame); tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; @@ -529,10 +519,8 @@ void sensors1_changed(unsigned char new_value) { tcp_frame_t tcp_frame; - unsigned char i; - for (i = 0; i < sizeof(tcp_frame); i++) - tcp_frame[i] = '\0'; + tcp_frame_zero(&tcp_frame); tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; @@ -605,10 +593,8 @@ unsigned char new_light_mode) { tcp_frame_t tcp_frame; - unsigned char i; - for (i = 0; i < sizeof(tcp_frame); i++) - tcp_frame[i] = '\0'; + tcp_frame_zero(&tcp_frame); tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; @@ -635,10 +621,8 @@ unsigned char wings_position) { tcp_frame_t tcp_frame; - unsigned char i; - for (i = 0; i < sizeof(tcp_frame); i++) - tcp_frame[i] = '\0'; + tcp_frame_zero(&tcp_frame); tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; @@ -678,10 +662,8 @@ void position2_changed(unsigned char spin_position) { tcp_frame_t tcp_frame; - unsigned char i; - for (i = 0; i < sizeof(tcp_frame); i++) - tcp_frame[i] = '\0'; + tcp_frame_zero(&tcp_frame); tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; Modified: daemon/trunk/libs/USBDaemon_tcp_server.c =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.c 2007-06-05 19:37:06 UTC (rev 349) +++ daemon/trunk/libs/USBDaemon_tcp_server.c 2007-06-05 20:00:10 UTC (rev 350) @@ -252,6 +252,8 @@ { tcp_frame_t data; + tcp_frame_zero(&data); + data[0] = SOURCE_SUB_DAEMON; data[1] = SS_DEFAULT; data[2] = DATA_TP_CMD; Modified: daemon/trunk/libs/USBDaemon_tcp_server.h =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.h 2007-06-05 19:37:06 UTC (rev 349) +++ daemon/trunk/libs/USBDaemon_tcp_server.h 2007-06-05 20:00:10 UTC (rev 350) @@ -29,6 +29,7 @@ #include <netinet/in.h> #include <sys/un.h> #include <stdio.h> +#include <string.h> /*_____________________ D E F I N E S ______________________________________*/ #define TUX_SERVER_MAXLINES 4096 @@ -49,6 +50,9 @@ #define TCP_FRAME_SIZE 16 typedef unsigned char tcp_frame_t[TCP_FRAME_SIZE]; +#define tcp_frame_zero(frame_ptr) \ + memset(*(frame_ptr), '\0', sizeof(tcp_frame_t)) + /*_____________________ V A R I A B L E S ___________________________________*/ extern int tcp_clients_handle[]; extern unsigned char tcp_clients_count; |