summaryrefslogtreecommitdiff
path: root/simulation.scm
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-12-18 12:27:59 +0100
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-12-18 12:28:05 +0100
commit8cf24759a4e3b0ba70479e0e3111cf51e706b97f (patch)
tree6fb6650883fcd66effd2382b562ca798beea8a38 /simulation.scm
parentb0538012a6e7d90c947b683d404adc0bf55c662c (diff)
fixup! simulation: prepare for better interference system
Diffstat (limited to 'simulation.scm')
-rw-r--r--simulation.scm44
1 files changed, 28 insertions, 16 deletions
diff --git a/simulation.scm b/simulation.scm
index 95933e6..50c97e4 100644
--- a/simulation.scm
+++ b/simulation.scm
@@ -42,15 +42,23 @@
(format #f "~d~6'0d - ~?~%" (car now) (cdr now) f data))))))
+;; For End-Device <--> Radio <--> Gateway
;; type can be:
;; '[up/down]link-start
;; '[up/down]link-end
-(define-record-type <event>
- (make-event type channel-n frame)
- event?
- (type event-type)
- (channel-n event-channel-n)
- (frame event-frame))
+(define-record-type <radio-event>
+ (make-radio-event type channel-n frame)
+ radio-event?
+ (type radio-event-type)
+ (channel-n radio-event-channel-n)
+ (frame radio-event-frame))
+
+;; For Gateway <--> Network Server
+(define-record-type <network-event>
+ (make-network-event gateway-id frame)
+ network-event?
+ (gateway-id network-event-gateway-id)
+ (frame network-event-frame))
;; body can be:
;; 'unconfirmed-data (uplink)
@@ -113,9 +121,9 @@
(if confirmed? 'confirmed-data 'unconfirmed-data))))
(when confirmed?
(atomic-box-compare-and-swap! to-confirm #f frame-number))
- (put-message upstream-chn (make-event 'uplink-start channel frame))
+ (put-message upstream-chn (make-radio-event 'uplink-start channel frame))
(sleep time-on-air)
- (put-message upstream-chn (make-event 'uplink-end channel frame))))
+ (put-message upstream-chn (make-radio-event 'uplink-end channel frame))))
(define (upstream)
(define current-frame 0)
@@ -155,9 +163,9 @@
(lambda ()
(sleep RECEIVE_DELAY1)
(let ((frame (make-frame seq-number to '() 'ack)))
- (put-message downstream (make-event 'downlink-start channel frame))
+ (put-message downstream (make-radio-event 'downlink-start channel frame))
(sleep time-on-air) ;; TODO: size / data-rate
- (put-message downstream (make-event 'downlink-end channel frame))))))
+ (put-message downstream (make-radio-event 'downlink-end channel frame))))))
;; Upstream: listen, and answer in new fibers
(lambda ()
@@ -194,19 +202,19 @@
(lambda ()
(forever
(match (get-message in)
- (($ <event> 'uplink-start channel-n frame)
+ (($ <radio-event> 'uplink-start channel-n frame)
(ll "Device ~a started ~a of frame ~a"
(frame-DeviceAddr frame)
(frame-body frame)
(frame-FCnt frame)))
- (($ <event> 'downlink-start channel-n 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)))
- (($ <event> 'uplink-end channel-n frame)
+ (($ <radio-event> 'uplink-end channel-n frame)
(ll "Device ~a finished ~a of frame ~a"
(frame-DeviceAddr frame)
(frame-body frame)
@@ -217,7 +225,7 @@
(lambda (k gateway)
(put-message (device-channel gateway) frame)))))
- (($ <event> 'downlink-end channel-n frame)
+ (($ <radio-event> 'downlink-end channel-n frame)
(ll "Device ~a finished ~a of frame ~a"
(frame-DeviceAddr frame)
(frame-body frame)
@@ -229,8 +237,12 @@
frame)))))))
-(define (make-network-server upstream)
- #f)
+(define (make-network-server upstream gateways end-devices)
+
+ (lambda ()
+ (forever
+ (match (ev (get-message upstream))
+ (($ <network-event> gateway-id frame) #f)))))