Esempio n. 1
0
DVD_RESP_TYPE CDVDongleController::getResponse(unsigned char* buffer, unsigned int length)
{
	wxASSERT(buffer != NULL);
	wxASSERT(length >= DVD_AUDIO_LENGTH_BYTES);

	unsigned char c1, c2;
	int len = m_controller->read(&c1, 1U);
	if (len == 0)
		return DVDRT_NONE;

	if (len < 0) {
		wxLogError(wxT("Unable to receive the DVD header: len=%d"), len);
		return DVDRT_ERROR;
	}

	switch (c1) {
		case 0xA0U:		// DVD_AMBE_HEADER
			wxLogMessage(wxT("Re-synchronising with the DV-Dongle"));
			buffer[0U] = 0x32U;
			buffer[1U] = c1;
			return processResponse(buffer, length);

		case 0x81U:		// DVD_AUDIO_HEADER
			wxLogMessage(wxT("Re-synchronising with the DV-Dongle"));
			buffer[0U] = 0x42U;
			buffer[1U] = c1;
			return processResponse(buffer, length);

		default:
			m_controller->read(&c2, 1U);
			buffer[0U] = c1;
			buffer[1U] = c2;
			return processResponse(buffer, length);
	}
}
Esempio n. 2
0
void LocalClient::run()
{
    QLocalSocket *socket = new QLocalSocket(this);
    socket->connectToServer("/tmp/testservice");
    if (!socket->waitForConnected()) {
        qDebug() << "could not connect to server: " << socket->errorString();
        return;
    }

    m_client = new QJsonRpcSocket(socket, this);
    QJsonRpcServiceReply *reply = m_client->invokeRemoteMethod("agent.testMethod");
    connect(reply, SIGNAL(finished()), this, SLOT(processResponse()));

    reply = m_client->invokeRemoteMethod("agent.testMethodWithParams", "one", false, 10);
    connect(reply, SIGNAL(finished()), this, SLOT(processResponse()));

    reply = m_client->invokeRemoteMethod("agent.testMethodWithVariantParams", "one", false, 10, QVariant(2.5));
    connect(reply, SIGNAL(finished()), this, SLOT(processResponse()));

    reply = m_client->invokeRemoteMethod("agent.testMethodWithParamsAndReturnValue", "matt");
    connect(reply, SIGNAL(finished()), this, SLOT(processResponse()));

    // test bulk messages
    /*
    QJsonRpcMessage first = QJsonRpcMessage::createRequest("agent.testMethodWithParamsAndReturnValue", "testSendMessage");
    m_client->sendMessage(first);

    QJsonRpcMessage second = QJsonRpcMessage::createRequest("agent.testMethodWithParamsAndReturnValue", "testSendMessages1");
    QJsonRpcMessage third = QJsonRpcMessage::createRequest("agent.testMethodWithParamsAndReturnValue", "testSendMessages2");
    m_client->sendMessage(QList<QJsonRpcMessage>() << second << third);
    */
}
Esempio n. 3
0
	void PowerMonitor::applyDefaultSettings() // U, note:  CE must be disabled before sending U, and reenabled afterwards			
	{
	//_cell << "AT+CGREG?" <<  crl << endl;
	Serial << "CE0" <<crl;// stop CE
	processResponse("CE0");
	Serial << ")U" <<crl;// apply defaults
	processResponse(")U");
	Serial << "CE1" <<crl;// start CE
	processResponse("CE1");
	Serial.flush();
	}
Esempio n. 4
0
	int PowerMonitor::iMaxSet(int channel,double value)	// set the external RMS current corresponding to 250 mVpk input of the ADC (A2)(A4)
	{
	switch (channel)
		{
		case 1: // first channel
			Serial << ")A2=+" << value <<crl;// set current when ADC reads maximum
			return int(processResponse(")A2"));
			// process response	and determine return value
		break;
		case 2: // second channel
			Serial << ")A4=+" << value <<crl;// set current when ADC reads maximum
			return int(processResponse(")A4"));
		break;
		}	
	}
Esempio n. 5
0
	//********************************************************************************************************//
	//											Multi channel coommands
	//********************************************************************************************************//
	double PowerMonitor::Temperature(int channel) // returns temperature of internals  (20),(60)
	{
	switch(channel)
		{
		case 1:
			Serial << ")20?" << crl;// get channel 1 temperature
			return processResponse(")20")+22;
		break;
		
		case 2:
			Serial << ")60?" << crl;// get channel 2 temperature
			return processResponse(")60")+22;
		break;
		}
	}
