Esempio n. 1
0
void TMsgCore::OnNewConnection()  // server side
{
  QTcpSocket *socket;
  if (m_tcpServer) socket = m_tcpServer->nextPendingConnection();
  assert(socket);

  bool ret = connect(socket, SIGNAL(readyRead()), SLOT(OnReadyRead()));
  ret = ret && connect(socket, SIGNAL(disconnected()), SLOT(OnDisconnected()));
  assert(ret);
  m_sockets.insert(socket);
}
Esempio n. 2
0
  // TODO: use exceptions
  bool Irc::Run()
  {
    if (!Connect())
    {
      return false;
    }

    connect(&m_socket, SIGNAL(readyRead()), this, SLOT(OnReadyRead()));
    m_eventloop.exec();

    // Start delivering messages from the queue
    m_message_queue->Process();

    return true;
  }
Esempio n. 3
0
void TMsgCore::OnReadyRead()  // server side
{
  std::set<QTcpSocket *>::iterator it = m_sockets.begin();
  for (; it != m_sockets.end(); it++)  // devo scorrerli tutti perche' non so da
                                       // quale socket viene il messaggio...
  {
    if ((*it)->state() == QTcpSocket::ConnectedState &&
        (*it)->bytesAvailable() > 0)
      break;
  }
  if (it != m_sockets.end()) {
    readFromSocket(*it);
    OnReadyRead();
  }
}
Esempio n. 4
0
bool NetworkConnection::openConnection(const QString & host, const unsigned short port, bool not_main_connection)
{	
	qsocket = new QTcpSocket();	//try with no parent passed for now
	if(!qsocket)
		return 0;
	//connect signals
	
	//connect(qsocket, SIGNAL(hostFound()), SLOT(OnHostFound()));
	connect(qsocket, SIGNAL(connected()), SLOT(OnConnected()));
	connect(qsocket, SIGNAL(readyRead()), SLOT(OnReadyRead()));
	connect(qsocket, SIGNAL(disconnected ()), SLOT(OnConnectionClosed()));
//	connect(qsocket, SIGNAL(delayedCloseFinished()), SLOT(OnDelayedCloseFinish()));
//	connect(qsocket, SIGNAL(bytesWritten(qint64)), SLOT(OnBytesWritten(qint64)));
    connect(qsocket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(OnError(QAbstractSocket::SocketError)));

	if(qsocket->state() != QTcpSocket::UnconnectedState)
	{
		qDebug("Called openConnection while in state %d", qsocket->isValid());
		return 0;
	}
	//remove asserts later
	Q_ASSERT(host != 0);
	Q_ASSERT(port != 0);

	if(!not_main_connection)
		drawPleaseWait();

	qDebug("Connecting to %s %d...\n", host.toLatin1().constData(), port);
	// assume info.host is clean
	qsocket->connectToHost(host, (quint16) port);
	
	/* If dispatch does not have a UI, the thing that sets the UI
	 * will setupRoomAndConsole */
	/* Tricky now without dispatches... who sets up the UI?
	 * there's always a mainwindow... but maybe things aren't setup? */
	
	/* connectionInfo as a message with those pointers is probably a bad idea */
	return (qsocket->state() != QTcpSocket::UnconnectedState);
}
Esempio n. 5
0
/**
 * At construction time, we want to listen to a tcp socket and emit a signal
 * when reading is finished.
 *
 * @param socket -- The socket to construct message from.
 * @param target -- The target canceller/receiver.
 *
 * @version
 * - JR Lewis      pre-2012.02.08
 *   - Initial version.
 * - JR Lewis      2012.02.08
 *   - Bringing this into the net project.
 * - JR Lewis      2012.02.13
 *   - Adding target.
 */
