diff options
author | stuebinm | 2023-05-26 21:07:48 +0200 |
---|---|---|
committer | stuebinm | 2023-05-26 21:14:20 +0200 |
commit | e029a031050e08599f9d6d5fa654c17d985039c1 (patch) | |
tree | 3b4dd35bf6f6a8495b47ac5158a954151c9c0b55 /tools/obu-ping | |
parent | 8737181eac0dce062ff0541e263ba0bf6a772c66 (diff) |
expose sequence length of trip to onboard unit
Diffstat (limited to '')
-rwxr-xr-x | tools/obu-ping | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/tools/obu-ping b/tools/obu-ping index 2897e23..8d0a84a 100755 --- a/tools/obu-ping +++ b/tools/obu-ping @@ -78,11 +78,11 @@ Arguments: (while #t (ping-pos statefile url token)))) -(define (ping-pos dir url token) +(define (ping-pos statefile url token) (let ([pos (try-get-current-pos)]) (display (format "~a\n" pos)) (if (not (equal? token #f)) - (display (format "server: ~a\n" (ping url token pos)))))) + (display (format "server: ~a\n" (ping url token pos statefile)))))) (define (get-token url trip statefile) (define cached? @@ -109,18 +109,26 @@ Arguments: :secure tls) 2)))) -(define (ping url token pos) +(define (ping url token pos statefile) (define tls (equal? (uri-ref url 'scheme) "https")) - (parameterize ([json-object-handler json-symbol-key]) - (parse-json-string - (values-ref (http-post - (uri-ref url 'host+port) - "/api/train/ping" - (construct-json-string `((token . ,token) - (lat . ,(assoc-ref pos 'lat)) - (long . ,(assoc-ref pos 'lon)) - (timestamp . ,(assoc-ref pos 'time)))) - :content-type "application/json" - :secure tls) - 2)))) + (define anchor + (parameterize ([json-object-handler json-symbol-key]) + (parse-json-string + (values-ref (http-post + (uri-ref url 'host+port) + "/api/train/ping" + (construct-json-string `((token . ,token) + (lat . ,(assoc-ref pos 'lat)) + (long . ,(assoc-ref pos 'lon)) + (timestamp . ,(assoc-ref pos 'time)))) + :content-type "application/json" + :secure tls) + 2)))) + (define sequencelength + (guard [e (else 100000)] + (with-input-from-process `(obu-config -s ,statefile sequencelength) read))) + (if (> (assoc-ref anchor 'sequence) (sequencelength - 0.2)) + (do-process `(obu-config -s ,statefile -d token)) + #f) + anchor) |