Quellcode durchsuchen

resolves #31

* adding 'help' option that displays semantic version
* populates `gps_stat` from initial `state_info` load
* sends an initial `send_status_update()` on startup (after IPC connect)
  to push out state information
* loads paddle after initial `state_info` load
* still some question as to whether this will handle the `paddlemgr` going
  down and restoring enough state to correctly identify position for `billing_log`
  entries, but hopefully this should be a good start

marking as resovling #31 as this is a good first effort and fixes for
the underlying `billing_log` entries misidentifiying driver, equipment number,
paddle/trip/route/stop will need more investigation as to why it's occuring
to get a better fix.
abetusk vor 4 Jahren
Ursprung
Commit
cbe0778cbf
1 geänderte Dateien mit 33 neuen und 0 gelöschten Zeilen
  1. 33 0
      busunit/paddlemgr/paddlemgr.c

+ 33 - 0
busunit/paddlemgr/paddlemgr.c

@@ -40,6 +40,8 @@
 #include "../commhub/client_utils.h"
 #include "../common/gpsmath.h"
 
+#define PADDLEMGR_VERSION "0.1.1"
+
 // structure for loading stop definitions
 //
 typedef struct stop_struct {
@@ -431,6 +433,8 @@ int main(int argc, char **argv) {
 
   struct message_record incoming_msg;
 
+  int send_initial_status_update = 0;
+
 #ifdef DEBUG_PRINT
   long long int _usec_now, _usec_prv, _usec_del;
   _usec_now = get_usec_time();
@@ -438,6 +442,31 @@ int main(int argc, char **argv) {
   _usec_del = 60000000;
 #endif
 
+  if ( (argc>1) && (
+       (strncmp(argv[1], "-h", 3)==0) ||
+       (strncmp(argv[1], "-v", 3)==0) ) ) {
+    printf("paddlemgr version: %s\n", PADDLEMGR_VERSION);
+    exit(0);
+  }
+
+  //----
+
+  // try to restore as much state as possible
+  //
+  init_state_info();
+
+  gps_stat.lat = state_info.lat;
+  gps_stat.lon = state_info.lon;
+  gps_stat.gps_good = state_info.gps_good;
+  gps_stat.num_sats = state_info.num_sats;
+
+  if (state_info.paddle != 0) {
+    if (load_paddle(state_info.paddle) >= 0) {
+      send_initial_status_update = 1;
+    }
+  }
+  //----
+
   configure_signal_handlers(argv[0]);
   maintain_ipc_hub_connect(argv[0]);
 
@@ -453,6 +482,10 @@ int main(int argc, char **argv) {
   register_dispatch_callback(MAILBOX_NEXT_STOP, CALLBACK_USER(4), handle_next_req, NULL);
   register_dispatch_callback(MAILBOX_PREV_STOP, CALLBACK_USER(5), handle_prev_req, NULL);
 
+  //---
+  if (send_initial_status_update) { send_status_update(); }
+  //---
+
   while( exit_request_status == EXIT_REQUEST_NONE ) {
 
     RESET_WATCHDOG();