move timesync seq_no into message body from port

This commit is contained in:
Marius Gripp 2019-10-04 15:31:31 +02:00
parent f86bfaefb6
commit ba732012b9
4 changed files with 18 additions and 13 deletions

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -25,7 +25,7 @@ typedef std::chrono::duration<long long int, std::ratio<1, 1000>>
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<milliseconds>(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
#endif