Exemple #1
0
void ItemSyncTests::searchTags()
{
    const QString tab1 = testTab(1);
    const Args args = Args() << "tab" << tab1;
    RUN(Args(args) << "-e" << "plugins.itemtags.tags(0)", "");
    RUN(Args(args) << "add" << "A" << "B" << "C", "");
    RUN(Args(args) << "-e" << "plugins.itemtags.tag('x', 0, 1)", "");
    RUN(Args(args) << "-e" << "plugins.itemtags.tag('y', 1, 2)", "");
    RUN(Args(args) << "-e" << "plugins.itemtags.tag('z', 2)", "");
    RUN(Args(args) << "-e" << "plugins.itemtags.tags(0)", "x\n");
    RUN(Args(args) << "-e" << "plugins.itemtags.tags(1)", "x\ny\n");
    RUN(Args(args) << "-e" << "plugins.itemtags.tags(2)", "y\nz\n");

    RUN(Args(args) << "keys" << "RIGHT", "");
    RUN(Args(args) << "keys" << "x", "");
    waitFor(waitMsSearch);
    RUN(Args(args) << "keys" << "TAB" << "CTRL+A", "");
    RUN(Args(args) << "testselecteditems", "0\n1\n");

    RUN(Args(args) << "keys" << "ESCAPE", "");
    RUN(Args(args) << "keys" << "y", "");
    waitFor(waitMsSearch);
    RUN(Args(args) << "keys" << "TAB" << "CTRL+A", "");
    RUN(Args(args) << "testselecteditems", "1\n2\n");

    RUN(Args(args) << "keys" << "ESCAPE", "");
    RUN(Args(args) << "keys" << "z", "");
    waitFor(waitMsSearch);
    RUN(Args(args) << "keys" << "TAB" << "CTRL+A", "");
    RUN(Args(args) << "testselecteditems", "2\n");
}
Exemple #2
0
//parameters
//	temperature : temperature to read.
//	humidity : humidity to read.
//return -1 : read too shortly. retry latter .
//		  0 : read successfully
//        1 : DHT11 not ready.
//		  4 : Checksum Error
int DHT11::read(uint8_t& humidity, uint8_t& temperature) {
	if((millis()-this->last_read_time<DHT11_RETRY_DELAY)&&this->last_read_time!=0)	return -1;

	pinMode(pin,OUTPUT);
	digitalWrite(pin, LOW);
	delay(18);
	digitalWrite(pin, HIGH);
	pinMode(pin,INPUT);

	if(waitFor(LOW, 40)<0)	return 1; //waiting for DH11 ready
	if(waitFor(HIGH, 90)<0)	return 1; //waiting for first LOW signal(80us)
	if(waitFor(LOW, 90)<0)	return 1; //waiting for first HIGH signal(80us)

	byte hI=this->readByte();
	byte hF=this->readByte();
	byte tI=this->readByte();
	byte tF=this->readByte();
	byte cksum=this->readByte();
	if(hI+hF+tI+tF!=cksum)
		return 4;
	
	humidity = hI;
	temperature = tI;
	
	// Serial.println(hF);
	// Serial.println(tF);
	
	// humidity=(float)hI+(((float)hF)/100.0F);
	// temperature=(float)tI+(((float)tF)/100.0F);
	this->last_read_time=millis();
	return 0;
}
Exemple #3
0
//read one bye
byte DHT11::readByte() {
	int i=0;
	byte ret=0;
	for(i=7;i>=0;i--)
	{
		waitFor(HIGH); //wait for 50us in LOW status
		delayMicroseconds(30); //wait for 30us
		if(digitalRead(this->pin)==HIGH) //if HIGH status lasts for 30us, the bit is 1;
		{
			ret|=1<<(i);
			waitFor(LOW); //wait for rest time in HIGH status.
		}
	}
	return ret;
}
Exemple #4
0
ThreadPool::~ThreadPool() {
	requestTermination();
	waitFor(seconds(10));
	for (Thread *thread : _threads) {
		delete thread;
	}
}
void JNICALL Java_java_lang_Runtime_00024SubProcess_destroy0 (JNIEnv *env, jobject obj, jint handle) {
    if (waitFor(env, obj, handle)) return;

    TerminateProcess(
        (HANDLE) handle /* handle to the process */,
        ERROR_PROCESS_ABORTED /* exit code for the process */ );
}
Exemple #6
0
bool Sim900::getSignalQuality(int &strength, int &error_rate)
{
    if(lock())
    {
        _serial->write("AT+CSQ\r\n");
        _serial->flush();
        delay(100);
        String d;
        if(waitFor("OK", true, &d))
        {
            int _start = d.lastIndexOf("+CSQ");
            _start = d.indexOf(" ", _start) + 1;
            int split = d.indexOf(",", _start);
            int _end = d.indexOf("\r", _start);
            strength = d.substring(_start, split).toInt();
            error_rate = d.substring(split+1, _end).toInt();
            unlock();
            return true;
        } else
        {
            unlock();
        }
    }
    return false;
}
Exemple #7
0
int system_sleep_pin_impl(uint16_t wakeUpPin, uint16_t edgeTriggerMode, long seconds, uint32_t param, void* reserved)
{
    SYSTEM_THREAD_CONTEXT_SYNC(system_sleep_pin_impl(wakeUpPin, edgeTriggerMode, seconds, param, reserved));
    // If we're connected to the cloud, make sure all
    // confirmable UDP messages are sent before sleeping
    if (spark_cloud_flag_connected()) {
        Spark_Sleep();
    }

    bool network_sleep = network_sleep_flag(param);
    if (network_sleep)
    {
        network_suspend();
    }
    LED_Off(LED_RGB);
    HAL_Core_Enter_Stop_Mode(wakeUpPin, edgeTriggerMode, seconds);
    if (network_sleep)
    {
        network_resume();   // asynchronously bring up the network/cloud
    }
    // if single-threaded, managed mode then reconnect to the cloud (for up to 60 seconds)
    auto mode = system_mode();
    if (system_thread_get_state(nullptr)==spark::feature::DISABLED && (mode==AUTOMATIC || mode==SEMI_AUTOMATIC) && spark_cloud_flag_auto_connect()) {
        waitFor(spark_cloud_flag_connected, 60000);
    }

    if (spark_cloud_flag_connected()) {
        Spark_Wake();
    }
    return 0;
}
Exemple #8
0
std::map<uint64_t, const std::vector<uint8_t>*> PutCollector::errs()
{
    waitFor(m_expected);
    std::map<uint64_t, const std::vector<uint8_t>*> tmp;
    m_errs.swap(tmp);
    return tmp;
}
Exemple #9
0
uint8_t WaspUART::waitFor(	char* ans1, 
							char* ans2,
							char* ans3,  
							uint32_t timeout)
{
	return waitFor( ans1, ans2, ans3, NULL, timeout );	
}				
Exemple #10
0
bool Sim900::powerUp()
{
    if(SIM900_DEBUG_OUTPUT) {
        SIM900_DEBUG_OUTPUT_STREAM->println("Powering up Modem!");
    }
    if(!isPoweredUp())
    {
        //if(_ser != NULL)
        //{
        //	_ser->listen();
        //}
        powerToggle();
        if(waitFor("Call Ready", true, NULL))
        {
            return true;
        } else
        {
            if(isPoweredUp())
            {
                powerToggle();
            }
        }

    }
    return false;
}
Exemple #11
0
uint8_t WaspUART::waitFor(	char* ans1, 
							char* ans2, 
							char* ans3, 
							char* ans4)
{
	return waitFor( ans1, ans2, ans3, ans4, _def_timeout );	
}		
Exemple #12
0
void WiFiNode::removeAllNetworks() {
	if (!wpaCtrl) {
		DBGMSG_ERR("iface is closed");
		return;
	}
	char reply[1024] = {0};
	size_t replyLen = sizeof(reply) - 1;
	int reqRes = makeRequest("LIST_NETWORKS", reply, &replyLen);
	if (reqRes) {
		DBGMSG_ERR("Failed to list networks [%d]", reqRes);
	} else {
		int linesCount = 0;
		char *ptr = reply;
		bool active = strstr(reply, "CURRENT");
		while (ptr && (ptr = strstr(ptr+1, "\n"))) {
			linesCount++;
		}
		DBGMSG_M("Found [%d] networks", linesCount-1);
		if (linesCount > 1) {
			reqRes = makeRequest("REMOVE_NETWORK ALL", reply, &replyLen);
			if (active) {
				waitFor(WPA_EVENT_DISCONNECTED, 1000);
			}
		}
	}
}
Exemple #13
0
bool WiFiNode::scan() {
	if (!wpaCtrl) {
		DBGMSG_ERR("iface is closed");
		return false;
	}
	char reply[1024] = {0};
	size_t replyLen = sizeof(reply) - 1;

	int res = makeRequest("SCAN", reply, &replyLen);
	if (res || !strstr(reply, "OK")) {
		DBGMSG_ERR("Failed to start scanning [%d]", res);
		return false;
	}
	if (waitFor(WPA_EVENT_SCAN_RESULTS, 5000)) {
		DBGMSG_ERR("scanning failed");
		return false;
	}

	replyLen = sizeof(reply) - 1;
	res = makeRequest("SCAN_RESULTS", reply, &replyLen);
	if (res) {
		DBGMSG_ERR("Failed to get scanning results [%d]", res);
		return false;
	}

//	TODO: parse scan result here

	return true;
}
Exemple #14
0
std::map<uint64_t, std::string> GetCollector::errs()
{
    waitFor(m_expected);
    std::map<uint64_t, std::string> tmp;
    m_errs.swap(tmp);
    return tmp;
}
Exemple #15
0
STDMETHODIMP GuestSessionWrap::WaitFor(ULONG aWaitFor,
                                       ULONG aTimeoutMS,
                                       GuestSessionWaitResult_T *aReason)
{
    LogRelFlow(("{%p} %s:enter aWaitFor=%RU32 aTimeoutMS=%RU32 aReason=%p\n", this, "GuestSession::waitFor", aWaitFor, aTimeoutMS, aReason));

    VirtualBoxBase::clearError();

    HRESULT hrc;

    try
    {
        CheckComArgOutPointerValidThrow(aReason);

        AutoCaller autoCaller(this);
        if (FAILED(autoCaller.rc()))
            throw autoCaller.rc();

        hrc = waitFor(aWaitFor,
                      aTimeoutMS,
                      aReason);
    }
    catch (HRESULT hrc2)
    {
        hrc = hrc2;
    }
    catch (...)
    {
        hrc = VirtualBoxBase::handleUnexpectedExceptions(this, RT_SRC_POS);
    }

    LogRelFlow(("{%p} %s: leave aReason=%RU32 hrc=%Rhrc\n", this, "GuestSession::waitFor", *aReason, hrc));
    return hrc;
}
int main() {
    uint8_t position;
    uint8_t error;
    int code;

    printf("init : %d\n", initAXcomm(115200));

    code = axRead8(146, 0x05, &position, &error);
    printf("read8 : code = %d, error = %x, result = %d\n", code, error, position);
    while(1) {
        axWrite8(0xFE, 0x19, 1, &error);
        waitFor(500);
        axWrite8(0xFE, 0x19, 0, &error);
        waitFor(500);
    }
    return 0;
}
Exemple #17
0
void Thing1Class::reset()
{
	pinMode(_powerPin, OUTPUT);
	digitalWrite(_powerPin, LOW);
	delay(200);
	digitalWrite(_powerPin, HIGH);
	_serial->begin(_bitsPerSeconds);
	waitFor(READY);
}
Exemple #18
0
void VolumeMaxCLProcessor::executeVolumeOperation(const Volume* volume,
                                                  const VolumeCLBase* volumeCL,
                                                  VolumeCLBase* volumeOutCL, const size3_t& outDim,
                                                  const size3_t& globalWorkGroupSize,
                                                  const size3_t& localWorkgroupSize) {
    cl::Event events[2];
    try {
        BufferCL* tmpVolumeCL;
        int argIndex = 0;
        kernel_->setArg(argIndex++, *volumeCL);
        kernel_->setArg(argIndex++,
                        *(volumeCL->getVolumeStruct(volume)
                              .getRepresentation<BufferCL>()));  // Scaling for 12-bit data
        if (supportsVolumeWrite_) {
            kernel_->setArg(argIndex++, *volumeOutCL);
        } else {
            size_t outDimFlattened = outDim.x * outDim.y * outDim.z;
            if (tmpVolume_ == nullptr || tmpVolume_->getSize() != outDimFlattened) {
                delete tmpVolume_;
                tmpVolume_ = new Buffer<unsigned char>(outDimFlattened);
            }
            tmpVolumeCL = tmpVolume_->getEditableRepresentation<BufferCL>();
            kernel_->setArg(argIndex++, *tmpVolumeCL);
        }
        kernel_->setArg(argIndex++, ivec4(outDim, 0));
        kernel_->setArg(argIndex++, ivec4(volumeRegionSize_.get()));

        OpenCL::getPtr()->getQueue().enqueueNDRangeKernel(
            *kernel_, cl::NullRange, globalWorkGroupSize, localWorkgroupSize, nullptr, &events[0]);

        if (!supportsVolumeWrite_) {
            std::vector<cl::Event> waitFor(1, events[0]);
            OpenCL::getPtr()->getQueue().enqueueCopyBufferToImage(
                tmpVolumeCL->get(), volumeOutCL->getEditable(), 0, size3_t(0), size3_t(outDim),
                &waitFor, &events[1]);
        }
    } catch (cl::Error& err) {
        LogError(getCLErrorString(err));
    }

#if IVW_PROFILING
    try {
        if (supportsVolumeWrite_) {
            events[0].wait();
            LogInfo("Exec time: " << events[0].getElapsedTime() << " ms");
        } else {
            // Measure both computation and copy (only need to wait for copy)
            events[1].wait();
            LogInfo("Exec time (computation, copy): "
                    << events[0].getElapsedTime() << " + " << events[1].getElapsedTime() << " = "
                    << events[0].getElapsedTime() + events[1].getElapsedTime() << " ms");
        }
    } catch (cl::Error& err) {
        LogError(getCLErrorString(err));
    }
#endif
}
Exemple #19
0
bool Sim900::powerDown()
{
    if(isPoweredUp())
    {
        powerToggle();
        return waitFor("NORMAL POWER DOWN", true, NULL);
    }
    return false;
}
Exemple #20
0
static int reply1(int chan, int code, char *payload)
{
    int payloadLength = (payload ? strlen(payload) : 0);
    char result;
    int count;
    
    if (payloadLength == 0) {
dprint(debug, "REPLY %d, %d\n", chan, code);
        request("REPLY:%d,%d", chan, code);
    }
        
    else {
        int remaining = payloadLength;
        while (remaining > 0) {
            if ((count = remaining) > CHUNK_SIZE)
                count = CHUNK_SIZE;
            if (remaining == payloadLength) {
dprint(debug, "REPLY %d, %d, %d, %d\n", chan, code, payloadLength, count);
                request("REPLY:%d,%d,%d,%d", chan, code, payloadLength, count);
                requestPayload(payload, count);
            }
            else {
dprint(debug, "SEND %d, %d\n", chan, count);
                request("SEND:%d,%d", chan, count);
                requestPayload(payload, count);
            }
            payload += count;
            remaining -= count;
            if (remaining > 0) {
                waitFor(CMD_PREFIX "=^c,^d\r", &result, &count);
dprint(debug, " ret %c %d\n", result, count);
                if (result != 'S') {
dprint(debug, " failed with %d\n", count);
                    return count;
                }
            }
        }
    }
    
    waitFor(CMD_PREFIX "=^c,^d\r", &result, &count);
dprint(debug, " final ret %c %d\n", result, count);
    
    return payloadLength;
}
 tcAuthState verifyCredentials() override
 {
     tcAuthState r;
     tcVerifyCredentialsAsync(m_ctx);
     waitFor([&](){
         r = tcGetVerifyCredentialsState(m_ctx);
         return r.code != tcEStatusCode_InProgress;
     });
     return r;
 }
 tcAuthState enterPin(const char *pin) override
 {
     tcAuthState r;
     tcEnterPinAsync(m_ctx, pin);
     waitFor([&](){
         r = tcGetEnterPinState(m_ctx);
         return r.code != tcEStatusCode_InProgress;
     });
     return r;
 }
 tcAuthState requestAuthURL(const char *consumer_key, const char *consumer_secret) override
 {
     tcAuthState r;
     tcRequestAuthURLAsync(m_ctx, consumer_key, consumer_secret);
     waitFor([&](){
         r = tcGetRequestAuthURLState(m_ctx);
         return r.code != tcEStatusCode_InProgress;
     });
     return r;
 }
