📄 packagedeal.c
字号:
//IPC_ProcState_Read(PROCID_DISPATCH,CurDispatch_Info,&LocalDispatch_Info);
//put DISPATCH data and com status to sharemem
//printf("DISPATCH read success!\r\n");
//printf("DISPATCH Data CarState:%d\r\n",LocalDispatch_Info.CarState);
//printf("DISPATCH Data Proc_Info.CommState:%d\r\n",LocalDispatch_Info.CommState);
//printf("DISPATCH Data Proc_Info.PID:%d\r\n",LocalDispatch_Info.Proc_Info.PID);
//printf("DISPATCH Data Proc_Info.ctime:%s\r\n",ctime(&(LocalDispatch_Info.Proc_Info.ctime)));
return 0;
}
free(echoString);
}
return 1;
}
#endif
//GPRS发送,由毛鹏修改过,修改内容为不把注册信息加入内存
#if 1
int RegesterInfo(int sockFD, Package_Info commInter,struct sockaddr_in echoServAddr)
{
int i;
char RecvDataAll[ECHOMAX];
unsigned short echoStringLen; /* Length of string to echo */
char *echoString; /* String to send to echo server */
Dispatch_Info LocalDispatch_Info; //Point the share mem
// Deal_SendInfo(commInter,1); //此处移去把注册信息添加到内存中的发送队列中的内容
//此处添加为当前注册信息生成流水号的内容
staticSendSeriNO=staticSendSeriNO+1;
commInter.SerialNo=staticSendSeriNO;
// printf("Here to send!\r\n");
if (commInter.SerialNo!=0)
{
echoStringLen=SendMessageCreate(commInter,RecvDataAll);
// printf("Here2!\r\n");
echoString=malloc(echoStringLen);
memcpy(echoString,RecvDataAll,echoStringLen);
if (echoStringLen > ECHOMAX) /* Check input length */
printf("word too length!\r\n");
/*MB_DEB("%s() : register data is ",__FUNCTION__);
for(i=0;i<echoStringLen;i++)
{
printf("0x%02x ",*(echoString+i)&0xff);
}*/
/* Send the string to the server */
if (sendto(sockFD, echoString, echoStringLen, 0, (struct sockaddr *)
&echoServAddr, sizeof(echoServAddr)) != echoStringLen)
{
printf("RegesterInfo sendto fail!\r\n");
//修改共享内存(注册失败)
IPC_ProcState_Read(PROCID_DISPATCH,CurDispatch_Info,&LocalDispatch_Info);
//LocalDispatch_Info.CarState=0;
LocalDispatch_Info.CommState=0;
LocalDispatch_Info.Proc_Info.PID = getpid();
time(&(LocalDispatch_Info.Proc_Info.ctime));
//Share mem write
IPC_ProcState_Write(PROCID_DISPATCH,CurDispatch_Info,&LocalDispatch_Info);
//IPC_ProcState_Read(PROCID_DISPATCH,CurDispatch_Info,&LocalDispatch_Info);
//put DISPATCH data and com status to sharemem
//printf("DISPATCH read success!\r\n");
//printf("DISPATCH Data CarState:%d\r\n",LocalDispatch_Info.CarState);
//printf("DISPATCH Data Proc_Info.CommState:%d\r\n",LocalDispatch_Info.CommState);
//printf("DISPATCH Data Proc_Info.PID:%d\r\n",LocalDispatch_Info.Proc_Info.PID);
//printf("DISPATCH Data Proc_Info.ctime:%s\r\n",ctime(&(LocalDispatch_Info.Proc_Info.ctime)));
return 0;
}
free(echoString);
}
return 1;
}
#endif
//GPRS发送数据
int SocketSendInfo(int sockFD, Package_Info commInter,struct sockaddr_in echoServAddr)
{
char RecvDataAll[ECHOMAX];
unsigned short echoStringLen; /* Length of string to echo */
char *echoString; /* String to send to echo server */
Dispatch_Info LocalDispatch_Info; //Point the share mem
Deal_SendInfo(commInter,1);
if (CurDispatch_SendInfo[0].SerialNo!=0)
{
echoStringLen=SendMessageCreate(CurDispatch_SendInfo[0],RecvDataAll);
echoString=malloc(echoStringLen);
memcpy(echoString,RecvDataAll,echoStringLen);
if (echoStringLen > ECHOMAX) /* Check input length */
printf("word too length!\r\n");
/* Send the string to the server */
if (sendto(sockFD, echoString, echoStringLen, 0, (struct sockaddr *)
&echoServAddr, sizeof(echoServAddr)) != echoStringLen)
{
printf("SocketSendInfo sendto fail!\r\n");
//修改共享内存()
IPC_ProcState_Read(PROCID_DISPATCH,CurDispatch_Info,&LocalDispatch_Info);
//LocalDispatch_Info.CarState=0;
LocalDispatch_Info.CommState=0;
LocalDispatch_Info.Proc_Info.PID = getpid();
time(&(LocalDispatch_Info.Proc_Info.ctime));
//Share mem write
IPC_ProcState_Write(PROCID_DISPATCH,CurDispatch_Info,&LocalDispatch_Info);
//IPC_ProcState_Read(PROCID_DISPATCH,CurDispatch_Info,&LocalDispatch_Info);
//put DISPATCH data and com status to sharemem
//printf("DISPATCH read success!\r\n");
//printf("DISPATCH Data CarState:%d\r\n",LocalDispatch_Info.CarState);
//printf("DISPATCH Data Proc_Info.CommState:%d\r\n",LocalDispatch_Info.CommState);
//printf("DISPATCH Data Proc_Info.PID:%d\r\n",LocalDispatch_Info.Proc_Info.PID);
//printf("DISPATCH Data Proc_Info.ctime:%s\r\n",ctime(&(LocalDispatch_Info.Proc_Info.ctime)));
}
else
{
// printf("Here send out data!");
Waitresp = 1;
}
free(echoString);
return 0;
}
return 1;
}
//发送的数据已经存在缓冲中
int SocketReSendInfo(int sockFD, Package_Info commInter,struct sockaddr_in echoServAddr)
{
char RecvDataAll[ECHOMAX];
unsigned short echoStringLen; /* Length of string to echo */
char *echoString; /* String to send to echo server */
Dispatch_Info LocalDispatch_Info; //Point the share mem
int i=0;
// Deal_SendInfo(commInter,1);
for(i=0;i<ECHOMAX;i++)
{
if (CurDispatch_SendInfo[i].SerialNo!=0)
{
printf("Unsend in position %d!",i);
echoStringLen=SendMessageCreate(CurDispatch_SendInfo[i],RecvDataAll);
echoString=malloc(echoStringLen);
memcpy(echoString,RecvDataAll,echoStringLen);
if (echoStringLen > ECHOMAX) /* Check input length */
printf("word too length!\r\n");
/* Send the string to the server */
if (sendto(sockFD, echoString, echoStringLen, 0, (struct sockaddr *)
&echoServAddr, sizeof(echoServAddr)) != echoStringLen)
{
printf("SocketSendInfo sendto fail!\r\n");
//修改共享内存()
IPC_ProcState_Read(PROCID_DISPATCH,CurDispatch_Info,&LocalDispatch_Info);
//LocalDispatch_Info.CarState=0;
LocalDispatch_Info.CommState=0;
LocalDispatch_Info.Proc_Info.PID = getpid();
time(&(LocalDispatch_Info.Proc_Info.ctime));
//Share mem write
IPC_ProcState_Write(PROCID_DISPATCH,CurDispatch_Info,&LocalDispatch_Info);
//IPC_ProcState_Read(PROCID_DISPATCH,CurDispatch_Info,&LocalDispatch_Info);
//put DISPATCH data and com status to sharemem
//printf("DISPATCH read success!\r\n");
//printf("DISPATCH Data CarState:%d\r\n",LocalDispatch_Info.CarState);
//printf("DISPATCH Data Proc_Info.CommState:%d\r\n",LocalDispatch_Info.CommState);
//printf("DISPATCH Data Proc_Info.PID:%d\r\n",LocalDispatch_Info.Proc_Info.PID);
//printf("DISPATCH Data Proc_Info.ctime:%s\r\n",ctime(&(LocalDispatch_Info.Proc_Info.ctime)));
}
else
{
// printf("Here send out data!");
Waitresp = 1;
}
free(echoString);
return 0;
}
}
return 1;
}
//GPS回复信息
int RepeatSendInfo(int sockFD, Package_Info commInter,struct sockaddr_in echoServAddr)
{
char RecvDataAll[ECHOMAX];
unsigned short echoStringLen; /* Length of string to echo */
char *echoString; /* String to send to echo server */
Dispatch_Info LocalDispatch_Info; //Point the share mem
echoStringLen=SendMessageCreate(commInter,RecvDataAll);
echoString=malloc(echoStringLen);
memcpy(echoString,RecvDataAll,echoStringLen);
if (echoStringLen > ECHOMAX) /* Check input length */
printf("word too length!\r\n");
/* Send the string to the server */
if (sendto(sockFD, echoString, echoStringLen, 0, (struct sockaddr *)
&echoServAddr, sizeof(echoServAddr)) != echoStringLen)
{
printf("RepeatSendInfo sendto fail!\r\n");
//修改共享内存()
IPC_ProcState_Read(PROCID_DISPATCH,CurDispatch_Info,&LocalDispatch_Info);
//LocalDispatch_Info.CarState=0;
LocalDispatch_Info.CommState=0;
LocalDispatch_Info.Proc_Info.PID = getpid();
time(&(LocalDispatch_Info.Proc_Info.ctime));
//Share mem write
IPC_ProcState_Write(PROCID_DISPATCH,CurDispatch_Info,&LocalDispatch_Info);
//IPC_ProcState_Read(PROCID_DISPATCH,CurDispatch_Info,&LocalDispatch_Info);
//put DISPATCH data and com status to sharemem
//printf("DISPATCH read success!\r\n");
//printf("DISPATCH Data CarState:%d\r\n",LocalDispatch_Info.CarState);
//printf("DISPATCH Data Proc_Info.CommState:%d\r\n",LocalDispatch_Info.CommState);
//printf("DISPATCH Data Proc_Info.PID:%d\r\n",LocalDispatch_Info.Proc_Info.PID);
//printf("DISPATCH Data Proc_Info.ctime:%s\r\n",ctime(&(LocalDispatch_Info.Proc_Info.ctime)));
return 0;
}
free(echoString);
return 1;
}
//从内存中读出一个没有成功发送的数据包
int Get_UnSendInfo(Package_Info *SendInfo)
{
int i;
// printf("Search in buffer!\n");
for(i=0;i<100;i++)//ECHOMAX;i++)
{
// printf("*%d*",CurDispatch_SendInfo[i].SerialNo);
if(CurDispatch_SendInfo[i].SerialNo!=0)
{
memcpy(SendInfo,&(CurDispatch_SendInfo[i]),sizeof(Package_Info));
return 1;
}
}
return 0;
}
//处理发送队列,参数SendType的值为1时,则把要发送的数据加入到内存的队列中;
//参数SendType的值为2时,则要把发送的数据从内存队列中删除
void Deal_SendInfo(Package_Info SendInfo,int SendType)
{
Package_Info tmpSendInfo[ECHOMAX];
int i,j,k,OldSend;
memset(tmpSendInfo,0,sizeof(tmpSendInfo));
if (SendType==1)
{
j=0;
for (i=0;i<ECHOMAX;i++)
{
//把当前队列中所有未发送的数据全部复制一份到临时队列中
if (CurDispatch_SendInfo[i].SerialNo!=0)
{
tmpSendInfo[j].BeginEnd=CurDispatch_SendInfo[i].BeginEnd;
tmpSendInfo[j].ByteLength=CurDispatch_SendInfo[i].ByteLength;
memcpy(tmpSendInfo[j].SerialNum,CurDispatch_SendInfo[i].SerialNum,sizeof(CurDispatch_SendInfo[i].SerialNum));
tmpSendInfo[j].AppType=CurDispatch_SendInfo[i].AppType;
tmpSendInfo[j].OperationNo=CurDispatch_SendInfo[i].OperationNo;
tmpSendInfo[j].SerialNo=CurDispatch_SendInfo[i].SerialNo;
tmpSendInfo[j].DataType=CurDispatch_SendInfo[i].DataType;
tmpSendInfo[j].DataLength=CurDispatch_SendInfo[i].DataLength;
memcpy(tmpSendInfo[j].DataIP,CurDispatch_SendInfo[i].DataIP,sizeof(CurDispatch_SendInfo[i].DataIP));
tmpSendInfo[j].DataPort=CurDispatch_SendInfo[i].DataPort;
tmpSendInfo[j].ContentType=CurDispatch_SendInfo[i].ContentType;
tmpSendInfo[j].CheckFlag=CurDispatch_SendInfo[i].CheckFlag;
memcpy(tmpSendInfo[j].DataContent,CurDispatch_SendInfo[i].DataContent,sizeof(CurDispatch_SendInfo[i].DataContent));
j++;
}
}
//清空当前队列
memset(&CurDispatch_SendInfo,0,sizeof(CurDispatch_SendInfo));
//生成新的流水号
staticSendSeriNO=staticSendSeriNO+1;
SendInfo.SerialNo=staticSendSeriNO;
OldSend=0;
for (i=0;i<j;i++)
{
//把临时队列中的数据重新拷贝回到当前队列中
CurDispatch_SendInfo[i].BeginEnd=tmpSendInfo[i].BeginEnd;
CurDispatch_SendInfo[i].ByteLength=tmpSendInfo[i].ByteLength;
memcpy(CurDispatch_SendInfo[i].SerialNum,tmpSendInfo[i].SerialNum,sizeof(tmpSendInfo[i].SerialNum));
CurDispatch_SendInfo[i].AppType=tmpSendInfo[i].AppType;
CurDispatch_SendInfo[i].OperationNo=tmpSendInfo[i].OperationNo;
CurDispatch_SendInfo[i].SerialNo=tmpSendInfo[i].SerialNo;
CurDispatch_SendInfo[i].DataType=tmpSendInfo[i].DataType;
CurDispatch_SendInfo[i].DataLength=tmpSendInfo[i].DataLength;
memcpy(CurDispatch_SendInfo[i].DataIP,tmpSendInfo[i].DataIP,sizeof(tmpSendInfo[i].DataIP));
CurDispatch_SendInfo[i].DataPort=tmpSendInfo[i].DataPort;
CurDispatch_SendInfo[i].ContentType=tmpSendInfo[i].ContentType;
CurDispatch_SendInfo[i].CheckFlag=tmpSendInfo[i].CheckFlag;
memcpy(CurDispatch_SendInfo[i].DataContent,tmpSendInfo[i].DataContent,sizeof(tmpSendInfo[i].DataContent));
//要发送的数据与之前的数据一模一样
if ((SendInfo.BeginEnd==tmpSendInfo[i].BeginEnd) && (SendInfo.ByteLength==tmpSendInfo[i].ByteLength) &&
(SendInfo.AppType==tmpSendInfo[i].AppType) && (SendInfo.OperationNo==tmpSendInfo[i].OperationNo) &&
(SendInfo.DataType==tmpSendInfo[i].DataType) && (SendInfo.DataLength==tmpSendInfo[i].DataLength) &&
(SendInfo.DataPort==tmpSendInfo[i].DataPort) && (SendInfo.ContentType==tmpSendInfo[i].ContentType))
{
OldSend=1; //标记为次数据已发送过
staticSendSeriNO=staticSendSeriNO-1; //由于数据已经存在缓冲区内,流水号减一
for(k=0;k<12;k++)
{
if (SendInfo.SerialNum[k]!=tmpSendInfo[i].SerialNum[k])
{
OldSend=0;
break;
}
}
for(k=0;k<15;k++)
{
if ((SendInfo.DataIP[k]!=tmpSendInfo[i].DataIP[k]) || (OldSend==0))
{
OldSend=0;
break;
}
}
for(k=0;k<ECHOMAX;k++)
{
if ((SendInfo.DataContent[k]!=tmpSendInfo[i].DataContent[k]) || (OldSend==0))
{
OldSend=0;
break;
}
}
if (OldSend==0)
{
staticSendSeriNO=staticSendSeriNO+1; //最终判断数据未发送,再恢复加一
}
}
}
if (((unsigned short)(SendInfo.OperationNo & 0xFF)==200))
{
if (OldSend!=1) //如果没发送过,把发送缓冲中的首个数据设置为注册数据
{
CurDispatch_SendInfo[0].BeginEnd=SendInfo.BeginEnd;
CurDispatch_SendInfo[0].ByteLength=SendInfo.ByteLength;
memcpy(CurDispatch_SendInfo[0].SerialNum,SendInfo.SerialNum,sizeof(SendInfo.SerialNum));
CurDispatch_SendInfo[0].AppType=SendInfo.AppType;
CurDispatch_SendInfo[0].OperationNo=SendInfo.OperationNo;
CurDispatch_SendInfo[0].SerialNo=SendInfo.SerialNo;
CurDispatch_SendInfo[0].DataType=SendInfo.DataType;
CurDispatch_SendInfo[0].DataLength=SendInfo.DataLength;
memcpy(CurDispatch_SendInfo[0].DataIP,SendInfo.DataIP,sizeof(SendInfo.DataIP));
CurDispatch_SendInfo[0].DataPort=SendInfo.DataPort;
CurDispatch_SendInfo[0].ContentType=SendInfo.ContentType;
CurDispatch_SendInfo[0].CheckFlag=SendInfo.CheckFlag;
memcpy(CurDispatch_SendInfo[0].DataContent,SendInfo.DataContent,sizeof(SendInfo.DataContent));
}
}
else if (OldSend!=1) //如果没发送过,把当前数据加入到队列中
{
if ((SendInfo.SerialNo!=0) && (j<ECHOMAX))
{
CurDispatch_SendInfo[j].BeginEnd=SendInfo.BeginEnd;
CurDispatch_SendInfo[j].ByteLength=SendInfo.ByteLength;
memcpy(CurDispatch_SendInfo[j].SerialNum,SendInfo.SerialNum,sizeof(SendInfo.SerialNum));
CurDispatch_SendInfo[j].AppType=SendInfo.AppType;
CurDispatch_SendInfo[j].OperationNo=SendInfo.OperationNo;
CurDispatch_SendInfo[j].SerialNo=SendInfo.SerialNo;
CurDispatch_SendInfo[j].DataType=SendInfo.DataType;
CurDispatch_SendInfo[j].DataLength=SendInfo.DataLength;
memcpy(CurDispatch_SendInfo[j].DataIP,SendInfo.DataIP,sizeof(SendInfo.DataIP));
CurDispatch_SendInfo[j].DataPort=SendInfo.DataPort;
CurDispatch_SendInfo[j].ContentType=SendInfo.ContentType;
CurDispatch_SendInfo[j].CheckFlag=SendInfo.CheckFlag;
memcpy(CurDispatch_SendInfo[j].DataContent,SendInfo.DataContent,sizeof(SendInfo.DataContent));
}
}
}
else if (SendType==2)
{
for (i=0;i<ECHOMAX;i++)
{
if (CurDispatch_SendInfo[i].SerialNo==SendInfo.SerialNo)
{
switch (SendInfo.OperationNo)
{
case 63 : //收到GPS信息应答
printf("Receive GPS back Info & GpsSendOK!\n");
if(!(CurDispatch_SendInfo[i].DataContent[19]&0x18))//||(CurDispatch_SendInfo[i].DataContent[18]))) //为主动上发信息
{
// printf("");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -