22#define PINS_ACTIVE_LAYOUT sense_board_pins::TC_Board
23#include "STAR_ADS126X.h"
33#define FILTER ADS126X_SINC4
34#define DATA_RATE ADS126X_RATE_7200
37#define READINGS_PER_MUX 5
100 return (
static_cast<float>(code) * 2.5f) / 2147483648.0f;
104 for (
int i = 0; i < cycles; i++) {
115 daq::PacketHeader& hdr_out) {
116 if (len <
sizeof(daq::PacketHeader))
118 memcpy(&hdr_out, buffer,
sizeof(daq::PacketHeader));
130 daq::PacketHeader hdr;
134 switch (hdr.packet_type) {
136 daq::PacketHeader dummy;
137 daq::ServerHeartbeatPacket data;
153 (
static_cast<uint32_t
>(buffer[7]) << 24) |
154 (
static_cast<uint32_t
>(buffer[8]) << 16) |
155 (
static_cast<uint32_t
>(buffer[9]) << 8) |
156 static_cast<uint32_t
>(buffer[10]);
165 if (len >=
sizeof(daq::PacketHeader))
180 daq::BoardHeartbeatPacket hb;
181 memset(hb.firmware_hash, 0,
sizeof(hb.firmware_hash));
184 hb.board_state = board_state;
191 udp.beginPacket(dest_ip, dest_port);
208 udp.beginPacket(dest_ip, dest_port);
219 for (
int i = 0; i <
count; i++) {
222 const auto reading =
ads126x.readADC1();
223 if (!reading.checksumValid)
225 chunk.add_datapoint(
sensorId,
static_cast<uint32_t
>(reading.value));
288 Serial.println(
"TC Hotfire state machine starting...");
290 bool spiffs_ok =
false;
293 if (SPIFFS.begin(
false)) {
295 if (f && f.available() >= 1) {
297 if (f.read(&
b, 1) == 1) {
301 Serial.print(
"Board ID and IP from SPIFFS: ");
303 Serial.print(
" / 192.168.2.");
304 Serial.println(
static_cast<unsigned>(
b));
313 "SPIFFS read skipped or failed, using default board ID 1 / "
332 ESP_ERROR_CHECK(esp_read_mac(
mac, ESP_MAC_ETH));
342 Serial.print(
"Ethernet IP: ");
344 Serial.println(
"Setup complete. State: WaitingForServer (TC Board)");
351 int packetSize =
udp.parsePacket();
352 if (packetSize > 0) {
354 int remotePort =
udp.remotePort();
387 unsigned long now =
millis();
void delayMicroseconds(unsigned int)
#define ETHERNET_INIT_DELAY_MS
#define SPIFFS_BOARD_VALUE_PATH
#define ETHERNET_BEGIN_DELAY_MS
#define BOARD_HEARTBEAT_INTERVAL_MS
#define ETHERNET_SPI_DELAY_MS
static EthernetClass Ethernet
#define ADS126X_REF_POS_VDD
#define ADS126X_REF_NEG_VSS
static StoredConfig stored_config
constexpr uint8_t settlePulses(uint8_t filter, uint8_t data_rate, bool chop_enabled=false, bool idac_rotation_enabled=false)
std::vector< daq::SensorDataChunkCollection > dataChunks
static unsigned long lastHeartbeatMillis
IPAddress dns(192, 168, 2, 1)
IPAddress subnet(255, 255, 255, 0)
IPAddress staticIP(192, 168, 2, BOARD_ID_DEFAULT)
IPAddress serverIP(192, 168, 2, 20)
static void sendBoardHeartbeat()
IPAddress gateway(0, 0, 0, 0)
static ActuatorControllerState state
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]
static void read_data(int count)
static void run_WaitingForServer()
static uint8_t currentConnector
static void sendSensorDataPacketTo(IPAddress dest_ip, int dest_port)
static void applyPacketTransition(IncomingPacketKind kind)
IPAddress dns(192, 168, 2, 1)
IPAddress subnet(255, 255, 255, 0)
IPAddress staticIP(192, 168, 2, BOARD_ID_DEFAULT)
IPAddress serverIP(192, 168, 2, 20)
const int serverPortDefault
static void flush_cycles(int cycles)
static float convert_code_to_voltage(int32_t code)
static bool readPacketHeader(const uint8_t *buffer, size_t len, daq::PacketHeader &hdr_out)
static void run_StandaloneAbort()
static IncomingPacketKind processIncomingPacket(const uint8_t *buffer, size_t len, IPAddress remote_ip, int remote_port)
IPAddress gateway(0, 0, 0, 0)
*brief create JSON pointer *sa reference_tokens const string_t const string_t & b
size_type count(const key_type &key) const
size_t create_sensor_data_packet(const std::vector< SensorDataChunkCollection > &chunks, const uint8_t num_sensors, uint32_t timestamp_ms, uint8_t *buffer, size_t buffer_size)
Creates a complete Sensor Data packet in the provided buffer.
bool parse_server_heartbeat_packet(const uint8_t *buffer, size_t buffer_size, PacketHeader &header_out, ServerHeartbeatPacket &data_out)
Parses a Server Heartbeat packet from buffer.
size_t create_board_heartbeat_packet(const BoardHeartbeatPacket &data, uint32_t timestamp_ms, uint8_t *buffer, size_t buffer_size)
Creates a complete Board Heartbeat packet in the provided buffer.
BoardState
Defines the operational state of a board.
*brief user defined string literal for JSON values *sa std::size_t n
constexpr int getAdcChannel(uint8_t connector, uint8_t pin)
constexpr const Layout & Pins
uint32_t actuator_controller_ip
Represents a single data chunk with timestamp and sensor datapoints.
static std::string ch(int ain, const std::string &kind, const std::string &extra="", const std::string &board="lj")