Exemple #24
0
bool WiFiNode::conect(const char *ssid, const char *psk) {
	if (!wpaCtrl) {
		DBGMSG_ERR("iface is closed");
		return false;
	}
	if (!ssid || !psk) {
		DBGMSG_ERR("Credential is Null");
		return false;
	}
//	removeAllNetworks();
	char reply[1024] = {0};
	size_t replyLen = sizeof(reply) - 1;
	int reqRes = makeRequest("ADD_NETWORK", reply, &replyLen);
	if (reqRes) {
		DBGMSG_ERR("Failed to add network [%d]", reqRes);
		return false;
	}
	char *tmp;
	int networkId = strtol(reply, &tmp, 10);
	DBGMSG_M("New Network id is [%d]", networkId);

	char requestBuffer[1024];
	const size_t requestBufferSize = sizeof(requestBuffer) - 1;

	snprintf(requestBuffer, requestBufferSize, "SET_NETWORK %d ssid \"%s\"", networkId, ssid);
	reqRes = makeRequest(requestBuffer, reply, &replyLen);
	if (reqRes || !strstr(reply, "OK")) {
		DBGMSG_ERR("Failed to set ssid [%d]", reqRes);
		return false;
	}

	snprintf(requestBuffer, requestBufferSize, "SET_NETWORK %d psk \"%s\"", networkId, psk);
	reqRes = makeRequest(requestBuffer, reply, &replyLen);
	if (reqRes || !strstr(reply, "OK")) {
		DBGMSG_ERR("Failed to set psk [%d]", reqRes);
		return false;
	}

	snprintf(requestBuffer, requestBufferSize, "ENABLE_NETWORK %d", networkId);
	reqRes = makeRequest(requestBuffer, reply, &replyLen);
	if (reqRes || !strstr(reply, "OK")) {
		DBGMSG_ERR("Failed to enable network %d [%d]", networkId, reqRes);
		return false;
	}

	if (waitFor(WPA_EVENT_CONNECTED, 15000)) {
		DBGMSG_ERR("Connection Failed");
		return false;
	}
	DBGMSG_H("Connected to <%s>", ssid);
	int obt = obtainIp();
	DBGMSG_H("obtain ip  <%d>", obt);

	return true;
}
 tcTweetState tweet(const char *message) override
 {
     tcTweetState r;
     int th = tcTweetAsync(m_ctx, message);
     waitFor([&](){
         r = tcGetTweetState(m_ctx, th);
         bool ret = r.code != tcEStatusCode_InProgress;
         if (!ret) { printf("in progress...\n"); }
         return ret;
     }, 2000);
     return r;
 }
