#include "cmds.h"
#include "Drivers/EthDrv/phy_drv/phy_common.h"
#include "cliutils/cli.h"

#include <stdlib.h>
#include <string.h>

#include "FreeRTOS.h"
#include "cmsis_os2.h"

#include "portable.h"
#include "standard_output/standard_output.h"             

CMD_FUNCTION(os_info) {
    osVersion_t kVersion;
    char kId[32];
    kId[sizeof(kId) - 1] = 0;
    osKernelGetInfo(&kVersion, kId, sizeof(kId) - 1);
    MSG("OS: %s\n Kernel version: %d\n API version: %d\n", kId, kVersion.kernel, kVersion.api);

    HeapStats_t stats;
    vPortGetHeapStats(&stats);
    MSG("Free OS memory: %u bytes\n", stats.xAvailableHeapSpaceInBytes);

    return 0;
}

CMD_FUNCTION(phy_info) {
    phy_print_full_name();
    return 0;
}

CMD_FUNCTION(print_ip) {
    MSGraw("IP: " ANSI_COLOR_BYELLOW);
    //PRINT_IPv4(E.ethIntf->ip);
    MSGraw(ANSI_COLOR_RESET "\r\n");
    return 0;
}

void cmd_init() {
    cli_register_command("osinfo \t\t\tPrint OS-related information", 1, 0, os_info);
    cli_register_command("phyinfo \t\t\tPrint Ethernet PHY information", 1, 0, phy_info);

    cli_register_command("ip \t\t\tPrint IP-address", 1, 0, print_ip);
}