/// <summary> /// 新的升级方案中,在升级后先将网络中的所有WS解言(允许上传数据) /// </summary> /// <returns>允许上传数据是否成功</returns> private bool dismuteWsUpstream() { int iWsCnt = 0; lock (m_dicOnLineWs) { iWsCnt = m_dicOnLineWs.Count; } if (iWsCnt == 0) { CommStackLog.RecordErr(enLogLayer.eAdapter, "No online WS"); return(false); } else { // 打印当前在线WS集合,方便问题定位 lock (m_dicOnLineWs) { foreach (string ws in m_dicOnLineWs.Keys) { if (m_dicOnLineWs[ws]) { CommStackLog.RecordInf(enLogLayer.eAdapter, ws + " online"); } else { CommStackLog.RecordInf(enLogLayer.eAdapter, ws + " offline"); } } } // 进入使言期 m_bMuteOrDismute = false; List <string> lstDismutedSuccess = new List <string>(); lock (m_listMutedWs) { foreach (string key in m_listMutedWs) { lock (m_dicOnLineWs) { try { if (!m_dicOnLineWs[key]) { continue; } } catch (Exception ex) { continue; } } tCtlWsUpstrParam param = new tCtlWsUpstrParam(); tMAC mac = new tMAC(key); param.mac.Assign(mac); param.u8Control = 0; m_asigDismute.Reset(); m_bDismuteTimeout = false; CtlWsUpstr(param); // 判定是否迷失 if (m_asigDismute.WaitOne(SYC_WAIT_MAX_TIME)) { if (m_bDismuteTimeout) { m_asigDismute.Reset(); m_bDismuteTimeout = false; CommStackLog.RecordErr(enLogLayer.eAdapter, "Dismuted(" + key + ") timeout"); continue; } else { m_asigDismute.Reset(); m_bDismuteTimeout = false; CommStackLog.RecordInf(enLogLayer.eAdapter, "Dismuted(" + key + ") ok"); lstDismutedSuccess.Add(key); } } else { m_asigDismute.Reset(); m_bDismuteTimeout = false; CommStackLog.RecordInf(enLogLayer.eAdapter, "Dismuted(" + key + ") lost"); } } // 从禁言列表中删除已经成功解言的WS foreach (string key in lstDismutedSuccess) { m_listMutedWs.Remove(key); } lstDismutedSuccess.Clear(); // 如果目前还有未解言的WS,则很有可能是最后一个升级的WS,最多再等待10分钟 if (m_listMutedWs.Count != 0) { int waitWsOnlineTolerance = 600000; int waitWsOnlineCheckTime = 0; while (waitWsOnlineCheckTime < waitWsOnlineTolerance) { // 每间隔1秒钟检查是否有新的WS加入 Thread.Sleep(1000); waitWsOnlineCheckTime += 1000; // 检查是否未解言的WS加入网络 foreach (string key in m_listMutedWs) { lock (m_dicOnLineWs) { try { if (!m_dicOnLineWs[key]) { continue; } } catch (Exception ex) { continue; } } // 一旦未解言成功的WS加入网络,则进行解言 tCtlWsUpstrParam param = new tCtlWsUpstrParam(); param.mac.Assign(new tMAC(key)); param.u8Control = 0; m_asigDismute.Reset(); m_bDismuteTimeout = false; CtlWsUpstr(param); // 判定是否迷失 if (m_asigDismute.WaitOne(SYC_WAIT_MAX_TIME)) { if (m_bDismuteTimeout) { m_asigDismute.Reset(); m_bDismuteTimeout = false; CommStackLog.RecordErr(enLogLayer.eAdapter, "Dismuted(" + key + ") timeout"); continue; } else { m_asigDismute.Reset(); m_bDismuteTimeout = false; CommStackLog.RecordInf(enLogLayer.eAdapter, "Dismuted(" + key + ") ok"); lstDismutedSuccess.Add(key); } } else { m_asigDismute.Reset(); m_bDismuteTimeout = false; CommStackLog.RecordInf(enLogLayer.eAdapter, "Dismuted(" + key + ") lost"); } } // 从禁言列表中删除已经成功解言的WS foreach (string key in lstDismutedSuccess) { m_listMutedWs.Remove(key); } lstDismutedSuccess.Clear(); // 所有该解言的WS都解言完成,退出解言过程 if (m_listMutedWs.Count == 0) { return(true); } } if (waitWsOnlineCheckTime >= waitWsOnlineTolerance) { return(false); } } } return(true); } }
/// <summary> /// 在升级前先将网络中的所有WS禁言(禁止上传数据) /// </summary> /// <returns>禁止上传数据是否成功</returns> private bool muteWsUpstream() { int iWsCnt = 0; lock (m_dicOnLineWs) { iWsCnt = m_dicOnLineWs.Count; } if (iWsCnt == 0) { CommStackLog.RecordErr(enLogLayer.eAdapter, "No online WS"); return(false); } else { lock (m_dicOnLineWs) { foreach (string ws in m_dicOnLineWs.Keys) { if (m_dicOnLineWs[ws]) { dicExpectedMutedWs.Add(ws, true); CommStackLog.RecordInf(enLogLayer.eAdapter, ws + " online"); } else { CommStackLog.RecordInf(enLogLayer.eAdapter, ws + " offline"); } } } // 进入禁言期 m_bMuteOrDismute = true; // 清空已控制WS列表 m_listMutedWs.Clear(); lock (m_listMutedWs) { foreach (string key in dicExpectedMutedWs.Keys) { tCtlWsUpstrParam param = new tCtlWsUpstrParam(); param.mac.Assign(new tMAC(key)); param.u8Control = 1; m_asigMute.Reset(); m_bMuteTimeout = false; // 通知WS暂不上传波形数据 CtlWsUpstr(param); // 判定是否迷失 if (m_asigMute.WaitOne(SYC_WAIT_MAX_TIME)) { if (m_bMuteTimeout) { m_asigMute.Reset(); m_bMuteTimeout = false; CommStackLog.RecordErr(enLogLayer.eAdapter, "Muted(" + key + ") timeout"); } else { m_asigMute.Reset(); m_bMuteTimeout = false; // 记录已经禁言成功的WS MAC地址 m_listMutedWs.Add(key); CommStackLog.RecordInf(enLogLayer.eAdapter, "Muted(" + key + ") ok"); } } else { m_asigMute.Reset(); m_bMuteTimeout = false; // 迷失的情况也算是禁言成功 CommStackLog.RecordInf(enLogLayer.eAdapter, "Muted(" + key + ") lost"); } } dicExpectedMutedWs.Clear(); } // 如果没有一个WS能够控制成功,则告诉上层不能升级 if (m_listMutedWs.Count == 0) { return(false); } else { return(true); } } }