diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2024-12-18 16:44:13 +0100 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2024-12-18 16:44:13 +0100 |
commit | 7bb68f4ac6d538bab339395cf89a4f292ae0ff9a (patch) | |
tree | e555f3e3efc621a53705b293c2d521a2113d1609 /simulation.scm | |
parent | c28dbf40debd25786276e6b5601236730f010997 (diff) |
simulation: forward interferences
Diffstat (limited to 'simulation.scm')
-rw-r--r-- | simulation.scm | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/simulation.scm b/simulation.scm index ee71d10..4ce8fc0 100644 --- a/simulation.scm +++ b/simulation.scm @@ -158,7 +158,7 @@ (define (make-gateway id upstream downstream) (define time-on-air 0.01) ;s (TODO) - (define radio-interference-queue '()) + (define pending-interferences '()) (define (forward-frame x) (ll "forwarding ~a" x)) @@ -170,13 +170,13 @@ (match ev (($ <radio-event> 'uplink-start channel-n frame) #f) (($ <radio-event> 'interference channel-n frame) - (set! radio-interference-queue (cons ev radio-interference-queue))) + (set! pending-interferences (cons ev pending-interferences))) (($ <radio-event> 'uplink-end channel-n frame) (let-values (((mine not-mine) (partition (lambda (x) (eq? (radio-event-frame x) (radio-event-frame ev))) - radio-interference-queue))) - (set! radio-interference-queue not-mine) + pending-interferences))) + (set! pending-interferences not-mine) (when (null? mine) ;; TODO (forward-frame frame))))))))) @@ -186,8 +186,9 @@ ;; We can access it only from one fiber! Careful! (define lorawan-channels (make-hash-table)) - (define (interference? chn) - (< 1 (length (hash-table-ref lorawan-channels chn)))) + (define (interferences ev chn) + (let ((res (hash-table-ref/default lorawan-channels chn '()))) + (if (equal? res (list ev)) '() res))) (define (use-lorawan-channel! chn start-event) (hash-table-update!/default lorawan-channels chn (lambda (event-list) @@ -201,6 +202,11 @@ (remove! (lambda (x) (eq? (radio-event-frame x) (radio-event-frame end-event))) event-list)))) + (define (radio-event->interference ev) + "Make a new radio-event of type 'interference from another radio-event" + (match ev + (($ <radio-event> type channel-n frame) + (make-radio-event 'interference channel-n frame)))) (lambda () (forever @@ -212,12 +218,18 @@ (frame-FCnt frame) channel-n) (use-lorawan-channel! channel-n ev) - (hash-table-walk gateways - (lambda (k gateway) - (put-message (device-channel gateway) ev))) - (when (interference? channel-n) - ;; TODO: send an 'interference event to the device - (ll "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))) + (let ((ints (interferences ev channel-n))) + (hash-table-walk gateways + (lambda (k gateway) + (spawn-fiber + (lambda () + (put-message (device-channel gateway) ev) + (for-each + (lambda (ev) + (ll "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") + (put-message (device-channel gateway) + (radio-event->interference ev))) + ints))))))) (($ <radio-event> 'downlink-start channel-n frame) (ll "Device ~a started downlink-frame #~a on channel ~a" @@ -225,13 +237,15 @@ (frame-FCnt frame) channel-n) (use-lorawan-channel! channel-n ev) - (put-message - (device-channel (hash-table-ref end-devices - (frame-DeviceAddr frame))) - ev) - (when (interference? channel-n) - ;; TODO: send an 'interference event to the device - (ll "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))) + (let ((chan (hash-table-ref end-devices + (frame-DeviceAddr frame))) + (ints (interferences ev channel-n))) + (put-message chan ev) + (for-each + (lambda (ev) + (ll "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") + (put-message chan (radio-event->interference ev))) + ints))) (($ <radio-event> 'uplink-end channel-n frame) (ll "Device ~a ended uplink-frame #~a on channel ~a" @@ -240,8 +254,10 @@ channel-n) (release-lorawan-channel! channel-n ev) (hash-table-walk gateways - (lambda (k gateway) - (put-message (device-channel gateway) ev)))) + (lambda (k gateway) + (spawn-fiber + (lambda () + (put-message (device-channel gateway) ev)))))) (($ <radio-event> 'downlink-end channel-n frame) (ll "Device ~a ended uplink-frame #~a on channel ~a" |