예제 #1
0
        /// <summary>
        /// 泊位状态检测事件(设备上传)
        /// </summary>
        /// <param name="deviceNo">设备编号</param>
        /// <param name="reviceMsg">泊位状态检测数据帧</param>
        /// <param name="remotePoint">数据来源的IP地址及端口</param>
        /// <returns></returns>
        public async Task DeviceStateChange(string deviceNo, string reviceMsg, IPEndPoint remotePoint)
        {
            try
            {
                string[] szCommand = reviceMsg.Split(',');
                string   tstamp    = szCommand[4]; //时间戳
                string   seqno     = szCommand[5]; //帧序号(设备入网请求、泊位状态检测事件、设备心跳=》以上命令中才存在帧序号)

                //查询设备是否存在,存在则更新设备状态
                var modelInfo = await _deviceInfo.FirstOrDefaultAsync(d => d.DeviceNo == deviceNo);

                if (modelInfo != null)
                {
                    //获取消息部分内容
                    string   message = GetMsgContent(reviceMsg);
                    string[] szMsg   = message.Split(',');
                    //更新数据库设备信息
                    modelInfo.MagStatus        = int.Parse(szMsg[1]);
                    modelInfo.RadaStatus       = int.Parse(szMsg[2]);
                    modelInfo.SynStatus        = int.Parse(szMsg[3]);
                    modelInfo.NbSignal         = szMsg[4];
                    modelInfo.Temperature      = int.Parse(szMsg[5]);
                    modelInfo.MagneticXYZ      = string.Format("{0},{1},{2}", szMsg[6], szMsg[7], szMsg[8]);
                    modelInfo.RadarXYZ         = string.Format("{0},{1},{2}", szMsg[9], szMsg[10], szMsg[11]);
                    modelInfo.Distance         = int.Parse(szMsg[12]);
                    modelInfo.BatVoltage       = szMsg[13];
                    modelInfo.FwVer            = szMsg[14];
                    modelInfo.HwVer            = szMsg[15];
                    modelInfo.DevHealth        = int.Parse(szMsg[16]);
                    modelInfo.healthT          = int.Parse(szMsg[17]);
                    modelInfo.DeviceStatus     = 1;
                    modelInfo.StatusUpdateTime = DateTime.Now;
                    //更新设备信息
                    await _deviceInfo.UpdateAsync(modelInfo);
                }
                //回复指令
                string command = SendCommands.RStateDetection(deviceNo, tstamp, seqno);
                bool   bRet    = UdpCommunication.UpdSendMessage(command, remotePoint);
                if (bRet)
                {
                    //更新指令回复信息
                    var cmdModel = await _commandLog.FirstOrDefaultAsync(c => c.DeviceNo == deviceNo && c.Tstamp == tstamp);

                    if (cmdModel != null)
                    {
                        string rMsg = GetMsgContent(command);
                        cmdModel.ResultMessage = rMsg;
                        cmdModel.CmdStatus     = 2;
                        await _commandLog.UpdateAsync(cmdModel);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
            }
        }
예제 #2
0
        /// <summary>
        /// 设备请求入网(设备上传)
        /// </summary>
        /// <param name="deviceNo">设备编号</param>
        /// <param name="reviceMsg">请求入网帧</param>
        /// <param name="remotePoint">数据来源的IP地址及端口</param>
        /// <returns></returns>
        public async Task AccessNetwork(string deviceNo, string reviceMsg, IPEndPoint remotePoint)
        {
            try
            {
                string[] szCommand = reviceMsg.Split(',');
                string   tstamp    = szCommand[4]; //时间戳
                string   seqno     = szCommand[5]; //帧序号(设备入网请求、泊位状态检测事件、设备心跳=》以上命令中才存在帧序号)
                //回复指令
                string command = "";
                //查询设备是否注册,如果未注册则请求入网失败
                var modelInfo = await _deviceInfo.FirstOrDefaultAsync(d => d.DeviceNo == deviceNo);

                if (modelInfo == null)
                {
                    command = SendCommands.RAccessNetwork(deviceNo, tstamp, seqno, false);
                }
                else
                {
                    //获取消息部分内容
                    string   message = GetMsgContent(reviceMsg);
                    string[] szMsg   = message.Split(',');
                    //更新数据库设备信息
                    modelInfo.NbSignal         = szMsg[1];
                    modelInfo.DevHealth        = int.Parse(szMsg[2]);
                    modelInfo.BatVoltage       = szMsg[3];
                    modelInfo.FwVer            = szMsg[4];
                    modelInfo.HwVer            = szMsg[5];
                    modelInfo.healthT          = int.Parse(szMsg[6]);
                    modelInfo.DeviceStatus     = 1;
                    modelInfo.StatusUpdateTime = DateTime.Now;
                    //更新设备信息
                    await _deviceInfo.UpdateAsync(modelInfo);

                    //获取回复指令
                    command = SendCommands.RAccessNetwork(deviceNo, tstamp, seqno, true);
                }
                bool bRet = UdpCommunication.UpdSendMessage(command, remotePoint);
                if (bRet)
                {
                    //更新指令回复信息
                    var cmdModel = await _commandLog.FirstOrDefaultAsync(c => c.DeviceNo == deviceNo && c.Tstamp == tstamp);

                    if (cmdModel != null)
                    {
                        string rMsg = GetMsgContent(command);
                        cmdModel.ResultMessage = rMsg;
                        cmdModel.CmdStatus     = 2;
                        await _commandLog.UpdateAsync(cmdModel);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
            }
        }
예제 #3
0
        /// <summary>
        /// 传感器波动数据(设备上传)
        /// </summary>
        /// <param name="deviceNo">设备编号</param>
        /// <param name="reviceMsg">传感器波动数据帧</param>
        /// <param name="remotePoint">数据来源的IP地址及端口</param>
        /// <returns></returns>
        public async Task SensorFluctuation(string deviceNo, string reviceMsg, IPEndPoint remotePoint)
        {
            try
            {
                string[] szCommand = reviceMsg.Split(',');
                string   tstamp    = szCommand[4]; //时间戳

                //查询设备是否存在,存在则更新设备状态
                var modelInfo = await _deviceInfo.FirstOrDefaultAsync(d => d.DeviceNo == deviceNo);

                if (modelInfo != null)
                {
                    //获取消息部分内容
                    string   message = GetMsgContent(reviceMsg);
                    string[] szMsg   = message.Split(',');

                    SensorWave_Log model = new SensorWave_Log
                    {
                        DeviceNo     = deviceNo,
                        Tstamp       = tstamp,
                        Magnetic10   = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", szMsg[0], szMsg[1], szMsg[2], szMsg[3], szMsg[4], szMsg[5], szMsg[6], szMsg[7], szMsg[8], szMsg[9]),
                        MagneticXYZ  = string.Format("{0},{1},{2}", szMsg[10], szMsg[11], szMsg[12]),
                        SmoothXYZ    = string.Format("{0},{1},{2}", szMsg[13], szMsg[14], szMsg[15]),
                        RadarDataXYZ = string.Format("{0},{1},{2}", szMsg[16], szMsg[17], szMsg[18]),
                        Distance     = int.Parse(szMsg[19]),
                        BerthStatus  = int.Parse(szMsg[20]),
                        AddTime      = DateTime.Now
                    };
                    await _sensorWaveLog.InsertAsync(model);
                }
                //回复指令
                string command = SendCommands.RSensorFluctuation(deviceNo, tstamp);
                bool   bRet    = UdpCommunication.UpdSendMessage(command, remotePoint);
                if (bRet)
                {
                    //更新指令回复信息
                    var cmdModel = await _commandLog.FirstOrDefaultAsync(c => c.DeviceNo == deviceNo && c.Tstamp == tstamp);

                    if (cmdModel != null)
                    {
                        string rMsg = GetMsgContent(command);
                        cmdModel.ResultMessage = rMsg;
                        cmdModel.CmdStatus     = 2;
                        await _commandLog.UpdateAsync(cmdModel);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
            }
        }
예제 #4
0
        /// <summary>
        /// 自检测异常报警数据(设备上传)
        /// </summary>
        /// <param name="deviceNo">设备编号</param>
        /// <param name="reviceMsg">自检测异常报警数据帧</param>
        /// <param name="remotePoint">数据来源的IP地址及端口</param>
        /// <returns></returns>
        public async Task SelfCheckingAlarm(string deviceNo, string reviceMsg, IPEndPoint remotePoint)
        {
            try
            {
                string[] szCommand = reviceMsg.Split(',');
                string   tstamp    = szCommand[4]; //时间戳

                //查询设备是否存在,存在则更新设备状态
                var modelInfo = await _deviceInfo.FirstOrDefaultAsync(d => d.DeviceNo == deviceNo);

                if (modelInfo != null)
                {
                    //获取消息部分内容
                    string   message = GetMsgContent(reviceMsg);
                    string[] szMsg   = message.Split(',');

                    //更新设备报警数据
                    modelInfo.NbSignalCode     = int.Parse(szMsg[0]);
                    modelInfo.SensorCode       = int.Parse(szMsg[1]);
                    modelInfo.FlashCode        = int.Parse(szMsg[2]);
                    modelInfo.BatteryCode      = int.Parse(szMsg[3]);
                    modelInfo.StatusUpdateTime = DateTime.Now;

                    await _deviceInfo.UpdateAsync(modelInfo);
                }
                //回复指令
                string command = SendCommands.RSelfCheckingAlarm(deviceNo, tstamp);
                bool   bRet    = UdpCommunication.UpdSendMessage(command, remotePoint);
                if (bRet)
                {
                    //更新指令回复信息
                    var cmdModel = await _commandLog.FirstOrDefaultAsync(c => c.DeviceNo == deviceNo && c.Tstamp == tstamp);

                    if (cmdModel != null)
                    {
                        string rMsg = GetMsgContent(command);
                        cmdModel.ResultMessage = rMsg;
                        cmdModel.CmdStatus     = 2;
                        await _commandLog.UpdateAsync(cmdModel);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
            }
        }
예제 #5
0
        /// <summary>
        /// 设备心跳(设备上传)
        /// </summary>
        /// <param name="deviceNo">设备编号</param>
        /// <param name="reviceMsg">设备心跳数据帧</param>
        /// <param name="remotePoint">数据来源的IP地址及端口</param>
        /// <returns></returns>
        public async Task DeviceHeartbeat(string deviceNo, string reviceMsg, IPEndPoint remotePoint)
        {
            try
            {
                string[] szCommand = reviceMsg.Split(',');
                string   tstamp    = szCommand[4]; //时间戳
                string   seqno     = szCommand[5]; //帧序号(设备入网请求、泊位状态检测事件、设备心跳=》以上命令中才存在帧序号)

                //查询设备是否存在,存在则更新设备状态
                var modelInfo = await _deviceInfo.FirstOrDefaultAsync(d => d.DeviceNo == deviceNo);

                if (modelInfo != null)
                {
                    //获取消息部分内容
                    string   message = GetMsgContent(reviceMsg);
                    string[] szMsg   = message.Split(',');
                    //如果设备存在则插入设备心跳记录
                    Heartbeat_Log model = new Heartbeat_Log
                    {
                        DeviceNo    = deviceNo,
                        Tstamp      = tstamp,
                        DeviceState = int.Parse(szMsg[1]),
                        NbSignal    = szMsg[2],
                        Temperature = int.Parse(szMsg[3]),
                        BatVoltage  = szMsg[4],
                        FwVer       = szMsg[5],
                        HwVer       = szMsg[6],
                        DevHealth   = int.Parse(szMsg[7]),
                        HbeatT      = int.Parse(szMsg[8]),
                        NbSendN     = int.Parse(szMsg[9]),
                        BbRecvN     = int.Parse(szMsg[10]),
                        SampleN     = int.Parse(szMsg[11]),
                        RebootN     = int.Parse(szMsg[12]),
                        NbRebootN   = int.Parse(szMsg[13]),
                        NoackN      = int.Parse(szMsg[14]),
                        AddTime     = DateTime.Now
                    };
                    await _heartBeatLog.InsertAsync(model);

                    //更新设备信息
                    modelInfo.DeviceStatus     = 1;
                    modelInfo.NbSignal         = szMsg[2];
                    modelInfo.Temperature      = int.Parse(szMsg[3]);
                    modelInfo.BatVoltage       = szMsg[4];
                    modelInfo.FwVer            = szMsg[5];
                    modelInfo.HwVer            = szMsg[6];
                    modelInfo.DevHealth        = int.Parse(szMsg[7]);
                    modelInfo.healthT          = int.Parse(szMsg[8]);
                    modelInfo.StatusUpdateTime = DateTime.Now;
                    await _deviceInfo.UpdateAsync(modelInfo);
                }
                //回复指令
                string command = SendCommands.RDeviceHeartbeat(deviceNo, tstamp, seqno);
                bool   bRet    = UdpCommunication.UpdSendMessage(command, remotePoint);
                if (bRet)
                {
                    //更新指令回复信息
                    var cmdModel = await _commandLog.FirstOrDefaultAsync(c => c.DeviceNo == deviceNo && c.Tstamp == tstamp && c.CommandType == szCommand[3]);

                    if (cmdModel != null)
                    {
                        string rMsg = GetMsgContent(command);
                        cmdModel.ResultMessage = rMsg;
                        cmdModel.CmdStatus     = 2;
                        await _commandLog.UpdateAsync(cmdModel);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
            }
        }