/// <summary>
        /// 获取等待时间最长的用户请求,请求出队列
        /// </summary>
        /// <returns>等待时间最长的用户请求</returns>
        public UserRequestElement DeQ()
        {
            lock (lockObj)
            {
                if (urgentReqQ.Count > 0)
                {
                    current = urgentReqQ.Dequeue();
                }
                else if (normalReqQ.Count > 0)
                {
                    current = normalReqQ.Dequeue();
                }
                // 队列中无请求
                else
                {
                    current = null;
                }

                // 当用户请求队列中无请求原子时,重置心情求入队列信号
                if ((urgentReqQ.Count + normalReqQ.Count) <= 0)
                {
                    sigNewReqArrived.Reset();
                }

                return(current);
            }
        }
        /// <summary>
        /// 将新的用户请求入紧急或者普通队列
        /// </summary>
        /// <param name="element">新请求元素</param>
        /// <returns>true表示请求入队列成功,false表示请求入队列失败,意味请求队列已满</returns>
        public bool EnQ(UserRequestElement element, bool urgent = false)
        {
            lock (lockObj)
            {
                // 检查请求队列是否已满
                if ((normalReqQ.Count + urgentReqQ.Count) >= capacity)
                {
                    return(false);
                }

                // 请求队列未满
                // 根据请求紧迫程度入队列
                if (urgent)
                {
                    urgentReqQ.Enqueue(element);
                }
                else
                {
                    normalReqQ.Enqueue(element);
                }

                sigNewReqArrived.Set();
                return(true);
            }
        }
示例#3
0
        public void Reset()
        {
            // 重置底层
            if (m_Ser != null)
            {
                m_Ser.Reset();
            }

            m_bBusyTx          = false;
            m_u8CmdId          = enCmd.CMDID_END;
            m_u8OutputBufLen   = 0;
            Adapter2MeshBridge = null;
            lock (m_dicAsyncCmdRespRecords)
            {
                m_dicAsyncCmdRespRecords.Clear();
            }

            m_asigMgrResponsed.Reset();
        }
示例#4
0
        /// <summary>
        /// 将用户请求转换成有意义的字符串
        /// </summary>
        /// <param name="element">用户请求元素</param>
        /// <returns>用户请求字符串描述</returns>
        private string describeCmd(UserRequestElement element)
        {
            if (element == null)
            {
                return("");
            }
            if (element.cmd != enCmd.CMDID_SENDDATA)
            {
                return(element.cmd.ToString());
            }
            else
            {
                tSENDDATA    sendData = (tSENDDATA)element.param;
                enAppMainCMD cmd      = (enAppMainCMD)(sendData.u8aData[APP_CMD_OFFS_IN_NOTF_DATA] >> 5);
                byte         subCmd   = (byte)(sendData.u8aData[APP_CMD_OFFS_IN_NOTF_DATA] & 0x1F);
                switch (cmd)
                {
                case enAppMainCMD.eNotify:
                {
                    if (subCmd == (byte)enAppNotifySubCMD.eSelfReport)
                    {
                        return("ReplySelfReport(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppNotifySubCMD.eHealthReport)
                    {
                        return("ReplyHealthReport(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppNotifySubCMD.eWaveDesc)
                    {
                        return("ReplyWaveDesc(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppNotifySubCMD.eWaveData)
                    {
                        return("ReplyWaveData(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppNotifySubCMD.eEigenVal)
                    {
                        return("ReplyEigenVal(" + sendData.mac.ToHexString() + ")");
                    }
                    else
                    {
                        return(null);
                    }
                }

                case enAppMainCMD.eSet:
                {
                    if (subCmd == (byte)enAppSetSubCMD.eTimeCali)
                    {
                        return("SetTimeCali(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppSetSubCMD.eNetworkID)
                    {
                        return("SetNetworkID(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppSetSubCMD.eMeasDef)
                    {
                        return("SetMeasDef(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppSetSubCMD.eSn)
                    {
                        return("SetSn(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppSetSubCMD.eCaliCoeff)
                    {
                        return("SetSensorCali(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppSetSubCMD.eADCloseVolt)
                    {
                        return("SetADCloseVolt(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppSetSubCMD.eRevStop)
                    {
                        return("SetRevStop(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppSetSubCMD.eTrigParam)
                    {
                        return("SetTrigParam(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppSetSubCMD.eWsRouteMode)
                    {
                        return("SetWsRouteMode(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppSetSubCMD.eWsDebugMode)
                    {
                        return("SetWsDebugMode(" + sendData.mac.ToHexString() + ")");
                    }
                    else
                    {
                        return(null);
                    }
                }

                case enAppMainCMD.eGet:
                {
                    if (subCmd == (byte)enAppGetSubCMD.eSn)
                    {
                        return("GetSn(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppGetSubCMD.eCaliCoeff)
                    {
                        return("GetCaliCoeff(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppGetSubCMD.eADCloseVolt)
                    {
                        return("GetADCloseVolt(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppGetSubCMD.eRevStop)
                    {
                        return("GetRevStop(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppGetSubCMD.eTrigParam)
                    {
                        return("GetTrigParam(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppGetSubCMD.eWsRouteMode)
                    {
                        return("GetWsRouteMode(" + sendData.mac.ToHexString() + ")");
                    }
                    else
                    {
                        return(null);
                    }
                }

                case enAppMainCMD.eRestore:
                {
                    if (subCmd == (byte)enAppRestoreSubCMD.eWS)
                    {
                        return("RestoreWS(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppRestoreSubCMD.eWG)
                    {
                        return("RestoreWG" + sendData.mac.ToHexString() + ")");
                    }
                    else
                    {
                        return(null);
                    }
                }

                case enAppMainCMD.eReset:
                {
                    if (subCmd == (byte)enAppResetSubCMD.eWS)
                    {
                        return("ResetWS(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppResetSubCMD.eWG)
                    {
                        return("ResetWG" + sendData.mac.ToHexString() + ")");
                    }
                    else
                    {
                        return(null);
                    }
                }

                case enAppMainCMD.eUpdate:
                {
                    if (subCmd == (byte)enAppUpdateSubCMD.eFwDesc)
                    {
                        return("UpdateFwDesc(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppUpdateSubCMD.eFwData)
                    {
                        return("UpdateFwData(" + sendData.mac.ToHexString() + ")");
                    }
                    else if (subCmd == (byte)enAppUpdateSubCMD.eControl)
                    {
                        return("UpdateControl(" + sendData.mac.ToHexString() + ")");
                    }
                    else
                    {
                        return(null);
                    }
                }

                default: return("");
                }
            }
        }