Ejemplo n.º 1
0
        /**
         * 发送203所自研设备:渗漏预警仪、液位监测仪、井盖传感器的配置信息
         * **/
        private bool sendCasicConfig(DeviceDTO dto, Dictionary <String, String> settings)
        {
            //判断设备是否已经唤醒
            //TODO LIST:获取会话信息,发送数据

            /*
             * var server0 = bootstrap.GetServerByName(CASIC_SERVER_NAME);
             * CasicServer casicServer0 = server0 as CasicServer;
             * CasicSession session0 = casicServer0.GetSessionByID(dto.SessionId) as CasicSession;
             * CasicSession.DeviceDTO dev = session0.devMaps[dto.Name];
             * if (!dev.IsWakeUp && dev.DevType!="集中器")
             * {
             *  return false;
             * }
             * */

            String[] parameters = dto.Tag.Split(',');

            //TODO: construct the receving casic data
            String preamble   = parameters[0];
            byte   btpreamble = byte.Parse(preamble, System.Globalization.NumberStyles.HexNumber);

            String version   = parameters[1];
            byte   btVersion = byte.Parse(version, System.Globalization.NumberStyles.HexNumber);

            String deviceId = parameters[3];//6个字节

            byte[] btDevId = new byte[6];
            btDevId[0] = byte.Parse(deviceId.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
            btDevId[1] = byte.Parse(deviceId.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
            btDevId[2] = byte.Parse(deviceId.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
            btDevId[3] = byte.Parse(deviceId.Substring(6, 2), System.Globalization.NumberStyles.HexNumber);
            btDevId[4] = byte.Parse(deviceId.Substring(8, 2), System.Globalization.NumberStyles.HexNumber);
            btDevId[5] = byte.Parse(deviceId.Substring(10, 2), System.Globalization.NumberStyles.HexNumber);

            String routeFlag   = parameters[4];
            byte   btRouteFlag = byte.Parse(routeFlag, System.Globalization.NumberStyles.HexNumber);

            String dstNodeAddr = parameters[5];//2个字节

            byte[] btDstNode = new byte[2];
            btDstNode[0] = byte.Parse(dstNodeAddr.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
            btDstNode[1] = byte.Parse(dstNodeAddr.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);

            String seq   = parameters[7];
            byte   btSeq = byte.Parse(seq, System.Globalization.NumberStyles.HexNumber);

            byte[] btPdu = new byte[2];; //2个字节
            byte[] tag   = null;

            switch (dto.TypeName)
            {
            case "渗漏预警仪":
                btPdu[0] = 0x03;
                btPdu[1] = 0x82;
                tag      = this.getNosieTag(settings);
                break;

            case "液位监测仪":
                btPdu[0] = 0x03;
                btPdu[1] = 0x87;
                tag      = this.getYWTag(settings);
                break;

            case "集中器":
                btPdu[0] = 0x03;
                btPdu[1] = 0x85;
                tag      = this.getHubTag(settings);
                break;

            case "温度压力监测仪":
                btPdu[0] = 0x03;
                btPdu[1] = 0x88;
                tag      = this.getTempTag(settings);
                break;

            /*
             * case "压力计":
             * btPdu[0] = 0x03;
             * btPdu[1] = 0x89;
             * tag = this.getPressTag(settings);
             * break;
             * */
            case "远传水表":
                btPdu[0] = 0x03;
                btPdu[1] = 0x8A;
                tag      = this.getWaterMeterTag(settings);
                break;

            case "井盖传感器":
                btPdu[0] = 0x03;
                btPdu[1] = 0x86;
                break;

            default:
                break;
            }

            int totalLen = 6 + 1 + 2 + 2 + 1 + tag.Length;

            byte[] btLens  = new byte[2];
            byte[] btlens0 = BitConverter.GetBytes(totalLen);
            btLens[0] = btlens0[1];
            btLens[1] = btlens0[0];

            //wrap the whole data
            byte[] result = new byte[1 + 1 + 2 + 6 + 1 + 2 + 2 + 1 + tag.Length];
            result[0] = btpreamble;
            result[1] = btVersion;
            btLens.CopyTo(result, 2);
            btDevId.CopyTo(result, 4);
            result[10] = btRouteFlag;
            btDstNode.CopyTo(result, 11);
            btPdu.CopyTo(result, 13);
            result[15] = btSeq;
            tag.CopyTo(result, 16);


            //  session.Logger.Info("CRC校验前数据:" + BitConverter.ToString(result));

            //增加CRC校验
            String strCrc = StringUtil.To16HexString(String.Format("{0:X}", (int)CodeUtils.CRC16_AD(result)));

            byte[] btcrc = { CodeUtils.String2Byte(strCrc.Substring(0, 2)), CodeUtils.String2Byte(strCrc.Substring(2, 2)) };
            byte[] afcrc = new byte[result.Length + 2];
            result.CopyTo(afcrc, 0);
            btcrc.CopyTo(afcrc, result.Length);

            //TODO LIST:获取会话信息,发送数据
            var          server      = bootstrap.GetServerByName(CASIC_SERVER_NAME);
            CasicServer  casicServer = server as CasicServer;
            CasicSession session     = casicServer.GetSessionByID(dto.SessionId) as CasicSession;

            session.Logger.Info("手动下发渗漏噪声配置信息:" + BitConverter.ToString(afcrc));
            session.Send(afcrc, 0, afcrc.Length);
            return(true);
        }
Ejemplo n.º 2
0
        public void wakeUpCasicDev(DeviceDTO dto)
        {
            //判断当前是够已经唤醒,如果已经唤醒则不再下发配置信息
            //判断设备是否已经唤醒
            //TODO LIST:获取会话信息,发送数据
            var          server0      = bootstrap.GetServerByName(CASIC_SERVER_NAME);
            CasicServer  casicServer0 = server0 as CasicServer;
            CasicSession session0     = casicServer0.GetSessionByID(dto.SessionId) as CasicSession;

            CasicSession.DeviceDTO dev = session0.devMaps[dto.Name];
            if (dev.IsWakeUp || dev.DevType == "集中器")
            {
                return;
            }

            String[] parameters = dto.Tag.Split(',');

            //TODO: construct the receving casic data
            String preamble   = parameters[0];
            byte   btpreamble = byte.Parse(preamble, System.Globalization.NumberStyles.HexNumber);

            String version   = parameters[1];
            byte   btVersion = byte.Parse(version, System.Globalization.NumberStyles.HexNumber);

            String deviceId = parameters[3];//6个字节

            byte[] btDevId = new byte[6];
            btDevId[0] = byte.Parse(deviceId.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
            btDevId[1] = byte.Parse(deviceId.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
            btDevId[2] = byte.Parse(deviceId.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
            btDevId[3] = byte.Parse(deviceId.Substring(6, 2), System.Globalization.NumberStyles.HexNumber);
            btDevId[4] = byte.Parse(deviceId.Substring(8, 2), System.Globalization.NumberStyles.HexNumber);
            btDevId[5] = byte.Parse(deviceId.Substring(10, 2), System.Globalization.NumberStyles.HexNumber);

            String routeFlag   = parameters[4];
            byte   btRouteFlag = byte.Parse(routeFlag, System.Globalization.NumberStyles.HexNumber);

            String dstNodeAddr = parameters[5];//2个字节

            byte[] btDstNode = new byte[2];
            btDstNode[0] = byte.Parse(dstNodeAddr.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
            btDstNode[1] = byte.Parse(dstNodeAddr.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);

            String sPtuType  = parameters[6];//2个字节
            Int16  btpduType = Int16.Parse(sPtuType, System.Globalization.NumberStyles.HexNumber);
            Int16  opearType = (Int16)(btpduType & 0x7F);
            Int16  pdu       = (Int16)(2688 + opearType); //0X0A80

            byte[] btPdu0 = BitConverter.GetBytes(pdu);
            byte[] btPdu  = { btPdu0[1], btPdu0[0] };

            //  btDstNode[0] = byte.Parse(dstNodeAddr.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
            //  btDstNode[1] = byte.Parse(dstNodeAddr.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);

            String seq   = parameters[7];
            byte   btSeq = byte.Parse(seq, System.Globalization.NumberStyles.HexNumber);

            byte[] tag = { 0x60, 0x00, 0x02, 0x00, 0x00, 0x01, 0x00 };

            byte[] totoalLen = { 0x00, 0x13 };

            //wrap the whole data
            byte[] result = new byte[1 + 1 + 2 + 6 + 1 + 2 + 2 + 1 + 7];
            result[0] = btpreamble;
            result[1] = btVersion;
            totoalLen.CopyTo(result, 2);
            btDevId.CopyTo(result, 4);
            result[10] = btRouteFlag;
            btDstNode.CopyTo(result, 11);
            btPdu.CopyTo(result, 13);
            result[15] = btSeq;
            tag.CopyTo(result, 16);

            //增加CRC校验
            String strCrc = StringUtil.To16HexString(String.Format("{0:X}", (int)CodeUtils.CRC16_AD(result)));

            byte[] btcrc = { CodeUtils.String2Byte(strCrc.Substring(0, 2)), CodeUtils.String2Byte(strCrc.Substring(2, 2)) };
            byte[] afcrc = new byte[result.Length + 2];
            result.CopyTo(afcrc, 0);
            btcrc.CopyTo(afcrc, result.Length);

            //TODO LIST:获取会话信息,发送数据
            var          server      = bootstrap.GetServerByName(CASIC_SERVER_NAME);
            CasicServer  casicServer = server as CasicServer;
            CasicSession session     = casicServer.GetSessionByID(dto.SessionId) as CasicSession;

            session.Logger.Info("下发唤醒信息:" + "设备编号:" + deviceId + "" + BitConverter.ToString(afcrc));
            session.Send(afcrc, 0, afcrc.Length);
        }