summaryrefslogtreecommitdiff
path: root/ebus-racket/ebus
diff options
context:
space:
mode:
authorEbus-at-dockstar <ebus@dockstar>2014-09-16 01:36:38 +0200
committerEbus-at-dockstar <ebus@dockstar>2014-09-16 01:41:16 +0200
commitf3295bd150079984d115faad0a5a9de10c6d6de0 (patch)
treea4825033c7a3bbe92d83502f571ba88fc5a30288 /ebus-racket/ebus
parentf7f2f4a611f15d98d8e33241dc65d5cbfe7ff03b (diff)
downloadebus-alt-f3295bd150079984d115faad0a5a9de10c6d6de0.tar.gz
ebus-alt-f3295bd150079984d115faad0a5a9de10c6d6de0.zip
ersatzwerte
Diffstat (limited to 'ebus-racket/ebus')
-rw-r--r--ebus-racket/ebus/layer7.rkt81
1 files changed, 51 insertions, 30 deletions
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 #<eof>
@@ -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))