|
@@ -29,16 +29,8 @@ const int buildno = (1+(int)(
|
|
|
|
|
|
int lcd = 0;
|
|
|
int verbose = 0;
|
|
|
-int optPoll = 0;
|
|
|
-int optRes = 0;
|
|
|
-bool optInc = false;
|
|
|
-bool optEcho = false;
|
|
|
-bool optLom = false;
|
|
|
-bool optForce = false;
|
|
|
-bool optTerm = false;
|
|
|
-bool optAdd = false;
|
|
|
bool optDate = false;
|
|
|
-bool optSuppress = false;
|
|
|
+bool optPower = false;
|
|
|
|
|
|
|
|
|
void *mainLoop(void *threadid);
|
|
@@ -62,7 +54,7 @@ int main(int argc, char *argv[]) {
|
|
|
"Build number %d\n", buildno);
|
|
|
|
|
|
// Argument handling
|
|
|
- while (prev_ind = optind, (opt = getopt(argc, argv, "vV:r:teilfhads")) != -1) {
|
|
|
+ while (prev_ind = optind, (opt = getopt(argc, argv, "vVdp")) != -1) {
|
|
|
if (argc > 3)
|
|
|
if (optind == prev_ind + 2 && *optarg == '-') {
|
|
|
opt = '?';
|
|
@@ -78,64 +70,24 @@ int main(int argc, char *argv[]) {
|
|
|
*/
|
|
|
verbose++;
|
|
|
break;
|
|
|
- case 'r': // set start resistance
|
|
|
- optRes = atoi(optarg);
|
|
|
- printf("Starting Poti with %d Ohms\n", optRes);
|
|
|
- break;
|
|
|
case 'V':
|
|
|
//printf("Build number %d\n", buildno);
|
|
|
return EXIT_SUCCESS;
|
|
|
break;
|
|
|
- case 't':
|
|
|
- printf(
|
|
|
- "I'm counting myself as a terminal node and terminate the CAN bus.\n");
|
|
|
- optTerm = true;
|
|
|
- break;
|
|
|
- case 'e':
|
|
|
- printf("Echoing all CAN messages\n");
|
|
|
- optEcho = true;
|
|
|
- break;
|
|
|
- case 'i':
|
|
|
- printf("Increasing Wiper step every second.\n");
|
|
|
- optInc = true;
|
|
|
- break;
|
|
|
- case 'l':
|
|
|
- printf("Setting MCP2510 to listen only mode on shutdown.\n");
|
|
|
- optLom = true;
|
|
|
- break;
|
|
|
- case 'f':
|
|
|
- printf("I'm forcing a speedtest.\n");
|
|
|
- optForce = true;
|
|
|
- break;
|
|
|
- case 'a':
|
|
|
- printf(
|
|
|
- "I will add new nodes if they don't appear in the nodes file.\n");
|
|
|
- optAdd = true;
|
|
|
- break;
|
|
|
- case 'd':
|
|
|
+ case 'd': // Print timestamp in every line
|
|
|
optDate = true;
|
|
|
break;
|
|
|
- case 's':
|
|
|
- printf("I will suppress a speedtest due to many RX/TX errors.\n");
|
|
|
- optSuppress = true;
|
|
|
+ case 'p': // power machine on program start
|
|
|
+ optPower = true;
|
|
|
break;
|
|
|
+
|
|
|
case '?':
|
|
|
case 'h':
|
|
|
- printf("Usage: %s [-hvVteilfads] [-r ohms]\n", argv[0]);
|
|
|
+ printf("Usage: %s [-hvVdp]\n", argv[0]);
|
|
|
printf("\t-h\t\tPrints this help\n");
|
|
|
printf("\t-v\t\tSets verbose output, can be used multiple times\n");
|
|
|
- printf(
|
|
|
- "\t-r ohms\t\tSets the start resistance of the digital potentiometer\n");
|
|
|
printf("\t-V\t\tPrints only the version and exits\n");
|
|
|
- printf("\t-t\t\tTerminates the CAN Bus with a connected DiPoti\n");
|
|
|
- printf("\t-e\t\tEchoes all incoming CAN messages (Debugging)\n");
|
|
|
- printf("\t-i\t\tIncreases the Wiper of the DigiPot every second\n");
|
|
|
- printf(
|
|
|
- "\t-l\t\tSets the MCP2515 to listen only mode on shutdown\n");
|
|
|
- printf("\t-f\t\tForces a speedtest after startup\n");
|
|
|
- printf("\t-s\t\tSuppress a speedtest in case of errors\n");
|
|
|
- printf("\t-a\t\tAdd new nodes if not known in file nodes\n");
|
|
|
- printf("\t-d\t\tPrints a timestamp in front of every message\n");
|
|
|
+ printf("\t-p\t\tPowers the machine on program start\n");
|
|
|
|
|
|
printf("Listening to the following signals:\n");
|
|
|
printf("\tSIGUSR1(%u)\tPrints monitor data of all nodes\n",
|
|
@@ -144,7 +96,7 @@ int main(int argc, char *argv[]) {
|
|
|
SIGHUP);
|
|
|
return EXIT_SUCCESS;
|
|
|
default:
|
|
|
- fprintf(stderr, "Usage: %s [-hvVteilfads] [-r ohms]\n", argv[0]);
|
|
|
+ fprintf(stderr, "Usage: %s [-hvVdp]\n", argv[0]);
|
|
|
return EXIT_FAILURE;
|
|
|
break;
|
|
|
}
|
|
@@ -175,7 +127,7 @@ int main(int argc, char *argv[]) {
|
|
|
if (lcd < 0) logger_error("Error: unable to init LCD (%d)\n", lcd);
|
|
|
lcdClear(lcd);
|
|
|
lcdHome(lcd);
|
|
|
- lcdPrintf(lcd,"CoffeePi b%d", buildno);
|
|
|
+ lcdPrintf(lcd," CoffeePi ", buildno);
|
|
|
|
|
|
// http://www.tutorialspoint.com/cplusplus/cpp_multithreading.htm
|
|
|
|
|
@@ -207,7 +159,7 @@ int main(int argc, char *argv[]) {
|
|
|
pthread_attr_destroy(&attr);
|
|
|
|
|
|
// Insert main stuff here.
|
|
|
- timeTimer.setDivider(1);
|
|
|
+ timeTimer.setDivider(20);
|
|
|
timeTimer.start();
|
|
|
|
|
|
sleep(2);
|
|
@@ -230,6 +182,7 @@ 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");
|
|
|
sqlExecute("begin");
|
|
|
// Save stuff here
|
|
@@ -297,5 +250,5 @@ void timeHandler(void) {
|
|
|
time ( &rawtime );
|
|
|
timeinfo = localtime ( &rawtime );
|
|
|
lcdPosition(lcd, 0, 1);
|
|
|
- lcdPrintf(lcd, "%.2d:%.2d:%.2d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
|
|
|
+ lcdPrintf(lcd, " %.2d:%.2d:%.2d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
|
|
|
}
|