📄 epa_socmapent.c
字号:
/**************************************************************************
**
** 文件: EPA_SocMapEnt.c
** 描述: 该文件完成套接字映射实体的报文封装、解包与超时诊断功能
**
**************************************************************************/
//include library files
#include <stdio.h>
#include <string.h>
//include user defined files
#include "Define.h"
#include "Global_Variable.h"
#include "Extern_Function.h"
#include "IP_UDP.h"
#include "EPA_CSME.h"
#include "EPA_SocMapEnt.h"
//为EPA套接字映射对象开辟存储区
uchar Socket_Mapping_Buf[sizeof(struct Socket_Mapping)];
/**************************************************************************
**
** 函数: void Error_Man(void)
** 描述: 该函数完成证实请求报文发送时,规定时间内未收到正响应或收到负响应的出错处理
**
**************************************************************************/
void Error_Man(void)
{
/*ErrorType *Error;
switch Error->Error_Class
{case 0: switch Error->Error_Code
{case 0: Resource_Memory_Unavailable(); break;
case 1: Resource_Other(); break;
default: break;
} break;
case 1: switch Error->Error_Code
{case 0: Service_Object_State_Conflict(); break;
case 1: Service_Object_Constraint_Conflict(); break;
case 2: Service_Parameter_Inconsistent(); break;
case 3: Service_Illegal_Parameter(); break;
case 4: Service_Size_Error(); break;
case 5: Service_Other(); break;
default: break;
} break;
case 2: switch Error->Error_Code
{case 0: Access_Object_Access_Unsupported(); break;
case 1: Access_Object_Non_Existent(); break;
case 2: Access_Object_Access_Denied(); break;
case 3: Access_Hardware_Fault(); break;
case 4: Access_Type_Conflict(); break;
case 5: Access_Object_Attribute_Inconsistent(); break;
case 6: Access_Access_to_Element_Unsupported(); break;
case 7: Access_Other(); break;
default: break;
} break;
case 3: switch Error->Error_Code
{case 0: Timer_Timer_Expire(); break;
case 1: Timer_Timer_Error(); break;
case 2: Timer_Other(); break;
default: break;
} break;
case 4: switch Error->Error_Code
{case 0: Other_Other(); break;
default: break;
} break;
default: break;*/
}
/**************************************************************************
**
** 函数: void Make_App_Header(uchar,uchar,uint,uint)
** 描述: 该函数完成应用服务头的构造,
入口参数分别为消息类型、服务标识、消息长度、报文标识
**
**************************************************************************/
void Make_App_Header(uchar message_type,uchar service_id,uint len,uint message_id)
{
S_She->ServiceID=(message_type+service_id);
S_She->Length=htons(len);
S_She->MessageID=htons(message_id);
}
/**************************************************************************
**
** 函数: void Socket_Enpacket(void)
** 描述: 该函数完成服务报文的打包
**
**************************************************************************/
void Socket_Enpacket(void)
{
uchar id;
uchar type;
uint len;
id=Som->Active_ServiceID;
if(id==EM_GetDeviceAttribute_ID||id==EM_SetDeviceAttribute_ID\
||id==EM_ClearDeviceAttribute_ID||id==DomainDownload_ID||id==DomainUpload_ID\
||id==Read_ID||id==Write_ID||id==AcknowledgeEventNotification_ID||id==AlterEventCondition_ID)
//服务报文是证实报文
{
if(Som->Active_Message_Time.Date==0&&Som->Active_Message_Time.Millisecond==0)//证实应答报文
type=Message_REP;
else //证实请求报文
{
type=Message_REQ;
Timer2_Init((uint)(Som->Active_Message_Time.Date*24*3600*1000+Som->Active_Message_Time.Millisecond));
}
}
else //服务报文是无证实报文
type=Message_REQ;
len=Som->Message_Length+sizeof(struct Service_Header);
Make_App_Header(type,Som->Active_ServiceID,len,Som->Active_MessageID); //构造消息头
if(memcmp(Som->Remote_IP_Address,Bro_IP,4)==0)//广播方式
Send_UDP(Bro_MAC,Som->Remote_IP_Address,Som->Active_UDP_Port,Som->Active_UDP_Port,len); //向UDP层传递
else //单播方式
Send_UDP(Dest_MAC,Som->Remote_IP_Address,Som->Active_UDP_Port,Som->Active_UDP_Port,len); //向UDP层传递
}
/**************************************************************************
**
** 函数: void Socket_Depacket(void)
** 描述: 该函数完成服务报文的解包
**
**************************************************************************/
void Socket_Depacket(void)
{
if(ntohs(R_Pdp->UDP_Sour_Port)==EPA_Port) //收到的UDP报文是EPA报文
{
if((R_Pdp->UDP_Data[0]==NonPeriodDataAnnunciation_ID||R_Pdp->UDP_Data[0]==EndofNonPeriodDataSending_ID)\
&&Ready_Ed==TRUE) //收到的EPA报文是(结束)声明报文,并且设备已经处于Ready状态
Receive_Annunciation_Data(R_Pdp->UDP_Data[0]); //见EPA_CSME.c
else if(R_Pdp->UDP_Data[0]!=NonPeriodDataAnnunciation_ID&&R_Pdp->UDP_Data[0]!=EndofNonPeriodDataSending_ID)
//收到的EPA报文是应用层报文,交由上层处理
Receive_Application_Data(); //见Application.c
}
}
/******************* End Of File **********************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -