STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
anonymous_namespace{ota_service_main.cpp} Namespace Reference

OTA Service — Ethernet firmware flash for DiabloAvionics ESP32-S3 boards. More...

Functions

void signalHandler (int)
std::string trim (const std::string &s)
bool flashFirmware (const std::string &ip, const std::string &bin_path, std::string &error)
std::string readFirstPioEnv (const std::string &iniPath)
void sanitizeOneLine (std::string &s)
bool runPioBuild (const std::string &projectDir, int boardId, std::string &buildLog, std::string &error)
 Run pio in projectDir; capture combined stdout/stderr into buildLog.
bool buildAndFlash (const std::string &ip, const std::string &projectDir, int boardId, std::string &error, std::string &buildOutput)
void handleClient (int client_fd)

Variables

std::atomic< bool > g_running {true}
static constexpr uint16_t OTA_PORT = 3232
std::string g_bind_address = "0.0.0.0"
static constexpr size_t CHUNK_SIZE = 4096
static constexpr int CONNECT_TIMEOUT_S = 5
static constexpr int TRANSFER_TIMEOUT_S = 60

Detailed Description

OTA Service — Ethernet firmware flash for DiabloAvionics ESP32-S3 boards.

Listens on TCP port 9997 for commands: OTA_FLASH:<board_ip>:<firmware_path> — flash existing .bin to board:3232 OTA_BUILD_FLASH|board_ip|abs_project_dir|board_id — run pio run in abs_project_dir (board_id 1–254 sets PLATFORMIO_BUILD_FLAGS=-DTEMP_HARDCODE_BOARD_ID=N; 0 = no flag), then flash .pio/build/<env>/firmware.bin

Replies: "OK\n" or "ERR:<reason>\n"

Protocol (matches ota-flash.ts):

  1. TCP connect to board_ip:3232
  2. Send 4-byte firmware size (big-endian)
  3. Send .bin in 4 KB chunks
  4. Read "OK" in response before board reboots

Usage: ./ota_service [–port PORT]

Function Documentation

◆ buildAndFlash()

bool anonymous_namespace{ota_service_main.cpp}::buildAndFlash ( const std::string & ip,
const std::string & projectDir,
int boardId,
std::string & error,
std::string & buildOutput )

Definition at line 272 of file ota_service_main.cpp.

References flashFirmware(), readFirstPioEnv(), runPioBuild(), and sanitizeOneLine().

Referenced by handleClient().

◆ flashFirmware()

bool anonymous_namespace{ota_service_main.cpp}::flashFirmware ( const std::string & ip,
const std::string & bin_path,
std::string & error )

◆ handleClient()

void anonymous_namespace{ota_service_main.cpp}::handleClient ( int client_fd)

Definition at line 300 of file ota_service_main.cpp.

References buildAndFlash(), flashFirmware(), g_running, sanitizeOneLine(), send(), token, and trim().

Referenced by main().

◆ readFirstPioEnv()

std::string anonymous_namespace{ota_service_main.cpp}::readFirstPioEnv ( const std::string & iniPath)

Definition at line 177 of file ota_service_main.cpp.

References end(), and trim().

Referenced by buildAndFlash().

◆ runPioBuild()

bool anonymous_namespace{ota_service_main.cpp}::runPioBuild ( const std::string & projectDir,
int boardId,
std::string & buildLog,
std::string & error )

Run pio in projectDir; capture combined stdout/stderr into buildLog.

Definition at line 202 of file ota_service_main.cpp.

References _exit(), check(), read(), and sanitizeOneLine().

Referenced by buildAndFlash().

◆ sanitizeOneLine()

void anonymous_namespace{ota_service_main.cpp}::sanitizeOneLine ( std::string & s)

Definition at line 192 of file ota_service_main.cpp.

Referenced by buildAndFlash(), handleClient(), and runPioBuild().

◆ signalHandler()

void anonymous_namespace{ota_service_main.cpp}::signalHandler ( int )

Definition at line 45 of file ota_service_main.cpp.

References g_running.

◆ trim()

std::string anonymous_namespace{ota_service_main.cpp}::trim ( const std::string & s)

Definition at line 50 of file ota_service_main.cpp.

References a, and b.

Referenced by flashFirmware(), handleClient(), and readFirstPioEnv().

Variable Documentation

◆ CHUNK_SIZE

size_t anonymous_namespace{ota_service_main.cpp}::CHUNK_SIZE = 4096
staticconstexpr

Definition at line 63 of file ota_service_main.cpp.

Referenced by flashFirmware().

◆ CONNECT_TIMEOUT_S

int anonymous_namespace{ota_service_main.cpp}::CONNECT_TIMEOUT_S = 5
staticconstexpr

Definition at line 64 of file ota_service_main.cpp.

Referenced by flashFirmware().

◆ g_bind_address

std::string anonymous_namespace{ota_service_main.cpp}::g_bind_address = "0.0.0.0"

Definition at line 62 of file ota_service_main.cpp.

Referenced by flashFirmware(), and main().

◆ g_running

std::atomic<bool> anonymous_namespace{ota_service_main.cpp}::g_running {true}

Definition at line 43 of file ota_service_main.cpp.

Referenced by handleClient(), and signalHandler().

◆ OTA_PORT

uint16_t anonymous_namespace{ota_service_main.cpp}::OTA_PORT = 3232
staticconstexpr

Definition at line 58 of file ota_service_main.cpp.

Referenced by flashFirmware().

◆ TRANSFER_TIMEOUT_S

int anonymous_namespace{ota_service_main.cpp}::TRANSFER_TIMEOUT_S = 60
staticconstexpr

Definition at line 65 of file ota_service_main.cpp.

Referenced by flashFirmware().