/*!
 * Display the user options for the Azimuth menu
 */
static void dispElOptions()
{
    sendROM(elOption1);
    sendNewLine(1);
    sendROM(elOption2);
    sendNewLine(1);
    sendROM(elOption3);
    sendNewLine(1);
    if (m_userMode == FACTORY)
    {
        sendROM(elOption4);
        sendNewLine(1);
        transChar('\t');
        sendROM(menuPrefix5);
        transChar('\t');
        sendROM(goUp);
    }
    else
    {
        transChar('\t');
        sendROM(menuPrefix4);
        transChar('\t');
        sendROM(goUp);
    }
    sendNewLine(2);
    sendROM(CHOOSE);
    sendNewLine(1);
    sendROM(CHOOSE2);
}
/*!
 * Display the user options for the Azimuth menu
 */
static void dispRngOptions()
{
    //sendROM(rngOption1);
    sendROM(rngOption1);
    sendNewLine(1);
    //sendROM(rngOption2);
    sendROM(rngOption2);
    sendNewLine(1);
    if (m_userMode == FACTORY)
    {
        sendROM(rngOption3);
        sendNewLine(1);
        sendROM(rngOption4);
        sendNewLine(1);
        sendROM(rngOption5);
        sendNewLine(1);
        sendROM(rngOption7);
        sendNewLine(1);
        sendROM(rngOption8);
        sendNewLine(1);
        transChar('\t');
        sendROM(menuPrefix8);
        transChar('\t');
        sendROM(goUp);
    }
    else
    {
        transChar('\t');
        sendROM(menuPrefix3);
        transChar('\t');
        sendROM(goUp);
    }
    sendNewLine(2);
    sendROM(CHOOSE);
    sendNewLine(1);
    sendROM(CHOOSE2);
}
/*!
 * Display the current menu Title and other information over serial
 */
