#pragma once #include // Build an ESP32 UART config constant from individual parameters. // Shared by MacroEngine (for rs232 node execution) and SerialProtocol // (for the host-side RS232 terminal pass-through). inline uint32_t computeRS232Config(int dataBits, const char* parity, const char* stopBits) { bool twoStop = (strcmp(stopBits, "2") == 0 || strcmp(stopBits, "1.5") == 0); if (dataBits == 5) { if (strcmp(parity, "even") == 0) return twoStop ? SERIAL_5E2 : SERIAL_5E1; if (strcmp(parity, "odd") == 0) return twoStop ? SERIAL_5O2 : SERIAL_5O1; return twoStop ? SERIAL_5N2 : SERIAL_5N1; } else if (dataBits == 6) { if (strcmp(parity, "even") == 0) return twoStop ? SERIAL_6E2 : SERIAL_6E1; if (strcmp(parity, "odd") == 0) return twoStop ? SERIAL_6O2 : SERIAL_6O1; return twoStop ? SERIAL_6N2 : SERIAL_6N1; } else if (dataBits == 7) { if (strcmp(parity, "even") == 0) return twoStop ? SERIAL_7E2 : SERIAL_7E1; if (strcmp(parity, "odd") == 0) return twoStop ? SERIAL_7O2 : SERIAL_7O1; return twoStop ? SERIAL_7N2 : SERIAL_7N1; } else { // default to 8 data bits if (strcmp(parity, "even") == 0) return twoStop ? SERIAL_8E2 : SERIAL_8E1; if (strcmp(parity, "odd") == 0) return twoStop ? SERIAL_8O2 : SERIAL_8O1; return twoStop ? SERIAL_8N2 : SERIAL_8N1; } }