From 5e002f200691d5fd9c46ff645668b82e17c2261b Mon Sep 17 00:00:00 2001 From: Ebus-at-dockstar Date: Tue, 30 Apr 2013 17:49:26 +0200 Subject: ebus-racket: inserter adaption; remove tcp-repl --- ebus-racket/inserter.rkt | 22 +++++++--------------- ebus-racket/util/tcp-repl.rkt | 35 ----------------------------------- 2 files changed, 7 insertions(+), 50 deletions(-) delete mode 100644 ebus-racket/util/tcp-repl.rkt (limited to 'ebus-racket') diff --git a/ebus-racket/inserter.rkt b/ebus-racket/inserter.rkt index cd05ad9..a5a7ac8 100755 --- a/ebus-racket/inserter.rkt +++ b/ebus-racket/inserter.rkt @@ -1,11 +1,10 @@ #! /usr/bin/env racket #lang racket/base (require racket/cmdline - racket/tcp racket/stream + racket/tcp net/url "ebus/layer7.rkt" - "util/tcp-repl.rkt" "util/json.rkt") (define logger (make-logger 'ebus-inserter (current-logger))) @@ -13,7 +12,7 @@ (define connect-host? (make-parameter null)) (define connect-port? (make-parameter null)) (define insert? (make-parameter #f)) -(define baseurl? (make-parameter "http://localhost:8000/sensor")) +(define baseurl? (make-parameter "http://localhost:8080/api")) ;; Send field and value to database server (define (insert-field sensor-name datatype offset value) @@ -21,19 +20,14 @@ ((member datatype (list "bit" "byte" "data1b" "word" "bcd")) "int") ((member datatype (list "byteEnum")) "string"))) (set! value (cond ((string=? type "float") (real->decimal-string value)) + ((string=? type "int") (number->string value)) (else value))) - (define response - (read-line (put-pure-port - (string->url (format "~a/~a" (baseurl?) sensor-name)) - (string->bytes/utf-8 (format "value=~a&type=~a" value type))))) - (define responseJson (string->jsexpr response)) - (cond ((eq? (json-null) (hash-ref responseJson 'error)) - (log-message logger 'debug (format "Successful insert: type=~a value=~a" - type value) #t)) - (else (log-message logger 'error (format "Error: type=~a value=~a ERROR:~a" - type value response) #t)))) + (put-pure-port + (string->url (format "~a/value/~a" (baseurl?) sensor-name)) + (string->bytes/utf-8 value))) (define (handle-packet packet) + (for ([field packet]) (log-message logger 'info (format "Field: ~a" field) #t) (when (insert?) @@ -54,8 +48,6 @@ [("-c" "--connect") host port "Connect to server " (connect-host? host) (connect-port? (string->number port))] - ["--tcp-repl" port "Open REPL on TCP " - (tcp-repl-run (namespace-anchor->namespace repl-ns-anchor) (string->number port))] ["--insert" "Do Insert into Database" (insert? #t)] ["--baseurl" url "Database server http url" diff --git a/ebus-racket/util/tcp-repl.rkt b/ebus-racket/util/tcp-repl.rkt deleted file mode 100644 index 4b19d85..0000000 --- a/ebus-racket/util/tcp-repl.rkt +++ /dev/null @@ -1,35 +0,0 @@ -(module tcp-repl racket/base - (require mzlib/thread - racket/tcp) - (provide (prefix-out tcp-repl- run) - (prefix-out tcp-repl- logger)) - - (define logger (make-logger 'tcp-repl (current-logger))) - - (define (run namespace port) - (thread - (lambda () - (run-server port ; TCP-Port - (make-connection-handler namespace) ; connection handler - #f; timeout - (lambda (tcp-port max-allow-wait reuse?) ; listen handler - (log-message logger 'info (format "Listen on ~a:~a" "127.0.0.1" tcp-port) #t) - (tcp-listen tcp-port max-allow-wait reuse? "127.0.0.1")) - )))) - - (define (tcp-tostring port) - (let-values ([(address-from port-from address-to port-to) (tcp-addresses port #t)]) - (format "~a:~a -> ~a:~a" address-from port-from address-to port-to))) - - (define (make-connection-handler namespace) - (lambda (ip op) - (let/ec exit - (log-message logger 'info (format "New Connection ~a" (tcp-tostring ip)) #t) - (parameterize ([current-input-port ip] - [current-output-port op] - [current-error-port op] - [current-namespace namespace]) - (read-eval-print-loop)) - (log-message logger 'info (format "End Connection ~a" (tcp-tostring ip)) #t) - (close-output-port op)))) - ) ; end module tcp-repl \ No newline at end of file -- cgit v1.2.1