changeset 242:1b23ac90f06a main

Loop to read as many queued incoming messages as possible.
author Bob Cook <bob@bobcookdev.com>
date Sun, 28 Jun 2015 13:02:54 -0700
parents 0d0434043647
children b568dde5f512
files main/robots/odr-motion/canmsgs.cpp
diffstat 1 files changed, 35 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/main/robots/odr-motion/canmsgs.cpp	Sun Jun 28 12:56:35 2015 -0700
+++ b/main/robots/odr-motion/canmsgs.cpp	Sun Jun 28 13:02:54 2015 -0700
@@ -120,43 +120,46 @@
     uint8_t  recvdata[ 8 ];
     uint8_t  recvlen = sizeof( recvdata );
 
-    if ( ! m1can_read( &recvid, &recvrequest, recvdata, &recvlen ) )
-    {
-        return true; // no messages, everything ok
-    }
-
-    uint8_t  srcnode;
-    uint8_t  dstnode;
-    uint16_t dataid;
-    can_parse_message_id( recvid, &srcnode, &dstnode, &dataid );
-
-    if ( dstnode != can_node_broadcast && dstnode != can_node_odr_motion )
-    {
-        return true; // not for us, everything ok
-    }
-
-    switch ( dataid )
+    for ( ;; )
     {
-        case can_dataid_emergency:
-            status_got_emergency( srcnode );
-            break;
+        if ( ! m1can_read( &recvid, &recvrequest, recvdata, &recvlen ) )
+        {
+            return true; // no messages, everything ok
+        }
 
-        case can_dataid_all_clear:
-            status_got_all_clear( srcnode );
-            break;
+        uint8_t  srcnode;
+        uint8_t  dstnode;
+        uint16_t dataid;
+        can_parse_message_id( recvid, &srcnode, &dstnode, &dataid );
+
+        if ( dstnode != can_node_broadcast && dstnode != can_node_odr_motion )
+        {
+            continue; // not for us, everything ok, loop around and try again
+        }
 
-        case can_dataid_heartbeat:
-        case can_dataid_odrmgr_update:
-            status_got_heartbeat( srcnode );
-            break;
+        switch ( dataid )
+        {
+            case can_dataid_emergency:
+                status_got_emergency( srcnode );
+                break;
+
+            case can_dataid_all_clear:
+                status_got_all_clear( srcnode );
+                break;
 
-        case can_dataid_wheel_position:
-            update_position( reinterpret_cast< can_data_wheel_position* >( &recvdata ) );
-            break;
+            case can_dataid_heartbeat:
+            case can_dataid_odrmgr_update:
+                status_got_heartbeat( srcnode );
+                break;
 
-        case can_dataid_wheel_speed:
-            update_speed( reinterpret_cast< can_data_wheel_speed* >( &recvdata ) );
-            break;
+            case can_dataid_wheel_position:
+                update_position( reinterpret_cast< can_data_wheel_position* >( &recvdata ) );
+                break;
+
+            case can_dataid_wheel_speed:
+                update_speed( reinterpret_cast< can_data_wheel_speed* >( &recvdata ) );
+                break;
+        }
     }
 
     return true; // no errors