From f3295bd150079984d115faad0a5a9de10c6d6de0 Mon Sep 17 00:00:00 2001 From: Ebus-at-dockstar Date: Tue, 16 Sep 2014 01:36:38 +0200 Subject: ersatzwerte --- ebus-racket/ebus/layer7.rkt | 81 ++++++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 30 deletions(-) (limited to 'ebus-racket/ebus') diff --git a/ebus-racket/ebus/layer7.rkt b/ebus-racket/ebus/layer7.rkt index b3caf0b..b43a58a 100644 --- a/ebus-racket/ebus/layer7.rkt +++ b/ebus-racket/ebus/layer7.rkt @@ -8,6 +8,11 @@ (define-logger ebus7) +(define (ersatzwert) + 'ersatzwert) +(define (ersatzwert? v) + (eq? (ersatzwert) v)) + (define definition (let* ([in (open-input-file "../ebus-xml/ebus.xml")] [xexpr (parameterize ([collapse-whitespace #t] @@ -94,19 +99,25 @@ ;; type data1b (define (field-decoder-data1b value) - value) + (if (= value #x80) + (ersatzwert) + value)) ;; type data1c (define (field-decoder-data1c value) - (/ value 2.0)) + (if (= value #xff) + (ersatzwert) + (/ value 2.0))) ;; type data2b (define (field-decoder-data2b lowByte highByte) - (if (= (bitwise-and highByte 128) 128) - (* -1 - (+ (+ 256 (bitwise-not highByte)) - (/ (+ 256 (bitwise-not (+ lowByte 1))) 256.0))) - (+ highByte (/ lowByte 256.0)))) + (if (and (= highByte 128) (= lowByte 0)) + (ersatzwert) + (if (= (bitwise-and highByte 128) 128) + (* -1 + (+ (+ 256 (bitwise-not highByte)) + (/ (+ 256 (bitwise-not (+ lowByte 1))) 256.0))) + (+ highByte (/ lowByte 256.0))))) ;; type data2c ;; Beispiel für die Berechnung: @@ -118,22 +129,25 @@ ;; + dez(Low_ Nibble (Low Byte (x))) / 16 (define (field-decoder-data2c lowByte highByte) (define (lowNibble v) - (bitwise-and v #x0f)) + (bitwise-and v #x0f)) (define (highNibble v) - (arithmetic-shift v -4)) + (arithmetic-shift v -4)) (define (u-not v) - (+ 256 (bitwise-not v))) - (if (= (bitwise-and highByte 128) 128) - (* -1 - (+ (arithmetic-shift (u-not highByte) 4) - (highNibble (u-not lowByte)) - (/ (+ (lowNibble (u-not lowByte)) 1) - 16.0))) - (+ (arithmetic-shift highByte 4) - (highNibble lowByte) - (/ - (lowNibble lowByte) - 16)))) + (+ 256 (bitwise-not v))) + + (if (and (= highByte 128) (= lowByte 0)) + (ersatzwert) + (if (= (bitwise-and highByte 128) 128) + (* -1 + (+ (arithmetic-shift (u-not highByte) 4) + (highNibble (u-not lowByte)) + (/ (+ (lowNibble (u-not lowByte)) 1) + 16.0))) + (+ (arithmetic-shift highByte 4) + (highNibble lowByte) + (/ + (lowNibble lowByte) + 16))))) ;; type byteEnum (define (field-decoder-byteEnum value field-definition) @@ -149,13 +163,18 @@ ;; type word (define (field-decoder-word lowByte highByte) - (+ lowByte - (arithmetic-shift highByte 8))) + (define value + (+ lowByte (arithmetic-shift highByte 8))) + (if (= value #xffff) + (ersatzwert) + value)) ;; type bcd (define (field-decoder-bcd value) - (+ (bitwise-and value #x0f) - (arithmetic-shift value -4))) + (if (= value #xff) + (ersatzwert) + (+ (bitwise-and value #x0f) + (arithmetic-shift value -4)))) ;; read one ebus-paket or eof from input-port ;; or return # @@ -165,10 +184,12 @@ (paket-parse paket)) (else paket))) -(provide (prefix-out layer7- paket) - (prefix-out layer7- paket-parse) - (prefix-out layer7- device) - (prefix-out layer7- device-name) - (prefix-out layer7- definition) +(provide (prefix-out layer7- ersatzwert) + (prefix-out layer7- ersatzwert?) + (prefix-out layer7- paket) + (prefix-out layer7- paket-parse) + (prefix-out layer7- device) + (prefix-out layer7- device-name) + (prefix-out layer7- definition) ;; read ebus from port an return fields from next paket (prefix-out layer7- read-ebus)) -- cgit v1.2.1