Files
Jakub 8f4c92a217 feat(sim): add variants/sim/ — real companion_radio firmware on native + Emscripten
New board variant compiling the unmodified MyMesh/UITask/DataStore app
logic against real mesh::Radio/MainBoard/RTCClock/RNG interfaces, for
running the actual firmware outside embedded hardware:

- Native (plain g++, platform = native): ASCII-art display over stdout,
  stdin-driven input, local-disk-backed DataStore/IdentityStore.
- Emscripten/WASM (variants/sim/build_wasm.sh, since PlatformIO's native
  platform force-overrides any CC/CXX toolchain override back to system
  clang++): canvas-backed display, IDBFS-backed persistence across page
  reloads, JS-callable input via sim_enqueue_key(), emscripten_set_main_loop.

Real rweather/Crypto (AES128/SHA256/Ed25519) vendored unmodified and
proven working on both targets. variants/sim/web/index.html is a bare
verification harness, not the polished website embed.
2026-09-03 00:46:47 +02:00

36 lines
1.3 KiB
C++

#pragma once
// Minimal native stand-in for densaugeo/base64's base64.hpp. Real board envs
// pull in the whole library via lib_deps; src/helpers/BaseChatMesh.cpp
// (built for every board, including the sim, whenever MAX_GROUP_CHANNELS is
// defined) only ever calls decode_base64() -- to decode a channel's
// user-supplied PSK -- so that's the only function reproduced here, as a
// plain standard base64 decoder (skips '=' padding/whitespace/invalid chars
// rather than erroring, same permissive behaviour the real library has).
static inline int _sim_b64_val(unsigned char c) {
if (c >= 'A' && c <= 'Z') return c - 'A';
if (c >= 'a' && c <= 'z') return c - 'a' + 26;
if (c >= '0' && c <= '9') return c - '0' + 52;
if (c == '+') return 62;
if (c == '/') return 63;
return -1;
}
inline unsigned int decode_base64(const unsigned char input[], unsigned int inputLength, unsigned char output[]) {
unsigned int out_len = 0;
int val = 0, bits = -8;
for (unsigned int i = 0; i < inputLength; i++) {
unsigned char c = input[i];
if (c == '=') break;
int v = _sim_b64_val(c);
if (v < 0) continue; // skip whitespace/invalid characters
val = (val << 6) + v;
bits += 6;
if (bits >= 0) {
output[out_len++] = (unsigned char)((val >> bits) & 0xFF);
bits -= 8;
}
}
return out_len;
}