Exemple #1
0
static void loadSystemParams(void)
{

u08 EEaddr;
s08 eeStatus = FALSE;
u08 i;
systemVarsType sVars;

	// Leo la configuracion:  Intento leer hasta 3 veces.
	EEaddr = EEADDR_START_PARAMS;
	for (i=0; i<3; i++) {
		eeStatus = paramLoad(&sVars, EEaddr, sizeof(systemVarsType));
		if (eeStatus == TRUE) break;
	}

	vTaskDelay( 100 / portTICK_RATE_MS );

	// Confirmo que pude leer bien.
	if ( (eeStatus == FALSE) || (sVars.initByte != 0x49) ) {
		// No pude leer la EE correctamente o es la primera vez que arranco.
		// Inicializo a default.
		snprintf_P( &cmd_printfBuff,CHAR128,PSTR("loadSystemParams::Load EE error: default !!\r\n\0") );
		logPrintStr(LOG_NONE, &cmd_printfBuff);

		loadDefaults(&sVars);
		// Almaceno en la EE para el proximo arranque.
		paramStore(&sVars, EEaddr, sizeof(systemVars));

	} else {
		// Pude leer la eeprom correctamente.
		snprintf_P( &cmd_printfBuff,CHAR128,PSTR("loadSystemParams::Load config ok !!\r\n\0") );
		logPrintStr(LOG_NONE, &cmd_printfBuff);
	}

	// Siempre debo arrancar con esto en FALSE para aguantar a las tareas.
	sVars.initStatus = FALSE;

	sVars.wrkMode = WK_NORMAL;
	strncpy_P(sVars.dlgIp, PSTR("000.000.000.000\0"),16);
	sVars.csq = 0;
	sVars.dbm = 0;
	sVars.dcd = 0;
	sVars.ri = 0;
	sVars.termsw = 0;

	// Actualizo el systemVars.
	if (xSemaphoreTake( sem_systemVars, MSTOTAKESYSTEMVARSSEMPH ) == pdTRUE ) {
		memcpy(&systemVars, &sVars, sizeof(systemVarsType));
		xSemaphoreGive( sem_systemVars );
	}

	snprintf_P( &cmd_printfBuff,CHAR128,PSTR("loadSystemParams::Config analogs=%d\r\n\0"), NRO_CHANNELS );
	logPrintStr(LOG_NONE, &cmd_printfBuff);

}
Exemple #2
0
void loadDefaults( void )
{
	// Valores por default.
u08 channel;

	while ( xSemaphoreTake( sem_SYSVars, ( TickType_t ) 10 ) != pdTRUE )
		taskYIELD();

	systemVars.initByte = 0x49;
	strncpy_P(systemVars.dlgId, PSTR("SPY999\0"),DLGID_LENGTH);
	strncpy_P(systemVars.serverPort, PSTR("80\0"),PORT_LENGTH	);
	strncpy_P(systemVars.passwd, PSTR("spymovil123\0"),PASSWD_LENGTH);
	strncpy_P(systemVars.serverScript, PSTR("/cgi-bin/sp5K/sp5K.pl\0"),SCRIPT_LENGTH);
//	strncpy_P(sVars->serverScript, PSTR("/cgi-bin/sp5K/test.pl\0"),SCRIPT_LENGTH);

	systemVars.csq = 0;
	systemVars.dbm = 0;
	systemVars.gsmBand = 8;
	systemVars.dcd = 0;
	systemVars.ri = 0;
	systemVars.termsw = 0;
	systemVars.wrkMode = WK_NORMAL;
	systemVars.pwrMode = PWR_CONTINUO;

	strncpy_P(systemVars.apn, PSTR("SPYMOVIL.VPNANTEL\0"),APN_LENGTH);

	// DEBUG
	//systemVars.debugLevel = D_NONE;
	//systemVars.debugLevel = D_DATA;
	//systemVars.debugLevel = D_GPRS + D_DIGITAL;
	//systemVars.debugLevel = D_BASIC + D_GPRS;
	systemVars.debugLevel = D_BASIC;

	strncpy_P(systemVars.serverAddress, PSTR("192.168.0.9\0"),IP_LENGTH);
	systemVars.timerPoll = 60;			// Poleo c/5 minutos
	systemVars.timerDial = 10800;		// Transmito c/3 hs.

	systemVars.pwrSave = modoPWRSAVE_OFF;
	systemVars.pwrSaveStartTime =pv_convertHHMM2min(2230);	// 22:30 PM
	systemVars.pwrSaveEndTime =	pv_convertHHMM2min(630);	// 6:30 AM

	// Todos los canales quedan por default en 0-20mA, 0-6k.
	for ( channel = 0; channel < NRO_CHANNELS; channel++) {
		systemVars.Imin[channel] = 0;
		systemVars.Imax[channel] = 20;
		systemVars.Mmin[channel] = 0;
		systemVars.Mmax[channel] = 6.0;
		systemVars.offmmin[channel] = 0.0;
		systemVars.offmmax[channel] = 0.0;
	}

	strncpy_P(systemVars.aChName[0], PSTR("pA\0"),3);
	strncpy_P(systemVars.aChName[1], PSTR("pB\0"),3);
	strncpy_P(systemVars.aChName[2], PSTR("pC\0"),3);

	// Canales digitales
	strncpy_P(systemVars.dChName[0], PSTR("v0\0"),3);
	systemVars.magPP[0] = 0.1;
	strncpy_P(systemVars.dChName[1], PSTR("v1\0"),3);
	systemVars.magPP[1] = 0.1;

	// Salidas
	systemVars.outputs.wrkMode = OUTPUT_CONSIGNA;
	systemVars.outputs.dout[0] = 0;
	systemVars.outputs.dout[1] = 0;
	systemVars.outputs.dout[2] = 0;
	systemVars.outputs.dout[3] = 0;
	systemVars.outputs.horaConsDia = pv_convertHHMM2min(530);		// Consigna diurna
	systemVars.outputs.horaConsNoc = pv_convertHHMM2min(2330);		// Consigna nocturna
	systemVars.outputs.chVA = 0;
	systemVars.outputs.chVB = 1;

	// Almaceno en la EE para el proximo arranque.
	paramStore(&systemVars, EEADDR_START_PARAMS, sizeof(systemVars));

	xSemaphoreGive( sem_SYSVars );

}