Renaming variables, types, fields in AP hub sync code

Bug: 29886751

Change-Id: I06a86e570817514bd95c5ec9c8a736d61da74290
diff --git a/firmware/inc/algos/ap_hub_sync.h b/firmware/inc/algos/ap_hub_sync.h
index b47c4dd..ad5d446 100644
--- a/firmware/inc/algos/ap_hub_sync.h
+++ b/firmware/inc/algos/ap_hub_sync.h
@@ -29,32 +29,32 @@
  * This implements an AP-HUB time sync algorithm that is expected to improve time sync accuracy by
  * avoiding communication latency jitter.
  *
- * It uses max of (ap_time - hub_time) in a window, which is more consistent than average, to
+ * It uses max of (apTime - hubTime) in a window, which is more consistent than average, to
  * establish mapping between ap timestamp and hub stamp. Additional low pass filtering is added
  * to further lowering jitter (it is not expected for two clocks to drift much in short time).
  *
- * Max is slightly anti-intuitive here because difference is defined as ap_time - hub_time. Max of
- * that is equivalent to min of hub_time - ap_time, which corresponds to a packet that get delayed
+ * Max is slightly anti-intuitive here because difference is defined as apTime - hubTime. Max of
+ * that is equivalent to min of hubTime - apTime, which corresponds to a packet that get delayed
  * by system scheduling minimally (closer to the more consistent hardware related latency).
  */
 
 struct ApHubSync {
-    uint64_t last_ts;           // ap_time of previous data point, used for control expiration
-    int64_t delta_est;          // the estimated delta between two clocks, filtered.
+    uint64_t lastTs;           // AP time of previous data point, used for control expiration
+    int64_t deltaEstimation;   // the estimated delta between two clocks, filtered.
 
-    int64_t win_max;            // track the maximum timestamp difference in a window
-    uint64_t win_timeout;       // track window expiration time
-    uint8_t state;              // internal state of the sync
+    int64_t windowMax;         // track the maximum timestamp difference in a window
+    uint64_t windowTimeout;    // track window expiration time
+    uint8_t state;             // internal state of the sync
 };
 
 // reset data structure
-void ahsync_reset(struct ApHubSync* sync);
+void apHubSyncReset(struct ApHubSync* sync);
 
-// add a data point (a pair of ap_time and the corresponding hub time).
-void ahsync_add_delta(struct ApHubSync* sync, uint64_t ap_time, uint64_t hub_time);
+// add a data point (a pair of apTime and the corresponding hub time).
+void apHubSyncAddDelta(struct ApHubSync* sync, uint64_t apTime, uint64_t hubTime);
 
 // get the estimation of time delta
-int64_t ahsync_get_delta(struct ApHubSync* sync, uint64_t hub_time);
+int64_t apHubSyncGetDelta(struct ApHubSync* sync, uint64_t hubTime);
 
 #ifdef __cplusplus
 }
diff --git a/firmware/src/algos/ap_hub_sync.c b/firmware/src/algos/ap_hub_sync.c
index 00c46b3..ac04d37 100644
--- a/firmware/src/algos/ap_hub_sync.c
+++ b/firmware/src/algos/ap_hub_sync.c
@@ -35,70 +35,70 @@
     USE_FILTERED
 };
 
