1(define (state->number state)
2 (if (number? state)
3 state
4 (cond
5 ((eq? state 'on) pkt-on)
6 ((eq? state 'off) pkt-off)
7 ((eq? state 'restore) pkt-restore)
8 (else (error "unknown LED state")))))
9
10(define (assoc->list asc)
11 (fold (lambda (x ys)
12 (let ((pair (assoc x asc)))
13 (append ys
14 (list (if pair
15 (state->number (cdr pair))
16 pkt-restore)))))
17 '() (range num-leds)))
18
19(define (marshal asc)
20 (define padding (make-list pkt-pad 0))
21
22 (list->u8vector
23 (append
24 (list pkt-hdr pkt-rw)
25 (assoc->list asc)
26 padding)))