Exemple #1
0
void doMeasurementAndWaitForResponse() {
  doTimeout = false;
  hasConnection = false;
  needConnection = true;
  doMeasurement();
  blink(PIN_GRN, 100);
}
void PowercastRxControlLayer::doTimerActions()
{
	unsigned long currentTime = getCurrentTimeMiliseconds();
	if (currentTime - timerPing >= DELAY_PING) {
		eventTimeoutPing();
		timerPing = currentTime;
	}

	doMeasurement();
}
void PowercastRxControl4Layer::doTimerActions()
{
	//Serial.println(".");
	//Serial.println(millis());
	unsigned long currentTime;

	if (currentState == STATE_IDLE) {
		currentTime = getCurrentTimeMiliseconds();
		if (currentTime - timerPing >= RX4_DELAY_PING) {
			eventTimeoutPing();
			timerPing = getCurrentTimeMiliseconds();
		}
	}
	
	if (currentState != STATE_CHARGING) {
		if (txAddressQueue.checkOldestTxForTimeout())
		{
			eventTimeoutRemoveOldestProbeSender();
		}


	}
	

	if (currentState == STATE_WAITING_FOR_POWER) {
		currentTime = getCurrentTimeMiliseconds();
		if (currentTime - timerWaitingForPower >= RX4_DELAY_WAITING_FOR_POWER) {
			eventTimeoutWaitingForPower();
		}
		
		if (voltageMeasurementStructData->calculatedVoltageMv > RX4_VOLTAGE_THRESHOLD) {
			eventVoltageAboveThreshold();
		}
	}

	if (currentState == STATE_CHARGING) {

		currentTime = getCurrentTimeMiliseconds();
		if (currentTime - timerProbing >= RX4_DELAY_POWER_PROBING) {
			eventTimeoutPowerProbing();
			timerProbing = getCurrentTimeMiliseconds();
		}

		if (voltageMeasurementStructData->calculatedVoltageMv < RX4_VOLTAGE_THRESHOLD) {
			eventVoltageBelowThreshold();
		}
	}

	doMeasurement();
}
/*
 * Main and helper functions ...
 */
int main(int argc, char **argv)
{
	if (parse_args(argc, argv)) {
		perror("Parsing error.");
		return -1;
	}

	if (check_args()) {
		perror("Invalid arguments.");
		return -1;
	}

	if (realtime)
		setRealtimePrio();

	if (doMeasurement() == -1)
		perror("Measurement was not successful.\n");

	closeFile();
	return 0;
}
void PowercastTxControl2Layer::doTimerActions()
{
	//Serial.println(".");
	unsigned long currentTime;
	//int timeFromLastPing = currentTime - lastPingReceived;
	//int timeForProbeTimeout = currentTime - powerProbeTimer;
	//Serial.println("LAST PING  ---   LAST PROBE TIME");
	//Serial.print(timeFromLastPing);
	//Serial.print("  ---   ");
	//Serial.println(timeForProbeTimeout);

	currentTime = getCurrentTimeMiliseconds();
	if ((currentState == STATE_ON || currentState == STATE_ON_POWER_PROBE || currentState == STATE_OFF_POWER_PROBE) && currentTime - lastPingReceived >= TIMEOUT_PING) {
		eventTimeoutPing();
	}

	currentTime = getCurrentTimeMiliseconds();
	if (currentState == STATE_ON && currentTime - powerProbeTimer >= TIMEOUT_ON_PROBE) {
		eventTimeoutOnProbe();
		powerProbeTimer = currentTime;
	}

	/*
	currentTime = getCurrentTimeMiliseconds();
	Serial.print("---timer actions: ");
	Serial.print(currentTime);
	Serial.print(" -- ");
	Serial.print(powerProbeSentTimer);
	Serial.print(" -- ");
	Serial.print(currentTime - powerProbeSentTimer);
	Serial.println(" -- ");*/

	currentTime = getCurrentTimeMiliseconds();
	if ((currentState == STATE_OFF_POWER_PROBE || currentState == STATE_ON_POWER_PROBE) && (currentTime - powerProbeSentTimer >= TIMEOUT_PROBE_SENT)) {
		eventPwrProbeTimeout();
	}

	doMeasurement();
}
void PowercastTxControl3Layer::doTimerActions()
{
	//Serial.println(".");
	unsigned long currentTime;
	//int timeFromLastPing = currentTime - lastPingReceived;
	//int timeForProbeTimeout = currentTime - powerProbeTimer;
	//Serial.println("LAST PING  ---   LAST PROBE TIME");
	//Serial.print(timeFromLastPing);
	//Serial.print("  ---   ");
	//Serial.println(timeForProbeTimeout);

	if (currentState == STATE_OFF_POWER_PROBE) {
		currentTime = getCurrentTimeMiliseconds();
		if (currentTime - powerProbeResponseTimer >= TX4_TIMEOUT_POWER_PROBE_RESPONSE) {
			eventTimeoutPowerProbeResponse();
		}
	}
	
	if (currentState == STATE_ON) {
		currentTime = getCurrentTimeMiliseconds();
		if (currentTime - lastPowerProbeReceived >= TX4_TIMEOUT_TX_PROBE_RECEIVE) {
			eventTimeoutOnPowerProbe();
			lastPowerProbeReceived = currentTime;
		}
	}

	/*
	currentTime = getCurrentTimeMiliseconds();
	Serial.print("---timer actions: ");
	Serial.print(currentTime);
	Serial.print(" -- ");
	Serial.print(powerProbeSentTimer);
	Serial.print(" -- ");
	Serial.print(currentTime - powerProbeSentTimer);
	Serial.println(" -- ");*/

	doMeasurement();
}