big refactoring and features added

This commit is contained in:
Ayzen
2026-04-24 16:51:15 +03:00
parent eafc328caa
commit ea1fbb071d
184 changed files with 35336 additions and 75480 deletions

344
App/Models/app_types.h Normal file
View File

@ -0,0 +1,344 @@
/**
* @file app_types.h
* @brief Shared application-level types, constants, and protocol identifiers.
*
* Architectural note:
* This header owns the firmware vocabulary used by the modular App layer.
* CubeMX-generated headers keep only board-level definitions, while every
* application module includes these types to communicate through explicit
* interfaces instead of ad-hoc globals and scattered macros.
*/
#ifndef APP_TYPES_H
#define APP_TYPES_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
/** @brief Total number of 16-bit words in a telemetry frame, including header. */
#define APP_TELEMETRY_WORD_COUNT 15u
/** @brief Total number of bytes in a telemetry frame. */
#define APP_TELEMETRY_FRAME_BYTES 30u
/** @brief Maximum number of payload words stored by the UART protocol parser. */
#define APP_PROTOCOL_MAX_PAYLOAD_WORDS 15u
/** @brief Maximum packet size handled by the UART protocol parser. */
#define APP_PROTOCOL_MAX_PACKET_BYTES 32u
/** @brief Maximum number of visible characters allowed in a saved profile name. */
#define APP_PROFILE_NAME_MAX_CHARACTERS 16u
/** @brief Maximum profile display-name length, including the terminating NUL. */
#define APP_PROFILE_NAME_LENGTH (APP_PROFILE_NAME_MAX_CHARACTERS + 1u)
/** @brief Maximum stored path length for profile and waveform files. */
#define APP_PROFILE_PATH_LENGTH 96u
/** @brief Future profile list file for SD-card based standalone operation. */
#define APP_STORAGE_PROFILE_INDEX_FILE "profiles.csv"
/** @brief UART header for the host work-configuration packet. */
#define APP_PACKET_HEADER_WORK_CONFIG 0x1111u
/** @brief UART header for the "return to defaults" command. */
#define APP_PACKET_HEADER_DEFAULTS 0x2222u
/** @brief UART header for the "transmit live telemetry" command. */
#define APP_PACKET_HEADER_TX_CURRENT 0x4444u
/** @brief UART header for the "query state" command. */
#define APP_PACKET_HEADER_QUERY_STATE 0x6666u
/** @brief UART header for profile-save control packets. */
#define APP_PACKET_HEADER_PROFILE_SAVE_CONTROL 0x7777u
/** @brief UART header for the AD9102 control packet. */
#define APP_PACKET_HEADER_AD9102_CONTROL 0x8888u
/** @brief UART header for the AD9833 control packet. */
#define APP_PACKET_HEADER_AD9833_CONTROL 0x9999u
/** @brief UART header for the DS1809 control packet. */
#define APP_PACKET_HEADER_DS1809_CONTROL 0xAAAAu
/** @brief UART header for the STM32 internal DAC control packet. */
#define APP_PACKET_HEADER_STM32_DAC_CONTROL 0xBBBBu
/** @brief UART header for the AD9102 waveform upload control packet. */
#define APP_PACKET_HEADER_AD9102_WAVE_CONTROL 0xCCCCu
/** @brief UART header for the AD9102 waveform upload data packet. */
#define APP_PACKET_HEADER_AD9102_WAVE_DATA 0xDDDDu
/** @brief UART header for profile-save data packets. */
#define APP_PACKET_HEADER_PROFILE_SAVE_DATA 0xEEEEu
/** @brief Packet size of the host work-configuration message, in bytes. */
#define APP_PACKET_BYTES_WORK_CONFIG 30u
/** @brief Packet size of short control messages, in bytes. */
#define APP_PACKET_BYTES_SHORT_CONTROL 10u
/** @brief Packet size of AD9102 waveform-data messages, in bytes. */
#define APP_PACKET_BYTES_AD9102_WAVE_DATA 30u
/** @brief Packet size of profile-save control messages, in bytes. */
#define APP_PACKET_BYTES_PROFILE_SAVE_CONTROL 30u
/** @brief Packet size of profile-save data messages, in bytes. */
#define APP_PACKET_BYTES_PROFILE_SAVE_DATA 30u
/** @brief Number of payload words carried by the host work packet. */
#define APP_PACKET_WORDS_WORK_CONFIG 14u
/** @brief Number of payload words carried by short control packets. */
#define APP_PACKET_WORDS_SHORT_CONTROL 4u
/** @brief Number of payload words carried by AD9102 waveform-data packets. */
#define APP_PACKET_WORDS_AD9102_WAVE_DATA 14u
/** @brief Number of payload words carried by profile-save control packets. */
#define APP_PACKET_WORDS_PROFILE_SAVE_CONTROL 14u
/** @brief Number of payload words carried by profile-save data packets. */
#define APP_PACKET_WORDS_PROFILE_SAVE_DATA 14u
/** @brief First status byte flag for SD-card related errors. */
#define APP_STATUS_FLAG_SD_ERROR 0x01u
/** @brief First status byte flag for UART framing/header errors. */
#define APP_STATUS_FLAG_UART_ERROR 0x02u
/** @brief First status byte flag for checksum or payload validation errors. */
#define APP_STATUS_FLAG_UART_DECODE_ERROR 0x04u
/** @brief First status byte flag for TEC1-related runtime errors. */
#define APP_STATUS_FLAG_TEC1_ERROR 0x08u
/** @brief First status byte flag for TEC2-related runtime errors. */
#define APP_STATUS_FLAG_TEC2_ERROR 0x10u
/** @brief First status byte flag for default/reset handling errors. */
#define APP_STATUS_FLAG_DEFAULT_ERROR 0x20u
/** @brief First status byte flag for AD9102 configuration/upload errors. */
#define APP_STATUS_FLAG_AD9102_ERROR 0x80u
/** @brief AD9102 control flag: enable or disable output. */
#define APP_AD9102_FLAG_ENABLE 0x0001u
/** @brief AD9102 control flag: select triangle instead of saw ramp. */
#define APP_AD9102_FLAG_TRIANGLE 0x0002u
/** @brief AD9102 control flag: use SRAM-backed waveform path. */
#define APP_AD9102_FLAG_SRAM 0x0004u
/** @brief AD9102 control flag: use amplitude/sample-count short format. */
#define APP_AD9102_FLAG_SRAM_FORMAT_ALT 0x0008u
/** @brief AD9833 control flag: enable or disable output. */
#define APP_AD9833_FLAG_ENABLE 0x0001u
/** @brief AD9833 control flag: select triangle mode. */
#define APP_AD9833_FLAG_TRIANGLE 0x0002u
/** @brief DS1809 control flag: pulse the "up" control line. */
#define APP_DS1809_FLAG_INCREMENT 0x0001u
/** @brief DS1809 control flag: pulse the "down" control line. */
#define APP_DS1809_FLAG_DECREMENT 0x0002u
/** @brief STM32 DAC control flag: enable output buffer/channel. */
#define APP_STM32_DAC_FLAG_ENABLE 0x0001u
/** @brief Op-code used to begin a custom AD9102 waveform upload. */
#define APP_AD9102_WAVE_OPCODE_BEGIN 0x0001u
/** @brief Op-code used to commit a custom AD9102 waveform upload. */
#define APP_AD9102_WAVE_OPCODE_COMMIT 0x0002u
/** @brief Op-code used to cancel a custom AD9102 waveform upload. */
#define APP_AD9102_WAVE_OPCODE_CANCEL 0x0003u
/** @brief Op-code used to begin a streamed profile-save session. */
#define APP_PROFILE_SAVE_OPCODE_BEGIN 0x0001u
/** @brief Op-code used to commit a streamed profile-save session. */
#define APP_PROFILE_SAVE_OPCODE_COMMIT 0x0002u
/** @brief Op-code used to cancel a streamed profile-save session. */
#define APP_PROFILE_SAVE_OPCODE_CANCEL 0x0003u
/** @brief Section id used for profile INI text chunks during profile save. */
#define APP_PROFILE_SAVE_SECTION_PROFILE_TEXT 0x0001u
/** @brief Section id used for optional waveform CSV chunks during profile save. */
#define APP_PROFILE_SAVE_SECTION_WAVEFORM_TEXT 0x0002u
/** @brief Maximum number of raw data bytes carried by one profile-save data packet. */
#define APP_PROFILE_SAVE_MAX_DATA_BYTES_PER_PACKET 22u
/**
* @brief High-level runtime modes executed by the application core.
*/
typedef enum app_mode_t {
APP_MODE_IDLE = 0,
APP_MODE_WORK,
APP_MODE_TX_CURRENT,
APP_MODE_ERROR
} app_mode_t;
/**
* @brief Deferred application events injected by future UI/GPIO frontends.
*/
typedef enum app_event_t {
APP_EVENT_NONE = 0,
APP_EVENT_PROFILE_NEXT
} app_event_t;
/**
* @brief Internal transmission slots queued by the application core.
*/
typedef enum app_tx_request_t {
APP_TX_REQUEST_NONE = 0,
APP_TX_REQUEST_STATUS,
APP_TX_REQUEST_CURRENT_FRAME
} app_tx_request_t;
/**
* @brief Packet kinds emitted by the UART protocol parser.
*/
typedef enum app_packet_kind_t {
APP_PACKET_KIND_NONE = 0,
APP_PACKET_KIND_WORK_CONFIG,
APP_PACKET_KIND_DEFAULTS,
APP_PACKET_KIND_TX_CURRENT,
APP_PACKET_KIND_QUERY_STATE,
APP_PACKET_KIND_PROFILE_SAVE_CONTROL,
APP_PACKET_KIND_AD9102_CONTROL,
APP_PACKET_KIND_AD9833_CONTROL,
APP_PACKET_KIND_DS1809_CONTROL,
APP_PACKET_KIND_STM32_DAC_CONTROL,
APP_PACKET_KIND_AD9102_WAVE_CONTROL,
APP_PACKET_KIND_AD9102_WAVE_DATA,
APP_PACKET_KIND_PROFILE_SAVE_DATA
} app_packet_kind_t;
/**
* @brief User-visible signal-generation mode for the AD9102 path.
*/
typedef enum waveform_mode_t {
WAVEFORM_MODE_SAW = 0,
WAVEFORM_MODE_SRAM_GENERATED,
WAVEFORM_MODE_SRAM_CUSTOM
} waveform_mode_t;
/**
* @brief Packed enable flags and misc runtime settings for the board.
*/
typedef struct work_config_t {
uint8_t work_enabled;
uint8_t supply_5v1_enabled;
uint8_t supply_5v2_enabled;
uint8_t laser1_enabled;
uint8_t laser2_enabled;
uint8_t reference1_enabled;
uint8_t reference2_enabled;
uint8_t tec1_enabled;
uint8_t tec2_enabled;
uint8_t temp_sensor1_enabled;
uint8_t temp_sensor2_enabled;
uint8_t pid1_from_host;
uint8_t pid2_from_host;
uint16_t averages;
uint16_t message_id;
} work_config_t;
/**
* @brief Runtime configuration of one laser channel.
*/
typedef struct laser_channel_config_t {
uint16_t target_temperature_raw;
float pid_p;
float pid_i;
uint16_t current_raw;
} laser_channel_config_t;
/**
* @brief Mutable per-channel runtime state derived from sensor feedback.
*/
typedef struct laser_runtime_t {
uint16_t current_temperature_raw;
float integral_error;
uint16_t power_raw;
} laser_runtime_t;
/**
* @brief Normalised configuration for AD9102 waveform control.
*/
typedef struct waveform_config_t {
waveform_mode_t mode;
uint8_t enabled;
uint8_t triangle;
uint8_t saw_step;
uint8_t pat_period_base;
uint16_t pat_period;
uint16_t sample_count;
uint8_t hold_cycles;
uint16_t amplitude;
char source_path[APP_PROFILE_PATH_LENGTH];
} waveform_config_t;
/**
* @brief AD9833 generator configuration mirrored from the serial-control path.
*/
typedef struct ad9833_config_t {
uint8_t enabled;
uint8_t triangle;
uint32_t frequency_word;
} ad9833_config_t;
/**
* @brief STM32 internal DAC configuration mirrored from the serial-control path.
*/
typedef struct stm32_dac_config_t {
uint8_t enabled;
uint16_t code;
} stm32_dac_config_t;
/**
* @brief Absolute DS1809 target expressed as a number of steps above the minimum tap.
*/
typedef struct ds1809_config_t {
bool apply_position;
uint8_t position_from_min;
} ds1809_config_t;
/**
* @brief Standalone profile model loaded from SD-card configuration.
*/
typedef struct profile_t {
char display_name[APP_PROFILE_NAME_LENGTH];
char profile_path[APP_PROFILE_PATH_LENGTH];
char waveform_path[APP_PROFILE_PATH_LENGTH];
bool auto_run;
bool boot_enabled;
work_config_t work_config;
laser_channel_config_t laser_channels[2];
waveform_config_t waveform;
ad9833_config_t ad9833;
stm32_dac_config_t stm32_dac;
ds1809_config_t ds1809;
} profile_t;
/**
* @brief Telemetry frame sent over UART.
*/
typedef struct telemetry_frame_t {
uint16_t words[APP_TELEMETRY_WORD_COUNT];
} telemetry_frame_t;
#endif /* APP_TYPES_H */