通信编程总结
#include<stdio.h>
#include<stdlib.h>
enum protocal_name_t
{
TCP = 0,
local,
};
//通道所挂载的协议
struct commmunication_protocal_list_t
{
enum protocal_name_t protocal_name; //协议名称
int communication_root_id;//协议通道挂载的文件id
struct communication_protocal_list_t *next;
};
//通信时:每个通信通道都必须的数据结构
struct communication_root_data_t
{
int *frame; //帧的长度
int root_id;//用来区分是哪个通信通道
struct communication_protocal_list_t *communication_protocal_list;//各个通信通道所挂载的协议
int *data_buf;//底层串口真正的buf长度
};
struct communication_root_data_t *communication_root_data = 0;
//每个协议具体的配置:初始化,发送,解析,处理
struct protocal_concrete_config_t
{
struct communication_protocal_list_t *(*init) (struct communication_root_data_t *communication_root_data);
int(*send) (struct communication_root_data_t *communication_root_data);
int(*parse) (struct communication_root_data_t *communication_root_data);
int(*process) (struct communication_root_data_t *communication_root_data);
};
struct protocal_cfg_t
{
struct protocal_concrete_config_t *protocal_concrete_config;//具体的协议
int *clint;//每个协议对应的客户端
};
int clint[] = { 0x10,0x20,0x30,0x40,0x50 };
int clint1[] = { 0x20,0x30,0x40,0x50,0x60,0x70};//TCP和本地协议的客户端
struct communication_protocal_list_t * init(struct c