diff --git a/prosjekt.X/command-handler.c b/prosjekt.X/command-handler.c new file mode 100644 index 0000000..91e537c --- /dev/null +++ b/prosjekt.X/command-handler.c @@ -0,0 +1,5 @@ +#include "command-handler.h" + +command_t parse_command(char *command_str); + +void route_command(command_t command); diff --git a/prosjekt.X/command-handler.h b/prosjekt.X/command-handler.h new file mode 100644 index 0000000..7d8c304 --- /dev/null +++ b/prosjekt.X/command-handler.h @@ -0,0 +1,65 @@ +/* + * 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 + +// Enum of all valid command types +typedef enum { + WRITE_CHANGE, // Change the configuration + READ_CONFIG, // Read, and print the current configuration + READ_VOLTAGE, // Read, and print a voltage + READ_TERMPERATURE, // Read, and print the temperature + READ_FAN_SPEED, // Read, and print the current fan speed + READ_BULK_FAN_SPEED, // Read, and print the stored back fan speed data + CLEAR_BULK_FAN_SPEED, // 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_NONE // No voltage source selected +} src_voltage_t; + +// Enum of all valid config options +// TODO: Move into config header file +typedef enum { + 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, // The first fan + FAN2, // 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 + config_option_t conf; // The configuration option to cange +} command_context_t; + +// Parses the input string and outputs one of the valid commands +command_context_t parse_command(char *command_str); + +// Routes the provided command to the appropriate function to handle it +void route_command(command_context_t command); + +#ifdef __cplusplus +} +#endif + +#endif /* COMMAND_HANDLER_H */ diff --git a/prosjekt.X/nbproject/configurations.xml b/prosjekt.X/nbproject/configurations.xml index d7f88a4..64209ae 100644 --- a/prosjekt.X/nbproject/configurations.xml +++ b/prosjekt.X/nbproject/configurations.xml @@ -4,6 +4,7 @@ + command-handler.h main.c + command-handler.c