22#include "actuator_config.h"
23#include "firmware_hash.h"
120 const unsigned long now =
millis();
193 daq::BoardHeartbeatPacket hb;
215 if (loc.ip_address == ip)
222 return IPAddress((ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF,
230 daq::PacketHeader& header_out) {
231 if (buffer_size <
sizeof(daq::PacketHeader))
233 memcpy(&header_out, buffer,
sizeof(daq::PacketHeader));
248 const std::vector<daq::ActuatorCommand>&
commands);
253 daq::PacketHeader hdr;
257 switch (hdr.packet_type) {
259 daq::PacketHeader dummy;
260 daq::ServerHeartbeatPacket data;
268 daq::PacketHeader dummy;
269 uint8_t is_controller = 0;
270 std::vector<daq::AbortActuatorLocation> act_locs;
271 std::vector<daq::AbortPTLocation> pt_locs;
272 uint8_t enable_serial_printing = 0;
274 buffer, len, dummy, is_controller, act_locs, pt_locs,
275 enable_serial_printing)) {
276 (void)enable_serial_printing;
296 uint32_t rip =
static_cast<uint32_t
>(remoteIP);
303 daq::PacketHeader cmd_header;
304 std::vector<daq::ActuatorCommand>
commands;
319 const std::vector<daq::ActuatorCommand>&
commands) {
326 uint8_t new_state = (cmd.actuator_state != 0) ? 1 : 0;
327 uint8_t idx = cmd.actuator_id - 1;
345 float voltage = (
static_cast<float>(adcValue) / 4095.0f) * 3.3f;
346 uint32_t voltage_bits;
347 memcpy(&voltage_bits, &voltage,
sizeof(
float));
348 chunk.add_datapoint(i, voltage_bits);
354 std::vector<daq::SensorDataChunkCollection>
chunks;
373 unsigned long now =
millis();
384 size_t buffer_size) {
385 if (buffer_size <
sizeof(daq::PacketHeader))
387 daq::PacketHeader header;
390 header.timestamp =
millis();
391 memcpy(buffer, &header,
sizeof(header));
392 return sizeof(header);
548 Serial.println(
"Initializing actuators...");
557 Serial.println(
"All actuators initialized to OFF state");
573 Serial.println(
"Actuator Hotfire (controller) starting...");
575 if (SPIFFS.begin(
false)) {
577 if (f && f.available() >= 1) {
579 if (f.read(&
b, 1) == 1) {
582 Serial.print(
"Board ID and IP from SPIFFS: ");
584 Serial.print(
" / 192.168.2.");
585 Serial.println(
static_cast<unsigned>(
b));
601 ESP_ERROR_CHECK(esp_read_mac(
mac, ESP_MAC_ETH));
611 Serial.print(
"Ethernet initialized. IP: ");
618 Serial.println(
"Setup complete. State: WaitingForServer");
624 int packetSize =
udp.parsePacket();
625 if (packetSize > 0) {
666 unsigned long now =
millis();
void digitalWrite(int, int)
#define NO_CONNECTION_ABORT_DONE_MS
#define NO_CONN_ABORT_PT_WAIT_MS
#define ETHERNET_INIT_DELAY_MS
#define CONNECTION_LOSS_GRACE_MS
#define STANDALONE_ABORT_PT_LOSS_MS
#define SPIFFS_BOARD_VALUE_PATH
#define ETHERNET_BEGIN_DELAY_MS
#define HEARTBEAT_TIMEOUT_MS
#define ADC_READ_INTERVAL_MS
#define BOARD_HEARTBEAT_INTERVAL_MS
#define ETHERNET_SPI_DELAY_MS
static EthernetClass Ethernet
#define DIABLO_COMMS_VERSION
std::vector< daq::SensorDataChunkCollection > chunks
static void readCurrentSensePinsAndSend()
static void run_NoPTAbort()
static unsigned long lastHeartbeatMillis
static unsigned long last_adc_read_ms
static void run_WaitingForServer()
static bool no_conn_abort_pt_sent
static unsigned long led_cycle_start_ms
static void run_AbortFinished()
static unsigned long last_server_heartbeat_ms
static unsigned long led_phase_start_ms
static uint8_t led_blink_index
static bool isIPInPTLocations(uint32_t ip)
static void initializeCurrentSensePins()
static bool heartbeatTimedOut()
static void run_NoConnectionAbort()
static bool pt_data_received_during_no_conn_abort_wait
static IncomingPacketKind processIncomingPacket(const uint8_t *buffer, size_t len, IPAddress remoteIP)
static std::vector< daq::AbortPTLocation > abort_pt_locations
static void applyPacketTransition(IncomingPacketKind kind)
static void updateLedNonBlocking()
IPAddress dns(192, 168, 2, 1)
static void sendNoConnectionAbortToAllPTs()
static uint8_t getStateNumber(ActuatorControllerState s)
IPAddress subnet(255, 255, 255, 0)
IPAddress staticIP(192, 168, 2, BOARD_ID_DEFAULT)
static bool is_abort_controller
static void initializeActuators()
static bool readPacketHeader(const uint8_t *buffer, size_t buffer_size, daq::PacketHeader &header_out)
IPAddress serverIP(192, 168, 2, 20)
static uint8_t actuator_states[NUM_ACTUATORS]
static void run_ConnectionLossDetected()
static size_t create_no_connection_abort_packet(uint8_t *buffer, size_t buffer_size)
static void run_StandaloneAbort()
static void sendBoardHeartbeat()
static void run_PTAbort()
static void processActuatorCommands(const std::vector< daq::ActuatorCommand > &commands)
static ActuatorControllerState last_led_state
IPAddress gateway(0, 0, 0, 0)
static ActuatorControllerState state
static void run_StandardAbort()
static void streamSensorDataIfDue()
static IPAddress uint32ToIPAddress(uint32_t ip)
static unsigned long state_enter_ms
static std::vector< daq::AbortActuatorLocation > abort_actuator_locations
static LedPhase led_phase
static daq::BoardState getBoardStateForHeartbeat()
static unsigned long last_pt_data_from_config_ms
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]
static osMessageQueueId_t commands
*brief create JSON pointer *sa reference_tokens const string_t const string_t & b
int getActuatorPin(uint8_t actuator_id)
constexpr int NUM_ACTUATORS
int getCurrentSensePin(uint8_t actuator_id)
constexpr Layout Actuator_Board
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.
@ CONNECTION_LOSS_DETECTED
bool parse_actuator_command_packet(const uint8_t *buffer, size_t buffer_size, PacketHeader &header_out, std::vector< ActuatorCommand > &commands_out)
Parses an Actuator Command packet from buffer.
bool parse_actuator_config_packet(const uint8_t *buffer, size_t buffer_size, PacketHeader &header_out, uint8_t &is_abort_controller_out, std::vector< AbortActuatorLocation > &abort_actuators_out, std::vector< AbortPTLocation > &abort_pts_out, uint8_t &enable_serial_printing_out)
Parses an Actuator Config packet from buffer.
static bool elapsed(uint32_t now, uint32_t then, uint32_t interval)
Represents a single data chunk with timestamp and sensor datapoints.