Author: remi
Date: 2008-07-01 09:38:51 +0200 (Tue, 01 Jul 2008)
New Revision: 1285

Modified:
   software_suite_v2/middleware/tuxdriver/trunk/src/tux_usb.c
   software_suite_v2/middleware/tuxdriver/trunk/src/tux_usb.h
Log:
* Added a check of the id frame which must be incremented after each request. 
To activate it, you must to define -DUSB_IDFRAME in the makefile. This check 
only work with a dongle which implement this counter ! The automatic reset of 
the RF after too many errors on this counter is disabled with the define 
-DUSB_DEBUG.
* The automatic reset of the RF after too many empty frames can be disabled 
with the define -DUSB_DEBUG.

Modified: software_suite_v2/middleware/tuxdriver/trunk/src/tux_usb.c
===================================================================
--- software_suite_v2/middleware/tuxdriver/trunk/src/tux_usb.c  2008-07-01 
07:32:16 UTC (rev 1284)
+++ software_suite_v2/middleware/tuxdriver/trunk/src/tux_usb.c  2008-07-01 
07:38:51 UTC (rev 1285)
@@ -41,7 +41,6 @@
 static simple_callback_t loop_cycle_complete_function;
 static rf_state_callback_t rf_state_callback_function;
 static unsigned char last_knowed_rf_state = 0;
-static int read_error_counter = 0;
 static char frame_status_request[5] = {1, 1, 0, 0, 0};
 static char frame_reset_dongle[5] = {1, 1, 0, 0, 0xFE};
 static char frame_reset_rf[5] = {1, 1, 0, 0, 0xFD};
@@ -60,6 +59,12 @@
 static bool get_read_loop_started(void);
 static void read_usb_loop(void);
 
+#ifdef USB_IDFRAME 
+static int id_frame_last = 999;
+static int freezed_frame_cnt = 0;
+#endif
+static int empty_frame_cnt = 0;
+
 /**
  *
  */
@@ -215,7 +220,11 @@
 LIBLOCAL TuxUSBError
 tux_usb_capture(void)
 {   
-    read_error_counter = 0;
+    empty_frame_cnt = 0;
+#ifdef USB_IDFRAME 
+    id_frame_last = 999;
+    freezed_frame_cnt = 0;
+#endif
     
     if (!tux_hid_capture(TUX_VID, TUX_PID))
     {
@@ -303,28 +312,67 @@
     int i, j;
     int rf_state;
     int packet_count;
+    int id_frame;
     char *data_buf;
     char packet_data[4];
     
+    id_frame = data[0];
     rf_state = data[1];
     packet_count = data[3]; 
     data_buf = (char *)data;
     data_buf += 4;
-    
+
+#ifdef USB_IDFRAME    
+    /* Check if the frame is newer than the last received one */
+    if (id_frame == id_frame_last)
+    {
+        freezed_frame_cnt++;
+        log_warning("The id of USB frame is the same than the previous [%d]", 
+            freezed_frame_cnt);
+#ifndef USB_DEBUG
+        if (freezed_frame_cnt >= TUX_USB_FREEZED_FRAMES_LIMIT)
+        {
+            freezed_frame_cnt = 0;
+            id_frame_last = 999;
+            log_error("The USB frame retriving seems to be freezed [%d]",
+                TUX_USB_FREEZED_FRAMES_LIMIT);
+            log_info("The RF connection will be reinitialized");
+            tux_usb_rf_reset();
+        }
+#endif
+        return;
+    }
+    else
+    {
+        freezed_frame_cnt = 0;
+        id_frame_last = id_frame;
+    }
+#endif
+   
     /* Having RF state to ON and no status frame is not normal */
     if ((packet_count == 0) && (rf_state == 1))
     {
-        read_error_counter++;
-        log_warning("Read errors count : %d", read_error_counter);
-        if (read_error_counter >= TUX_USB_ERROR_LIMIT)
+        empty_frame_cnt++;
+#ifndef USB_DEBUG
+        if (empty_frame_cnt > 2)
         {
-            /* Reset of the RF */
+            log_warning("Consecutive frames without status : %d", 
empty_frame_cnt);
+        }
+        if (empty_frame_cnt >= TUX_USB_ERROR_LIMIT)
+        {
+            log_error("DONGLE ERROR : Too many consecutive frames without 
status [%d], but the RF is online", 
+                TUX_USB_ERROR_LIMIT);
+            empty_frame_cnt = 0;
+            log_info("The RF connection will be reinitialized");
             tux_usb_rf_reset();
         }
+#else
+        log_warning("Consecutive frames without status : %d", empty_frame_cnt);
+#endif
     }
     else
     {
-        read_error_counter = 0;
+        empty_frame_cnt = 0;
     }
     
     if (last_knowed_rf_state != rf_state)
@@ -342,6 +390,12 @@
 #endif
     }
     
+    if (packet_count > 15)
+    {
+        log_error("DONGLE ERROR : Statuses packets count is wrong (>15)");
+        return;
+    }
+    
     for (i = 0; i < packet_count; i++)
     {
         for (j = 0; j < 4; j++)
@@ -488,6 +542,8 @@
         {
             usleep(1000);
         }
+        
+        current_timeout = get_time();
     }
     
     set_read_loop_started(false);

Modified: software_suite_v2/middleware/tuxdriver/trunk/src/tux_usb.h
===================================================================
--- software_suite_v2/middleware/tuxdriver/trunk/src/tux_usb.h  2008-07-01 
07:32:16 UTC (rev 1284)
+++ software_suite_v2/middleware/tuxdriver/trunk/src/tux_usb.h  2008-07-01 
07:38:51 UTC (rev 1285)
@@ -26,18 +26,13 @@
 
 #include "tux_misc.h"
 
-#define TUX_PID                     0xFF07
-#define TUX_VID                     0x03EB
-#define TUX_INTERFACE               0x03
-#define TUX_SEND_LENGTH             0x05
-#define TUX_RECEIVE_LENGTH          64
-#define TUX_WRITE_EP                0x05
-#define TUX_READ_EP                 0x84
-#define TUX_WRITE_TIMEOUT           1000
-#define TUX_READ_TIMEOUT            1000
-#define TUX_READ_LOOP_INTERVAL      0.1
-#define TUX_USB_ERROR_LIMIT         10
-#define MIN_FIRMWARE_VERSION        0x030
+#define TUX_PID                         0xFF07
+#define TUX_VID                         0x03EB
+#define TUX_SEND_LENGTH                 5
+#define TUX_RECEIVE_LENGTH              64
+#define TUX_READ_LOOP_INTERVAL          0.1
+#define TUX_USB_ERROR_LIMIT             20
+#define TUX_USB_FREEZED_FRAMES_LIMIT    10
 
 #ifdef WIN32
 #   define usb_busses               usb_get_busses()


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to