stanleyhuangyc / Freematics

Official source code repository for Freematics
https://freematics.com
430 stars 349 forks source link

teleserver: reduces teleloger-timestamp(ticks) from 64bit-->32bit and overflows every 2 weeks #168

Open ankostis opened 1 year ago

ankostis commented 1 year ago

(i'm surprised nobody else has reported this)

The telelogger (v5) transmits uint64 for timestamps from CPU ticks https://github.com/stanleyhuangyc/Freematics/blob/98f38d9c921fdd55598bff1012e846e6e8dfefae/firmware_v5/telelogger/teleclient.cpp#L161 but teleserver although it uses atol() to parse it back, it assigns the result in a uint32(!): https://github.com/stanleyhuangyc/Freematics/blob/98f38d9c921fdd55598bff1012e846e6e8dfefae/server/teleserver/teleserver.h#L87 https://github.com/stanleyhuangyc/Freematics/blob/98f38d9c921fdd55598bff1012e846e6e8dfefae/server/teleserver/udpserver.c#L115 https://github.com/stanleyhuangyc/Freematics/blob/98f38d9c921fdd55598bff1012e846e6e8dfefae/server/teleserver/udpserver.c#L129-L131

Indeed we have noticed that device-ticks overflow at random durations, roughly before ~20 days (31bits correspond to ~25days, 32-->49days).

Q1: is this analysis correct? Q2: (if yes) is this on purpose? Q3: (if no) would you accept a PR to fix it?