Esempio n. 1
0
        /// <summary>
        /// 项目扣分
        /// </summary>
        /// <param name="kch">考车号</param>
        /// <param name="xmbh">项目编号,包含项目编号和错误编号,用@分隔</param>
        /// <param name="time">时间</param>
        /// <returns></returns>
        private bool HandleM17C53(int kch, string xmbh, string time)
        {
            string errorMsg = string.Empty;

            string[] strArray = BaseMethod.SplitString(xmbh, BaseDefine.SPLIT_CHAR_AT, out errorMsg);
            if (!string.IsNullOrEmpty(errorMsg) || strArray.Length != 2)
            {
                Log.GetLogger().ErrorFormat("17C53 接口存在错误,{0}", errorMsg);
                return(false);
            }
            string strXmCode     = strArray[0];
            string strErrrorCode = strArray[1];
            int    xmCode        = string.IsNullOrEmpty(strXmCode) ? 0 : int.Parse(strXmCode);

            int kskm = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_ENV, BaseDefine.CONFIG_SECTION_CONFIG,
                                                 BaseDefine.CONFIG_KEY_KSKM, 0); //考试科目
            string xmName = string.Empty;                                        //项目名称

            if (BaseDefine.CONFIG_VALUE_KSKM_3 == kskm)                          //科目三
            {
                xmName = GetKM3Name(xmCode);
            }
            else  //科目二
            {
                xmName = GetKM2Name(xmCode);
            }

            //扣分类型、扣除分数
            if (!m_dicJudgeRules.ContainsKey(strErrrorCode))
            {
                Log.GetLogger().ErrorFormat("数据库扣分规则表中不存在错误编号为 {0} 的记录,请检查配置。", strErrrorCode);
                return(false);
            }
            string kflx = m_dicJudgeRules[strErrrorCode].JudgementType;
            int    kcfs = m_dicJudgeRules[strErrrorCode].Points;

            if (!m_dicExamProcedures.ContainsKey(kch))
            {
                Log.GetLogger().ErrorFormat("m_dicExamProcedures 字典找不到考车号 : {0}", kch);
                return(false);
            }
            ExamProcedure examProcedure = m_dicExamProcedures[kch];

            if (!examProcedure.Handle17C53(xmName, kflx, kcfs))
            {
                Log.GetLogger().ErrorFormat("examProcedure.Handle17C53 failed, kch={0}", kch);
                return(false);
            }

            Log.GetLogger().InfoFormat("HandleM17C53 end, kch={0}, xmName={1}, kflx={2}, kcfs={3}", kch, xmName, kflx, kcfs);
            return(true);
        }
Esempio n. 2
0
        //设置串口参数
        public override void SetCom(ComParam param)
        {
            if (string.IsNullOrEmpty(param.Com) || param.Rate <= 0)
            {
                logger.ErrorFormat("SetCom param error, portname={0}, baudrate={1}", param.Com, param.Rate);
                return;
            }

            string errorMsg = string.Empty;

            signalData = BaseMethod.SplitString(param.Pwd, ',', out errorMsg);
            if (!string.IsNullOrEmpty(errorMsg))
            {
                logger.ErrorFormat("SetCom param error, pwd={0}", param.Pwd);
                return;
            }

            com = new BekUtils.Communication.ComUtil(param.Com, param.Rate, param.DataBits);
        }
