0% found this document useful (0 votes)
27 views14 pages

Cupcarbon Apendix

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views14 pages

Cupcarbon Apendix

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Apendix -A

List of Commands

Language Sensor Radio Module Embedded Card Messages Data Mobile Visualization

inc / dec areadsensor Atch loop data move Simulation

conc dreadsensor Atid stop rdata rmove cprint

hash getpos Atpl buffer vdata route edge

int getpos2 atmy cbuffer send

max / min getinfo atnd delay receive

smax / smin rotate atnid led wait

and / or atget mark read

xor / not drssi print pick

band / bor distance printfile

bxor / bnot battery

for end time

if [else] end kill

while end script

goto rscript

function

math

rand / randb

rgauss

set

tab / vec

tget / tset

vget / vset

angle / angle2

sadd / spop / nth

charat / length

and (logic)
→ x=a&b
and x a b
angle / angle2
angle a x1#y1 x2#y2 x3#y3
→ a = angle formed by the edge {(x2, y2),(x1,y1)} and {(x2, y2),(x3,y3)}

angle2 a x1 y1 x2 y2 x3 y3
→ a = angle formed by the edge {(x2, y2),(x1,y1)} and {(x2, y2),(x3,y3)}

areadsensor (Analog Read Sensor)


areadsensor s
→ s=X or s=S#y#v, where X means that there is no sensed value (or event), S means that a
sensed value has been read from the event having id=y, where the read value is
equal to v (use the function rdata function to read these values). If there is
many events then s=S#s1#v1#s2#v2#S3#v3… (use rdata function to read these
values). Note that, s2, s3, … can be null if there is no many events.

atch
atch 12
→ Change the channel of the current sensor to 12
SenScript 3

atid
atid 1111
→ Change the identifier of the sensor to 1111

atpl
atpl 60
→ Change the signal power (power level) of the radio of the sensor. In this
example, the sensor will use only 60% of its radio range.

atmy
atmy 4
→ Change the my of the sensor to 4.

atnd
atnd n
→ n = the number of the neighbors of the sensor.

atnd n v
→ n = the number of the neighbors of the sensor and v the vector of the
identifiers of each neighbor (use vget to get the values of v)

atnid
atnid 2222
→ Change the network address

band
band x 1010 1100
→ x = 1000

battery
battery x
→ x = the level of the battery in Joules

battery set x
→ The level of the battery will be set to x

bnot
band x 1010
→ x = 0101

bor
bor x 1010 1100
→ x = 1110
buffer
SenScript 4

buffer x
→ x = the size of the buffer in bits
bxor
band x 1010 1100
→ x = 0110

cbuffer
cbuffer
→ clear the buffer

charat
charat c hello 1
→ c = ‘e’
the character situated in the index 1 of hello

conc
conc x a b
→ concatenate a and b and assign it to x (=ab). In java this command is written as x = “a”+”b”;

conc x a b
→ concatenate the value of the variable a with the value of the variable b

cprint
cprint "hello" x
→ The same function as print where the result is displayed in the console

data
data p 1 4 6
→ p = 1#4#6

dec
dec x
→x=x-1

delay
delay 1000
→ wait 1 second (1000 ms) before the next instruction

distance
distance x 2
→ x = the Euclidean distance between the current sensor and a communicating sensor node
having an id=2.

dreadsensor
SenScript 5

dreadsensor x
→ x=1 if the sensor detects an event (mobile), x=0, otherwise

drssi
drssi x
→ x = the rssi value transformed to a Euclidean distance between the current
sensor the last sending sensor node.

egde
edge a x
→ to mark (if a=1) or unmark (if a=0) the edge (communication link) between the
current sensor node andthe node having the id x.

for end
for i 0 10 print "i = " idelay 1000 end
→ the same as the following for on C: for(int i=0; i<10; i+=1)

for i 0 10 2 print "i = " idelay 1000 end


→ the same as the following for on C: for(int i=0; i<10; i+=2)

function
The function command can be used only with the source code of CupCarbon.
SenScript 6

