2024-05-06 19:04:20 +00:00
# ifndef NDEBUG
2024-02-29 06:56:22 +00:00
# define DEBUG_printf printf
2024-05-06 19:04:20 +00:00
# else
# define DEBUG_printf
# endif
2024-02-29 06:56:22 +00:00
2024-05-06 19:04:20 +00:00
# include "secret.h"
2024-02-18 19:55:43 +00:00
# include "pico_lib.h"
2024-05-10 22:01:22 +00:00
# include "network.h"
2024-04-19 18:59:54 +00:00
# include "bmc_handler.h"
2024-02-29 06:56:22 +00:00
# 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 ( ) ;
2024-05-10 22:01:22 +00:00
network_init ( BMC_HOSTNAME , WIFI_SSID , WIFI_PASS ) ;
2024-02-29 06:56:22 +00:00
http_serv_init ( ) ;
2024-02-14 21:33:20 +00:00
bmc_handler_init ( ) ;
2024-05-10 22:01:22 +00:00
serial_handler_init ( ) ;
2024-02-14 21:33:20 +00:00
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 ) ;
2024-05-10 22:01:22 +00:00
char command [ BUF_SIZE ] ;
2024-03-05 05:07:18 +00:00
while ( ! http_serv_state - > complete ) {
2024-05-10 22:01:22 +00:00
printf ( " > " ) ;
serial_get_line ( command , BUF_SIZE ) ;
if ( strcmp ( command , " help " ) = = 0 ) {
printf ( " PICO BMC Shell \n \n help \t show this help message \n info \t show network name, hostname, ip address, and http server port \n clear \t clears the screen \n " ) ;
}
else if ( strcmp ( command , " info " ) = = 0 ) {
printf ( " Network: %s \n Hostname: %s \n Address: %s \n HTTP 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
}
2024-02-29 06:56:22 +00:00
2024-05-10 22:01:22 +00:00
serial_handler_deinit ( ) ;
2024-02-29 22:21:31 +00:00
bmc_handler_deinit ( ) ;
2024-02-29 06:56:22 +00:00
http_serv_deinit ( ) ;
2024-05-10 22:01:22 +00:00
network_deinit ( ) ;
2024-03-05 05:07:18 +00:00
cyw43_arch_deinit ( ) ;
return 0 ;
2024-02-14 02:01:59 +00:00
}