diff --git a/include/timesync.h b/include/timesync.h index 82da84f7..8b8c42bc 100644 --- a/include/timesync.h +++ b/include/timesync.h @@ -12,7 +12,9 @@ void timesync_init(void); void send_timesync_req(void); -int recv_timesync_ans(const uint8_t seq_no, const uint8_t buf[], const uint8_t buf_len); + +int recv_timesync_ans(const uint8_t buf[], uint8_t buf_len); + void process_timesync_req(void *taskparameter); void store_time_sync_req(uint32_t t_millisec); diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 088d4305..e6aa7114 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -561,8 +561,8 @@ void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg, #if (TIME_SYNC_LORASERVER) // valid timesync answer -> call timesync processor - if ((port >= TIMEANSWERPORT_MIN) && (port <= TIMEANSWERPORT_MAX)) { - recv_timesync_ans(port, pMsg, nMsg); + if (port == TIMEPORT) { + recv_timesync_ans(pMsg, nMsg); break; } #endif diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 40852f59..f7826a9a 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -30,7 +30,7 @@ * |< Scan Window > |< Scan Window > | ... |< Scan Window > | * |< Scan Interval >|< Scan Interval >| ... |< Scan Interval >| * |< Scan duration >| -* +* * Scan duration sets how long scanning should be going on, before starting a new scan cycle. 0 means infinite (default). * Scan window sets how much of the interval should be occupied by scanning. Should be >= BLESCANINTERVAL. * Scan interval is how long scanning should be done on each channel. BLE uses 3 channels for advertising. @@ -97,9 +97,9 @@ #define BEACONPORT 6 // beacon alarms #define BMEPORT 7 // BME680 sensor #define BATTPORT 8 // battery voltage -#define TIMEPORT 9 // time query -#define TIMEANSWERPORT_MIN 0xA0 // time answer, start of port range -#define TIMEANSWERPORT_MAX 0xDF // time answer, end of port range +#define TIMEPORT 9 // time query and response +#define TIMEDIFFPORT 13 // time adjust diff +#define TIMEREQUEST_MAX_SEQNO 250 // time answer, start of port range #define SENSOR1PORT 10 // user sensor #1 #define SENSOR2PORT 11 // user sensor #2 #define SENSOR3PORT 12 // user sensor #3 diff --git a/src/timesync.cpp b/src/timesync.cpp index 6c60a225..a50d7ca1 100644 --- a/src/timesync.cpp +++ b/src/timesync.cpp @@ -25,7 +25,7 @@ typedef std::chrono::duration> TaskHandle_t timeSyncReqTask = NULL; -static uint8_t time_sync_seqNo = random(TIMEANSWERPORT_MIN, TIMEANSWERPORT_MAX); +static uint8_t time_sync_seqNo = 0; static bool timeSyncPending = false; static myClock_timepoint time_sync_tx[TIME_SYNC_SAMPLES]; static myClock_timepoint time_sync_rx[TIME_SYNC_SAMPLES]; @@ -93,9 +93,10 @@ void process_timesync_req(void *taskparameter) { time_point_cast(time_sync_tx[k]); // wrap around seqNo, keeping it in time port range - time_sync_seqNo = (time_sync_seqNo < TIMEANSWERPORT_MAX) - ? time_sync_seqNo + 1 - : TIMEANSWERPORT_MIN; + time_sync_seqNo++; + if(time_sync_seqNo > TIMEREQUEST_MAX_SEQNO) { + time_sync_seqNo = 0; + } if (i < TIME_SYNC_SAMPLES - 1) { // wait until next cycle @@ -154,7 +155,9 @@ void store_time_sync_req(uint32_t timestamp) { } // process timeserver timestamp answer, called from lorawan.cpp -int recv_timesync_ans(const uint8_t seq_no, const uint8_t buf[], const uint8_t buf_len) { +int recv_timesync_ans(const uint8_t buf[], const uint8_t buf_len) { + uint8_t seq_no = buf[0]; + buf++; // if no timesync handshake is pending then exit if (!timeSyncPending) @@ -223,4 +226,4 @@ void timesync_init() { 1); // CPU core } -#endif \ No newline at end of file +#endif