summaryrefslogtreecommitdiff
path: root/simulation.scm
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-12-18 13:59:07 +0100
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-12-18 13:59:07 +0100
commit38331a0e9f356ad6de4789938e1604df0b8fa184 (patch)
treee3f8a5c377fe69c8627e439fd8dfa67b3f20c322 /simulation.scm
parent8cf24759a4e3b0ba70479e0e3111cf51e706b97f (diff)
simulation: radio channel usage control
Diffstat (limited to 'simulation.scm')
-rw-r--r--simulation.scm99
1 files changed, 56 insertions, 43 deletions
diff --git a/simulation.scm b/simulation.scm
index 50c97e4..a710fa0 100644
--- a/simulation.scm
+++ b/simulation.scm
@@ -184,57 +184,70 @@
(define (make-radio in end-devices gateways)
+ "Fiber for radio resource allocation/control."
- ;; Semaphore-like channel adquisition-release
+ ;; We can access it only from one fiber! Careful!
(define lorawan-channels (make-hash-table))
- (define (use-lorawan-channel chn)
- #f)
- (define (release-lorawan-channel chn)
- #f)
-
-
- ;; TODO: this is broken, only accounts for the interference of the frame
- ;; that was already being sent, and not from the new one that produced the
- ;; interference => both should be affected.
- (define (interference?)
- #f)
+ (define (interference? chn)
+ (< 1 (length (hash-table-ref lorawan-channels chn))))
+ (define (use-lorawan-channel! chn start-event)
+ (hash-table-update!/default lorawan-channels chn
+ (lambda (event-list)
+ (cons start-event event-list))
+ '()))
+ (define (release-lorawan-channel! chn end-event)
+ (hash-table-update! lorawan-channels chn
+ (lambda (event-list)
+ ;; what if we have more than one?
+ ;; is that possible?
+ (remove! (lambda (x) (eq? (radio-event-frame x)
+ (radio-event-frame end-event)))
+ event-list))))
(lambda ()
(forever
- (match (get-message in)
- (($ <radio-event> 'uplink-start channel-n frame)
- (ll "Device ~a started ~a of frame ~a"
- (frame-DeviceAddr frame)
- (frame-body frame)
- (frame-FCnt frame)))
-
- (($ <radio-event> 'downlink-start channel-n frame)
- (ll "Device ~a started ~a of frame ~a"
- (frame-DeviceAddr frame)
- (frame-body frame)
- (frame-FCnt frame)))
-
- (($ <radio-event> 'uplink-end channel-n frame)
- (ll "Device ~a finished ~a of frame ~a"
- (frame-DeviceAddr frame)
- (frame-body frame)
- (frame-FCnt frame))
- (if (interference?) ;; TODO: interferences are broken
- (ll "Interference!!!!!!")
+ (let ((ev (get-message in)))
+ (match ev
+ (($ <radio-event> 'uplink-start channel-n frame)
+ (ll "Device ~a started uplink-frame #~a on channel ~a"
+ (frame-DeviceAddr frame)
+ (frame-FCnt frame)
+ channel-n)
+ (use-lorawan-channel! channel-n ev)
+ (when (interference? channel-n)
+ ;; TODO: send an 'interference event to the device
+ (ll "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")))
+
+ (($ <radio-event> 'downlink-start channel-n frame)
+ (ll "Device ~a started downlink-frame #~a on channel ~a"
+ (frame-DeviceAddr frame)
+ (frame-FCnt frame)
+ channel-n)
+ (use-lorawan-channel! channel-n ev)
+ (when (interference? channel-n)
+ ;; TODO: send an 'interference event to the device
+ (ll "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")))
+
+ (($ <radio-event> 'uplink-end channel-n frame)
+ (ll "Device ~a ended uplink-frame #~a on channel ~a"
+ (frame-DeviceAddr frame)
+ (frame-FCnt frame)
+ channel-n)
+ (release-lorawan-channel! channel-n ev)
(hash-table-walk gateways
(lambda (k gateway)
- (put-message (device-channel gateway) frame)))))
-
- (($ <radio-event> 'downlink-end channel-n frame)
- (ll "Device ~a finished ~a of frame ~a"
- (frame-DeviceAddr frame)
- (frame-body frame)
- (frame-FCnt frame))
- (if (interference?) ;; TODO: interferences are broken
- (ll "Interference!!!!!!")
+ (put-message (device-channel gateway) frame))))
+
+ (($ <radio-event> 'downlink-end channel-n frame)
+ (ll "Device ~a ended uplink-frame #~a on channel ~a"
+ (frame-DeviceAddr frame)
+ (frame-FCnt frame)
+ channel-n)
+ (release-lorawan-channel! channel-n ev)
(put-message
- (device-channel (hash-table-ref end-devices (frame-DeviceAddr frame)))
- frame)))))))
+ (device-channel (hash-table-ref end-devices
+ (frame-DeviceAddr frame)))
+ frame)))))))
(define (make-network-server upstream gateways end-devices)