diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2024-12-18 17:08:28 +0100 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2024-12-18 17:08:28 +0100 |
commit | 1667bbac8600e5b65fd9775f40e92f2faffc4ec1 (patch) | |
tree | fd3b51666498cac74edf8de23309a8de242baa61 /simulation.scm | |
parent | 360d8e95f1b3c3891c993cefbc96c1a9370b885f (diff) |
simulation: start with network server
Diffstat (limited to 'simulation.scm')
-rw-r--r-- | simulation.scm | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/simulation.scm b/simulation.scm index 417bde2..4087d78 100644 --- a/simulation.scm +++ b/simulation.scm @@ -156,17 +156,18 @@ (spawn-fiber upstream) (spawn-fiber downstream))) -(define (make-gateway id upstream downstream) +(define (make-gateway id in radio network) (define time-on-air 0.01) ;s (TODO) (define pending-interferences '()) (define (forward-frame x) - (ll "forwarding ~a" x)) + (ll "Gateway ~a forwarding ~a" id x) + (put-message network (make-network-event id x))) ;; Upstream: listen, and answer in new fibers (lambda () (forever - (let* ((ev (get-message upstream))) + (let* ((ev (get-message in))) (match ev (($ <radio-event> 'uplink-start channel-n frame) #f) (($ <radio-event> 'interference channel-n frame) @@ -275,8 +276,9 @@ (lambda () (forever - (match (ev (get-message upstream)) - (($ <network-event> gateway-id frame) #f))))) + (match (get-message upstream) + (($ <network-event> gateway-id frame) + (ll "Network event happend!")))))) @@ -286,7 +288,8 @@ (let* ((radio-chn (make-channel)) (end-devices (make-hash-table)) - (gateways (make-hash-table))) + (gateways (make-hash-table)) + (network-chn (make-channel))) (for-each (lambda (id) @@ -301,9 +304,11 @@ (let ((chn (make-channel))) (hash-table-set! gateways id - (make-device chn (make-gateway id chn radio-chn))))) + (make-device chn (make-gateway id chn radio-chn network-chn))))) (iota 1 2)) + (spawn-fiber (make-network-server network-chn gateways end-devices)) + (spawn-fiber (make-radio radio-chn end-devices gateways)) (hash-table-walk end-devices (lambda (_ device) (spawn-fiber (device-thunk device)))) |