// Example program
// work in progress 2022.08.07
#include <iostream>
#include <string>

enum cmd_parser_mode_t{
    PARSING_DEVICE,
    CHECK_DEVICE,
    PARSING_COMMAND,
    CHECK_COMMAND,
    PARSING_VALUE,
    CHECK_VALUE,
    COMMAND_VALID
};

void device_check(const std::string cmd)
{
    std::cout << cmd << std::endl;
}



void cmd_parser(const std::string &cmd)
{
    cmd_parser_mode_t parser_mode = PARSING_DEVICE;
    std::string::size_type pos;
    
    for(uint32_t i = 0; i < cmd.length(); i++) {  
        switch(parser_mode) {
            case PARSING_DEVICE:
                std::cout << parser_mode << std::endl;
                
                pos = cmd.find('_');
                if (pos != std::string::npos)
                {
                    device_check(cmd.substr(0, pos));
                }
                else
                {
                    return;
                }
                parser_mode = CHECK_DEVICE;
                break;
            case CHECK_DEVICE:
                std::cout << parser_mode << std::endl;
                parser_mode = PARSING_COMMAND;
                break;
            case PARSING_COMMAND:
                std::cout << parser_mode << std::endl;
                parser_mode = CHECK_COMMAND;
                break;
            case CHECK_COMMAND:
                std::cout << parser_mode << std::endl;
                parser_mode = PARSING_VALUE;
                break;
            case PARSING_VALUE:
                std::cout << parser_mode << std::endl;
                parser_mode = CHECK_VALUE;
                break;
            case CHECK_VALUE:
                std::cout << parser_mode << std::endl;
                parser_mode = COMMAND_VALID;
                break;
            case COMMAND_VALID:
                std::cout << parser_mode << std::endl;
                break;
            default:
                return;
                break;
        };
    }
}



int main()
{
    std::string cmd_in = "DEVICE_COMMAND_VALUE";
    
    cmd_parser(cmd_in);

    return 0;
}

