expect seqNo in payload and not in port

This commit is contained in:
Marius Gripp 2019-08-13 13:16:56 +02:00
parent ce7d3ab292
commit 730f35babf
3 changed files with 7 additions and 7 deletions

View File

@ -7,7 +7,7 @@
#include "timekeeper.h" #include "timekeeper.h"
//#define TIME_SYNC_TRIGGER 100 // threshold for time sync [milliseconds] //#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] #define TIME_SYNC_FIXUP 4 // calibration to fixup processing time [milliseconds]
void timesync_init(void); void timesync_init(void);

View File

@ -265,9 +265,9 @@ void onEvent(ev_t ev) {
#if (TIME_SYNC_LORASERVER) #if (TIME_SYNC_LORASERVER)
// timesync answer -> call timesync processor // timesync answer -> call timesync processor
if ((LMIC.frame[LMIC.dataBeg - 1] >= TIMEANSWERPORT_MIN) && if ((LMIC.frame[LMIC.dataBeg] >= TIMEANSWERPORT_MIN) &&
(LMIC.frame[LMIC.dataBeg - 1] <= TIMEANSWERPORT_MAX)) { (LMIC.frame[LMIC.dataBeg] <= TIMEANSWERPORT_MAX)) {
recv_timesync_ans(LMIC.frame[LMIC.dataBeg - 1], recv_timesync_ans(LMIC.frame[LMIC.dataBeg],
LMIC.frame + LMIC.dataBeg, LMIC.dataLen); LMIC.frame + LMIC.dataBeg, LMIC.dataLen);
break; break;
} }

View File

@ -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 else { // we received a probably valid time frame
uint8_t k = seq_no % TIME_SYNC_SAMPLES; 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 // the 5th byte contains the fractional seconds in 2^-8 second steps
// (= 1/250th sec), we convert this to ms // (= 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 // pointers to 4 bytes 4 bytes containing UTC seconds since unix epoch, msb
uint32_t timestamp_sec, *timestamp_ptr; uint32_t timestamp_sec, *timestamp_ptr;
// convert buffer to uint32_t, octet order is big endian // 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 // swap byte order from msb to lsb, note: this is platform dependent
timestamp_sec = __builtin_bswap32(*timestamp_ptr); timestamp_sec = __builtin_bswap32(*timestamp_ptr);