#include <Arduino.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>
#include <STAR_EthernetOTA.h>
#include <Wire.h>
#include <daq-protocol.h>
#include <esp_mac.h>
#include <cstring>
#include <vector>
#include "firmware_hash.h"
#include "hotfire_config.h"
#include "sense_config.h"
Go to the source code of this file.
|
| #define | BOARD_ID 61 |
| | ProtoEncoder Hotfire — dual AS5600 encoder board.
|
|
| static constexpr int | ENC1_SDA = 4 |
| static constexpr int | ENC1_SCL = 5 |
| static constexpr int | ENC2_SDA = 15 |
| static constexpr int | ENC2_SCL = 7 |
| static constexpr int | ETH_MOSI = 11 |
| static constexpr int | ETH_MISO = 13 |
| static constexpr int | ETH_SCLK = 12 |
| static constexpr int | ETH_CS = 10 |
| static constexpr uint8_t | AS5600_ADDR = 0x36 |
| static constexpr uint8_t | REG_STATUS = 0x0B |
| static constexpr uint8_t | REG_RAW_MSB = 0x0C |
| static constexpr uint8_t | STATUS_MH = 0x08 |
| static constexpr uint8_t | STATUS_ML = 0x10 |
| static constexpr uint8_t | STATUS_MD = 0x20 |
| static constexpr uint16_t | READ_ERROR = 0xFFFF |
| static constexpr uint8_t | SENSOR_ID_ENC1 = 1 |
| static constexpr uint8_t | SENSOR_ID_ENC2 = 2 |
| static constexpr uint8_t | NUM_SENSORS = 2 |
| static constexpr int | ENCODER_PACKET_BUF_SIZE = 512 |
| static constexpr int | UDP_LISTEN_PORT = 5005 |
| static State | boardState = State::Setup |
| static byte | mac [6] |
| static IPAddress | staticIP |
| static IPAddress | gateway (0, 0, 0, 0) |
| static IPAddress | subnet (255, 255, 255, 0) |
| static IPAddress | dns_addr (192, 168, 2, 1) |
| static IPAddress | serverIP (192, 168, 2, HOTFIRE_SERVER_IP_OCTET_4) |
| static constexpr int | serverPort = HOTFIRE_SERVER_PORT |
| static EthernetUDP | udp |
| static StarOTA::Server | otaServer (HOTFIRE_OTA_PORT) |
| static std::vector< daq::SensorDataChunkCollection > | dataChunks |
| static unsigned long | lastHeartbeatMs = 0 |
◆ BOARD_ID
ProtoEncoder Hotfire — dual AS5600 encoder board.
Minimal state machine: Setup -> SelfTest -> Active. In Setup, sends SETUP heartbeats and waits for any SENSOR_CONFIG packet. In SelfTest, probes each encoder over I2C, sends a SELF_TEST packet, then transitions to Active. In Active, streams encoder data continuously.
Definition at line 23 of file main.cpp.
◆ State
| enum class State : uint8_t |
|
strong |
| Enumerator |
|---|
| Setup | |
| SelfTest | |
| Active | |
Definition at line 72 of file main.cpp.
◆ checkMagnetPresence()
| bool checkMagnetPresence |
( |
TwoWire & | bus, |
|
|
const char * | label ) |
|
static |
◆ currentBoardState()
◆ i2cReadBytes()
| bool i2cReadBytes |
( |
TwoWire & | bus, |
|
|
uint8_t | reg, |
|
|
uint8_t * | buf, |
|
|
uint8_t | len ) |
|
static |
◆ loop()
Definition at line 312 of file main.cpp.
References Active, BOARD_HEARTBEAT_INTERVAL_MS, boardState, chunk, dataChunks, delay(), lastHeartbeatMs, LOOP_DELAY_MS, millis(), NUM_SENSORS, otaServer, StarOTA::printTestMessage(), READ_ERROR, readRawAngle(), runSelfTest(), SelfTest, sendDataChunks(), sendHeartbeat(), daq::SENSOR_CONFIG, SENSOR_ID_ENC1, SENSOR_ID_ENC2, SENSOR_MAX_CHUNKS_BEFORE_SEND, Serial, Setup, and udp.
◆ readRawAngle()
| uint16_t readRawAngle |
( |
TwoWire & | bus | ) |
|
|
static |
◆ runSelfTest()
Definition at line 167 of file main.cpp.
References Active, boardState, daq::create_self_test_packet(), ENCODER_PACKET_BUF_SIZE, millis(), SENSOR_ID_ENC1, SENSOR_ID_ENC2, Serial, serverIP, serverPort, testEncoderComms(), and udp.
Referenced by loop().
◆ sendDataChunks()
◆ sendHeartbeat()
Definition at line 241 of file main.cpp.
References BOARD_ID, daq::create_board_heartbeat_packet(), currentBoardState(), ENCODER_PACKET_BUF_SIZE, FirmwareHash::get(), millis(), daq::SAFE, serverIP, serverPort, and udp.
Referenced by abortFinish(), loop(), mainloop(), setup(), and standardAbort().
◆ setup()
Definition at line 263 of file main.cpp.
References BOARD_ID, checkMagnetPresence(), delay(), dns_addr, ENC1_SCL, ENC1_SDA, ENC2_SCL, ENC2_SDA, ETH_CS, ETH_MISO, ETH_MOSI, ETH_SCLK, Ethernet, ETHERNET_BEGIN_DELAY_MS, ETHERNET_INIT_DELAY_MS, ETHERNET_SPI_DELAY_MS, gateway, HOTFIRE_OTA_PORT, IPAddress, mac, otaServer, FirmwareHash::print(), Serial, serverIP, serverPort, staticIP, subnet, udp, and UDP_LISTEN_PORT.
◆ testEncoderComms()
| bool testEncoderComms |
( |
TwoWire & | bus | ) |
|
|
static |
◆ AS5600_ADDR
| uint8_t AS5600_ADDR = 0x36 |
|
staticconstexpr |
◆ boardState
◆ dataChunks
◆ dns_addr
| IPAddress dns_addr(192, 168, 2, 1) |
( |
192 | , |
|
|
168 | , |
|
|
2 | , |
|
|
1 | ) |
|
static |
◆ ENC1_SCL
◆ ENC1_SDA
◆ ENC2_SCL
◆ ENC2_SDA
◆ ENCODER_PACKET_BUF_SIZE
| int ENCODER_PACKET_BUF_SIZE = 512 |
|
staticconstexpr |
◆ ETH_CS
◆ ETH_MISO
◆ ETH_MOSI
◆ ETH_SCLK
◆ gateway
| IPAddress gateway(0, 0, 0, 0) |
( |
0 | , |
|
|
0 | , |
|
|
0 | , |
|
|
0 | ) |
|
static |
◆ lastHeartbeatMs
| unsigned long lastHeartbeatMs = 0 |
|
static |
◆ mac
◆ NUM_SENSORS
◆ otaServer
◆ READ_ERROR
| uint16_t READ_ERROR = 0xFFFF |
|
staticconstexpr |
◆ REG_RAW_MSB
| uint8_t REG_RAW_MSB = 0x0C |
|
staticconstexpr |
◆ REG_STATUS
| uint8_t REG_STATUS = 0x0B |
|
staticconstexpr |
◆ SENSOR_ID_ENC1
| uint8_t SENSOR_ID_ENC1 = 1 |
|
staticconstexpr |
◆ SENSOR_ID_ENC2
| uint8_t SENSOR_ID_ENC2 = 2 |
|
staticconstexpr |
◆ serverIP
◆ serverPort
◆ staticIP
◆ STATUS_MD
◆ STATUS_MH
◆ STATUS_ML
◆ subnet
| IPAddress subnet(255, 255, 255, 0) |
( |
255 | , |
|
|
255 | , |
|
|
255 | , |
|
|
0 | ) |
|
static |
◆ udp
◆ UDP_LISTEN_PORT
| int UDP_LISTEN_PORT = 5005 |
|
staticconstexpr |