From 039c464876311588cfd9ad5eb86273eb22ba66e6 Mon Sep 17 00:00:00 2001 From: Ebus-at-dockstar Date: Wed, 17 Sep 2014 00:03:59 +0200 Subject: ebus-raket: decoder for byte, dumper: output l2+l7 --- ebus-racket/dumper.rkt | 26 ++++++++++---------------- ebus-racket/ebus/layer7.rkt | 16 ++++++++++------ 2 files changed, 20 insertions(+), 22 deletions(-) (limited to 'ebus-racket') diff --git a/ebus-racket/dumper.rkt b/ebus-racket/dumper.rkt index 95081d1..285261b 100755 --- a/ebus-racket/dumper.rkt +++ b/ebus-racket/dumper.rkt @@ -10,13 +10,10 @@ ;(define verbose? (make-parameter #f)) (define connect-host? (make-parameter null)) (define connect-port? (make-parameter null)) -(define layer7? (make-parameter #f)) (define greeting (command-line #:once-each - [("-a" "--layer7") - "Parse Layer7" (layer7? #t)] [("-c" "--connect") host port "Connect to server " @@ -35,19 +32,16 @@ (define (read-ebus-loop2 input-port) (let ([paket (layer2-read-ebus (current-input-port))]) (pretty-print paket) + (pretty-print (layer7-paket-parse paket)) (cond ((not (eof-object? paket)) (read-ebus-loop2 input-port))))) -(define (read-ebus-loop7 input-port) - (let ([fields (layer7-read-ebus (current-input-port))]) - (if (not (void? fields)) - (pretty-print fields) - (display "")) - (cond ((not (eof-object? fields)) (read-ebus-loop7 input-port))))) +;(define (read-ebus-loop7 input-port) +; (let ([fields (layer7-read-ebus (current-input-port))]) +; (if (not (void? fields)) +; (pretty-print fields) +; (display "")) +; (cond ((not (eof-object? fields)) (read-ebus-loop7 input-port))))) -(if (layer7?) - (let () - (display "Layer 7\n") - (read-ebus-loop7 (current-input-port))) - (let () - (display "Layer 2\n") - (read-ebus-loop2 (current-input-port)))) +(let () + (display "Layer 2\n") + (read-ebus-loop2 (current-input-port))) diff --git a/ebus-racket/ebus/layer7.rkt b/ebus-racket/ebus/layer7.rkt index b43a58a..b2947a0 100644 --- a/ebus-racket/ebus/layer7.rkt +++ b/ebus-racket/ebus/layer7.rkt @@ -71,14 +71,14 @@ (make-hash (list (list 'bit (lambda (name field offset payload) (list name 'bit (field-decoder-bit (list-ref payload offset))))) + (list 'byte (lambda (name field offset payload) + (list name 'byte (field-decoder-byte (list-ref payload offset))))) (list 'bcd (lambda (name field offset payload) (list name 'bcd (field-decoder-bcd (list-ref payload offset))))) (list 'data1b (lambda (name field offset payload) (list name 'data1b (field-decoder-data1b (list-ref payload offset))))) (list 'data1c (lambda (name field offset payload) (list name 'data1b (field-decoder-data1c (list-ref payload offset))))) - (list 'byte (lambda (name field offset payload) - (list name 'byte (list-ref payload offset)))) (list 'data2b (lambda (name field offset payload) (list name 'data2b (field-decoder-data2b (list-ref payload offset) @@ -97,6 +97,11 @@ (cond ((= value 1) 1) (else 0))) +;; type byte +(define (field-decoder-byte value) + (cond ((= value #xff) (ersatzwert)) + (else value))) + ;; type data1b (define (field-decoder-data1b value) (if (= value #x80) @@ -171,10 +176,9 @@ ;; type bcd (define (field-decoder-bcd value) - (if (= value #xff) - (ersatzwert) - (+ (bitwise-and value #x0f) - (arithmetic-shift value -4)))) + (cond ((= value #xff) (ersatzwert)) + (else (+ (bitwise-and value #x0f) + (* (arithmetic-shift value -4) 10))))) ;; read one ebus-paket or eof from input-port ;; or return # -- cgit v1.2.1