A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.
Dependents: oldheating gps motorhome heating
udp/ntp/ntptimestamp.c@200:5acbc41bf469, 2021-05-20 (annotated)
- Committer:
- andrewboyson
- Date:
- Thu May 20 14:32:52 2021 +0000
- Revision:
- 200:5acbc41bf469
- Parent:
- 124:6e558721ec1c
Increased number of arp entries from 20 to 30 to accommodate the number of WIZ devices plus a few incoming port 80 calls from the internet.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewboyson | 124:6e558721ec1c | 1 | #include <stdint.h> |
andrewboyson | 124:6e558721ec1c | 2 | #include <stdbool.h> |
andrewboyson | 124:6e558721ec1c | 3 | |
andrewboyson | 124:6e558721ec1c | 4 | #include "clktime.h" |
andrewboyson | 124:6e558721ec1c | 5 | #include "clkutc.h" |
andrewboyson | 124:6e558721ec1c | 6 | |
andrewboyson | 124:6e558721ec1c | 7 | #define SECONDS_BETWEEN_1900_AND_1970 2208988800ULL |
andrewboyson | 124:6e558721ec1c | 8 | |
andrewboyson | 124:6e558721ec1c | 9 | #define ERA_BASE_LOW 1LL //Adjust this from 0 to 1 between 1968 and 2036; 1 to 2 between 2104 and 2168 |
andrewboyson | 124:6e558721ec1c | 10 | #define ERA_BASE_HGH 0LL //Adjust this from 0 to 1 between 2036 and 2104; 1 to 2 between 2172 and 2240 |
andrewboyson | 124:6e558721ec1c | 11 | |
andrewboyson | 124:6e558721ec1c | 12 | uint64_t NtpTimeStampFromClkTime(clktime tai) |
andrewboyson | 124:6e558721ec1c | 13 | { |
andrewboyson | 124:6e558721ec1c | 14 | clktime utc = ClkUtcFromTai(tai); |
andrewboyson | 124:6e558721ec1c | 15 | uint64_t timestamp = utc << (32 - CLK_TIME_ONE_SECOND_SHIFT); |
andrewboyson | 124:6e558721ec1c | 16 | |
andrewboyson | 124:6e558721ec1c | 17 | timestamp += SECONDS_BETWEEN_1900_AND_1970 << 32; //This should just wrap around the unsigned timestamp removing the unwanted era. |
andrewboyson | 124:6e558721ec1c | 18 | |
andrewboyson | 124:6e558721ec1c | 19 | return timestamp; |
andrewboyson | 124:6e558721ec1c | 20 | } |
andrewboyson | 124:6e558721ec1c | 21 | clktime NtpTimeStampToClkTime(uint64_t timestamp) |
andrewboyson | 124:6e558721ec1c | 22 | { |
andrewboyson | 124:6e558721ec1c | 23 | bool isHigh = (timestamp & (1ULL << 63)) != 0; |
andrewboyson | 124:6e558721ec1c | 24 | |
andrewboyson | 124:6e558721ec1c | 25 | clktime utc = timestamp - (SECONDS_BETWEEN_1900_AND_1970 << 32); |
andrewboyson | 124:6e558721ec1c | 26 | utc >>= (32 - CLK_TIME_ONE_SECOND_SHIFT); |
andrewboyson | 124:6e558721ec1c | 27 | |
andrewboyson | 124:6e558721ec1c | 28 | //Correct for era |
andrewboyson | 124:6e558721ec1c | 29 | if (isHigh) utc += ERA_BASE_HGH << (32 + CLK_TIME_ONE_SECOND_SHIFT); |
andrewboyson | 124:6e558721ec1c | 30 | else utc += ERA_BASE_LOW << (32 + CLK_TIME_ONE_SECOND_SHIFT); |
andrewboyson | 124:6e558721ec1c | 31 | |
andrewboyson | 124:6e558721ec1c | 32 | clktime tai = ClkUtcToTai(utc); |
andrewboyson | 124:6e558721ec1c | 33 | |
andrewboyson | 124:6e558721ec1c | 34 | return tai; |
andrewboyson | 124:6e558721ec1c | 35 | } |
andrewboyson | 124:6e558721ec1c | 36 |