bool CSwitchActivation::ConsoleCommandProcess()

in Firmware/ExpressivePixelsCore/EPXApp_Trigger_Switch.cpp [84:156]


bool CSwitchActivation::ConsoleCommandProcess(const char *pszCommand, bool *pbResponseSuccess, EPXString &innerResponse)
{
	bool syntax = false;
	char *pszPostToken;
	
	if (CExpressivePixelsApp::CompareToken(pszCommand, (const char *)TTYTOKEN_SWITCHACTIVATION, &pszPostToken))
	{
		char *pszAction = CExpressivePixelsApp::ExtractNextParameter(pszPostToken, &pszPostToken);
		if (pszAction != NULL)
		{
			if (!stricmp(pszAction, (const char *)TTYTOKEN_ADD))
			{
				char *pszPin = CExpressivePixelsApp::ExtractNextParameter(pszPostToken, &pszPostToken);
				if (pszPin != NULL)
				{
					if (pszPostToken != NULL)						
					{
						syntax = true;									
						*pbResponseSuccess = AddEntry(pszPin, pszPostToken);
					}
				}
				if (!syntax)
				{
					innerResponse += JSON_KEYOBJECTOPEN("info");	
					innerResponse += JSON_KEYVALUE_STRINGPAIR("details", "Syntax error");
					innerResponse += JSON_CLOSEOBJECT;
				}
			}
			else if (!stricmp(pszAction, (const char *)TTYTOKEN_DELETE))
			{
				char *pszPin = CExpressivePixelsApp::ExtractNextParameter(pszPostToken, &pszPostToken);
				if (pszPin != NULL)
				{
					syntax = true;						
					*pbResponseSuccess = RemoveEntry(pszPin);
				}				
				if (!syntax)
				{
					innerResponse += JSON_KEYOBJECTOPEN("info");	
					innerResponse += JSON_KEYVALUE_STRINGPAIR("details", "Syntax error");
					innerResponse += JSON_CLOSEOBJECT;
				}
			}
			else if (!stricmp(pszAction, (const char *)TTYTOKEN_DELETEALL))
				*pbResponseSuccess = RemoveAll();			
			else if (!stricmp(pszAction, (const char *)TTYTOKEN_LIST))
			{
				SWITCHACTIVATIONITEM *pCur = FirstEntry();
				
				innerResponse += JSON_KEYOBJECTOPEN("info");				
				innerResponse += JSON_KEYOBJECTOPENARRAY("Switch Triggers");				
				while (pCur != NULL)
				{
					innerResponse += JSON_QUOTEDVALUE(EPXString("PinName ") + pCur->pszPin + " -> " + pCur->szAnimationName);
					if (pCur->pNext != NULL)
						innerResponse += EPXString(JSON_CONTINUATION) + JSON_LINESEPARATOR;
					pCur = pCur->pNext;
				}				
				innerResponse += EPXString(JSON_CLOSEARRAY);
				innerResponse += JSON_CLOSEOBJECT;
				*pbResponseSuccess = true;
			}
			else
			{
				innerResponse += JSON_KEYOBJECTOPEN("info");	
				innerResponse += JSON_KEYVALUE_STRINGPAIR("details", "Unknown SWITCHACTIVATION action");
				innerResponse += JSON_CLOSEOBJECT;
			}
		}
		return true;
	}
	return false;
}