/****************************************************************************** 版权所有: 文件名称: Uart_comm.c 文件版本: 01.01 创建作者: xxxxxx 创建日期: 2014-12-17 功能说明: 面板通信 其它说明: 修改记录: */ /*------------------------------- 头文件 -------------------------------------- */ #include "head.h" #ifdef FUN_GPRS #include "gprs_aux.h" #endif /*------------------------------- 宏定义 -------------------------------------- */ #define COMM_TYPE 5 #define MAX_INST_MASK 3 #define MAX_BOARD_MASK 3 /*------------------------------ 类型结构 ------------------------------------- */ UART_INST_BUF_DEF ptBuf[COMM_TYPE]; int prior=1; int hmi_chnl=0; bool hmi_status=0; DWORD count = 0; /*------------------------------ 函数声明 ------------------------------------- */ //static void _Uart_Comm_Send(int len,u8 *buf); //static void _uart_comm_queue(void); /*------------------------------ 外部函数 ------------------------------------- 外部函数供其它实体文件引用,必须仔细检查传入参数的合法性. */ void uart_comm_init(UART_COMM_STRUCT *pt,BYTE chnl) { memset(pt,0,sizeof(UART_COMM_STRUCT)); pt->type = IEC_HMI_CHN; hmi_chnl = chnl; } //将数据加入缓冲区 int Add_Uart_Frame(int board,int len,u8 *para) { UART_INST_DEF *pt = &ptBuf[board].tInst[ptBuf[board].head]; memcpy(pt->para, para, len); pt->len=(BYTE)len; ptBuf[board].head = (ptBuf[board].head + 1) & (UART_MAX_INST_BUFS-1); return 1; } void Sub_Uart_Frame(int board ) { ptBuf[board].tail = (ptBuf[board].tail - 1) & (UART_MAX_INST_BUFS-1); } void Uart_Comm_Send(void) { int i = 0; static int s_cnt[COMM_TYPE] ={0}; int ret = 0; //按优先级发送 for(i=1;ipara, (int)pt->len); if(ret==0) { ptBuf[i].tail = (ptBuf[i].tail + 1) & (UART_MAX_INST_BUFS-1); s_cnt[i]++; if(g_print_hmi) { print_msg("TX_HMI:",pt->para,(int)pt->len); } } break; } } else { s_cnt[i] = 0; } } } void Uart_Comm_Recv(void) { u8 buf[UART_FRAME_LEN]; int ret = 0; BYTE src_addr; BYTE dst_addr; ret = protocol_get_oneframe(&g_h_boj[0], buf); if(ret == 0) { ret = (int)buf[1] + 6; if(g_print_hmi) print_msg("RX_HMI:",buf, ret); if(buf[ret-1] & 0x80) { src_addr = (buf[ret-1] >> 3) & 0x07; // 起始地址 dst_addr = buf[ret-1] & 0x07; // 目标地址 switch(src_addr) { case HMI_BOARD: HMI_Board_Recv((int)buf[1] + 6, buf); hmi_status = true; count = ustimer_get_origin(); break; case PDA_BOARD: PDA_Board_Recv((int)buf[1] + 6, buf); break; case GPRS_BOARD: #ifdef FUN_GPRS // modfiy for xxxxxx 20220706 GPRS没有使用。 GPRS_Board_Proc((int)buf[1] + 6, buf); #endif break; case MAINTAIN_BOARD: Maintain_Board_Recv((int)buf[1] + 6,buf); break; default: break; } } } if(ustimer_get_duration(count) > 10 * USTIMER_SEC) { hmi_status = false; } } /*------------------------------ 内部函数 ------------------------------------- */ void Reset_Uart_Link(UART_COMM_STRUCT *pt) { pt->cTypeCounter = 0; pt->cRecvCnt = 0; } /*------------------------------ 文件结束 ------------------------------------- */