Signals | Public Member Functions | Protected Slots | Protected Member Functions
DaemonLink Class Reference

Brief description of class still missing. More...

#include <DaemonLink.h>

Inheritance diagram for DaemonLink:
CubeLink GpsLink NetLink SystemLink

List of all members.

Signals

void stateChanged ()

Public Member Functions

 DaemonLink (Station *station)
bool isAvailable ()
unsigned int port () const
void send (const char *msg)
void send (const char *buf, unsigned int len)
void setPort (unsigned int p)
 ~DaemonLink ()

Protected Slots

virtual void connected ()

Protected Member Functions

virtual int bytesAvailable (const char *buffer, int bytesCount)=0
int findMatch (const char *buffer, int &bytesRead, int bytesCount, const char *string)
bool match (const char *buffer, int &bytesRead, int bytesCount, const char *string)
double readDouble (const char *buffer, int &bytesRead, int bytesCount, bool &ok)
int readInteger (const char *buffer, int &bytesRead, int bytesCount, bool &ok)
long int readLongInteger (const char *buffer, int &bytesRead, int bytesCount, bool &ok)
QByteArray readString (const char *buffer, int &bytesRead, int bytesCount, bool &ok)
Stationstation ()
const Stationstation () const

Detailed Description

Brief description of class still missing.

Full description of class still missing


Constructor & Destructor Documentation

Description of constructor still missing

References bytesAvailable(), connected(), station(), and TRACE.

  : QObject(station)
{
  TRACE;
  _station=station;
  _port=0;
  _connectionTimer.setInterval(5000);
  QObject::connect(&_connectionTimer, SIGNAL(timeout()), this, SLOT(connect()));
  QObject::connect(&_socket, SIGNAL(readyRead()), this, SLOT(bytesAvailable()));
  QObject::connect(&_socket, SIGNAL(connected()), this, SLOT(connected()));
  QObject::connect(&_socket, SIGNAL(disconnected()), this, SLOT(hungUp()));
  connect();
  _connectionTimer.start();
}

Description of destructor still missing

References TRACE.

{
  TRACE;
  _socket.disconnectFromHost();
}

Member Function Documentation

virtual int DaemonLink::bytesAvailable ( const char *  buffer,
int  bytesCount 
) [protected, pure virtual]

Implemented in GpsLink, SystemLink, CubeLink, and NetLink.

Referenced by DaemonLink().

void DaemonLink::connected ( ) [protected, virtual, slot]

Reimplemented in GpsLink, and CubeLink.

References stateChanged(), and TRACE.

Referenced by DaemonLink().

{
  TRACE;
  _connectionTimer.stop();
  emit stateChanged();
}
int DaemonLink::findMatch ( const char *  buffer,
int &  bytesRead,
int  bytesCount,
const char *  string 
) [protected]

Returns 0 if buffer at bytesRead index does not contain string even partially at the end. Returns 1 if buffer at bytesRead index contains string partially at the end. Returns 2 if buffer at bytesRead index contains string completely.

{
  int si=0;
  int bi=bytesRead;
  while(bi<bytesCount) {
    if(string[si]=='\0') { // Completely matched
      bytesRead=bi;
      return 2;
    }
    if(buffer[bi]==string[si]) {
      si++;
    } else {
      si=0;
    }
    bi++;
  }
  if(si>0) { // Partially matched, do not advance bytesRead
    return 1;
  } else {
    bytesRead=bytesCount;
    return 0;
  }
}

References TRACE.

Referenced by Station::abortDownloadGps(), Station::clearUsb(), Station::downloadGps(), Station::isAvailable(), Station::linkState(), Station::navigationGps(), Station::powerOff(), Station::reboot(), Station::setSeismicParameters(), Station::startGps(), Station::startSeismic(), Station::stopGps(), and Station::stopSeismic().

{
  TRACE;
  switch(_socket.state()) {
  case QAbstractSocket::UnconnectedState:
    connect();
    _connectionTimer.start();
    return false;
  case QAbstractSocket::HostLookupState:
  case QAbstractSocket::ConnectingState:
  case QAbstractSocket::ClosingState:
    // Transient state, skip for now, try next time
    return false;
  case QAbstractSocket::ConnectedState:
    // Connection available
    break;
  case QAbstractSocket::BoundState:
  case QAbstractSocket::ListeningState:
    // Not possible here (server states only)
    return false;
  }
  return true;
}
bool DaemonLink::match ( const char *  buffer,
int &  bytesRead,
int  bytesCount,
const char *  string 
) [protected]

Returns true if buffer at bytesRead index starts with string.

Referenced by CubeLink::bytesAvailable(), SystemLink::bytesAvailable(), and GpsLink::bytesAvailable().

{
  int n=bytesCount-bytesRead;
  int sn=strlen(string);
  if(n>=sn && strncmp(buffer+bytesRead, string, sn)==0) {
    bytesRead+=sn;
    return true;
  } else {
    return false;
  }
}
unsigned int DaemonLink::port ( ) const [inline]
{return _port;}
double DaemonLink::readDouble ( const char *  buffer,
int &  bytesRead,
int  bytesCount,
bool &  ok 
) [protected]

Returns -1 if value is truncated and bytesRead is not modified.

{
  int i;
  double value;
  for(i=bytesRead; i<bytesCount && !isspace(buffer[i]); i++) {}
  int n=i-bytesRead;
  if(n>0 && i<bytesCount) {
    char * temp=new char[n+1];
    strncpy(temp, buffer+bytesRead, n);
    temp[n]='\0';
    value=atof(temp);
    bytesRead=i;
    ok=true;
    delete [] temp;
  } else {
    value=-1;
    ok=false;
  }
  return value;
}
int DaemonLink::readInteger ( const char *  buffer,
int &  bytesRead,
int  bytesCount,
bool &  ok 
) [protected]

Returns -1 if value is truncated and bytesRead is not modified.

{
  int i;
  int value;
  for(i=bytesRead; i<bytesCount && !isspace(buffer[i]); i++) {}
  int n=i-bytesRead;
  if(n>0 && i<bytesCount) {
    char * temp=new char[n+1];
    strncpy(temp, buffer+bytesRead, n);
    temp[n]='\0';
    value=atoi(temp);
    bytesRead=i;
    ok=true;
    delete [] temp;
  } else {
    value=-1;
    ok=false;
  }
  return value;
}
long int DaemonLink::readLongInteger ( const char *  buffer,
int &  bytesRead,
int  bytesCount,
bool &  ok 
) [protected]

Returns -1 if value is truncated and bytesRead is not modified.

{
  int i;
  long int value;
  for(i=bytesRead; i<bytesCount && !isspace(buffer[i]); i++) {}
  int n=i-bytesRead;
  if(n>0 && i<bytesCount) {
    char * temp=new char[n+1];
    strncpy(temp, buffer+bytesRead, n);
    temp[n]='\0';
    value=atol(temp);
    bytesRead=i;
    ok=true;
    delete [] temp;
  } else {
    value=-1;
    ok=false;
  }
  return value;
}
QByteArray DaemonLink::readString ( const char *  buffer,
int &  bytesRead,
int  bytesCount,
bool &  ok 
) [protected]

Returns -1 if value is truncated and bytesRead is not modified.

{
  int i;
  QByteArray value;
  for(i=bytesRead; i<bytesCount && !isspace(buffer[i]); i++) {}
  int n=i-bytesRead;
  if(n>0 && i<bytesCount) {
    value=QByteArray(buffer+bytesRead, n);
    bytesRead=i;
    ok=true;
  } else {
    ok=false;
  }
  return value;
}
void DaemonLink::send ( const char *  msg)
void DaemonLink::send ( const char *  buf,
unsigned int  len 
)

References TRACE.

{
  TRACE;
  if(_socket.state()==QAbstractSocket::ConnectedState) {
    _socket.write(buf, len);
    _socket.flush();
  }
}
void DaemonLink::setPort ( unsigned int  p) [inline]
void DaemonLink::stateChanged ( ) [signal]

Referenced by connected().

Station* DaemonLink::station ( ) [inline, protected]

Referenced by NetLink::bytesAvailable(), DaemonLink(), and GpsLink::raw().

{return _station;}
const Station* DaemonLink::station ( ) const [inline, protected]
{return _station;}

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