コード例 #1
0
ファイル: sp5KV5_PZ_tkCmd.c プロジェクト: ppeluffo/sp5KV5_PZ
/*------------------------------------------------------------------------------------*/
static void cmdWriteFunction(void)
{
s08 retS = FALSE;
u08 argc;

	argc = pv_makeArgv();

	// SAVE
	if (!strcmp_P( strupr(argv[1]), PSTR("SAVE\0"))) {
		retS = u_saveSystemParams();
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// PASSWD
	if (!strcmp_P( strupr(argv[1]), PSTR("PASSWD\0"))) {
		if ( argv[2] == NULL ) {
			retS = FALSE;
		} else {
			memset(systemVars.passwd, '\0', sizeof(systemVars.passwd));
			memcpy(systemVars.passwd, argv[2], sizeof(systemVars.passwd));
			systemVars.passwd[PASSWD_LENGTH - 1] = '\0';
			retS = TRUE;
		}
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// DLGID
	if (!strcmp_P( strupr(argv[1]), PSTR("DLGID\0"))) {
		if ( argv[2] == NULL ) {
			retS = FALSE;
		} else {
			memcpy(systemVars.dlgId, argv[2], sizeof(systemVars.dlgId));
			systemVars.dlgId[DLGID_LENGTH - 1] = '\0';
			retS = TRUE;
		}
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// APN
	if (!strcmp_P( strupr(argv[1]), PSTR("APN\0"))) {
		if ( argv[2] == NULL ) {
			retS = FALSE;
		} else {
			memset(systemVars.apn, '\0', sizeof(systemVars.apn));
			memcpy(systemVars.apn, argv[2], sizeof(systemVars.apn));
			systemVars.apn[APN_LENGTH - 1] = '\0';
			retS = TRUE;
		}
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// ROAMING
	if (!strcmp_P( strupr(argv[1]), PSTR("ROAMING\0"))) {
		if (!strcmp_P( strupr(argv[2]), PSTR("ON"))) { systemVars.roaming = TRUE; }
		if (!strcmp_P( strupr(argv[2]), PSTR("OFF"))) { systemVars.roaming = FALSE; }
		pv_snprintfP_OK();
		return;
	}

	// SERVER PORT
	if (!strcmp_P( strupr(argv[1]), PSTR("PORT\0"))) {
		if ( argv[2] == NULL ) {
			retS = FALSE;
		} else {
			memset(systemVars.serverPort, '\0', sizeof(systemVars.serverPort));
			memcpy(systemVars.serverPort, argv[2], sizeof(systemVars.serverPort));
			systemVars.serverPort[PORT_LENGTH - 1] = '\0';
			retS = TRUE;
		}
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// SERVER IP
	if (!strcmp_P( strupr(argv[1]), PSTR("IP\0"))) {
		if ( argv[2] == NULL ) {
			retS = FALSE;
		} else {
			memset(systemVars.serverAddress, '\0', sizeof(systemVars.serverAddress));
			memcpy(systemVars.serverAddress, argv[2], sizeof(systemVars.serverAddress));
			systemVars.serverAddress[IP_LENGTH - 1] = '\0';
			retS = TRUE;
		}
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// SERVER SCRIPT
	if (!strcmp_P( strupr(argv[1]), PSTR("SCRIPT\0"))) {
		if ( argv[2] == NULL ) {
			retS = FALSE;
		} else {
			memset(systemVars.serverScript, '\0', sizeof(systemVars.serverScript));
			memcpy(systemVars.serverScript, argv[2], sizeof(systemVars.serverScript));
			systemVars.serverScript[SCRIPT_LENGTH - 1] = '\0';
			retS = TRUE;
		}
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	/* DEBUGLEVEL */
	if (!strcmp_P( strupr(argv[1]), PSTR("DEBUGLEVEL\0"))) {
		retS = pv_cmdWrDebugLevel(argv[2]);
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	/* DEBUGLEVEL */
	if (!strcmp_P( strupr(argv[1]), PSTR("LOG\0"))) {
		retS = pv_cmdWrLog(argv[2]);
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	/* WRKMODE */
	if (!strcmp_P( strupr(argv[1]), PSTR("WRKMODE\0"))) {
		retS = pv_cmdWrkMode(argv[2],argv[3]);
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// CANALES ANALOGICOS
	if (!strcmp_P( strupr(argv[1]), PSTR("A0\0"))) {
		retS = u_configAnalogCh( 0, argv[2] );
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	if (!strcmp_P( strupr(argv[1]), PSTR("A1\0"))) {
		retS = u_configAnalogCh( 1, argv[2] );
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	if (!strcmp_P( strupr(argv[1]), PSTR("A2\0"))) {
		retS = u_configAnalogCh( 2, argv[2] );
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// TIMERPOLL
	if (!strcmp_P( strupr(argv[1]), PSTR("TIMERPOLL\0"))) {
		retS = u_configTimerPoll(argv[2]);

		// tk_range: notifico en modo persistente. Si no puedo, me voy a resetear por watchdog. !!!!
		while ( xTaskNotify(xHandle_tkRange, TK_PARAM_RELOAD , eSetBits ) != pdPASS ) {
			vTaskDelay( ( TickType_t)( 100 / portTICK_RATE_MS ) );
		}

		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// RTC
	if (!strcmp_P( strupr(argv[1]), PSTR("RTC\0"))) {
		retS = u_wrRtc(argv[2]);
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	//----------------------------------------------------------------------
	// COMANDOS USADOS PARA DIAGNOSTICO
	// DEBEMOS ESTAR EN MODO SERVICE
	//----------------------------------------------------------------------

	// GSMBAND:
	// Debo estar en modo service ya que para que tome el valor debe resetearse
	if (!strcmp_P( strupr(argv[1]), PSTR("GSMBAND\0"))) {
		if ( argv[2] == NULL ) {
			retS = FALSE;
		} else {
			systemVars.gsmBand = atoi(argv[2]);
			retS = TRUE;
		}
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// EE: write ee pos string
	if (!strcmp_P( strupr(argv[1]), PSTR("EE\0")) && ( systemVars.wrkMode == WK_SERVICE) ) {
		retS = pv_cmdWrEE( argv[2], argv[3]);
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// gprsPWR
	if (!strcmp_P( strupr(argv[1]), PSTR("GPRSPWR\0")) && ( systemVars.wrkMode == WK_SERVICE) ) {
		retS = MCP_setGprsPwr( (u08) atoi(argv[2]) );
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// gprsSW
	if (!strcmp_P( strupr(argv[1]), PSTR("GPRSSW\0")) && ( systemVars.wrkMode == WK_SERVICE) ) {
		retS = MCP_setGprsSw( (u08) atoi(argv[2]) );
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// MCP
	// write mcp 0|1|2 addr value
	if (!strcmp_P( strupr(argv[1]), PSTR("MCP\0")) && ( systemVars.wrkMode == WK_SERVICE) ) {
		switch( atoi(argv[2] )) {
		case 0:
			retS = MCP_write( MCP0_ADDR, atoi(argv[3]), atoi(argv[4]) );
			break;
		case 1:
			retS = MCP_write( MCP1_ADDR, atoi(argv[3]), atoi(argv[4]) );
			break;
		}
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// ATCMD
	// Envia un comando al modem.
	if (!strcmp_P( strupr(argv[1]), PSTR("ATCMD\0")) && ( systemVars.wrkMode == WK_SERVICE) ) {
		snprintf( cmd_printfBuff,sizeof(cmd_printfBuff),"%s\r",argv[2] );
		FreeRTOS_ioctl( &pdUART0,ioctl_UART_CLEAR_RX_BUFFER, NULL);
		FreeRTOS_ioctl( &pdUART0,ioctl_UART_CLEAR_TX_BUFFER, NULL);
		FreeRTOS_write( &pdUART0, cmd_printfBuff, sizeof(cmd_printfBuff) );

		snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("sent->%s\r\n\0"),argv[2] );
		FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );
		return;
	}

	// RANGE control
	if (!strcmp_P( strupr(argv[1]), PSTR("RANGECTL\0")) && ( systemVars.wrkMode == WK_SERVICE) ) {
		if (!strcmp_P( strupr(argv[2]), PSTR("RUN"))) {
			u_rangeSignal(RUN);
			retS = TRUE;
		}
		if (!strcmp_P( strupr(argv[2]), PSTR("STOP"))) {
			u_rangeSignal(STOP);
			retS = TRUE;
		}
		retS ? pv_snprintfP_OK() : 	pv_snprintfP_ERR();
		return;
	}

	// CMD NOT FOUND
	snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("ERROR\r\nCMD NOT DEFINED\r\n"));
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );
	return;
}
コード例 #2
0
ファイル: sp5K_tkCmd.c プロジェクト: spymovil/sp5K
void sp5K_writeFunction(void)
{

u08 dateTimeStr[11];
char tmp[3];
RtcTimeType rtcDateTime;
char *p;
u08 devId, address, regValue;
u08 value = 0;
s08 retS = FALSE;
u08  mcp_address = 0;
u08 length = 0;
u08 *nro = NULL;
u08 *msg = NULL;
u08 timeout;
char phase;
u08 chip;
u16 sleepTime;

	memset( cmd_printfBuff, NULL, CHAR128);
	makeargv();

	// Parametros:
	if (!strcmp_P( strupr(argv[1]), PSTR("PARAM\0")))
	{

		// PASSWD
		if (!strcmp_P( strupr(argv[2]), PSTR("PASSWD\0"))) {
			memset(systemVars.passwd, '\0', sizeof(systemVars.passwd));
			memcpy(systemVars.passwd, argv[3], sizeof(systemVars.passwd));
			systemVars.passwd[PASSWD_LENGTH - 1] = '\0';
			pv_snprintfP_OK();
			return;
		}

		// APN
		if (!strcmp_P( strupr(argv[2]), PSTR("APN\0"))) {
			memset(systemVars.apn, '\0', sizeof(systemVars.apn));
			memcpy(systemVars.apn, argv[3], sizeof(systemVars.apn));
			systemVars.apn[APN_LENGTH - 1] = '\0';
			pv_snprintfP_OK();
			return;
		}

		// SERVER PORT
		if (!strcmp_P( strupr(argv[2]), PSTR("PORT\0"))) {
			memset(systemVars.serverPort, '\0', sizeof(systemVars.serverPort));
			memcpy(systemVars.serverPort, argv[3], sizeof(systemVars.serverPort));
			systemVars.serverPort[PORT_LENGTH - 1] = '\0';
			pv_snprintfP_OK();
			return;
		}

		// SERVER IP
		if (!strcmp_P( strupr(argv[2]), PSTR("IP\0"))) {
			memset(systemVars.serverAddress, '\0', sizeof(systemVars.serverAddress));
			memcpy(systemVars.serverAddress, argv[3], sizeof(systemVars.serverAddress));
			systemVars.serverAddress[IP_LENGTH - 1] = '\0';
			pv_snprintfP_OK();
			return;
		}

		// SERVER SCRIPT
		// write param script cgi-bin/oseApp/scripts/oseSp5K001.pl
		if (!strcmp_P( strupr(argv[2]), PSTR("SCRIPT\0"))) {
			memset(systemVars.serverScript, '\0', sizeof(systemVars.serverScript));
			memcpy(systemVars.serverScript, argv[3], sizeof(systemVars.serverScript));
			systemVars.serverScript[SCRIPT_LENGTH - 1] = '\0';
			pv_snprintfP_OK();
			return;
		}

		// MagP ( magnitud  por pulso )
		if (!strcmp_P( strupr(argv[2]), PSTR("MAGP\0"))) {
			retS = setParamMagP(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// dname X ( digital name X )
		if (!strcmp_P( strupr(argv[2]), PSTR("DNAME\0"))) {
			retS = setParamDname(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// aname X ( analog name X )
		if (!strcmp_P( strupr(argv[2]), PSTR("ANAME\0"))) {
			retS = setParamAname(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// imin X
		if (!strcmp_P( strupr(argv[2]), PSTR("IMIN\0"))) {
			retS = setParamImin(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// imax X
		if (!strcmp_P( strupr(argv[2]), PSTR("IMAX\0"))) {
			retS = setParamImax(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// Mmin X
		if (!strcmp_P( strupr(argv[2]), PSTR("MMIN\0"))) {
			retS = setParamMmin(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// Mmax X
		if (!strcmp_P( strupr(argv[2]), PSTR("MMAX\0"))) {
			retS = setParamMmax(argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// offmmin X
		if (!strcmp_P( strupr(argv[2]), PSTR("OFFMMIN\0"))) {
			retS = setParamOffset(0,argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// offmmax X
		if (!strcmp_P( strupr(argv[2]), PSTR("OFFMMAX\0"))) {
			retS = setParamOffset(1,argv[3], argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		/* DebugLevel */
		if (!strcmp_P( strupr(argv[2]), PSTR("DEBUGLEVEL\0"))) {
			retS = setParamDebugLevel(argv[3]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		/* LogLevel */
		if (!strcmp_P( strupr(argv[2]), PSTR("LOGLEVEL\0"))) {
			retS = setParamLogLevel(argv[3]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		// dlgId
		if (!strcmp_P( strupr(argv[2]), PSTR("DLGID\0"))) {
			memcpy(systemVars.dlgId, argv[3], sizeof(systemVars.dlgId));
			systemVars.dlgId[DLGID_LENGTH - 1] = '\0';
			pv_snprintfP_OK();
			return;
		}

		/* TimerPoll */
		if (!strcmp_P( strupr(argv[2]), PSTR("TIMERPOLL\0"))) {
			retS = setParamTimerPoll(argv[3]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		/* TimerDial */
		if (!strcmp_P( strupr(argv[2]), PSTR("TIMERDIAL\0"))) {
			retS = setParamTimerDial(argv[3]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		/* Wrkmode */
		if (!strcmp_P( strupr(argv[2]), PSTR("WRKMODE\0"))) {
			retS = setParamWrkMode(argv[3],argv[4]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

		/* Pwrmode */
		if (!strcmp_P( strupr(argv[2]), PSTR("PWRMODE\0"))) {
			retS = setParamPwrMode(argv[3]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}

/*		// MONITOR
		// write param monitor [sqe|frame]
		if (!strcmp_P( strupr(argv[2]), PSTR("MONITOR\0"))) {
			retS = setParamMonitor(argv[3]);
			if ( retS ) {
				pv_snprintfP_OK();
			} else {
				pv_snprintfP_ERR();
			}
			return;
		}
*/


	}

	// CONSIGNA
	if (!strcmp_P( strupr(argv[2]), PSTR("CONSIGNA\0"))) {
		retS = setParamConsigna(argv[3], argv[4]);
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// ALL SystemVars ( save )
	if (!strcmp_P( strupr(argv[1]), PSTR("SAVE\0"))) {
		retS = saveSystemParamsInEE( &systemVars );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// RTC
	if (!strcmp_P( strupr(argv[1]), PSTR("RTC\0"))) {
		/* YYMMDDhhmm */
		memcpy(dateTimeStr, argv[2], 10);
		// year
		tmp[0] = dateTimeStr[0]; tmp[1] = dateTimeStr[1];	tmp[2] = '\0';
		rtcDateTime.year = atoi(tmp);
		// month
		tmp[0] = dateTimeStr[2]; tmp[1] = dateTimeStr[3];	tmp[2] = '\0';
		rtcDateTime.month = atoi(tmp);
		// day of month
		tmp[0] = dateTimeStr[4]; tmp[1] = dateTimeStr[5];	tmp[2] = '\0';
		rtcDateTime.day = atoi(tmp);
		// hour
		tmp[0] = dateTimeStr[6]; tmp[1] = dateTimeStr[7];	tmp[2] = '\0';
		rtcDateTime.hour = atoi(tmp);
		// minute
		tmp[0] = dateTimeStr[8]; tmp[1] = dateTimeStr[9];	tmp[2] = '\0';
		rtcDateTime.min = atoi(tmp);

		retS = rtcSetTime(&rtcDateTime);

		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// Si no estoy en modo service no puedo hacer estas tareas administrativas.

	if ( systemVars.wrkMode != WK_SERVICE) {
		snprintf_P( &cmd_printfBuff,CHAR128,PSTR("WARNING: Debe pasar a modo SERVICE !!!\r\n\0"));
		sp5K_printStr(&cmd_printfBuff);
		return;
	}

	// MCP
	// write mcp 0|1|2 addr value
	if (!strcmp_P( strupr(argv[1]), PSTR("MCP\0"))) {
		devId = atoi(argv[2]);
		address = atoi(argv[3]);
		regValue = strtol(argv[4],NULL,2);

		if ( devId == 0 ) { mcp_address = MCP_ADDR0; }
		if ( devId == 1 ) { mcp_address = MCP_ADDR1; }
		if ( devId == 2 ) { mcp_address = MCP_ADDR2; }

		retS = MCP_write( address,  mcp_address, 1, &regValue);
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// EEPROM
	if (!strcmp_P( strupr(argv[1]), PSTR("EE\0"))) {
		address = atoi(argv[2]);
		p = argv[3];
		while (*p != NULL) {
			p++;
			length++;
			if (length > CMDLINE_BUFFERSIZE )
				break;
		}

		retS = EE_write( address, length, argv[3] );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// LED
	// write led 0|1
	if (!strcmp_P( strupr(argv[1]), PSTR("LED\0"))) {
		value = atoi(argv[2]);
		retS = MCP_setLed( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// gprsPWR
	if (!strcmp_P( strupr(argv[1]), PSTR("GPRSPWR\0"))) {
		value = atoi(argv[2]);
		retS = MCP_setGprsPwr( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// gprsSW
	if (!strcmp_P( strupr(argv[1]), PSTR("GPRSSW\0"))) {
		value = atoi(argv[2]);
		retS = MCP_setGprsSw( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// termPWR
	if (!strcmp_P( strupr(argv[1]), PSTR("TERMPWR\0"))) {
		value = atoi(argv[2]);
		retS = MCP_setTermPwr( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// sensorPWR
	if (!strcmp_P( strupr(argv[1]), PSTR("SENSORPWR\0"))) {
		value = atoi(argv[2]);
		retS = MCP_setSensorPwr( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// analogPWR
	if (!strcmp_P( strupr(argv[1]), PSTR("ANALOGPWR\0"))) {
		value = atoi(argv[2]);
		retS = MCP_setAnalogPwr( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// SMS
	if (!strcmp_P(argv[1], PSTR("SMS\0"))) {
		nro = argv[2];
		msg = cmdlineGetArgStr(3);

		rprintfStr(GPRS_UART, "AT+CMGS=\"+\0" );
		rprintfStr(GPRS_UART, nro );
		rprintfStr(GPRS_UART, "\r\0");

		// Espero el prompt > para enviar el mensaje.
		timeout = 10;
		xUartQueueFlush(GPRS_UART);
		while (timeout > 0) {
			vTaskDelay( (portTickType)( 1000 / portTICK_RATE_MS ));
			if (strstr( &xUart0RxedCharsBuffer.buffer, ">") != NULL) {
				break;
			}
			timeout--;
		}
		rprintfStr(GPRS_UART, msg );
		rprintfStr(GPRS_UART, "\r");

		rprintfStr(CMD_UART, &xUart0RxedCharsBuffer.buffer );
		rprintfCRLF(CMD_UART);

		rprintfStr(GPRS_UART, "\032");

		return;
	}

	// ATCMD
	if (!strcmp_P(argv[1], PSTR("ATCMD\0"))) {
		msg = argv[2];
		timeout = atoi(argv[3]);
		if (timeout == 0)
			timeout = 1;

		xUartQueueFlush(GPRS_UART);
		rprintfStr(GPRS_UART, msg);
		rprintfStr(GPRS_UART, "\r\0");

		rprintfStr(CMD_UART, "sent>\0");
		rprintfStr(CMD_UART, msg);
		rprintfCRLF(CMD_UART);

		while (timeout > 0) {
			vTaskDelay( (portTickType)( 1000 / portTICK_RATE_MS ));
			timeout--;
		}

		rprintfStr(CMD_UART, &xUart0RxedCharsBuffer.buffer );
		rprintfCRLF(CMD_UART);

		return;
	}

#ifdef CHANNELS_3

	// Valves: Phase
	// write ph A1 1
	if (!strcmp_P( strupr(argv[1]), PSTR("PH\0"))) {

		phase = toupper( argv[2][0]  );
		//(s0)++;
		chip = argv[2][1] - 0x30;
		value = atoi(argv[3]);

		retS = setValvesPhase(phase,chip, value);
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// Valves: Enable
	// write en A1 1
	if (!strcmp_P( strupr(argv[1]), PSTR("EN\0"))) {

		phase = toupper( argv[2][0]  );
		//(s0)++;
		chip = argv[2][1] - 0x30;
		value = atoi(argv[3]);

		retS = setValvesEnable(phase,chip, value);
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// Valves: Reset
	if (!strcmp_P( strupr(argv[1]), PSTR("VRESET\0"))) {

		value = atoi(argv[2]);

		retS = setValvesReset( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// Valves: Sleep
	if (!strcmp_P( strupr(argv[1]), PSTR("VSLEEP\0"))) {

		value = atoi(argv[2]);

		retS = setValvesSleep( value );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;
	}

	// Valves: Pulse [A/B][1/2] {+|-} {ms}
	if (!strcmp_P( strupr(argv[1]), PSTR("VPULSE\0"))) {

		phase = toupper( argv[2][0]  );
		chip = argv[2][1] - 0x30;
		value = toupper( argv[3][0]  );
		sleepTime = atol(argv[4]);

		if ( sleepTime > 5000 ) {
			sleepTime = 5000;
		}

		retS = setValvesPulse( phase, chip, value, sleepTime );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;

	}

	// Valves: OPEN
	if (!strcmp_P( strupr(argv[1]), PSTR("OPEN\0"))) {

		phase = toupper( argv[2][0]  );
		chip = argv[2][1] - 0x30;

		retS = setValvesOpen( phase, chip );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;

	}

	// Valves: CLOSE
	if (!strcmp_P( strupr(argv[1]), PSTR("CLOSE\0"))) {

		phase = toupper( argv[2][0]  );
		chip = argv[2][1] - 0x30;

		retS = setValvesClose( phase, chip );
		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;

	}

	// Valves: Consigna
	if (!strcmp_P( strupr(argv[1]), PSTR("CONSIGNA\0"))) {

		if (!strcmp_P( strupr(argv[2]), PSTR("DIA\0"))) {
			retS = setConsignaDia();
		}

		if (!strcmp_P( strupr(argv[2]), PSTR("NOCHE\0"))) {
			retS = setConsignaNoche();
		}

		if ( retS ) {
			pv_snprintfP_OK();
		} else {
			pv_snprintfP_ERR();
		}
		return;

	}
#endif

	// CMD NOT FOUND
	if (xSemaphoreTake( sem_CmdUart, MSTOTAKECMDUARTSEMPH ) == pdTRUE ) {
		rprintfProgStrM(CMD_UART, "ERROR\r\n");
		rprintfProgStrM(CMD_UART, "CMD NOT DEFINED\r\n");
		xSemaphoreGive( sem_CmdUart );
	}
	return;

}