summaryrefslogtreecommitdiff
path: root/ebus-racket
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2012-02-26 00:34:47 +0100
committerYves Fischer <yvesf-git@xapek.org>2012-02-26 00:35:11 +0100
commit99e5d85621eb3b7153da9c7c46c3ab39f5d99f1f (patch)
treee5438163c249820442532043f0f5a190a2d843aa /ebus-racket
parentcb7f015ae3e4e386fe7d1a6da5c0e6f403bc7f7c (diff)
downloadebus-alt-99e5d85621eb3b7153da9c7c46c3ab39f5d99f1f.tar.gz
ebus-alt-99e5d85621eb3b7153da9c7c46c3ab39f5d99f1f.zip
ebus-racket: fix payload escaping issue
Diffstat (limited to 'ebus-racket')
-rw-r--r--ebus-racket/parse.rkt40
1 files changed, 25 insertions, 15 deletions
diff --git a/ebus-racket/parse.rkt b/ebus-racket/parse.rkt
index 46d91fd..dcc749c 100644
--- a/ebus-racket/parse.rkt
+++ b/ebus-racket/parse.rkt
@@ -31,12 +31,12 @@
primaryCommand
secondaryCommand
payloadLength)) )))
-;; 1 payload data byte
-(define ebus-payload (choice (seq ebus-const-escape
- escape-code <- (byte-in (list #"\0" #"\1"))
+;; single, maybe escaped, payload data byte
+(define ebus-payload (choice (seq escape-seq <- (bytes= ebus-const-escape)
+ escape-code <- (byte-in (list 0 1))
(return (cond
- ((= escape-code #"\0") ebus-const-escape)
- ((= escape-code #"\0") ebus-const-syn))))
+ ((= escape-code 0) ebus-const-escape)
+ ((= escape-code 1) ebus-const-syn))))
any-byte
))
@@ -69,26 +69,36 @@
(define ebus-sync (tokens syncs <- (seq (repeat (string->bytes/latin-1 "\xaa")))
(return (length syncs))))
-(define input-port (open-input-file "../doc/dumps/dump_2011-12-17_23-04-00.bin"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(define (read-ebus)
+(define (read-ebus input-port)
(let ([syn ((make-reader ebus-sync #:sof? #f #:eof? #f) input-port)]
[paket ((make-reader parse-ebus-paket #:sof? #f #:eof? #f) input-port)])
+ (cond ((not (false? syn))
+ (display (format "drop ~s x SYN (~s) ~n" syn ebus-const-syn))))
(cond ((not (false? paket))
- (cond ((not (false? syn))
- (display (format "drop ~s x SYN (~s) ~n" syn ebus-const-syn))))
- (display (format "Paket ~s~n" paket)))
+ paket)
+ ((eof-object? (peek-byte input-port))
+ eof)
(else
(display (format "drop ~s ~n" (peek-byte input-port)))
- (file-position input-port (+ 1 (file-position input-port)))
- ))
- (cond ((not (eof-object? (peek-byte input-port)))
- (read-ebus)))))
+ ; skip one byte
+ (read-byte input-port)
+ ;(file-position input-port (+ 1 (file-position input-port)))
+ (read-ebus input-port)))))
+
+(define (main input-port)
+ (let ([paket (read-ebus input-port)])
+ (display (format "Paket ~s~n" paket))
+ (cond ((not (eof-object? paket)) (main input-port)))))
+
+;(define input-port (open-input-file "../doc/dumps/dump_2011-12-17_23-04-00.bin"))
+(main (current-input-port))
+
+;((make-reader ebus-payload #:sof? #f #:eof? #f) (open-input-bytes (bytes 169 1 3 96)))
-(read-ebus)
;(define-values (cin cout)