function x myf 1,2,v


→ execute the function myf with the arguments 1, 2 and the value of v. The obtained result is
returned in x. To create your own function (example: myf(args)):
1. Add the following script in the method function of the class
ScriptFunction (package script_functions):

if(function.equals("myf")) { return Function_Calc.myf(args);


}

2. Add the methode myf the class Functions as follows:

public static String myf(String [] args)


{String valToReturn = "";
// TODO
// Your program herereturn valToReturn;
}

getinfo
getinfo p
→ if a mobile is detected by the sensing unit, it returns in p information formed by the id and
the coordinates of the mobile in a format: id#longitude#latitude.

getpos
getpos pos
→ pos = the position of the sensor longitude#latitude

→ pos = "-5.489438533782959#48.390415333407574"; // example

getpos pos rdata pos x y


→ x = longitude; // example: -5.489438533782959

→ y = latitude; // example: 48.390415333407574

getpos2
getpos2 x y
→ x = longitude and y = latitude
→ x = -5.489438533782959; and y = 48.390415333407574; // example

goto
goto 5
→ Go to to the line of the code number 5

goto B
→ Go to to the line labeled by B To
label a line by B:
B:set x 12

hash
SenScript 7

hash x hello
→ assign to x the hash code of hello

if [else] end
if (x==1)
mark 1else
mark 0
end
if ((x==1) && ((y>0) || (y<5)))mark 1

else
mark 0
end
SenScript 8

• In the current version of CupCarbon, it is not possible to write: if (x==1 && y>0) ...
• One must write: if ((x==1) && (y>0)) ...

inc
inc x
→x=x+1

int
int x a
→ assign to x the integer value of a (if a=3.2 then x=3)

kill
kill 0.3
→ the current node will be killed (i.e., with empty battery) with a probability of 30%

led
led 1 2
→ set the color number 2 to the sensor (1 is not important here, it represents
the pin number in the read card)

length
length v hello
→v=5
the length of the string “hello”

loop
loop
→ Starting the loop section

mark
mark 1
→ Mark or unmark (mark 0) the sensor

math
math f y x
→ y = f(x) where f = "sqrt, sin, cos, tan, asin, acos, atan, abs, pow,
log, log10, exp". Example:
math sin y 3.14
→ y=sin(3.14)

max
max x 4 3
→ assign to x the maximum value between 4 and 3 (4 and 3 can be replaced with variables)

min
min x 4 3
→ assign to x the minimum value between 4 and 3 (4 and 3 can be replaced with variables)
SenScript 9

move
move x y z t
→ The sensor node will go to the position latitude (x), longitude (y), and
elevation (z) with the speed t meters/second.

not (logic)
not x a
→ x = ~a

nth
nth v i t
→ v will be equal to the ith value of t (t is in a format of a string with the separator &)
→ Example: if t=4&9&2&7 then nth v 1 t will put in v the value 9 (v=9) and t remains the
same.

or (logic)
or x a b
→x=a|b

pick
pick x
→ same as read x without removing the read data from the buffer

printfile
printfile "hello"
→ add the string “hello” in a file generated during the simulation in the
directory results with the name of the sensor node

print
print "hello"
→ display hello

print x
→ display the value of x

print "i = " i


→ display "i = (value of i)"

print ""
→ display nothing

radio
radio [name of a radio module]radio radio2
→ Select the radio module having the name radio2. This means that any send
command that will be used after this instruction will consider the radio2 as the
radio module which will send the message. The considered standard is the one
of the considered radio module.
SenScript 10

rand
rand [variable]rand x
→ x = rand

randb
reandb [varialbe][inf][sup]reandb x 2 6
→ x = random values between 2 (included) and 6 (included)

rdata
rdata p a b
→ We assume that p is a message formed using the command data. It is
possible to form manually p which is a string with # separator (example:
p=hello#4). In this example, rdata p a b will lead to an a="hello” and b=4

read
read x
→ Assign the value of the buffer to x

receive
receive x

→ Wait until receiving data in the buffer and assign it to x. This is a blocking
function, if there is not data in the buffer then it remains blocked on this
instruction.

receive x t
→ Wait until receiving data in the buffer. If there is no data received after t
milliseconds then x will receive an empty message (x=””) and the execution of
the script will be continued.

rgauss
rgauss x
→ x = Standard Gaussian random value

rmove
rmove t
→ Go to the next point of the route created by the markers. A route must be
assigned before simulation to the sensor node. The next instruction of the
script will be executed after t milliseconds. Note that the mobility check box in
the simulation parameters view must be activated.

rotate
rotate x t
→ Rotate with x (double) units the Directional sensor node. The next
instruction of the script will be executed after t milliseconds.

route
route route1
SenScript 11

→ The sensor node will change its route to route having the name route1 after intersecting
with it.

rscript
rscript flooding
→ Load the script floodint.csc while reinitializing the variables of the environment (see
script function)

sadd
sadd x t
→ add the value of x to the stack t which is in a format of string separated by
the symbol &. You can use the command spop to get the first element of the
stack t.

→ Example: if t = 4&6&7, sadd 56 t will lead to: t = 56&4&6&7

script
script flooding
→ Load the script flooding.csc without reinitializing the variables of the environment (see
rscript function)

send
send hello 2
→ Sends hello to the sensor having an id=2

send p 2
→ Sends the value of p to the sensor having an id=2

send p
→ Sends the value of p in a broadcast mode

send p *
→ Sends the value of p in a broadcast mode(the same as send p)

send p * 3
→ Sends the value of p in broadcast except the sensor having an id=3

send p 0 4
→ Sends the value of p to sensors having a MY address equal to 4

send p 0 0 5
SenScript 12

→ Direct sending of the value p to sensors having an id equal to 5 (like in a GPRS/3G/4G


mode)

send !color 1
→ Change the color of the send link on the IHM. It is practical to differentiate
the type of the communication links(of the send instruction) between sensors.

set
set x 5 set s hello set x ""
→x=5 → x = "hello"; → x = ""
set z x*5
set z (x*y)/3
set z x%y
set z (x+y)%2

simulation
simulation 50 200
simulation sspeed 50
simulation aspeed 200
→ just for the visualization and it is not considered in the simulation
process. It allows to change the simulation speed during the simulation
process.

smin
smin m x y
→ x and y must be in a format a#b. If x=a#b and y=c#d then m=x if b<d or m=y if d<=b

smax
smax m x y
→ x and y must be in a format a#b. If x=a#b and y=c#d then m=x if b>d or m=y if d>=b

spop
spop v t
→ retrieve the first value from the stack t (in a format of a string with the
separator &) and put it in the variable v.
→ Example: if t = 4&6&7, sad v t will put in v the value 4 and t becomes t = 6&7

stop
stop
→ Stop the execution of the script

tab
tab t 2 5
→ create a table t with 2 rows and 5 columns (t[2][5])

tget
tget x t 0 2
→ x = t[0][2]
SenScript 13

time
time x
→ assign to x the current simulation time

tset
tset 55 t 0 2
→ t[0][2] = 55

vdata
vdata v 14#54#2
Transform tokens that are separated with # to a vector, with the name v, of these tokens.
→ v[0]=14, v[1]=54 and v[2]=2
SenScript 14

vec
vec v 5
→ create a vector v with 5 elements (t[5])

vget / vset
vget x v 2
→ x = v[2]

vset 55 v 1
→ v[1] = 55

wait
wait (deprecated use receive)
→ Wait until receiving data in the buffer

wait 1000 (deprecated use receive)


→ Wait until receiving data in the buffer. If there is no data received after 1
second (=1000 milliseconds) then the execution of the script will be continued.

while end
while (1)
→ The same as "while (true)" in C.

Example:
set i 0
while ((i<5) && (i>=0))print "i = " i delay 1000
set i i+1 // inc i
end

xor (logic)
xor x a b → x=a^

You might also like