Beispiel #1
0
void TNodejsDHT11Sensor::TReadTask::Run() {
	const uint64 StartTm = TTm::GetCurUniMSecs();

	int RetryN = 0;
	bool Success = false;
	while (true) {
		RetryN++;

		try {
			JsSensor->Sensor->Read();
			Success = true;
			break;
		} catch (const PExcept& Except) {
			const uint64 TimeExpired = TTm::GetCurUniMSecs() - StartTm;
			const int64 TimeLeft = int64(JsSensor->MxSampleTm) - int64(TimeExpired);

			JsSensor->Notify->OnNotifyFmt(TNotifyType::ntInfo, "Failed to read DHT11: %s, time left %ld ...", Except->GetMsgStr().CStr(), (RetryN+1));

			if (TimeLeft - int64(TDHT11Sensor::SAMPLING_TM) <= 0) { break; }

			// sleep for 2 seconds before reading again
			JsSensor->Notify->OnNotifyFmt(TNotifyType::ntInfo, "Attempt %d in 2 seconds ...", (RetryN+1));
			TSysProc::Sleep(TDHT11Sensor::MIN_SAMPLING_PERIOD);
		}
	}


	if (!Success) {
		SetExcept(TExcept::New("Failed to read DHT11 after " + TUInt64::GetStr(JsSensor->MxSampleTm)));
	}
}
Beispiel #2
0
void TNodeJsYL40Adc::TReadTask::Run() {
	try {
		const TIntStrKdV& InputNumNmKdV = Adc->InputNumNmKdV;

		Adc->Notify->OnNotifyFmt(TNotifyType::ntInfo, "YL-40 will read %d inputs ...", InputNumNmKdV.Len());
		ValV.Gen(InputNumNmKdV.Len());
		for (int InputN = 0; InputN < InputNumNmKdV.Len(); InputN++) {
			int Val = Adc->Adc->Read(InputNumNmKdV[InputN].Key);
			ValV[InputN] = Val;
		}
	} catch (const PExcept& Except) {
		SetExcept(Except);
	}
}
Beispiel #3
0
__stkargs __sigfunc new_signal(int signo, __sigfunc handler)
{
    register struct Task *this_task;

    this_task = (struct Task *) FindTask(NULL);

    switch (signo) {
    case SIGALRM:{
	    ULONG sigalrm;

	    sigalrm = sys_signal_alarm;
	    if ((__sigfunc) handler == SIG_IGN) {	/* remove SIGALRM
							 * handler */
		SetExcept(0L, sigalrm);	/* Only sigalrm !! */
		sys_signal_alarm = 0;
		handler_alarm = NULL;
		cleanup_timer(&treq);
	    } else {		/* install handler */
		if (!setup_timer(UNIT_VBLANK, &treq)) {
		    printf("Could not setup_timer\n");
		    break;	/* What else ?? */
		}
		sigalrm = 1L << (treq->tr_node.io_Message.mn_ReplyPort->mp_SigBit);

		this_task->tc_ExceptCode = (APTR) catch_exception;
		sys_signal_alarm = sigalrm;
		handler_alarm = (void (*) ()) handler;
		SetExcept(sigalrm, sigalrm);
		/* If we start treq, handler will be called */
	    }
	    break;
	}
    case SIGHUP:{
	    ULONG sighup;

	    sighup = (((__sigfunc) handler == SIG_IGN) || ((__sigfunc) handler == SIG_DFL))
		? 0 : EXT_SIGHUP;

	    this_task->tc_ExceptCode = (APTR) catch_exception;
	    sys_signal_hup = sighup;
	    handler_hup = (void (*) ()) handler;
	    SetExcept(sighup, EXT_SIGHUP);
	    break;
	}
    case SIGUSR1:{
	    ULONG sigusr;

	    sigusr = (((__sigfunc) handler == SIG_IGN) || ((__sigfunc) handler == SIG_DFL))
		? 0 : EXT_SIGUSR;

	    this_task->tc_ExceptCode = (APTR) catch_exception;
	    sys_signal_usr = sigusr;
	    handler_usr = (void (*) ()) handler;
	    SetExcept(sigusr, EXT_SIGUSR);
	    break;
	}
    default:
	signal(signo, handler);
	break;
    }
    return handler;
}