expect seqNo in payload and not in port
This commit is contained in:
parent
ce7d3ab292
commit
730f35babf
@ -7,7 +7,7 @@
|
||||
#include "timekeeper.h"
|
||||
|
||||
//#define TIME_SYNC_TRIGGER 100 // threshold for time sync [milliseconds]
|
||||
#define TIME_SYNC_FRAME_LENGTH 0x05 // timeserver answer frame length [bytes]
|
||||
#define TIME_SYNC_FRAME_LENGTH 0x06 // timeserver answer frame length [bytes]
|
||||
#define TIME_SYNC_FIXUP 4 // calibration to fixup processing time [milliseconds]
|
||||
|
||||
void timesync_init(void);
|
||||
|
@ -265,9 +265,9 @@ void onEvent(ev_t ev) {
|
||||
|
||||
#if (TIME_SYNC_LORASERVER)
|
||||
// timesync answer -> call timesync processor
|
||||
if ((LMIC.frame[LMIC.dataBeg - 1] >= TIMEANSWERPORT_MIN) &&
|
||||
(LMIC.frame[LMIC.dataBeg - 1] <= TIMEANSWERPORT_MAX)) {
|
||||
recv_timesync_ans(LMIC.frame[LMIC.dataBeg - 1],
|
||||
if ((LMIC.frame[LMIC.dataBeg] >= TIMEANSWERPORT_MIN) &&
|
||||
(LMIC.frame[LMIC.dataBeg] <= TIMEANSWERPORT_MAX)) {
|
||||
recv_timesync_ans(LMIC.frame[LMIC.dataBeg],
|
||||
LMIC.frame + LMIC.dataBeg, LMIC.dataLen);
|
||||
break;
|
||||
}
|
||||
|
@ -174,15 +174,15 @@ int recv_timesync_ans(uint8_t seq_no, uint8_t buf[], uint8_t buf_len) {
|
||||
else { // we received a probably valid time frame
|
||||
|
||||
uint8_t k = seq_no % TIME_SYNC_SAMPLES;
|
||||
|
||||
uint8_t *timestamp_buf = buf+1;
|
||||
// the 5th byte contains the fractional seconds in 2^-8 second steps
|
||||
// (= 1/250th sec), we convert this to ms
|
||||
uint16_t timestamp_msec = 4 * buf[4];
|
||||
uint16_t timestamp_msec = 4 * timestamp_buf[4];
|
||||
// pointers to 4 bytes 4 bytes containing UTC seconds since unix epoch, msb
|
||||
uint32_t timestamp_sec, *timestamp_ptr;
|
||||
|
||||
// convert buffer to uint32_t, octet order is big endian
|
||||
timestamp_ptr = (uint32_t *)buf;
|
||||
timestamp_ptr = (uint32_t *)timestamp_buf;
|
||||
// swap byte order from msb to lsb, note: this is platform dependent
|
||||
timestamp_sec = __builtin_bswap32(*timestamp_ptr);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user