Skip to main content

GodsEye from ST — the GEV_* functions

ControlForge can serve the godseye 3D globe on its own port and drive it from Structured Text. A page that opens http://<page host>/?display=<name> (the IDE's Open globe ↗ button mints the ticket) becomes a named display; the GEV_* family sends it any operation from the catalogue — fly somewhere, switch a style, track an aircraft, play a scene, draw a pin — and reads back what the display reports.

Every operation ST can send is in the catalogue the runtime serves at GET /api/godseye/operations (28 upstream voice tools, capture_frame, display_info, and the component rows for the rest of the UI). Names are the catalogue's: fly_to_location, set_visual_style, track_entity, set_layer_visibility, control_scene, annotate_map, set_camera_orientation…

The idiom: send, poll, read​

GEV_REQUEST_SEND never blocks the scan. It hands back a request id; the answer lands in its slot whenever the display replies, and the program polls:

PROGRAM GlobeDemo
VAR
tick : TON;
req : DINT := 0;
state : DINT := 0;
reply : STRING(4096) := ''; (* a plain STRING holds 248 bytes — size it for the result *)
view : STRING(512) := '';
step : INT := 0;
END_VAR

tick(IN := TRUE, PT := T#2s);

CASE step OF
0: (* wait for a display to connect *)
IF GEV_CONNECTED('stage') THEN
step := 1;
END_IF;

1: (* send one catalogue operation *)
req := GEV_REQUEST_SEND('stage', 'fly_to_location',
'{"locationId":"austin","rangeM":20000,"waitForArrival":true}',
30000);
IF req > 0 THEN
step := 2;
ELSE
reply := GEV_LAST_ERROR(); (* why it was refused *)
step := 9;
END_IF;

2: (* poll: 0 pending, 1 ready, -1 timeout, -2 error *)
state := GEV_REQUEST_RESULT(req);
IF state <> 0 THEN
reply := GEV_REQUEST_DATA(req); (* result JSON or the error text; frees the slot *)
step := 3;
END_IF;

3: (* read what the display reports *)
view := GEV_VIEW('stage'); (* {"lat":…,"lon":…,"height_m":…,"heading":…,"pitch":…,"roll":…} *)
step := 4;

4: (* every 2 s, drain the display's events for this task *)
IF tick.Q THEN
tick(IN := FALSE);
WHILE GEV_EVENT_PENDING('stage') > 0 DO
reply := GEV_EVENT_NEXT('stage'); (* {"kind":"view"|"click"|"select"|"track","data":{…},"ts":…} *)
END_WHILE;
END_IF;
END_CASE;
END_PROGRAM

The functions​

FunctionReturns
GEV_REQUEST_SEND(display, op, args_json, timeout_ms) : DINTrequest id > 0, or 0 when refused at once — no such display, not connected, unknown op, an op the page lacks, arguments that fail the op's schema, the display's pending table full, page host not running, capture_frame, or 64 requests already outstanding on this task (godseye.max_slots_per_task). GEV_LAST_ERROR() says which, in the hub's own words. args_json '' means {}.
GEV_REQUEST_RESULT(id) : DINT0 pending · 1 ready · −1 timeout · −2 error or unknown id
GEV_REQUEST_DATA(id) : STRING'' while pending. In a terminal state: the result JSON (ready) or the error text (timeout/error) — and the slot is freed; a second read is '' and RESULT then reads −2
GEV_REQUEST_DROP(id) : BOOLabandon a request without reading; TRUE if a slot was freed
GEV_LAST_ERROR() : STRINGwhy the last GEV_REQUEST_SEND on this task refused; '' once a request was sent
GEV_CONNECTED(display) : BOOLis the display connected right now
GEV_DISPLAYS() : STRING[{"name":…,"connected_s":…,"upstream":…}]
GEV_VIEW(display) : STRINGthe last camera the display reported, or ''
GEV_EVENT_NEXT(display) : STRINGthe next event after this task's cursor, '' when none
GEV_EVENT_PENDING(display) : DINTevents waiting after this task's cursor
GEV_EVENT_DROPPED(display) : DINTthe display's ring overflow count

The result of a ready request is the display's own answer, wrapped: {"ok":true,"data":{…the operation's result…},"ms":2680}; a page-side refusal is {"ok":false,"data":{"ok":false,"error":"…"},"ms":…} — still state 1 (ready), because the display answered. Read the JSON with JSON_GET_STRING, JSON_GET_NUMBER and friends.

Arguments are checked. A wrong count or type faults the task with a message naming the function and the expected signature (never a silent 0).

Size the STRING for the answer. A plain STRING variable holds 248 bytes and an assignment cuts a longer value there, silently. Results are JSON: fly_to_location answers in ~170 bytes, display_info in ~250, get_current_view_state in ~3,000. Declare reply : STRING(4096) (or larger) for anything you will parse; the GEV_* functions themselves never truncate — measured: the same 2,984-byte result arrived whole in a STRING(8192) and cut at 248 in a plain STRING.

Drawing on every display — the layer writers​

