Brief description of class still missing. More...
#include <Serial.h>
Public Member Functions | |
| DynamicBuffer * | buffer () 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 () |
Brief description of class still missing.
Full description of class still missing
| GpCoreTools::Serial::Serial | ( | const std::string & | devicePath, |
| speed_t | speed, | ||
| DynamicBuffer * | buffer = 0 |
||
| ) |
| GpCoreTools::Serial::~Serial | ( | ) | [virtual] |
| DynamicBuffer * GpCoreTools::Serial::buffer | ( | ) | const [inline] |
Returns current data input buffer.
Referenced by Serial(), and UbxDevice::startBroadcast().
{return _buffer;}
| bool GpCoreTools::Serial::connect | ( | ) |
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().
{
TRACE;
setFileDescriptor(-1);
connect();
}
| bool GpCoreTools::Serial::isConnected | ( | ) |
References GpCoreTools::Stream::isActive(), lock(), TRACE, and unlock().
Referenced by CubeDevice::isConnected().
| 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] |
Write data through current serial line. It returns true if all bytes were successfully written.
References GpCoreTools::Stream::fileDescriptor().
Referenced by CrystalfontzBuffer::bytesAvailable(), CrystalfontzDevice::configureBoot(), connect(), event(), CrystalfontzDevice::firstPage(), CubeSerial::hungUp(), CubeDevice::mutexWrite(), UbxDevice::requestNavigation(), CubeSerial::start(), CubeDevice::write(), and CrystalfontzDevice::~CrystalfontzDevice().
{
return ::write(fileDescriptor(), buf, byteCount)==byteCount;
}