static void displayMenuSerial()
{
    int j;
    sendNewLine(1);
    clearScreen();
    filler(width);
    sendNewLine(1);
    transChar('\t');
    sendROM(m_currentMenu.lcdTitleMessage);
    sendNewLine(1);
    filler(width);
    sendNewLine(2);
    m_currentMenu.serialDisplayFunction();
    sendNewLine(2);
    filler(width);
    for (j=0;j<1000;j++);
    sendNewLine(1);
}
Beispiel #4
0
//-------------------------------------------------------------------------------------
bool TelnetHandler::processCommand()
{
	if(command_.size() == 0)
	{
		sendNewLine();
		return true;
	}

	if(state_ == TELNET_STATE_PASSWD)
	{
		if(command_ == pTelnetServer_->passwd())
		{
			state_ = (TELNET_STATE)pTelnetServer_->deflayer();
			std::string s = getWelcome();
			pEndPoint_->send(s.c_str(), s.size());
			command_ = "";
			sendEnter();
			sendNewLine();
			return true;
		}
		else
		{
			command_ = "";
			sendNewLine();
			return true;
		}
	}


	bool logcmd = true;
	//for(int i=0; i<(int)historyCommand_.size(); ++i)
	{
		//if(historyCommand_[i] == command_)
		//{
		//	logcmd = false;
		//	break;
		//}
	}

	if(logcmd)
	{
		historyCommand_.push_back(command_);
		historyCommandCheck();
		historyCommandIndex_ = historyCommand_.size() - 1;
	}

	std::string cmd = command_;
	command_ = "";

	if(cmd == ":python")
	{
		if(pTelnetServer_->pScript() == NULL)
			return true;

		state_ = TELNET_STATE_PYTHON;
		sendNewLine();
		return true;
	}
	else if(cmd == ":help")
	{
		std::string str = help();
		pEndPoint_->send(str.c_str(), str.size());
		sendNewLine();
		return true;
	}
	else if(cmd == ":root")
	{
		sendNewLine();
		state_ = TELNET_STATE_ROOT;
		return true;
	}
	else if(cmd == ":quit")
	{
		state_ = TELNET_STATE_QUIT;
		
		pTelnetServer_->closeHandler((*pEndPoint_), this);
		return false;
	}
	else if(cmd.find(":cprofile") == 0)
	{
		uint32 timelen = 10;
		
		cmd.erase(cmd.find(":cprofile"), strlen(":cprofile"));
		if(cmd.size() > 0)
		{
			try
			{
				KBEngine::StringConv::str2value(timelen, cmd.c_str());
			}
			catch(...)  
			{
				timelen = 10;
			}

			if(timelen < 1 || timelen > 999999999)
				timelen = 10;
		}

		std::string str = fmt::format("Waiting for {} secs.\r\n", timelen);
		pEndPoint_->send(str.c_str(), str.size());
		
		std::string profileName = KBEngine::StringConv::val2str(KBEngine::genUUID64());

		if(pProfileHandler_) pProfileHandler_->destroy();
		pProfileHandler_ = new TelnetCProfileHandler(this, *pTelnetServer_->pNetworkInterface(), 
			timelen, profileName, pEndPoint_->addr());

		readonly();
		return false;
	}
	else if(cmd.find(":pyprofile") == 0)
	{
		uint32 timelen = 10;

		cmd.erase(cmd.find(":pyprofile"), strlen(":pyprofile"));
		if(cmd.size() > 0)
		{
			try
			{
				KBEngine::StringConv::str2value(timelen, cmd.c_str());
			}
			catch(...)  
			{
				timelen = 10;
			}

			if(timelen < 1 || timelen > 999999999)
				timelen = 10;
		}

		std::string str = fmt::format("Waiting for {} secs.\r\n", timelen);
		pEndPoint_->send(str.c_str(), str.size());

		std::string profileName = KBEngine::StringConv::val2str(KBEngine::genUUID64());

		if(pProfileHandler_) pProfileHandler_->destroy();
		pProfileHandler_ = new TelnetPyProfileHandler(this, *pTelnetServer_->pNetworkInterface(), 
			timelen, profileName, pEndPoint_->addr());

		readonly();
		return false;
	}
	else if(cmd.find(":eventprofile") == 0)
	{
		uint32 timelen = 10;

		cmd.erase(cmd.find(":eventprofile"), strlen(":eventprofile"));
		if(cmd.size() > 0)
		{
			try
			{
				KBEngine::StringConv::str2value(timelen, cmd.c_str());
			}
			catch(...)  
			{
				timelen = 10;
			}

			if(timelen < 1 || timelen > 999999999)
				timelen = 10;
		}

		std::string str = fmt::format("Waiting for {} secs.\r\n", timelen);
		pEndPoint_->send(str.c_str(), str.size());

		std::string profileName = KBEngine::StringConv::val2str(KBEngine::genUUID64());

		if(pProfileHandler_) pProfileHandler_->destroy();
		pProfileHandler_ = new TelnetEventProfileHandler(this, *pTelnetServer_->pNetworkInterface(), 
			timelen, profileName, pEndPoint_->addr());

		readonly();
		return false;
	}
	else if(cmd.find(":networkprofile") == 0)
	{
		uint32 timelen = 10;

		cmd.erase(cmd.find(":networkprofile"), strlen(":networkprofile"));
		if(cmd.size() > 0)
		{
			try
			{
				KBEngine::StringConv::str2value(timelen, cmd.c_str());
			}
			catch(...)  
			{
				timelen = 10;
			}

			if(timelen < 1 || timelen > 999999999)
				timelen = 10;
		}

		std::string str = fmt::format("Waiting for {} secs.\r\n", timelen);
		pEndPoint_->send(str.c_str(), str.size());

		std::string profileName = KBEngine::StringConv::val2str(KBEngine::genUUID64());

		if(pProfileHandler_) pProfileHandler_->destroy();
		pProfileHandler_ = new TelnetNetworkProfileHandler(this, *pTelnetServer_->pNetworkInterface(), 
			timelen, profileName, pEndPoint_->addr());

		readonly();
		return false;
	}

	if(state_ == TELNET_STATE_PYTHON)
	{
		processPythonCommand(cmd);
	}

	sendNewLine();
	return true;
}
/*!
 * Description: General funtion for menus which set values
 *              (Such as Set Max Range). This calls the
 *              appropriate function, and transmits user messages.
 */
