示例#1
0
boolean handleUDBSockets(void)
{
	uint8_t buffer[BUFLEN];
	int32_t bytesRead;
	int16_t i;
	boolean didRead = false;
	
	// Handle GPS Socket
	if (gpsSocket) {
		bytesRead = UDBSocket_read(gpsSocket, buffer, BUFLEN);
		if (bytesRead < 0) {
			UDBSocket_close(gpsSocket);
			gpsSocket = NULL;
		}
		else {
			for (i=0; i<bytesRead; i++) {
				udb_gps_callback_received_byte(buffer[i]);
			}
			if (bytesRead>0) didRead = true;
		}
	}
	
	// Handle Telemetry Socket
	if (telemetrySocket) {
		bytesRead = UDBSocket_read(telemetrySocket, buffer, BUFLEN);
		if (bytesRead < 0) {
			UDBSocket_close(telemetrySocket);
			telemetrySocket = NULL;
		}
		else {
			for (i=0; i<bytesRead; i++) {
				udb_serial_callback_received_byte(buffer[i]);
			}
			if (bytesRead>0) didRead = true;
		}
	}
	
	// Handle optional Serial RC input Socket
	if (serialSocket) {
		bytesRead = UDBSocket_read(serialSocket, buffer, BUFLEN);
		if (bytesRead < 0) {
			UDBSocket_close(serialSocket);
			serialSocket = NULL;
		}
		else {
			if (bytesRead>0) {
				sil_handle_seial_rc_input(buffer, bytesRead);
				didRead = true;
			}
		}
	}
	
	return didRead;
}
示例#2
0
void __attribute__((__interrupt__, __no_auto_psv__)) _U1RXInterrupt(void)
{
	_U1RXIF = 0 ; // clear the interrupt
	indicate_loading_inter ;
	interrupt_save_set_corcon ;
	
	while ( U1STAbits.URXDA )
	{
		unsigned char rxchar = U1RXREG ;
		udb_gps_callback_received_byte(rxchar) ;
	}

	U1STAbits.OERR = 0 ;		
	interrupt_restore_corcon ;
	return ;
}
示例#3
0
void __attribute__((__interrupt__, __no_auto_psv__)) _U1RXInterrupt(void)
{
	_U1RXIF = 0; // clear the interrupt
	indicate_loading_inter;
	interrupt_save_set_corcon;
	
	while (U1STAbits.URXDA)
	{
		uint8_t rxchar = U1RXREG;
#if (HILSIM_USB != 1)
		udb_gps_callback_received_byte(rxchar);
#endif // HILSIM_USB
	}
	U1STAbits.OERR = 0;
	interrupt_restore_corcon;
}
示例#4
0
void CDCTasks(void)
{
	BYTE numBytesRead;

	// Blink the LEDs according to the USB device status
	if (blinkStatusValid)
	{
		BlinkUSBStatus();
	}

	// User Application USB tasks
	if ((USBDeviceState < CONFIGURED_STATE) || (USBSuspendControl == 1))
	{
		return;
	}

#if (HILSIM_USB == 1)
	numBytesRead = getsUSBUSART(USB_In_Buffer, sizeof(USB_In_Buffer));
	if (numBytesRead != 0)
	{
		int i = 0;
		while (i < numBytesRead)
		{
			udb_gps_callback_received_byte(USB_In_Buffer[i++]);
		}
	}

	if (mUSBUSARTIsTxTrfReady())
	{
		int i = 0;
		int txchar;
		while ((i < sizeof(USB_Out_Buffer)) && ((txchar = udb_gps_callback_get_byte_to_send()) != -1))
		{
			USB_Out_Buffer[i++] = txchar;
		}
		if (i > 0)
		{
			putUSBUSART(USB_Out_Buffer, i);
		}
	}

#else
	if (mUSBUSARTIsTxTrfReady())
	{
		numBytesRead = getsUSBUSART(USB_Out_Buffer, sizeof(USB_Out_Buffer));
		if (numBytesRead != 0)
		{
			BYTE i;

			for (i = 0; i < numBytesRead; i++)
			{
				switch (USB_Out_Buffer[i])
				{
					case 0x0A:
					case 0x0D:
						USB_In_Buffer[i] = USB_Out_Buffer[i];
						break;
					default:
						USB_In_Buffer[i] = USB_Out_Buffer[i] + 1;
						break;
				}
			}
			putUSBUSART(USB_In_Buffer, numBytesRead);
		}
	}
#endif
	CDCTxService();
}