DRONE/dronecommunication.c
void receive_data(serial_data_struct* pdata_package_receive_kopter, DroneInfo* CurrentDroneInfo){
	//fp = fopen ("GPS_Data.txt","a+");
	if (uart0_filestream != -1)
	{
		memset(pdata_package_receive_kopter->txrxdata, 0, 1023);
		{	
			int rx_length = read(uart0_filestream, (void*)pdata_package_receive_kopter->txrxdata, 512);		//Filestream, buffer to store in, number of bytes to read (max)
			if (rx_length > 0)
			{
					{
						//printf( "RECEIVED (len %d): ", rx_length);
						for(int i=0; i<rx_length;++i)
						{
							if(!(pdata_package_receive_kopter->txrxdata[i] == '\r'))
								printf( "%c", pdata_package_receive_kopter->txrxdata[i] );
						}
						//printf( " \n");	
					}
					pdata_package_receive_kopter->cmdLength = rx_length;
					pdata_package_receive_kopter->count = rx_length;
					pdata_package_receive_kopter->position = 0;
					while(get_char(pdata_package_receive_kopter))
					{
						if(!collect_data(pdata_package_receive_kopter))
						{
							pdata_package_receive_kopter->collecting = 0;
							pdata_package_receive_kopter->dataLength = pdata_package_receive_kopter->position_package;
							pdata_package_receive_kopter->position_package = 0;
							u16 crc = 0;
							u8 	crc1, crc2;
							for (int i = 0; i < pdata_package_receive_kopter->dataLength - 3; i++)
							{
								crc += pdata_package_receive_kopter->collecting_data[i];
							}
							crc %= 4096;
							crc1 = '=' + crc / 64;
							crc2 = '=' + crc % 64;
							if(crc1 == pdata_package_receive_kopter->collecting_data[pdata_package_receive_kopter->dataLength - 3] && crc2 == pdata_package_receive_kopter->collecting_data[pdata_package_receive_kopter->dataLength - 2])
							{
                                CurrentDroneInfo->streamInfo = uart0_filestream;
								analyze_data_package(pdata_package_receive_kopter, CurrentDroneInfo);
								//>> CRC OK
								pdata_package_receive_kopter->position_package = 0;
							}else{
								//>> CRC NOT OK
								//printf("RX Checksum Error\n");
                                CurrentDroneInfo->streamInfo = -1;
								pdata_package_receive_kopter->position_package = 0;
								memset(pdata_package_receive_kopter->collecting_data, 0, 1023);
							}
						}
                        else
                        {
                            CurrentDroneInfo->streamInfo = -1;
                        }
                        
					}
                /**/
			}
            else
            {
                CurrentDroneInfo->streamInfo = -1;
            }
            
		}
	}else{
		//printf("KOPTER RX Error\n");
        CurrentDroneInfo->streamInfo = uart0_filestream;
	}
	//fclose (fp);
	//return true;
}
//>> Receiving Data from the Kopter and collecting serial frame if needed
// from ExPlat project on Mikrokopter SVN
//------------------------------------------------------------------------------------------------------
>> Receiving Data from the Kopter and collecting serial frame if needed
from ExPlat project on Mikrokopter SVN
>> Receiving Data from the Kopter and collecting serial frame if needed from ExPlat project on Mikrokopter SVN
void receive_data(serial_data_struct* pdata_package_receive_kopter, DroneInfo* CurrentDroneInfo){
	if (uart0_filestream != -1)
	{
		memset(pdata_package_receive_kopter->txrxdata, 0, 1023);
		{	
			int rx_length = read(uart0_filestream, (void*)pdata_package_receive_kopter->txrxdata, 512);		
			if (rx_length > 0)
			{
					{
						for(int i=0; i<rx_length;++i)
						{
							if(!(pdata_package_receive_kopter->txrxdata[i] == '\r'))
								printf( "%c", pdata_package_receive_kopter->txrxdata[i] );
						}
					}
					pdata_package_receive_kopter->cmdLength = rx_length;
					pdata_package_receive_kopter->count = rx_length;
					pdata_package_receive_kopter->position = 0;
					while(get_char(pdata_package_receive_kopter))
					{
						if(!collect_data(pdata_package_receive_kopter))
						{
							pdata_package_receive_kopter->collecting = 0;
							pdata_package_receive_kopter->dataLength = pdata_package_receive_kopter->position_package;
							pdata_package_receive_kopter->position_package = 0;
							u16 crc = 0;
							u8 	crc1, crc2;
							for (int i = 0; i < pdata_package_receive_kopter->dataLength - 3; i++)
							{
								crc += pdata_package_receive_kopter->collecting_data[i];
							}
							crc %= 4096;
							crc1 = '=' + crc / 64;
							crc2 = '=' + crc % 64;
							if(crc1 == pdata_package_receive_kopter->collecting_data[pdata_package_receive_kopter->dataLength - 3] && crc2 == pdata_package_receive_kopter->collecting_data[pdata_package_receive_kopter->dataLength - 2])
							{
                                CurrentDroneInfo->streamInfo = uart0_filestream;
								analyze_data_package(pdata_package_receive_kopter, CurrentDroneInfo);
								pdata_package_receive_kopter->position_package = 0;
							}else{
                                CurrentDroneInfo->streamInfo = -1;
								pdata_package_receive_kopter->position_package = 0;
								memset(pdata_package_receive_kopter->collecting_data, 0, 1023);
							}
						}
                        else
                        {
                            CurrentDroneInfo->streamInfo = -1;
                        }
					}
			}
            else
            {
                CurrentDroneInfo->streamInfo = -1;
            }
		}
	}else{
        CurrentDroneInfo->streamInfo = uart0_filestream;
	}
}
void receive_data ( serial_data_struct * pdata_package_receive_kopter , DroneInfo * CurrentDroneInfo ) { if ( uart0_filestream != -1 ) { memset ( pdata_package_receive_kopter -> txrxdata , 0 , 1023 ) ; { int rx_length = read ( uart0_filestream , ( void * ) pdata_package_receive_kopter -> txrxdata , 512 ) ; if ( rx_length > 0 ) { { for ( int i = 0 ; i < rx_length ; ++ i ) { if ( ! ( pdata_package_receive_kopter -> txrxdata [ i ] == ' \r ' ) ) printf ( " " , pdata_package_receive_kopter -> txrxdata [ i ] ) ; } } pdata_package_receive_kopter -> cmdLength = rx_length ; pdata_package_receive_kopter -> count = rx_length ; pdata_package_receive_kopter -> position = 0 ; while ( get_char ( pdata_package_receive_kopter ) ) { if ( ! collect_data ( pdata_package_receive_kopter ) ) { pdata_package_receive_kopter -> collecting = 0 ; pdata_package_receive_kopter -> dataLength = pdata_package_receive_kopter -> position_package ; pdata_package_receive_kopter -> position_package = 0 ; u16 crc = 0 ; u8 crc1 , crc2 ; for ( int i = 0 ; i < pdata_package_receive_kopter -> dataLength - 3 ; i ++ ) { crc += pdata_package_receive_kopter -> collecting_data [ i ] ; } crc %= 4096 ; crc1 = ' ' + crc / 64 ; crc2 = ' ' + crc % 64 ; if ( crc1 == pdata_package_receive_kopter -> collecting_data [ pdata_package_receive_kopter -> dataLength - 3 ] && crc2 == pdata_package_receive_kopter -> collecting_data [ pdata_package_receive_kopter -> dataLength - 2 ] ) { CurrentDroneInfo -> streamInfo = uart0_filestream ; analyze_data_package ( pdata_package_receive_kopter , CurrentDroneInfo ) ; pdata_package_receive_kopter -> position_package = 0 ; } else { CurrentDroneInfo -> streamInfo = -1 ; pdata_package_receive_kopter -> position_package = 0 ; memset ( pdata_package_receive_kopter -> collecting_data , 0 , 1023 ) ; } } else { CurrentDroneInfo -> streamInfo = -1 ; } } } else { CurrentDroneInfo -> streamInfo = -1 ; } } } else { CurrentDroneInfo -> streamInfo = uart0_filestream ; } }
>> Receiving Data from the Kopter and collecting serial frame if needed
from ExPlat project on Mikrokopter SVN
>> Receiving Data from the Kopter and collecting serial frame if needed from ExPlat project on Mikrokopter SVN
//fp = fopen ("GPS_Data.txt","a+"); //Filestream, buffer to store in, number of bytes to read (max) //printf( "RECEIVED (len %d): ", rx_length); //printf( " \n");	 //>> CRC OK //>> CRC NOT OK //printf("RX Checksum Error\n"); /**/ //printf("KOPTER RX Error\n"); //fclose (fp); //return true;