diff options
Diffstat (limited to 'ebus-racket/layer7.rkt')
-rw-r--r-- | ebus-racket/layer7.rkt | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/ebus-racket/layer7.rkt b/ebus-racket/layer7.rkt index 95739e6..eb37e91 100644 --- a/ebus-racket/layer7.rkt +++ b/ebus-racket/layer7.rkt @@ -4,11 +4,12 @@ (planet lizorkin/ssax:2:0/ssax) "layer2.rkt") +(define logger (make-logger 'ebus-layer7 (current-logger))) + (define definition (ssax:xml->sxml (open-input-file "../ebus-xml/ebus.xml") '[(#f . "http://xapek.org/ebus/0.1")])) - (define (paket ebus-paket) (define primaryCommand (layer2-ebus-paket-primaryCommand ebus-paket)) (define secondaryCommand (layer2-ebus-paket-secondaryCommand ebus-paket)) @@ -23,22 +24,24 @@ ;; returns device-name in a list or empty-list (define (device-name address) - ((sxpath "@name/text()") (device address))) + (first ((sxpath "@name/text()") (device address)))) (define (paket-fields ebus-paket) (define paket-definition (paket ebus-paket)) (cond ((> (length paket-definition) 0) (let* - ([paket-name (first ((sxpath "@name/text()") paket-definition))] + ([paket-name (string-append + (device-name (layer2-ebus-paket-source ebus-paket)) + "." + (first ((sxpath "@name/text()") paket-definition)))] [fields ((sxpath "fields/*") paket-definition)] [values (for/list ([field fields]) (paket-fields-dispatch-decoder ebus-paket field paket-name))]) ;; filter invalid values (for/list ([value values] #:when (not (void? value))) value))) - (else (display (format "Unknown Paket: ~s~n" ebus-paket)) - (void)))) + (else (void (log-message logger 'warning (format "Unknown Paket: ~s" ebus-paket) #t))))) (define (paket-fields-dispatch-decoder ebus-paket field paket-name) (define datatype ((sxpath "name()") field)) @@ -74,8 +77,7 @@ ((string=? "byteEnum" datatype) (list name datatype offset (field-decoder-byteEnum (list-ref payload offset) field))) - (else (display (string-append "unknown datatype: " datatype "\n")) - (void)))) + (else (void (log-message logger 'error (format "unknown datatype: ~a" datatype) #t))))) ;; type bit (define (field-decoder-bit value) @@ -150,4 +152,5 @@ (prefix-out layer7- device) (prefix-out layer7- device-name) ;; read ebus from port an return fields from next paket - (prefix-out layer7- read-ebus))
\ No newline at end of file + (prefix-out layer7- read-ebus) + (prefix-out layer7- logger))
\ No newline at end of file |