pico-bmc/main.c

59 lines
1.5 KiB
C
Raw Normal View History

2024-05-06 19:04:20 +00:00
#ifndef NDEBUG
#define DEBUG_printf printf
2024-05-06 19:04:20 +00:00
#else
#define DEBUG_printf
#endif
2024-05-06 19:04:20 +00:00
#include "secret.h"
#include "pico_lib.h"
#include "network.h"
#include "bmc_handler.h"
#include "http_serv.h"
2024-05-06 19:04:20 +00:00
#include "serial_handler.h"
2024-02-14 02:01:59 +00:00
int main() {
2024-03-05 05:07:18 +00:00
stdio_init_all();
2024-02-14 02:01:59 +00:00
2024-03-05 05:07:18 +00:00
if (cyw43_arch_init()) {
DEBUG_printf("[INIT] [ERR] Failed to initialise cyw43\n");
return 1;
}
2024-02-14 02:01:59 +00:00
cyw43_arch_enable_sta_mode();
network_init(BMC_HOSTNAME, WIFI_SSID, WIFI_PASS);
http_serv_init();
bmc_handler_init();
serial_handler_init();
2024-02-16 22:45:10 +00:00
// set LED to on to indicate it has connected and initialized
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
char command [BUF_SIZE];
2024-03-05 05:07:18 +00:00
while (!http_serv_state->complete) {
printf("> ");
serial_get_line(command, BUF_SIZE);
if (strcmp(command, "help") == 0) {
printf("PICO BMC Shell\n\nhelp\tshow this help message\ninfo\tshow network name, hostname, ip address, and http server port\nclear\tclears the screen\n");
}
else if (strcmp(command, "info") == 0) {
printf("Network: %s\nHostname: %s\nAddress: %s\nHTTP Port: %i\n", WIFI_SSID, BMC_HOSTNAME, ip_ntoa(netif_ip4_addr(&cyw43_state.netif[CYW43_ITF_STA])), HTTP_PORT);
}
else if (strcmp(command, "clear") == 0) {
printf("\033[2J\033[H");
}
else if (strcmp(command, "") == 0) {
continue;
}
else {
printf("Unknown command: %s\n", command);
}
2024-02-29 22:21:31 +00:00
}
serial_handler_deinit();
2024-02-29 22:21:31 +00:00
bmc_handler_deinit();
http_serv_deinit();
network_deinit();
2024-03-05 05:07:18 +00:00
cyw43_arch_deinit();
return 0;
2024-02-14 02:01:59 +00:00
}