MessageAssembler::MessageAssembler(QTcpSocket& socket, QObject* target)
: QObject(0)
, socket(socket)
, block_size(0)
, cancel(false)
{
    bool r = QObject::connect( &socket
                             , SIGNAL(readyRead())
                             , this
                             , SLOT(OnReadyRead()));
    assert(r);

    r = QObject::connect( target
                        , SIGNAL(CancelTimer())
                        , this
                        , SLOT(OnCancel()));
    assert(r);

    r = QObject::connect( this
                        , SIGNAL(MessageConstructed(QString const&))
                        , target
                        , SLOT(OnMessageConstructed(QString const&)));
    assert(r);
}
Esempio n. 6
0
//--------------------------------------------------------------------------------------
// Mwars::Mwars()
// the Constructor
//--------------------------------------------------------------------------------------
Mwars::Mwars(QWidget *parent) : QMainWindow(parent), ui(new Ui::mwarsForm)  {

    ui->setupUi(this);  // Ui:mwarsForm ui

    //*********** two timers
    QTimer *keepServerAliveTimer = new QTimer(this);  // instantiate timer
    QTimer *testTimer = new QTimer(this);


    // a. TCP stream to scanner server
    // clientSocket: client socket sends stream to scanner. clientSocket already exists
    // Q_SIGNALS signals emitted by socket  unimplemented: void hostFound() void connected()
    connect( &clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
            this, SLOT(clientSocketError(QAbstractSocket::SocketError)) );
    connect( &clientSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
            this, SLOT(clientSocketState(QAbstractSocket::SocketState)) );

    connect( &clientSocket, SIGNAL(readyRead()),this, SLOT(OnReadyRead()) );
    connect( &clientSocket, SIGNAL(disconnected()), this, SLOT(disconnectedz()) );

    // b. UDP stream from opencv / camera
    listenSocket = new QUdpSocket ( this );
    listenSocket->bind(9988 );
    connect( listenSocket, SIGNAL(readyRead()),this, SLOT(OnReadyRead()) );

    //signals from within code
    connect( this, SIGNAL(connectScanner()), this, SLOT(connectToScanner()));  // Constructor
    connect( keepServerAliveTimer, SIGNAL(timeout()), this, SLOT(keepServerAlive()));

//    connect( testTimer, SIGNAL(timeout()), this, SLOT(testSignal()));

    // signals from ui
    connect( ui->xSlider, SIGNAL(valueChanged(int)), this, SLOT(sendScanCmd()));
    connect( ui->ySlider, SIGNAL(valueChanged(int)), this, SLOT(sendScanCmd()));
    connect( ui->spinboxXCamTrim, SIGNAL(valueChanged(int)), this, SLOT(sendScanCmd()));
    connect( ui->spinboxYCamTrim, SIGNAL(valueChanged(int)), this, SLOT(sendScanCmd()));

    //connect( ui->pbLaserToggle, SIGNAL(clicked()), this, SLOT(laserToggle()));
    connect( ui->pushButtonLaserDisableToggle, SIGNAL(clicked()), this, SLOT(laserDisableToggle()));
    connect( ui->pushButtonScannerToggle, SIGNAL(clicked()), this, SLOT(scannerToggle()));
    connect( ui->pushButtonConnect, SIGNAL(clicked()), this, SLOT(connectToScanner()));
    connect( ui->radioButtonVerboseOn, SIGNAL(clicked()), this, SLOT(verboseOn()));
    connect( ui->radioButtonVerboseOff, SIGNAL(clicked()), this, SLOT(verboseOff()));
    connect( ui->pushButtonResetScanner, SIGNAL(clicked()), this, SLOT(resetScanner()));
    connect( ui->pushButtonCameraDataToggle, SIGNAL(clicked()), this, SLOT(cameraDataToggle()));
    connect( ui->pushButtonTestDataToggle, SIGNAL(clicked()), this, SLOT(testDataToggle()));
    //connect( ui->pbAlignBS, SIGNAL(clicked()), this, SLOT(alignBoresight()));

    connect( ui->pbCalibrateToggle, SIGNAL(clicked()), this, SLOT(calibrateToggle()));
    connect( ui->pbCalSetULHC, SIGNAL(clicked()), this, SLOT(calSetULHC()));
    connect( ui->pbCalSetLRHC, SIGNAL(clicked()), this, SLOT(calSetLRHC()));
    connect( ui->pbCalFullFrame, SIGNAL(clicked()), this, SLOT(calFullFrame()));
    connect( ui->pbCalHalfFrame, SIGNAL(clicked()), this, SLOT(calHalfFrame()));

    connect( ui->spinboxXCamTrim, SIGNAL(valueChanged(int)), this, SLOT(xCamTrim()));
    connect( ui->spinboxYCamTrim, SIGNAL(valueChanged(int)), this, SLOT(yCamTrim()));
    connect( ui->pbCamTrimOffset, SIGNAL(clicked()), this, SLOT(camTrimOffset()));

    connect( ui->sbXCamOffset, SIGNAL(valueChanged(int)), this, SLOT(xCamOffset()));
    connect( ui->sbYCamOffset, SIGNAL(valueChanged(int)), this, SLOT(yCamOffset()));
    connect( ui->pbCamOffset, SIGNAL(clicked()), this, SLOT(camScanOffset()));

    connect( ui->pbCalLaserBsight, SIGNAL(clicked()), this, SLOT(alignBoresight()));
    //connect( this, SIGNAL (testSignal()), this, SLOT (testSignal()));


    // temporary stuff to test parallax offset
    g_xLenWallFOV_mm = (1310 * 2);  // measured width, x axis, of FOV at target distance = range (mm)
    g_yLenWallFOV_mm = (975 * 2);
    g_xSF_pixelTomm =  (float)g_xLenWallFOV_mm / CAMERA_X_PIXELS;
    g_ySF_pixelTomm =  (float)g_yLenWallFOV_mm / CAMERA_Y_PIXELS;
    range_mm         = 2750;          // measured range cam to target (mm)


    //overwritten when cam file is read
    g_xScanFOVOrigin_su = DAC_X_MIN;		// scanner origin corresponding to x_camFOVOrigin (scan units)
    g_xScanFOVMax_su    = DAC_X_MAX;		// scanner max x corresponding to x_camFOVMax (scan units)

    // read camera to scanner calibration file. This reads the calibration parameters
    // and sets main slider and spin box values
    readXMLFile();

    ui->spinboxXCamTrim->setRange(-5000, +5000);
    ui->spinboxYCamTrim->setRange(-5000, +5000);
    ui->radioButtonVerboseOff->setChecked(true);

    clearStateWidets();				// clear Server State widget text

#ifdef FORCE_ENABLE_WIDGETS
    enableWidgets();
#else
     disableWidgets();				// control widgets get enabled when connected
#endif

    verbose = false;                // verbose OFF
    laserOnFlag = false;
    testDataEnableFlag = false;     // set by TestData button to turn on test data stream
    cameraDataEnableFlag = false;   // set by Camera Data button to turn on OpenCVcamera data stream
    laserDisableFlag = false;       // set by Laser On/Off button
    scannerOnFlag = false;          // set by Scanner On/Off button
    tcpConnected = false;           // tcp connected
    serverReady = false;
    calibrateFlag = false;

    setWindowTitle(tr("MWARS SCANNER CONSOLE"));



    // =================== start scannerserver comms ===============================
    //  a) UDP stream of co-ords and laser command from OpenCV Project mwars
    //  b) TCP connection to server in the scanner unit

    // 1. connect to the TCP server in the laser scanner unit
    emit connectScanner();              //runs connectToScanner


    // ==================== timers ==================================
    // start the keep alivetimer. Used to get response to update Console
    keepServerAliveTimer->start(1000);  //1000 = 1 sec

    //start the test signal timer for testSignal()
    // 1000 = 1 sec, 1 = 1mS
    //testTimer->start(100);             // 5 Hz
    //testTimer->start(10);              // 50 Hz
    //testTimer->start(20);              // 25 Hz
    // testTimer->start(60);              //  8 Hz
    // testTimer->start(50);              //  10 Hz

    sendScanCmd();     // init scanner, slew to slider values

    rectangleIsRunning = false;
}
CBasicListener::CBasicListener()
{
    connect(this, SIGNAL(readyRead()), SLOT(OnReadyRead()));
}