INTRODUCTION
Overview
Download and Install
Documentation
Publications

REPOSITORY
Libraries

DEVELOPER
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         
serialhandler.h
1 /*
2  * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
3  * http://gearbox.sf.net/
4  * Copyright (c) 2004-2010 Alex Brooks
5  *
6  * This distribution is licensed to you under the terms described in
7  * the LICENSE file included in this distribution.
8  *
9  */
10 
11 #ifndef SICK_ACFR_SERIALHANDLER_H
12 #define SICK_ACFR_SERIALHANDLER_H
13 
14 #include <gbxsickacfr/messages.h>
15 #include <gbxserialacfr/serial.h>
16 #include <gbxsickacfr/gbxiceutilacfr/thread.h>
17 #include <gbxsickacfr/gbxiceutilacfr/buffer.h>
18 #include <gbxsickacfr/gbxserialdeviceacfr/serialdevicehandler.h>
19 #include <gbxsickacfr/gbxserialdeviceacfr/stickinbuffercallback.h>
20 
21 namespace gbxsickacfr {
22 
23 class RxMsgParser : public gbxserialdeviceacfr::RxMsgParser
24 {
25 public:
26  gbxserialdeviceacfr::RxMsgPtr parseBuffer( const std::vector<char> &buffer,
27  int &numBytesParsed )
28  {
29  LmsRxMsgPtr lmsRxMsg = parseBufferForRxMsgs( (const uChar*)&(buffer[0]),
30  buffer.size(),
31  numBytesParsed );
32  return lmsRxMsg;
33  }
34 
35 };
36 
37 // LmsRxMsg plus a timeStamp
38 class TimedLmsRxMsg {
39 public:
40  TimedLmsRxMsg() {}
41  TimedLmsRxMsg( int s, int us, const LmsRxMsgPtr &r )
42  : timeStampSec(s), timeStampUsec(us), msg(r) {}
43 
44  int timeStampSec;
45  int timeStampUsec;
46  LmsRxMsgPtr msg;
47 };
48 
49 //
50 // @brief Handles the serial port.
51 //
52 // Read in this separate loop so we can hopefully grab the messages
53 // as soon as they arrive, without relying on having Driver::read()
54 // called by an external thread which may be doing other stuff.
55 // This will hopefully give us more accurate timestamps.
56 //
57 // @author Alex Brooks
58 //
59 class SerialHandler
60 {
61 
62 public:
63 
64  SerialHandler( const std::string &dev,
65  gbxutilacfr::Tracer &tracer,
66  gbxutilacfr::Status &status );
67  ~SerialHandler();
68 
69  void send( const std::vector<uChar> &telegram )
70  { serialDeviceHandler_->send( (const char*)&(telegram[0]), telegram.size() ); }
71 
72  void setBaudRate( int baudRate )
73  { serialDeviceHandler_->setBaudRate( baudRate ); }
74 
75  // waits up to maxWaitMs for a RxMsg
76  // return codes same as gbxiceutilacfr::Buffer
77  int getNextRxMsg( TimedLmsRxMsg &timedRxMsg, int maxWaitMs )
78  {
79  gbxserialdeviceacfr::TimedRxMsg genericTimedRxMsg;
80  int ret = bufferCallback_.rxMsgBuffer().getAndPopWithTimeout( genericTimedRxMsg, maxWaitMs );
81  if ( ret == 0 )
82  {
83  timedRxMsg.timeStampSec = genericTimedRxMsg.timeStampSec;
84  timedRxMsg.timeStampUsec = genericTimedRxMsg.timeStampUsec;
85 
86  // This cast is safe becuase the rxMsg had to have been generated by RxMsgParser
87  timedRxMsg.msg = LmsRxMsgPtr::dynamicCast( genericTimedRxMsg.msg );
88  }
89  return ret;
90  }
91 
92 private:
93 
94  RxMsgParser rxMsgParser_;
95  gbxserialdeviceacfr::StickInBufferCallback bufferCallback_;
96  gbxserialacfr::Serial serialPort_;
97  gbxserialdeviceacfr::SerialDeviceHandler *serialDeviceHandler_;
98  // Keep a smart pointer to the SerialDeviceHandler as a thread, for stop/start purposes
99  gbxiceutilacfr::ThreadPtr serialDeviceHandlerThreadPtr_;
100 };
101 
102 }
103 
104 #endif
SICK laser driver.
Definition: serialdevicehandler.h:43
Encapsulates a serial port.
Definition: serial.h:43
Local and remote tracing.
Definition: tracer.h:111
Handles the serial port.
Definition: serialdevicehandler.h:88
Received message plus a timeStamp: a simple container to keep the two together.
Definition: stickinbuffercallback.h:10
Local interface to component status.
Definition: status.h:253
IceUtil::Handle< gbxiceutilacfr::Thread > ThreadPtr
A smart pointer to the thread class.
Definition: thread.h:106
 

Generated for GearBox by  doxygen 1.4.5