-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathtools.cpp
74 lines (64 loc) · 2.5 KB
/
tools.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <mutex>
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include <sys/time.h>
#include <string>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "main.h"
#include "tools.h"
std::mutex log_mutex;
void lprintf(const char *format, ...) {
// Only print if debug flag is set, else do nothing
if (debugFlag) {
va_list ap;
char fmt[2048];
//actual time
time_t rawtime;
struct tm *timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
char buf[256];
strcpy(buf, asctime(timeinfo));
buf[strlen(buf)-1] = 0;
//connect with args
snprintf(fmt, sizeof(fmt), "%s %s\n", buf, format);
//put on screen:
va_start(ap, format);
vprintf(fmt, ap);
va_end(ap);
//to the logfile:
static FILE *log;
log_mutex.lock();
log = fopen(LOG_FILE, "a");
va_start(ap, format);
vfprintf(log, fmt, ap);
va_end(ap);
fclose(log);
log_mutex.unlock();
}
}
int print_help() {
printf("\nUSAGE: ./inverter_poller <args> [-r <command>], [-h | --help], [-1 | --run-once]\n\n");
printf("SUPPORTED ARGUMENTS:\n");
printf(" -r <raw-command> TX 'raw' command to the inverter\n");
printf(" -h | --help This Help Message\n");
printf(" -1 | --run-once Runs one iteration on the inverter, and then exits\n");
printf(" -d Additional debugging\n\n");
printf("RAW COMMAND EXAMPLES (see protocol manual for complete list):\n");
printf("Set output source priority POP00 (Utility first)\n");
printf(" POP01 (Solar first)\n");
printf(" POP02 (SBU)\n");
printf("Set charger priority PCP00 (Utility first)\n");
printf(" PCP01 (Solar first)\n");
printf(" PCP02 (Solar and utility)\n");
printf(" PCP03 (Solar only)\n");
printf("Set other commands PEa / PDa (Enable/disable buzzer)\n");
printf(" PEb / PDb (Enable/disable overload bypass)\n");
printf(" PEj / PDj (Enable/disable power saving)\n");
printf(" PEu / PDu (Enable/disable overload restart)\n");
printf(" PEx / PDx (Enable/disable backlight)\n\n");
return 1;
}