summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-12-15 22:40:15 +0100
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-12-15 22:40:25 +0100
commit8bbd598025d52fe66613dedec5e1a990a88953b8 (patch)
treee74e5e2dd5d24c5f4cc6e806857c23977bee2644
parent6a14fc35a2684b5be69df7dc4046a3b9c459627d (diff)
simulation: match on records
-rw-r--r--simulation.scm52
1 files changed, 25 insertions, 27 deletions
diff --git a/simulation.scm b/simulation.scm
index c667750..ca30041 100644
--- a/simulation.scm
+++ b/simulation.scm
@@ -120,33 +120,31 @@
(lambda ()
(forever
(let ((ev (get-message in)))
- (match (event-type ev)
- ('start
- (let ((msg (event-data ev)))
- (ll "Device ~a started ~a of message ~a"
- (message-device-id msg)
- (message-body msg)
- (message-id msg))
- (set! started (cons msg started))))
- ('end
- (let ((msg (event-data ev)))
- (ll "Device ~a finished ~a of message ~a"
- (message-device-id msg)
- (message-body msg)
- (message-id msg))
- (set! started
- (remove! (lambda (x)
- (and (= (message-id msg) (message-id x))
- (= (message-device-id msg) (message-device-id x)))) started))
- (if (interference? msg started)
- (ll "Interference!!!!!!")
- (if (message-uplink? msg)
- (hash-table-walk gateways
- (lambda (k gateway)
- (put-message (device-channel gateway) msg)))
- (put-message
- (device-channel (hash-ref end-devices (message-device-id msg)))
- msg))))))))))
+ (match ev
+ (($ <event> 'start msg)
+ (ll "Device ~a started ~a of message ~a"
+ (message-device-id msg)
+ (message-body msg)
+ (message-id msg))
+ (set! started (cons msg started)))
+ (($ <event> 'end msg)
+ (ll "Device ~a finished ~a of message ~a"
+ (message-device-id msg)
+ (message-body msg)
+ (message-id msg))
+ (set! started
+ (remove! (lambda (x)
+ (and (= (message-id msg) (message-id x))
+ (= (message-device-id msg) (message-device-id x)))) started))
+ (if (interference? msg started)
+ (ll "Interference!!!!!!")
+ (if (message-uplink? msg)
+ (hash-table-walk gateways
+ (lambda (k gateway)
+ (put-message (device-channel gateway) msg)))
+ (put-message
+ (device-channel (hash-ref end-devices (message-device-id msg)))
+ msg)))))))))