STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
main.cpp File Reference
#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"
Include dependency graph for main.cpp:

Go to the source code of this file.

Macros

#define BOARD_ID   61
 ProtoEncoder Hotfire — dual AS5600 encoder board.

Enumerations

enum class  State : uint8_t { Setup = 1 , SelfTest = 10 , Active = 2 }

Functions

static bool i2cReadBytes (TwoWire &bus, uint8_t reg, uint8_t *buf, uint8_t len)
static uint16_t readRawAngle (TwoWire &bus)
static bool checkMagnetPresence (TwoWire &bus, const char *label)
static bool testEncoderComms (TwoWire &bus)
static void runSelfTest ()
static void sendDataChunks ()
static daq::BoardState currentBoardState ()
static void sendHeartbeat ()
void setup ()
void loop ()

Variables

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

Macro Definition Documentation

◆ BOARD_ID

#define BOARD_ID   61

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.

Enumeration Type Documentation

◆ State

enum class State : uint8_t
strong
Enumerator
Setup 
SelfTest 
Active 

Definition at line 72 of file main.cpp.

Function Documentation

◆ checkMagnetPresence()

bool checkMagnetPresence ( TwoWire & bus,
const char * label )
static

Definition at line 116 of file main.cpp.

References delay(), i2cReadBytes(), millis(), REG_STATUS, Serial, start(), STATUS_MD, STATUS_MH, and STATUS_ML.

◆ currentBoardState()

daq::BoardState currentBoardState ( )
static

Definition at line 228 of file main.cpp.

References daq::ACTIVE, Active, boardState, daq::SELF_TEST, SelfTest, daq::SETUP, and Setup.

Referenced by sendHeartbeat().

◆ i2cReadBytes()

bool i2cReadBytes ( TwoWire & bus,
uint8_t reg,
uint8_t * buf,
uint8_t len )
static

Definition at line 96 of file main.cpp.

References AS5600_ADDR, and reg.

◆ loop()

◆ readRawAngle()

uint16_t readRawAngle ( TwoWire & bus)
static

Definition at line 109 of file main.cpp.

References i2cReadBytes(), READ_ERROR, and REG_RAW_MSB.

◆ runSelfTest()

void runSelfTest ( )
static

◆ sendDataChunks()

void sendDataChunks ( )
static

◆ sendHeartbeat()

◆ setup()

◆ testEncoderComms()

bool testEncoderComms ( TwoWire & bus)
static

Definition at line 162 of file main.cpp.

References i2cReadBytes(), and REG_STATUS.

Referenced by runSelfTest().

Variable Documentation

◆ AS5600_ADDR

uint8_t AS5600_ADDR = 0x36
staticconstexpr

Definition at line 50 of file main.cpp.

◆ boardState

State boardState = State::Setup
static

Definition at line 73 of file main.cpp.

Referenced by currentBoardState(), loop(), provideAbortData(), runSelfTest(), and sendHeartbeat().

◆ dataChunks

std::vector<daq::SensorDataChunkCollection> dataChunks
static

Definition at line 89 of file main.cpp.

◆ dns_addr

IPAddress dns_addr(192, 168, 2, 1) ( 192 ,
168 ,
2 ,
1  )
static

Referenced by setup().

◆ ENC1_SCL

int ENC1_SCL = 5
staticconstexpr

Definition at line 35 of file main.cpp.

Referenced by setup().

◆ ENC1_SDA

int ENC1_SDA = 4
staticconstexpr

Definition at line 34 of file main.cpp.

Referenced by setup().

◆ ENC2_SCL

int ENC2_SCL = 7
staticconstexpr

Definition at line 39 of file main.cpp.

Referenced by setup().

◆ ENC2_SDA

int ENC2_SDA = 15
staticconstexpr

Definition at line 38 of file main.cpp.

Referenced by setup().

◆ ENCODER_PACKET_BUF_SIZE

int ENCODER_PACKET_BUF_SIZE = 512
staticconstexpr

Definition at line 66 of file main.cpp.

Referenced by runSelfTest(), sendDataChunks(), and sendHeartbeat().

◆ ETH_CS

int ETH_CS = 10
staticconstexpr

Definition at line 45 of file main.cpp.

◆ ETH_MISO

int ETH_MISO = 13
staticconstexpr

Definition at line 43 of file main.cpp.

◆ ETH_MOSI

int ETH_MOSI = 11
staticconstexpr

Definition at line 42 of file main.cpp.

◆ ETH_SCLK

int ETH_SCLK = 12
staticconstexpr

Definition at line 44 of file main.cpp.

◆ gateway

IPAddress gateway(0, 0, 0, 0) ( 0 ,
0 ,
0 ,
0  )
static

◆ lastHeartbeatMs

unsigned long lastHeartbeatMs = 0
static

Definition at line 90 of file main.cpp.

Referenced by loop().

◆ mac

byte mac[6]
static

Definition at line 78 of file main.cpp.

◆ NUM_SENSORS

uint8_t NUM_SENSORS = 2
staticconstexpr

Definition at line 61 of file main.cpp.

◆ otaServer

◆ READ_ERROR

uint16_t READ_ERROR = 0xFFFF
staticconstexpr

Definition at line 56 of file main.cpp.

◆ REG_RAW_MSB

uint8_t REG_RAW_MSB = 0x0C
staticconstexpr

Definition at line 52 of file main.cpp.

◆ REG_STATUS

uint8_t REG_STATUS = 0x0B
staticconstexpr

Definition at line 51 of file main.cpp.

◆ SENSOR_ID_ENC1

uint8_t SENSOR_ID_ENC1 = 1
staticconstexpr

Definition at line 59 of file main.cpp.

Referenced by loop(), and runSelfTest().

◆ SENSOR_ID_ENC2

uint8_t SENSOR_ID_ENC2 = 2
staticconstexpr

Definition at line 60 of file main.cpp.

Referenced by loop(), and runSelfTest().

◆ serverIP

IPAddress serverIP(192, 168, 2, HOTFIRE_SERVER_IP_OCTET_4) ( 192 ,
168 ,
2 ,
HOTFIRE_SERVER_IP_OCTET_4  )
static

◆ serverPort

int serverPort = HOTFIRE_SERVER_PORT
staticconstexpr

Definition at line 84 of file main.cpp.

◆ staticIP

IPAddress staticIP
static

Definition at line 79 of file main.cpp.

◆ STATUS_MD

uint8_t STATUS_MD = 0x20
staticconstexpr

Definition at line 55 of file main.cpp.

◆ STATUS_MH

uint8_t STATUS_MH = 0x08
staticconstexpr

Definition at line 53 of file main.cpp.

◆ STATUS_ML

uint8_t STATUS_ML = 0x10
staticconstexpr

Definition at line 54 of file main.cpp.

◆ subnet

IPAddress subnet(255, 255, 255, 0) ( 255 ,
255 ,
255 ,
0  )
static

◆ udp

EthernetUDP udp
static

Definition at line 86 of file main.cpp.

◆ UDP_LISTEN_PORT

int UDP_LISTEN_PORT = 5005
staticconstexpr

Definition at line 67 of file main.cpp.

Referenced by setup().