⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 senddatagramv3.0.c

📁 这是一个linux下基于MiniGUI的手机界面设计源码
💻 C
📖 第 1 页 / 共 3 页
字号:
				Reset( );
				DecimalToHex(Ant_AltitudeVal,0);
				ToHexChar( &AntAltitude,4 );

				for( i=0;i<4;i++ )
				{
					printf("%X ", AntAltitude[i]);
     				DataGram[count++]= AntAltitude[i];
				}
   				DataGram[count]='\0';
   				printf("\n");
				free( AntAltitude );
				AntAltitude= NULL;

				printf("Now3 it is:");
				for(i=0;i<count;i++)
					printf("%X ",DataGram[i]);
				printf("\n");

			
				/* Set the data of Air Pressure & temperature*/
				for( i=0;i<4;i++ )
						DataGram[count++]= 0x00;
				DataGram[count]='\0';
   				printf("\n");
				
				/* Set the frequency of the message sent to the terminal */
				frequency=0;
				frequency=atol(sendArg.dwsq->commFrequency);

				Reset( );
				printf("The decimal num is %ud\n",frequency);
				DecimalToHex(frequency,0);
				ToHexChar(&Frequency,2);

				for(i=0;i<2;i++)
				{
			
     				printf("%X ", Frequency[i]);
     				DataGram[count++]= Frequency[i];

   				}
   				DataGram[count]='\0';
   				printf("\n");
				free( Frequency );
				Frequency= NULL;


				/* And caculate the checksum */
				for(i=0;i<count;i++)
					checksum^=DataGram[i];
				DataGram[count++]=checksum;
				DataGram[count]='\0';

				/* Send the datagram */
				printf("Final it is:");
				for(i=0;i<count;i++)
					printf("%X ",DataGram[i]);
				printf("\n ");
		
			}

			break;

		case ALTIMETRYMODE_FIRMODE:
			
			if( sendArg.dwsq->heightType == HEIGHTINDICTATION_NORMAL )
			{
				/* Set the type of information*/
				printf("Set the type of information\n");
				/* Set the AltimetryMode to ALTIMETRYMODE_FIRMODE */
				DataGram[count] = DataGram[count] | 0x08 & 0xFB;
				/* Set the HeightType to HEIGHTINDICTATION_NORMAL */
				DataGram[count] = DataGram[count] & 0xFE & 0xFC;
				/* Secure the former 4 bits to zero */
				DataGram[count++] &= 0x0F;

				DataGram[count]='\0';
   				printf("\n");


				/* Set the antennna Altitude */

				/* Set the higher 16 bits to zero */
				for( i=0;i<2;i++ )
					DataGram[count++]= 0x00;
				DataGram[count]='\0';
   				printf("\n");

				/* Set the lower  16 bits to store the antenna height */
				Ant_AltitudeVal= 0;
				Ant_AltitudeVal= atol( sendArg.dwsq->antAltitude );
				Reset( );
				DecimalToHex(Ant_AltitudeVal,0);
				ToHexChar( &AntAltitude,2 );
				printf("sendArg.dwsq->antAltitude %ld\n",sendArg.dwsq->antAltitude);
				for( i=0;i<2;i++ )
				{
					printf("%X ", AntAltitude[i]);
     				DataGram[count++]= AntAltitude[i];
				}
   				DataGram[count]='\0';
   				printf("\n");
				free( AntAltitude );
				AntAltitude= NULL;

				printf("Now3 it is:");
				for(i=0;i<count;i++)
					printf("%X ",DataGram[i]);
				printf("\n");


				/* Set the data of Air Pressure & temperature*/
				AirPressureVal= 0;
				AirPressureVal= atol( sendArg.dwsq->airPressure );
				Reset( );
				DecimalToHex(AirPressureVal,0);
				ToHexChar( &AirPressure,3);

				printf("The airPressure is:\n");
				for( i=0; i<3; i++)
				{
					printf("%X ",AirPressure[i] );

				}
				printf("\n");

				/* Set the former 20 bits to store the data of air pressure */
				c2= AirPressure[2] & 0x0F;
				c1= ( AirPressure[2] >> 4) & 0x0F;
				DataGram[17]= ( DataGram[17]=c2) << 4;
				DataGram[16]= c1;
				DataGram[16] |= 0xF0;

				c2= AirPressure[1] & 0x0F;
				c1= ( AirPressure[1] >> 4) & 0x0F;
				temp= ( c2 << 4) | 0x0F;
				DataGram[16] &= temp;
				DataGram[15]= c1;
				DataGram[15] |= 0xF0;

				c2= AirPressure[0] & 0x0F;
				temp= ( c2 << 4) | 0x0F;
				DataGram[15] &= temp;

				free( AirPressure );
				AirPressure= NULL;

				/* Set the later 12 bits to store the data of temperature */
				TemperatureVal= 0;
				TemperatureVal= atol( sendArg.dwsq->temperature );
				Reset( );
				DecimalToHex(TemperatureVal,0);
				ToHexChar( &Temperature,2);

				printf("The temperature is:\n");
				for( i=0; i<2; i++)
				{
					printf("%X ",Temperature[i] );

				}
				printf("\n");

				DataGram[17] |= 0x0F;
				temp = Temperature[0] & 0x0F;
				if( sendArg.dwsq->temperatureValSign == 0 )
					temp &= 0xF7;
				else if( sendArg.dwsq->temperatureValSign == 1)
					temp |= 0x08;
				temp |= 0xF0;

				/*printf("DataGram[17] is :%X \n",DataGram[17]);
				printf("temp is :%X \n",temp);*/

				DataGram[17]  &= temp;
				DataGram[18] = Temperature[1];

				count= 19;

   				DataGram[count]='\0';
   				printf("\n");
				free( Temperature );
				Temperature= NULL;


				printf("Now4 it is:");
				for(i=0;i<count;i++)
					printf("%X ",DataGram[i]);
				printf("\n");

				/* Set the frequency of the message sent to the terminal */
				frequency=0;
				frequency=atol(sendArg.dwsq->commFrequency);

				Reset( );
				printf("The decimal num is %ud\n",frequency);
				DecimalToHex(frequency,0);
				ToHexChar(&Frequency,2);

				for(i=0;i<2;i++)
				{

     				printf("%X ", Frequency[i]);
     				DataGram[count++]= Frequency[i];

   				}
   				DataGram[count]='\0';
   				printf("\n");
				free( Frequency );
				Frequency= NULL;


				/* And caculate the checksum */
				for(i=0;i<count;i++)
					checksum^=DataGram[i];
				DataGram[count++]=checksum;
				DataGram[count]='\0';

				/* Send the datagram */
				printf("Final it is:");
				for(i=0;i<count;i++)
					printf("%X ",DataGram[i]);
		
		
			}
			else if( sendArg.dwsq->heightType == HEIGHTINDICTATION_UPPERAIR )
			{
				/* Set the type of information*/

				/* Set the AltimetryMode to ALTIMETRYMODE_FIRMODE */
				DataGram[count] = DataGram[count] | 0x08 | 0x04;
				/* Set the HeightType to HEIGHTINDICTATION_UPPERAIR */
				DataGram[count] = DataGram[count] | 0x01 & 0xFC;
				/* Secure the former 4 bits to zero */
				DataGram[count++] &= 0x0F;

				DataGram[count]='\0';
   				printf("\n");


				/* Set the antennna Altitude */

				
				Ant_AltitudeVal= 0;
				Ant_AltitudeVal= atol( sendArg.dwsq->antAltitude );
				Reset( );
				DecimalToHex(Ant_AltitudeVal,0);
				ToHexChar( &AntAltitude,4 );

				for( i=0;i<4;i++ )
				{
					printf("%X ", AntAltitude[i]);
     				DataGram[count++]= AntAltitude[i];
				}
   				DataGram[count]='\0';
   				printf("\n");
				free( AntAltitude );
				AntAltitude= NULL;

				printf("Now3 it is:");
				for(i=0;i<count;i++)
					printf("%X ",DataGram[i]);
				printf("\n");
			
				/* Set the data of Air Pressure & temperature*/
				
				AirPressureVal= 0;
				AirPressureVal= atol( sendArg.dwsq->airPressure );
				Reset( );
				DecimalToHex(AirPressureVal,0);
				ToHexChar( &AirPressure,3);

				/* Set the former 20 bits to store the data of air pressure */
				c2= AirPressure[2] & 0x0F;
				c1= ( AirPressure[2] >> 4) & 0x0F;
				DataGram[17]= ( DataGram[17]=c2) << 4;
				DataGram[16]= c1;
				DataGram[16] |= 0xF0;

				c2= AirPressure[1] & 0x0F;
				c1= ( AirPressure[1] >> 4) & 0x0F;
				temp= ( c2 << 4) | 0x0F;
				DataGram[16] &= temp;
				DataGram[15]= c1;
				DataGram[15] |= 0xF0;

				c2= AirPressure[0] & 0x0F;
				temp= ( c2 << 4) | 0x0F;
				DataGram[15] &= temp;

				free( AirPressure );
				AirPressure= NULL;

				/* Set the later 12 bits to store the data of temperature */
				TemperatureVal= 0;
				TemperatureVal= atol( sendArg.dwsq->temperature );
				Reset( );
				DecimalToHex(TemperatureVal,0);
				ToHexChar( &Temperature,2);
				
				DataGram[17] |= 0x0F;
				temp = Temperature[0] & 0x0F;
				if( sendArg.dwsq->temperatureValSign == 0 )
					temp &= 0xF7;
				else if( sendArg.dwsq->temperatureValSign == 1)
					temp |= 0x08;
				temp |= 0xF0;
				DataGram[17]  &= temp;
				DataGram[18]  = Temperature[1];
				
				count= 19;

   				DataGram[count]='\0';
   				printf("\n");
				free( Temperature );
				Temperature= NULL;


				printf("Now4 it is:");
				for(i=0;i<count;i++)
					printf("%X ",DataGram[i]);
				printf("\n");

				/* Set the frequency of the message sent to the terminal */
				frequency=0;
				frequency=atol(sendArg.dwsq->commFrequency);

				Reset( );
				printf("The decimal num is %ud\n",frequency);
				DecimalToHex(frequency,0);
				ToHexChar(&Frequency,2);

				for(i=0;i<2;i++)
				{
			
     				printf("%X ", Frequency[i]);
     				DataGram[count++]= Frequency[i];

   				}
   				DataGram[count]='\0';
   				printf("\n");
				free( Frequency );
				Frequency= NULL;


				/* And caculate the checksum */
				for(i=0;i<count;i++)
					checksum^=DataGram[i];
				DataGram[count++]=checksum;
				DataGram[count]='\0';

				/* Send the datagram */
				printf("Final it is:");
				for(i=0;i<count;i++)
					printf("%X ",DataGram[i]);

			}


			break;

		case ALTIMETRYMODE_SECMODE:

			if( sendArg.dwsq->heightType == HEIGHTINDICTATION_NORMAL )
			{
		

			}
			else if( sendArg.dwsq->heightType == HEIGHTINDICTATION_UPPERAIR )
			{


		
		
		
			}

			break;
	
		}/*end of switch*/

		break;

	case 'T':
		/****apply the request for remoting communication*/

		/* The fixed part's length of corresponding datagram*/
		/* is  18  bytes and caculate  the   total   length!*/

		DecimalToHex(sendArg.fixedLen+sendArg.length,0);
		ToHexChar(&Len,2);

		/*Put the main string and the substring together!*/
		for(i=0;i<2;i++)
		{
     			printf("%X ", Len[i]);
     			DataGram[count++]=Len[i];
		}
   		DataGram[count]='\0';
   		printf("\n");

		printf("Now1 it is:");
		for(i=0;i<count;i++)
                   printf("%X ",DataGram[i]);
		printf("\n");
		free( Len );
		Len= NULL;

		/*****Add the user source ID**********************/
		sum=0;
        sum=atol(sendArg.srcID);
		if(sum >1048576 )
		{
			printf("User ID has exceeded the valid value border!" );
			return;	

		}
		Reset( );
		printf("The decimal num is %ld\n",sum);
		DecimalToHex(sum,0);
		ToHexChar(&SRCID,3);


		for(i=0;i<3;i++)
		{
			if(i==0)
			{
			  SRCID[i] &=0x1F;
			}
     		printf("%X ", SRCID[i]);
     		DataGram[count++]=SRCID[i];

   		}
   		DataGram[count]='\0';
   		printf("\n");

		printf("Now2 it is:");
		for(i=0;i<count;i++)
			printf("%X ",DataGram[i]);
        	printf("\n");
		free(SRCID);
		SRCID= NULL;

        /****Add the information type to the datagram*****/
		if( sendArg.txsq->codeType == 0 )
			Type[0]= 0x44;
		else if( sendArg.txsq->codeType == 1 )
			Type[0]= 0x46;

		DataGram[ count++ ]= Type[0];
        DataGram[count]= '\0';

		printf("Now3 it is:");
		for(i=0;i<count;i++)
			printf("%X ",DataGram[i]);
        printf("\n");


		/*******Add the destination user  ID**************/
		sum=0;
        sum=atol(sendArg.srcID);
		if(sum >1048576 )
		{
			printf("User ID has exceeded the valid value border!" );
			return;

		}
		Reset( );
		printf("The decimal num is %ld\n",sum);
		DecimalToHex(sum,0);
		ToHexChar(&DESID,3);


		for(i=0;i<3;i++)
		{
			if(i==0)
			{
			  DESID[i] &=0x1F;
			}
     		printf("%X ", DESID[i]);
     		DataGram[count++]=DESID[i];

   		}
   		DataGram[count]='\0';
   		printf("\n");

		printf("Now4 it is:");
		for(i=0;i<count;i++)
			printf("%X ",DataGram[i]);
        printf("\n");

		/*****Add the actual data length to datagram*****/
		Reset( );
        DecimalToHex(sendArg.length*8,0);
		ToHexChar(&Len,2);


		for(i=0;i<2;i++)
		{
			printf("%X ", Len[i]);
     		DataGram[count++]=Len[i];

   		}
   		DataGram[count]='\0';
   		printf("\n");

		printf("Now5 it is:");
		for(i=0;i<count;i++)
			printf("%X ",DataGram[i]);
        printf("\n");
		free( Len );
		Len=NULL;

		/*****Add the responding mode to datagram*******/
		if(sendArg.txsq->isAnswer== 0)
			IsAnswer[0]=0x00;
		else
		    IsAnswer[0]=0x01;

        DataGram[count++]=IsAnswer[0];
        DataGram[count]='\0';

		printf("Now6 it is:");
		for(i=0;i<count;i++)
                   printf("%X ",DataGram[i]);
        	printf("\n");


		/*****Add the actual data to the datagram*******/
		for(i=0;i<sendArg.length;i++)
		{
			printf("%X ", (sendArg.txsq->content)[i]);
     		DataGram[count++]=(sendArg.txsq->content)[i];

   		}
   		DataGram[count]='\0';
   		printf("\n");
		printf("After Adding  data to the rear,it is:");
		for(i=0;i<count;i++)
			printf("%X ",DataGram[i]);
        printf("\n");

        /*****Caculate the checksum and Add it  to the end of datagram***************/
		for(i=0;i<count;i++)
		    checksum^=DataGram[i];

		c2=checksum & 0x0F; c1=((checksum>>4) & 0x0F);
		DataGram[count++]=checksum;
        DataGram[count]='\0';

		/*if(c1<10)
		  c1+='0';
		else
		  c1+='A'-10;
		if(c2<10)
		  c2+='0';
		else
		  c2+='A'-10;

		printf("%c,%c\n",c1,c2);*/

		/*****Send the datagram to remoting client with serial port******/
		printf("Now7 it is:");
                for(i=0;i<count;i++)
                   printf("%X ",DataGram[i]);
					
        	printf("\n");


        /****************************************************************/

		break;
	case 'C':
		/*apply the request for serial port output's information*/

		/* The fixed part's length of serial port output atagram*/
		/* is  12  bytes  and  caculate  the   total   length!  */

		DecimalToHex(sendArg.fixedLen+sendArg.length,0);
		ToHexChar(&Len,2);

		/*Put the main string and the substring together!*/
		for(i=0;i<2;i++)
		{
     			printf("%X ", Len[i]);
     			DataGram[count++]=Len[i];
		}
   		DataGram[count]='\0';
   		printf("\n");
		free( Len );
		Len= NULL;

		printf("Now1 it is:");
		for(i=0;i<count;i++)
                   printf("%X ",DataGram[i]);
		printf("\n");

		/*****Add the user source ID**********************/
		sum=0;
        sum=atol(sendArg.srcID);
		if(sum >1048576 )
		{
			printf("User ID has exceeded the valid value border!" );
			return;	

		}
		Reset( );
		printf("The decimal num is %ld\n",sum);
		DecimalToHex(sum,0);
		ToHexChar(&SRCID,3);


		for(i=0;i<3;i++)
		{
			if(i==0)
			{
			  SRCID[i] &=0x1F;
			}
     		printf("%X ", SRCID[i]);
     		DataGram[count++]=SRCID[i];

   		}
   		DataGram[count]='\0';
   		printf("\n");
		free( SRCID );
		SRCID= NULL;

		printf("Now2 it is:");
		for(i=0;i<count;i++)
			printf("%X ",DataGram[i]);
        	printf("\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -