MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    m_remoteAddr = QHostAddress(REMOTE_IP_STRING);
    m_remotePort = REMOTE_PORT;
    m_tickCount = 0;
    m_sendCount = 0;
    m_recvCount = 0;
    m_isConnected = false;

    memset((void *)&m_machineData, 0, sizeof(m_machineData));

    m_timer = new QTimer(this);
    m_timer->setInterval((int)(1000.0 / CONNECTION_FREQ));

    ui->setupUi(this);

    ui->pushButtonConnect->connect(
                ui->pushButtonConnect,
                SIGNAL(clicked()),
                this,
                SLOT(OnPushbuttonConnectClicked()));

    ui->lineEditCmd->connect(
                ui->lineEditCmd,
                SIGNAL(returnPressed()),
                this,
                SLOT(OnCommandLineReturned()));

    m_tcpSocket = new QTcpSocket();
    m_tcpSocket->connect(
                m_tcpSocket,
                SIGNAL(readyRead()),
                this,
                SLOT(OnDatagramReceived()));

    m_timer->connect(
                m_timer,
                SIGNAL(timeout()),
                this,
                SLOT(OnTimerTick()));

    m_tcpSocket->connect(
                m_tcpSocket,
                SIGNAL(disconnected()),
                this,
                SLOT(OnSocketDisconnected()));

    ui->lineEditIP->setText(REMOTE_IP_STRING);

    QString txt;
    ui->lineEditPort->setText(txt.sprintf("%d", REMOTE_PORT));
    ui->lineEditCmd->setFocus();

    InitializePloting();

    m_paramSetWindow = new ParamSetWindow(this);
}
Example #2
0
bool
SkyLinesTracking::Client::OnFileEvent(int fd, unsigned mask)
{
  if (!socket.IsDefined())
    return false;

  uint8_t buffer[4096];
  ssize_t nbytes;
  SocketAddress source_address;

  while ((nbytes = socket.Read(buffer, sizeof(buffer), source_address)) > 0)
    if (source_address == address)
      OnDatagramReceived(buffer, nbytes);

  return true;
}
Example #3
0
void
Server::OnReceive(const boost::system::error_code &ec, size_t size)
{
  // TODO: use recvmmsg() on Linux

  if (ec) {
    if (ec == boost::asio::error::operation_aborted)
      return;

    socket.close();

    OnError(boost::system::system_error(ec));
    return;
  }

  OnDatagramReceived(std::move(client_buffer), buffer, size);

  AsyncReceive();
}
Example #4
0
void
SkyLinesTracking::Client::OnReceive(const boost::system::error_code &ec,
                                    size_t size)
{
    if (ec) {
        if (ec == boost::asio::error::operation_aborted)
            return;

        {
            const ScopeLock protect(mutex);
            socket.close();
        }

        if (handler != nullptr)
            handler->OnSkyLinesError(boost::system::system_error(ec));
        return;
    }

    if (sender_endpoint == endpoint)
        OnDatagramReceived(buffer, size);
}