📄 senddatagramv3.0.c~
字号:
printf("************Enter CKSC selected BaudRate*******\n");
/*****Add the selected BaudRate*******************/
if( strcmp( sendArg.cksc->baudRate, "19200") == 0 )
{
DataGram[count++]=0x00;
DataGram[count]='\0';
/* And caculate the checksum and Add it to the end of datagram*/
for(i=0;i<count;i++)
checksum^=DataGram[i];
DataGram[count++]=checksum;
DataGram[count]='\0';
/* Send the datagram to remoting client with serial port */
printf("Now it is:");
for(i=0;i<count;i++)
printf("%X ",DataGram[i]);
printf("\n");
free(DataGram); return;
}
if( strcmp( sendArg.cksc->baudRate, "1200") == 0 )
{
DataGram[count++]=0x01;
DataGram[count]='\0';
/* caculate the checksum */
for(i=0;i<count;i++)
checksum^=DataGram[i];
DataGram[count++]=checksum;
DataGram[count]='\0';
/* Send the datagram */
printf("Now it is:");
for(i=0;i<count;i++)
printf("%X ",DataGram[i]);
printf("\n");
free(DataGram); return;
}
if( strcmp( sendArg.cksc->baudRate, "2400") == 0 )
{
DataGram[count++]=0x02;
DataGram[count]='\0';
/* And caculate the checksum */
for(i=0;i<count;i++)
checksum^=DataGram[i];
DataGram[count++]=checksum;
DataGram[count]='\0';
/* Send the datagram */
printf("Now it is:");
for(i=0;i<count;i++)
printf("%X ",DataGram[i]);
printf("\n");
free(DataGram); return;
}
if( strcmp( sendArg.cksc->baudRate, "4800") == 0 )
{
DataGram[count++]=0x03;
DataGram[count]='\0';
/* And caculate the checksum */
for(i=0;i<count;i++)
checksum^=DataGram[i];
DataGram[count++]=checksum;
DataGram[count]='\0';
/* Send the datagram */
printf("Now it is:");
for(i=0;i<count;i++)
printf("%X ",DataGram[i]);
printf("\n");
free(DataGram); return;
}
if( strcmp( sendArg.cksc->baudRate, "9600") == 0 )
{
DataGram[count++]=0x04;
DataGram[count]='\0';
/* And caculate the checksum */
for(i=0;i<count;i++)
checksum^=DataGram[i];
DataGram[count++]=checksum;
DataGram[count]='\0';
/* Send the datagram */
printf("Now it is:");
for(i=0;i<count;i++)
printf("%X ",DataGram[i]);
printf("\n");
free(DataGram); return;
}
if( strcmp( sendArg.cksc->baudRate, "38400") == 0 )
{
DataGram[count++]=0x05;
DataGram[count]='\0';
/* And caculate the checksum */
for(i=0;i<count;i++)
checksum^=DataGram[i];
DataGram[count++]=checksum;
DataGram[count]='\0';
/* Send the datagram */
printf("Now it is:");
for(i=0;i<count;i++)
printf("%X ",DataGram[i]);
printf("\n");
free(DataGram); return;
}
if( strcmp( sendArg.cksc->baudRate, "57600") == 0 )
{
DataGram[count++]=0x06;
DataGram[count]='\0';
/* And caculate the checksum */
for(i=0;i<count;i++)
checksum^=DataGram[i];
DataGram[count++]=checksum;
DataGram[count]='\0';
/* Send the datagram */
printf("Now it is:");
for(i=0;i<count;i++)
printf("%X ",DataGram[i]);
printf("\n");
free(DataGram); return;
}
if( strcmp( sendArg.cksc->baudRate, "115200") == 0 )
{
DataGram[count++]=0x07;
DataGram[count]='\0';
/* And caculate the checksum */
for(i=0;i<count;i++)
checksum^=DataGram[i];
DataGram[count++]=checksum;
DataGram[count]='\0';
/* Send the datagram */
printf("Now it is:");
for(i=0;i<count;i++)
printf("%X ",DataGram[i]);
printf("\n");
free(DataGram); return;
}
break;
case 'I':
/*apply the request for IC card's checking*/
/* 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!" );
free(DataGram); 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");
/*****Add the fixed frame***************/
DataGram[count++]=sendArg.icjc->frame;
DataGram[count]='\0';
/* 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 'X':
/*apply the request for system checking*/
/* The fixed part's length of serial port output atagram*/
/* is 13 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!" );
free(DataGram); 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");
/* Add the frequency of the checking */
frequency=0;
frequency=atol( sendArg.xtzj->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 'S':
/*apply the request for current time information*/
/* The fixed part's length of serial port output atagram*/
/* is 13 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!" );
free(DataGram); 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");
/* Add the frequency of the checking */
frequency=0;
frequency=atol( sendArg.sjsc->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 'B':
/*apply the request for system version's information*/
/* The fixed part's length of serial port output atagram*/
/* is 13 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!" );
free(DataGram); 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");
/* 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;
}
/* end of switch */
free(DataGram);
}
/*int TestSend( void )
//int main( void )
{
/*for DWSQ
DWSQ *dwsq; int AltimetryMode=3,HeightType=1,Frequency,loc_AltitudeSign=1,temperatureValSign=1;
char cmd[]="$DWSQ",srcID[]="105006",frequency[]="12",locationAltitude[]="15",antennaAltitude[]="15",airPressure[]="15",temperature[]="15"; dwsq = (DWSQ *)malloc(sizeof( DWSQ ));
dwsq->altimetryMode = 3; dwsq->heightType = 1; dwsq->loc_AltitudeSign = 1; dwsq->temperatureValSign = 1;
dwsq->locAltitude = "15"; dwsq->antAltitude = "15"; dwsq->airPressure = "15"; dwsq->temperature = "15"; dwsq->commFrequency = "12";
SendDataGram( cmd,srcID, dwsq,NULL,NULL,NULL,NULL,NULL,0,LEN_OF_DWSQ ); free(dwsq);*/
/*for TXSQ
TXSQ *txsq;
int i,j;
char str[]="程度军区",cmd[]="$TXSQ",srcID[]="105006";
txsq = (TXSQ *)malloc(sizeof( TXSQ )); printf("Address of txsq is %X\n ",txsq);
sendArg.srcID = "105006"; sendArg.cmd ="$TXSQ"; sendArg.txsq = txsq; sendArg.fixedLen = LEN_OF_TXSQ;
j=convert(str,&(sendArg.txsq->content),0); sendArg.length = j;
printf("%d\n",j);
for(i=0;i<j;i++)
printf("%X ",(sendArg.txsq->content)[i]);
printf("\n"); CheckTidCount(); Pthread_create( &tid_Processing[tidProcessing], &attr, SendDataGram, NULL);*/
//SendDataGram( cmd,srcID, NULL,txsq,NULL,NULL,NULL,NULL,j,LEN_OF_TXSQ );
//free(txsq);
/*for CKSC
CKSC *cksc;
char str[]="19200",cmd[]="$CKSC",srcID[]="105006";
cksc = (CKSC *)malloc(sizeof( CKSC ));
cksc->baudRate = "19200";
SendDataGram( cmd,srcID, NULL,NULL,cksc,NULL,NULL,NULL,0,LEN_OF_CKSC ); free(cksc);*/
/*for ICJC
ICJC *icjc;
char cmd[]="$ICJC",srcID[]="105006"; icjc = (ICJC *)malloc(sizeof( ICJC ));
icjc->frame = 0;
SendDataGram(cmd,srcID,NULL,NULL,NULL,icjc,NULL,NULL,0,LEN_OF_ICJC);
free(icjc);*/
/*for XTZJ
XTZJ *xtzj;
char cmd[]="$XTZJ",srcID[]="105006"; xtzj = (XTZJ *)malloc(sizeof( XTZJ ));
xtzj->commFrequency = "39470";
SendDataGram(cmd,srcID,NULL,NULL,NULL,NULL,xtzj,NULL,0,LEN_OF_XTZJ);
free(xtzj);*/
/*for SJSC
SJSC *sjsc;
char cmd[]="$SJSC",srcID[]="105006"; sjsc = (SJSC *)malloc(sizeof( SJSC ));
sjsc->commFrequency = "39470",
SendDataGram(cmd,srcID,NULL,NULL,NULL,NULL,NULL,sjsc,0,LEN_OF_SJSC); free(sjsc); */
/*for BBDQ
char cmd[]="$BBDQ",srcID[]="105006";
SendDataGram(cmd,srcID,NULL,NULL,NULL,NULL,NULL,NULL,0,LEN_OF_BBDQ);
sleep( 5 );
return 0;
}*/#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -