summaryrefslogtreecommitdiff
path: root/simulation.scm
diff options
context:
space:
mode:
Diffstat (limited to 'simulation.scm')
-rw-r--r--simulation.scm54
1 files changed, 48 insertions, 6 deletions
diff --git a/simulation.scm b/simulation.scm
index bdba9d6..6728c42 100644
--- a/simulation.scm
+++ b/simulation.scm
@@ -5,6 +5,7 @@
#:use-module (srfi srfi-69)
#:use-module (ice-9 atomic)
#:use-module (ice-9 match)
+ #:use-module (ice-9 getopt-long)
#:use-module (fibers)
#:use-module (fibers channels)
#:use-module (fibers operations)
@@ -364,7 +365,7 @@
-(define (run-simulation)
+(define (run-simulation end-device-count gateway-count)
;; We need synchronized logger and counter running in fibers
(spawn-fiber logger)
(spawn-fiber counter)
@@ -380,7 +381,7 @@
(hash-table-set!
end-devices id
(make-device chn (make-class-a id (modulo id 3) radio-chn chn)))))
- (iota 4))
+ (iota end-device-count gateway-count))
(for-each
(lambda (id)
@@ -388,7 +389,7 @@
(hash-table-set!
gateways id
(make-device chn (make-gateway id chn radio-chn network-chn)))))
- (iota 1 2))
+ (iota gateway-count 0))
(spawn-fiber (make-network-server network-chn gateways end-devices))
@@ -398,6 +399,47 @@
(hash-table-walk gateways
(lambda (_ device) (spawn-fiber (device-thunk device))))))
-(run-fibers
- run-simulation
- #:drain? #t)
+(define (main args)
+ (define help
+"
+LoRaWAN interference simulator:
+
+USAGE:
+~/guile simulation.scm -d END_DEVICE_COUNT -g GATWEWAY_COUNT
+
+OPTIONS:
+~/-g, --gateways~25tGateway count to add to the simulation
+~/-d, --end-devices~25tEnd Device count to add to the simulation
+~/-h, --help~25tShow this help~&
+")
+ (define option-spec
+ '((gateways (single-char #\g) (value #t))
+ (end-devices (single-char #\d) (value #t))
+ (help (single-char #\h) (value #f))))
+
+ (let* ((options (getopt-long args option-spec))
+ (end-devices-op (option-ref options 'end-devices #f))
+ (gateways-op (option-ref options 'gateways #f)))
+ (when (option-ref options 'help #f)
+ (format #t help)
+ (exit 0))
+ (unless end-devices-op
+ (format #t "ERROR: No end-device count provided~%")
+ (exit 1))
+ (unless gateways-op
+ (format #t "ERROR: No gateway count provided~%")
+ (exit 1))
+ (let* ((end-devices (and end-devices-op (string->number end-devices-op)))
+ (gateways (and gateways-op (string->number gateways-op))))
+ (unless (integer? end-devices)
+ (format #t "ERROR: -d, --end-devices: expecting integer~%")
+ (exit 1))
+ (unless (integer? gateways)
+ (format #t "ERROR: -g, --gateways: expecting integer~%")
+ (exit 1))
+
+ (run-fibers
+ (lambda () (run-simulation end-devices gateways))
+ #:drain? #t))))
+
+(main (command-line))