interplane.Get Omega
Read in your language

interplane-mv

INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.

Brought by drakestapleton

branch main Branches Tags History

interplane-mv / docs / external / nightdriver / 666 / harness / host / ndhost_modern.cpp

69 lines · 2222 bytes Raw Blame History
1// Host driver: runs the real SocketServer::Run() on Linux loopback. Written for this harness.
2// Every line on stdout is machine-parsed by the Rust harness:
3// LOG <tag> <text> firmware debug output
4// PKT cmd=<u> len=<n> fnv=<hex> a packet handed to ProcessIncomingData
5#include "globals.h"
6#include "socketserver.h"
7#include "values.h"
8#include "systemcontainer.h"
9#include "nd_network.h"
10#include <cstdlib>
11#include <fcntl.h>
12#include <cstring>
13#include <thread>
14
15int g_debugLevel = 1;
16HostValues g_Values;
17HostSystem g_hostSystem;
18HostSystem* g_ptrSystem = &g_hostSystem;
19std::mutex g_buffer_mutex;
20
21void host_log(int level, const char* tag, const char* fmt, ...)
22{
23 if (level > g_debugLevel) return;
24 char buf[512];
25 va_list ap; va_start(ap, fmt); vsnprintf(buf, sizeof buf, fmt, ap); va_end(ap);
26 size_t n = strlen(buf); while (n && (buf[n-1] == '\n')) buf[--n] = 0;
27 printf("LOG %s %s\n", tag, buf);
28}
29
30namespace nd_network {
31bool IsWiFiConnected() { return true; }
32void SetSocketBlockingEnabled(int fd, bool blocking)
33{
34 int fl = fcntl(fd, F_GETFL, 0);
35 fcntl(fd, F_SETFL, blocking ? (fl & ~O_NONBLOCK) : (fl | O_NONBLOCK));
36}
37int GetWiFiRSSI() { return -50; }
38}
39
40extern "C" {
41void uzlib_uncompress_init(struct uzlib_uncomp*, void*, unsigned) {}
42int uzlib_zlib_parse_header(struct uzlib_uncomp*) { return -1; } // compressed path not exercised
43int uzlib_uncompress_chksum(struct uzlib_uncomp*) { return -1; }
44}
45
46bool ProcessIncomingData(allocated_unique_ptr<uint8_t[]>& p, size_t len)
47{
48 uint32_t h = 2166136261u;
49 for (size_t i = 0; i < len; i++) { h ^= p[i]; h *= 16777619u; }
50 uint16_t cmd = p[0] | (p[1] << 8);
51 printf("PKT cmd=%u len=%zu fnv=%08x\n", cmd, len, h);
52 return true;
53}
54
55struct HostServer : SocketServer
56{
57 using SocketServer::SocketServer;
58 using SocketServer::Run;
59};
60
61int main(int argc, char** argv)
62{
63 if (argc < 2) { fprintf(stderr, "usage: ndhost <port> [debug-level]\n"); return 2; }
64 if (argc > 2) g_debugLevel = atoi(argv[2]);
65 setvbuf(stdout, nullptr, _IOLBF, 0);
66 HostServer s(atoi(argv[1]), NUM_LEDS);
67 s.Run(); // the real accept/read/dispatch loop; runs until the harness kills this process
68 return 0;
69}