All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Member Functions
GpCoreTools::Serial Class Reference

Brief description of class still missing. More...

#include <Serial.h>

Inheritance diagram for GpCoreTools::Serial:
GpCoreTools::Stream CrystalfontzDevice CubeSerial

List of all members.

Public Member Functions

DynamicBufferbuffer () const
bool connect ()
virtual void event (short type)
virtual short eventTypes ()
virtual void hungUp ()
bool isConnected ()
int lock ()
 Serial (const std::string &devicePath, speed_t speed, DynamicBuffer *buffer=0)
bool tryLock ()
int unlock ()
bool write (const char *buf, ssize_t byteCount)
virtual ~Serial ()

Detailed Description

Brief description of class still missing.

Full description of class still missing


Constructor & Destructor Documentation

GpCoreTools::Serial::Serial ( const std::string &  devicePath,
speed_t  speed,
DynamicBuffer buffer = 0 
)

Description of constructor still missing

buffer can be null for single way serial connection

References buffer(), and TRACE.

  {
    TRACE;
    _speed=speed;
    _devicePath=devicePath;
    _buffer=buffer;
    assert(pthread_mutex_init(&_mutex, 0)==0);
  }

Description of destructor still missing

References TRACE.

  {
    TRACE;
    delete _buffer;
  }

Member Function Documentation

Returns current data input buffer.

Referenced by Serial(), and UbxDevice::startBroadcast().

{return _buffer;}

Returns false if connection times out and if event loop is interrupted.

References GpCoreTools::EventLoop::instance(), lock(), TRACE, unlock(), and write().

Referenced by CubeSerial::hungUp(), hungUp(), and main().

  {
    TRACE;
    lock();
    while(!open()) {
      unlock();
      sleep(5);
      if (EventLoop::instance()->isTerminated()) {
        return false;
      }
      lock();
    }
    init();
    unlock();
    Log::write(0, "%s connected\n", _devicePath.data());
    return true;
  }
void GpCoreTools::Serial::event ( short  type) [virtual]

Implements GpCoreTools::Stream.

References GpCoreTools::Stream::close(), GpCoreTools::Stream::fileDescriptor(), hungUp(), GpCoreTools::DynamicBuffer::read(), TRACE, and write().

  {
    TRACE;
    if(type & (POLLIN | POLLPRI)) {
      if(type & POLLPRI) {
        Log::write(8, "priority data ready (type=%i, POLLIN=%i, POLLPRI=%i\n", type, POLLIN, POLLPRI);
      }
      if(_buffer) {
        if(!_buffer->read()) {
          Log::write(1, "error reading data (socket %i)\n", fileDescriptor());
        }
      }
    }
    if(type & (POLLRDHUP | POLLHUP)) {
      Log::write(1, "connection hung up\n");
      close();
      hungUp();
    }
  }
virtual short GpCoreTools::Serial::eventTypes ( ) [inline, virtual]

Implements GpCoreTools::Stream.

{return POLLIN | POLLPRI | POLLRDHUP | POLLHUP;}
void GpCoreTools::Serial::hungUp ( ) [virtual]

Reimplemented in CubeSerial.

References connect(), GpCoreTools::Stream::setFileDescriptor(), and TRACE.

Referenced by event().

References GpCoreTools::Stream::isActive(), lock(), TRACE, and unlock().

Referenced by CubeDevice::isConnected().

  {
    TRACE;
    lock();
    bool a=isActive();
    unlock();
    return a;
  }
int GpCoreTools::Serial::lock ( ) [inline]

Referenced by connect(), isConnected(), UbxDevice::sendState(), and UbxDevice::startBroadcast().

{return pthread_mutex_lock(&_mutex);}
bool GpCoreTools::Serial::tryLock ( ) [inline]

Referenced by CubeDevice::mutexWrite().

{return pthread_mutex_trylock(&_mutex)==0;}
int GpCoreTools::Serial::unlock ( ) [inline]

Referenced by connect(), isConnected(), CubeDevice::mutexWrite(), UbxDevice::sendState(), and UbxDevice::startBroadcast().

{return pthread_mutex_unlock(&_mutex);}
bool GpCoreTools::Serial::write ( const char *  buf,
ssize_t  byteCount 
) [inline]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines