/* initialize cm class */ INT cm_init(VOID) { NDIS_PHYSICAL_ADDRESS pa = NDIS_PHYSICAL_ADDRESS_CONST(-1, -1); D_LOG(D_ENTRY, ("cm_init: entry")); NdisZeroMemory(cm_tbl, sizeof(cm_tbl)); NdisZeroMemory(cm_used, sizeof(cm_used)); ChannelInit(); return(CM_E_SUCC); }
/******************************************************************************* * @function_name: LDRV_UsartOpen * @function_file: dr_Uart.c * @描述:配置UART的工作模式,打开UART接收 * @入口参数: com-指串口号, 枚举的端口之一 pModeConfig - 配置Uart的工作模式 rxfile-文件接收初始地址 size-文件大小 * @出口参数: 无 * @Attention: size一定要為sizeof(rxfile) *--------------------------------------------------------- * @修改人: ffq (2013-10-09) ******************************************************************************/ void LDRV_UsartOpen(COM_TYPEDEF com,COM_DataFormat type,COM_BaudeType baude,uint8 * rxfile,uint16 size, COM_DoubleMode doubleM) { MFS_UARTModeConfigT tUARTModeConfig; ChannelInit(); //电表通讯通道com和单片机通道channel映射 Comm[com].ucStR=IDLE; Comm[com].ucStt=IDLE; Comm[com].ucRecvTmr=0; Comm[com].ucTxTmr=0; /*数据地址之间传递*/ Comm[com].ucRxBuf = rxfile; /*接收数据长度大小*/ Comm[com].ucRXLen = size; Comm[com].ucTXLen = 0; Comm[com].ucRxPos=0; Comm[com].ucTxPos=0; Comm[com].ucResetTmr = RX_IDLE_RST; /*全双工/半双工*/ Comm[com].doubleMode =doubleM; /*配置开启接受*/ /*配置关闭接受使能*/ MFS_UARTDisableRX(Comm[com].channel); /*配置关闭发送总线空闲中断*/ MFS_UARTDisableTXBusIdleInt(Comm[com].channel); /*配置关闭发送使能*/ MFS_UARTDisableTX(Comm[com].channel); /*配置PLC端口*/ Init_UartPort(com); /*选择串口模式*/ /*选择PLC的波特率*/ BaudRate_Config(&tUARTModeConfig,baude); /*选择PLC的数据类型*/ DataFormat_Config(&tUARTModeConfig,type); /*配置串行数据从最低位开始传输*/ tUARTModeConfig.Bitorder=UART_BITORDER_LSB; /*配置Uart串行数据信号模式为NRZ模式*/ tUARTModeConfig.NRZ=UART_NRZ; /*配置PLC的工作模式*/ UARTConfigMode(Comm[com].channel,&tUARTModeConfig); //接收使能 LDRV_CommRxEnable(com); return; }
/*------------------------------------------------------------------------------ FUNCTION NAME: ConfigureApp DESCRIPTION: Reads COMMSERV###.INI file. Fills TerminalList global variable with terminals associated to each channel. Every channel is initialized call ChannelInit. PARAMETERS: - INPUT: - OUTPUT: RETURN: - TRUE: OK - FALSE: Error NOTES: ------------------------------------------------------------------------------*/ BOOL ConfigureApp (void) { int TerminalIdx; /* Aux. */ char StrAux[128]; /* Error messages string */ char Section[20]; int ChannelIdx; /* Channel index */ int Port, BaudRate; /* Serial port */ u_long TerminalNum; /* Terminal number */ BYTE Enabled; /* Terminal state: enabled/disbaled */ BYTE IncomingCalls; /* Incoming calls permission */ BYTE OutgoingCalls; /* Outgoing batch channel permission */ /* Line and operation mode */ BYTE LineType, OperationMode; char DialType[3]; /* Terminal phone */ char ModemPhone[20]; char IpAddr[30]; /* TCP/IP address and port */ u_short UdpPort; /* Channel timeouts */ u_long TerminalAnswerTimeOut; u_long DownloadTimeOut; u_long ModemTimeOut; u_short NumChannels, NumTerminals, NumCommLine; BYTE ProcessLockedState; /* Disable process during configuration update */ ProcessLockedState = DB_PROCESS.Locked; DB_PROCESS.Locked = TRUE; /* Get and check number of terminals */ NumTerminals = GetPrivateProfileInt ("TERMINALS", "NumTerminals", 0, "CommServer.ini"); if (!NumTerminals || NumTerminals < 0) { /* Error */ sprintf (StrAux, CS_LOG_MSG_00052); LogWrite (DB_PROCESS.LoggerRouteId, DB_PROCESS.CommServerRouteId, StrAux, 1); goto ErrorHandler; } /* endif */ /* Check number of channels value */ if (NumTerminals > MAX_TERMINALS_COMMSERVER) { /* Error */ sprintf (StrAux, CS_LOG_MSG_00053); LogWrite (DB_PROCESS.LoggerRouteId, DB_PROCESS.CommServerRouteId, StrAux, 1); goto ErrorHandler; } /* endif */ /* Fill node list structure with terminals in profile */ for (TerminalIdx = 0; TerminalIdx < NumTerminals; TerminalIdx++) { /* Section name */ sprintf (Section, "T%05u", TerminalIdx); /* Get and check Terminal number */ TerminalNum = GetPrivateProfileInt (Section, "TerminalNumber", 0, "CommServer.ini"); /* Operation mode. Default = online */ OperationMode = (BYTE) GetPrivateProfileInt (Section, "OperationMode", 0xff, "CommServer.ini"); /* Get and check channel index */ NumCommLine = GetPrivateProfileInt (Section, "Channel", 0, "CommServer.ini"); /* Get terinal operation state. Default = Enabled */ Enabled = (BYTE) GetPrivateProfileInt (Section, "Enabled", 0, "CommServer.ini"); /* Get ip address */ GetPrivateProfileString (Section, "Ip", " ", IpAddr, 16, "CommServer.ini"); /* Get tcp/ip port */ UdpPort = (u_short) GetPrivateProfileInt (Section, "UdpPort", 0, "CommServer.ini"); /* Channel modem phone number */ GetPrivateProfileString (Section, "ModemPhone", " ", ModemPhone, sizeof (ModemPhone), "CommServer.ini"); /* Initialize terminal */ DB_TERMINALS.NumTerminals++; if (!TerminalInit (TerminalIdx, TerminalNum, NumCommLine, OperationMode, ModemPhone, Enabled, inet_addr (IpAddr), htons (UdpPort))) { /* Error */ sprintf (StrAux, CS_LOG_MSG_00054, TerminalNum); LogWrite (DB_PROCESS.LoggerRouteId, DB_PROCESS.CommServerRouteId, StrAux, 1); goto ErrorHandler; } /* endif */ } /* endfor */ /*----------------------------------------------------------*/ /* Modification: bsearch & qsort operations synchronization */ /* XID on 02-APR-1998 */ /*----------------------------------------------------------*/ /* Lock database access */ LockDBAccess (); /* Sort terminals database */ qsort ((void *) &DB_TERMINALS.Terminal[0], (size_t) DB_TERMINALS.NumTerminals, sizeof (TerminalItemDef), (int (*)(const void*, const void*)) CompareTerminalItems); /* Unlock database access */ UnlockDBAccess (); /* Get and check number of channels */ NumChannels = GetPrivateProfileInt ("CHANNELS", "NumChannels", 0, "CommServer.ini"); if (!NumChannels || NumChannels < 0) { /* Error */ sprintf (StrAux, CS_LOG_MSG_00055); LogWrite (DB_PROCESS.LoggerRouteId, DB_PROCESS.CommServerRouteId, StrAux, 1); goto ErrorHandler; } /* endif */ /* Check number of channels value */ if (NumChannels > MAX_CHANNELS) { /* Error */ sprintf (StrAux, CS_LOG_MSG_00056); LogWrite (DB_PROCESS.LoggerRouteId, DB_PROCESS.CommServerRouteId, StrAux, 1); goto ErrorHandler; } /* endif */ /* Get channel information and call ChannelInit */ for (ChannelIdx = 0; ChannelIdx < NumChannels; ChannelIdx++) { /* Section name */ sprintf (Section, "CHANNEL%u", ChannelIdx); /* Get and check communication port */ Port = GetPrivateProfileInt (Section, "Port", 0, "CommServer.ini"); /* Get and check channel baud rate */ BaudRate = GetPrivateProfileInt (Section, "BaudRate", 0, "CommServer.ini"); /* Dial type. Default = tone */ GetPrivateProfileString (Section, "DialType", " ", DialType, 2, "CommServer.ini"); /* Get channel timeouts */ TerminalAnswerTimeOut = (int) GetPrivateProfileInt (Section, "TerminalAnswerTimeOut", 0, "CommServer.ini"); ModemTimeOut = (int) GetPrivateProfileInt (Section, "ModemTimeOut", 0, "CommServer.ini"); DownloadTimeOut = (int) GetPrivateProfileInt (Section, "DownloadTimeOut", 0, "CommServer.ini"); /* Line type */ LineType = (BYTE) GetPrivateProfileInt (Section, "LineType", 0xff, "CommServer.ini"); /* Get incoming calls permission (only for batch) */ IncomingCalls = (BYTE) GetPrivateProfileInt (Section, "IncomingCalls", 0, "CommServer.ini"); /* Get incoming calls permission (only for batch) */ OutgoingCalls = (BYTE) GetPrivateProfileInt (Section, "OutgoingCalls", 0, "CommServer.ini"); /* Get channel permission. Default = Enabled */ Enabled = (BYTE) GetPrivateProfileInt (Section, "Enabled", 0, "CommServer.ini"); /* Initialize channel */ DB_CHANNELS->NumChannels++; if (!ChannelInit (ChannelIdx, (u_short) ChannelIdx, Enabled, Port, LineType, BaudRate, DialType[0], TerminalAnswerTimeOut, DownloadTimeOut, ModemTimeOut, IncomingCalls, OutgoingCalls)) { /* Error */ sprintf (StrAux, CS_LOG_MSG_00057, ChannelIdx); LogWrite (DB_PROCESS.LoggerRouteId, DB_PROCESS.CommServerRouteId, StrAux, 1); goto ErrorHandler; } /* endif */ } /* endfor */ /* Configure channels with new added terminals */ if (!UpdateTerminalListChannel ()) { goto ErrorHandler; } /* endif */ /* Lock/Unlock channels depending on configured terminals */ for (ChannelIdx = 0; ChannelIdx < DB_CHANNELS->NumChannels; ChannelIdx++) { /* Lock channel if it has any associated terminal */ if (DB_CHANNELS->Channel[ChannelIdx].TerminalList.ListLength > 0) /* Lock channel */ LockChannel (ChannelIdx); else /* Unlock channel */ UnlockChannel (ChannelIdx); } /* endfor */ /* Restore process state */ DB_PROCESS.Locked = ProcessLockedState; /* Enable process */ DB_PROCESS.Enabled = PROCESS_ENABLED; /* Init. OK */ return TRUE; ErrorHandler: /* Restore process state */ DB_PROCESS.Locked = ProcessLockedState; return FALSE; } /* ConfigureApp */