Esempio n. 3
0
        //采样线程函数
        private void SampleThreadProc()
        {
            while (true)
            {
                #region 连接串口
                if (!com.IsOpen)
                {
                    int nRet = com.ConnectSerialPort();
                    if (-1 == nRet)
                    {
                        logger.ErrorFormat("ConnectSerialPort faild, retry after sleep");
                        Thread.Sleep(BaseDefine.COMMON_VALUE_SLEEP_2500);
                        continue;
                    }
                    else if (-2 == nRet)
                    {
                        logger.ErrorFormat("ConnectSerialPort faild, abort sample thread");
                        sampleThread.Abort();
                        return;
                    }
                }
                #endregion

                //读 OBD 数据
                string   errorMsg = string.Empty;
                string   retStr   = string.Empty;
                int      nLen     = com.ReadSerialPort(ref retStr);
                string[] destList = BaseMethod.SplitString(retStr, '$', out errorMsg);
                if (!string.IsNullOrEmpty(errorMsg))
                {
                    logger.ErrorFormat(errorMsg);
                    Thread.Sleep(BaseDefine.COMMON_VALUE_SLEEP_200);
                    continue;
                }

                //解析 OBD 数据
                for (int i = 0; i < destList.Length; i++)
                {
                    string   tempError = string.Empty;
                    string[] dest      = BaseMethod.SplitString(destList[i], ',', out tempError);
                    if (!string.IsNullOrEmpty(tempError))
                    {
                        logger.InfoFormat("OBD 存在空数据,destList[{0}]={1}", i, destList[i]);
                        continue;
                    }

                    if (BaseDefine.DATA_TYPE_OBD_DT == dest[0])
                    {
                        if (dest.Length >= 22)
                        {
                            #region 从协议取值
                            lock (lockObj)
                            {
                                #region 安全带
                                if ("1" == dest[12])
                                {
                                    sampleData.Aqd = 1;
                                }
                                else if ("#" == dest[12])
                                {
                                    sampleData.Aqd = 9;
                                }
                                else
                                {
                                    sampleData.Aqd = 0;
                                }
                                #endregion

                                #region 脚刹
                                if ("1" == dest[7])
                                {
                                    sampleData.Js = 1;
                                }
                                else if ("#" == dest[7])
                                {
                                    sampleData.Js = 9;
                                }
                                else
                                {
                                    sampleData.Js = 0;
                                }
                                #endregion

                                #region 关门
                                if ("1" == dest[13])
                                {
                                    sampleData.Gm = 1;
                                }
                                else if ("#" == dest[13])
                                {
                                    sampleData.Gm = 9;
                                }
                                else
                                {
                                    sampleData.Gm = 0;
                                }
                                #endregion

                                #region 离合
                                if ("1" == dest[6])
                                {
                                    sampleData.Lh = 1;
                                }
                                else if ("#" == dest[6])
                                {
                                    sampleData.Lh = 9;
                                }
                                else
                                {
                                    sampleData.Lh = 0;
                                }
                                #endregion

                                #region 左转向灯
                                if ("1" == dest[14])
                                {
                                    sampleData.Zzxd = 1;
                                }
                                else if ("#" == dest[14])
                                {
                                    sampleData.Zzxd = 9;
                                }
                                else
                                {
                                    sampleData.Zzxd = 0;
                                }
                                #endregion

                                #region 右转向灯
                                if ("1" == dest[15])
                                {
                                    sampleData.Yzxd = 1;
                                }
                                else if ("#" == dest[15])
                                {
                                    sampleData.Yzxd = 9;
                                }
                                else
                                {
                                    sampleData.Yzxd = 0;
                                }
                                #endregion

                                #region 喇叭
                                if ("1" == dest[10])
                                {
                                    sampleData.Lb = 1;
                                }
                                else if ("#" == dest[10])
                                {
                                    sampleData.Lb = 9;
                                }
                                else
                                {
                                    sampleData.Lb = 0;
                                }
                                #endregion

                                #region 近光灯
                                if ("1" == dest[17])
                                {
                                    sampleData.Jgd = 1;
                                }
                                else if ("#" == dest[17])
                                {
                                    sampleData.Jgd = 9;
                                }
                                else
                                {
                                    sampleData.Jgd = 0;
                                }
                                #endregion

                                #region 远光灯
                                if ("1" == dest[18])
                                {
                                    sampleData.Ygd = 1;
                                }
                                else if ("#" == dest[18])
                                {
                                    sampleData.Ygd = 9;
                                }
                                else
                                {
                                    sampleData.Ygd = 0;
                                }
                                #endregion

                                #region 危险告警灯
                                if ("1" == dest[19])
                                {
                                    sampleData.Gjd = 1;
                                }
                                else if ("#" == dest[19])
                                {
                                    sampleData.Gjd = 9;
                                }
                                else
                                {
                                    sampleData.Gjd = 0;
                                }
                                #endregion

                                #region 雾灯
                                if ("1" == dest[20])
                                {
                                    sampleData.Wd = 1;
                                }
                                else if ("#" == dest[20])
                                {
                                    sampleData.Wd = 9;
                                }
                                else
                                {
                                    sampleData.Wd = 0;
                                }
                                #endregion

                                #region 倒车
                                if ("1" == dest[21])
                                {
                                    sampleData.Dc = 1;
                                }
                                else if ("#" == dest[21])
                                {
                                    sampleData.Dc = 9;
                                }
                                else
                                {
                                    sampleData.Dc = 0;
                                }
                                #endregion

                                #region 速度
                                if ("#" == dest[3])
                                {
                                    sampleData.Ycsd = -1;
                                }
                                else
                                {
                                    float fSd = 0;
                                    float.TryParse(dest[3], out fSd);
                                    sampleData.Ycsd = fSd;
                                }
                                #endregion

                                #region 转速
                                if ("#" == dest[2])
                                {
                                    sampleData.Zs = -1;
                                }
                                else
                                {
                                    int nZs = 0;
                                    int.TryParse(dest[2], out nZs);
                                    sampleData.Zs = nZs;
                                }
                                #endregion

                                #region 档位
                                if (BaseDefine.DATA_TYPE_DW_MN == dest[5] || BaseDefine.DATA_TYPE_DW_AN == dest[5])
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_N;
                                }
                                else if (BaseDefine.DATA_TYPE_DW_M1 == dest[5] || BaseDefine.DATA_TYPE_DW_A1 == dest[5])
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_1;
                                }
                                else if (BaseDefine.DATA_TYPE_DW_M2 == dest[5] || BaseDefine.DATA_TYPE_DW_A2 == dest[5])
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_2;
                                }
                                else if (BaseDefine.DATA_TYPE_DW_M3 == dest[5] || BaseDefine.DATA_TYPE_DW_A3 == dest[5])
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_3;
                                }
                                else if (BaseDefine.DATA_TYPE_DW_M4 == dest[5] || BaseDefine.DATA_TYPE_DW_A4 == dest[5])
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_4;
                                }
                                else if (BaseDefine.DATA_TYPE_DW_M5 == dest[5] || BaseDefine.DATA_TYPE_DW_A5 == dest[5])
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_5;
                                }
                                else if (BaseDefine.DATA_TYPE_DW_MR == dest[5] || BaseDefine.DATA_TYPE_DW_AR == dest[5])
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_R;
                                }
                                else if (BaseDefine.DATA_TYPE_DW_AP == dest[5])
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_P;
                                }
                                else if (BaseDefine.DATA_TYPE_DW_AD == dest[5])
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_D;
                                }
                                else
                                {
                                    sampleData.Dw = (byte)DwDefine.DW_OTHER;
                                }
                                #endregion
                            }
                            #endregion
                        }
                    }
                    else if (BaseDefine.DATA_TYPE_OBD_INFO == dest[0])
                    {
                        logger.InfoFormat("dest[0]={0}, continue", BaseDefine.DATA_TYPE_OBD_INFO);
                        continue;
                    }
                    else if (BaseDefine.DATA_TYPE_OBD_IO == dest[0])
                    {
                        if (signalData != null && dest.Length >= signalData.Length + 1)
                        {
                            tempError = string.Empty;
                            for (int j = 0; j < signalData.Length; j++)
                            {
                                string[] tempSz = BaseMethod.SplitString(signalData[j], '@', out tempError);
                                if (tempSz != null && tempSz.Length >= 2)
                                {
                                    #region 从协议取值
                                    lock (lockObj)
                                    {
                                        if ("1" == tempSz[1])
                                        {
                                            if ("1" == tempSz[0])
                                            {
                                                tempSz[0] = "0";
                                            }
                                            else
                                            {
                                                tempSz[0] = "1";
                                            }
                                        }

                                        byte byteTemp;
                                        byte.TryParse(dest[j + 1], out byteTemp);
                                        switch (tempSz[0])
                                        {
                                        case "1":       //安全带
                                            sampleData.Aqd = byteTemp;
                                            break;

                                        case "2":       //左转向灯
                                            sampleData.Zzxd = byteTemp;
                                            break;

                                        case "3":       //右转向灯
                                            sampleData.Yzxd = byteTemp;
                                            break;

                                        case "4":       //熄火
                                            sampleData.Yzxd = byteTemp;
                                            break;

                                        case "5":       //点火
                                            sampleData.Dh = byteTemp;
                                            break;

                                        case "6":       //手刹
                                            sampleData.Ss = byteTemp;
                                            break;

                                        case "7":       //右转向灯
                                            sampleData.Yzxd = byteTemp;
                                            break;

                                        case "8":       //档位??????????????????????????????????????????
                                            sampleData.Dw = byteTemp;
                                            break;

                                        case "9":       //近光灯
                                            sampleData.Jgd = byteTemp;
                                            break;

                                        case "10":       //远光灯
                                            sampleData.Ygd = byteTemp;
                                            break;

                                        case "11":       //脚刹
                                            sampleData.Js = byteTemp;
                                            break;

                                        case "12":       //倒车
                                            sampleData.Dc = byteTemp;
                                            break;

                                        case "13":       //雾灯
                                            sampleData.Wd = byteTemp;
                                            break;

                                        case "14":       //喇叭
                                            sampleData.Lb = byteTemp;
                                            break;

                                        case "15":       //油箱
                                            sampleData.Yx = byteTemp;
                                            break;

                                        case "16":       //副刹
                                            sampleData.Fs = byteTemp;
                                            break;

                                        case "17":       //离合
                                            sampleData.Lh = byteTemp;
                                            break;

                                        case "18":       //危险告警灯
                                            sampleData.Gjd = byteTemp;
                                            break;

                                        case "19":       //示廓灯
                                            sampleData.Skd = byteTemp;
                                            break;

                                        default:
                                            break;
                                        }
                                    }
                                    #endregion
                                }
                            }
                        }
                    }
                }

                Thread.Sleep(BaseDefine.COMMON_VALUE_SLEEP_200);
            }
        }
