From 79614c6c284585d4fb1fa728e3965beeab7752d3 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Sun, 26 Feb 2012 18:40:06 +0100 Subject: ebus-racket: remove seperate ebus-header struct --- ebus-racket/parser.rkt | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'ebus-racket/parser.rkt') 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 -- cgit v1.2.1