Ejemplo n.º 1
0
  void TriggerWait::process() {
    output()->clearTrigger();

    if (input(kWait)->source->triggered &&
        input(kTrigger)->source->triggered) {

      if (input(kWait)->source->trigger_offset <=
          input(kTrigger)->source->trigger_offset) {
        waitTrigger(input(kWait)->source->trigger_value);
        sendTrigger(input(kTrigger)->source->trigger_offset);
      }
      else {
        sendTrigger(input(kTrigger)->source->trigger_offset);
        waitTrigger(input(kWait)->source->trigger_value);
      }
    }
    else if (input(kWait)->source->triggered)
      waitTrigger(input(kWait)->source->trigger_value);
    else if (input(kTrigger)->source->triggered)
      sendTrigger(input(kTrigger)->source->trigger_offset);
  }
unsigned long UltrasonicProximitySensor::getDistanceInCm() const
{
  unsigned long ditance_in_cm = 0;
  sendTrigger();
  ditance_in_cm = waitEcho();

  if (ditance_in_cm <= 0 || ditance_in_cm > _max_distance_in_cm) {
    return 0;
  }

  return ditance_in_cm;
}
Ejemplo n.º 3
0
void Trigger::evalData(L1Data * data)
{
	if(symbol_ == data->symbol_)
	{
		l1Data_.push(data);

		if(buy(data))
		{
			sendTrigger(PurchaseData::Buy, data);
		}
		else if(sell(data))
		{
			sendTrigger(PurchaseData::Sell, data);
		}

		if(l1Data_.size() > 10)
		{
			L1Data * front = l1Data_.front();
			l1Data_.pop();
			delete front;
		}
	}
}
Ejemplo n.º 4
0
status_t WifiDisplaySource::onReceiveM4Response(
        int32_t sessionID, const sp<ParsedMessage> &msg) {
    int32_t statusCode;
    if (!msg->getStatusCode(&statusCode)) {
        return ERROR_MALFORMED;
    }

    if (statusCode != 200) {
        return ERROR_UNSUPPORTED;
    }

    if (mUsingHDCP && !mHDCPInitializationComplete) {
        ALOGI("Deferring SETUP trigger until HDCP initialization completes.");

        mSetupTriggerDeferred = true;
        return OK;
    }

    return sendTrigger(sessionID, TRIGGER_SETUP);
}
Ejemplo n.º 5
0
void qc::on_pushButton_3_clicked(){
  QLocale c(QLocale::C);
  bool flok;
  float fduration=1/(ui.lineEdit_5->displayText().toFloat(&flok));
  int duration=0,count=0;
  QString _dur=c.toString(fduration,'f',3);
  bool ok;
  int repetitions=ui.lineEdit_7->displayText().toInt(&ok);

  QStack<QChar> lilstack;
  for(QString::iterator beg=_dur.begin(); beg!=_dur.end(); beg++){
    if(*beg!=c.decimalPoint()){ 
      lilstack.push(*beg); 
      ++count;
    }
  }

  for(int a=0;a<count;a++){
    QChar q=lilstack.pop();
    int ds=q.digitValue();
    duration+=pow(10,a)*ds;
  }  

  QString msg=
    QString("*RST\n\r")+
    QString("FUNC ")+ui.comboBox->currentText().left(1)+QString("\n\r")+
    QString("AMPL ")+ui.lineEdit_2->displayText()+ui.comboBox_2->currentText()+QString("\n\r")+
    QString("OFFS ")+ui.lineEdit_6->displayText()+QString("\n\r")+
    QString("SDIR ")+ui.comboBox_3->currentText().left(1)+QString("\n\r")+
    QString("STYP ")+ui.comboBox_4->currentText().left(1)+QString("\n\r")+
    QString("SPFR ")+ui.lineEdit_4->displayText()+QString("\n\r")+
    QString("STFR ")+ui.lineEdit_3->displayText()+QString("\n\r")+
    QString("STRS 0\n\r")+QString("SWEN 1\n\r");

  if(ui.lineEdit_5->displayText().toInt()>1000){
    QMessageBox mb;
    mb.setWindowTitle(tr("Uruchamianie sweep"));
    mb.setStandardButtons(QMessageBox::Yes);
    mb.setText(tr("Uwaga! - nie mozna uruchomic sweepowania gesciej, niz 1 kHz! Czestotliwosc zostanie zmniejszona."));
    int ret=mb.exec();
    if(ret==QMessageBox::Yes){
      ui.lineEdit_5->setText("1000");
    }
  }
  
  msg+=QString("SRAT ")+ui.lineEdit_5->displayText()+QString("\n\r");
    
  QMessageBox messageBox;
  messageBox.setWindowTitle(tr("Uruchamianie portu sweep pojedyñczy"));
  messageBox.setText(msg);
  messageBox.exec();

  QTimer *xz=new QTimer(this);

  QFile file("SYNCHRO.dat");
  file.open(QIODevice::ReadWrite|QIODevice::Text); //Uwaga - w przypadku dziwnego zachowania zwróciæ uwagê na to, czy da siê otwieraæ ten plik
  QTextStream *syncdata=new QTextStream(&file);
  *syncdata<<duration<<"\n\r"<<_dur<<"\n\r"<<repetitions<<"\n\r";
  QTime t;
  
  if(_connset){
    QWPORT(msg.toStdString().c_str());
    for(int a=0;a<repetitions;a++){
      *syncdata<<(t.toString("hh:mm:ss:zzz\n\r"));
      xz->singleShot(duration,this,SLOT(sendTrigger()));
    }
  }
  file.close();
}
Ejemplo n.º 6
0
int main(){

	int read_nodes[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
	int write_nodes[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 , 11, 12, 13, 14, 15};
	int num_samples = 32767; // use 16383 for 16K buffer
	int host_id = 210; // 10.0.0.210 is the IP address of host
	int numNodeRange = 16;

	double readLatency[numNodeRange];
	double writeLatency[numNodeRange];

	int numNodes;
	FILE *fpr, *fpw;
	fpr = fopen("../traces/read_time_new.dat", "w"); 
	fpw = fopen("../traces/write_time_new.dat", "w"); 


	for (numNodes = 1; numNodes <= numNodeRange; numNodes++){

		int arr_node_sock[numNodes];

		// first initialize the sockets 
		nodes_initialize(arr_node_sock, numNodes);
		printf("-------nodes intialiazed------------\n");

		sendTrigger(); // send trigger before reading buffers
		
		readLatency[numNodes] = measureLatency(numNodes, num_samples, arr_node_sock, read_nodes, host_id, multi_read);

		printf(" Read latency [Nodes=%d] = %2.2f \n", numNodes, readLatency[numNodes]);

		// close all opened sockets
		nodes_disable(arr_node_sock, numNodes);
		printf("-------nodes closed------------\n");

		fprintf(fpr, "%d \t %2.4f\n", numNodes, readLatency[numNodes]);
	} 	

	fclose(fpr);

	for (numNodes = 1; numNodes <= numNodeRange; numNodes++){

		int arr_node_sock[numNodes];

		// first initialize the sockets 
		nodes_initialize(arr_node_sock, numNodes);
		printf("-------nodes intialiazed------------\n");
		
		writeLatency[numNodes] = measureLatency(numNodes, num_samples, arr_node_sock, read_nodes, host_id, multi_write);

		sendTrigger(); // send trigger after writing 

		printf(" Write latency [Nodes=%d] = %2.2f \n", numNodes, writeLatency[numNodes]);

		// close all opened sockets
		nodes_disable(arr_node_sock, numNodes);
		printf("-------nodes closed------------\n");

		fprintf(fpw, "%d \t %2.4f\n", numNodes, writeLatency[numNodes]);
	} 

	fclose(fpw);

	return 0;
}
Ejemplo n.º 7
0
void WifiDisplaySource::onMessageReceived(const sp<AMessage> &msg) {
    switch (msg->what()) {
        case kWhatStart:
        {
            sp<AReplyToken> replyID;
            CHECK(msg->senderAwaitsResponse(&replyID));

            AString iface;
            CHECK(msg->findString("iface", &iface));

            status_t err = OK;

            ssize_t colonPos = iface.find(":");

            unsigned long port;

            if (colonPos >= 0) {
                const char *s = iface.c_str() + colonPos + 1;

                char *end;
                port = strtoul(s, &end, 10);

                if (end == s || *end != '\0' || port > 65535) {
                    err = -EINVAL;
                } else {
                    iface.erase(colonPos, iface.size() - colonPos);
                }
            } else {
                port = kWifiDisplayDefaultPort;
            }

            if (err == OK) {
                if (inet_aton(iface.c_str(), &mInterfaceAddr) != 0) {
                    sp<AMessage> notify = new AMessage(kWhatRTSPNotify, this);

                    err = mNetSession->createRTSPServer(
                            mInterfaceAddr, port, notify, &mSessionID);
                } else {
                    err = -EINVAL;
                }
            }

            mState = AWAITING_CLIENT_CONNECTION;

            sp<AMessage> response = new AMessage;
            response->setInt32("err", err);
            response->postReply(replyID);
            break;
        }

        case kWhatRTSPNotify:
        {
            int32_t reason;
            CHECK(msg->findInt32("reason", &reason));

            switch (reason) {
                case ANetworkSession::kWhatError:
                {
                    int32_t sessionID;
                    CHECK(msg->findInt32("sessionID", &sessionID));

                    int32_t err;
                    CHECK(msg->findInt32("err", &err));

                    AString detail;
                    CHECK(msg->findString("detail", &detail));

                    ALOGE("An error occurred in session %d (%d, '%s/%s').",
                          sessionID,
                          err,
                          detail.c_str(),
                          strerror(-err));

                    mNetSession->destroySession(sessionID);

                    if (sessionID == mClientSessionID) {
                        mClientSessionID = 0;

                        mClient->onDisplayError(
                                IRemoteDisplayClient::kDisplayErrorUnknown);
                    }
                    break;
                }

                case ANetworkSession::kWhatClientConnected:
                {
                    int32_t sessionID;
                    CHECK(msg->findInt32("sessionID", &sessionID));

                    if (mClientSessionID > 0) {
                        ALOGW("A client tried to connect, but we already "
                              "have one.");

                        mNetSession->destroySession(sessionID);
                        break;
                    }

                    CHECK_EQ(mState, AWAITING_CLIENT_CONNECTION);

                    CHECK(msg->findString("client-ip", &mClientInfo.mRemoteIP));
                    CHECK(msg->findString("server-ip", &mClientInfo.mLocalIP));

                    if (mClientInfo.mRemoteIP == mClientInfo.mLocalIP) {
                        // Disallow connections from the local interface
                        // for security reasons.
                        mNetSession->destroySession(sessionID);
                        break;
                    }

                    CHECK(msg->findInt32(
                                "server-port", &mClientInfo.mLocalPort));
                    mClientInfo.mPlaybackSessionID = -1;

                    mClientSessionID = sessionID;

                    ALOGI("We now have a client (%d) connected.", sessionID);

                    mState = AWAITING_CLIENT_SETUP;

                    status_t err = sendM1(sessionID);
                    CHECK_EQ(err, (status_t)OK);
                    break;
                }

                case ANetworkSession::kWhatData:
                {
                    status_t err = onReceiveClientData(msg);

                    if (err != OK) {
                        mClient->onDisplayError(
                                IRemoteDisplayClient::kDisplayErrorUnknown);
                    }

#if 0
                    // testing only.
                    char val[PROPERTY_VALUE_MAX];
                    if (property_get("media.wfd.trigger", val, NULL)) {
                        if (!strcasecmp(val, "pause") && mState == PLAYING) {
                            mState = PLAYING_TO_PAUSED;
                            sendTrigger(mClientSessionID, TRIGGER_PAUSE);
                        } else if (!strcasecmp(val, "play")
                                    && mState == PAUSED) {
                            mState = PAUSED_TO_PLAYING;
                            sendTrigger(mClientSessionID, TRIGGER_PLAY);
                        }
                    }
#endif
                    break;
                }

                case ANetworkSession::kWhatNetworkStall:
                {
                    break;
                }

                default:
                    TRESPASS();
            }
            break;
        }

        case kWhatStop:
        {
            CHECK(msg->senderAwaitsResponse(&mStopReplyID));

            CHECK_LT(mState, AWAITING_CLIENT_TEARDOWN);

            if (mState >= AWAITING_CLIENT_PLAY) {
                // We have a session, i.e. a previous SETUP succeeded.

                status_t err = sendTrigger(
                        mClientSessionID, TRIGGER_TEARDOWN);

                if (err == OK) {
                    mState = AWAITING_CLIENT_TEARDOWN;

                    (new AMessage(kWhatTeardownTriggerTimedOut, this))->post(
                            kTeardownTriggerTimeouSecs * 1000000ll);

                    break;
                }

                // fall through.
            }

            finishStop();
            break;
        }

        case kWhatPause:
        {
            sp<AReplyToken> replyID;
            CHECK(msg->senderAwaitsResponse(&replyID));

            status_t err = OK;

            if (mState != PLAYING) {
                err = INVALID_OPERATION;
            } else {
                mState = PLAYING_TO_PAUSED;
                sendTrigger(mClientSessionID, TRIGGER_PAUSE);
            }

            sp<AMessage> response = new AMessage;
            response->setInt32("err", err);
            response->postReply(replyID);
            break;
        }

        case kWhatResume:
        {
            sp<AReplyToken> replyID;
            CHECK(msg->senderAwaitsResponse(&replyID));

            status_t err = OK;

            if (mState != PAUSED) {
                err = INVALID_OPERATION;
            } else {
                mState = PAUSED_TO_PLAYING;
                sendTrigger(mClientSessionID, TRIGGER_PLAY);
            }

            sp<AMessage> response = new AMessage;
            response->setInt32("err", err);
            response->postReply(replyID);
            break;
        }

        case kWhatReapDeadClients:
        {
            mReaperPending = false;

            if (mClientSessionID == 0
                    || mClientInfo.mPlaybackSession == NULL) {
                break;
            }

            if (mClientInfo.mPlaybackSession->getLastLifesignUs()
                    + kPlaybackSessionTimeoutUs < ALooper::GetNowUs()) {
                ALOGI("playback session timed out, reaping.");

                mNetSession->destroySession(mClientSessionID);
                mClientSessionID = 0;

                mClient->onDisplayError(
                        IRemoteDisplayClient::kDisplayErrorUnknown);
            } else {
                scheduleReaper();
            }
            break;
        }

        case kWhatPlaybackSessionNotify:
        {
            int32_t playbackSessionID;
            CHECK(msg->findInt32("playbackSessionID", &playbackSessionID));

            int32_t what;
            CHECK(msg->findInt32("what", &what));

            if (what == PlaybackSession::kWhatSessionDead) {
                ALOGI("playback session wants to quit.");

                mClient->onDisplayError(
                        IRemoteDisplayClient::kDisplayErrorUnknown);
            } else if (what == PlaybackSession::kWhatSessionEstablished) {
                mPlaybackSessionEstablished = true;

                if (mClient != NULL) {
                    if (!mSinkSupportsVideo) {
                        mClient->onDisplayConnected(
                                NULL,  // SurfaceTexture
                                0, // width,
                                0, // height,
                                mUsingHDCP
                                    ? IRemoteDisplayClient::kDisplayFlagSecure
                                    : 0,
                                0);
                    } else {
                        size_t width, height;

                        CHECK(VideoFormats::GetConfiguration(
                                    mChosenVideoResolutionType,
                                    mChosenVideoResolutionIndex,
                                    &width,
                                    &height,
                                    NULL /* framesPerSecond */,
                                    NULL /* interlaced */));

                        mClient->onDisplayConnected(
                                mClientInfo.mPlaybackSession
                                    ->getSurfaceTexture(),
                                width,
                                height,
                                mUsingHDCP
                                    ? IRemoteDisplayClient::kDisplayFlagSecure
                                    : 0,
                                playbackSessionID);
                    }
                }

                finishPlay();

                if (mState == ABOUT_TO_PLAY) {
                    mState = PLAYING;
                }
            } else if (what == PlaybackSession::kWhatSessionDestroyed) {
                disconnectClient2();
            } else {
                CHECK_EQ(what, PlaybackSession::kWhatBinaryData);

                int32_t channel;
                CHECK(msg->findInt32("channel", &channel));

                sp<ABuffer> data;
                CHECK(msg->findBuffer("data", &data));

                CHECK_LE(channel, 0xff);
                CHECK_LE(data->size(), 0xffffu);

                int32_t sessionID;
                CHECK(msg->findInt32("sessionID", &sessionID));

                char header[4];
                header[0] = '$';
                header[1] = channel;
                header[2] = data->size() >> 8;
                header[3] = data->size() & 0xff;

                mNetSession->sendRequest(
                        sessionID, header, sizeof(header));

                mNetSession->sendRequest(
                        sessionID, data->data(), data->size());
            }
            break;
        }

        case kWhatKeepAlive:
        {
            int32_t sessionID;
            CHECK(msg->findInt32("sessionID", &sessionID));

            if (mClientSessionID != sessionID) {
                // Obsolete event, client is already gone.
                break;
            }

            sendM16(sessionID);
            break;
        }

        case kWhatTeardownTriggerTimedOut:
        {
            if (mState == AWAITING_CLIENT_TEARDOWN) {
                ALOGI("TEARDOWN trigger timed out, forcing disconnection.");

                CHECK(mStopReplyID != NULL);
                finishStop();
                break;
            }
            break;
        }

        case kWhatHDCPNotify:
        {
            int32_t msgCode, ext1, ext2;
            CHECK(msg->findInt32("msg", &msgCode));
            CHECK(msg->findInt32("ext1", &ext1));
            CHECK(msg->findInt32("ext2", &ext2));

            ALOGI("Saw HDCP notification code %d, ext1 %d, ext2 %d",
                    msgCode, ext1, ext2);

            switch (msgCode) {
                case HDCPModule::HDCP_INITIALIZATION_COMPLETE:
                {
                    mHDCPInitializationComplete = true;

                    if (mSetupTriggerDeferred) {
                        mSetupTriggerDeferred = false;

                        sendTrigger(mClientSessionID, TRIGGER_SETUP);
                    }
                    break;
                }

                case HDCPModule::HDCP_SHUTDOWN_COMPLETE:
                case HDCPModule::HDCP_SHUTDOWN_FAILED:
                {
                    // Ugly hack to make sure that the call to
                    // HDCPObserver::notify is completely handled before
                    // we clear the HDCP instance and unload the shared
                    // library :(
                    (new AMessage(kWhatFinishStop2, this))->post(300000ll);
                    break;
                }

                default:
                {
                    ALOGE("HDCP failure, shutting down.");

                    mClient->onDisplayError(
                            IRemoteDisplayClient::kDisplayErrorUnknown);
                    break;
                }
            }
            break;
        }

        case kWhatFinishStop2:
        {
            finishStop2();
            break;
        }

        default:
            TRESPASS();
    }
}
Ejemplo n.º 8
0
void ofApp::onCubeTriggered(vector <int>& args)
{
//    ofLog() << "cube object Triggered from sequencer";
    sendTrigger(args[0], args[1]);
}