aboutsummaryrefslogtreecommitdiff
path: root/tools/obu-ping
diff options
context:
space:
mode:
Diffstat (limited to 'tools/obu-ping')
-rwxr-xr-xtools/obu-ping38
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)