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 timesync_init(void);
void send_timesync_req(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 process_timesync_req(void *taskparameter);
void store_time_sync_req(uint32_t t_millisec); 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) #if (TIME_SYNC_LORASERVER)
// valid timesync answer -> call timesync processor // valid timesync answer -> call timesync processor
if ((port >= TIMEANSWERPORT_MIN) && (port <= TIMEANSWERPORT_MAX)) { if (port == TIMEPORT) {
recv_timesync_ans(port, pMsg, nMsg); recv_timesync_ans(pMsg, nMsg);
break; break;
} }
#endif #endif

View File

@ -30,7 +30,7 @@
* |< Scan Window > |< Scan Window > | ... |< Scan Window > | * |< Scan Window > |< Scan Window > | ... |< Scan Window > |
* |< Scan Interval >|< Scan Interval >| ... |< Scan Interval >| * |< Scan Interval >|< Scan Interval >| ... |< Scan Interval >|
* |< Scan duration >| * |< Scan duration >|
* *
* Scan duration sets how long scanning should be going on, before starting a new scan cycle. 0 means infinite (default). * 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 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. * 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 BEACONPORT 6 // beacon alarms
#define BMEPORT 7 // BME680 sensor #define BMEPORT 7 // BME680 sensor
#define BATTPORT 8 // battery voltage #define BATTPORT 8 // battery voltage
#define TIMEPORT 9 // time query #define TIMEPORT 9 // time query and response
#define TIMEANSWERPORT_MIN 0xA0 // time answer, start of port range #define TIMEDIFFPORT 13 // time adjust diff
#define TIMEANSWERPORT_MAX 0xDF // time answer, end of port range #define TIMEREQUEST_MAX_SEQNO 250 // time answer, start of port range
#define SENSOR1PORT 10 // user sensor #1 #define SENSOR1PORT 10 // user sensor #1
#define SENSOR2PORT 11 // user sensor #2 #define SENSOR2PORT 11 // user sensor #2
#define SENSOR3PORT 12 // user sensor #3 #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; 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 bool timeSyncPending = false;
static myClock_timepoint time_sync_tx[TIME_SYNC_SAMPLES]; static myClock_timepoint time_sync_tx[TIME_SYNC_SAMPLES];
static myClock_timepoint time_sync_rx[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]); time_point_cast<milliseconds>(time_sync_tx[k]);
// wrap around seqNo, keeping it in time port range // wrap around seqNo, keeping it in time port range
time_sync_seqNo = (time_sync_seqNo < TIMEANSWERPORT_MAX) time_sync_seqNo++;
? time_sync_seqNo + 1 if(time_sync_seqNo > TIMEREQUEST_MAX_SEQNO) {
: TIMEANSWERPORT_MIN; time_sync_seqNo = 0;
}
if (i < TIME_SYNC_SAMPLES - 1) { if (i < TIME_SYNC_SAMPLES - 1) {
// wait until next cycle // wait until next cycle
@ -154,7 +155,9 @@ void store_time_sync_req(uint32_t timestamp) {
} }
// process timeserver timestamp answer, called from lorawan.cpp // 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 no timesync handshake is pending then exit
if (!timeSyncPending) if (!timeSyncPending)
@ -223,4 +226,4 @@ void timesync_init() {
1); // CPU core 1); // CPU core
} }
#endif #endif