Skip to content

Commit 776c850

Browse files
martinjaegercarlescufi
authored andcommitted
lorawan: services: clock_sync: fix resync with multiple transmissions
Only the first resync transmission was sent out immediately because the work item was rescheduled to the usual periodicity in the work handler immediately after sending out the first transmission. Signed-off-by: Martin Jäger <[email protected]>
1 parent 8bb9bb6 commit 776c850

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

subsys/lorawan/services/clock_sync.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,6 @@ static int clock_sync_app_time_req(void)
191191

192192
lorawan_services_schedule_uplink(LORAWAN_PORT_CLOCK_SYNC, tx_buf, tx_pos, 0);
193193

194-
if (ctx.nb_transmissions > 0) {
195-
ctx.nb_transmissions--;
196-
lorawan_services_reschedule_work(&ctx.resync_work, K_SECONDS(CLOCK_RESYNC_DELAY));
197-
}
198-
199194
return 0;
200195
}
201196

@@ -205,10 +200,15 @@ static void clock_sync_resync_handler(struct k_work *work)
205200

206201
clock_sync_app_time_req();
207202

208-
/* Add +-30s jitter to actual periodicity as required */
209-
periodicity = ctx.periodicity - 30 + sys_rand32_get() % 61;
203+
if (ctx.nb_transmissions > 0) {
204+
ctx.nb_transmissions--;
205+
lorawan_services_reschedule_work(&ctx.resync_work, K_SECONDS(CLOCK_RESYNC_DELAY));
206+
} else {
207+
/* Add +-30s jitter to actual periodicity as required */
208+
periodicity = ctx.periodicity - 30 + sys_rand32_get() % 61;
210209

211-
lorawan_services_reschedule_work(&ctx.resync_work, K_SECONDS(periodicity));
210+
lorawan_services_reschedule_work(&ctx.resync_work, K_SECONDS(periodicity));
211+
}
212212
}
213213

214214
int lorawan_clock_sync_get(uint32_t *gps_time)

0 commit comments

Comments
 (0)