Esempio n. 4
0
        private void DataHandlerThreadProc()
        {
            string errorMsg = string.Empty;

            //解析车载数据
            string[] retArray = BaseMethod.SplitString(m_data, BaseDefine.SPLIT_CHAR_ASTERISK, out errorMsg);
            if (!string.IsNullOrEmpty(errorMsg))
            {
                goto END;
            }

            int nLength = retArray.Length;

            if (nLength != BaseDefine.INTERFACE_FIELD_COUNT_KM2 &&
                nLength != BaseDefine.INTERFACE_FIELD_COUNT_KM3)
            {
                errorMsg = string.Format("车载数据格式不正确,{0} 数量不对", BaseDefine.SPLIT_CHAR_ASTERISK);
                goto END;
            }

            string strKch  = retArray[1];
            int    nKch    = string.IsNullOrEmpty(strKch) ? 0 : int.Parse(strKch);   //考车号
            string strType = retArray[2];
            int    nType   = string.IsNullOrEmpty(strType) ? 0 : int.Parse(strType); //类型
            string strXmbh = retArray[5];                                            //项目编号
            string strZkzh = retArray[6];                                            //准考证号
            string strTime = retArray[7];                                            //时间

            if (!m_dicCars.ContainsKey(nKch))
            {
                Log.GetLogger().ErrorFormat("找不到考车{0},请检查配置", nKch);
                return;
            }
            Log.GetLogger().InfoFormat(
                "接收到车载接口信息,考车号={0}, 类型={1}, 项目编号={2}, 准考证号={3}, 时间={4}",
                nKch, nType, strXmbh, strZkzh, strTime);

            switch (nType)
            {
            case BaseDefine.PACK_TYPE_M17C51:       //考试开始
            {
                HandleM17C51(nKch, strZkzh);
            }
            break;

            case BaseDefine.PACK_TYPE_M17C52:       //项目开始
            {
                HandleM17C52(nKch, strZkzh, strXmbh);
            }
            break;

            case BaseDefine.PACK_TYPE_M17C53:       //扣分
            {
                HandleM17C53(nKch, strXmbh, strTime);
            }
            break;

            case BaseDefine.PACK_TYPE_M17C54:
            {
                //项目抓拍照片,这里不需要处理
            }
            break;

            case BaseDefine.PACK_TYPE_M17C55:       //项目完成
            {
                HandleM17C55(nKch, strZkzh, strXmbh);
            }
            break;

            case BaseDefine.PACK_TYPE_M17C56:       //考试完成
            {
                string score = retArray[5];         //17C56时该字段为考试成绩
                int    kscj  = string.IsNullOrEmpty(score) ? 0 : int.Parse(score);

                Log.GetLogger().InfoFormat("车载传过来的考试成绩为:{0}", kscj);

                if (kscj < 0)
                {
                    kscj = 0;
                }

                HandleM17C56(nKch, kscj);
            }
            break;

            default:
                break;
            }

END:
            {
                if (!string.IsNullOrEmpty(errorMsg))
                {
                    Log.GetLogger().ErrorFormat("处理车载数据(DataHandlerThreadProc)时产生错误,{0}", errorMsg);
                }
                else
                {
                    Log.GetLogger().InfoFormat("DataHandlerThreadProc 执行结束");
                }
            }

            return;
        }
