changeset 198:75c3c9c8868f main

Add a new canbus message for the number of satellites used in a position fix.
author Bob Cook <bob@bobcookdev.com>
date Sat, 24 Aug 2013 12:38:35 -0700
parents ff6cfa2ea1ee
children 15d96880b4ba 439e242e672a
files main/packages/common/can/can_messages.h main/robots/odr-gps/canmsgs.cpp main/robots/odr-gps/func.h main/robots/odr-gps/main.cpp
diffstat 4 files changed, 45 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/main/packages/common/can/can_messages.h	Wed Aug 21 21:02:30 2013 -0700
+++ b/main/packages/common/can/can_messages.h	Sat Aug 24 12:38:35 2013 -0700
@@ -34,8 +34,6 @@
 
 #include <stdint.h>
 
-#include "packages/common/util/fixedpoint.h"
-
 // ----------------------------------------------------------------------------------------
 //  Overall scheme (lower is higher priority):
 // 
@@ -124,6 +122,16 @@
 
 // ----------------------------------------------------------------------------------------
 
+const uint16_t can_dataid_gps_fix = 0x0103;
+
+typedef struct
+{
+    uint8_t satellites; // zero indicates no fix
+
+} can_data_gps_fix;
+
+// ----------------------------------------------------------------------------------------
+
 const uint16_t can_dataid_wheel_position = 0x0110;
 
 typedef struct
--- a/main/robots/odr-gps/canmsgs.cpp	Wed Aug 21 21:02:30 2013 -0700
+++ b/main/robots/odr-gps/canmsgs.cpp	Sat Aug 24 12:38:35 2013 -0700
@@ -51,7 +51,7 @@
 
 bool canmsg_send_emergency()
 {
-    return m1can_send( can_build_message_id( can_node_odr_motion,
+    return m1can_send( can_build_message_id( can_node_sensor_gps,
                                              can_node_broadcast,
                                              can_dataid_emergency ), 0, 0 );
 }
@@ -60,7 +60,7 @@
 
 bool canmsg_send_all_clear()
 {
-    return m1can_send( can_build_message_id( can_node_odr_motion,
+    return m1can_send( can_build_message_id( can_node_sensor_gps,
                                              can_node_broadcast,
                                              can_dataid_all_clear ), 0, 0 );
 }
@@ -69,13 +69,28 @@
 
 bool canmsg_send_heartbeat()
 {
-    return m1can_send( can_build_message_id( can_node_odr_motion,
+    return m1can_send( can_build_message_id( can_node_sensor_gps,
                                              can_node_broadcast,
                                              can_dataid_heartbeat ), 0, 0 );
 }
 
 // ----------------------------------------------------------------------------------------
 
+bool canmsg_send_gps_fix_info( uint8_t satellites )
+{
+    uint32_t msgid;
+    msgid = can_build_message_id( can_node_sensor_gps,
+                                  can_node_broadcast,
+                                  can_dataid_gps_fix );
+
+    can_data_gps_fix data;
+    data.satellites = satellites;
+
+    return m1can_send( msgid, reinterpret_cast< uint8_t* >( &data ), sizeof( data ) );
+}
+
+// ----------------------------------------------------------------------------------------
+
 bool canmsg_send_gps_latitude( int16_t degrees, uint16_t minutes, uint16_t min_fract )
 {
     uint32_t msgid;
@@ -91,14 +106,7 @@
     data.min_thousandths += ( min_fract / // convert between units
                 ( nmea_fractional_minutes_multiplier / can_data_gps_min_multiplier ) );
 
-    if ( ! m1can_send( msgid,
-                       reinterpret_cast< uint8_t* >( &data ),
-                       sizeof( data ) ) )
-    {
-        return false;
-    }
-
-    return true;
+    return m1can_send( msgid, reinterpret_cast< uint8_t* >( &data ), sizeof( data ) );
 }
 
 // ----------------------------------------------------------------------------------------
@@ -118,14 +126,7 @@
     data.min_thousandths += ( min_fract / // convert between units
                 ( nmea_fractional_minutes_multiplier / can_data_gps_min_multiplier ) );
 
-    if ( ! m1can_send( msgid,
-                       reinterpret_cast< uint8_t* >( &data ),
-                       sizeof( data ) ) )
-    {
-        return false;
-    }
-
-    return true;
+    return m1can_send( msgid, reinterpret_cast< uint8_t* >( &data ), sizeof( data ) );
 }
 
 // ----------------------------------------------------------------------------------------
@@ -147,7 +148,7 @@
     uint16_t dataid;
     can_parse_message_id( recvid, &srcnode, &dstnode, &dataid );
 
-    if ( dstnode != can_node_broadcast && dstnode != can_node_odr_motion )
+    if ( dstnode != can_node_broadcast && dstnode != can_node_sensor_gps )
     {
         return true; // not for us, everything ok
     }
--- a/main/robots/odr-gps/func.h	Wed Aug 21 21:02:30 2013 -0700
+++ b/main/robots/odr-gps/func.h	Sat Aug 24 12:38:35 2013 -0700
@@ -53,6 +53,7 @@
 bool canmsg_send_emergency();
 bool canmsg_send_all_clear();
 bool canmsg_send_heartbeat();
+bool canmsg_send_gps_fix_info( uint8_t satellites );
 bool canmsg_send_gps_latitude( int16_t degrees, uint16_t minutes, uint16_t min_fract );
 bool canmsg_send_gps_longitude( int16_t degrees, uint16_t minutes, uint16_t min_fract );
 bool canmsg_process_pending();
--- a/main/robots/odr-gps/main.cpp	Wed Aug 21 21:02:30 2013 -0700
+++ b/main/robots/odr-gps/main.cpp	Sat Aug 24 12:38:35 2013 -0700
@@ -265,9 +265,16 @@
 
                 status_got_gps_sentence();
 
-                if ( nmea_position_fix() )
+                uint8_t satellites;
+
+                if ( nmea_position_fix( &satellites ) )
                 {
                     led_green_2_on();
+                    
+                    if ( ! canmsg_send_gps_fix_info( satellites ) )
+                    {
+                        ++can_comm_errors;
+                    }
 
                     int16_t  degrees;
                     uint16_t minutes;
@@ -290,6 +297,11 @@
                 else
                 {
                     led_green_2_toggle();
+
+                    if ( ! canmsg_send_gps_fix_info( 0 ) )
+                    {
+                        ++can_comm_errors;
+                    }
                 }
             }
         }