Esempio n. 6
0
	double PowerMonitor::power(int channel) // returns active power second +WWW.www (27) (67)
	{
	switch(channel)
		{
		case 1:
			Serial << ")27?" << crl;// get channel 1
			return processResponse(")27");
		break;
		
		case 2:
			Serial << ")67?" << crl;// get channel 2
			return processResponse(")67");
		break;
		}
	}
Esempio n. 7
0
	double PowerMonitor::powerFactor(int channel) // returns the power factor between -0.950 and 1 (2D) (6D)
	{
	switch(channel)
		{
		case 1:
			Serial << ")2D?" << crl;// get channel 1
			return processResponse(")2D");
		break;
		
		case 2:
			Serial << ")6D?" << crl;// get channel 2
			return processResponse(")6D");
		break;
		}
	}
Esempio n. 8
0
	double PowerMonitor::irms(int channel) // returns rms Current +III.iii (2A) (6A)
	{
	switch(channel)
		{
		case 1:
			Serial << ")2A?" << crl;// get channel 1
			return processResponse(")2A");
		break;
		
		case 2:
			Serial << ")6A?" << crl;// get channel 2
			return processResponse(")6A");
		break;
		}
	}
Esempio n. 9
0
void TTRssFetcher::finishedSignIn()
{
    Settings *s = Settings::instance();
    if (!processResponse()) {
        s->setSignedIn(false);
        sessionId = "";
        apiLevel = 0;
        return;
    } else {
        s->setSignedIn(true);
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
        sessionId = jsonObj["content"].toObject()["session_id"].toString();
        apiLevel = jsonObj["content"].toObject()["api_level"].toInt();
#else
        sessionId = jsonObj["content"].toMap()["session_id"].toString();
        apiLevel = jsonObj["content"].toMap()["api_level"].toInt();
#endif
        if (busyType == Fetcher::CheckingCredentials) {
            emit credentialsValid();
            setBusy(false);
        } else {
            sendApiCall("getConfig", FETCHER_SLOT(finishedConfig));
        }
    }
}
Esempio n. 10
0
void WiFlyRNXV::listenAndProcess(){
	uint8_t resp=0;
	
	if(uart.available()){
		if(checkBufferResponse(NULL,5000)){
			Serial.println("TCP OPEN");
			Serial.print("RESP:");
			resp=processResponse(true);
			Serial.println(resp,DEC);
			Serial.print("RECV:");
			responseBuffer.trim();
			Serial.println(responseBuffer);
			
			//Send some data
			uart.println(processActualResponse(resp));
			
			if(checkBufferResponse("*CLOS*",5000)){
				Serial.println("TCP CLOSE");
			}

		}
		
	}
	
	
}
Esempio n. 11
0
void EPDStreamer::post(const char *host, const char *path, const char *data)
{
    if (connState != STATE_CONN_CONNECTED) {
        return;
    }

    Serial.print("POST ");
    Serial.print(path);
    Serial.print(" data=");
    Serial.println(data);

    client.print("POST ");
    client.print(path);
    client.println(" HTTP/1.0");
    client.print("Host: ");
    client.println(host);
    client.println("Connection: close");
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.print("Content-Length: ");
    client.println(strlen(data));
    client.println();
    client.print(data);

    httpState = STATE_HTTP_HEADER_STATUS;

    processResponse();
}
Esempio n. 12
0
Controller::Controller()
    try
        : num_connect_attempts_ { 2 },
          response_schema_ { getResponseMessageSchema() },
          connector_ptr_ { new PCPClient::Connector { BROKER_URL,
                                                      CONTROLLER_CLIENT_TYPE,
                                                      CA,
                                                      CERT,
                                                      KEY } } {
    // Connector::registerMessageCallback()

    connector_ptr_->registerMessageCallback(
        response_schema_,
        [this](const PCPClient::ParsedChunks& parsed_chunks) {
            processResponse(parsed_chunks);
        });

    connector_ptr_->setPCPErrorCallback(
        [this](const PCPClient::ParsedChunks& parsed_chunks) {
            processError(parsed_chunks);
        });
} catch (PCPClient::connection_config_error& e) {
    std::string err_msg { "failed to configure the PCP Connector: " };
    throw controller_error { err_msg + e.what() };
}
Esempio n. 13
0
//read data on the arduino
int CQboduinoDriver::read(cereal::CerealPort *port, std::string& read, long timeout)
{
    std::string buf;

    try
    {
        if(!port->readBetween(&buf,INPUT_FLAG,OUTPUT_FLAG,timeout))
        {
            return -1;
        }
    }
    catch(const std::exception & e)
    {
        std::cerr<<"qboduino driver : exception while trying to read" << e.what();
        return -1;
    }

//check if packet is correct
    int code=processResponse((uint8_t*)buf.c_str(),buf.size(),read);

    if( code != 1) {
        read.clear();
    }

    return code;
}
Esempio n. 14
0
// Worker thread
void HttpClient::networkThreadAlone(HttpRequest* request, HttpResponse* response)
{
    increaseThreadCount();

    char responseMessage[RESPONSE_BUFFER_SIZE] = { 0 };
    processResponse(response, responseMessage);

    _schedulerMutex.lock();
    if (nullptr != _scheduler)
    {
        _scheduler->performFunctionInCocosThread([this, response, request]{
            const ccHttpRequestCallback& callback = request->getCallback();
            Ref* pTarget = request->getTarget();
            SEL_HttpResponse pSelector = request->getSelector();

            if (callback != nullptr)
            {
                callback(this, response);
            }
            else if (pTarget && pSelector)
            {
                (pTarget->*pSelector)(this, response);
            }
            response->release();
            // do not release in other thread
            request->release();
        });
    }
    _schedulerMutex.unlock();

    decreaseThreadCountAndMayDeleteThis();
}
Esempio n. 15
0
void Connection::readyRead()
{
    while (m_socket && m_socket->bytesAvailable()) {
        long length;
        {
            QByteArray data;
            char c;
            while(m_socket->getChar(&c)) {
                if(c==0) break;
                data.append(c);
            }
            length = data.toLong();
        }
        QByteArray data;
        while (data.length() <= length) {
            if (!data.isEmpty() && !m_socket->waitForReadyRead()) {
                return;
            }
            data += m_socket->read(length - data.length() + 1);
        }
        //kDebug() << data;

        QDomDocument doc;
        doc.setContent(data);
        if (doc.documentElement().tagName() == "init") {
            processInit(doc);
        } else if (doc.documentElement().tagName() == "response") {
            processResponse(doc);
        } else if (doc.documentElement().tagName() == "stream") {
            processStream(doc);
        } else {
            //kWarning() << "unknown element" << xml->name();
        }
    }
}
Esempio n. 16
0
int nuvotonTask(void * dummy)
{
    daemonize("nuvotonTask");

    allow_signal(SIGTERM);

    while(1)
    {
        int dataAvailable = 0;

        if (wait_event_interruptible(rx_wq, (RCVBufferStart != RCVBufferEnd)))
        {
            printk("wait_event_interruptible failed\n");
            continue;
        }

        if (RCVBufferStart != RCVBufferEnd)
            dataAvailable = 1;

        while (dataAvailable)
        {
            processResponse();

            if (RCVBufferStart == RCVBufferEnd)
                dataAvailable = 0;

            dprintk(150, "start %d end %d\n",  RCVBufferStart,  RCVBufferEnd);
        }
    }

    printk("nuvotonTask died!\n");

    return 0;
}
std::int32_t CmdAcknowledgeBailment::run(
    std::string server,
    std::string mynym,
    std::string hisnym,
    std::string mypurse)
{
    if (!checkServer("server", server)) { return -1; }

    if (!checkNym("mynym", mynym)) { return -1; }

    if (!checkNym("hisnym", hisnym)) { return -1; }

    std::string terms = inputText("Deposit instructions");
    if (0 == terms.size()) { return -1; }

    std::string response;
    {
        response = Opentxs::
                       Client()
                       .ServerAction()
                       .AcknowledgeBailment(
                           Identifier::Factory(mynym),
                           Identifier::Factory(server),
                           Identifier::Factory(hisnym),
                           Identifier::Factory(mypurse),
                           terms)
                       ->Run();
    }
    return processResponse(response, "acknowledge bailment");
}
Esempio n. 18
0
// Worker thread
void HttpClient::networkThreadAlone(HttpRequest* request)
{
    // Create a HttpResponse object, the default setting is http access failed
    HttpResponse *response = new (std::nothrow) HttpResponse(request);
    char errorBuffer[CURL_ERROR_SIZE] = { 0 };
    processResponse(response, errorBuffer);

    auto scheduler = Director::getInstance()->getScheduler();
    scheduler->performFunctionInCocosThread([response, request]{
        const ccHttpRequestCallback& callback = request->getCallback();
        Ref* pTarget = request->getTarget();
        SEL_HttpResponse pSelector = request->getSelector();

        if (callback != nullptr)
        {
            callback(s_pHttpClient, response);
        }
        else if (pTarget && pSelector)
        {
            (pTarget->*pSelector)(s_pHttpClient, response);
        }
        response->release();
        // do not release in other thread
        request->release();
    });
}
Esempio n. 19
0
void TTRssFetcher::finishedCategories()
{
    if (!processResponse()) {
        return;
    }

    startJob(StoreCategories);
}
Esempio n. 20
0
void TTRssFetcher::finishedFeeds()
{
    if (!processResponse()) {
        return;
    }

    startJob(StoreFeeds);
}
Esempio n. 21
0
void TTRssFetcher::finishedStream()
{
    if (!processResponse()) {
        return;
    }

    startJob(StoreStream);
}
Esempio n. 22
0
	double PowerMonitor::lineFrequency(int channel) // returns line freq in Hz.hz (21)(61)
	{
	double returnvalue ;
	switch(channel)
		{
		case 1:
			Serial << ")21?" << crl;// get channel 1 temperature
			 returnvalue = processResponse(")21");
			return returnvalue;
		break;
		
		case 2:
			Serial << ")61?" << crl;// get channel 2 temperature
			 returnvalue = processResponse(")61");
			return returnvalue;
		break;
		}
	}
