2017-07-24 23:56:26 -03:00
|
|
|
STATUS_VSTIG = 10
|
|
|
|
GROUND_VSTIG = 11
|
|
|
|
WAIT4STEP = 10
|
|
|
|
v_status = {}
|
|
|
|
v_ground = {}
|
|
|
|
|
|
|
|
function uav_initstig() {
|
|
|
|
v_status = stigmergy.create(STATUS_VSTIG)
|
|
|
|
v_ground = stigmergy.create(GROUND_VSTIG)
|
|
|
|
}
|
|
|
|
|
|
|
|
counter=WAIT4STEP
|
|
|
|
function uav_updatestig() {
|
|
|
|
if(counter<=0) {
|
|
|
|
var ls={.g=0,.b=battery.capacity,.x=xbee_status.rssi,.f=flight.status}
|
|
|
|
log("Pushing ", ls, "on vstig with id:", id)
|
|
|
|
v_status.put(id, ls)
|
|
|
|
counter=WAIT4STEP
|
|
|
|
} else
|
|
|
|
counter=counter-1
|
|
|
|
}
|
|
|
|
|
2017-06-19 17:15:18 -03:00
|
|
|
function checkusers() {
|
|
|
|
# Read a value from the structure
|
|
|
|
if(size(users)>0)
|
|
|
|
log("Got a user!")
|
|
|
|
|
2017-07-24 23:56:26 -03:00
|
|
|
# log(users)
|
|
|
|
# users_print(users.dataG)
|
|
|
|
# if(size(users.dataG)>0)
|
|
|
|
# vt.put("p", users.dataG)
|
2017-06-19 17:15:18 -03:00
|
|
|
|
|
|
|
# Get the number of keys in the structure
|
|
|
|
#log("The vstig has ", vt.size(), " elements")
|
|
|
|
# users_save(vt.get("p"))
|
|
|
|
# table_print(users.dataL)
|
|
|
|
}
|
|
|
|
|
|
|
|
function users_save(t) {
|
|
|
|
if(size(t)>0) {
|
|
|
|
foreach(t, function(id, tab) {
|
|
|
|
#log("id: ",id," Latitude ", tab.la, "Longitude ", tab.lo)
|
|
|
|
add_user_rb(id,tab.la,tab.lo)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# printing the contents of a table: a custom function
|
2017-07-24 23:56:26 -03:00
|
|
|
function usertab_print(t) {
|
2017-06-19 17:15:18 -03:00
|
|
|
if(size(t)>0) {
|
|
|
|
foreach(t, function(u, tab) {
|
|
|
|
log("id: ",u," Range ", tab.r, "Bearing ", tab.b)
|
|
|
|
})
|
|
|
|
}
|
2017-07-24 23:56:26 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
function stattab_print() {
|
|
|
|
if(v_status.size()>0) {
|
|
|
|
u=0
|
|
|
|
while(u<8){
|
|
|
|
tab = v_status.get(u)
|
|
|
|
if(tab!=nil) {
|
|
|
|
log("id: ", u)
|
|
|
|
log("- GPS ", tab.g)
|
|
|
|
log("- Battery ", tab.b)
|
|
|
|
log("- Xbee ", tab.x)
|
|
|
|
log("- Status ", tab.f)
|
|
|
|
}
|
|
|
|
u=u+1
|
|
|
|
}
|
|
|
|
}
|
2017-06-19 17:15:18 -03:00
|
|
|
}
|