コード例 #1
0
ファイル: sock.c プロジェクト: Cloudxtreme/hybserv2
int
CompleteHubConnection(struct Servlist *hubptr)

{
	int errval;
	socklen_t errlen;

	assert(hubptr != 0);

	ClearHubConnect(hubptr);

	errval = 0;
	errlen = sizeof(errval);

	if (getsockopt(HubSock, SOL_SOCKET, SO_ERROR,
	               (void *)&errval, &errlen) == -1)
	{
		putlog(LOG1, "getsockopt(SO_ERROR) failed: %s", strerror(errno));
		return 0;
	}

	if (errval > 0)
	{
		putlog(LOG1,
		       "Error connecting to %s tcp/%d: %s",
		       hubptr->hostname, hubptr->port, strerror(errval));

		return 0;
	}

	signon();

	hubptr->connect_ts = current_ts;

#ifdef RECORD_RESTART_TS
	most_recent_sjoin = current_ts;
#endif

	SendUmode(OPERUMODE_Y, "*** Connected to %s tcp/%d",
	          hubptr->hostname, hubptr->port);
	putlog(LOG1, "Connected to %s tcp/%d", hubptr->hostname, hubptr->port);

	burst_complete = 0;

	return 1;
} /* CompleteHubConnection() */
コード例 #2
0
ファイル: main.c プロジェクト: frazahod/SUBGEN-NuLAB-EcoLAB-
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();
}