-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add time synchronisation with NTP (#579)
* Add api::time::from_timestamp_utc function * Add date function to lisp * Add file/exists? function to lisp * Rewrite lisp ntp client * Update NTP packet to work with more servers * Fix userspace binaries build
- Loading branch information
Showing
7 changed files
with
52 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!lisp | ||
|
||
(load "/lib/lisp/core.lsp") | ||
|
||
(var config "/ini/ntp") | ||
(var default-server "time.cloudflare.com") | ||
|
||
(var server (if (not (nil? args)) | ||
(first args) | ||
(if (file/exists? config) (str/trim (read config)) default-server))) | ||
(var addr (or (host server) server)) | ||
(var port 123) | ||
(var socket (socket/connect "udp" addr port)) | ||
|
||
(var req (map (fun (i) (if (eq? i 0) 0x23 0)) (range 0 48))) | ||
(file/write socket req) | ||
(var res (file/read socket 48)) | ||
|
||
(var buf (slice res 40 4)) | ||
(var time (- (bin->num (concat '(0 0 0 0) buf) "int") 2208988800)) | ||
(print (date time)) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters