diff options
-rwxr-xr-x | ebus-racket/dumper.rkt | 4 | ||||
-rw-r--r-- | ebus-racket/layer2-test.rkt (renamed from ebus-racket/parser-test.rkt) | 22 | ||||
-rw-r--r-- | ebus-racket/layer2.rkt (renamed from ebus-racket/parser.rkt) | 12 | ||||
-rw-r--r-- | ebus-racket/layer7.rkt | 26 |
4 files changed, 45 insertions, 19 deletions
diff --git a/ebus-racket/dumper.rkt b/ebus-racket/dumper.rkt index adbc6fe..3c66015 100755 --- a/ebus-racket/dumper.rkt +++ b/ebus-racket/dumper.rkt @@ -1,7 +1,7 @@ #! /usr/bin/env racket #lang racket -(require (prefix-in parser: "parser.rkt")) +(require "layer2.rkt") ;(define verbose? (make-parameter #f)) (define connect-host? (make-parameter null)) @@ -24,4 +24,4 @@ (current-input-port cin))) ; -(parser:read-ebus-loop (current-input-port)) +(layer2-read-ebus-loop (current-input-port)) diff --git a/ebus-racket/parser-test.rkt b/ebus-racket/layer2-test.rkt index 1b4bc71..ed20ca6 100644 --- a/ebus-racket/parser-test.rkt +++ b/ebus-racket/layer2-test.rkt @@ -1,15 +1,15 @@ #lang racket (require rackunit rackunit/text-ui - (prefix-in parser: "parser.rkt")) + "layer2.rkt") -(define parser-test +(define layer2-test (test-suite "Tests for Ebus Parser" (test-case "Test sample Master-Master Paket" (let - ([paket (parser:read-ebus (open-input-bytes (bytes + ([paket (layer2-read-ebus (open-input-bytes (bytes 170 ; SYN 170 003 ; Source @@ -29,13 +29,13 @@ 000 ; ACK 170 ; SYN 170)))]) - (check-eq? (parser:ebus-paket-source paket) 003) - (check-eq? (parser:ebus-paket-destination paket) 241) - (check-eq? (parser:ebus-paket-primaryCommand paket) 008) - (check-eq? (parser:ebus-paket-secondaryCommand paket) 000) - (check-eq? (parser:ebus-paket-payloadLength paket) 008) - (check-eq? (parser:ebus-paket-payloadLength paket) - (length (parser:ebus-paket-payload paket))) + (check-eq? (layer2-ebus-paket-source paket) 003) + (check-eq? (layer2-ebus-paket-destination paket) 241) + (check-eq? (layer2-ebus-paket-primaryCommand paket) 008) + (check-eq? (layer2-ebus-paket-secondaryCommand paket) 000) + (check-eq? (layer2-ebus-paket-payloadLength paket) 008) + (check-eq? (layer2-ebus-paket-payloadLength paket) + (length (layer2-ebus-paket-payload paket))) )))) -(run-tests parser-test)
\ No newline at end of file +(run-tests layer2-test) diff --git a/ebus-racket/parser.rkt b/ebus-racket/layer2.rkt index 773e86e..dbdd411 100644 --- a/ebus-racket/parser.rkt +++ b/ebus-racket/layer2.rkt @@ -92,9 +92,9 @@ (display (format "Paket ~s~n" paket)) (cond ((not (eof-object? paket)) (read-ebus-loop input-port))))) -(provide read-ebus - read-ebus-loop - (struct-out ebus-paket) - (struct-out ebus-body-broadcast) - (struct-out ebus-body-mastermaster) - (struct-out ebus-body-masterslave))
\ No newline at end of file +(provide (prefix-out layer2- read-ebus) + (prefix-out layer2- read-ebus-loop) + (prefix-out layer2- (struct-out ebus-paket)) + (prefix-out layer2- (struct-out ebus-body-broadcast)) + (prefix-out layer2- (struct-out ebus-body-mastermaster)) + (prefix-out layre2- (struct-out ebus-body-masterslave))) diff --git a/ebus-racket/layer7.rkt b/ebus-racket/layer7.rkt new file mode 100644 index 0000000..5b8f496 --- /dev/null +++ b/ebus-racket/layer7.rkt @@ -0,0 +1,26 @@ +#lang racket +(require (planet lizorkin/sxml:2:1/sxml)) +(require (planet lizorkin/ssax:2:0/ssax)) + +(define definition + (ssax:xml->sxml (open-input-file "../ebus-xml/ebus.xml") + '[(#f . "http://xapek.org/ebus/0.1")])) + + +(define (ebus-paket primaryCommand secondaryCommand) + ((sxpath (string-append "//packet[@primary=" (number->string primaryCommand) + " and @secondary=" (number->string secondaryCommand) "]")) + definition)) + +;; returns the full device-definition +(define (device address) + ((sxpath (string-append "//devices/device[@address=" (number->string address) "]")) + definition)) + +;; returns device-name in a list or empty-list +(define (device-name address) + ((sxpath "@name/text()") (device address))) + +(provide (prefix-out layer7- ebus-paket) + (prefix-out layer7- device) + (prefix-out layer7- device-name))
\ No newline at end of file |