summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xebus-racket/dumper.rkt4
-rw-r--r--ebus-racket/parser-test.rkt56
-rw-r--r--ebus-racket/parser.rkt11
3 files changed, 66 insertions, 5 deletions
diff --git a/ebus-racket/dumper.rkt b/ebus-racket/dumper.rkt
index 7ac1da6..adbc6fe 100755
--- a/ebus-racket/dumper.rkt
+++ b/ebus-racket/dumper.rkt
@@ -1,7 +1,7 @@
#! /usr/bin/env racket
#lang racket
-(require "parser.ss")
+(require (prefix-in parser: "parser.rkt"))
;(define verbose? (make-parameter #f))
(define connect-host? (make-parameter null))
@@ -24,4 +24,4 @@
(current-input-port cin)))
;
-(read-ebus-loop (current-input-port))
+(parser:read-ebus-loop (current-input-port))
diff --git a/ebus-racket/parser-test.rkt b/ebus-racket/parser-test.rkt
new file mode 100644
index 0000000..672dff2
--- /dev/null
+++ b/ebus-racket/parser-test.rkt
@@ -0,0 +1,56 @@
+#lang racket
+(require rackunit
+ rackunit/text-ui
+ (prefix-in parser: "parser.rkt"))
+
+(define parser-test
+ (test-suite
+ "Tests for Ebus Parser"
+ (test-case
+ "Test sample Master-Master Paket"
+ (let
+ ([paket (parser:read-ebus (open-input-bytes (bytes
+ 170 ; SYN
+ 170
+ 170
+ 003 ; Source
+ 241 ; Destination
+ 008 ; primaryCommand
+ 000 ; secondaryCommand
+ 008 ; payloadLength
+ 128 ; p1
+ 040 ; p2
+ 230 ; p3
+ 002 ; p4
+ 000 ; p5
+ 002 ; p6
+ 000 ; p7
+ 010 ; p8
+ 128 ; CRC
+ 000 ; ACK
+ 170 ; SYN
+ 170)))])
+ (check-eq? (parser:ebus-header-source (parser:ebus-paket-header paket)) 003)
+ (check-eq? (parser:ebus-header-destination (parser:ebus-paket-header paket)) 241)
+ (check-eq? (parser:ebus-header-primaryCommand (parser:ebus-paket-header paket)) 008)
+ (check-eq? (parser:ebus-header-secondaryCommand (parser:ebus-paket-header paket)) 000)
+ (check-eq? (parser:ebus-header-payloadLength (parser:ebus-paket-header paket)) 008)
+ (check-eq? (parser:ebus-header-payloadLength (parser:ebus-paket-header paket))
+ (length (parser:ebus-paket-payload paket)))
+ ))))
+
+;(check-equal? (my-+ 1 1) 2 "Simple addition")
+
+ ;(check-equal? (my-* 1 2) 2 "Simple multiplication")
+;
+; (test-case
+; "List has length 4 and all elements even"
+; (let ([lst (list 2 4 6 9)])
+; (check = (length lst) 4)
+; (for-each
+; (lambda (elt)
+; (check-pred even? elt))
+; lst)))))
+
+
+(run-tests parser-test) \ No newline at end of file
diff --git a/ebus-racket/parser.rkt b/ebus-racket/parser.rkt
index 1b9ed5b..51b9b55 100644
--- a/ebus-racket/parser.rkt
+++ b/ebus-racket/parser.rkt
@@ -19,7 +19,7 @@
(crc payloadSlaveLength payloadSlave crcSlave)
#:transparent)
-(struct ebus-paket (header body) #:transparent)
+(struct ebus-paket (header payload body) #:transparent)
(define parse-ebus-header (token (seq source <- any-byte
destination <- any-byte
@@ -64,7 +64,7 @@
payload <- (repeat ebus-payload (ebus-header-payloadLength header) (ebus-header-payloadLength header))
body <- (cond ((= (ebus-header-destination header) ebus-const-broadcastaddr) parse-ebus-broadcast)
(else parse-ebus-master-or-slave))
- (return (ebus-paket header body)))))
+ (return (ebus-paket header payload body)))))
(define ebus-sync (tokens syncs <- (seq (repeat (string->bytes/latin-1 "\xaa")))
(return (length syncs))))
@@ -95,4 +95,9 @@
(cond ((not (eof-object? paket)) (read-ebus-loop input-port)))))
(provide read-ebus
- read-ebus-loop) \ No newline at end of file
+ read-ebus-loop
+ (struct-out ebus-paket)
+ (struct-out ebus-header)
+ (struct-out ebus-body-broadcast)
+ (struct-out ebus-body-mastermaster)
+ (struct-out ebus-body-masterslave)) \ No newline at end of file