GETSEC() is dope!
![ke4pjw](https://forums.parallax.com/uploads/userpics/828/nPYIHEX8MXNFN.jpg)
in Propeller 2
Just used GETSEC() for the first time. I needed a 5 second timout for my DNS resolver. That's so sweet!
' Set timeout to 5 seconds l := GETSEC() + 5 repeat until W6100.ReceiveData(W6100.IDM_BSR_Socket0_Register,1) == 0 if GETSEC() >= l debug("DNS Server timed out.") return -1
I now have designs to couple GETSEC() with a NTP client to calculate and update system time.
Thanks for adding that in! Very convenient!
Comments
You could get a more precise timeout, and with slightly less computation, if you just did it the old-fashioned way:
This is also guaranteed to never overflow - your way will hang for 2^32 seconds if called at just the wrong time (which happens only every 2^32 seconds, which is almost never, but still, why write slower, less robust code if you don't have to).
I do the same thing with getms() -- this is my timeout code in a Ping))) object for the P2. The combination of smart pins and getms() and getsec() is kind of neat.
So my thinking was, when GETSEC() overflows 32 bits, that will be about 136 years from P2 boot time. So I am not worried about it.
cnt will roll over once every 15 seconds or so at 270MHz, right? So you have to take that into account, which you have in your code. It just takes more calculations. The same rollover could be applied to what I did, but none of us will be around to test it![:) :)](https://forums.parallax.com/resources/emoji/smile.png)
Thank you for sharing! I will implement your logic, for it to properly deal with the rollover at 136 years after boot time.
I was mostly excited about the prospect of being able to back into the epoch of the boot time via a network clock and know the real time based on that. (And periodically adjusting for drift.) A one second counter is very handy, specifically for that.