mikrokontrollersystemer-pro.../prosjekt.X/command-handler.h
2024-04-27 14:52:46 +02:00

87 lines
2.5 KiB
C

/*
* File: command-handler.h
* Author: Sebastian H. Gabrielli
*
* Created on March 6, 2024, 12:43 PM
*/
#ifndef COMMAND_HANDLER_H
#define COMMAND_HANDLER_H
#ifdef __cplusplus
extern "C" {
#endif
#include "eeprom.h"
#include <avr/io.h>
#include <stdint.h>
#include <string.h>
#include "voltage.h"
#include "themistor-temp.h"
// Enum of all valid command types
typedef enum {
WRITE_CONFIG = 0x21, // Change the configuration
READ_CONFIG = 0x11, // Read, and print the current configuration
READ_VOLTAGE = 0x12, // Read, and print a voltage
READ_TERMPERATURE = 0x13, // Read, and print the temperature
READ_FAN_SPEED = 0x14, // Read, and print the current fan speed
READ_BULK_FAN_SPEED = 0x15, // Read, and print the stored back fan speed data
CLEAR_BULK_FAN_SPEED = 0x22, // Clear the buffer of stored fan speed data
UNKNOWN_COMMAND // An unrecognized command has been sent
} command_t;
// Enum of all valid voltage sources
typedef enum {
SRC_INTERNAL, // Internal volage
SRC_EXTRNAL, // External voltage
SRC_THERMISTOR, // Thermistor voltage
SRC_NONE // No voltage source selected
} src_voltage_t;
// Enum of all valid config options
// TODO: Move into config header file
typedef enum {
SAMPLE_TIME = 0x01, // Time between each fan speed sample
CNF_NONE, // No config option
} config_option_t;
// Enum of all valid fans
// TODO: Consider moving into it's own fan page
typedef enum {
FAN1 = 1, // The first fan
FAN2 = 2, // The second fan
FAN_NONE // No fan
} fans_t;
// Struct with command context
typedef struct {
command_t command; // The command to execute
src_voltage_t src_voltage; // The selected voltage source
fans_t fan; // The selected fan
config_option_t conf; // The configuration option to cange
uint16_t conf_val; // The value of the config option to change
} command_context_t;
// Fan history variables
extern volatile uint16_t fan1_history[512];
extern volatile uint16_t fan2_history[512];
// Config
extern volatile config_t config;
extern volatile bool store_config;
// Parses the input string and outputs one of the valid commands
void parse_command(uint8_t *command, uint8_t command_len);
// Routes the provided command to the appropriate function to handle it
// If the command is a read command it then returns the current byte.
// The position is the byte to read when multiple bytes are being read.
uint8_t route_command(int pos);
#ifdef __cplusplus
}
#endif
#endif /* COMMAND_HANDLER_H */