-
Notifications
You must be signed in to change notification settings - Fork 160
TimeSyncHelper for GPS time synchronization #759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Time syncing can already be handled by MicroNMEALocationProvider ... It only has to be correctly constructed (passing the rtc as a parameter) ATM time is only synced when gps gets first fix, this could be made periodic Why not adding a new mechanism for doing that, but I think it should at least be motivated ;) |
I thought in the future there will be other methods for time sync, not just GPS, so a separate helper could be expanded. |
I have two major remarks:
It also blocks the node until a fix is obtained (which in some cases can take forever) Maybe you could get a simpler solution by controlling the existing LocationProvider ? (while still achieving your goal of genericity) asking it to toggle gps until a fix is obtained ? and triggering a new sync after some time ? (enabling location for the time of the sync ...) LocationProvider has a I don't say that the current implementation is perfect (it's been written quite some time ago, I think in february for my custom firmwares), and I'm ok to discuss them and accept changes ... ;) |
It's complicated for some reasons:
What do you mean it takes over the GPS? |
Please, be assured I just want to help you get the functionality merged ;) At the present state (without getting more involved in your code and for that I'd need to be convinced, which I'm not yet), I only guess from what I overread, asking for some details ... I'm sorry, but when I read:
my first guess is that you block the repeater until the initial sync is completed ;) Let's say it's ok, then, If you stop waiting gps after 30s at boot (but I prefer a repeater that boots directly and is not synced than waiting 30s). Maybe you could trigger an advert after sync (or delay the first advert) I've seen you have your own instance of I really think you'd better rely on the Once again, my wish is that you get your functionality in, proposing ways to better integrate with current codebase. In current state I doubt @ripplebiz would merge it but I might be wrong ... Maybe I should have started by saying your code is interesting (which is true) before critisizing it ... but I feel 1/ the functionality is needed 2/ there are some issues to address before integrating it |
I am very assured you want to help don't worry, even if my mediocre english is not reflecting it :) That doesn't block the repeater until the first sync, the TimeSyncHelper::process() is non-blocking, at least I think, because I specifically tried to write it not to. I tested it (altough only on my G2 repeater). I try to look into modifying micronmeaprovider but I wanted a separate instance so if we, say, try to sync from the mesh, or NTP in the future, everything will be in one place and location provider is providing location only as the name says :) |
was just trying to tell you I could not guess before going further in isInitialSyncComplet
I find it nice to have a helper that handles synchronizing (and which can do it from several sources). But I think for the gps, it could delegate some part to the process that handles the gps. There is some balance to find here ... |
I try to refactor, so some commands will be delegated, but I need to be careful, because location is a sensitive data and I really don't wanna touch anything that gives out location. |
this is definitely going the right way ... Now you talk about giving location, I understand your point. But here we should be sure there are barriers in case we don't want to leak locations, and those should be between the location provider and the advertisements ;) (did not think about it yet) I'm wondering why you chose to have all TimeSyncHelper members static ? It has some advantages, but that is not the way other helper classes are constructed. I would prefer to have objects used there for more consistency throughout the code (even if I agree that there this will probably end as a single object ;)) |
|
||
_initialSyncTimeoutCounter++; | ||
|
||
if (sensors._location != nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_location
is only present in EnvironmentSensorManager
so you make an assumption on the sensor_manager that is here ... could be more generic by using this kind of func to get to the gps (I find it complicated but that's what we have for now):
MeshCore/examples/companion_radio/ui-new/UITask.cpp
Lines 750 to 770 in 95d1f05
void UITask::toggleGPS() { | |
if (_sensors != NULL) { | |
// toggle GPS on/off | |
int num = _sensors->getNumSettings(); | |
for (int i = 0; i < num; i++) { | |
if (strcmp(_sensors->getSettingName(i), "gps") == 0) { | |
if (strcmp(_sensors->getSettingValue(i), "1") == 0) { | |
_sensors->setSettingValue("gps", "0"); | |
soundBuzzer(UIEventType::ack); | |
showAlert("GPS: Disabled", 800); | |
} else { | |
_sensors->setSettingValue("gps", "1"); | |
soundBuzzer(UIEventType::ack); | |
showAlert("GPS: Enabled", 800); | |
} | |
_next_refresh = 0; | |
break; | |
} | |
} | |
} | |
} |
I think we could add a more simple getter to access sensors from their name in the code ...
Once you have a link to the locationprovider, it can be a member of your class for later use ...
examples/simple_room_server/main.cpp
Outdated
// send out initial Advertisement to the mesh | ||
// send out initial Advertisement to the mesh | ||
#ifdef ENV_INCLUDE_GPS | ||
while (!TimeSyncHelper::isInitialSyncCompleted()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not letting the repeater work even if the sync has not been done ?
And let TimeSyncHelper send the alert when ready ?
An idea (that has to be discussed) could be to make TimeSyncHelper manage the adverts ? (might be a bad idea, don't really know ...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe let it manage only the initial boot-time advert... I'll think about some solution
|
||
class MyMesh; | ||
extern MyMesh the_mesh; | ||
extern EnvironmentSensorManager sensors; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The target might not use EnvironmentSensorManager ...
the type is defined in target.h ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it is getting way over my head sorry.
maybe I try it after the whole sensors and GPS is cleaned up and refactored to a much more uniform and simpler solution.
I never really coded and don't want to use LLM's to write code I can't understand after.
I did not want to commit it yet, sorry, it's just the first try. |
Please take your time, there is no need to rush And try to simplify as much as possible ;) |
Closing this for now, as I can’t make it fully universal yet, and I don’t want to add an unnecessary sidetrack to the codebase. |
My shot at timesync, because if we have GPS, we shouldn't sync manually.
Tested on G2 repeater.
(enabled on repeaters & room servers with this commit)