Exemple #26
0
void LOCK(volatile void *ptr){
	int locked;
	locked=CMPXCHG(ptr,0,1);
	unsigned int delay;
	delay = 1;
	int *p;
	p=ptr;
	printf("LOCK! The Lock is: %d\n",*p);	
	if(locked == 1){
		waitFor(delay);
		delay = delay *2;	
	}
}
// getBattVoltage - Function to verify the battery voltage.
void XBeeLib::getBattVoltage(long *battVoltage){
  // Read 1.1V reference against AVcc
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  // Wait for Vref to settle.
  waitFor(5);
  // Convert
  ADCSRA |= _BV(ADSC);
  while (bit_is_set(ADCSRA,ADSC));
  *battVoltage = ADCL;
  *battVoltage |= ADCH<<8;
  // Back-calculate AVcc in mV.
  *battVoltage = 1126400L / *battVoltage;
}
Exemple #28
0
	void run() {
		running = true;
		preRun();
		while (running) {
			if (selector.wait(waitFor())) {
				receive();
			}
			else {
				timeout();
			}
		}
		postRun();
	}
Exemple #29
0
QByteArray readReply(QNetworkReply *reply, const Scriptable &scriptable)
{
    QByteArray data;
    while ( !reply->isFinished() ) {
        if (scriptable.isAborted())
            return QByteArray();
        waitFor(100);
        if ( reply->waitForReadyRead(100) )
            data.append(reply->readAll());
    }
    data.append(reply->readAll());

    return data;
}
Process::~Process() 
{
  DOUT("Process::~Process()");
  if (_status == ProcessStillRunning)
    waitFor();

  _stdinWriter = Nil;
  _stdoutReader = Nil;
  _stderrReader = Nil;

  _args = Nil;

  if (_envp) {
    _envp = Nil;
  }
}