Permalink
Browse files

Modifications for 2012.

  • Loading branch information...
1 parent d22813f commit cec79552b1b0b59166d08a7448c6773b57f6e3a9 @mjcarroll mjcarroll committed May 2, 2012
@@ -7,7 +7,6 @@ include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
# Release : w/o debug symbols, w/ optimization
# RelWithDebInfo : w/ debug symbols, w/ optimization
# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries
-#set(ROS_BUILD_TYPE RelWithDebInfo)
set(ROS_BUILD_TYPE Debug)
rosbuild_init()
@@ -17,29 +16,17 @@ set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
-# Check for OS X and if so disable kqueue support in asio
-IF(CMAKE_SYSTEM_NAME MATCHES Darwin)
- add_definitions(-DBOOST_ASIO_DISABLE_KQUEUE)
-ENDIF(CMAKE_SYSTEM_NAME MATCHES Darwin)
-
#uncomment if you have defined messages
rosbuild_genmsg()
#uncomment if you have defined services
#rosbuild_gensrv()
-#common commands for building c++ executables and libraries
-#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
-#target_link_libraries(${PROJECT_NAME} another_library)
-#rosbuild_add_boost_directories()
-#rosbuild_link_boost(${PROJECT_NAME} thread)
-#rosbuild_add_executable(example examples/example.cpp)
-#target_link_libraries(example ${PROJECT_NAME})
-
-rosbuild_find_ros_package(dynamic_reconfigure)
-include(${dynamic_reconfigure_PACKAGE_PATH}/cmake/cfgbuild.cmake)
-gencfg()
+#rosbuild_find_ros_package(dynamic_reconfigure)
+#include(${dynamic_reconfigure_PACKAGE_PATH}/cmake/cfgbuild.cmake)
+#gencfg()
-rosbuild_add_boost_directories()
-rosbuild_add_executable(dg14_driver src/dg14_driver.cc)
-rosbuild_link_boost(dg14_driver program_options thread system)
+# Build the DG14 Library
+rosbuild_add_library(${PROJECT_NAME} src/dg14.cc)
+rosbuild_add_executable(dg14_node src/dg14_node.cc)
+target_link_libraries(dg14_node ${PROJECT_NAME})
@@ -1,15 +0,0 @@
-#!/usr/bin/env python
-# Gps Configuration
-
-PACKAGE="magellan_dg14"
-import roslib; roslib.load_manifest(PACKAGE)
-
-from dynamic_reconfigure.parameter_generator import *
-
-gen = ParameterGenerator()
-
-gen.add("northing_origin", double_t, 1, "Northing Origin", 3606769.25);
-gen.add("easting_origin", double_t, 1, "Easting Origin", 641734.05);
-
-exit(gen.generate(PACKAGE, "dynamic_reconfigure_node", "Gps"))
-
@@ -1,8 +0,0 @@
-\subsubsection usage Usage
-\verbatim
-<node name="dynamic_reconfigure_node" pkg="magellan_dg14" type="dynamic_reconfigure_node">
- <param name="northing_origin" type="double" value="3606769.25" />
- <param name="easting_origin" type="double" value="641734.05" />
-</node>
-\endverbatim
-
@@ -1,7 +0,0 @@
-\subsubsection parameters ROS parameters
-
-Reads and maintains the following parameters on the ROS server
-
-- \b "~northing_origin" : \b [double] Northing Origin min: -std::numeric_limits<double>::infinity(), default: 3606769.25, max: std::numeric_limits<double>::infinity()
-- \b "~easting_origin" : \b [double] Easting Origin min: -std::numeric_limits<double>::infinity(), default: 641734.05, max: std::numeric_limits<double>::infinity()
-
@@ -1,16 +0,0 @@
-# Autogenerated param section. Do not hand edit.
-param {
-group.0 {
-name=Dynamically Reconfigurable Parameters
-desc=See the [[dynamic_reconfigure]] package for details on dynamically reconfigurable parameters.
-0.name= ~northing_origin
-0.default= 3606769.25
-0.type= double
-0.desc=Northing Origin Range: -std::numeric_limits<double>::infinity() to std::numeric_limits<double>::infinity()
-1.name= ~easting_origin
-1.default= 641734.05
-1.type= double
-1.desc=Easting Origin Range: -std::numeric_limits<double>::infinity() to std::numeric_limits<double>::infinity()
-}
-}
-# End of autogenerated section. You may edit below.
@@ -0,0 +1,65 @@
+#ifndef DG14_DG14_H
+#define DG14_DG14_H
+
+#include <string>
+#include <sstream>
+#include <serial/serial.h>
+#include <serial/utils/serial_listener.h>
+
+#define DG14_THROW(exceptionClass, message) throw \
+ exceptionClass(__FILE__,__LINE__,(message))
+
+namespace dg14 {
+
+ enum ports {kA, kB, kC};
+ enum bauds {k300, k600, k1200, k2400, k4800,
+ k9600, k19200, k38400, k56800, k115200};
+
+ typedef boost::function<void(const std::string&)> LoggingCallback;
+
+ class DG14 {
+ public:
+ DG14 (std::string port = "");
+ ~DG14 (void);
+ void connect(std::string port = "");
+ void disconnect (void);
+ bool isConnected (void);
+
+ LoggingCallback debug;
+ LoggingCallback info;
+ LoggingCallback warn;
+
+ private:
+ std::string port_;
+ serial::Serial * serial_port_;
+ serial::utils::SerialListener serial_listener_;
+
+ bool checkConnection(void);
+ void setupFilters_(void);
+ serial::utils::BufferedFilterPtr test_filt_;
+
+ bool connected_;
+ };
+
+ /*!
+ * This exceptions occurs during connection.
+ */
+ class ConnectionException : public std::exception {
+ std::string file_;
+ int line_;
+ const char* e_what_;
+ public:
+ ConnectionException (std::string file, int line, const char * description)
+ : file_(file), line_(line), e_what_ (description) {}
+ virtual ~ConnectionException() throw() {}
+
+ virtual const char* what () const throw () {
+ std::stringstream ss;
+ ss << "Connection Exception: " << e_what_;
+ ss << ", file " << file_ << ", line " << line_ << ".";
+ return ss.str ().c_str ();
+ }
+ };
+}
+
+#endif
@@ -1,49 +0,0 @@
-#ifndef DG14_H_
-#define DG14_H_
-#include <serial.h>
-#include <string>
-#include <boost/asio.hpp>
-#include <boost/function.hpp>
-#include <gps_common/GPSFix.h>
-#include <gps_common/GPSStatus.h>
-#include <sensor_msgs/NavSatFix.h>
-#include <sensor_msgs/NavSatStatus.h>
-#include <nav_msgs/Odometry.h>
-
-#define CMD_TERMINATOR "\r\n"
-
-#define CMD_POS_ON "$PASHS,NME,POS,A,ON,0.2" CMD_TERMINATOR
-#define CMD_POS_OFF "$PASHS,NME,POS,A,OFF,0.2" CMD_TERMINATOR
-
-#define CMD_SAT_ON "$PASHS,NME,SAT,A,ON,0.2" CMD_TERMINATOR
-#define CMD_SAT_OFF "$PASHS,NME,SAT,A,OFF,0.2" CMD_TERMINATOR
-
-#define CMD_UTM_ON = "$PASHS,NME,UTM,A,ON,0.2" CMD_TERMINATOR
-#define CMD_UTM_OFF = "$PASHS,NME,UTM,A,OFF,0.2" CMD_TERMINATOR
-
-namespace dg14 {
- namespace s = std;
- class Gps {
- public:
- explicit Gps();
- explicit Gps(s::string, int buad = 115200);
-
- void Init(s::string, int baud = 115200);
- void Run();
- void Stop();
- void Cancel();
-
- void RegisterCallback(boost::function<void (s::string)> onsuccess);
- private:
- void RunLoop();
-
- boost::thread looper_;
- bool loop_flag_;
- boost::mutex mx_;
-
- boost::function<void (s::string)> onsuccess_;
- serial::Serial s_;
- };
-}
-
-#endif /* end DG14_H_ */
@@ -1,26 +0,0 @@
-/**
-\mainpage
-\htmlinclude manifest.html
-
-\b dg14 is ...
-
-<!--
-Provide an overview of your package.
--->
-
-
-\section codeapi Code API
-
-<!--
-Provide links to specific auto-generated API documentation within your
-package that is of particular interest to a reader. Doxygen will
-document pretty much every part of your code, so do your best here to
-point the reader to the actual API.
-
-If your codebase is fairly large or has different sets of APIs, you
-should use the doxygen 'group' tag to keep these APIs together. For
-example, the roscpp documentation has 'libros' group.
--->
-
-
-*/
@@ -8,12 +8,12 @@
<license>BSD</license>
<review status="unreviewed" notes=""/>
<url>http://ros.org/wiki/dg14</url>
- <depend package="rospy"/>
- <depend package="roscpp" />
+
+ <depend package="serial"/>
+ <depend package="serial_utils"/>
+ <depend package="roscpp"/>
<depend package="tf"/>
<depend package="nav_msgs"/>
- <depend package="gps_common"/>
- <depend package="serial" />
<depend package="dynamic_reconfigure" />
</package>
@@ -0,0 +1,111 @@
+#include "dg14/dg14.h"
+
+#include <iostream>
+#include <sstream>
+#include <cstdio>
+
+#include <boost/algorithm/string.hpp>
+#include <boost/lexical_cast.hpp>
+
+using namespace dg14;
+
+using std::string;
+using std::stringstream;
+using serial::Serial;
+using serial::utils::SerialListener;
+
+inline void defaultInfo(const string &msg) {
+ std::cout << "DG14 Info: " << msg << std::endl;
+}
+
+void default_handler(std::string token) {
+ std::cout << "default_handler got a: " << token << std::endl;
+}
+
+DG14::DG14 (string port):
+ port_(""), serial_port_(NULL), serial_listener_(1),
+ connected_(false)
+ {
+ this->port_ = port;
+ this->info = defaultInfo;
+
+ if (!this->port_.empty()) {
+ this->connect();
+ }
+ }
+
+DG14::~DG14() {
+ this->disconnect();
+}
+
+void DG14::connect (string port) {
+ if (this->connected_) {
+ DG14_THROW(ConnectionException, "already connected");
+ }
+
+ if (!port.empty()) {
+ this->port_ = port;
+ }
+
+ if (this->port_.empty()) {
+ DG14_THROW(ConnectionException, "serial port name is empty");
+ }
+
+ this->disconnect();
+ this->setupFilters_();
+
+ this->serial_port_ = new Serial();
+ this->serial_port_->setPort(this->port_);
+ this->serial_port_->setBaudrate(9600);
+ this->serial_port_->setParity(serial::parity_none);
+ this->serial_port_->setStopbits(serial::stopbits_one);
+ this->serial_port_->setBytesize(serial::eightbits);
+ this->serial_port_->setTimeout(10);
+ this->serial_port_->open();
+
+ this->serial_listener_.setChunkSize(2);
+ this->serial_listener_.startListening((*this->serial_port_));
+
+ if (this->checkConnection())
+ {
+ this->connected_ = true;
+ this->info("Connection established.");
+ } else
+ DG14_THROW(ConnectionException, "could not establish serial communication");
+}
+
+void DG14::disconnect () {
+ this->connected_ = false;
+ if (this->serial_listener_.isListening()) {
+ this->serial_listener_.stopListening();
+ }
+ if (this->serial_port_ != NULL) {
+ delete this->serial_port_;
+ this->serial_port_ = NULL;
+ }
+}
+
+bool DG14::isConnected () {
+ return this->connected_;
+}
+
+bool DG14::checkConnection(void) {
+ bool isConnected = false;
+ serial::utils::BufferedFilterPtr ok_filt =
+ this->serial_listener_.createBufferedFilter(SerialListener::contains("$PASHR,PRT"));
+
+ this->serial_port_->write("$PASHQ,PRT\r\n");
+ for (int i=0; i < 10; ++i)
+ {
+ if (!ok_filt->wait(50).empty()) {
+ isConnected = true;
+ break;
+ }
+ }
+ return isConnected;
+}
+
+void DG14::setupFilters_() {
+ this->serial_listener_.setDefaultHandler(default_handler);
+}
+
Oops, something went wrong.

0 comments on commit cec7955

Please sign in to comment.