From 9ed49d95ba4810a46b8768ec549c52c4fb0be533 Mon Sep 17 00:00:00 2001 From: xad1 Date: Tue, 2 May 2023 22:14:17 +0100 Subject: [PATCH] Few extra comments --- include/json/retrieve.h | 8 +++++++- include/json/send.h | 2 ++ include/json/utils.h | 3 ++- include/manage.h | 1 + include/menu.h | 9 ++++++++- include/pin.h | 2 ++ include/server.h | 8 ++++++++ include/statistics.h | 2 ++ include/utils.h | 2 ++ include/wifi_info.h | 5 ++++- src/json/send.cpp | 1 + src/main.cpp | 9 +++++++++ 12 files changed, 48 insertions(+), 4 deletions(-) diff --git a/include/json/retrieve.h b/include/json/retrieve.h index 4856a27..841e776 100644 --- a/include/json/retrieve.h +++ b/include/json/retrieve.h @@ -2,6 +2,7 @@ #define JSON_RETRIEVE_H #include +/// @brief Struct to store information about a node in appropriate data types. typedef struct { String name; float cpu; @@ -14,6 +15,7 @@ typedef struct { long long uptime; } Node; +/// @brief Struct to store information about a container in appropriate data types. typedef struct { String name; int id; @@ -23,6 +25,7 @@ typedef struct { long long uptime; } Container; +/// @brief Struct to store information about a VM in appropriate data types. typedef struct { String name; int id; @@ -34,7 +37,7 @@ typedef struct { long long netout; } VM; - +/// @brief Struct to store information about a disk in appropriate data types. typedef struct { String devpath; long long size; @@ -45,6 +48,7 @@ typedef struct { String health; } Disk; +/// @brief Struct to store information about a pool in appropriate data types. typedef struct { String name; long long free; @@ -52,12 +56,14 @@ typedef struct { String health; } Pool; +// Function declarations Node *getNodeInfo(int &numNodes); Container *getContainerInfo(int &numContainers, const String &node); VM *getVMInfo(int &numVMs, const String &node); Disk *getDiskInfo(int &numDisks, const String &node); Pool *getPoolInfo(int &numPools, const String &node); +/// @brief Template for a callback function for processing JSON data in to an appropriate struct. typedef void (*ProcessDataCallback)(DynamicJsonDocument&, int&, void*&); diff --git a/include/json/send.h b/include/json/send.h index 3ec2ee8..9c46ebc 100644 --- a/include/json/send.h +++ b/include/json/send.h @@ -1,6 +1,8 @@ #ifndef JSON_SEND_H #define JSON_SEND_H #include + +// Function declarations void restartVM(const String &node, const int &vmid); void restartContainer(const String &node, const int &containerid); void startVM(const String &node, const int &vmid); diff --git a/include/json/utils.h b/include/json/utils.h index edaa455..ab4ffe7 100644 --- a/include/json/utils.h +++ b/include/json/utils.h @@ -2,7 +2,8 @@ #define JSON_UTILS_H #include #include -//JsonObject getNode(String name, JsonArray nodes); + +// Function declarations Node getNode(const String &name); Container getContainer(const int &id, const String &node); VM getVM(const int &id, const String &node); diff --git a/include/manage.h b/include/manage.h index 0d744c2..15239ee 100644 --- a/include/manage.h +++ b/include/manage.h @@ -1,6 +1,7 @@ #ifndef MANAGE_H #define MANAGE_H +// Function declarations void vmRestart(); void containerRestart(); void vmStart(); diff --git a/include/menu.h b/include/menu.h index 2be2786..6ea9ec4 100644 --- a/include/menu.h +++ b/include/menu.h @@ -3,12 +3,14 @@ #include #include -// Struct for static menu items such as on the main menu. Has the name of the menu item and a function to run when it is selected. + +/// @brief Struct for static menu items such as on the main menu. Has the name of the menu item and a function to run when it is selected. typedef struct { String name; void (*function)(); } MenuItem; +// Function declarations void listNodes(Node* nodes, const int &numItems); int listContainers(Container* containers, const int &numItems); int listVMs(VM* vms, const int &numItems); @@ -18,11 +20,16 @@ void mainMenu(); void manageContainerMenu(); void manageVMMenu(); +/// @brief Template for a callback function to print a menu entry. typedef void (*MenuPrintCallback)(void*); +/// @brief Variable to hold the currently selected menu item index. extern int selectedItem; + +/// @brief Variable to hold the currently selected page index. extern int selectedPage; +/// @brief Variable to hold the name of the selected node. extern String selectedNode; #endif \ No newline at end of file diff --git a/include/pin.h b/include/pin.h index b945173..e7124d4 100644 --- a/include/pin.h +++ b/include/pin.h @@ -1,6 +1,8 @@ #ifndef PIN_H #define PIN_H #include + +/// @brief Constant which holds the pin code. const String LOCK_PIN = ""; /** * 0 = A Button diff --git a/include/server.h b/include/server.h index 882d988..a1c33a2 100644 --- a/include/server.h +++ b/include/server.h @@ -2,14 +2,22 @@ #ifndef SERVER_H_ #define SERVER_H_ + /** * Enter WiFi network and Proxmox information * */ +/// @brief Address of the Proxmox server being connected to. Do not add a trailing '/'. E.g. https://10.10.10.10:8006 const String PROXMOX_ADDRESS = ""; + +/// @brief Proxmox token user. E.g. root@pam const String PROXMOX_TOKEN_USER = ""; + +/// @brief Name of the Proxmox token. const String PROXMOX_TOKEN_NAME = ""; + +/// @brief Proxmox token secret key. E.g. 0ec1060d-a4a0-4975-a624-ea5cc49ee04e const String PROXMOX_TOKEN_SECRET = ""; #endif \ No newline at end of file diff --git a/include/statistics.h b/include/statistics.h index a4f60f7..77a1ba4 100644 --- a/include/statistics.h +++ b/include/statistics.h @@ -1,5 +1,7 @@ #ifndef STATISTICS_H #define STATISTICS_H + +// Function declarations void nodeInfo(); void containerInfo(); void vmInfo(); diff --git a/include/utils.h b/include/utils.h index 6509fdc..747eb20 100644 --- a/include/utils.h +++ b/include/utils.h @@ -2,8 +2,10 @@ #define UTILS_H #include +// Function declarations void displayError(String message); void connectWiFi(); bool enterPin(); int pinListener(); + #endif /* UTILS_H */ diff --git a/include/wifi_info.h b/include/wifi_info.h index d5951fc..760a414 100644 --- a/include/wifi_info.h +++ b/include/wifi_info.h @@ -2,10 +2,13 @@ #define WIFI_H_ /** - * Enter WiFi network and Proxmox information + * Enter WiFi network information */ +/// @brief The SSID of the WiFi network to connect to. const char* WIFI_SSID = ""; + +/// @brief The password of the WiFi network to connect to. const char* WIFI_PASS = ""; #endif \ No newline at end of file diff --git a/src/json/send.cpp b/src/json/send.cpp index 5998aef..c692444 100644 --- a/src/json/send.cpp +++ b/src/json/send.cpp @@ -33,6 +33,7 @@ void restartVM(const String &node, const int &vmid) apiSend(apiPath, ""); } + /// @brief The function to restart a given container. Calls the apiSend() function with the appropriate parameters to restart a container. /// @param node A reference to a string which contains the name of the node that is running the container that is being restarted. /// @param containerid A reference to an integer which holds the ID of the container being restarted. diff --git a/src/main.cpp b/src/main.cpp index 9574a9b..a724de3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,11 @@ #include #include + +/** + * @brief The main loop of the program. Runs the node selection screen, followed by the main menu. + * In the case of any errors the program will start this loop again. + */ void loop() { // Check if still connected to a WiFi network. If not then display this to the user and then attempt to reconnect. @@ -39,6 +44,10 @@ void loop() } } +/** + * @brief Initial setup of the program. Run the pin system before attempting WiFi connection. + * Setup ends after successful connection to a WiFi network. + */ void setup() { Serial.begin(115200);