Преглед на файлове

Implemented some program termination handling and some cleanup

Philipp Hinz преди 8 години
родител
ревизия
dfa6c234e9
променени са 8 файла, в които са добавени 33 реда и са изтрити 48 реда
  1. 1 1
      CoffeeCode/buildno
  2. 2 0
      CoffeeCode/coffee.h
  3. 0 33
      CoffeeCode/database.cpp
  4. 2 9
      CoffeeCode/database.h
  5. 1 1
      CoffeeCode/global.h
  6. 7 4
      CoffeeCode/main.cpp
  7. 19 0
      CoffeeCode/timer.cpp
  8. 1 0
      CoffeeCode/timer.h

+ 1 - 1
CoffeeCode/buildno

@@ -1 +1 @@
-60
+61

+ 2 - 0
CoffeeCode/coffee.h

@@ -32,4 +32,6 @@ int getSigValue(void);
 void changeState(int newState);
 void brewTimeHandler (void);
 
+void coffeeTerminate(void);  //@TODO: Implement this method, called on program termination
+
 #endif /* COFFEE_H_ */

+ 0 - 33
CoffeeCode/database.cpp

@@ -148,42 +148,9 @@ int sqlExecute2(char *query) {
  */
 
 int sqlSetup() {
-	sqlExecute("CREATE TABLE IF NOT EXISTS nodes "
-			"(id INTEGER PRIMARY KEY ASC AUTOINCREMENT, "
-			"guid INTEGER UNIQUE, "
-			"term INTEGER, "
-			"terminal NUMERIC, "
-			"devclass INTEGER, "
-			"devtype INTEGER, "
-			"hw INTEGER, "
-			"fwmajor INTEGER, "
-			"fwminor INTEGER, "
-			"lastseen INTEGER, "
-			"tableversion INTEGER, "
-			"clockspeed INTEGER, "
-			"voltage NUMERIC);");
 	sqlExecute("CREATE TABLE IF NOT EXISTS config "
 			"(id INTEGER PRIMARY KEY, "
 			"value NUMERIC);");
-	sqlExecute("CREATE TABLE IF NOT EXISTS monitorlog "
-			"(id INTEGER PRIMARY KEY ASC AUTOINCREMENT, "
-			"time NUMERIC, "
-			"node INTEGER, "
-			"type INTEGER, "
-			"value NUMERIC, "
-			"weight INTEGER);");
-	sqlExecute("CREATE TABLE IF NOT EXISTS counters "
-			"(id INTEGER PRIMARY KEY ASC, "
-			"por INTEGER, "
-			"wdr INTEGER, "
-			"bodr INTEGER, "
-			"er INTEGER, "
-			"asc INTEGER, "
-			"uptime INTEGER, "
-			"rxerr INTEGER, "
-			"txerr INTEGER, "
-			"rx INTEGER, "
-			"tx INTEGER);");
 	return 0;
 }
 

+ 2 - 9
CoffeeCode/database.h

@@ -19,21 +19,14 @@ using namespace std;
 
 // Config Keys
 typedef enum {
-	CRC = 1,
-	AliveCRC = 2,
-	lastTC1 = 3,
-	lastTC2 = 4,
-	lastTC3 = 5,
-	lastTerm = 6,
-	testSlowCnt = 7,
+	brewcounter = 1,
+
 } config_key_t;
 
 int sqlOpen();
 void sqlClose();
 int sqlSetup();
 int sqlExecute(string query);
-int sqlInsertNode(uint8_t *guid, bool terminal);
-int sqlReadNodes();
 char *inttochar(uint8_t *guid);
 uint8_t *chartoint(const unsigned char *guid);
 uint8_t *int64to8bit(sqlite_int64 guid);

+ 1 - 1
CoffeeCode/global.h

@@ -17,7 +17,7 @@
 #define TIMER_DELAY_US	50000	// Basic timer delay in us
 // SQL config
 
-#define SQL_DATABASE	"nodes.sqlite"
+#define SQL_DATABASE	"coffee.sqlite"
 
 // Global variables
 

+ 7 - 4
CoffeeCode/main.cpp

@@ -178,11 +178,14 @@ int main(int argc, char *argv[]) {
 
 void terminationHandler(int signum) {
 	logger(V_NONE, "Caught signal %d, exiting gracefully..\n", signum);
-	timeTimer.stop();
-	logger(V_NONE, "Saving my state to the database..\n");
+	stopTimers();
+	coffeeTerminate();
+	//displayTerminate();
+
+	/*logger(V_NONE, "Saving my state to the database..\n");
 	sqlExecute("begin");
 	// Save stuff here
-	sqlExecute("end");
+	sqlExecute("end");*/
 
 	sqlClose(); // Closing DB connection
 
@@ -227,7 +230,7 @@ void killThread(int threadid, int sig) {
 void *mainLoop(void *threadid) {
 	sqlOpen();
 
-	//sqlSetup();
+	sqlSetup();
 
 	// Do more stuff here
 

+ 19 - 0
CoffeeCode/timer.cpp

@@ -207,6 +207,25 @@ void initTimers(void) {
 	counter = 0;
 }
 
+/**
+ * Stops all existing timers
+ */
+
+void stopTimers(void) {
+	timer *t = firstTimer;
+
+	while (t != NULL) {
+		t->stop();
+		t = t->next;
+	}
+	logger(V_BASIC, "Stopped all timers.\n");
+}
+
+/**
+ * This is a dummy thread
+ * @param *threadid Thread ID
+ */
+
 void *nullThread(void *threadid) {
 	pthread_exit(NULL);
 }

+ 1 - 0
CoffeeCode/timer.h

@@ -36,6 +36,7 @@ private:
 };
 
 void initTimers(void);
+void stopTimers(void);
 void *nullThread(void *threadid);
 
 #define SIG SIGRTMIN