📄 socket_data_struct.h
字号:
#ifndef _socket_H
#define _socket_H
/*
#if !defined unsigned int
#define unsigned int unsigned int
#endif
#if !defined WORD
#define WORD unsigned short
#endif
*/
#if !defined NULL
#define NULL 0
#endif
#define PACKETLEN 1024
#include <iostream.h>
/****
struct Message is a unification communication format between socket layer
and mdot layer or application layer
****/
typedef struct
{
unsigned int Device; // message type:DEVICE_SYSTEM or DEVICE_TRANSMIT
unsigned int Event; // message name:there are different kinds of message
unsigned int SubMsg; // acorrding to event,have different value of submsg
unsigned int Length; // if it is DEVICE_TRANSMIT,present the actual length of data, if not, the value is 0
char *DataPtr; // this attribute to get real data
unsigned int Data[2]; // Data[0] holds destination's device ID, Data[1] is 0 at temporary
}Message;
/****
struct RUDP is a unification communication format between one side of the socket
layer to the other side
****/
typedef struct
{
char RUDPVersion; // the value is 1 at temporary
unsigned int S_deviceID; // the sender's device ID
unsigned int D_deviceID; // the receiver's device ID
char packet_type; // packet type: 0 for data packet,while 1 for control one
unsigned short packet_length; // this means the whole length,including RUDP header and data length
unsigned int packet_seq; // every packet has a single sequence number,and this attribute holds it
}RUDP;
/****
from activity list,get ip and port by the know device ID,packet
ip and port as Addr_Str for convenient transsmition
****/
typedef struct
{
unsigned int ip; // the right ip according to the device ID
unsigned short port; // the right port according to the device ID
}Addr_Str;
/****
struct A_FIND_STR is for judging the device ID,ip,and sequence number of the RUDP packet
****/
typedef struct
{
unsigned int type; // different types means different ways to compare
unsigned int deviceID; // way in compare device ID
unsigned int ip; // way in compare ip
unsigned int seq; // way in compare sequence number
}A_FIND_STR;
/****
struct T2_ITEM_STR is use for retranssimition once packet can not
successfully transits at the first time
****/
typedef struct
{
unsigned int deviceID; // the sender's device ID
unsigned int RUDP_Seq; // the packet's sequence number
unsigned int N; // the times of retransimmision
unsigned int T; // the value of the timer
Message msg; // the messages from the mdot layer or application layer
Addr_Str addr_str; // the receiver's address(ip and port)
RUDP rudp; // the header of RUDP
char *packet_ptr; // the data of RUDP
// operator overload,in order to locate the retranssimition packet
bool operator==(const A_FIND_STR& a_find_str)
{
return (deviceID==a_find_str.deviceID)&&(RUDP_Seq==a_find_str.seq);
}
}T2_ITEM_STR;
/****
struct Seq_STR is for add the right sequence in RUDP packet and
make sure the receiver receive the expect packet
****/
typedef struct
{
unsigned int D_deviceID; // the receiver's device ID
unsigned int s; // the sender side's current packet sequence number
unsigned int r; // the expect sequence number of the packet the receiver wanna get
}Seq_STR;
/****
struct ActivityNode_STR is for getting ip,port or password by device ID
****/
typedef struct
{
unsigned int deviceID; // device ID
unsigned int ip; // deviceID corresponds to this ip
unsigned short port; // deviceID corresponds to this port
char password[8]; // deviceID corresponds to this password
// operator overload,in order to locate the device ID or ip
bool operator==(const A_FIND_STR& a_find_str)
{
if(a_find_str.type==0)
{
return deviceID==a_find_str.deviceID;
}
else
{
return ip==a_find_str.ip;
}
}
}ActivityNode_STR;
/****
struct No_ActivityNode_STR is for getting ip,port or password by device ID
****/
typedef struct
{
unsigned int deviceID; // device ID
unsigned int ip; // deviceID corresponds to this ip
unsigned short port; // deviceID corresponds to this port
char password[8]; //deviceID corresponds to this password
// operator overload,in order to locate the device ID or ip
bool operator==(const A_FIND_STR& a_find_str)
{
if(a_find_str.type==0)
{
return deviceID==a_find_str.deviceID;
}
else if(a_find_str.type==1)
{
return ip==a_find_str.ip;
}
else
{
return (deviceID==a_find_str.deviceID)&&(ip==a_find_str.ip);
}
}
}No_ActivityNode_STR;
/****
struct Data_Queue_STR is the content of the receiver's receive buffer holds
****/
typedef struct
{
unsigned int RUPDTag; // RUDP tag
char rudp_data[PACKETLEN]; // RUDP data
}Data_Queue_STR;
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -