⚡ add new std file phi.nas
This commit is contained in:
parent
fee646965e
commit
0b66227667
261
std/fg_env.nas
261
std/fg_env.nas
|
@ -564,264 +564,3 @@ foreach(var a;runtime.argv())
|
||||||
if(contains(fg_env_cli,a)){
|
if(contains(fg_env_cli,a)){
|
||||||
fg_env_cli[a].f();
|
fg_env_cli[a].f();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# related doc: https://sourceforge.net/p/flightgear/fgdata/ci/next/tree/Docs/README.properties
|
|
||||||
# ================================================================================
|
|
||||||
# CONTROLS
|
|
||||||
# ================================================================================
|
|
||||||
|
|
||||||
# Flight Controls
|
|
||||||
# ---------------
|
|
||||||
# /controls/flight/aileron
|
|
||||||
# /controls/flight/aileron-trim
|
|
||||||
# /controls/flight/elevator
|
|
||||||
# /controls/flight/elevator-trim
|
|
||||||
# /controls/flight/rudder
|
|
||||||
# /controls/flight/rudder-trim
|
|
||||||
# /controls/flight/flaps
|
|
||||||
# /controls/flight/slats
|
|
||||||
# /controls/flight/BLC // Boundary Layer Control
|
|
||||||
# /controls/flight/spoilers
|
|
||||||
# /controls/flight/speedbrake
|
|
||||||
# /controls/flight/wing-sweep
|
|
||||||
# /controls/flight/wing-fold
|
|
||||||
# /controls/flight/drag-chute
|
|
||||||
|
|
||||||
# Engines
|
|
||||||
# -------
|
|
||||||
# /controls/engines/throttle_idle
|
|
||||||
# /controls/engines/engine[%d]/throttle
|
|
||||||
# /controls/engines/engine[%d]/starter
|
|
||||||
# /controls/engines/engine[%d]/fuel-pump
|
|
||||||
# /controls/engines/engine[%d]/fire-switch
|
|
||||||
# /controls/engines/engine[%d]/fire-bottle-discharge
|
|
||||||
# /controls/engines/engine[%d]/cutoff
|
|
||||||
# /controls/engines/engine[%d]/mixture
|
|
||||||
# /controls/engines/engine[%d]/propeller-pitch
|
|
||||||
# /controls/engines/engine[%d]/magnetos
|
|
||||||
# /controls/engines/engine[%d]/boost
|
|
||||||
# /controls/engines/engine[%d]/WEP
|
|
||||||
# /controls/engines/engine[%d]/cowl-flaps-norm
|
|
||||||
# /controls/engines/engine[%d]/feather
|
|
||||||
# /controls/engines/engine[%d]/ignition
|
|
||||||
# /controls/engines/engine[%d]/augmentation
|
|
||||||
# /controls/engines/engine[%d]/afterburner
|
|
||||||
# /controls/engines/engine[%d]/reverser
|
|
||||||
# /controls/engines/engine[%d]/water-injection
|
|
||||||
# /controls/engines/engine[%d]/condition
|
|
||||||
|
|
||||||
# Fuel
|
|
||||||
# ----
|
|
||||||
# /controls/fuel/dump-valve
|
|
||||||
# /controls/fuel/tank[%d]/fuel_selector
|
|
||||||
# /controls/fuel/tank[%d]/to_engine
|
|
||||||
# /controls/fuel/tank[%d]/to_tank
|
|
||||||
# /controls/fuel/tank[%d]/boost-pump[%d]
|
|
||||||
|
|
||||||
# /consumables/fuel/tank[%d]/level-lbs
|
|
||||||
# /consumables/fuel/tank[%d]/level-gal_us
|
|
||||||
# /consumables/fuel/tank[%d]/capacity-gal_us
|
|
||||||
# /consumables/fuel/tank[%d]/density-ppg
|
|
||||||
# /consumables/fuel/total-fuel-lbs
|
|
||||||
# /consumables/fuel/total-gal_us
|
|
||||||
|
|
||||||
|
|
||||||
# Gear
|
|
||||||
# ----
|
|
||||||
# /controls/gear/brake-left
|
|
||||||
# /controls/gear/brake-right
|
|
||||||
# /controls/gear/brake-parking
|
|
||||||
# /controls/gear/steering
|
|
||||||
# /controls/gear/gear-down
|
|
||||||
# /controls/gear/antiskid
|
|
||||||
# /controls/gear/tailhook
|
|
||||||
# /controls/gear/tailwheel-lock
|
|
||||||
# /controls/gear/wheel[%d]/alternate-extension
|
|
||||||
|
|
||||||
# Anti-Ice
|
|
||||||
# --------
|
|
||||||
# /controls/anti-ice/wing-heat
|
|
||||||
# /controls/anti-ice/pitot-heat
|
|
||||||
# /controls/anti-ice/wiper
|
|
||||||
# /controls/anti-ice/window-heat
|
|
||||||
# /controls/anti-ice/engine[%d]/carb-heat
|
|
||||||
# /controls/anti-ice/engine[%d]/inlet-heat
|
|
||||||
|
|
||||||
# Hydraulics
|
|
||||||
# ----------
|
|
||||||
# /controls/hydraulic/system[%d]/engine-pump
|
|
||||||
# /controls/hydraulic/system[%d]/electric-pump
|
|
||||||
|
|
||||||
# Electric
|
|
||||||
# --------
|
|
||||||
# /controls/electric/battery-switch
|
|
||||||
# /controls/electric/external-power
|
|
||||||
# /controls/electric/APU-generator
|
|
||||||
# /controls/electric/engine[%d]/generator
|
|
||||||
# /controls/electric/engine[%d]/bus-tie
|
|
||||||
|
|
||||||
# Pneumatic
|
|
||||||
# ---------
|
|
||||||
# /controls/pneumatic/APU-bleed
|
|
||||||
# /controls/pneumatic/engine[%d]/bleed
|
|
||||||
|
|
||||||
# Pressurization
|
|
||||||
# --------------
|
|
||||||
# /controls/pressurization/mode
|
|
||||||
# /controls/pressurization/dump
|
|
||||||
# /controls/pressurization/outflow-valve
|
|
||||||
# /controls/pressurization/pack[%d]/pack-on
|
|
||||||
|
|
||||||
# Lights
|
|
||||||
# ------
|
|
||||||
# /controls/lighting/landing-lights
|
|
||||||
# /controls/lighting/turn-off-lights
|
|
||||||
# /controls/lighting/formation-lights
|
|
||||||
# /controls/lighting/taxi-light
|
|
||||||
# /controls/lighting/logo-lights
|
|
||||||
# /controls/lighting/nav-lights
|
|
||||||
# /controls/lighting/beacon
|
|
||||||
# /controls/lighting/strobe
|
|
||||||
# /controls/lighting/panel-norm
|
|
||||||
# /controls/lighting/instruments-norm
|
|
||||||
# /controls/lighting/dome-norm
|
|
||||||
|
|
||||||
# Armament
|
|
||||||
# --------
|
|
||||||
# /controls/armament/master-arm
|
|
||||||
# /controls/armament/station-select
|
|
||||||
# /controls/armament/release-all
|
|
||||||
# /controls/armament/station[%d]/stick-size
|
|
||||||
# /controls/armament/station[%d]/release-stick
|
|
||||||
# /controls/armament/station[%d]/release-all
|
|
||||||
# /controls/armament/station[%d]/jettison-all
|
|
||||||
|
|
||||||
# Seat
|
|
||||||
# ----
|
|
||||||
# /controls/seat/vertical-adjust
|
|
||||||
# /controls/seat/fore-aft-adjust
|
|
||||||
# /controls/seat/cmd_selector_valve
|
|
||||||
# /controls/seat/eject[%d]/initiate
|
|
||||||
# /controls/seat/eject[%d]/status
|
|
||||||
|
|
||||||
# APU
|
|
||||||
# ---
|
|
||||||
# /controls/APU/off-start-run
|
|
||||||
# /controls/APU/fire-switch
|
|
||||||
|
|
||||||
# Autoflight
|
|
||||||
# ----------
|
|
||||||
# /controls/autoflight/autopilot[%d]/engage
|
|
||||||
# /controls/autoflight/autothrottle-arm
|
|
||||||
# /controls/autoflight/autothrottle-engage
|
|
||||||
# /controls/autoflight/heading-select
|
|
||||||
# /controls/autoflight/altitude-select
|
|
||||||
# /controls/autoflight/bank-angle-select
|
|
||||||
# /controls/autoflight/vertical-speed-select
|
|
||||||
# /controls/autoflight/speed-select
|
|
||||||
# /controls/autoflight/mach-select
|
|
||||||
# /controls/autoflight/vertical-mode
|
|
||||||
# /controls/autoflight/lateral-mode
|
|
||||||
|
|
||||||
# ================================================================================
|
|
||||||
# FDM (Aircraft settings)
|
|
||||||
# ================================================================================
|
|
||||||
|
|
||||||
# Position
|
|
||||||
# ---------------
|
|
||||||
# /position/latitude-deg
|
|
||||||
# /position/longitude-deg
|
|
||||||
# /position/altitude-ft
|
|
||||||
|
|
||||||
# Orientation
|
|
||||||
# -----------
|
|
||||||
# /orientation/roll-deg
|
|
||||||
# /orientation/pitch-deg
|
|
||||||
# /orientation/heading-deg
|
|
||||||
|
|
||||||
# /orientation/roll-rate-degps
|
|
||||||
# /orientation/pitch-rate-degps
|
|
||||||
# /orientation/yaw-rate-degps
|
|
||||||
|
|
||||||
# /orientation/side-slip-rad
|
|
||||||
# /orientation/side-slip-deg
|
|
||||||
# /orientation/alpha-deg
|
|
||||||
|
|
||||||
# Velocities
|
|
||||||
# ----------
|
|
||||||
# /velocities/airspeed-kt
|
|
||||||
# /velocities/mach
|
|
||||||
# /velocities/speed-north-fps
|
|
||||||
# /velocities/speed-east-fps
|
|
||||||
# /velocities/speed-down-fps
|
|
||||||
|
|
||||||
# /velocities/uBody-fps
|
|
||||||
# /velocities/vBody-fps
|
|
||||||
# /velocities/wBody-fps
|
|
||||||
|
|
||||||
# /velocities/vertical-speed-fps
|
|
||||||
# /velocities/glideslope
|
|
||||||
|
|
||||||
# Acceleration
|
|
||||||
# ------------
|
|
||||||
# /accelerations/nlf
|
|
||||||
|
|
||||||
# /accelerations/ned/north-accel-fps_sec
|
|
||||||
# /accelerations/ned/east-accel-fps_sec
|
|
||||||
# /accelerations/ned/down-accel-fps_sec
|
|
||||||
|
|
||||||
# /accelerations/pilot/x-accel-fps_sec
|
|
||||||
# /accelerations/pilot/y-accel-fps_sec
|
|
||||||
# /accelerations/pilot/z-accel-fps_sec
|
|
||||||
|
|
||||||
# Engines
|
|
||||||
# -------
|
|
||||||
|
|
||||||
# common:
|
|
||||||
# /engines/engine[%d]/fuel-flow-gph
|
|
||||||
# /engines/engine[%d]/fuel-flow_pph
|
|
||||||
# /engines/engine[%d]/thrust_lb
|
|
||||||
# /engines/engine[%d]/running
|
|
||||||
# /engines/engine[%d]/starter
|
|
||||||
# /engines/engine[%d]/cranking
|
|
||||||
|
|
||||||
# piston:
|
|
||||||
# /engines/engine[%d]/mp-osi
|
|
||||||
# /engines/engine[%d]/egt-degf
|
|
||||||
# /engines/engine[%d]/oil-temperature-degf
|
|
||||||
# /engines/engine[%d]/oil-pressure-psi
|
|
||||||
# /engines/engine[%d]/cht-degf
|
|
||||||
# /engines/engine[%d]/rpm
|
|
||||||
|
|
||||||
# turbine:
|
|
||||||
# /engines/engine[%d]/n1
|
|
||||||
# /engines/engine[%d]/n2
|
|
||||||
# /engines/engine[%d]/epr
|
|
||||||
# /engines/engine[%d]/augmentation
|
|
||||||
# /engines/engine[%d]/water-injection
|
|
||||||
# /engines/engine[%d]/ignition
|
|
||||||
# /engines/engine[%d]/nozzle-pos-norm
|
|
||||||
# /engines/engine[%d]/inlet-pos-norm
|
|
||||||
# /engines/engine[%d]/reversed
|
|
||||||
# /engines/engine[%d]/cutoff
|
|
||||||
|
|
||||||
# propeller:
|
|
||||||
# /engines/engine[%d]/rpm
|
|
||||||
# /engines/engine[%d]/pitch
|
|
||||||
# /engines/engine[%d]/torque
|
|
||||||
|
|
||||||
|
|
||||||
# ================================================================================
|
|
||||||
# LIGHT
|
|
||||||
# ================================================================================
|
|
||||||
# /sim/time/sun-angle-rad
|
|
||||||
# /rendering/scene/ambient/red
|
|
||||||
# /rendering/scene/ambient/ggreen
|
|
||||||
# /rendering/scene/ambient/blue
|
|
||||||
# /rendering/scene/diffuse/red
|
|
||||||
# /rendering/scene/diffuse/green
|
|
||||||
# /rendering/scene/diffuse/blue
|
|
||||||
# /rendering/scene/specular/red
|
|
||||||
# /rendering/scene/specular/green
|
|
||||||
# /rendering/scene/specular/blue
|
|
|
@ -299,7 +299,7 @@ var stringify = func(object) {
|
||||||
var k = keys(h);
|
var k = keys(h);
|
||||||
var vsize = size(k);
|
var vsize = size(k);
|
||||||
for(var i = 0; i<vsize; i += 1) {
|
for(var i = 0; i<vsize; i += 1) {
|
||||||
s ~= k[i]~":";
|
s ~= "\""~k[i]~"\":";
|
||||||
gen(h[k[i]]);
|
gen(h[k[i]]);
|
||||||
if (i!=vsize-1) {
|
if (i!=vsize-1) {
|
||||||
s ~= ",";
|
s ~= ",";
|
||||||
|
|
|
@ -0,0 +1,145 @@
|
||||||
|
# used to get property tree from fgfs by httpd
|
||||||
|
# use --httpd=5500 to start fgfs
|
||||||
|
# and use this script to get property tree
|
||||||
|
# 2023/11/06 ValKmjolnir
|
||||||
|
|
||||||
|
use module.libsock;
|
||||||
|
use std.json;
|
||||||
|
|
||||||
|
var _raw_str = func(s) {
|
||||||
|
var v = split("", s);
|
||||||
|
var res = "";
|
||||||
|
foreach(var i; v) {
|
||||||
|
if (i=="\r") {
|
||||||
|
res ~= "\\r";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (i=="\n") {
|
||||||
|
res ~= "\\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
res ~= i;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
var _get_time = func() {
|
||||||
|
return "["~os.time()~"]";
|
||||||
|
}
|
||||||
|
|
||||||
|
var _connect = func(hostname, port) {
|
||||||
|
var socket = libsock.socket;
|
||||||
|
var sd = socket.socket(
|
||||||
|
socket.AF_INET,
|
||||||
|
socket.SOCK_STREAM,
|
||||||
|
socket.IPPROTO_TCP
|
||||||
|
);
|
||||||
|
var ip_info = hostname~":"~port;
|
||||||
|
while((var err = socket.connect(sd, hostname, port))==socket.SOCKET_ERROR) {
|
||||||
|
println(_get_time(), " failed to connect ", ip_info, ": ", socket.errno());
|
||||||
|
unix.sleep(1);
|
||||||
|
}
|
||||||
|
println(_get_time(), " connect to ", ip_info, " succeeded");
|
||||||
|
return sd;
|
||||||
|
}
|
||||||
|
|
||||||
|
var new = func(hostname, port) {
|
||||||
|
var socket = libsock.socket;
|
||||||
|
var sd = _connect(hostname, port);
|
||||||
|
|
||||||
|
var getprop = func(path) {
|
||||||
|
if (size(path)==0 or path[0]!='/'[0]) {
|
||||||
|
println("node \"", path, "\" not found, invalid path");
|
||||||
|
return {path: path};
|
||||||
|
}
|
||||||
|
# GET header
|
||||||
|
var header = "GET /json"~path~" HTTP/1.1\r\n\r\n";
|
||||||
|
var res = socket.send(sd, header);
|
||||||
|
|
||||||
|
# get message head 1024
|
||||||
|
var message = socket.recv(sd, 1024);
|
||||||
|
if (find("404 Not Found", message.str)>=0) {
|
||||||
|
println("node \"", path, "\" not found, get 404 response");
|
||||||
|
return {path: path};
|
||||||
|
}
|
||||||
|
# get total message
|
||||||
|
var total_source = message.str;
|
||||||
|
# 0\r\n\r\n is the tail of chunked http info
|
||||||
|
while(find("0\r\n\r\n", total_source)<0) {
|
||||||
|
message = socket.recv(sd, 1024);
|
||||||
|
total_source ~= message.str;
|
||||||
|
}
|
||||||
|
|
||||||
|
# get json in this message
|
||||||
|
var begin_position = find("{", total_source);
|
||||||
|
var end_position = find("0\r\n\r\n", total_source);
|
||||||
|
var length = end_position-begin_position;
|
||||||
|
if (begin_position<0) {
|
||||||
|
println("node \"", path, "\" not found, invalid begin token");
|
||||||
|
return {path: path};
|
||||||
|
}
|
||||||
|
if (length<0) {
|
||||||
|
println("node \"", path, "\" not found, invalid end token");
|
||||||
|
return {path: path};
|
||||||
|
}
|
||||||
|
var data = substr(total_source, begin_position, length);
|
||||||
|
|
||||||
|
# parse this json and return
|
||||||
|
var props = json.parse(data);
|
||||||
|
if (json.get_error()) {
|
||||||
|
println("encounter error when parsing \"", path, "\"");
|
||||||
|
logprint(LOG_DEBUG, _raw_str(data));
|
||||||
|
return {path: path};
|
||||||
|
}
|
||||||
|
|
||||||
|
# empty prop node is not allowed...
|
||||||
|
if (size(props)==0) {
|
||||||
|
println("node \"", path, "\" not found, empty tree node");
|
||||||
|
}
|
||||||
|
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
|
||||||
|
var setprop = func(path, data) {
|
||||||
|
if (size(path)==0 or path[0]!='/'[0]) {
|
||||||
|
println("node \"", path, "\" not found, invalid path");
|
||||||
|
return {path: path};
|
||||||
|
}
|
||||||
|
# POST header
|
||||||
|
var header = "POST /json"~path~" HTTP/1.1\r\n\r\n";
|
||||||
|
# generate value
|
||||||
|
header ~= "{\"value\":\""~data~"\"}\r\n\r\n";
|
||||||
|
|
||||||
|
var res = socket.send(sd, header);
|
||||||
|
var message = socket.recv(sd, 1024);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
getprop: getprop,
|
||||||
|
setprop: setprop
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var dump = func(tree, indent = "") {
|
||||||
|
if (size(tree)==0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
println(indent, "-------------------");
|
||||||
|
var tree_keys = keys(tree);
|
||||||
|
sort(tree_keys, func(a,b) {return cmp(a, b)<0;});
|
||||||
|
foreach(var key; tree_keys) {
|
||||||
|
if (key == "children") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
println(indent, key, " : \"", tree[key], "\"");
|
||||||
|
}
|
||||||
|
println(indent, "-------------------");
|
||||||
|
|
||||||
|
if (contains(tree, "children")) {
|
||||||
|
foreach(var i; tree.children) {
|
||||||
|
dump(i, indent~" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,146 +1,4 @@
|
||||||
# used to get property tree from fgfs by httpd
|
use std.phi;
|
||||||
# use --httpd=5500 to start fgfs
|
|
||||||
# and use this script to get property tree
|
|
||||||
# 2023/11/06 ValKmjolnir
|
|
||||||
|
|
||||||
use module.libsock;
|
|
||||||
use std.json;
|
|
||||||
|
|
||||||
var connection = {};
|
|
||||||
connection.new = func(hostname, port) {
|
|
||||||
var socket = libsock.socket;
|
|
||||||
var sd = socket.socket(
|
|
||||||
socket.AF_INET,
|
|
||||||
socket.SOCK_STREAM,
|
|
||||||
socket.IPPROTO_TCP
|
|
||||||
);
|
|
||||||
|
|
||||||
while((var err = socket.connect(sd, hostname, port))==socket.SOCKET_ERROR) {
|
|
||||||
println(
|
|
||||||
"[", os.time(), "] connect to ",
|
|
||||||
hostname, ":", port, " failed: ",
|
|
||||||
socket.errno()
|
|
||||||
);
|
|
||||||
unix.sleep(1);
|
|
||||||
}
|
|
||||||
println("[", os.time(), "] connect to ", hostname, ":", port, " succeeded");
|
|
||||||
|
|
||||||
var raw = func(s) {
|
|
||||||
var v = split("", s);
|
|
||||||
var res = "";
|
|
||||||
foreach(var i; v) {
|
|
||||||
if (i=="\r") {
|
|
||||||
res ~= "\\r";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (i=="\n") {
|
|
||||||
res ~= "\\n\n";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
res ~= i;
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
var getprop = func(path) {
|
|
||||||
# GET header
|
|
||||||
var header = "GET /json"~path~" HTTP/1.1\n\r\n";
|
|
||||||
var res = socket.send(sd, header);
|
|
||||||
|
|
||||||
# get message head 1024
|
|
||||||
var message = socket.recv(sd, 1024);
|
|
||||||
var head_vector = split("\r\n", message.str);
|
|
||||||
if (size(head_vector)<11) {
|
|
||||||
println("getprop: node \"", path, "\" not found, invalid header");
|
|
||||||
logprint(LOG_DEBUG, raw(message.str));
|
|
||||||
return {path: path};
|
|
||||||
}
|
|
||||||
var message_total_size = num("0x"~head_vector[10]);
|
|
||||||
|
|
||||||
# get total message
|
|
||||||
var total_source = message.str;
|
|
||||||
var total_size = message.size;
|
|
||||||
while(total_size<=message_total_size) {
|
|
||||||
message = socket.recv(sd, 1024);
|
|
||||||
total_source ~= message.str;
|
|
||||||
total_size += message.size;
|
|
||||||
}
|
|
||||||
# if not get end of the message, recv one more time
|
|
||||||
if (find("0\r\n\r\n", total_source)<0) {
|
|
||||||
message = socket.recv(sd, 1024);
|
|
||||||
total_source ~= message.str;
|
|
||||||
total_size += message.size;
|
|
||||||
}
|
|
||||||
|
|
||||||
# get json in this message
|
|
||||||
var begin_position = find("{", total_source);
|
|
||||||
if (begin_position<0) {
|
|
||||||
println("getprop: node \"", path, "\" not found, invalid begin token");
|
|
||||||
return {path: path};
|
|
||||||
}
|
|
||||||
var end_position = find("0\r\n\r\n", total_source);
|
|
||||||
var length = end_position-begin_position;
|
|
||||||
if (length<0) {
|
|
||||||
println("getprop: node \"", path, "\" not found, invalid end token");
|
|
||||||
return {path: path};
|
|
||||||
}
|
|
||||||
var data = substr(total_source, begin_position, length);
|
|
||||||
|
|
||||||
# parse this json and return
|
|
||||||
var props = json.parse(data);
|
|
||||||
if (json.get_error()) {
|
|
||||||
println("getprop: encounter error when parsing \"", path, "\"");
|
|
||||||
logprint(LOG_DEBUG, raw(data));
|
|
||||||
return {path: path};
|
|
||||||
}
|
|
||||||
|
|
||||||
# empty prop node is not allowed...
|
|
||||||
if (size(props)==0) {
|
|
||||||
println("getprop: node \"", path, "\" not found, empty tree node");
|
|
||||||
}
|
|
||||||
|
|
||||||
return props;
|
|
||||||
}
|
|
||||||
|
|
||||||
var setprop = func(path, data) {
|
|
||||||
# POST header
|
|
||||||
var header = "POST /json"~path~" HTTP/1.1\n\n";
|
|
||||||
# generate value
|
|
||||||
header ~= "{\"value\":\""~data~"\"}\n\r\n";
|
|
||||||
|
|
||||||
var res = socket.send(sd, header);
|
|
||||||
var message = socket.recv(sd, 1024);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
getprop: getprop,
|
|
||||||
setprop: setprop
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
var dump = func(tree, indent = "") {
|
|
||||||
if (size(tree)==0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
println(indent, "-------------------");
|
|
||||||
var tree_keys = keys(tree);
|
|
||||||
sort(tree_keys, func(a,b) {return cmp(a, b)<0;});
|
|
||||||
foreach(var key; tree_keys) {
|
|
||||||
if (key == "children") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
println(indent, key, " : \"", tree[key], "\"");
|
|
||||||
}
|
|
||||||
println(indent, "-------------------");
|
|
||||||
|
|
||||||
if (contains(tree, "children")) {
|
|
||||||
println(indent, "children :");
|
|
||||||
foreach(var i; tree.children) {
|
|
||||||
dump(i, indent~" ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var tips = func() {
|
var tips = func() {
|
||||||
println("usage:");
|
println("usage:");
|
||||||
|
@ -158,24 +16,28 @@ if (size(arg)>2) {
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var connect = connection.new(arg[0], num(arg[1]));
|
var connect = phi.new(arg[0], num(arg[1]));
|
||||||
var count = 0;
|
var count = 0;
|
||||||
var recursive_get_prop = func(path = "/") {
|
var recursive_get_prop = func(path = "/") {
|
||||||
count += 1;
|
count += 1;
|
||||||
if (math.mod(count, 100)==0) {
|
if (math.mod(count, 50)==0) {
|
||||||
println("get ", count," nodes, now: \"", path, "\"");
|
println("get ", count," nodes, now: \"", path, "\"");
|
||||||
}
|
}
|
||||||
var props = connect.getprop(path);
|
var props = connect.getprop(path);
|
||||||
var tree = {};
|
var tree = {};
|
||||||
tree.path = props.path;
|
foreach(var key; keys(props)) {
|
||||||
|
if (key=="children") {
|
||||||
|
tree.children = [];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
tree[key] = props[key];
|
||||||
|
}
|
||||||
if (!contains(props, "children")) {
|
if (!contains(props, "children")) {
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
tree.children = [];
|
|
||||||
foreach(var child; props.children) {
|
foreach(var child; props.children) {
|
||||||
var node = {};
|
var node = recursive_get_prop(child.path);
|
||||||
node = recursive_get_prop(child.path);
|
|
||||||
append(tree.children, node);
|
append(tree.children, node);
|
||||||
}
|
}
|
||||||
return tree;
|
return tree;
|
||||||
|
@ -183,4 +45,4 @@ var recursive_get_prop = func(path = "/") {
|
||||||
|
|
||||||
# takes about 5 min to get whole tree
|
# takes about 5 min to get whole tree
|
||||||
var props = recursive_get_prop("/");
|
var props = recursive_get_prop("/");
|
||||||
dump(props);
|
phi.dump(props);
|
||||||
|
|
Loading…
Reference in New Issue