[tuxdroid-svn] r240 - svnlook: warning: cannot set LC_CTYPE locale svnlook: warning: environment va
Status: Beta
Brought to you by:
ks156
From: svnlook:warning@affinitic.be:cannot s. L. l. <c2m...@c2...> - 2007-04-11 19:39:02
|
Author: svnlook: warning: cannot set LC_CTYPE locale Date: svnlook: warning: environment variable LANG is EN New Revision: 240 Modified: daemon/trunk/libs/USBDaemon_command_tux.c daemon/trunk/libs/USBDaemon_status_table.c daemon/trunk/libs/USBDaemon_tcp_server.c daemon/trunk/libs/USBDaemon_tcp_server.h Log: neimad 2007-04-11 21:38:19 +0200 (Wed, 11 Apr 2007) 695 * Defined type tcp_frame_t, which is for now merely a typedef on unsigned char [16]. Will need some more encapsulation (initialization function, for instance). * Removed the data/frame size parameter of most comm functions as it was always 16 (now sizeof(tcp_frame_t)). * Got rid of tcp_clients_table_size, which was meant to "optimize" somehow the iterations on the client handles array. In fact it was incremented but never decremented, and it won't be of any use with the upcoming select() patch anyway. * Unused client handles are -1, not 0, as 0 is theorically a valid file descriptor. Should have been in a separate patch, but I'm too tired to split that right now. svnlook: warning: cannot set LC_CTYPE locale svnlook: warning: environment variable LANG is EN svnlook: warning: please check that your locale name is correct Modified: daemon/trunk/libs/USBDaemon_command_tux.c =================================================================== --- daemon/trunk/libs/USBDaemon_command_tux.c 2007-04-11 19:31:41 UTC (rev 239) +++ daemon/trunk/libs/USBDaemon_command_tux.c 2007-04-11 19:38:19 UTC (rev 240) @@ -35,24 +35,25 @@ /************************************************************************** */ void commands_dispatcher( unsigned char client_id, /* Client source */ - unsigned char src_frame[16]) /* Source frame */ + tcp_frame_t src_frame) /* Source frame */ { unsigned char ACK_DP; /* daemon processing ack */ unsigned char data[12]; /* data part of source frame */ unsigned char result[12]; /* result data to return */ - unsigned char tcp_frame[16];/* tcp frame to send */ - unsigned char ack_dp_frame[16]; - unsigned char i; + tcp_frame_t tcp_frame; /* tcp frame to send */ + tcp_frame_t ack_dp_frame; + int i; unsigned char no_ack; no_ack = 0; /* Cut data part of source frame */ - for(i = 0; i < 12; i++) + for (i = 0; i < sizeof(tcp_frame_t) - 4; i++) { result[i] = 0; data[i] = src_frame[i + 4]; } + /* Make source header */ tcp_frame[0] = src_frame[0]; /* return source */ tcp_frame[1] = src_frame[1]; /* return sub source */ @@ -194,22 +195,26 @@ } /* Paste result treatement into tcp frame */ - for(i = 0; i < 12; i++) + for (i = 0; i < sizeof(tcp_frame_t) - 4; i++) tcp_frame[i + 4] = result[i]; + /* Send daemon processing ack to client */ - for(i = 0; i < 16; i++)ack_dp_frame[i] = 0; + for (i = 0; i < sizeof(tcp_frame_t); i++) + ack_dp_frame[i] = '\0'; + ack_dp_frame[0] = src_frame[0]; ack_dp_frame[1] = src_frame[1]; ack_dp_frame[2] = DATA_TP_ACK_DP; ack_dp_frame[3] = src_frame[3]; ack_dp_frame[4] = ACK_DP; - if(!no_ack) + + if (!no_ack) { - tcp_server_send_raw_to_client(client_id, ack_dp_frame, 16); + tcp_server_send_raw_to_client(client_id, ack_dp_frame); /* Send tcp frame to client */ if(ACK_DP == ACK_DP_OK) { - tcp_server_send_raw_to_client(client_id, tcp_frame, 16); + tcp_server_send_raw_to_client(client_id, tcp_frame); } } } @@ -221,23 +226,17 @@ /******************************************************************** */ /* sub_daemon_cmd_struct() */ /******************************************************************** */ -void sub_daemon_cmd_struct( - unsigned char data[], - unsigned char result[], - int id_client - ) +void sub_daemon_cmd_struct(unsigned char data[], unsigned char result[], + int id_client) { - unsigned char i; - int my_client_handle; - switch (data[0]) { case SUB_D_CMD_STRUC_DISCONNECT_CLIENT: pthread_mutex_lock(&tcp_mutex); /* Byte 2 equal id client to disconnect */ - if (tcp_clients_handle[data[1]] != 0) + if (tcp_clients_handle[data[1]] >= 0) { - tcp_clients_handle[data[1]] = 0; + tcp_clients_handle[data[1]] = -1; tcp_clients_count--; printf("TCP socket : Client %d is disconnected\n", data[1]); result[0] = ACK_CMD_OK; @@ -250,11 +249,10 @@ break; case SUB_D_CMD_STRUC_DISCONNECT_CLIENT_ME: pthread_mutex_lock(&tcp_mutex); - my_client_handle = tcp_clients_handle[id_client]; - tcp_clients_handle[id_client] = 0; + close(tcp_clients_handle[id_client]); + tcp_clients_handle[id_client] = -1; tcp_clients_count--; printf("TCP socket : Client %d is disconnected\n", id_client); - close(my_client_handle); result[0] = ACK_CMD_NO_ACK; pthread_mutex_unlock(&tcp_mutex); break; @@ -265,10 +263,14 @@ exit(0); break; case SUB_D_CMD_STRUC_DEFINE_CLIENT_NAME: - for(i = 0; i < 11; i++) - tcp_clients_name[id_client][i] = data[i + 1]; - result[0] = ACK_CMD_OK; - printf("Name of client %d is %s\n", id_client, tcp_clients_name[id_client]); + { + int i; + for (i = 0; i < 11; i++) + tcp_clients_name[id_client][i] = data[i + 1]; + result[0] = ACK_CMD_OK; + printf("Name of client %d is %s\n", id_client, + tcp_clients_name[id_client]); + } break; } } Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2007-04-11 19:31:41 UTC (rev 239) +++ daemon/trunk/libs/USBDaemon_status_table.c 2007-04-11 19:38:19 UTC (rev 240) @@ -103,10 +103,12 @@ /************************************************************************ */ void update_system_status_table(unsigned char new_status[4]) { - unsigned char tcp_frame[16]; + tcp_frame_t tcp_frame; unsigned char i; - for(i = 0;i < 16;i++)tcp_frame[i] = 0; + for (i = 0; i < sizeof(tcp_frame); i++) + tcp_frame[i] = '\0'; + tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; tcp_frame[2] = DATA_TP_RSP; @@ -119,7 +121,7 @@ RF_status = new_status[1]; tcp_frame[4] = DATA_STATUS_RF_CONNECTED; tcp_frame[5] = RF_status; - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } /* Command status change */ if(CMD_status != new_status[2]) @@ -191,7 +193,7 @@ unsigned char toggle; unsigned char check; unsigned char new_code; - unsigned char tcp_frame[16]; + tcp_frame_t tcp_frame; unsigned char i; code = new_status[1] & 0x3F; @@ -219,14 +221,18 @@ if(new_code) { printf("Remote code : %.2x\n", code); - for(i = 6;i < 16;i++)tcp_frame[i] = 0; + + for (i = 0; i < sizeof(tcp_frame); i++) + tcp_frame[i] = '\0'; + tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; tcp_frame[2] = DATA_TP_RSP; tcp_frame[3] = SUBDATA_TP_STATUS; tcp_frame[4] = DATA_STATUS_IR_CODE; tcp_frame[5] = code; - tcp_server_send_raw(tcp_frame, 16); + + tcp_server_send_raw(tcp_frame); } } @@ -235,10 +241,11 @@ /************************************************************************ */ void pong_event(unsigned char pong_number, unsigned char pong_received) { - unsigned char tcp_frame[16]; + tcp_frame_t tcp_frame; unsigned char i; - for(i = 0;i < 16;i++)tcp_frame[i] = 0; + for (i = 0; i < sizeof(tcp_frame); i++) + tcp_frame[i] = '\0'; tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; @@ -247,7 +254,8 @@ tcp_frame[4] = DATA_STATUS_PONG; tcp_frame[5] = pong_number; tcp_frame[6] = pong_received; - tcp_server_send_raw(tcp_frame, 16); + + tcp_server_send_raw(tcp_frame); } /************************************************************************ */ @@ -255,10 +263,11 @@ /************************************************************************ */ void portb_changed(unsigned char new_value) { - unsigned char tcp_frame[16]; + tcp_frame_t tcp_frame; unsigned char i; - for(i = 0;i < 16;i++)tcp_frame[i] = 0; + for (i = 0; i < sizeof(tcp_frame); i++) + tcp_frame[i] = '\0'; tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; @@ -279,7 +288,7 @@ printf("wings motor backward 1\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } /* spin motor backward */ if((portb.Byte & 0x02) != (new_value & 0x02)) @@ -295,7 +304,7 @@ printf("spin motor backward 1\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } /* spin motor forward */ if((portb.Byte & 0x04) != (new_value & 0x04)) @@ -311,7 +320,7 @@ printf("spin motor forward 1\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } /* mouth open position motor */ if((portb.Byte & 0x08) != (new_value & 0x08)) @@ -329,7 +338,7 @@ printf("mouth open position 1\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } /* mouth close position motor */ if((portb.Byte & 0x10) != (new_value & 0x10)) @@ -345,7 +354,7 @@ printf("mouth close position 1\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } /* charger inhibit signal */ if((portb.Byte & 0x40) != (new_value & 0x40)) @@ -361,7 +370,7 @@ printf("charger inhibit signal 1\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } portb.Byte = new_value; } @@ -371,15 +380,17 @@ /************************************************************************ */ void portc_changed(unsigned char new_value) { - unsigned char tcp_frame[16]; + tcp_frame_t tcp_frame; unsigned char i; - for(i = 0;i < 16;i++)tcp_frame[i] = 0; + for (i = 0; i < sizeof(tcp_frame); i++) + tcp_frame[i] = '\0'; tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; tcp_frame[2] = DATA_TP_RSP; tcp_frame[3] = SUBDATA_TP_STATUS; + /* wings position switch */ if((portc.Byte & 0x02) != (new_value & 0x02)) { @@ -394,7 +405,7 @@ printf("wings position switch 1\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } /* right blue led */ if((portc.Byte & 0x04) != (new_value & 0x04)) @@ -410,7 +421,7 @@ printf("right blue led on\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } /* left blue led */ if((portc.Byte & 0x08) != (new_value & 0x08)) @@ -426,7 +437,7 @@ printf("left blue led on\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } portc.Byte = new_value; } @@ -436,15 +447,17 @@ /************************************************************************ */ void portd_changed(unsigned char new_value) { - unsigned char tcp_frame[16]; + tcp_frame_t tcp_frame; unsigned char i; - for(i = 0;i < 16;i++)tcp_frame[i] = 0; + for (i = 0; i < sizeof(tcp_frame); i++) + tcp_frame[i] = '\0'; tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; tcp_frame[2] = DATA_TP_RSP; tcp_frame[3] = SUBDATA_TP_STATUS; + /* head motor for eyes */ if((portd.Byte & 0x01) != (new_value & 0x01)) { @@ -459,7 +472,7 @@ printf("head motor for eyes 1\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } /* head motor for mouth */ if((portd.Byte & 0x02) != (new_value & 0x02)) @@ -475,7 +488,7 @@ printf("head motor for mouth 1\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16);; + tcp_server_send_raw(tcp_frame); } /* spin position switch */ if((portd.Byte & 0x08) != (new_value & 0x08)) @@ -491,7 +504,7 @@ printf("spin position switch 1\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } /* wings motor forward */ if((portd.Byte & 0x10) != (new_value & 0x10)) @@ -507,7 +520,7 @@ printf("wings motor forward 1\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } /* IR led */ if((portd.Byte & 0x20) != (new_value & 0x20)) @@ -523,7 +536,7 @@ printf("IR led 1\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } /* eyes open position switch */ if((portd.Byte & 0x40) != (new_value & 0x40)) @@ -539,7 +552,7 @@ printf("eyes open position switch 1\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } /* eyes closed position switch */ if((portd.Byte & 0x80) != (new_value & 0x80)) @@ -555,7 +568,7 @@ printf("eyes closed position switch 1\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } portd.Byte = new_value; } @@ -565,15 +578,17 @@ /************************************************************************ */ void sensors1_changed(unsigned char new_value) { - unsigned char tcp_frame[16]; + tcp_frame_t tcp_frame; unsigned char i; - for(i = 0;i < 16;i++)tcp_frame[i] = 0; + for (i = 0; i < sizeof(tcp_frame); i++) + tcp_frame[i] = '\0'; tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; tcp_frame[2] = DATA_TP_RSP; tcp_frame[3] = SUBDATA_TP_STATUS; + /* Left wing push */ if((sensors1.Byte & 0x01) != (new_value & 0x01)) { @@ -588,7 +603,7 @@ printf("Left wing button Down\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } /* Right wing push */ if((sensors1.Byte & 0x02) != (new_value & 0x02)) @@ -604,7 +619,7 @@ printf("Right wing button Down\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } /* power plug insertion switch */ if((sensors1.Byte & 0x04) != (new_value & 0x04)) @@ -620,7 +635,7 @@ printf("power plug insertion switch off\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } /* Head push */ if((sensors1.Byte & 0x08) != (new_value & 0x08)) @@ -636,7 +651,7 @@ printf("Head button Down\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } /* Led charger */ if((sensors1.Byte & 0x10) != (new_value & 0x10)) @@ -652,7 +667,7 @@ printf("Charger led 0\n"); tcp_frame[5] = 0; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } /* mute status */ if((sensors1.Byte & 0x80) != (new_value & 0x80)) @@ -668,7 +683,7 @@ printf("mute status on\n"); tcp_frame[5] = 1; } - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } sensors1.Byte = new_value; } @@ -681,10 +696,11 @@ unsigned char new_value_low, unsigned char new_light_mode) { - unsigned char tcp_frame[16]; + tcp_frame_t tcp_frame; unsigned char i; - for(i = 0;i < 16;i++)tcp_frame[i] = 0; + for (i = 0; i < sizeof(tcp_frame); i++) + tcp_frame[i] = '\0'; tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; @@ -692,9 +708,11 @@ tcp_frame[3] = SUBDATA_TP_STATUS; tcp_frame[4] = DATA_STATUS_LIGHT_LEVEL; + sensors2.level_light_high.Byte = new_value_high; sensors2.level_light_low.Byte = new_value_low; sensors2.light_mode.Byte = new_light_mode; + tcp_frame[5] = new_value_high; tcp_frame[6] = new_value_low; } @@ -707,10 +725,11 @@ unsigned char mouth_position, unsigned char wings_position) { - unsigned char tcp_frame[16]; + tcp_frame_t tcp_frame; unsigned char i; - for(i = 0;i < 16;i++)tcp_frame[i] = 0; + for (i = 0; i < sizeof(tcp_frame); i++) + tcp_frame[i] = '\0'; tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; @@ -722,21 +741,21 @@ position1.eyes_position.Byte = eyes_position; tcp_frame[4] = DATA_STATUS_EYES_POSITION_COUNTER; tcp_frame[5] = eyes_position; - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } if(position1.mouth_position.Byte != mouth_position) { position1.mouth_position.Byte = mouth_position; tcp_frame[4] = DATA_STATUS_MOUTH_POSITION_COUNTER; tcp_frame[5] = mouth_position; - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } if(position1.wings_position.Byte != wings_position) { position1.wings_position.Byte = wings_position; tcp_frame[4] = DATA_STATUS_WINGS_POSITION_COUNTER; tcp_frame[5] = wings_position; - tcp_server_send_raw(tcp_frame, 16); + tcp_server_send_raw(tcp_frame); } } @@ -745,10 +764,11 @@ /************************************************************************ */ void position2_changed(unsigned char spin_position) { - unsigned char tcp_frame[16]; + tcp_frame_t tcp_frame; unsigned char i; - for(i = 0; i < 16; i++)tcp_frame[i] = 0; + for (i = 0; i < sizeof(tcp_frame); i++) + tcp_frame[i] = '\0'; tcp_frame[0] = SOURCE_TUX; tcp_frame[1] = SS_DEFAULT; @@ -758,5 +778,6 @@ tcp_frame[4] = DATA_STATUS_SPIN_POSITION_COUNTER; position2.Byte = spin_position; tcp_frame[5] = spin_position; - tcp_server_send_raw(tcp_frame, 16); + + tcp_server_send_raw(tcp_frame); } Modified: daemon/trunk/libs/USBDaemon_tcp_server.c =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.c 2007-04-11 19:31:41 UTC (rev 239) +++ daemon/trunk/libs/USBDaemon_tcp_server.c 2007-04-11 19:38:19 UTC (rev 240) @@ -31,9 +31,9 @@ #include "USBDaemon_status_table.h" #include "USBDaemon_tcp_server.h" /*_____________________ V A R I A B L E S __________________________________*/ -int tcp_server_handle; -int tcp_clients_handle[TUX_MAX_TCP_CLIENTS]; -unsigned char tcp_clients_table_size = 0; +int tcp_server_handle = -1; +int tcp_clients_handle[TUX_MAX_TCP_CLIENTS] = + { [0 ... TUX_MAX_TCP_CLIENTS - 1] = -1 }; unsigned char tcp_clients_count = 0; client_name_t tcp_clients_name[TUX_MAX_TCP_CLIENTS]; struct sockaddr_in tcp_server_sockaddr; @@ -49,7 +49,7 @@ { int tmp_client; int client_added; - unsigned char datas_recv[16]; + tcp_frame_t datas_recv; int i; int rt_read; int tmp_handle; @@ -95,68 +95,59 @@ fcntl(tcp_server_handle, F_SETFL, O_NONBLOCK); while(tcp_server_handle) { - /* Demande de connection d'un client */ + /* Client connection */ pthread_mutex_lock(&tcp_mutex); - if ((tmp_client = accept(tcp_server_handle, (struct sockaddr *) NULL, NULL)) >= 0) + tmp_client = accept(tcp_server_handle, (struct sockaddr *)NULL, NULL); + if (tmp_client >= 0) { fcntl(tmp_client, F_SETFL, O_NONBLOCK); printf("TCP socket : accept OK\n"); + client_added = 0; - if (tcp_clients_table_size == TUX_MAX_TCP_CLIENTS - 1) + for (i = 0; i < TUX_MAX_TCP_CLIENTS; i++) { - printf("TCP socket : client not accepted : client table is full\n"); - close(tmp_handle); - } - for(i = 0;i < tcp_clients_table_size;i++) - { - if(tcp_clients_handle[i] == 0) + if (tcp_clients_handle[i] < 0) { tcp_clients_handle[i] = tmp_client; - client_added = 1; tcp_clients_count++; + client_added = 1; break; } } - if(!client_added) + + if (!client_added) { - tcp_clients_table_size++; - tcp_clients_handle[tcp_clients_table_size-1] = tmp_client; - tcp_clients_count++; + printf("TCP socket : client not accepted : client table is full\n"); + close(tmp_handle); } } - /* Reception de messages venant des clients */ - if(tcp_clients_table_size > 0) + + /* Receive messages from clients */ + for (i = 0; i < TUX_MAX_TCP_CLIENTS; i++) { - for(i = 0;i < tcp_clients_table_size;i++) + if (tcp_clients_handle[i] >= 0) { - if(tcp_clients_handle[i] > 0) + rt_read = recv(tcp_clients_handle[i], datas_recv, sizeof(datas_recv), 0); + if (rt_read == 0) { - /*rt_read = read(tcp_clients_handle[i], datas_recv, 16); */ - rt_read = recv(tcp_clients_handle[i], datas_recv, 16, 0); - if(rt_read < 0) - { - /* No datas */ - } - else if(rt_read == 0) - { - tmp_handle = tcp_clients_handle[i]; - tcp_clients_handle[i] = 0; - tcp_clients_count--; - close(tmp_handle); - printf("TCP socket : Client %d is disconnected READ\n", i); - } - else - { - pthread_mutex_unlock(&tcp_mutex); - commands_dispatcher((unsigned char)i, datas_recv); - pthread_mutex_lock(&tcp_mutex); - } + close(tcp_clients_handle[i]); + tcp_clients_handle[i] = -1; + tcp_clients_count--; + printf("TCP socket : Client %d is disconnected READ\n", i); } - pthread_mutex_unlock(&tcp_mutex); - usleep(1000); - pthread_mutex_lock(&tcp_mutex); + else if (rt_read > 0) + { + pthread_mutex_unlock(&tcp_mutex); + commands_dispatcher((unsigned char)i, datas_recv); + pthread_mutex_lock(&tcp_mutex); + } } + + pthread_mutex_unlock(&tcp_mutex); + usleep(1000); + pthread_mutex_lock(&tcp_mutex); } + pthread_mutex_unlock(&tcp_mutex); usleep(1000); } @@ -165,68 +156,59 @@ /************************************************************************ */ /* tcp_server_send_raw() */ /************************************************************************ */ -void tcp_server_send_raw( - unsigned char datas[64], - unsigned char datas_count) +void tcp_server_send_raw(const tcp_frame_t data) { int i; - int tmp_handle; pthread_mutex_lock(&tcp_mutex); + if (tux_tcp_status == TUX_TCP_STATUS_DOWN) { pthread_mutex_unlock(&tcp_mutex); return; } - if(tcp_clients_table_size == 0) + + for (i = 0; i < TUX_MAX_TCP_CLIENTS; i++) { - pthread_mutex_unlock(&tcp_mutex); - return; - } - for(i = 0;i < tcp_clients_table_size;i++) - { - if(tcp_clients_handle[i] > 0) + if (tcp_clients_handle[i] < 0) + continue; + + if (send(tcp_clients_handle[i], data, sizeof(tcp_frame_t), 0) == 0) { - if(send(tcp_clients_handle[i], datas, datas_count, 0) == 0) - { - tmp_handle = tcp_clients_handle[i]; - tcp_clients_handle[i] = 0; - printf("TCP socket : Client %d is disconnected WRITE ALL\n", i); - tcp_clients_count--; - close(tmp_handle); - } + close(tcp_clients_handle[i]); + tcp_clients_handle[i] = -1; + tcp_clients_count--; + printf("TCP socket : Client %d is disconnected WRITE ALL\n", i); } } + pthread_mutex_unlock(&tcp_mutex); } /************************************************************************ */ /* tcp_server_send_raw_to_client() */ /************************************************************************ */ -void tcp_server_send_raw_to_client( - int client_index, - unsigned char datas[64], - unsigned char datas_count) +void tcp_server_send_raw_to_client(int client_index, const tcp_frame_t data) { - int tmp_handle; - pthread_mutex_lock(&tcp_mutex); + if (tux_tcp_status == TUX_TCP_STATUS_DOWN) { pthread_mutex_unlock(&tcp_mutex); return; } - if(tcp_clients_handle[client_index] != 0) + + if (tcp_clients_handle[client_index] >= 0) { - if(send(tcp_clients_handle[client_index], datas, datas_count, 0) == 0) + if (send(tcp_clients_handle[client_index], data, sizeof(tcp_frame_t), 0) == 0) { - tmp_handle = tcp_clients_handle[client_index]; - tcp_clients_handle[client_index] = 0; - printf("TCP socket : Client %d is disconnected WRITE client\n", client_index); + close(tcp_clients_handle[client_index]); + tcp_clients_handle[client_index] = -1; tcp_clients_count--; - close(tmp_handle); + printf("TCP socket : Client %d is disconnected WRITE client\n", client_index); } } + pthread_mutex_unlock(&tcp_mutex); } @@ -235,15 +217,19 @@ /************************************************************************ */ void send_daemon_disconnected() { - unsigned char send_data[64]; - send_data[0] = SOURCE_SUB_DAEMON; - send_data[1] = SS_DEFAULT; - send_data[2] = DATA_TP_CMD; - send_data[3] = SUBDATA_TP_STRUCT; - send_data[4] = SUB_D_CMD_STRUC_DISCONNECT_CLIENT; - tcp_server_send_raw(send_data, 16); + tcp_frame_t data; + + data[0] = SOURCE_SUB_DAEMON; + data[1] = SS_DEFAULT; + data[2] = DATA_TP_CMD; + data[3] = SUBDATA_TP_STRUCT; + data[4] = SUB_D_CMD_STRUC_DISCONNECT_CLIENT; + + tcp_server_send_raw(data); + pthread_mutex_lock(&tcp_mutex); close(tcp_server_handle); pthread_mutex_unlock(&tcp_mutex); + usleep(10000); } Modified: daemon/trunk/libs/USBDaemon_tcp_server.h =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.h 2007-04-11 19:31:41 UTC (rev 239) +++ daemon/trunk/libs/USBDaemon_tcp_server.h 2007-04-11 19:38:19 UTC (rev 240) @@ -38,6 +38,10 @@ /*_____________________ T Y P E _ D E F ____________________________________*/ #define CLIENT_NAME_LEN 15 typedef unsigned char client_name_t[CLIENT_NAME_LEN + 1]; + +#define TCP_FRAME_SIZE 16 +typedef unsigned char tcp_frame_t[TCP_FRAME_SIZE]; + /*_____________________ V A R I A B L E S ___________________________________*/ extern int tcp_clients_handle[]; extern unsigned char tcp_clients_count; @@ -45,6 +49,6 @@ extern pthread_mutex_t tcp_mutex; /*_____________________ F U N C T I O N S __________________________________*/ extern void tcp_server_start_task(); -extern void tcp_server_send_raw(unsigned char datas[64], unsigned char datas_count); -extern void tcp_server_send_raw_to_client(int client_index, unsigned char datas[64], unsigned char datas_count); +extern void tcp_server_send_raw(const tcp_frame_t data); +extern void tcp_server_send_raw_to_client(int client_index, const tcp_frame_t data); extern void send_daemon_disconnected(); |