|
|
@@ -54,7 +54,7 @@
|
|
|
|
|
|
#define _SLEN LINE_BUFFER_SIZE
|
|
|
|
|
|
-#define DIU_MINDER_VERSION "2.1.12"
|
|
|
+#define DIU_MINDER_VERSION "2.1.13"
|
|
|
|
|
|
static const char *s_http_port = "60535";
|
|
|
static struct mg_serve_http_opts s_http_server_opts;
|
|
|
@@ -71,8 +71,8 @@ gps_status my_gps_stat={0};
|
|
|
|
|
|
time_t mkgmtime(struct tm *tm);
|
|
|
|
|
|
-int token_diag_serial = 0;
|
|
|
-char token_diag_string[LINE_BUFFER_SIZE] = {0};
|
|
|
+int token_diag_serial = 0;
|
|
|
+char token_diag_string[LINE_BUFFER_SIZE] = {0};
|
|
|
|
|
|
|
|
|
// return total bytes in dst
|
|
|
@@ -100,6 +100,8 @@ set_paddle_req paddle_req = {0};
|
|
|
driver_status my_driver_status={0};
|
|
|
int update_driver_status = 0;
|
|
|
|
|
|
+state_info_t my_state_info = {0};
|
|
|
+
|
|
|
int md5_of_file(char *filename, void *result) {
|
|
|
FILE *f = NULL;
|
|
|
char chunk[LINE_BUFFER_SIZE]={0};
|
|
|
@@ -110,20 +112,20 @@ int md5_of_file(char *filename, void *result) {
|
|
|
|
|
|
if (!filename) { return -1; }
|
|
|
|
|
|
- if(!MD5_Init(&ctx)) {
|
|
|
+ if (!MD5_Init(&ctx)) {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
f = fopen(filename, "rb");
|
|
|
|
|
|
- if(!f) {
|
|
|
+ if (!f) {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
while(1) {
|
|
|
retval = fread(chunk, 1, LINE_BUFFER_SIZE, f);
|
|
|
|
|
|
- if(retval <= 0) {
|
|
|
+ if (retval <= 0) {
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
@@ -237,7 +239,7 @@ int handle_gps_time(float gtime, int date) {
|
|
|
|
|
|
// If we scanned at all required fields
|
|
|
//
|
|
|
- if(n >= 6) {
|
|
|
+ if (n >= 6) {
|
|
|
struct tm gpstm = {0};
|
|
|
|
|
|
// GPS date only uses two digits for year, so we must assume the century
|
|
|
@@ -270,7 +272,7 @@ int handle_gps_time(float gtime, int date) {
|
|
|
|
|
|
// if we have more than MAX_GPS_CLOCK_DRIFT seconds of clock drift
|
|
|
//
|
|
|
- if(abs(utc - now) > MAX_GPS_CLOCK_DRIFT) {
|
|
|
+ if (abs(utc - now) > MAX_GPS_CLOCK_DRIFT) {
|
|
|
struct timeval ts = {0};
|
|
|
|
|
|
// Set the timeval struct to the calculated utc timestamp from the GPS unit.
|
|
|
@@ -284,7 +286,7 @@ int handle_gps_time(float gtime, int date) {
|
|
|
|
|
|
// If we have a valid connection to the IPC hub
|
|
|
//
|
|
|
- if( hub_fd >= 0) {
|
|
|
+ if ( hub_fd >= 0) {
|
|
|
|
|
|
// Stick a message into the diagnostic log to record the fact that we've set the system clock from GPS
|
|
|
//
|
|
|
@@ -333,10 +335,10 @@ static int handle_stale_gps_condition() {
|
|
|
|
|
|
// If we have entered this function with the impression that we have a valid GPS fix...
|
|
|
//
|
|
|
- if(previous_good_flag > 0) {
|
|
|
+ if (previous_good_flag > 0) {
|
|
|
// If it has been at least GPS_STALE_THRESHOLD seconds since the last fix
|
|
|
//
|
|
|
- if( stale_time >= GPS_STALE_THRESHOLD ) {
|
|
|
+ if ( stale_time >= GPS_STALE_THRESHOLD ) {
|
|
|
clear_stale_gps_data();
|
|
|
my_gps_stat.gps_good = 0;
|
|
|
return_code |= 1;
|
|
|
@@ -348,7 +350,7 @@ static int handle_stale_gps_condition() {
|
|
|
// we have a valid connection to the IPC hub we should use that IPC hub connection to
|
|
|
// add a note to the diagnostic log indicating that we've declared the GPS data stale.
|
|
|
//
|
|
|
- if( return_code && (hub_fd >= 0) ) {
|
|
|
+ if ( return_code && (hub_fd >= 0) ) {
|
|
|
struct message_record outgoing_msg;
|
|
|
|
|
|
format_log_message(&outgoing_msg, LOGLEVEL_DEBUG, "GPS fix has been stale for %d seconds, setting GPS = NO.", stale_time);
|
|
|
@@ -375,7 +377,7 @@ int update_gps(char *in) {
|
|
|
int return_code = 0;
|
|
|
|
|
|
|
|
|
- if(!strncmp(in,"$GPRMC",6)) {
|
|
|
+ if (!strncmp(in,"$GPRMC",6)) {
|
|
|
float f1=0;
|
|
|
char f2=0;
|
|
|
float f3=0;
|
|
|
@@ -392,12 +394,12 @@ int update_gps(char *in) {
|
|
|
|
|
|
// If we have a full GPRMC sentence we can consider setting the time
|
|
|
//
|
|
|
- if(num == 11) {
|
|
|
+ if (num == 11) {
|
|
|
|
|
|
// Require at least MIN_SATS_FOR_TIME satellites to accept a new system clock value from the GPS unit.
|
|
|
// This is to keep a crummy GPS fix from generating a bogus or unstable system time.
|
|
|
//
|
|
|
- if(my_gps_stat.num_sats >= MIN_SATS_FOR_TIME) {
|
|
|
+ if (my_gps_stat.num_sats >= MIN_SATS_FOR_TIME) {
|
|
|
// Pass the time field (f1) and the date field (f9) in to the routine that sets the system clock if needed.
|
|
|
// (this routine also stores the utc timestamp derived from the GPS date and time fields so it can be passed to
|
|
|
// other modules that may have a need for this information).
|
|
|
@@ -405,7 +407,7 @@ int update_gps(char *in) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(num > 0) {
|
|
|
+ if (num > 0) {
|
|
|
|
|
|
// update snapshot with latitude
|
|
|
//
|
|
|
@@ -431,7 +433,7 @@ int update_gps(char *in) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- else if(!strncmp(in,"$GPGGA",6)) {
|
|
|
+ else if (!strncmp(in,"$GPGGA",6)) {
|
|
|
int f1=0;
|
|
|
float f2=0;
|
|
|
char f3=0;
|
|
|
@@ -447,7 +449,7 @@ int update_gps(char *in) {
|
|
|
|
|
|
num=sscanf(in,"$GPGGA,%d,%f,%c,%f,%c,%d,%d,%f,%f,%c,%f,%c",&f1,&f2,&f3,&f4,&f5,&f6,&f7,&f8,&f9,&f10,&f11,&f12);
|
|
|
|
|
|
- if(num == 12) {
|
|
|
+ if (num == 12) {
|
|
|
|
|
|
// require 3 satellites minimum
|
|
|
//
|
|
|
@@ -479,7 +481,7 @@ int update_gps(char *in) {
|
|
|
// If we have a connection to the IPC hub and we had previously not had a valid
|
|
|
// GPS fix but we now do, make a note of it in the diagnostic log.
|
|
|
//
|
|
|
- if( (previous_good_flag == 0) && (my_gps_stat.gps_good != 0) && (hub_fd >= 0) ) {
|
|
|
+ if ( (previous_good_flag == 0) && (my_gps_stat.gps_good != 0) && (hub_fd >= 0) ) {
|
|
|
struct message_record outgoing_msg;
|
|
|
|
|
|
format_log_message(&outgoing_msg, LOGLEVEL_DEBUG, "GPS fix is now valid with %d satellites. Setting GPS = YES.", my_gps_stat.num_sats);
|
|
|
@@ -494,11 +496,11 @@ void maintain_ipc_hub_connect(char *progname) {
|
|
|
|
|
|
// if we have no connection to the IPC hub
|
|
|
//
|
|
|
- if(hub_fd < 0) {
|
|
|
+ if (hub_fd < 0) {
|
|
|
|
|
|
// if we haven't tried the hub in a few seconds
|
|
|
//
|
|
|
- if( (time(NULL) - last_hub_try) > HUB_RETRY_TIME ) {
|
|
|
+ if ( (time(NULL) - last_hub_try) > HUB_RETRY_TIME ) {
|
|
|
|
|
|
// retry it
|
|
|
//
|
|
|
@@ -508,7 +510,7 @@ void maintain_ipc_hub_connect(char *progname) {
|
|
|
//
|
|
|
hub_fd = connect_to_message_server(progname);
|
|
|
|
|
|
- if(hub_fd >= 0) {
|
|
|
+ if (hub_fd >= 0) {
|
|
|
// Subscribe to the default status messages
|
|
|
//
|
|
|
subscribe_to_default_messages(hub_fd);
|
|
|
@@ -545,7 +547,7 @@ void maintain_ipc_hub_connect(char *progname) {
|
|
|
message_callback_return handle_status_request(struct message_record *msg, void *param) {
|
|
|
struct message_record outgoing_msg;
|
|
|
|
|
|
- if(hub_fd >= 0) {
|
|
|
+ if (hub_fd >= 0) {
|
|
|
prepare_message(&outgoing_msg, MAILBOX_DRIVER_STATUS, &my_driver_status, sizeof(my_driver_status));
|
|
|
send_message(hub_fd, &outgoing_msg);
|
|
|
prepare_message(&outgoing_msg, MAILBOX_GPS_STATUS, &my_gps_stat, sizeof(my_gps_stat));
|
|
|
@@ -556,7 +558,7 @@ message_callback_return handle_status_request(struct message_record *msg, void *
|
|
|
}
|
|
|
|
|
|
message_callback_return handle_vault_drop(struct message_record *msg, void *param) {
|
|
|
- if(diu_fd >= 0) {
|
|
|
+ if (diu_fd >= 0) {
|
|
|
write(diu_fd, "/V:\r", 4);
|
|
|
}
|
|
|
return MESSAGE_HANDLED_CONT;
|
|
|
@@ -573,7 +575,7 @@ message_callback_return handle_driver_notify(struct message_record *msg, void *p
|
|
|
long long dup_usec_delta = 0;
|
|
|
|
|
|
|
|
|
- if(strncmp((const char *)(msg->payload), dup_notify_str, MAX_PAYLOAD_LENGTH)) {
|
|
|
+ if (strncmp((const char *)(msg->payload), dup_notify_str, MAX_PAYLOAD_LENGTH)) {
|
|
|
dup_notify_count = 1;
|
|
|
strncpy(dup_notify_str, (const char *)(msg->payload), MAX_PAYLOAD_LENGTH - 1);
|
|
|
dup_notify_str[MAX_PAYLOAD_LENGTH - 1] = '\0';
|
|
|
@@ -589,25 +591,25 @@ message_callback_return handle_driver_notify(struct message_record *msg, void *p
|
|
|
|
|
|
switch(msg->payload[0]) {
|
|
|
case LOGLEVEL_EVENT:
|
|
|
- if(!is_dup || (dup_usec_delta >= DUP_USEC_BEEP_THRESHOLD)) {
|
|
|
+ if (!is_dup || (dup_usec_delta >= DUP_USEC_BEEP_THRESHOLD)) {
|
|
|
DIU_ACK_BEEP(diu_fd);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case LOGLEVEL_REJECT:
|
|
|
- if(!is_dup || (dup_usec_delta >= DUP_USEC_BEEP_THRESHOLD)) {
|
|
|
+ if (!is_dup || (dup_usec_delta >= DUP_USEC_BEEP_THRESHOLD)) {
|
|
|
DIU_ERROR_BEEP(diu_fd);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case LOGLEVEL_ACCEPT:
|
|
|
- if(!is_dup || (dup_usec_delta >= DUP_USEC_BEEP_THRESHOLD)) {
|
|
|
+ if (!is_dup || (dup_usec_delta >= DUP_USEC_BEEP_THRESHOLD)) {
|
|
|
DIU_ACK_BEEP(diu_fd);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case LOGLEVEL_ERROR:
|
|
|
- if(!is_dup || (dup_usec_delta >= DUP_USEC_BEEP_THRESHOLD)) {
|
|
|
+ if (!is_dup || (dup_usec_delta >= DUP_USEC_BEEP_THRESHOLD)) {
|
|
|
DIU_CRITICAL_BEEP(diu_fd);
|
|
|
}
|
|
|
break;
|
|
|
@@ -615,7 +617,7 @@ message_callback_return handle_driver_notify(struct message_record *msg, void *p
|
|
|
default: break;
|
|
|
}
|
|
|
|
|
|
- if(is_dup) {
|
|
|
+ if (is_dup) {
|
|
|
snprintf(_text, MAX_PAYLOAD_LENGTH, "driver_notify replace %s %s %d x %s", "white", "black", dup_notify_count, &msg->payload[1]);
|
|
|
ws_send(&g_mgr, _text);
|
|
|
}
|
|
|
@@ -649,7 +651,7 @@ static inline int can_report_diu_error() {
|
|
|
|
|
|
// If our last potential burst lockout has expired...
|
|
|
//
|
|
|
- if( (now - diu_error_burst) >= DIU_ERROR_RATE_LIMIT) {
|
|
|
+ if ( (now - diu_error_burst) >= DIU_ERROR_RATE_LIMIT) {
|
|
|
|
|
|
// reset our burst counter
|
|
|
//
|
|
|
@@ -662,7 +664,7 @@ static inline int can_report_diu_error() {
|
|
|
|
|
|
// if we haven't hit our burst limit...
|
|
|
//
|
|
|
- if(diu_error_counter < DIU_ERROR_BURST_LIMIT) {
|
|
|
+ if (diu_error_counter < DIU_ERROR_BURST_LIMIT) {
|
|
|
|
|
|
// count this message against our burst limit
|
|
|
//
|
|
|
@@ -725,11 +727,11 @@ static void process_ws_message(struct websocket_message *ws_msg) {
|
|
|
//
|
|
|
static void ui_handle_status_input(struct mg_connection *nc, struct http_message *hm) {
|
|
|
int i, npkgs, npkgnet=0, ncfgline=0;
|
|
|
- char buf[4*_SLEN],
|
|
|
- pkgnetline[_SLEN],
|
|
|
- cfgline[_SLEN],
|
|
|
- _str[_SLEN];
|
|
|
- char date_str[32];
|
|
|
+ char buf[4*_SLEN] = {0},
|
|
|
+ pkgnetline[_SLEN] = {0},
|
|
|
+ cfgline[_SLEN] = {0},
|
|
|
+ _str[_SLEN] = {0};
|
|
|
+ char date_str[32] = {0};
|
|
|
time_t t;
|
|
|
struct tm tm, pkgtime;
|
|
|
FILE *fp;
|
|
|
@@ -754,7 +756,7 @@ static void ui_handle_status_input(struct mg_connection *nc, struct http_message
|
|
|
pkgtime.tm_mon + 1, pkgtime.tm_mday, pkgtime.tm_year + 1900,
|
|
|
pkgtime.tm_hour, pkgtime.tm_min, pkgtime.tm_sec);
|
|
|
|
|
|
- _strnncat(pkgnetline, "|", _SLEN);
|
|
|
+ _strnncat(pkgnetline, "|", _SLEN);
|
|
|
_strnncat(pkgnetline, _str, _SLEN);
|
|
|
npkgnet++;
|
|
|
}
|
|
|
@@ -840,6 +842,8 @@ static void ui_handle_logout_input(struct mg_connection *nc, struct http_message
|
|
|
"ok .",
|
|
|
};
|
|
|
|
|
|
+ driver_logout();
|
|
|
+
|
|
|
mg_printf(nc, "HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n%s",
|
|
|
(unsigned long)strlen(msg[1]), msg[1]);
|
|
|
|
|
|
@@ -1392,21 +1396,6 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-//DEBUG
|
|
|
-//
|
|
|
-void _test_ws(struct mg_mgr *mgr) {
|
|
|
- struct mg_connection *conn;
|
|
|
- char buf[_SLEN];
|
|
|
-
|
|
|
- snprintf(buf, _SLEN, "test message");
|
|
|
-
|
|
|
- for (conn = mg_next(mgr, NULL); conn; conn = mg_next(mgr, conn)) {
|
|
|
- if (!is_websocket(conn)) { continue; }
|
|
|
- mg_send_websocket_frame(conn, WEBSOCKET_OP_TEXT, buf, strlen(buf));
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
//-------- web server functions ----
|
|
|
|
|
|
|
|
|
@@ -1438,18 +1427,30 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
struct mg_connection *nc;
|
|
|
|
|
|
+#ifdef DEBUG_PRINT
|
|
|
long long int _usec_now, _usec_prv, _usec_del;
|
|
|
+ _usec_now = get_usec_time();
|
|
|
+ _usec_prv = _usec_now;
|
|
|
+ _usec_del = 60000000;
|
|
|
+#endif
|
|
|
+
|
|
|
|
|
|
if ( (argc>1) && (
|
|
|
(strncmp(argv[1], "-h", 3)==0) ||
|
|
|
- (strncmp(argv[1], "-v", 3)==0) ) ) {
|
|
|
+ (strncmp(argv[1], "-v", 3)==0) ) ) {
|
|
|
printf("diu_minder version: %s\n", DIU_MINDER_VERSION);
|
|
|
exit(0);
|
|
|
}
|
|
|
|
|
|
- _usec_now = get_usec_time();
|
|
|
- _usec_prv = _usec_now;
|
|
|
- _usec_del = 60000000;
|
|
|
+ // get current state in case the diu_minder crashed
|
|
|
+ // and forgot it (diu_minder broadcasts initial
|
|
|
+ // state on startup, which defaults to zero)
|
|
|
+ //
|
|
|
+ get_state_info(&my_state_info);
|
|
|
+ my_driver_status.logged_in_driver = my_state_info.logged_in_driver;
|
|
|
+ memcpy(my_driver_status.driver_name, my_state_info.driver_name, DRIVER_NAME_LEN);
|
|
|
+ my_driver_status.driver_name[DRIVER_NAME_LEN-1] = '\0';
|
|
|
+ my_driver_status.equip_num = my_state_info.equip_num;
|
|
|
|
|
|
// setup mongoose web server
|
|
|
//
|
|
|
@@ -1503,36 +1504,40 @@ int main(int argc, char **argv) {
|
|
|
//
|
|
|
while( exit_request_status == EXIT_REQUEST_NONE ) {
|
|
|
|
|
|
+#ifdef DEBUG_PRINT
|
|
|
_usec_now = get_usec_time();
|
|
|
if ((_usec_now - _usec_prv) > _usec_del) {
|
|
|
- //DEBUG
|
|
|
printf("[%lli] diu_minder: heartbeat\n", get_usec_time());
|
|
|
- //DEBUG
|
|
|
-
|
|
|
_usec_prv = _usec_now;
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
RESET_WATCHDOG();
|
|
|
|
|
|
maintain_ipc_hub_connect(argv[0]);
|
|
|
|
|
|
- if(diu_fd < 0) {
|
|
|
+ if (diu_fd < 0) {
|
|
|
|
|
|
diu_fd = open_rs232_device(DRIVER_UI_PORT, USE_DEFAULT_BAUD, RS232_LINE);
|
|
|
|
|
|
- if(diu_fd < 0) {
|
|
|
+ if (diu_fd < 0) {
|
|
|
//fprintf(stderr, "Cannot open serial port %s for DIU!\n", DRIVER_UI_PORT);
|
|
|
}
|
|
|
+
|
|
|
else {
|
|
|
- write(diu_fd, "/Q:aK\r", 6); //Turn on all messages except ACKs for sent commands
|
|
|
+
|
|
|
+ // Turn on all messages except ACKs for sent commands
|
|
|
+ //
|
|
|
+ write(diu_fd, "/Q:aK\r", 6);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
now = time(NULL);
|
|
|
|
|
|
//Every second, we want to update the DIU clock (even though it only shows minutes, this covers power events...)
|
|
|
//
|
|
|
- if((now - last_diu_clock) > 0) {
|
|
|
+ if ((now - last_diu_clock) > 0) {
|
|
|
|
|
|
if (diu_fd>=0) {
|
|
|
set_diu_clock(diu_fd, now);
|
|
|
@@ -1543,28 +1548,33 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
//Every second we want to check to make sure that our GPS data have note gone stale...
|
|
|
//
|
|
|
- if((now - last_stale_gps_check) > 0) {
|
|
|
+ if ((now - last_stale_gps_check) > 0) {
|
|
|
|
|
|
// If the stale check results in an update to my_gps_stat, we must update any other
|
|
|
// modules which may be tracking GPS status via the IPC hub.
|
|
|
//
|
|
|
- if( handle_stale_gps_condition() > 0 ) {
|
|
|
+ if ( handle_stale_gps_condition() > 0 ) {
|
|
|
|
|
|
// If we have a connection to the IPC hub
|
|
|
//
|
|
|
- if(hub_fd >= 0) {
|
|
|
- //Go and toss the data to any other modules who happen to care about GPS
|
|
|
+ if (hub_fd >= 0) {
|
|
|
+
|
|
|
+ // Go and toss the data to any other modules who happen to care about GPS
|
|
|
+ //
|
|
|
prepare_message(&outgoing_msg, MAILBOX_GPS_STATUS, &my_gps_stat, sizeof(my_gps_stat));
|
|
|
send_message(hub_fd, &outgoing_msg);
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// Either way, remember that we did this stale check.
|
|
|
//
|
|
|
last_stale_gps_check = now;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- if(hup_request_status) {
|
|
|
+ if (hup_request_status) {
|
|
|
|
|
|
hup_request_status = 0;
|
|
|
|
|
|
@@ -1574,7 +1584,7 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
//If it is time to send out a driver status update
|
|
|
//
|
|
|
- if(update_driver_status && (hub_fd >= 0)) {
|
|
|
+ if (update_driver_status && (hub_fd >= 0)) {
|
|
|
|
|
|
//do so...
|
|
|
//
|
|
|
@@ -1586,9 +1596,9 @@ int main(int argc, char **argv) {
|
|
|
check_paddle_request();
|
|
|
|
|
|
//If we have to redraw the UI
|
|
|
- //if(redraw_flag && !calibration)
|
|
|
+ //if (redraw_flag && !calibration)
|
|
|
//
|
|
|
- if(!calibration) {
|
|
|
+ if (!calibration) {
|
|
|
|
|
|
//Redraw the menu reflecting any changes from the last touchscreen input
|
|
|
//or other stimulus
|
|
|
@@ -1609,14 +1619,14 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
nfd = 0;
|
|
|
|
|
|
- if(hub_fd >= 0) {
|
|
|
+ if (hub_fd >= 0) {
|
|
|
fds[nfd].fd = hub_fd;
|
|
|
fds[nfd].events = POLLIN;
|
|
|
fds[nfd].revents = 0;
|
|
|
nfd++;
|
|
|
}
|
|
|
|
|
|
- if(diu_fd >= 0) {
|
|
|
+ if (diu_fd >= 0) {
|
|
|
fds[nfd].fd = diu_fd;
|
|
|
fds[nfd].events = POLLIN;
|
|
|
fds[nfd].revents = 0;
|
|
|
@@ -1640,7 +1650,7 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
//if we have any file descriptors, poll them
|
|
|
//
|
|
|
- if(nfd > 0) {
|
|
|
+ if (nfd > 0) {
|
|
|
poll_return = poll(fds, nfd, POLL_TIMEOUT);
|
|
|
}
|
|
|
|
|
|
@@ -1658,22 +1668,25 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
//if poll didn't net us any work to do,
|
|
|
//
|
|
|
- if(poll_return < 1) {
|
|
|
+ if (poll_return < 1) {
|
|
|
+
|
|
|
//lets try again
|
|
|
//
|
|
|
continue;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- for(i = 0; i < nfd; i++) //Loop through all polled file descriptors
|
|
|
- {
|
|
|
+ // Loop through all polled file descriptors
|
|
|
+ //
|
|
|
+ for (i = 0; i < nfd; i++) {
|
|
|
|
|
|
//If we're looking at the DIU...
|
|
|
//
|
|
|
- if( fds[i].fd == diu_fd ) {
|
|
|
+ if ( fds[i].fd == diu_fd ) {
|
|
|
|
|
|
//if poll says our serial port has become bogus...
|
|
|
//
|
|
|
- if(fds[i].revents & (POLLHUP | POLLERR | POLLNVAL)) {
|
|
|
+ if (fds[i].revents & (POLLHUP | POLLERR | POLLNVAL)) {
|
|
|
fprintf(stderr, "This is very odd... Poll returned flags %d on our serial port...\n", fds[i].revents);
|
|
|
|
|
|
if (diu_fd >= 0) {
|
|
|
@@ -1683,53 +1696,54 @@ int main(int argc, char **argv) {
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- if(fds[i].revents & POLLIN) {
|
|
|
+ if (fds[i].revents & POLLIN) {
|
|
|
read_return = read(fds[i].fd, line, sizeof(line));
|
|
|
|
|
|
- if(read_return > 0) {
|
|
|
+ if (read_return > 0) {
|
|
|
char *trav = line;
|
|
|
|
|
|
line[read_return] = '\0';
|
|
|
strip_crlf(line);
|
|
|
|
|
|
- //advance until EOL or we hit our start sentinel
|
|
|
- while(*trav && (*trav != '/') ) { trav++; }
|
|
|
+ // advance until EOL or we hit our start sentinel
|
|
|
+ //
|
|
|
+ while (*trav && (*trav != '/') ) { trav++; }
|
|
|
|
|
|
- //Check to see that our address header is intact...
|
|
|
+ // Check to see that our address header is intact...
|
|
|
//
|
|
|
- if( (trav[0] == '/') && (trav[2] == ':') ) {
|
|
|
+ if ( (trav[0] == '/') && (trav[2] == ':') ) {
|
|
|
|
|
|
- switch(trav[1]) {
|
|
|
+ switch (trav[1]) {
|
|
|
|
|
|
//-----------------------------------"/T:" means it's a touchscreen event
|
|
|
//
|
|
|
case 'T':
|
|
|
|
|
|
- //advance past the header
|
|
|
+ // advance past the header
|
|
|
//
|
|
|
trav += 3;
|
|
|
|
|
|
retval = sscanf(trav, "%x,%x,%x", &tz, &tx, &ty);
|
|
|
|
|
|
- if(retval == 3) {
|
|
|
- if(tz) {
|
|
|
+ if (retval == 3) {
|
|
|
+ if (tz) {
|
|
|
|
|
|
- if(down_time == 0) {
|
|
|
+ if (down_time == 0) {
|
|
|
down_time = time(NULL);
|
|
|
}
|
|
|
else {
|
|
|
- if( (time(NULL) - down_time) > TS_CALIB_HOLD_TIME) {
|
|
|
+ if ( (time(NULL) - down_time) > TS_CALIB_HOLD_TIME) {
|
|
|
begin_touchscreen_calibration();
|
|
|
calibration = 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
- if(!calibration) {
|
|
|
+ if (!calibration) {
|
|
|
// calibration from here turned off...
|
|
|
}
|
|
|
else {
|
|
|
- if(advance_touchscreen_calibration(tx, ty, tz)) {
|
|
|
+ if (advance_touchscreen_calibration(tx, ty, tz)) {
|
|
|
calibration = 0;
|
|
|
}
|
|
|
else {
|
|
|
@@ -1737,12 +1751,11 @@ int main(int argc, char **argv) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
+ else {
|
|
|
down_time = 0;
|
|
|
- if(!calibration) { }
|
|
|
+ if (!calibration) { }
|
|
|
else {
|
|
|
- if(advance_touchscreen_calibration(tx, ty, tz)) {
|
|
|
+ if (advance_touchscreen_calibration(tx, ty, tz)) {
|
|
|
calibration = 0;
|
|
|
//redraw_flag = 1;
|
|
|
}
|
|
|
@@ -1759,51 +1772,53 @@ int main(int argc, char **argv) {
|
|
|
//
|
|
|
case 'G':
|
|
|
|
|
|
- //advance past the header
|
|
|
+ // advance past the header
|
|
|
//
|
|
|
trav += 3;
|
|
|
|
|
|
- //If this GPS update constitutes a meaningful piece of data
|
|
|
+ // If this GPS update constitutes a meaningful piece of data
|
|
|
//
|
|
|
- if(update_gps(trav) > 0) {
|
|
|
+ if (update_gps(trav) > 0) {
|
|
|
|
|
|
- //and we have a connection to the IPC hub
|
|
|
+ // and we have a connection to the IPC hub
|
|
|
//
|
|
|
- if(hub_fd >= 0) {
|
|
|
+ if (hub_fd >= 0) {
|
|
|
|
|
|
- //Go and toss the data to any other modules who happen to care about GPS
|
|
|
+ // Go and toss the data to any other modules who happen to care about GPS
|
|
|
//
|
|
|
prepare_message(&outgoing_msg, MAILBOX_GPS_STATUS, &my_gps_stat, sizeof(my_gps_stat));
|
|
|
send_message(hub_fd, &outgoing_msg);
|
|
|
}
|
|
|
|
|
|
- last_stale_gps_check = now; //Remember that we did a stale GPS check as part of our update.
|
|
|
+ // Remember that we did a stale GPS check as part of our update.
|
|
|
+ //
|
|
|
+ last_stale_gps_check = now;
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
- //handle warnings
|
|
|
+ // handle warnings
|
|
|
//
|
|
|
case '*':
|
|
|
|
|
|
- //debugs
|
|
|
+ // debugs
|
|
|
//
|
|
|
case '#':
|
|
|
|
|
|
- //and errors
|
|
|
+ // and errors
|
|
|
//
|
|
|
case '!':
|
|
|
|
|
|
- //If this DIU error/debug message has not run afoul of the rate limiting policy...
|
|
|
+ // If this DIU error/debug message has not run afoul of the rate limiting policy...
|
|
|
//
|
|
|
- if( can_report_diu_error() ) {
|
|
|
+ if ( can_report_diu_error() ) {
|
|
|
|
|
|
- //send them all to the log server
|
|
|
+ // send them all to the log server
|
|
|
//
|
|
|
format_log_message(&outgoing_msg, trav[1], "DIU Reports: %s", trav + 3);
|
|
|
send_message(hub_fd, &outgoing_msg);
|
|
|
|
|
|
//but in the case of errors, send them to the driver too
|
|
|
- if(trav[1] == '!') {
|
|
|
+ if (trav[1] == '!') {
|
|
|
format_driver_message(&outgoing_msg, trav[1], "DIU Reports: %s", trav + 3);
|
|
|
send_message(hub_fd, &outgoing_msg);
|
|
|
}
|
|
|
@@ -1832,13 +1847,13 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- //If we're looking at the IPC hub...
|
|
|
+ // If we're looking at the IPC hub...
|
|
|
//
|
|
|
- else if( fds[i].fd == hub_fd ) {
|
|
|
+ else if ( fds[i].fd == hub_fd ) {
|
|
|
|
|
|
- //if poll says our connection to the IPC hub has died...
|
|
|
+ // if poll says our connection to the IPC hub has died...
|
|
|
//
|
|
|
- if(fds[i].revents & (POLLHUP | POLLERR | POLLNVAL)) {
|
|
|
+ if (fds[i].revents & (POLLHUP | POLLERR | POLLNVAL)) {
|
|
|
fprintf(stderr, "The connection to the IPC hub has gone away...\n");
|
|
|
|
|
|
close(hub_fd);
|
|
|
@@ -1846,12 +1861,12 @@ int main(int argc, char **argv) {
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- //if we have mail in any of our mailboxes...
|
|
|
+ // if we have mail in any of our mailboxes...
|
|
|
//
|
|
|
- if(fds[i].revents & POLLIN) {
|
|
|
+ if (fds[i].revents & POLLIN) {
|
|
|
read_return = get_message(hub_fd, &incoming_msg);
|
|
|
|
|
|
- if(read_return < 0) {
|
|
|
+ if (read_return < 0) {
|
|
|
fprintf(stderr, "The connection to the IPC hub has gone away...\n");
|
|
|
|
|
|
close(hub_fd);
|
|
|
@@ -1879,11 +1894,11 @@ int main(int argc, char **argv) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(hub_fd >= 0) {
|
|
|
+ if (hub_fd >= 0) {
|
|
|
close(hub_fd);
|
|
|
}
|
|
|
|
|
|
- if(diu_fd >= 0) {
|
|
|
+ if (diu_fd >= 0) {
|
|
|
write(diu_fd, "/C:----\r",8);
|
|
|
close(diu_fd);
|
|
|
}
|