Bläddra i källkod

Some debugging for hal freezes

Philipp Hinz 7 år sedan
förälder
incheckning
f596d630a6
3 ändrade filer med 31 tillägg och 12 borttagningar
  1. 1 1
      CoffeeCode/buildno
  2. 18 6
      CoffeeCode/coffee.cpp
  3. 12 5
      CoffeeCode/hal.cpp

+ 1 - 1
CoffeeCode/buildno

@@ -1 +1 @@
-135
+142

+ 18 - 6
CoffeeCode/coffee.cpp

@@ -57,7 +57,8 @@ void *coffeeThread(void *threadid) {
 
 	logger(V_BREW, "Determining inital state\n");
 	//determine inital state
-	if (halGetRelaisState(RELAIS_POWER) && halGetRelaisState(RELAIS_HEAT) && !halGetRelaisState(RELAIS_PUMP)) {
+	if (halGetRelaisState(RELAIS_POWER) && halGetRelaisState(RELAIS_HEAT)
+			&& !halGetRelaisState(RELAIS_PUMP)) {
 		//wait for heat relais to switch
 		sleep(1);
 		if (halIsHeating()) { //Heating is on
@@ -103,7 +104,7 @@ void *coffeeThread(void *threadid) {
 			 *
 			 */
 		case STATE_INITALHEATING:
-			beginHeating = clock();
+			//beginHeating = clock();
 			if (SigValueEmpty())
 				pause();
 			switch (getSigValue()) {
@@ -117,16 +118,17 @@ void *coffeeThread(void *threadid) {
 				changeState(STATE_IDLE);
 				break;
 			}
+			/* FIXME See notes below
 			endHeating = clock();
 			heatingTime = double(endHeating - beginHeating) / CLOCKS_PER_SEC;
-			coffeeIncreaseHeatingTime((uint64_t)heatingTime);
+			coffeeIncreaseHeatingTime((uint64_t) heatingTime);*/
 			break;
 
 			/*
 			 *
 			 */
 		case STATE_HEATING:
-			beginHeating = clock();
+			//beginHeating = clock();
 			if (SigValueEmpty())
 				pause();
 			switch (getSigValue()) {
@@ -147,9 +149,19 @@ void *coffeeThread(void *threadid) {
 				changeState(STATE_BREWMANUAL);
 				break;
 			}
+			/*
+			 * @TODO FIXME:
+			 * The time measurement makes no sense, since the FSM loops and there are a lot of interrupts that
+			 * should be considered (like buttons or proximity sensor)
+			 * Suggestion: capture time snapshot once at change to heating. If a change to another state occurs,
+			 * 	capture again (like before, this capture is interrupted quite often)
+			 *
+			 * Another con: coffeeIncreaseHeatingTime() takes long for accessing the database, maybe store
+			 *  values at termination or periodically
+
 			endHeating = clock();
 			heatingTime = double(endHeating - beginHeating) / CLOCKS_PER_SEC;
-			coffeeIncreaseHeatingTime((uint64_t)heatingTime);
+			coffeeIncreaseHeatingTime((uint64_t) heatingTime);*/
 			break;
 			/*
 			 *
@@ -351,6 +363,6 @@ void coffeeIncreaseBrewCounter(void) {
 void coffeeIncreaseHeatingTime(uint64_t heatingTime) {
 	uint64_t totalHeatingTime = sqlGetConf(CFGHeatingTime);
 	if (sqlSetConf(CFGHeatingTime, (totalHeatingTime + heatingTime))) {
-			logger_error("Couldn't write heating time to database");
+		logger_error("Couldn't write heating time to database");
 	}
 }

+ 12 - 5
CoffeeCode/hal.cpp

@@ -2,7 +2,7 @@
  * hal.cpp
  *
  *  Created on: Aug 3, 2016
- *      Author: Philipp Hinz
+ *      Author: Philipp Hinz, Sebastian Vendt
  */
 #include <wiringPi.h>
 #include <stdlib.h>
@@ -215,6 +215,7 @@ void halIntPressure(void) {
  */
 void halIntProximity(void) {
 	logger(V_HAL, "IntProximity triggered\n");
+	return;
 	if (halProxSensorCovered()) {
 		halSendSignal(SigProxCvrd);
 	} else {
@@ -287,11 +288,17 @@ void halSendSignal(HalSig val) {
 	sigval value = { 0 };
 	value.sival_int = (int) val;
 
-	if (pthread_sigqueue(thread[THREAD_COFFEE], SIGUSR2, value)) {
-		logger_error("Failed to queue signal %d %s", val, strerror(errno));
-		//No Signals reach the state machine anymore...
-		exit(EXIT_FAILURE);
+	try {
+		if (pthread_sigqueue(thread[THREAD_COFFEE], SIGUSR2, value)) {
+			logger_error("Failed to queue signal %d %s\n", val,
+					strerror(errno));
+			//No Signals reach the state machine anymore...
+			exit(EXIT_FAILURE);
+		}
+	} catch (int e) {
+		logger_error("Whoops.. %d\n", e);
 	}
+
 }
 
 /**