/**************************************************************************//**
* @file
* @brief         Alcolyzer Console is for controlling and configuring the 
*                BierAlyzer. Compliant with BierAlyzer Firmware v1.1.
*                Compliant with the DDP Protocol v1.1.
* @headerfile    
* @details
******************************************************************************
* @author        M. Eng. CCR (Technikreferent des Durstigen Donnerstags)
* @version       1.0
* @date          Q1 2016
******************************************************************************
* @bug
* @warning       Because of the lazyness of the author there are a lot of magic numbers
******************************************************************************
* @copyright     <b>CC-Software</b> - http://www.cc-software.de
*                Open Source Software for http://www.durstiger-donnerstag.de
* @section       License
*                This code is open source. Feel free to use it for non-commercial purposes.
*                However consider:
*                - always mention the origin (CC-Software and Durstiger Donnerstag)
*                - if you altered code, additionally mark it as altered by you
*                - the author doesn't guarantee functionality and is not liable for
*                  any accidents or other occurrences due to the usage of this code
*******************************************************************************/

#include "stdafx.h"
#include <windows.h>

#include "DDProtocol.h"
#include "CommandParser.h"
#include "Command.h"

/**************************************************************************//**
* @addtogroup AlcoLyzer Console
*****************************************************************************/

void print_start_text(void)
{
    printf("*******************************************************************************\n");
    printf("*                           AlcoLyzer Console v1.0                            *\n");
    printf("*******************************************************************************\n");
    printf("* Consolenversion des AlcoLyzers fuer das AktionsBuendnis Durstiger Donnerstag*\n");
    printf("* Programmiert vom Technik-Referenten, CC-Software - www.cc-software.de       *\n");
    printf("* Kompatibel mit BierAlyzer Firmware v1.1                                     *\n");
    printf("*******************************************************************************\n\n");
}

/**************************************************************************//**
* @brief
*    Main Mann!!!
*
* @param argc
*    Not used.
*
* @param argv
*    Not used.
*
* @return
*    0
*****************************************************************************/
int main(int argc, char* argv[])
{
    //set appropriate command window settings
    //to make every info fit the command screen
    _COORD coord;
    coord.X = 180;
    coord.Y = 100;

    _SMALL_RECT Rect;
    Rect.Top = 0;
    Rect.Left = 0;
    Rect.Bottom = 100 - 1;
    Rect.Right = 180 - 1;

    HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE);      // Get Handle
    SetConsoleScreenBufferSize(Handle, coord);            // Set Buffer Size
    SetConsoleWindowInfo(Handle, TRUE, &Rect);            // Set Window Size

    print_start_text();

    if (!initDDP())
    {
        printf("<> AlcoLyzer Console gestartet.\n<> Fuer Command Auflistung help eingeben, zum Beenden quit.\n\n");

        char input[50], i;

        //main loop to ask for type inputs
        do{
            printf(">>");

            //reset buffer content
            for (i = 0; i < 50; i++){
                input[i] = 0;
            }
            i = 0;

            //read inputted characters until Return is pressed
            while (input[i - 1] != '\n'){
                input[i] = getchar();
                i++;
            }

            //forward input to command parser
            CommandParse(input);

        } while (!(input[0] == 'q' && input[1] == 'u' && input[2] == 'i' && input[3] == 't'));
    }

    deinitDDP();
    printf("\n<> Taste druecken zum Beenden ...");
    getchar();
    return 0;
}