Esempio n. 5
0
        private bool InitDevices()
        {
            dicCars.Clear();

            //获取 SDK Build
            if (!GetSDKBuildVersion())
            {
                return(false);
            }

            //窗口初始化(看不懂是什么作用,这里先翻译C++代码)
            int    kch   = 0;
            int    count = 4;
            string key   = string.Empty;

            m_dispalyShow[4] = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_DISPLAY, BaseDefine.CONFIG_SECTION_CONFIG,
                                                         BaseDefine.CONFIG_KEY_VIDEOWND, 1);
            for (int i = 0; i < count; i++)
            {
                key = string.Format("{0}{1}", BaseDefine.CONFIG_KEY_DISPLAY, i + 1);
                m_dispalyShow[i] = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_DISPLAY, BaseDefine.CONFIG_SECTION_CONFIG,
                                                             key, i);
                kch += m_dispalyShow[i];
            }
            if (kch != 6)
            {
                for (int i = 0; i < count; i++)
                {
                    key = string.Format("{0}{1}", BaseDefine.CONFIG_KEY_DISPLAY, i + 1);
                    string value = i.ToString();
                    INIOperator.INIWriteValue(BaseDefine.CONFIG_FILE_PATH_DISPLAY, BaseDefine.CONFIG_SECTION_CONFIG, key, value);
                    m_dispalyShow[i] = i;
                }
            }
            Log.GetLogger().InfoFormat("子窗口配置[%d,%d,%d,%d],音频窗口[%d]", m_dispalyShow[0], m_dispalyShow[1],
                                       m_dispalyShow[2], m_dispalyShow[3], m_dispalyShow[4]);

            //合码器初始化
            int nNum = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_CAR, BaseDefine.CONFIG_SECTION_JMQ,
                                                 BaseDefine.CONFIG_KEY_NUM, 0);   //合码器数量
            int nEven = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_DISPLAY, BaseDefine.CONFIG_SECTION_CONFIG,
                                                  BaseDefine.CONFIG_KEY_EVEN, 0); //是否隔行合码
            int nKskm = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_ENV, BaseDefine.CONFIG_SECTION_CONFIG,
                                                  BaseDefine.CONFIG_KEY_KSKM, 0); //考试科目
            int nWnd2 = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_DISPLAY, BaseDefine.CONFIG_SECTION_CONFIG,
                                                  BaseDefine.CONFIG_KEY_WND2, 1); //画面二状态
            int nHMQ = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_ENV, BaseDefine.CONFIG_SECTION_CONFIG,
                                                 BaseDefine.CONFIG_KEY_HMQ, 0);   //配置的是合码器还是解码器

            if (0 == nNum)
            {
                Log.GetLogger().ErrorFormat("合码器数量为0,请检查配置文件");
                return(false);
            }
            Log.GetLogger().InfoFormat("读取到 {0} 台合码器,EVEN = {1}, 科目{2},画面2={3}", nNum, nEven, nKskm, nWnd2);

            string errorMsg = string.Empty;

            for (int i = 1; i <= nNum; i++)
            {
                string strConf = INIOperator.INIGetStringValue(BaseDefine.CONFIG_FILE_PATH_CAR, BaseDefine.CONFIG_SECTION_JMQ,
                                                               i.ToString(), string.Empty);
                string[] confArray = BaseMethod.SplitString(strConf, BaseDefine.SPLIT_CHAR_COMMA, out errorMsg);
                if (!string.IsNullOrEmpty(errorMsg) || confArray.Length != 4)
                {
                    Log.GetLogger().ErrorFormat("合码器配置错误,请检查配置文件。section = {0}, key = {1}", BaseDefine.CONFIG_SECTION_JMQ, i.ToString());
                    return(false);
                }

                string ipAddress = confArray[0]; //合码器地址
                string user      = confArray[1]; //用户名
                string password  = confArray[2]; //密码
                string port      = confArray[3]; //端口
                if (string.IsNullOrEmpty(ipAddress) || string.IsNullOrEmpty(user) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(port))
                {
                    Log.GetLogger().ErrorFormat("合码器配置错误,请检查配置文件。section = {0}, key = {1}", BaseDefine.CONFIG_SECTION_JMQ, i.ToString());
                    return(false);
                }
                Log.GetLogger().InfoFormat("准备对合码器 {0} 进行初始化,ip={1}, port={2}, user={3}, password={4}", i, ipAddress, port, user, password);

                //登录设备
                if (!InitHMQ(ipAddress, user, password, port))
                {
                    return(false);
                }

                int    displayChanCount = (1 == nHMQ) ? m_struDecAbility.struDviInfo.byChanNums : m_struDecAbility.struBncInfo.byChanNums;
                string sectionJMQ       = string.Format("JMQ{0}", i);
                for (int j = 0; j < displayChanCount; j++)   //DVI、BNC 个数循环
                {
                    if ((1 == nEven) && (j % 2 == 1))
                    {
                        continue;
                    }

                    string keyBNC = string.Format("BNC{0}", j + 1); //从 1 开始
                    int    nKch   = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_CAR, sectionJMQ, keyBNC, -1);
                    if (-1 == nKch)                                 //没有配置
                    {
                        Log.GetLogger().InfoFormat("合码器 JMQ{0} 的 BNC 通道 {1} 处于空闲,可以配置。", i, keyBNC);
                        continue;
                    }

                    //检查通道配置及初始化
                    if (1 == nHMQ)
                    {
                        if (!CheckDVIChan(nKch, j)) //合码器
                        {
                            Log.GetLogger().ErrorFormat("通道检测及初始化错误,考车号={0},DVI={1}", nKch, j);
                        }
                    }
                    else
                    {
                        if (!CheckBNCChan(nKch, j)) //解码器
                        {
                            Log.GetLogger().ErrorFormat("通道检测及初始化错误,考车号={0},BNC={1}", nKch, j);
                        }
                    }
                }
            }

            return(true);
        }