Esempio n. 23
0
void ofxTwitter::newResponse(ofxHttpResponse &response) {
    data = processResponse(response);
	
	// ok, send back results
	if (delegate) {
		delegate->searchResult(data, tweetQueryIdentifier);
	}
	
}
Esempio n. 24
0
void		Client::listenFds(fd_set *bitField)
{
  if (select((_socket > 0 ? _socket : 0) + 1, bitField, NULL, NULL, NULL) == -1)
    throw std::exception();
  if (FD_ISSET(STDIN_FILENO, bitField))
    request_server();
  else if (FD_ISSET(_socket, bitField))
    processResponse();
}
Esempio n. 25
0
	double PowerMonitor::vrms(int channel) // returns rms Voltage +VVV.vvv (26) (66)		
	{
	double returnvalue;
	switch(channel)
		{
		case 1:
			Serial << ")26?" << crl;// get channel 1
			returnvalue = processResponse(")26");
			return returnvalue;
		break;
		
		case 2:
			Serial << ")66?" << crl;// get channel 2
			returnvalue = processResponse(")66");
			return returnvalue;
		break;
		}
	}	
Esempio n. 26
0
// Worker thread
void HttpClient::networkThread()
{
    increaseThreadCount();

    while (true)
    {
        HttpRequest *request;

        // step 1: send http request if the requestQueue isn't empty
        {
            std::lock_guard<std::mutex> lock(_requestQueueMutex);
            while (_requestQueue.empty())
            {
                _sleepCondition.wait(_requestQueueMutex);
            }
            request = _requestQueue.at(0);
            _requestQueue.erase(0);
        }

        if (request == _requestSentinel) {
            break;
        }

        // step 2: libcurl sync access
        
        // Create a HttpResponse object, the default setting is http access failed
        HttpResponse *response = new (std::nothrow) HttpResponse(request);

        processResponse(response, _responseMessage);


        // add response packet into queue
        _responseQueueMutex.lock();
        _responseQueue.pushBack(response);
        _responseQueueMutex.unlock();

        _schedulerMutex.lock();
        if (nullptr != _scheduler)
        {
            _scheduler->performFunctionInCocosThread(CC_CALLBACK_0(HttpClient::dispatchResponseCallbacks, this));
        }
        _schedulerMutex.unlock();
    }
    
    // cleanup: if worker thread received quit signal, clean up un-completed request queue
    _requestQueueMutex.lock();
    _requestQueue.clear();
    _requestQueueMutex.unlock();

    _responseQueueMutex.lock();
    _responseQueue.clear();
    _responseQueueMutex.unlock();

    decreaseThreadCountAndMayDeleteThis();
}
Esempio n. 27
0
// Worker thread
void HttpClient::networkThread()
{    
    auto scheduler = Director::getInstance()->getScheduler();
    
    while (true) 
    {
        HttpRequest *request;

        // step 1: send http request if the requestQueue isn't empty
        {
            std::lock_guard<std::mutex> lock(s_requestQueueMutex);
            while (s_requestQueue->empty()) {
                s_SleepCondition.wait(s_requestQueueMutex);
            }
            request = s_requestQueue->at(0);
            s_requestQueue->erase(0);
        }

        if (request == s_requestSentinel) {
            break;
        }

        // step 2: libcurl sync access
        
        // Create a HttpResponse object, the default setting is http access failed
        HttpResponse *response = new (std::nothrow) HttpResponse(request);
        
        processResponse(response, s_errorBuffer);
        

        // add response packet into queue
        s_responseQueueMutex.lock();
        s_responseQueue->pushBack(response);
        s_responseQueueMutex.unlock();
        
        if (nullptr != s_pHttpClient) {
            scheduler->performFunctionInCocosThread(CC_CALLBACK_0(HttpClient::dispatchResponseCallbacks, this));
        }
    }
    
    // cleanup: if worker thread received quit signal, clean up un-completed request queue
    s_requestQueueMutex.lock();
    s_requestQueue->clear();
    s_requestQueueMutex.unlock();
    
    
    if (s_requestQueue != nullptr) {
        delete s_requestQueue;
        s_requestQueue = nullptr;
        delete s_responseQueue;
        s_responseQueue = nullptr;
    }
    
}
Esempio n. 28
0
KeyExchangeMessage SessionBuilder::process(QSharedPointer<KeyExchangeMessage> message)
{
    if (!identityKeyStore->isTrustedIdentity(recipientId, message->getIdentityKey())) {
        throw UntrustedIdentityException(QString("Untrusted identity: %1").arg(recipientId));
    }

    KeyExchangeMessage responseMessage;

    if (message->isInitiate()) responseMessage = processInitiate(message);
    else                       processResponse(message);

    return responseMessage;
}
void HomeI2CMaster::read(uint8_t address, size_t messageSize, uint8_t messageID) {
  uint8_t bytesReceived;
  uint8_t retryCount = 0;
  bool retry = true;
  bool readSuccesful = true;
  I2CMessage response;
  DBUG_LOG(F("Receiving response: size, messageID"));
  DBUG_LOG(messageSize);
  DBUG_LOG(messageID);
  while (retry) {
    bytesReceived = 0;
    DBUG_LOG(F("Request Attempt:"));
    DBUG_LOG(retryCount+1);
    Wire.requestFrom(address, messageSize);
    DBUG_LOG(F("Response received"));
    while (Wire.available()) {
      if (bytesReceived == 0) {
        response.messageID = Wire.read();
        if (response.messageID != messageID) {
          DBUG_LOG(F("mesageID invalid. retrying"));
          DBUG_LOG(response.messageID);
          retryCount++;
          if (retryCount < I2C_TIMEOUT) {
            delay(I2C_TIMEOUT_DELAY);
          } else {
            ERROR_LOG(F("I2C Timeout"));
            readSuccesful = false;
            retry = false;
          }
        } else {
          DBUG_LOG(F("messageID valid:"));
          DBUG_LOG(response.messageID);
          retry = false;
        }
      } else {
        if (bytesReceived <= MAX_I2C_MESSAGE_SIZE) {
          response.buffer[bytesReceived-1] = Wire.read();
          DBUG_LOG(F("Data received:"));
          DBUG_LOG(response.buffer[bytesReceived-1], HEX);
        }
      }
      bytesReceived++;
    }
  }
  if (readSuccesful) {
    processResponse(response);
  } else {
    peripheral->sendMessageNack(messageID);
  }
}
Esempio n. 30
0
void TTRssFetcher::finishedConfig()
{
    if (!processResponse()) {
        return;
    }

#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
    iconsUrl = jsonObj["content"].toObject()["icons_url"].toString();
#else
    iconsUrl = jsonObj["content"].toMap()["icons_url"].toString();
#endif

    prepareUploadActions();
}