diff --git a/TSCP/src/MSCP/CFM/CFM_Net.c b/TSCP/src/MSCP/CFM/CFM_Net.c index 3dbfa2f..31e6195 100644 --- a/TSCP/src/MSCP/CFM/CFM_Net.c +++ b/TSCP/src/MSCP/CFM/CFM_Net.c @@ -37,8 +37,15 @@ #include "PFM_RemoteUpdate.h" #include "MSCP_Define.h" #include "CFM_Raw.h" +#include "CM_IP.h" #include +/** @brief 网卡名 */ +#define CFM_IP_INTERFACE_2oo2 "fec0" +#define CFM_IP_INTERFACE_2x2 "fec1" +#define CFM_IP_INTERFACE_MAINTAIN "wm0" +#define CFM_IP_NETMASK "255.255.255.0" + #define CFM_2oo2_MSG_NUM_MAX (200u) #define CFM_2X2_MSG_NUM_MAX (200u) #define CFM_OUTNET_MSG_NUM_MAX (5000u) @@ -3325,24 +3332,17 @@ void CFM_Net_Init(void) void CFM_NetworkCard_Init(void) { /*- 变量初始化 */ - CM_CHAR str[1024] = {0}; + ENUM_CM_RETURN ret = ENUM_CM_FALSE; /*- 配置2取网卡ip */ - (void)memset(str, 0, sizeof(str)); - (void)sprintf(str, "ifconfig %s %s", "fec0", g_PFM_Cfg.Local_Cfg.IP_2oo2); - (void)printf("%s\n",str); - (void)system(str); - + /*- 配置2取网卡ip */ + ret = CM_IP_TrySetIpAddrRetry(CFM_IP_INTERFACE_2oo2, g_PFM_Cfg.Local_Cfg.IP_2oo2, CFM_IP_NETMASK, 2); + CM_NM_ASSERT(ENUM_CM_TRUE == ret, NET_MODE, DARK_FAULT_CODE_FUN_ORDER_42, TSCP_DARK_ASSERT_1); /*- 配置通用网卡ip */ - (void)memset(str, 0, sizeof(str)); - (void)sprintf(str, "ifconfig %s %s", "fec1", g_PFM_Cfg.Local_Cfg.IP_Com); - (void)printf("%s\n",str); - (void)system(str); - + ret = CM_IP_TrySetIpAddrRetry(CFM_IP_INTERFACE_2x2, g_PFM_Cfg.Local_Cfg.IP_Com, CFM_IP_NETMASK, 2); + CM_NM_ASSERT(ENUM_CM_TRUE == ret, NET_MODE, DARK_FAULT_CODE_FUN_ORDER_42, TSCP_DARK_ASSERT_2); /*- 配置维护网卡ip */ - (void)memset(str, 0, sizeof(str)); - (void)sprintf(str, "ifconfig %s %s", "wm0", g_PFM_Cfg.Local_Cfg.IP_Maintain); - (void)printf("%s\n",str); - (void)system(str); + ret = CM_IP_TrySetIpAddrRetry(CFM_IP_INTERFACE_MAINTAIN, g_PFM_Cfg.Local_Cfg.IP_Maintain, CFM_IP_NETMASK, 2); + CM_NM_ASSERT(ENUM_CM_TRUE == ret, NET_MODE, DARK_FAULT_CODE_FUN_ORDER_42, TSCP_DARK_ASSERT_3); } /** * @brief UDP接收线程 diff --git a/TSCP/src/MSCP/CM/CM_IP.c b/TSCP/src/MSCP/CM/CM_IP.c new file mode 100644 index 0000000..6464fe8 --- /dev/null +++ b/TSCP/src/MSCP/CM/CM_IP.c @@ -0,0 +1,437 @@ +#include "CM_IP.h" +#include "CM_Memory.h" +#include "PFM_Log.h" + +#include +#include +#include +#include +#include +#include +#include + +/** +* @brief 检查设置IP接口的输入参数 +* @param[in] pNetCardName 网卡名 +* @param[in] pIpAddr IPv4地址字符串 +* @param[in] pNetMask 子网掩码字符串 +* @return 参数检查结果 +*/ +static ENUM_CM_RETURN CM_IP_SetIpAddrParamCheck(IN const CM_CHAR *pNetCardName, + IN const CM_CHAR *pIpAddr, + IN const CM_CHAR *pNetMask) +{ + ENUM_CM_RETURN rt = ENUM_CM_FALSE; + + /* 按使用顺序检查参数,避免在空指针上执行strlen等操作。 */ + if (NULL == pNetCardName) + { + printf("CM_IP_SetIpAddr netcard name is NULL.\n"); + } + else if (strlen(pNetCardName) >= IFNAMSIZ) + { + printf("CM_IP_SetIpAddr netcard name is too long: %s.\n", pNetCardName); + } + else if (NULL == pIpAddr) + { + printf("CM_IP_SetIpAddr ipAddr is NULL.\n"); + } + else if (NULL == pNetMask) + { + printf("CM_IP_SetIpAddr netMask is NULL.\n"); + } + else + { + rt = ENUM_CM_TRUE; + } + + return rt; +} + +/** +* @brief 检查读取IP接口的输入参数 +* @param[in] pNetCardName 网卡名 +* @param[out] pIpAddr IPv4地址输出缓存 +* @param[in] ipAddrLen IPv4地址输出缓存长度 +* @param[out] pNetMask 子网掩码输出缓存 +* @param[in] netMaskLen 子网掩码输出缓存长度 +* @return 参数检查结果 +*/ +static ENUM_CM_RETURN CM_IP_GetIpAddrParamCheck(IN const CM_CHAR *pNetCardName, + OUT CM_CHAR *pIpAddr, + IN CM_UINT32 ipAddrLen, + OUT CM_CHAR *pNetMask, + IN CM_UINT32 netMaskLen) +{ + ENUM_CM_RETURN rt = ENUM_CM_FALSE; + + /* 输出缓存需要能够容纳最长IPv4字符串及结尾字符。 */ + if (NULL == pNetCardName) + { + printf("CM_IP_GetIpAddr netcard name is NULL.\n"); + } + else if (strlen(pNetCardName) >= IFNAMSIZ) + { + printf("CM_IP_GetIpAddr netcard name is too long: %s.\n", pNetCardName); + } + else if (NULL == pIpAddr) + { + printf("CM_IP_GetIpAddr ipAddr is NULL.\n"); + } + else if (CM_IP_ADDR_STR_LEN > ipAddrLen) + { + printf("CM_IP_GetIpAddr ipAddr buffer is too small.\n"); + } + else if (NULL == pNetMask) + { + printf("CM_IP_GetIpAddr netMask is NULL.\n"); + } + else if (CM_IP_ADDR_STR_LEN > netMaskLen) + { + printf("CM_IP_GetIpAddr netMask buffer is too small.\n"); + } + else + { + rt = ENUM_CM_TRUE; + } + + return rt; +} + +/** +* @brief 设置网卡IPv4地址 +* @param[in] pNetCardName 网卡名 +* @param[in] pIpAddr IPv4点分十进制字符串 +* @param[in] pNetMask 子网掩码点分十进制字符串 +* @return 设置结果 +*/ +ENUM_CM_RETURN CM_IP_SetIpAddr(IN const CM_CHAR *pNetCardName, IN const CM_CHAR *pIpAddr, + IN const CM_CHAR *pNetMask) +{ + ENUM_CM_RETURN rt = ENUM_CM_FALSE; + ENUM_CM_RETURN retMem = ENUM_CM_FALSE; + ENUM_CM_RETURN paramCheckRt = ENUM_CM_FALSE; + CM_INT32 sock = -1; + CM_INT32 ret = 0; + CM_INT32 ipConvertRet = 0; + CM_INT32 netMaskConvertRet = 0; + struct ifreq ifReq; + struct sockaddr_in *pSockAddr = NULL; + struct in_addr netMaskAddr; + + /* 参数检查失败时不创建socket,也不修改网卡配置。 */ + paramCheckRt = CM_IP_SetIpAddrParamCheck(pNetCardName, pIpAddr, pNetMask); + if (ENUM_CM_TRUE == paramCheckRt) + { + /* ifreq在本函数中只初始化一次,网卡名和地址族供两个ioctl共用。 */ + retMem = CM_Memset((void*)&ifReq, (CM_UINT8)0U, (CM_SIZE_T)sizeof(struct ifreq), + (CM_SIZE_T)sizeof(struct ifreq)); + if (ENUM_CM_TRUE != retMem) + { + printf("CM_IP_SetIpAddr memset ifreq failed.\n"); + } + else + { + (void)strncpy(ifReq.ifr_name, pNetCardName, IFNAMSIZ - 1); + pSockAddr = (struct sockaddr_in*)&ifReq.ifr_addr; +#ifdef QNX + pSockAddr->sin_len = sizeof(struct sockaddr_in); +#endif + pSockAddr->sin_family = AF_INET; + + /* 先完成IP和掩码格式转换,任一格式错误都不执行ioctl。 */ + ipConvertRet = (CM_INT32)inet_pton(AF_INET, pIpAddr, &pSockAddr->sin_addr); + netMaskConvertRet = (CM_INT32)inet_pton(AF_INET, pNetMask, &netMaskAddr); + if (1 != ipConvertRet) + { + if (0 == ipConvertRet) + { + printf("CM_IP_SetIpAddr invalid ip address: %s.\n", pIpAddr); + } + else + { + perror("CM_IP_SetIpAddr inet_pton"); + } + } + else if (1 != netMaskConvertRet) + { + if (0 == netMaskConvertRet) + { + printf("CM_IP_SetIpAddr invalid netmask: %s.\n", pNetMask); + } + else + { + perror("CM_IP_SetIpAddr netmask inet_pton"); + } + } + else + { + sock = (CM_INT32)socket(AF_INET, SOCK_DGRAM, 0); + if (sock < 0) + { + perror("CM_IP_SetIpAddr socket"); + } + else + { + /*- 通过临时UDP socket设置指定网卡IP */ + ret = (CM_INT32)ioctl(sock, SIOCSIFADDR, &ifReq); + if (0 != ret) + { + perror("CM_IP_SetIpAddr ioctl SIOCSIFADDR"); + MSCP_LOG_MSG("CM_IP_SetIpAddr ioctl SIOCSIFADDR, %s:%s:%s\n",pNetCardName, pIpAddr, strerror(errno)); + } + else + { + /* 保留网卡名和地址族,只清除已使用的IP地址字段后写入掩码。 */ + retMem = CM_Memset((void*)&pSockAddr->sin_addr, (CM_UINT8)0U, + (CM_SIZE_T)sizeof(struct in_addr), + (CM_SIZE_T)sizeof(struct in_addr)); + if (ENUM_CM_TRUE != retMem) + { + printf("CM_IP_SetIpAddr memset address failed.\n"); + } + else + { + pSockAddr->sin_addr = netMaskAddr; + ret = (CM_INT32)ioctl(sock, SIOCSIFNETMASK, &ifReq); + if (0 != ret) + { + perror("CM_IP_SetIpAddr ioctl SIOCSIFNETMASK"); + MSCP_LOG_MSG("CM_IP_SetIpAddr ioctl SIOCSIFNETMASK, %s:%s:%s\n", + pNetCardName, pNetMask, strerror(errno)); + } + else + { + rt = ENUM_CM_TRUE; + } + } + } + + (void)close(sock); + } + } + } + } + + return rt; +} + +/** +* @brief 尝试设置网卡IPv4地址并读回校验 +* @param[in] pNetCardName 网卡名 +* @param[in] pIpAddr IPv4点分十进制字符串 +* @param[in] pNetMask 子网掩码点分十进制字符串 +* @return 设置和校验结果 +*/ +ENUM_CM_RETURN CM_IP_TrySetIpAddr(IN const CM_CHAR *pNetCardName, IN const CM_CHAR *pIpAddr, + IN const CM_CHAR *pNetMask) +{ + ENUM_CM_RETURN rt = ENUM_CM_FALSE; + ENUM_CM_RETURN setRt = ENUM_CM_FALSE; + ENUM_CM_RETURN getRt = ENUM_CM_FALSE; + CM_CHAR ipAddrRead[CM_IP_ADDR_STR_LEN] = { 0 }; + CM_CHAR netMaskRead[CM_IP_ADDR_STR_LEN] = { 0 }; + + /* 设置成功后立即读回,IP和掩码均一致才认为配置成功。 */ + setRt = CM_IP_SetIpAddr(pNetCardName, pIpAddr, pNetMask); + if (ENUM_CM_TRUE != setRt) + { + printf("CM_IP_TrySetIpAddr set ip failed.\n"); + } + else + { + getRt = CM_IP_GetIpAddr(pNetCardName, ipAddrRead, (CM_UINT32)sizeof(ipAddrRead), + netMaskRead, (CM_UINT32)sizeof(netMaskRead)); + if (ENUM_CM_TRUE != getRt) + { + printf("CM_IP_TrySetIpAddr get ip failed.\n"); + } + else if (0 != strcmp(ipAddrRead, pIpAddr)) + { + printf("CM_IP_TrySetIpAddr ip mismatch, set:%s, read:%s.\n", pIpAddr, ipAddrRead); + } + else if (0 != strcmp(netMaskRead, pNetMask)) + { + printf("CM_IP_TrySetIpAddr netmask mismatch, set:%s, read:%s.\n", pNetMask, netMaskRead); + } + else + { + rt = ENUM_CM_TRUE; + } + } + + return rt; +} + +/** +* @brief 尝试设置网卡IPv4地址,失败时重复尝试 +* @param[in] pNetCardName 网卡名 +* @param[in] pIpAddr IPv4点分十进制字符串 +* @param[in] pNetMask 子网掩码点分十进制字符串 +* @param[in] retryTimes 失败后的重试次数,总尝试次数为retryTimes + 1 +* @return 设置和校验结果 +*/ +ENUM_CM_RETURN CM_IP_TrySetIpAddrRetry(IN const CM_CHAR *pNetCardName, IN const CM_CHAR *pIpAddr, + IN const CM_CHAR *pNetMask, IN CM_UINT32 retryTimes) +{ + ENUM_CM_RETURN rt = ENUM_CM_FALSE; + CM_UINT32 tryIndex = 0u; + CM_CHAR log_buf[1024] = {0}; + + /* retryTimes表示首次尝试失败后的额外重试次数。 */ + while (CM_TRUE) + { + if (0u != tryIndex) + { + printf("CM_IP_TrySetIpAddrRetry retry %u.\n", tryIndex); + } + else + { + /* No action. */ + } + + rt = CM_IP_TrySetIpAddr(pNetCardName, pIpAddr, pNetMask); + if (ENUM_CM_TRUE == rt) + { + break; + } + else if (tryIndex >= retryTimes) + { + break; + } + else + { + tryIndex++; + } + } + + if (ENUM_CM_TRUE == rt) + { + (void)snprintf(log_buf, sizeof(log_buf), "IP Set Success, Interface:%s, IP:%s, NetMask:%s, retryTimes:%u.\n", + (NULL != pNetCardName) ? pNetCardName : "NULL", + (NULL != pIpAddr) ? pIpAddr : "NULL", + (NULL != pNetMask) ? pNetMask : "NULL", tryIndex); + } + else + { + (void)snprintf(log_buf, sizeof(log_buf), "IP Set Failed, Interface:%s, IP:%s, NetMask:%s, retryTimes:%u.\n", + (NULL != pNetCardName) ? pNetCardName : "NULL", + (NULL != pIpAddr) ? pIpAddr : "NULL", + (NULL != pNetMask) ? pNetMask : "NULL", tryIndex); + } + printf("%s", log_buf); + MSCP_LOG_MSG("%s", log_buf); + + return rt; +} + +/** +* @brief 读取网卡IPv4地址 +* @param[in] pNetCardName 网卡名 +* @param[out] pIpAddr IPv4点分十进制字符串输出缓存 +* @param[in] ipAddrLen pIpAddr缓存长度 +* @param[out] pNetMask 子网掩码字符串输出缓存 +* @param[in] netMaskLen pNetMask缓存长度 +* @return 读取结果 +*/ +ENUM_CM_RETURN CM_IP_GetIpAddr(IN const CM_CHAR *pNetCardName, OUT CM_CHAR *pIpAddr, + IN CM_UINT32 ipAddrLen, OUT CM_CHAR *pNetMask, + IN CM_UINT32 netMaskLen) +{ + ENUM_CM_RETURN rt = ENUM_CM_FALSE; + ENUM_CM_RETURN retMem = ENUM_CM_FALSE; + ENUM_CM_RETURN paramCheckRt = ENUM_CM_FALSE; + CM_INT32 sock = -1; + CM_INT32 ret = 0; + struct ifreq ifReq; + struct sockaddr_in *pSockAddr = NULL; + const CM_CHAR *pRetIpAddr = NULL; + + /* 参数合法后再清空输出,防止空指针或短缓存被写入。 */ + paramCheckRt = CM_IP_GetIpAddrParamCheck(pNetCardName, pIpAddr, ipAddrLen, + pNetMask, netMaskLen); + if (ENUM_CM_TRUE == paramCheckRt) + { + pIpAddr[0] = '\0'; + pNetMask[0] = '\0'; + /* ifreq在本函数中只初始化一次,随后仅复用其中的地址字段。 */ + retMem = CM_Memset((void*)&ifReq, (CM_UINT8)0U, (CM_SIZE_T)sizeof(struct ifreq), + (CM_SIZE_T)sizeof(struct ifreq)); + if (ENUM_CM_TRUE != retMem) + { + printf("CM_IP_GetIpAddr memset ifreq failed.\n"); + } + else + { + (void)strncpy(ifReq.ifr_name, pNetCardName, IFNAMSIZ - 1); + pSockAddr = (struct sockaddr_in*)&ifReq.ifr_addr; +#ifdef QNX + pSockAddr->sin_len = sizeof(struct sockaddr_in); +#endif + pSockAddr->sin_family = AF_INET; + + sock = (CM_INT32)socket(AF_INET, SOCK_DGRAM, 0); + if (sock < 0) + { + perror("CM_IP_GetIpAddr socket"); + } + else + { + /*- 通过临时UDP socket读取指定网卡IP */ + ret = (CM_INT32)ioctl(sock, SIOCGIFADDR, &ifReq); + if (0 != ret) + { + perror("CM_IP_GetIpAddr ioctl SIOCGIFADDR"); + MSCP_LOG_MSG("CM_IP_GetIpAddr ioctl SIOCGIFADDR, %s:%s:%s\n",pNetCardName, pIpAddr, strerror(errno)); + } + else + { + /*- 将二进制地址转换为点分十进制IP字符串 */ + pRetIpAddr = (const CM_CHAR*)inet_ntop(AF_INET, &pSockAddr->sin_addr, pIpAddr, ipAddrLen); + if (NULL == pRetIpAddr) + { + perror("CM_IP_GetIpAddr inet_ntop"); + } + else + { + /* 保留网卡名和地址族,只清除IP查询写入的地址字段。 */ + retMem = CM_Memset((void*)&pSockAddr->sin_addr, (CM_UINT8)0U, + (CM_SIZE_T)sizeof(struct in_addr), + (CM_SIZE_T)sizeof(struct in_addr)); + if (ENUM_CM_TRUE != retMem) + { + printf("CM_IP_GetIpAddr memset address failed.\n"); + } + else + { + ret = (CM_INT32)ioctl(sock, SIOCGIFNETMASK, &ifReq); + if (0 != ret) + { + perror("CM_IP_GetIpAddr ioctl SIOCGIFNETMASK"); + MSCP_LOG_MSG("CM_IP_GetIpAddr ioctl SIOCGIFNETMASK, %s:%s\n", + pNetCardName, strerror(errno)); + } + else + { + pRetIpAddr = (const CM_CHAR*)inet_ntop(AF_INET, &pSockAddr->sin_addr, + pNetMask, netMaskLen); + if (NULL == pRetIpAddr) + { + perror("CM_IP_GetIpAddr netmask inet_ntop"); + } + else + { + rt = ENUM_CM_TRUE; + } + } + } + } + } + + (void)close(sock); + } + } + } + + return rt; +} diff --git a/TSCP/src/MSCP/CM/CM_IP.h b/TSCP/src/MSCP/CM/CM_IP.h new file mode 100644 index 0000000..8dadca8 --- /dev/null +++ b/TSCP/src/MSCP/CM/CM_IP.h @@ -0,0 +1,65 @@ +/** +* @file CM_IP.h +* @brief 获取网卡IP地址 +*/ +#ifndef CM_IP_H_ +#define CM_IP_H_ + +#include "CM_Types.h" + +/** @brief IPv4点分十进制字符串长度,包含字符串结束符 */ +#define CM_IP_ADDR_STR_LEN (16u) + +/** +* @brief 设置网卡IPv4地址 +* @param[in] pNetCardName 网卡名 +* @param[in] pIpAddr IPv4点分十进制字符串,例如"192.168.1.10" +* @param[in] pNetMask 子网掩码点分十进制字符串,例如"255.255.255.0" +* @return 设置结果 +* - ENUM_CM_TRUE 成功 +* - ENUM_CM_FALSE 失败 +*/ +ENUM_CM_RETURN CM_IP_SetIpAddr(IN const CM_CHAR *pNetCardName, IN const CM_CHAR *pIpAddr, + IN const CM_CHAR *pNetMask); + +/** +* @brief 尝试设置网卡IPv4地址并读回校验 +* @param[in] pNetCardName 网卡名 +* @param[in] pIpAddr IPv4点分十进制字符串,例如"192.168.1.10" +* @param[in] pNetMask 子网掩码点分十进制字符串 +* @return 设置和校验结果 +* - ENUM_CM_TRUE 设置成功且读回一致 +* - ENUM_CM_FALSE 设置失败或读回不一致 +*/ +ENUM_CM_RETURN CM_IP_TrySetIpAddr(IN const CM_CHAR *pNetCardName, IN const CM_CHAR *pIpAddr, + IN const CM_CHAR *pNetMask); + +/** +* @brief 尝试设置网卡IPv4地址,失败时重复尝试 +* @param[in] pNetCardName 网卡名 +* @param[in] pIpAddr IPv4点分十进制字符串,例如"192.168.1.10" +* @param[in] pNetMask 子网掩码点分十进制字符串 +* @param[in] retryTimes 失败后的重试次数,总尝试次数为retryTimes + 1 +* @return 设置和校验结果 +* - ENUM_CM_TRUE 设置成功且读回一致 +* - ENUM_CM_FALSE 全部尝试失败或读回不一致 +*/ +ENUM_CM_RETURN CM_IP_TrySetIpAddrRetry(IN const CM_CHAR *pNetCardName, IN const CM_CHAR *pIpAddr, + IN const CM_CHAR *pNetMask, IN CM_UINT32 retryTimes); + +/** +* @brief 读取网卡IPv4地址 +* @param[in] pNetCardName 网卡名 +* @param[out] pIpAddr IPv4点分十进制字符串输出缓存 +* @param[in] ipAddrLen pIpAddr缓存长度,至少为CM_IP_ADDR_STR_LEN +* @param[out] pNetMask 子网掩码字符串输出缓存 +* @param[in] netMaskLen pNetMask缓存长度,至少为CM_IP_ADDR_STR_LEN +* @return 读取结果 +* - ENUM_CM_TRUE 成功 +* - ENUM_CM_FALSE 失败 +*/ +ENUM_CM_RETURN CM_IP_GetIpAddr(IN const CM_CHAR *pNetCardName, OUT CM_CHAR *pIpAddr, + IN CM_UINT32 ipAddrLen, OUT CM_CHAR *pNetMask, + IN CM_UINT32 netMaskLen); + +#endif diff --git a/TSCP/src/MSCP/PFM/PFM_Log.c b/TSCP/src/MSCP/PFM/PFM_Log.c index fd09120..ac39ed1 100644 --- a/TSCP/src/MSCP/PFM/PFM_Log.c +++ b/TSCP/src/MSCP/PFM/PFM_Log.c @@ -401,15 +401,14 @@ void MSCP_ASSERT(unsigned int x, unsigned int MaintenanceFlag, unsigned short Mo if(ENUM_INIT_MAIN_NET <= PFM_LOG_GET_INIT_STAGE()) { CFM_LogCiphertextSend(); - } - - /*- 等待日志队列全部发送*/ - LogQisEmpty = CFM_LogQ_isEmpty(); - while (ENUM_CM_FALSE == LogQisEmpty) - { - CFM_LogCiphertextSend(); - CM_Sleep(5u); + /*- 等待日志队列全部发送*/ LogQisEmpty = CFM_LogQ_isEmpty(); + while (ENUM_CM_FALSE == LogQisEmpty) + { + CFM_LogCiphertextSend(); + CM_Sleep(5u); + LogQisEmpty = CFM_LogQ_isEmpty(); + } } /*- 退出运营故障码*/ @@ -538,14 +537,14 @@ void MSCP_REBOOT_ASSERT(unsigned int x, unsigned int MaintenanceFlag,unsigned sh if(ENUM_INIT_MAIN_NET <= PFM_LOG_GET_INIT_STAGE()) { CFM_LogCiphertextSend(); - } - /*- 等待日志队列全部发送*/ - LogQisEmpty = CFM_LogQ_isEmpty(); - while (ENUM_CM_FALSE == LogQisEmpty) - { - CFM_LogCiphertextSend(); - CM_Sleep(5u); + /*- 等待日志队列全部发送*/ LogQisEmpty = CFM_LogQ_isEmpty(); + while (ENUM_CM_FALSE == LogQisEmpty) + { + CFM_LogCiphertextSend(); + CM_Sleep(5u); + LogQisEmpty = CFM_LogQ_isEmpty(); + } } /* 启动跟踪录制 */ @@ -1112,7 +1111,10 @@ CM_UINT32 *PFM_DarkLogGenerate(CM_UINT16 mode, CM_UINT16 fault, CM_UINT16 num) /* 宕机前向通控发送状态为宕机的心跳 连续发送三包*/ static void s_OutnetHeart_Send(void) { - CFM_TxOutnetHeart(ENUM_2x2_SHUTDOWN); - CFM_TxOutnetHeart(ENUM_2x2_SHUTDOWN); - CFM_TxOutnetHeart(ENUM_2x2_SHUTDOWN); + if(ENUM_INIT_NET <= PFM_LOG_GET_INIT_STAGE()) + { + CFM_TxOutnetHeart(ENUM_2x2_SHUTDOWN); + CFM_TxOutnetHeart(ENUM_2x2_SHUTDOWN); + CFM_TxOutnetHeart(ENUM_2x2_SHUTDOWN); + } }