-void ahsync_reset(struct ApHubSync* sync) {
+void apHubSyncReset(struct ApHubSync* sync) {
     sync->state = 0;
     if (DEBUG_SYNC) {
         osLog(LOG_DEBUG, "ApHub sync reset");
     }
 }
 
-void ahsync_add_delta(struct ApHubSync* sync, uint64_t ap_time, uint64_t hub_time) {
+void apHubSyncAddDelta(struct ApHubSync* sync, uint64_t apTime, uint64_t hubTime) {
 
-    int64_t delta = ap_time - hub_time;
+    int64_t delta = apTime - hubTime;
 
-    // if data is expired or last_ts is not set before, reset
-    if (ap_time > sync->last_ts + SYNC_EXPIRATION || sync->last_ts == 0) {
-        ahsync_reset(sync);
+    // if data is expired or lastTs is not set before, reset
+    if (apTime > sync->lastTs + SYNC_EXPIRATION || sync->lastTs == 0) {
+        apHubSyncReset(sync);
     }
 
-    sync->last_ts = ap_time;
+    sync->lastTs = apTime;
 
     if (sync->state == NOT_INITED) {
-        // setup the win_max before switching state
-        sync->win_max = delta;
-        sync->win_timeout = ap_time + SYNC_WINDOW_TIMEOUT;
+        // setup the windowMax before switching state
+        sync->windowMax = delta;
+        sync->windowTimeout = apTime + SYNC_WINDOW_TIMEOUT;
 
         sync->state = USE_MAX;
     } else {
-        sync->win_max = (delta > sync->win_max) ? delta : sync->win_max;
-        if (ap_time > sync->win_timeout) {
+        sync->windowMax = (delta > sync->windowMax) ? delta : sync->windowMax;
+        if (apTime > sync->windowTimeout) {
             // collected a window
 
-            // setup delta_est before switching state
+            // setup deltaEstimation before switching state
             if (sync->state == USE_MAX) {
-                sync->delta_est = sync->win_max;
+                sync->deltaEstimation = sync->windowMax;
             } else {
-                sync->delta_est = ((SYNC_FILTER_B - SYNC_FILTER_A) * sync->delta_est +
-                                   SYNC_FILTER_A * sync->win_max) / SYNC_FILTER_B;
+                sync->deltaEstimation = ((SYNC_FILTER_B - SYNC_FILTER_A) * sync->deltaEstimation +
+                                   SYNC_FILTER_A * sync->windowMax) / SYNC_FILTER_B;
             }
             sync->state = USE_FILTERED;
             if (DEBUG_SYNC) {
-                osLog(LOG_DEBUG, "ApHub new sync offset = %" PRId64, sync->delta_est);
+                osLog(LOG_DEBUG, "ApHub new sync offset = %" PRId64, sync->deltaEstimation);
             }
-            // start new window by resetting win_max and win_timeout after this window is done
-            sync->win_max = INT64_MIN;
-            sync->win_timeout = ap_time + SYNC_WINDOW_TIMEOUT;
+            // start new window by resetting windowMax and windowTimeout after this window is done
+            sync->windowMax = INT64_MIN;
+            sync->windowTimeout = apTime + SYNC_WINDOW_TIMEOUT;
         }
     }
 }
 
-int64_t ahsync_get_delta(struct ApHubSync* sync, uint64_t hub_time) {
+int64_t apHubSyncGetDelta(struct ApHubSync* sync, uint64_t hubTime) {
     int64_t ret;
     switch (sync->state) {
         case NOT_INITED:
             ret = 0;
             break;
         case USE_MAX:
-            ret = sync->win_max;
+            ret = sync->windowMax;
             break;
         case USE_FILTERED:
-            ret = sync->delta_est;
+            ret = sync->deltaEstimation;
             break;
         default:
             // indicate error, should never happen
             ret = INT64_MIN;
             osLog(LOG_WARN, "ApHub sync: Invalid sync state %d", sync->state);
-            ahsync_reset(sync);
+            apHubSyncReset(sync);
     }
     return ret;
 }
diff --git a/firmware/src/nanohubCommand.c b/firmware/src/nanohubCommand.c
index ef4fb21..955fcb2 100644
--- a/firmware/src/nanohubCommand.c
+++ b/firmware/src/nanohubCommand.c
@@ -65,7 +65,7 @@
 #define DEBUG_APHUB_TIME_SYNC   false
 
 #if DEBUG_APHUB_TIME_SYNC
-static void syncdbg_add(uint64_t, uint64_t);
+static void syncDebugAdd(uint64_t, uint64_t);
 #endif
 
 struct DownloadState
@@ -646,14 +646,14 @@
 static void addDelta(struct ApHubSync *sync, uint64_t apTime, uint64_t hubTime)
 {
 #if DEBUG_APHUB_TIME_SYNC
-    syncdbg_add(apTime, hubTime);
+    syncDebugAdd(apTime, hubTime);
 #endif
-    ahsync_add_delta(sync, apTime, hubTime);
+    apHubSyncAddDelta(sync, apTime, hubTime);
 }
 
 static int64_t getAvgDelta(struct ApHubSync *sync)
 {
-    return ahsync_get_delta(sync, sensorGetTime());
+    return apHubSyncGetDelta(sync, sensorGetTime());
 }
 
 static int fillBuffer(void *tx, uint32_t totLength, uint32_t *wakeup, uint32_t *nonwakeup)
@@ -1188,82 +1188,82 @@
 
 #define N_APHUB_SYNC_DATA 256
 #define PRINT_DELAY 20000000  // unit ns, 20ms
-struct aphub_sync_debugging_t {
-    uint64_t ap_first;
-    uint64_t hub_first;
-    uint32_t ap_delta[N_APHUB_SYNC_DATA]; // us
-    uint32_t hub_delta[N_APHUB_SYNC_DATA]; // us
-    int print_index; //negative means not printing
-    int write_index;
+struct ApHubSyncDebug {
+    uint64_t apFirst;
+    uint64_t hubFirst;
+    uint32_t apDelta[N_APHUB_SYNC_DATA]; // us
+    uint32_t hubDelta[N_APHUB_SYNC_DATA]; // us
+    int printIndex; //negative means not printing
+    int writeIndex;
 
-    uint32_t timer_id;
+    uint32_t printTimer;
 };
 
-struct aphub_sync_debugging_t aphub_sync_debug = {0};
+struct ApHubSyncDebug mApHubSyncDebug = {0};
 
-static void syncdbg_callback(uint32_t timerId, void *data) {
+static void syncDebugCallback(uint32_t timerId, void *data) {
 
-    if (aphub_sync_debug.print_index >= aphub_sync_debug.write_index ||
-        aphub_sync_debug.print_index >= N_APHUB_SYNC_DATA) {
-        timTimerCancel(aphub_sync_debug.timer_id);
+    if (mApHubSyncDebug.printIndex >= mApHubSyncDebug.writeIndex ||
+        mApHubSyncDebug.printIndex >= N_APHUB_SYNC_DATA) {
+        timTimerCancel(mApHubSyncDebug.printTimer);
 
-        osLog(LOG_DEBUG, "APHUB Done printing %d items", aphub_sync_debug.print_index);
-        aphub_sync_debug.write_index = 0;
-        aphub_sync_debug.print_index = -1;
+        osLog(LOG_DEBUG, "APHUB Done printing %d items", mApHubSyncDebug.printIndex);
+        mApHubSyncDebug.writeIndex = 0;
+        mApHubSyncDebug.printIndex = -1;
 
-        aphub_sync_debug.timer_id = 0;
+        mApHubSyncDebug.printTimer = 0;
     } else {
-        if (aphub_sync_debug.print_index == 0) {
+        if (mApHubSyncDebug.printIndex == 0) {
             osLog(LOG_DEBUG, "APHUB init %" PRIu64 " %" PRIu64,
-                  aphub_sync_debug.ap_first,
-                  aphub_sync_debug.hub_first);
+                  mApHubSyncDebug.apFirst,
+                  mApHubSyncDebug.hubFirst);
         }
 
         osLog(LOG_DEBUG, "APHUB %d %" PRIu32 " %" PRIu32,
-              aphub_sync_debug.print_index,
-              aphub_sync_debug.ap_delta[aphub_sync_debug.print_index],
-              aphub_sync_debug.hub_delta[aphub_sync_debug.print_index]);
+              mApHubSyncDebug.printIndex,
+              mApHubSyncDebug.apDelta[mApHubSyncDebug.printIndex],
+              mApHubSyncDebug.hubDelta[mApHubSyncDebug.printIndex]);
 
-        aphub_sync_debug.print_index++;
+        mApHubSyncDebug.printIndex++;
     }
 }
 
-static void syncdbg_trigger_print() {
-    if (aphub_sync_debug.timer_id) {
+static void syncDebugTriggerPrint() {
+    if (mApHubSyncDebug.printTimer) {
         //printing already going
         return;
     }
 
-    aphub_sync_debug.print_index = 0;
+    mApHubSyncDebug.printIndex = 0;
 
-    syncdbg_callback(0, NULL);
-    if (!(aphub_sync_debug.timer_id =
-          timTimerSet(PRINT_DELAY, 0, 50, syncdbg_callback, NULL, false /*oneShot*/))) {
+    syncDebugCallback(0, NULL);
+    if (!(mApHubSyncDebug.printTimer =
+          timTimerSet(PRINT_DELAY, 0, 50, syncDebugCallback, NULL, false /*oneShot*/))) {
         osLog(LOG_WARN, "Cannot get timer for printing");
 
-        aphub_sync_debug.write_index = 0; // discard all data
-        aphub_sync_debug.print_index = -1; // not printing
+        mApHubSyncDebug.writeIndex = 0; // discard all data
+        mApHubSyncDebug.printIndex = -1; // not printing
     }
 }
 
-static void syncdbg_add(uint64_t ap, uint64_t hub) {
-    if (aphub_sync_debug.write_index >= N_APHUB_SYNC_DATA) {
+static void syncDebugAdd(uint64_t ap, uint64_t hub) {
+    if (mApHubSyncDebug.writeIndex >= N_APHUB_SYNC_DATA) {
         //full
-        syncdbg_trigger_print();
+        syncDebugTriggerPrint();
         return;
     }
 
-    if (aphub_sync_debug.write_index == 0) {
-        aphub_sync_debug.ap_first = ap;
-        aphub_sync_debug.hub_first = hub;
+    if (mApHubSyncDebug.writeIndex == 0) {
+        mApHubSyncDebug.apFirst = ap;
+        mApHubSyncDebug.hubFirst = hub;
     }
 
     // convert ns to us
-    aphub_sync_debug.ap_delta[aphub_sync_debug.write_index] =
-            (uint32_t) U64_DIV_BY_CONST_U16((ap - aphub_sync_debug.ap_first), 1000u);
-    aphub_sync_debug.hub_delta[aphub_sync_debug.write_index] =
-            (uint32_t) U64_DIV_BY_CONST_U16((hub - aphub_sync_debug.hub_first), 1000u);
+    mApHubSyncDebug.apDelta[mApHubSyncDebug.writeIndex] =
+            (uint32_t) U64_DIV_BY_CONST_U16((ap - mApHubSyncDebug.apFirst), 1000u);
+    mApHubSyncDebug.hubDelta[mApHubSyncDebug.writeIndex] =
+            (uint32_t) U64_DIV_BY_CONST_U16((hub - mApHubSyncDebug.hubFirst), 1000u);
 
-    ++aphub_sync_debug.write_index;
+    ++mApHubSyncDebug.writeIndex;
 }
 #endif