summaryrefslogtreecommitdiff
path: root/ebus-racket/parser.rkt
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2012-02-26 18:40:06 +0100
committerYves Fischer <yvesf-git@xapek.org>2012-02-26 18:40:06 +0100
commit79614c6c284585d4fb1fa728e3965beeab7752d3 (patch)
tree47e1a3153179aa18327840eda8fe3859c0991c67 /ebus-racket/parser.rkt
parente01f36c90c19ddf52c4c3b2f9d14f1fb52349c4a (diff)
downloadebus-alt-79614c6c284585d4fb1fa728e3965beeab7752d3.tar.gz
ebus-alt-79614c6c284585d4fb1fa728e3965beeab7752d3.zip
ebus-racket: remove seperate ebus-header struct
Diffstat (limited to 'ebus-racket/parser.rkt')
-rw-r--r--ebus-racket/parser.rkt39
1 files changed, 18 insertions, 21 deletions
diff --git a/ebus-racket/parser.rkt b/ebus-racket/parser.rkt
index 51b9b55..773e86e 100644
--- a/ebus-racket/parser.rkt
+++ b/ebus-racket/parser.rkt
@@ -7,10 +7,6 @@
(define ebus-const-ackok (string->bytes/latin-1 "\x00"))
(define ebus-const-broadcastaddr 254)
-(struct ebus-header
- (source destination primaryCommand secondaryCommand payloadLength)
- #:transparent)
-
(struct ebus-body-broadcast (crc) #:transparent)
(struct ebus-body-mastermaster (crc) #:transparent)
@@ -19,18 +15,10 @@
(crc payloadSlaveLength payloadSlave crcSlave)
#:transparent)
-(struct ebus-paket (header payload body) #:transparent)
-
-(define parse-ebus-header (token (seq source <- any-byte
- destination <- any-byte
- primaryCommand <- any-byte
- secondaryCommand <- any-byte
- payloadLength <- any-byte
- (return (ebus-header source
- destination
- primaryCommand
- secondaryCommand
- payloadLength)) )))
+(struct ebus-paket
+ (source destination primaryCommand secondaryCommand payloadLength payload body)
+ #:transparent)
+
;; single, maybe escaped, payload data byte
(define ebus-payload (choice (seq escape-seq <- (bytes= ebus-const-escape)
escape-code <- (byte-in (list 0 1))
@@ -60,11 +48,21 @@
(define parse-ebus-master-or-slave (token (choice parse-ebus-mastermaster parse-ebus-masterslave)))
-(define parse-ebus-paket (token (seq header <- parse-ebus-header
- payload <- (repeat ebus-payload (ebus-header-payloadLength header) (ebus-header-payloadLength header))
- body <- (cond ((= (ebus-header-destination header) ebus-const-broadcastaddr) parse-ebus-broadcast)
+(define parse-ebus-paket (token (seq source <- any-byte
+ destination <- any-byte
+ primaryCommand <- any-byte
+ secondaryCommand <- any-byte
+ payloadLength <- any-byte
+ payload <- (repeat ebus-payload payloadLength payloadLength)
+ body <- (cond ((= destination ebus-const-broadcastaddr) parse-ebus-broadcast)
(else parse-ebus-master-or-slave))
- (return (ebus-paket header payload body)))))
+ (return (ebus-paket source
+ destination
+ primaryCommand
+ secondaryCommand
+ payloadLength
+ payload
+ body)))))
(define ebus-sync (tokens syncs <- (seq (repeat (string->bytes/latin-1 "\xaa")))
(return (length syncs))))
@@ -97,7 +95,6 @@
(provide read-ebus
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