Skip to content
This repository has been archived by the owner on Dec 26, 2024. It is now read-only.

Commit

Permalink
wireless-test complete
Browse files Browse the repository at this point in the history
  • Loading branch information
prasincs committed Apr 27, 2011
1 parent dc7fe12 commit 0c73391
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 24 deletions.
29 changes: 22 additions & 7 deletions library/experiments/wireless-test.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
(use 'thor.lang :reload-all)
(use 'thor.lang
'thor.messages
'thor.net.wireless
'(incanter core charts stats) :reload-all)

(defduration 100)
(defduration 50)

(defdevice phone-1 {
(defdevice "phone-1" {
:type "phone"
:memory "100M"
:range "100"
Expand All @@ -15,6 +18,7 @@
:battery {
:type "Li-ion"
:voltage 3.6
:capacity 1600 ;mAh
:specific-energy 0.46
:efficiency 0.8 ; 80%
}
Expand Down Expand Up @@ -51,12 +55,12 @@


(def transmitter (create-node
{:device phone-1
{:device "phone-1"
:location {:x 50 :y 0}} ; start at very top
))

(def receiver (create-node
{:device phone-1
{:device "phone-1"
:location {:x 50 :y 1}}
)) ; start at distance 1 away from transmitter

Expand All @@ -69,15 +73,26 @@
(at-end (do
(println "Results" )
(println @power-loss-time)
))
(let [time (range 1 (get-duration))
power (reverse @power-loss-time)]
(view
(line-chart
time power))
)
))


(every 1 (do
(move-node receiver + {:x 0 :y 1})
(swap! power-loss-time conj
(:power-received
(get-message-network-attrs
(send-message "test" transmitter receiver ))))
(send-network-message
"test"
transmitter
receiver
{:time (get-current-time)})
)))
))

(simulation-run)
25 changes: 21 additions & 4 deletions src/thor/lang.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns #^{:doc "A description parser for thor AKA Hammer"}
thor.lang
(:use clojure.contrib.logging thor.utils)
(:require thor.queue)
(:use clojure.contrib.logging thor.utils)
(:require thor.queue thor.node)
)

(use '[clojure.contrib.math :only (expt) ])
Expand All @@ -11,7 +11,7 @@
(def *total-devices* (atom 100)) ; define total-devices with a default
(def *experiment-attrs* (atom {}))
(def *duration* (atom 0))
(def *current-time* (atom 0))
(def *current-time* (atom 1))
(def *keyspace* (atom (expt 2 10)))


Expand All @@ -30,9 +30,10 @@
:noise 0
})
)

(def *wired-network* (atom {}))

(defn get-duration [] @*duration*)

(defn get-network-attrs []
(if (= @*network-type* wireless )
@*wireless-network*
Expand Down Expand Up @@ -231,4 +232,20 @@
; todo -> implement
)

(defn get-device [n]
(if (contains? @*devices* n)
(get @*devices* n)
(throw (Error. "No such device in database"))
))

(defn create-node [attrs]

(if (contains? attrs :device)

(let [attrs (assoc attrs :device-attrs (get-device (attrs :device)))]
(println attrs)
(atom (thor.node/create-node attrs)))
))

(defn move-node [n op pos]
(reset! n (thor.node/node-move @n op pos)))
2 changes: 1 addition & 1 deletion src/thor/main.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns thor.main
(:gen-class)
;(:use thor.window thor.lang thor.queue)
(:use thor.messages clojure.stacktrace clojure.contrib.trace)
(:use thor.messages clojure.stacktrace )
)

;(defn put-items[]
Expand Down
3 changes: 3 additions & 0 deletions src/thor/messages.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
(if (contains? (get msg :attrs) attr)
(-> msg :attrs attr)
))
(defn get-message-network-attrs
[msg]
(-> msg :network-attrs ))

(defn get-message-path [msg]
(get-message-attr msg :nodes)
Expand Down
17 changes: 13 additions & 4 deletions src/thor/net/wireless.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
(ns thor.net.wireless
(:use thor.node thor.network)
(:require thor.queue) ; want queue actions to be more explicit
(:use thor.node
thor.network
thor.messages)
(:require thor.queue
) ; want queue actions to be more explicit
)

(use '[clojure.contrib.math :only (expt)])
Expand Down Expand Up @@ -56,5 +59,11 @@
(defn send-network-message
"Send a network message from a node to other"
[from to message &[attrs]]

)
(let [msg (create-message message from to attrs)]
(assoc msg :network-attrs
(-> {} (assoc
:power-received
(/ 1
(:time attrs)
)))))
)
21 changes: 13 additions & 8 deletions src/thor/node.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require clojure.core)
(:require clojure.contrib.math) ; this didn't work not sure why
(:import [java.util Random])
(:use thor.math)
(:use thor.math clojure.contrib.logging)
)

;
Expand Down Expand Up @@ -30,11 +30,11 @@
)

(defn create-node "create a node based on given info"
[id pos memory-size]
[{:keys [id location memory-size]}]
(Node.
id
(create-memory memory-size)
pos
location
0
0
0
Expand All @@ -61,19 +61,24 @@
{id (-> (* max-width max-height) rand int)}} ]]
(let [ random (Random.)]
(create-node
id
(random-position max-width max-height) 100)))
{:id id
:location (random-position max-width max-height)
:memory-size 100})))


; TODO : make multimethod
(defn get-location [n]
(n :location))

(defn change-location [loc op pos]
(println "Change Location")
(println loc)
(assoc pos :x (op (:x pos) (:x loc) )
:y (op (:y pos) (:y loc))))

(defn node-move [n op pos]
(debug "Node Move")
(prn (:location n))
(assoc n :location (change-location (:location n) op pos))
)

Expand Down Expand Up @@ -123,16 +128,16 @@
concat
(list
(create-node
n
(position
{:id n
:location (position
(+ (:x center)
(* (Math/cos
(* angle n) ) radius))
(+ (:y center)
(* (Math/sin
(* angle n) ) radius))
)
1000
:memory-size 1000}
))))
@nlist))

Expand Down

0 comments on commit 0c73391

Please sign in to comment.