public void Assign(object right) { tGETMOTELINKS val = right as tGETMOTELINKS; if (val == null) { throw new Exception("object is not tGETMOTELINKS type!"); } else { mac.Assign(val.mac); idx = val.idx; } }
public void Assign(object right) { tGETPATHINFO val = right as tGETPATHINFO; if (val == null) { throw new Exception("object is not tGETPATHINFO type!"); } else { source.Assign(val.source); dest.Assign(val.dest); } }
public void Assign(object right) { tGETMOTECONFIG val = right as tGETMOTECONFIG; if (val == null) { throw new Exception("object is not tGETMOTECONFIG type!"); } else { next = val.next; mac.Assign(val.mac); } }
public void Assign(object right) { tGETNEXTPATHINFO val = right as tGETNEXTPATHINFO; if (val == null) { throw new Exception("object is not tGETNEXTPATHINFO type!"); } else { mac.Assign(val.mac); filter = val.filter; pathId = val.pathId; } }
/// <summary> /// 进行WS固件升级 /// </summary> /// <param name="macList">请求升级的WS列表</param> /// <param name="firmware">请求升级的固件信息</param> /// <returns>请求成功与否</returns> public bool Update(List <tMAC> macList, tFirmware firmware) { if (macList == null || macList.Count == 0 || firmware == null || firmware.DicFwBlockDat == null || firmware.DicFwBlockDat.Count == 0) { return(false); } try { // 复制一份升级mote列表 lstUpdWs = new List <tMAC>(); foreach (tMAC mote in macList) { tMAC addMote = new tMAC(); addMote.Assign(mote); lstUpdWs.Add(addMote); } // 复制一份固件信息 fw = new tFirmware(firmware); // 构造升级线程 Thread threadUpdateWorker = new Thread(UpdateHandler); threadUpdateWorker.Name = "UpdateHandler"; threadUpdateWorker.Priority = ThreadPriority.AboveNormal; // 线程升级线程 threadUpdateWorker.Start(); return(true); } catch (Exception ex) { CommStackLog.RecordErr(enLogLayer.eAdapter, "Message:" + ex.Message); CommStackLog.RecordErr(enLogLayer.eAdapter, "Source: " + ex.Source); CommStackLog.RecordErr(enLogLayer.eAdapter, "StackTrace: " + ex.StackTrace); CommStackLog.RecordErr(enLogLayer.eAdapter, "ToString: " + ex.ToString()); return(false); } }
/// <summary> /// 系统脉搏定时器超时处理函数 /// </summary> private void heartbeatHandler() { CommStackLog.RecordInf(enLogLayer.eAdapter, "heartbeatHandler running"); while (m_bKeepRunning) { m_msigMainThreadRun.WaitOne(); m_asigHaultHeartbeat.Reset(); if (m_bHaultHeartbeat) { m_asigHaultHeartbeat.Set(); Thread.Sleep(200); continue; } try { if (m_Mesh.IsQueryingAllWs) { tMAC queryIter = new tMAC("0000000000000000"); ITERATOR: m_asigGetMtCfg.Reset(); m_bGetMtCfgTimeout = false; if (GetNextMoteConfig(queryIter) != enURErrCode.ERR_NONE) { CommStackLog.RecordInf(enLogLayer.eAdapter, "QueryAllWs unadmissible"); m_Mesh.IsQueryingAllWs = false; if (queryAllWsFailed != null) { queryAllWsFailed(); } continue; } else if (queryIter.isEqual(new tMAC("0000000000000000"))) { CommStackLog.RecordInf(enLogLayer.eAdapter, "QueryAllWs start"); lock (m_dicOnLineWs) { m_dicOnLineWs.Clear(); } m_i32MoniterWsIdx = 0; } if (!m_asigGetMtCfg.WaitOne(m_Mesh.AgtReq2MgrRepTimeout)) { m_bGetMtCfgTimeout = true; } if (!m_bGetMtCfgTimeout) { if (m_cacheGetMtCfgResult.RC == eRC.RC_OK) { if (!m_cacheGetMtCfgResult.isAP) { // Kous: 此处决定只要Mote不为Lost状态,则认为为在线 if (m_cacheGetMtCfgResult.u8State != (byte)enMoteState.Lost) { lock (m_dicOnLineWs) { m_dicOnLineWs.Add(m_cacheGetMtCfgResult.mac.ToHexString(), true); } } else { lock (m_dicOnLineWs) { m_dicOnLineWs.Add(m_cacheGetMtCfgResult.mac.ToHexString(), false); } } } else { m_macManager = (string)(m_cacheGetMtCfgResult.mac.ToHexString()).Clone(); } queryIter.Assign(m_cacheGetMtCfgResult.mac); goto ITERATOR; } else if (m_cacheGetMtCfgResult.RC == eRC.RC_END_OF_LIST) { queryIter.Assign(new tMAC("0000000000000000")); m_Mesh.IsQueryingAllWs = false; lock (m_dicOnLineWs) { if (QueryAllWsReaultNotify != null) { QueryAllWsReaultNotify(m_dicOnLineWs); } } CommStackLog.RecordInf(enLogLayer.eAdapter, "QueryAllWs end"); } else { m_Mesh.IsQueryingAllWs = false; if (queryAllWsFailed != null) { queryAllWsFailed(); } } } else { m_Mesh.IsQueryingAllWs = false; if (queryAllWsFailed != null) { queryAllWsFailed(); } } continue; } int iWsCnt1 = 0; lock (m_dicOnLineWs) { iWsCnt1 = m_dicOnLineWs.Count; } if (iWsCnt1 == 0) // 1 网络中无在线的WS { // 1.1 本次心跳周期内无接收到的报文 if (m_Serial.RxFrameCnt <= 0) { if (m_macManager == string.Empty) { Thread.Sleep(200); continue; } // 1.1.0 通过GetMoteConfig(Manager)感知系统脉搏 m_asigGetMtCfg.Reset(); m_bGetMtCfgTimeout = false; GetMoteConfig(new tMAC(m_macManager)); m_asigGetMtCfg.WaitOne(); // 1.1.1 GetMoteConfig(Manager)超时 if (m_bGetMtCfgTimeout) { if (m_u8HeartbeatRetryCnt++ > HEARTBEET_RETRY_TIMES) { m_u8HeartbeatRetryCnt = 0; CommStackLog.RecordInf(enLogLayer.eAdapter, "Pace-making failed!"); sessnLost(); } else { CommStackLog.RecordInf(enLogLayer.eAdapter, "Pace-making timeout!"); } } // 1.1.2 GetMoteConfig(Manager)正常 else { CommStackLog.RecordInf(enLogLayer.eAdapter, "Pace-making"); } } // 1.2 本次心跳周期内有接收到的报文 else { CommStackLog.RecordInf(enLogLayer.eAdapter, "Pace-making(Rx " + m_Serial.RxFrameCnt + ")"); // Added in 2016.10.21 by Kous,添加下一条语句 m_Serial.RxFrameCnt = 0; } } else // 2 网络中有在线的WS { // 2.0 通过GetMoteConfig感知系统脉搏 m_asigGetMtCfg.Reset(); m_bGetMtCfgTimeout = false; lock (m_dicOnLineWs) { GetMoteConfig(new tMAC(m_dicOnLineWs.Keys.ElementAt(m_i32MoniterWsIdx))); } m_asigGetMtCfg.WaitOne(); // 2.1 GetMoteConfig超时 if (m_bGetMtCfgTimeout) { if (m_u8HeartbeatRetryCnt++ > HEARTBEET_RETRY_TIMES) { m_u8HeartbeatRetryCnt = 0; CommStackLog.RecordInf(enLogLayer.eAdapter, "Pace-making failed!"); sessnLost(); } else { CommStackLog.RecordInf(enLogLayer.eAdapter, "Pace-making timeout!"); } } // 2.2 GetMoteConfig正常 else { CommStackLog.RecordInf(enLogLayer.eAdapter, "Pace-making"); m_u8HeartbeatRetryCnt = 0; int iWsCnt2 = 0; lock (m_dicOnLineWs) { iWsCnt2 = m_dicOnLineWs.Count; } // 轮询完毕,从头开始 if (++m_i32MoniterWsIdx >= iWsCnt2) { m_i32MoniterWsIdx = 0; } } } int residueSleepTime = cfgHeartbeatInterval; while (residueSleepTime > 200) { Thread.Sleep(200); if (m_Mesh.IsQueryingAllWs) { break; } residueSleepTime = residueSleepTime - 200; } if (m_Mesh.IsQueryingAllWs) { continue; } if (residueSleepTime > 0) { Thread.Sleep(residueSleepTime); } continue; } catch (Exception ex) { CommStackLog.RecordErr(enLogLayer.eAdapter, "Message:" + ex.Message); CommStackLog.RecordErr(enLogLayer.eAdapter, "Source: " + ex.Source); CommStackLog.RecordErr(enLogLayer.eAdapter, "StackTrace: " + ex.StackTrace); CommStackLog.RecordErr(enLogLayer.eAdapter, "ToString: " + ex.ToString()); } } }