ControlForge owns a layer store every connected display draws: points of interest (entities), polygons and polylines (shapes), and overlays (imagery, GeoJSON/KML/CZML, 3D Tiles, terrain — set through PUT /api/godseye/layer or Fred's controlforge_godseye_layer tool, not from ST). The store survives a display's reconnect: the page rebuilds it from the welcome. Between flushes only the latest value per id is kept for each display (display_rate_hz, default 10), so a program may move an entity every scan — the display sees ten updates a second, never ten thousand.

PROGRAM FleetOnGlobe
VAR
tick : TON;
t : LREAL := 0.0;
lat : LREAL;
lon : LREAL;
ok : BOOL;
why : STRING(256) := '';
fenced : BOOL := FALSE;
END_VAR

(* once: a geofence around the yard *)
IF NOT fenced THEN
fenced := GEV_SHAPE_SET('yard', 'polygon',
'[[30.270,-97.745],[30.270,-97.735],[30.262,-97.735],[30.262,-97.745]]',
'{"color":"#4ec9b0","fill":true,"label":"Yard"}');
END_IF;

(* every scan: the truck moves; the display coalesces *)
t := t + 0.001;
lat := 30.266 + 0.003 * SIN(t);
lon := -97.740 + 0.004 * COS(t);
ok := GEV_ENTITY_SET('truck-1', lat, lon, 200.0, 90.0,
'{"label":"Truck 1","color":"#ffcc00","size":12,"trail_s":30}');
IF NOT ok THEN
why := GEV_LAST_ERROR(); (* a limit, an off-globe position, a bad style *)
END_IF;
END_PROGRAM
FunctionReturns
GEV_ENTITY_SET(id, lat, lon, alt_m, heading_deg, style_json) : BOOLupsert; style_json {label, color, icon, size, trail_s} or ''; FALSE = refused, reason in GEV_LAST_ERROR()
GEV_ENTITY_REMOVE(id) : BOOL
GEV_SHAPE_SET(id, kind, points_json, style_json) : BOOLkind 'polygon' (≥ 3 points) or 'polyline' (≥ 2); points_json [[lat, lon, alt_m?], …]; style_json {color, width, fill, label}
GEV_SHAPE_REMOVE(id) : BOOL
GEV_LAYER_CLEAR() : BOOLentities, shapes and overlays, on every display

Limits (godseye.max_entities 2000, max_shapes 500, max_overlays 16, max_points_per_shape 5000): a set past one is refused with the limit named; updating an existing id never counts. The writers need the same capabilities.godseye.enabled consent as GEV_REQUEST_SEND.

GEV_REQUEST_SEND commands what an audience sees, so it needs the deployment's consent in the --config file:

capabilities:
godseye:
enabled: true

Without it the call faults the task with the gate's standard message, which names that key. The readers — GEV_REQUEST_RESULT, _DATA, _DROP, GEV_LAST_ERROR, GEV_CONNECTED, GEV_DISPLAYS, GEV_VIEW, GEV_EVENT_* — need nothing: a program may always ask whether a display exists.

The add-on itself must be on (godseye: {enabled: true, dir: <built page>}, or --godseye / --godseye-port); otherwise GEV_REQUEST_SEND returns 0 with GEV_LAST_ERROR() = godseye page host is not running.

Rules the display keeps​

  • A request goes only to a connected display; nothing is queued while it is away, and nothing is replayed when it comes back. Poll GEV_CONNECTED and send again.
  • Every request has a deadline (timeout_ms; 100 ms … 120 s). A flight with waitForArrival can take tens of seconds — give it 30 000 or more.
  • At most 64 requests outstanding per task (godseye.max_slots_per_task); read or drop them. GEV_REQUEST_DROP also abandons the wait for the display's answer — a command the display already accepted still runs there; a display is a screen, not a transaction.
  • One task's event cursor is its own: two tasks draining the same display each see every event.
  • Not for ST: capture_frame (an image in a STRING is the wrong shape); use the HTTP route GET /api/godseye/displays/<name>/capture or Fred's tool.

The console​

The 🌐 GodsEye console ↗ entry in the IDE's activity menu (shown when the add-on is configured or running) opens the operator's console full-screen in its own window (/hmi/godseye), so it can sit beside the globe window: the connected displays (session, uptime, viewport, page hooks, layer frames sent, events dropped), a command console whose operation picker and argument form are generated from the catalogue (GET /api/godseye/operations — read-class operations run through the query route, write-class through the command route), the latest capture, the live event log (view / select / track / click), and the ControlForge layer store with a clear button. The Config tab's GodsEye section starts and stops the page host and opens a display through a one-time ticket. No globe in the console: the globe is the full page.

Packaging​

The page ships beside the binary as godseye/ only through scripts/godseye/package-page.sh, which leaves out the non-commercial datasets (TeleGeography's submarine cables, the Bhote Koshi imagery) and refuses a key; docs/LINUX_DIST_RUNBOOK.md Step 6b. Turn the add-on on per instance (godseye: {enabled: true, dir: ./godseye}) — it is off unless asked.

Keys. Nothing is built in. The page is built once with placeholders and the page host fills them at serve time from the runtime's environment: GOOGLE_MAPS_API_KEY (photoreal 3D tiles, place search) and CESIUM_ION_TOKEN (world terrain, Bing imagery) for the browser side, OPENSKY_CLIENT_ID / OPENSKY_CLIENT_SECRET for the aircraft feed, TOMTOM_API_KEY for live traffic flow, OPENAI_API_KEY for the globe's own voice agent (godseye.voice.enabled: true; the page talks to OpenAI Realtime with a short-lived secret the runtime mints, budgeted per day by max_sessions_per_day) — names changeable under godseye.keys / godseye.feeds / godseye.voice. Put the values in an env file the unit reads (EnvironmentFile=), never in a project file; the status route says per key whether it was injected, never the value.

See also: docs/features/godseye-bridge.md (the contract), the godseye section of the IDE's Console.