Esempio n. 1
0
void handle(int newsock){
	size_t buflen = 4095;
	char buffer[buflen + 1];
	bta_pars par;
	do{
		ssize_t readed = recv(newsock, buffer, buflen, 0);
		if(readed < 1) break; // client closed or error
		parce_incoming_buf(buffer, readed, &par);
		#ifdef EBUG
			#define checkpar(val) if(par.val){ fprintf(stderr, "par: %s\n", val); }
			if(par.ALL){ fprintf(stderr, "par: ALL\n"); }
			checkpar(vel);
			checkpar(diff);
			checkpar(corr);
			checkpar(mtime);
			checkpar(sidtime);
			checkpar(meteo);
			checkpar(target);
			checkpar(p2mode);
			checkpar(eqcoor);
			checkpar(telmode);
			checkpar(horcoor);
			checkpar(valsens);
			checkpar(telfocus);
			#undef checkpar
		#endif // EBUG
		make_JSON(newsock, &par);
	}while(!par.ALL);
	close(newsock);
}
Esempio n. 2
0
int main(){
	uint32_t Old_timer = 0;

	// RCC clocking: 8MHz oscillator -> 72MHz system
	rcc_clock_setup_in_hse_8mhz_out_72mhz();

	GPIO_init();

	usb_disconnect(); // turn off USB while initializing all
	steppers_init();

	// USB
	usbd_dev = USB_init();

	// SysTick is a system timer with 1ms period
	SysTick_init();

	// wait a little and then turn on USB pullup
//	for (i = 0; i < 0x800000; i++)
//		__asm__("nop");

	usb_connect(); // turn on USB

	while(1){
		usbd_poll(usbd_dev);
		if(usbdatalen){ // there's something in USB buffer
			usbdatalen = parce_incoming_buf(usbdatabuf, usbdatalen);
		}
		//check_and_parce_UART(USART1); // also check data in UART buffers
		if(Timer - Old_timer > 999){ // one-second cycle
			Old_timer += 1000;
		}else if(Timer < Old_timer){ // Timer overflow
			Old_timer = 0;
		}
	}
}
Esempio n. 3
0
int main(){
	//int i;
	uint32_t Shtr_blink_timer = 0, Old_timer = 0, lastTRDread = 0, lastTmon = 0, OW_timer = 0;
	int oldusbdatalen = 0;
	//SPI_read_status SPI_stat;

	// RCC clocking: 8MHz oscillator -> 72MHz system
	rcc_clock_setup_in_hse_8mhz_out_72mhz();

	// turn off SWJ/JTAG
	AFIO_MAPR = AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_OFF;

	// GPIO
	GPIO_init();
	usb_disconnect(); // turn off USB while initializing all

	// init USART3 (master) & USART1 (slave)
	UART_init(USART3);
	UART_init(USART1);

	// USB
	usbd_dev = USB_init();

	// SysTick is a system timer with 1mc period
	SysTick_init();

	// instead of SPI1 we use those pins to control shutter and system state
	// SPI2 used for working with external ADC
	switch_SPI(SPI2); // init SPI2
	SPI_init();

	// wait a little and then turn on USB pullup
//	for (i = 0; i < 0x800000; i++)
//		__asm__("nop");

	// init ADC
	ADC_init();
	ADC_calibrate_and_start();

	steppers_init();

	usb_connect(); // turn on USB
	shutter_init();

	read_stored_data(); // copy stored data into RAM

	init_ow_dmatimer();
	//OW_send_read_seq();

	LED_STATUS_OK(); // All initialized - light up LED
	while(1){
		init_on_poweron_proc();
		usbd_poll(usbd_dev);
		if(oldusbdatalen != usbdatalen){ // there's something in USB buffer
			usbdatalen = parce_incoming_buf(usbdatabuf, usbdatalen, usb_send);
			oldusbdatalen = usbdatalen;
		}
		check_and_parce_UART(USART3); // check data in master UART buffers
		check_and_parce_UART(USART1); // also check data in slave UART buffers
		if(ad7794_on){
			if(Timer != lastTRDread){ // run this not more than once in 1ms
				lastTRDread = Timer;
				read_next_TRD();
			}
		}
		OW_process(); // process 1-wire commands
		// scan 1-wire each 1 second
		if(OW_scan && (Timer - OW_timer > 999 || Timer < OW_timer)){
			OW_timer = Timer;
			scan_onewire();
		}
		process_stepper_motors(); // check flags of motors' timers
		process_shutter(); // shutter state machine

		if(Timer - Shtr_blink_timer > 500 ||  Timer < Shtr_blink_timer){
			Shtr_blink_timer = Timer;
			// shutter LED will be blinking until init occurs
			if(Shutter_State == SHUTTER_NOTREADY)
				gpio_toggle(LED_SHUTTER_PORT, LED_SHUTTER_PIN);
		}

		if(Timer - Old_timer > 999){ // one-second cycle
			Old_timer += 1000;
			// init shutter if error occurs
			if(Shutter_State == SHUTTER_NOTREADY){
				shutter_init();
			}
		}else if(Timer < Old_timer){ // Timer overflow
			Old_timer = 0;
			tOVRFL++; // this is an overflow counter - for workinkg in long-long time interval
		}

		if((Timer - lastTmon > 9999) || (Timer < lastTmon)){ // run constant monitoring of ADC values each 10 seconds
			lastTmon += 10000;
			if(ADC_monitoring){
				print_time(lastsendfun);
				print_int_ad_vals(lastsendfun);
				print_ad_vals(lastsendfun);
			}
		}
	}
}