示例#1
0
void RTC_late()
{
   float time_now = 0;
   float time_alarm = 0;
   float fraction_of_day = 0;
   float hour, minute, second;
   
   //                        J F  M  A  M   J   J   A   S   O   N   D
   int16 end_of_month[12] = {0,31,59,90,120,151,181,212,243,273,304,334};
   //                        0  1  2  3   4   5   6   7   8   9  10  11
   
   alarm_passed = FALSE;
   
   RTC_read();
   RTC_read_alarm();
   RTC_Al_Yr_Reg = read8(ADDR_ALARM_YR);
   // if current year > alarm year .. alarm is in the past
   if (RTC_Yr_Reg > RTC_Al_Yr_Reg) alarm_passed = TRUE;
   else {
      // if current year = alarm year .. test rest of fields
      if (RTC_Yr_Reg == RTC_Al_Yr_Reg) {
      
         // calculate fractional current time
         time_now = end_of_month[RTC_Mon_Reg-1];
         time_now = time_now + RTC_DOM_Reg;
         
         hour = RTC_Hr_Reg;
         minute = RTC_Min_Reg;
         second = RTC_Sec_Reg;
         
         fraction_of_day = (hour / 24);
         fraction_of_day = fraction_of_day + (minute / (24*60));
         fraction_of_day = fraction_of_day + (second / (24*60*60));
         
         time_now = time_now + fraction_of_day;
         
         // calculate fractional alarm time
         hour = RTC_Al_Hr_Reg;
         minute = RTC_Al_Min_Reg;
         second = RTC_Al_Sec_Reg;
         
         time_alarm = end_of_month[RTC_Al_Mon_Reg-1];
         time_alarm = time_alarm + RTC_Al_DOM_Reg;
         
         fraction_of_day = (hour / 24);
         fraction_of_day = fraction_of_day + (minute / (24*60));
         fraction_of_day = fraction_of_day + (second / (24*60*60));
         
         time_alarm = time_alarm + fraction_of_day;
         
         // compare real and alarm time
         if (time_now > time_alarm) alarm_passed = TRUE;
      }
   }
}
示例#2
0
void time_stamp()
{
   int16 v_supply;
   
   clear_time_stmp_str();
   
   v_supply = read_supply();
   RTC_read();
   
   sprintf (time_stmp_str, "%02u/%02u/%02u %02u:%02u:%02u,%04.2w",
      RTC_Mon_Reg,RTC_DOM_Reg,RTC_Yr_Reg,RTC_Hr_Reg,RTC_Min_Reg,RTC_Sec_Reg,v_supply);
}
示例#3
0
/*------------------------------------------------------------------------------------*/
char *u_now(void)
{

	// Devuelve un puntero a un string con la fecha y hora formateadas para usar en
	// los mensajes de log.

RtcTimeType_t rtcDateTime;

	RTC_read(&rtcDateTime);
	rtcDateTime.year -= 2000;
	snprintf_P( nowStr,sizeof(nowStr), PSTR("%02d/%02d/%02d %02d:%02d:%02d\0"),rtcDateTime.day,rtcDateTime.month,rtcDateTime.year,rtcDateTime.hour,rtcDateTime.min,rtcDateTime.sec );
	return(nowStr);
}
示例#4
0
int8 master_macro_aws(int16 step){

   int16 addr;
   
   int8  macro_cmd[2];
   int16 macro_arg[2];
   int8  macro_end;
   
   --step;
   addr = macro_address[0] + (step*6);
   
   init_ext_eeprom();
   
   // port
   macro_cmd[0] = read_ext_eeprom(addr);
   ++addr;
   macro_arg[0] = read16_ext_eeprom(addr);
   ++addr;
   ++addr;
   // macro
   macro_cmd[1] = read_ext_eeprom(addr);
   ++addr;
   macro_arg[1] = read16_ext_eeprom(addr);
   ++addr;
   ++addr;
   
   macro_end = read_ext_eeprom(addr);
   
   // check basic structure
   if (macro_cmd[0] == 'P' && macro_cmd[1] == 'M') {
      
      RTC_read();
      RTC_display();
      fprintf(COM_A, "%c%Lu,%c%Lu\r\n",
         macro_cmd[0], macro_arg[0],            // port
         macro_cmd[1], macro_arg[1]);           // macro

      if (macro_arg[1] > 0 && macro_arg[1] < 17) {
         play_macro(macro_arg[1], macro_arg[0]);   // [1] casts to int8 / [0] = port
      }
   }
   else {
      cmd_err();
      macro_end = 59;
   }
   
   return (macro_end);
}
示例#5
0
/*------------------------------------------------------------------------------------*/
void pv_cmdRdRTC(void)
{
RtcTimeType_t rtcDateTime;
s08 retS = FALSE;
u08 pos;

	retS = RTC_read(&rtcDateTime);
	if (retS ) {
		pos = snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("OK\r\n"));
		pos += snprintf_P( &cmd_printfBuff[pos],(sizeof(cmd_printfBuff) - pos ),PSTR("%02d/%02d/%04d "),rtcDateTime.day,rtcDateTime.month, rtcDateTime.year );
		pos += snprintf_P( &cmd_printfBuff[pos],(sizeof(cmd_printfBuff) - pos ),PSTR("%02d:%02d:%02d\r\n\0"),rtcDateTime.hour,rtcDateTime.min, rtcDateTime.sec );
	} else {
		snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("ERROR\r\n\0"));
	}
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );
	return;
}
//------------------------------------------------------------------------------------
static int gTR_A04(void)
{
	// Expiro el tiempo de espera. Debo discar.
	// Evaluo si estoy dentro de un intervalo de pwrSave

RtcTimeType_t rtcDateTime;
u16 now;

	pwrSave_f = FALSE;

	// Si estoy en modo discreto con pwrSave habilitado
	if ( ( systemVars.pwrMode == PWR_DISCRETO ) && ( systemVars.pwrSave == modoPWRSAVE_ON ) ) {

		RTC_read(&rtcDateTime);
		now = rtcDateTime.hour * 60 + rtcDateTime.min;	// Hora actual en minutos desde las 00:00

		// Caso 1:
		if ( systemVars.pwrSaveStartTime < systemVars.pwrSaveEndTime ) {
			if ( ( now > systemVars.pwrSaveStartTime) && ( now < systemVars.pwrSaveEndTime) ) {
				pwrSave_f = TRUE;
				goto quit;
			}
		}

		// Caso 2:
		if ( systemVars.pwrSaveStartTime >= systemVars.pwrSaveEndTime ) {
			if ( ( now < systemVars.pwrSaveEndTime) || ( now > systemVars.pwrSaveStartTime ) ) {
				pwrSave_f = TRUE;
				goto quit;
			}
		}

	}

quit:

	g_printExitMsg("A04\0");
	return(gSST_MODEMAPAGADO_02);

}
示例#7
0
/*------------------------------------------------------------------------------------*/
static void cmdStatusFunction(void)
{

RtcTimeType_t rtcDateTime;
u16 pos;
u08 channel;
frameData_t Cframe;
StatBuffer_t pxFFStatBuffer;

	memset( &cmd_printfBuff, '\0', sizeof(cmd_printfBuff));
	snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("\r\nSpymovil %s %s %dch %s %s\r\n\0"), SP5K_MODELO, SP5K_VERSION, NRO_CHANNELS, SP5K_REV, SP5K_DATE);
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	// Last reset info
	pos = snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("Wdg (0x%X"),wdgStatus.resetCause);
	if (wdgStatus.resetCause & 0x01 ) {
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR(" PORF"));
	}
	if (wdgStatus.resetCause & 0x02 ) {
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR(" EXTRF"));
	}
	if (wdgStatus.resetCause & 0x04 ) {
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR(" BORF"));
	}
	if (wdgStatus.resetCause & 0x08 ) {
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR(" WDRF"));
	}
	if (wdgStatus.resetCause & 0x10 ) {
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR(" JTRF"));
	}
	pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR(" )\r\n\0"));
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	/* DlgId */
	snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("dlgid: %s\r\n\0"), systemVars.dlgId );
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	/* Fecha y Hora */
	RTC_read(&rtcDateTime);
	pos = snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("rtc: %02d/%02d/%04d "),rtcDateTime.day,rtcDateTime.month, rtcDateTime.year );
	pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("%02d:%02d:%02d\r\n\0"),rtcDateTime.hour,rtcDateTime.min, rtcDateTime.sec );
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	/* SERVER */
	snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR(">Server:\r\n\0"));
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	/* APN */
	snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("  apn: %s\r\n\0"), systemVars.apn );
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	/* SERVER IP:SERVER PORT */
	snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("  server ip:port: %s:%s\r\n\0"), systemVars.serverAddress,systemVars.serverPort );
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	/* SERVER SCRIPT */
	snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("  server script: %s\r\n\0"), systemVars.serverScript );
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	/* SERVER PASSWD */
	snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("  passwd: %s\r\n\0"), systemVars.passwd );
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	// MODEM ---------------------------------------------------------------------------------------
	snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR(">Modem:\r\n\0"));
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	/* Modem band */
	pos = snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("  band: "));
	switch ( systemVars.gsmBand) {
	case 0:
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("(900)"));
		break;
	case 1:
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("(1800)"));
		break;
	case 2:
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("dual band (900/1800)"));
		break;
	case 3:
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("pcs (1900)"));
		break;
	case 4:
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("gsm (850)"));
		break;
	case 5:
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("dual band (1900/850)"));
		break;
	case 6:
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("triband (900/1800/1900)"));
		break;
	case 7:
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("triband (850/1800/1900)"));
		break;
	case 8:
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("cuatriband (850/900/1800/1900)"));
		break;
	}
	pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("\r\n\0"));
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	/* ROAMING */
	if ( systemVars.roaming == TRUE ) {
		snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("  roaming ON\r\n\0"));
	} else {
		snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("  roaming OFF\r\n\0"));
	}
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	/* DLGIP */
	snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("  dlg ip: %s\r\n\0"), systemVars.dlgIp );
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	/* CSQ */
	snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("  signalQ: csq=%d, dBm=%d\r\n\0"), systemVars.csq, systemVars.dbm );
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	// SYSTEM ---------------------------------------------------------------------------------------
	snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR(">System:\r\n\0"));
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	/* Memoria */
	FF_stat(&pxFFStatBuffer);
	snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("  memory: wrPtr=%d,rdPtr=%d,delPtr=%d,Free=%d,4del=%d \r\n"), pxFFStatBuffer.HEAD,pxFFStatBuffer.RD, pxFFStatBuffer.TAIL,pxFFStatBuffer.rcdsFree,pxFFStatBuffer.rcds4del );
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	/* WRK mode (NORMAL / SERVICE) */
	pos = snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("  wrkmode: "));
	/* WRK mode (NORMAL / SERVICE) */
	switch (systemVars.wrkMode) {
	case WK_NORMAL:
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("normal\r\n"));
		break;
	case WK_SERVICE:
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("service\r\n"));
		break;
	case WK_MONITOR_FRAME:
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("monitor_frame\r\n"));
		break;
	case WK_MONITOR_SQE:
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("monitor_sqe\r\n"));
		break;
	default:
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("ERROR\r\n"));
		break;
	}
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	/* Timers */
	snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("  timerPoll [%ds]: %d\r\n\0"),systemVars.timerPoll, u_readTimeToNextPoll() );
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	/* DebugLevel */
	pos = snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("  debugLevel: "));
	if ( systemVars.debugLevel == D_NONE) {
		pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("none") );
	} else {
		if ( (systemVars.debugLevel & D_BASIC) != 0) { pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("+basic")); }
		if ( (systemVars.debugLevel & D_DATA) != 0) { pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("+data")); }
		if ( (systemVars.debugLevel & D_GPRS) != 0) { pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("+gprs")); }
		if ( (systemVars.debugLevel & D_MEM) != 0)   { pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("+mem")); }
		if ( (systemVars.debugLevel & D_DEBUG) != 0)  { pos += snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("+debug")); }
	}
	snprintf_P( &cmd_printfBuff[pos],sizeof(cmd_printfBuff),PSTR("\r\n\0"));
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	// Log
	if ( systemVars.log == ON ) {
		snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("  log: ON\r\n\0"));
	} else {
		snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("  log: OFF\r\n\0"));
	}
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	/* CONFIG */
	snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR(">Config:\r\n\0"));
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	for ( channel = 0; channel < NRO_CHANNELS; channel++) {
		snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("  Ch%d->%s\r\n\0"),channel, systemVars.chName[channel] );
		FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );
	}

	/* VALUES --------------------------------------------------------------------------------------- */
	memset(&Cframe,'\0', sizeof(frameData_t));
	u_readDataFrame (&Cframe);
	snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR(">Values:\r\n\0"));
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

	pos = snprintf_P( cmd_printfBuff, sizeof(cmd_printfBuff), PSTR("  "));
	// TimeStamp.
	pos += snprintf_P( &cmd_printfBuff[pos], sizeof(cmd_printfBuff),PSTR( "%04d%02d%02d,"),Cframe.rtc.year,Cframe.rtc.month,Cframe.rtc.day );
	pos += snprintf_P( &cmd_printfBuff[pos], sizeof(cmd_printfBuff), PSTR("%02d%02d%02d,"),Cframe.rtc.hour,Cframe.rtc.min, Cframe.rtc.sec );
	// Valores analogicos
	pos += snprintf_P( &cmd_printfBuff[pos], sizeof(cmd_printfBuff), PSTR("%s=%d,"),systemVars.chName[0],Cframe.inputs[0] );
	pos += snprintf_P( &cmd_printfBuff[pos], sizeof(cmd_printfBuff), PSTR("%s=%d,"),systemVars.chName[1],Cframe.inputs[1] );
	pos += snprintf_P( &cmd_printfBuff[pos], sizeof(cmd_printfBuff), PSTR("%s=%d"),systemVars.chName[2],Cframe.inputs[2] );

	pos += snprintf_P( &cmd_printfBuff[pos], sizeof(cmd_printfBuff), PSTR("\r\n\0") );
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );

}
示例#8
0
void main()
{
   disable_interrupts(GLOBAL);
   
   setup_spi(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 );
   setup_spi2(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 );
   
   setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|VSS_4V096);
   setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0);

   // TIMER 0 is being used to service the WTD
   setup_timer_0(T0_INTERNAL|T0_DIV_256);
   /* sets the internal clock as source and prescale 256. 
      At 10 Mhz timer0 will increment every 0.4us (Fosc*4) in this setup and overflows every
      6.71 seconds. Timer0 defaults to 16-bit if RTCC_8_BIT is not used.
      Fosc = 10 MHz, Fosc/4 = 2.5 Mhz, div 256 = 0.0001024 s, 65536 increments = 6.71 sec
      Fosc = 64 MHz, Fosc/4 = 16 Mhz, div 256 = 0.000016 s, 65536 increments = 1.05 sec
      .. pre-load with 3036 to get exact 1.0000 sec value
   */
   
   // TIMER 1 is used to extinguish the LED
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   /* sets the internal clock as source and prescale 4. 
      At 10Mhz timer0 will increment every 0.4us in this setup and overflows every
      104.8 ms. Timer1 is 16-bit.
      Fosc = 10 Mhz ... 2.5 MHz / div 4  = 0.00000160 s * 65536 = 0.104858 sec
      Fosc = 64 Mhz ... 16 MHz /  div 4  = 0.00000025 s * 65536 = 0.016384 sec
      Fosc = 64 Mhz ... 16 MHz /  div 8  = 0.00000200 s * 65536 = 0.032768 sec
   */   
   
   setup_stepper_pwm();  // Uses TIMER 2
   
   // TIMER 3 is used for stepper motor intervals
   setup_timer_3(T3_INTERNAL | T3_DIV_BY_1);   // 16 bit timer
   
   // TIMER 4 is use for serial time-outs. 8-bit timer.
   setup_timer_4(T4_DIV_BY_4, 127, 1);           
   
   setup_comparator(NC_NC_NC_NC);
   
   setup_oscillator(OSC_16MHZ | OSC_PLL_ON);  // Fosc = 64 MHz
          
   ext_int_edge(0, H_TO_L);         // Set up PIC18 EXT0
   enable_interrupts(INT_EXT);
   
   start_heartbeat();
   
   enable_interrupts(GLOBAL);

   init_hardware();
   motor_sleep_rdy();
   
   sleep_mode = FALSE;   
   busy_set();
   
   init_nv_vars();
   get_step_vars();
   init_aws();
   
   blink();
   
   //Add for TCP/IP interface
   //delay_ms(15000);
   
   signon();
   
   RTC_read();
   RTC_last_power();
   RTC_reset_HT();  
   RTC_read();    
   RTC_read_flags();
   
   if(nv_sd_status>0) fprintf(COM_A,"@SD=%Lu\r\n", nv_sd_status);
   init_rtc(); // This is the FAT RTC
   sd_status = init_sdcard();
   if(sd_status>0) msg_card_fail();
   
   reset_event();
   
   if(m_error[0] > 0 || m_error[1] > 0) msg_mer();  
   
   if (m_comp[0]==FALSE) {
      e_port[0]=0;
      write16(ADDR_E1_PORT,0);
      fprintf(COM_A, "@MC1,%Lu,%Ld\r\n", m_comp[0],e_port[0]);
   }
   if (m_comp[1]==FALSE) {
      m_lin_pos[1]=-1;
      write16(ADDR_M2_LIN_POS, -1);
      fprintf(COM_A, "@MC2,%Lu,%Ld\r\n", m_comp[1],m_lin_pos[1]);
   }
   
   if (nv_cmd_mode == FALSE){
      for(dt=0; dt<100; ++dt){
         blip();
         if (nv_cmd_mode == TRUE) {
            busy_clear();
            fputs("@OK!", COM_A);
            command_prompt();
            dt = 100;
         }
      }
   }
   else command_prompt();
   
   user_quit = auto_sample_ready();
   
   reset_cpu();
}
int main(void)
{
	
	//Initialise the UART
	UART_Init(9600);
	UART_writeString("Welcome\r\n");
	
	//Initialise the I2C Interface at 200kHz
	I2C_init(200);
	
	//Initialise the RTC, and show whether oscillator started successfully
	if (RTC_Init(RTC_ADDRESS, 1, 1))
	{
		UART_writeString("Oscillator is Running\r\n");
	}
	else
	{
		UART_writeString("ERROR: Oscillator did NOT start\r\n");
	}
	
	
	//Read the Time from the RTC
	tempVar = RTC_GetTime(RTC_ADDRESS, &timeYear, &timeMonth, &timeDay, &timeWeekDay, &timeHr, &timeAmPm, &timeMin, &timeSec);	
	
	//If Year is one and month is one and day is one, assume time not set (these are the Power-On-Reset values).
	//Set the Time
	if ((timeYear == 1) && (timeMonth ==1) && (timeDay == 1))
	{
		tempVar = RTC_SetTime(RTC_ADDRESS, 15,12,31,5,23,1,59,15);
	}
	

	//Check if Oscillator Running after time was set
	tempVar = RTC_read(RTC_ADDRESS, MCP794_RTCWKDAY);	

	if (!(tempVar & (1<<MCP794_OSCRUN)))
	{
		UART_writeString("Oscillator NOT Running\r\n\r\n");
	}
	else
	{
		#if DEBUGLEVEL > 2
		UART_writeString("Oscillator is Running\r\n");
		#endif
	}
	
    while(1)
    {
		_delay_ms(5000);	//Only read the time every 5 seconds
		
		//Read the Time
		tempVar = RTC_GetTime(RTC_ADDRESS, &timeYear, &timeMonth, &timeDay, &timeWeekDay, &timeHr, &timeAmPm, &timeMin, &timeSec);	//Reset minutes to zero
		
		//Print the time over the UART
		UART_writeString("\r\nTimecheck: ");
		UART_printDecimal(timeDay,2);
		UART_writeString("/");
		UART_printDecimal(timeMonth,2);
		UART_writeString("/20");
		UART_printDecimal(timeYear,2);
		
		UART_writeString("   ");
		UART_printDecimal(timeHr,2);
		UART_writeString(":");
		UART_printDecimal(timeMin,2);
		UART_writeString(":");
		UART_printDecimal(timeSec,2);
		UART_writeString("\r\n");

		
    }
}
示例#10
0
/*------------------------------------------------------------------------------------*/
static int anTR_07(void)
{
	// En modo discreto apago los sensores.
	// Promedio
	// Convierto a magnitud.
	// Completo el frame con fechaHora y datos digitales.
	// Imprimo
	// Si corresponde, salvo en BD.


u32 tickCount;
double I,M;
u08 i;
u16 D;
u08 channel;
u16 pos = 0;
size_t bWrite;
StatBuffer_t pxFFStatBuffer;

	//  En modo discreto debo apagar sensores
	if ( systemVars.pwrMode == PWR_DISCRETO )  {
		pv_ApagarSensores();
	}

	// Promedio canales analogicos y bateria
	for ( channel = 0; channel < (NRO_ANALOG_CHANNELS + 1); channel++) {
		rAIn[channel] /= CICLOS_POLEO;
		tickCount = xTaskGetTickCount();
		snprintf_P( aIn_printfBuff,CHAR128,PSTR(".[%06lu] tkAnalogIn::trD06 AvgCh[%d]=%.02f\r\n\0"), tickCount, channel, rAIn[channel]);
		u_debugPrint(D_DATA, aIn_printfBuff, sizeof(aIn_printfBuff) );
	}

	// Convierto los canales analogicos a magnitudes.
	for ( channel = 0; channel < NRO_ANALOG_CHANNELS ; channel++) {
		// Calculo la corriente medida en el canal
		I = rAIn[channel] * systemVars.Imax[channel] / 4096;
		// Calculo la pendiente
		M = 0;
		D = systemVars.Imax[channel] - systemVars.Imin[channel];
		if ( D != 0 ) {
			M = ( systemVars.Mmax[channel]  -  systemVars.Mmin[channel] ) / D;
			rAIn[channel] = systemVars.Mmin[channel] + M * ( I - systemVars.Imin[channel] );
		} else {
			// Error: denominador = 0.
			rAIn[channel] = -999;
		}
	}

#ifdef OSE_3CH

	// Convierto la bateria.
	rAIn[NRO_ANALOG_CHANNELS] = (15 * rAIn[NRO_ANALOG_CHANNELS]) / 4096;	// Bateria

	// DEBUG
	for ( channel = 0; channel <= NRO_ANALOG_CHANNELS; channel++) {
		tickCount = xTaskGetTickCount();
		snprintf_P( aIn_printfBuff,CHAR128,PSTR(".[%06lu] tkAnalogIn::trD06 MagCh[%d]=%.02f\r\n\0"), tickCount, channel, rAIn[channel]);
		u_debugPrint(D_DATA, aIn_printfBuff, sizeof(aIn_printfBuff) );
	}
#endif

#ifdef UTE_8CH
	// DEBUG
	for ( channel = 0; channel < NRO_ANALOG_CHANNELS; channel++) {
		tickCount = xTaskGetTickCount();
		snprintf_P( aIn_printfBuff,CHAR128,PSTR(".[%06lu] tkAnalogIn::trD06 MagCh[%d]=%.02f\r\n\0"), tickCount, channel, rAIn[channel]);
		u_debugPrint(D_DATA, aIn_printfBuff, sizeof(aIn_printfBuff) );
	}
#endif

	// Armo el frame.
	RTC_read(&Aframe.rtc);

	// Analogico
	for ( channel = 0; channel < NRO_ANALOG_CHANNELS; channel++) {
		Aframe.analogIn[channel] = rAIn[channel];
	}

#ifdef OSE_3CH
	// Bateria
	Aframe.batt = rAIn[3];
#endif

	// Digital
	u_readDigitalCounters( &Aframe.dIn, TRUE );
	// Convierto los pulsos a los valores de la magnitud.
	for ( i = 0; i < NRO_DIGITAL_CHANNELS; i++ ) {
		Aframe.dIn.pulses[i] *=  systemVars.magPP[i];
	}
#if !defined(SERIAL)
	// Guardo en BD ?
	if ( AN_flags.saveFrameInBD ) {
		AN_flags.saveFrameInBD = FALSE;
		bWrite = FF_fwrite( &Aframe, sizeof(Aframe));
		FF_stat(&pxFFStatBuffer);

		if ( bWrite != sizeof(Aframe) ) {
			// Error de escritura ??
			snprintf_P( aIn_printfBuff,sizeof(aIn_printfBuff),PSTR("WR ERROR: (%d)\r\n\0"),pxFFStatBuffer.errno);
		} else {
			// Stats de memoria
			snprintf_P( aIn_printfBuff, sizeof(aIn_printfBuff), PSTR("MEM [%d/%d/%d][%d/%d]\r\n\0"), pxFFStatBuffer.HEAD,pxFFStatBuffer.RD, pxFFStatBuffer.TAIL,pxFFStatBuffer.rcdsFree,pxFFStatBuffer.rcds4del);
		}
		u_debugPrint(D_BASIC, aIn_printfBuff, sizeof(aIn_printfBuff) );
	}
#endif

#ifdef UTE_8CH
	// Imprimo el frame.
	pos = snprintf_P( aIn_printfBuff, sizeof(aIn_printfBuff), PSTR("FRAME::{" ));
	// timeStamp.
	pos += snprintf_P( &aIn_printfBuff[pos], ( sizeof(aIn_printfBuff) - pos ),PSTR( "%04d%02d%02d,"),Aframe.rtc.year,Aframe.rtc.month,Aframe.rtc.day );
	pos += snprintf_P( &aIn_printfBuff[pos], ( sizeof(aIn_printfBuff) - pos ), PSTR("%02d%02d%02d"),Aframe.rtc.hour,Aframe.rtc.min, Aframe.rtc.sec );
	// Valores analogicos
	for ( channel = 0; channel < NRO_ANALOG_CHANNELS; channel++) {
		pos += snprintf_P( &aIn_printfBuff[pos], ( sizeof(aIn_printfBuff) - pos ), PSTR(",%s=%.02f"),systemVars.aChName[channel],Aframe.analogIn[channel] );
	}

#ifdef SERIAL
	// Valores digitales
	for ( channel = 0; channel < NRO_DIGITAL_CHANNELS; channel++) {
		pos += snprintf_P( &aIn_printfBuff[pos], ( sizeof(aIn_printfBuff) - pos ), PSTR(",%s_P=%.02f,%s_L=%d"), systemVars.dChName[channel],Aframe.dIn.pulses[channel], systemVars.dChName[channel],Aframe.dIn.level[channel] );
	}
#else
	// Valores digitales
	for ( channel = 0; channel < NRO_DIGITAL_CHANNELS; channel++) {
		pos += snprintf_P( &aIn_printfBuff[pos], ( sizeof(aIn_printfBuff) - pos ), PSTR(",%s{P=%.02f,L=%d,T=%d}"), systemVars.dChName[channel],Aframe.dIn.pulses[channel],Aframe.dIn.level[channel],Aframe.dIn.secsUp[channel] );
	}
#endif

	pos += snprintf_P( &aIn_printfBuff[pos], ( sizeof(aIn_printfBuff) - pos ), PSTR("}\r\n\0") );

	u_logPrint (aIn_printfBuff, sizeof(aIn_printfBuff) );

#ifdef SERIAL
	if ( systemVars.log == OFF ) {
		FreeRTOS_write( &pdUART1, aIn_printfBuff, sizeof(aIn_printfBuff) );
	}
#endif

#endif

#ifdef OSE_3CH
	// Imprimo el frame.
	pos = snprintf_P( aIn_printfBuff, sizeof(aIn_printfBuff), PSTR("FRAME::{" ));
	// timeStamp.
	pos += snprintf_P( &aIn_printfBuff[pos], ( sizeof(aIn_printfBuff) - pos ),PSTR( "%04d%02d%02d,"),Aframe.rtc.year,Aframe.rtc.month,Aframe.rtc.day );
	pos += snprintf_P( &aIn_printfBuff[pos], ( sizeof(aIn_printfBuff) - pos ), PSTR("%02d%02d%02d"),Aframe.rtc.hour,Aframe.rtc.min, Aframe.rtc.sec );
	// Valores analogicos
	for ( channel = 0; channel < NRO_ANALOG_CHANNELS; channel++) {
		pos += snprintf_P( &aIn_printfBuff[pos], ( sizeof(aIn_printfBuff) - pos ), PSTR(",%s=%.02f"),systemVars.aChName[channel],Aframe.analogIn[channel] );
	}
	// Valores digitales
	for ( channel = 0; channel < NRO_DIGITAL_CHANNELS; channel++) {
		pos += snprintf_P( &aIn_printfBuff[pos], ( sizeof(aIn_printfBuff) - pos ), PSTR(",%sP=%.02f"), systemVars.dChName[channel],Aframe.dIn.pulses[channel] );
	}
	// Bateria
	pos += snprintf_P( &aIn_printfBuff[pos], ( sizeof(aIn_printfBuff) - pos ), PSTR(",bt=%.02f}\r\n\0"),Aframe.batt );
	FreeRTOS_write( &pdUART1, aIn_printfBuff, sizeof(aIn_printfBuff) );
#endif


#ifdef CONSIGNA
	// Envio un mensaje a la tarea de la consigna diciendole que estan los datos listos
	if ( systemVars.consigna.type == CONSIGNA_CONTINUA ) {
		while ( xTaskNotify(xHandle_tkConsignas, TKC_FRAME_READY , eSetBits ) != pdPASS ) {
			vTaskDelay( ( TickType_t)( 100 / portTICK_RATE_MS ) );
		}
	//	snprintf_P( aIn_printfBuff,sizeof(aIn_printfBuff),PSTR("DEBUG SEND MSG 2 CC\r\n\0"));
	//	FreeRTOS_write( &pdUART1, aIn_printfBuff,sizeof(aIn_printfBuff) );
	}
#endif

	AN_flags.start2poll = FALSE;

	pv_AINprintExitMsg(7);
	return(anST_A01);
}