static void setValue(int input)
{
    char string[20] = " set to \0";
    char stringLcd[20] = {0};
    Direction dir;

    // Sends a new line
    sendNewLine(1);

    // Handle inpropper input values
    if (input < m_currentMenu.minVal || input > m_currentMenu.maxVal)
    {
        errOutOfRange(m_currentMenu.minVal, m_currentMenu.maxVal);
        sendNewLine(1);
        return;
    }

    // Handle Different cases
    // @TODO handle current values
    // @TODO Integrate
    switch (m_currentMenu.menuID)
    {
        case AZ_GOTO:
            dir.azimuth = input;
            dir.elevation = getDir().elevation;
            move(dir);
            sendROM(angleStr);
            break;
        case EL_GOTO:
            dir.azimuth = getDir().azimuth;
            dir.elevation = input;
            move(dir);
            sendROM(angleStr);
            break;
        case AZ_MIN:
            setMinAzimuthAngle((char) input);
            AzGoto.minVal = input;
            sendROM(angleStr);
            break;
        case AZ_MAX:
            setMaxAzimuthAngle((char) input);
            AzGoto.maxVal = input;
            sendROM(angleStr);
            break;
        case EL_MIN:
            setMinElevationAngle((char) input);
            ElGoto.minVal = input;
            sendROM(angleStr);
            break;
        case EL_MAX:
            setMaxElevationAngle((char) input);
            ElGoto.maxVal = input;
            sendROM(angleStr);
            break;
        case RANGE_MIN:
            setMinRange(input);
            sendROM(mmStr);
            break;
        case RANGE_MAX:
            setMaxRange(input);
            sendROM(mmStr);
            break;
        case US_SAMPLE_RATE:
            setUsSampleRate(input);
            sendROM(sampleRate);
            break;
        case US_SAMPLE_AVG:
            setNumSamples(input);
            sendROM(numPerSample);
            break;
    }

    // Transmit the final part of the sentence
    transmit(string);
    transmit(intToAscii(input));
    sendNewLine(1);

    //lcdWriteString(strcpypgm2ram(stringLcd, "OK!"), 2);
}
/*! **********************************************************************
 * Function: serviceMenu(void)
 *
 * \brief services any user interface with the menu
 *
 * Include:
 *
 * Description: Checks if the user has made any inputs to the system. If not
 *              the function simply returns. If they have then it services
 *              the inputs, displays the correct outputs and performs the
 *              specified actions
 *
 * Arguments: None
 *
 * Returns: None
 *************************************************************************/
void serviceMenu(void)
{
    char buttonInput;
    char string[50];
    int numericInpt;

    // Go to factory mode
    if (FACTORY_SWITCH == 1 && m_userMode == REMOTE)
    {
        m_userMode = FACTORY;
        setMenu(m_currentMenu);
    }
    // Rest back to serial mode
    else if(FACTORY_SWITCH == 0 && m_userMode == FACTORY)
    {
        m_userMode = REMOTE;
        setMenu(topMenu);
    }

    if (m_userMode == REMOTE || m_userMode == FACTORY)
    {
        // Check for serial input
        if (checkForSerialInput())
        {
            // Handle serial input
            numericInpt = getSerialNumericInput();
            sendNewLine(1);
            sendROM("DEBUG: Value entered = ");
            transmit(intToAscii(numericInpt));
            sendNewLine(1);
            clearReceive();
        }
        else
        {
            return;
        }
    }
//    else
//    {
//        if (userEmpty())
//        {
//            // Display the current value on the LCD
//            // Get the Potentiometer result for the current menu
//            numericInpt = getLocalPotResult(m_currentMenu.minVal, m_currentMenu.maxVal, m_currentMenu.increment);
//            // Display string on LCD
//            m_currentMenu.lcdDisplayFunction(numericInpt);
//            return;
//        }
//        else
//        {
//            // Confirm the user's input
//            buttonInput = userPop();
//            if (buttonInput == CONFIRM_CHAR)
//            {
//                numericInpt = getLocalPotResult(m_currentMenu.minVal, m_currentMenu.maxVal, m_currentMenu.increment);
//            }
//            else
//            {
//                // Back was pressed
//                numericInpt =  ESC_PRESSED;
//            }
//        }
//    }

    /// If Esc or Back button pressed, return
    if (numericInpt == ESC_PRESSED)
    {
        m_currentMenu.returnToPrevious();
        return;
    }
    else
    {
        /// Otherwise Confirm the selection
        m_currentMenu.confirmFunction(numericInpt);
        return;
    }
}