public override void OnCommandExecuting(SuperSocket.SocketBase.CommandExecutingContext commandContext) { BLL.DeviceLog bllLog = new DeviceLog(); BLL.Device bllDevice = new Device(); DGNSZSession session = (DGNSZSession)commandContext.Session; DeviceLogInfo log = null; //如果没有设备id,则进行了校时操作。 if (string.IsNullOrEmpty(session.MacID)) { session.Logger.Info("多功能漏损监测仪校时成功!"); byte[] sectionClose = Utility.ApplicationContext.getInstance().getLSSectionCloseConfig(); session.Send(sectionClose, 0, sectionClose.Length); session.Logger.Info("LSSECTION结束帧已经发送!" + BitConverter.ToString(sectionClose)); commandContext.Cancel = true; return; } //设备下发了噪声的默认配置 if (session.NoiseConf == null) { session.Logger.Info("多功能漏损监测仪噪声(" + session.MacID + ")默认配置成功!"); log = new DeviceLogInfo(); log.DEVICE_ID = Convert.ToInt32(bllDevice.getDeviceIdByCode(session.MacID)); log.MESSAGE = "噪声初始化!"; log.OPERATETYPE = "下发"; log.LOGTIME = DateTime.Now; bllLog.insert(log); return; } //设备配置下发 session.Logger.Info("多功能漏损监测仪噪声(" + session.MacID + ")配置成功:" + session.NoiseConf.FrameContent); session.NoiseConf.Status = true; new DeviceConfig().Update(session.NoiseConf); string[] config = session.NoiseConf.FrameContent.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries); string hour1 = byte.Parse(config[9], System.Globalization.NumberStyles.HexNumber).ToString(); string second1 = byte.Parse(config[10], System.Globalization.NumberStyles.HexNumber).ToString(); string interval1 = byte.Parse(config[11], System.Globalization.NumberStyles.HexNumber).ToString(); string count1 = byte.Parse(config[12], System.Globalization.NumberStyles.HexNumber).ToString(); string hour2 = byte.Parse(config[17], System.Globalization.NumberStyles.HexNumber).ToString(); string second2 = byte.Parse(config[18], System.Globalization.NumberStyles.HexNumber).ToString(); string interval2 = byte.Parse(config[19], System.Globalization.NumberStyles.HexNumber).ToString(); log = new DeviceLogInfo(); log.DEVICE_ID = Convert.ToInt32(bllDevice.getDeviceIdByCode(session.MacID)); log.MESSAGE = "噪声配置下发。密集开始时间" + hour1 + ":" + second1 + ";密集间隔" + interval1 + ";密集样本数:" + count1 + ";松散开始时间" + hour2 + ":" + second2 + ";松散间隔:" + interval2; log.OPERATETYPE = "下发"; log.LOGTIME = DateTime.Now; bllLog.insert(log); }
//命令执行后调用 public override void OnCommandExecuted(CommandExecutingContext commandContext) { SZSLNoiseSession session = (SZSLNoiseSession)commandContext.Session; BLL.DeviceLog bllLog = new DeviceLog(); BLL.Device bllDevice = new Device(); Model.DeviceLogInfo log = new Model.DeviceLogInfo(); log.DEVICE_ID = Convert.ToInt32(bllDevice.getDeviceIdByCode(session.MacID)); log.OPERATETYPE = "下发"; log.LOGTIME = DateTime.Now; if (session.Conf != null) { //记录实际下发信息 string content = session.Conf.FrameContent; string[] items = content.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries); byte[] sendData = new byte[items.Length]; for (int i = 0; i < items.Length; i++) { sendData[i] = byte.Parse(items[i], System.Globalization.NumberStyles.HexNumber); } log.MESSAGE = "更新渗漏配置:密集开始时间:" + sendData[4] + ":" + sendData[5] + "样本间隔:" + sendData[6] + "采集个数:" + sendData[7]; } else { //记录默认配置信息 byte[] set = ApplicationContext.getInstance().getDefaultSLConfig(); log.MESSAGE = "更新渗漏配置:密集开始时间:" + set[4] + ":" + set[5] + "样本间隔:" + set[6] + "采集个数:" + set[7]; } bllLog.insert(log); }
public override void OnCommandExecuting(SuperSocket.SocketBase.CommandExecutingContext commandContext) { BLL.DeviceLog bllLog = new DeviceLog(); BLL.Device bllDevice = new Device(); DGNSZSession session = (DGNSZSession)commandContext.Session; Model.DeviceLogInfo log = new Model.DeviceLogInfo(); log.DEVICE_ID = Convert.ToInt32(bllDevice.getDeviceIdByCode(session.MacID)); log.MESSAGE = "压力数据上报"; log.OPERATETYPE = "上报"; log.LOGTIME = DateTime.Now; bllLog.insert(log); }
public override void OnCommandExecuting(SuperSocket.SocketBase.CommandExecutingContext commandContext) { DeviceLog bllLog = new DeviceLog(); Device bllDevice = new Device(); DGNSZSession session = (DGNSZSession)commandContext.Session; DeviceLogInfo log = null; if (session.PressConf != null) { session.Logger.Info("多功能漏损监测仪压力(" + session.MacID + ")配置成功!"); session.PressConf.Status = true; new DeviceConfig().Update(session.PressConf); string[] config = session.PressConf.FrameContent.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries); string interval1 = Int16.Parse(config[8] + config[9], System.Globalization.NumberStyles.HexNumber).ToString(); string interval2 = Int16.Parse(config[10] + config[11], System.Globalization.NumberStyles.HexNumber).ToString(); log = new Model.DeviceLogInfo(); log.DEVICE_ID = Convert.ToInt32(bllDevice.getDeviceIdByCode(session.MacID)); log.MESSAGE = "压力配置下发.采集间隔" + interval1 + ";发送间隔" + interval2; log.OPERATETYPE = "add"; log.LOGTIME = DateTime.Now; bllLog.insert(log); } else { session.Logger.Info("多功能漏损监测仪压力(" + session.MacID + ")默认配置成功!"); log = new Model.DeviceLogInfo(); log.DEVICE_ID = Convert.ToInt32(bllDevice.getDeviceIdByCode(session.MacID)); log.MESSAGE = "压力初始化!"; log.OPERATETYPE = "add"; log.LOGTIME = DateTime.Now; bllLog.insert(log); } }
//命令执行后调用 public override void OnCommandExecuted(CommandExecutingContext commandContext) { SZSLNoiseSession session = (SZSLNoiseSession)commandContext.Session; BLL.DeviceLog bllLog = new DeviceLog(); BLL.Device bllDevice = new Device(); Model.DeviceLogInfo log = new Model.DeviceLogInfo(); log.DEVICE_ID = Convert.ToInt32(bllDevice.getDeviceIdByCode(session.MacID)); log.MESSAGE = "渗漏噪声服务器地址配置:" + ApplicationContext.getInstance().getSLIpConfig(); log.OPERATETYPE = "下发"; log.LOGTIME = DateTime.Now; bllLog.insert(log); }
//命令执行后调用 public override void OnCommandExecuted(CommandExecutingContext commandContext) { BLL.DeviceLog bllLog = new DeviceLog(); BLL.Device bllDevice = new Device(); SZSLNoiseSession session = (SZSLNoiseSession)commandContext.Session; try { Model.DeviceLogInfo log = new Model.DeviceLogInfo(); log.DEVICE_ID = Convert.ToInt32(bllDevice.getDeviceIdByCode(session.MacID)); log.MESSAGE = "渗漏噪声数据上传"; log.OPERATETYPE = "上报"; log.LOGTIME = DateTime.Now; bllLog.insert(log); } catch (Exception e) { commandContext.Session.Logger.Error("设备重启记录保存异常" + e.ToString()); } }
public override void ExecuteCommand(WSSession session, StringRequestInfo requestInfo) { try { //SewPeriodData:设备ID,上传时间,CO数据,O2氧气数据,H2S数据,可燃气体数据\r\n session.Logger.Info("污水数据已经上传!"); session.Logger.Info(requestInfo.Body); string[] bt = requestInfo.Body.Split(','); if (string.IsNullOrEmpty(session.MacID)) { session.MacID = bt[0]; } Model.SewPeriodDataInfo sew = new Model.SewPeriodDataInfo(); sew.DEVID = bt[0]; //转换bt[1] 20131212101010 bug fix by predator string sdate = bt[1].Substring(0, 4) + "-" + bt[1].Substring(4, 2) + "-" + bt[1].Substring(6, 2) + " " + bt[1].Substring(8, 2) + ":" + bt[1].Substring(10, 2) + ":" + bt[1].Substring(12, 2); sew.UPTIME = Convert.ToDateTime(sdate); sew.CO = bt[2]; sew.O2 = bt[3]; sew.H2S = bt[4]; sew.FIREGAS = bt[5]; new BLL.SewPeriodData().insert(sew); //send the time calibrating cmd /* * string sdata = "SewTiming:" + bt[0]+","+DateTime.Now.ToString("yyyyMMddHHmmss"); * byte[] data = new byte[sdata.Length + 2]; * Encoding.ASCII.GetBytes(sdata, 0, sdata.Length, data, 0); * data[sdata.Length] = 0x0D; * data[sdata.Length + 1] = 0x0A; * session.Send(data, 0, data.Length); * */ //send the success cmd; string sdata0 = "SewPeriodData:success"; byte[] data0 = new byte[sdata0.Length + 2]; Encoding.ASCII.GetBytes(sdata0, 0, sdata0.Length, data0, 0); data0[sdata0.Length] = 0x0D; data0[sdata0.Length + 1] = 0x0A; session.Send(data0, 0, data0.Length); //增加设备运行日志 BLL.DeviceLog bllLog = new DeviceLog(); BLL.Device bllDevice = new Device(); Model.DeviceLogInfo log = new Model.DeviceLogInfo(); log.DEVICE_ID = Convert.ToInt32(bllDevice.getDeviceIdByCode(session.MacID)); log.MESSAGE = "污水数据上报"; log.OPERATETYPE = "上报"; log.LOGTIME = DateTime.Now; bllLog.insert(log); } catch (Exception e) { session.Logger.Error("污水数据保存失败!"); session.Logger.Error(e.ToString()); } }
public override void ExecuteCommand(SZLiquidSession session, StringRequestInfo requestInfo) { try { session.Logger.Info("LSSETREQU:液位配置请求帧:" + requestInfo.Body); session.MacID = requestInfo.Parameters[5]; string address = requestInfo.Parameters[3]; byte add0 = byte.Parse(address.Substring(0, 2), System.Globalization.NumberStyles.HexNumber); byte add1 = byte.Parse(address.Substring(2, 2), System.Globalization.NumberStyles.HexNumber); byte add2 = byte.Parse(address.Substring(4, 2), System.Globalization.NumberStyles.HexNumber); byte ss = byte.Parse(DateTime.Now.ToString("yy")); byte ss1 = byte.Parse(DateTime.Now.ToString("MM")); byte ss2 = byte.Parse(DateTime.Now.ToString("dd")); byte ss3 = byte.Parse(DateTime.Now.ToString("HH")); byte ss4 = byte.Parse(DateTime.Now.ToString("mm")); byte ss5 = byte.Parse(DateTime.Now.ToString("ss")); byte ss7 = byte.Parse("0" + ((int)DateTime.Now.DayOfWeek).ToString()); BLL.DeviceLog bllLog = new DeviceLog(); BLL.Device bllDevice = new Device(); DeviceConfigInfo conf; conf = (new DeviceConfig()).GetDeviceConfByDeviceCodeAndSensorCode(session.MacID, "000034"); if (conf != null) { //状态传感配置信息 //50# 00#14 #01 #00#00#34# C1 #00#05 #00#00#00#00 #1.23 #2D#17#0F#04#0F#0A#0F#03# string content = conf.FrameContent; string[] items = content.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries); //byte[] sendData = new byte[items.Length]; byte[] sendData = new byte[26];//固定26字节 //for (int i = 0; i < items.Length; i++) for (int i = 0; i < 10; i++) { sendData[i] = byte.Parse(items[i], System.Globalization.NumberStyles.HexNumber); } //TODO LIST:修正液位警界高度、探头安装高度、当前时间 BLL.DjLiquid djBll = new BLL.DjLiquid(); AlarmRuleInfo rule = djBll.getAlarmRuleByDevcode(session.MacID); float highValue = rule != null ? rule.HighValue : 1000; byte[] btHighValue = BitConverter.GetBytes(highValue); sendData[10 + 0] = btHighValue[0]; sendData[10 + 1] = btHighValue[1]; sendData[10 + 2] = btHighValue[2]; sendData[10 + 3] = btHighValue[3]; float height = float.Parse(items[14]); byte[] btHeight = BitConverter.GetBytes(height); sendData[14 + 0] = btHeight[0]; sendData[14 + 1] = btHeight[1]; sendData[14 + 2] = btHeight[2]; sendData[14 + 3] = btHeight[3]; if (requestInfo.Parameters[0] == "50") { //液位时间修正 sendData[18] = ss5; sendData[19] = ss4; sendData[20] = ss3; sendData[21] = ss7; sendData[22] = ss2; sendData[23] = ss1; sendData[24] = ss; sendData[25] = 0x03; } string head = "LSSETREQU:"; byte[] btHead = System.Text.Encoding.Default.GetBytes(head); byte[] result = new byte[sendData.Length + btHead.Length]; Buffer.BlockCopy(btHead, 0, result, 0, btHead.Length); Buffer.BlockCopy(sendData, 0, result, btHead.Length, sendData.Length); session.Send(result, 0, result.Length); // /* * String crcIn = ""; * for (int i = 0; i < sendData.Length; i++) * { * crcIn += sendData[i].ToString("X2"); * } * ushort crcOut = CodeUtils.QuickCRC16(crcIn, 0, crcIn.Length); * byte[] crcOutByte = BitConverter.GetBytes(crcOut); * sendData[7] = crcOutByte[1]; * sendData[8] = crcOutByte[0]; * **/ session.Logger.Info("成功下发液位配置帧:" + BitConverter.ToString(result)); session.LiquidConf = conf; session.LiquidConf.SendTime = DateTime.Now; Model.DeviceLogInfo log = new Model.DeviceLogInfo(); log.DEVICE_ID = Convert.ToInt32(bllDevice.getDeviceIdByCode(session.MacID)); log.MESSAGE = "液位数据配置:采集间隔:" + sendData[9] + "分钟"; log.OPERATETYPE = "下发"; log.LOGTIME = DateTime.Now; bllLog.insert(log); return; } //无配置信息处理发送校时帧 byte[] setTime = { 0x50, 0x00, 0x14, 0x01, 0x00, 0x00, 0x34, 0xC2, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ss5, ss4, ss3, ss7, ss2, ss1, ss, 0x03 }; string head0 = "LSSETREQU:"; byte[] btHead0 = System.Text.Encoding.Default.GetBytes(head0); byte[] result0 = new byte[setTime.Length + btHead0.Length]; Buffer.BlockCopy(btHead0, 0, result0, 0, btHead0.Length); Buffer.BlockCopy(setTime, 0, result0, btHead0.Length, setTime.Length); session.Send(result0, 0, result0.Length); session.Logger.Info("成功下发液位计校时帧:" + BitConverter.ToString(result0, 0)); } catch (Exception e) { session.Logger.Error(e.ToString()); } }
public override void ExecuteCommand(SZLiquidSession session, StringRequestInfo requestInfo) { try { session.Logger.Info("LSLEVDATA:液位监测仪器:" + requestInfo.Body); //采集时间 string year = (Int32.Parse(requestInfo.Parameters[9].Substring(8, 2), System.Globalization.NumberStyles.HexNumber) + 2000).ToString(); string mon = Int32.Parse(requestInfo.Parameters[9].Substring(6, 2), System.Globalization.NumberStyles.HexNumber).ToString(); string day = Int32.Parse(requestInfo.Parameters[9].Substring(4, 2), System.Globalization.NumberStyles.HexNumber).ToString(); string hor = Int32.Parse(requestInfo.Parameters[9].Substring(2, 2), System.Globalization.NumberStyles.HexNumber).ToString(); string min = Int32.Parse(requestInfo.Parameters[9].Substring(0, 2), System.Globalization.NumberStyles.HexNumber).ToString(); DateTime upTime = Convert.ToDateTime(year + "-" + mon + "-" + day + " " + hor + ":" + min + ":00"); session.MacID = requestInfo.Parameters[5]; string cfg = requestInfo.Parameters[6]; string ldata = requestInfo.Parameters[10]; BLL.DeviceLog bllLog = new DeviceLog(); BLL.Device bllDevice = new Device(); Model.DeviceLogInfo log = new Model.DeviceLogInfo(); log.DEVICE_ID = Convert.ToInt32(bllDevice.getDeviceIdByCode(session.MacID)); log.MESSAGE = "液位数据上传"; log.OPERATETYPE = "上报"; log.LOGTIME = DateTime.Now; bllLog.insert(log); //采集个数 int count = Int16.Parse(requestInfo.Parameters[8], System.Globalization.NumberStyles.HexNumber); int isAlarm = Int16.Parse(requestInfo.Parameters[7], System.Globalization.NumberStyles.HexNumber); List <Model.DjLiquidInfo> djs = new List <DjLiquidInfo>(); List <Model.DjLiquidInfo> alarmDjs = new List <DjLiquidInfo>(); for (int i = 0; i < count; i++) { Model.DjLiquidInfo dj = new DjLiquidInfo(); //设备ID dj.DEVID = session.MacID; //液位数据 string lStr = ldata.Substring(i * 8, 8); byte[] lBt = { byte.Parse(lStr.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), byte.Parse(lStr.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), byte.Parse(lStr.Substring(4, 2), System.Globalization.NumberStyles.HexNumber), byte.Parse(lStr.Substring(6, 2), System.Globalization.NumberStyles.HexNumber) }; float liquidData = verifyLiquidData(BitConverter.ToSingle(lBt, 0), session.MacID, session); dj.LIQUIDDATA = liquidData.ToString(); //电池电量 dj.CELL = Int16.Parse(requestInfo.Parameters[11], System.Globalization.NumberStyles.HexNumber).ToString(); //采集时间 dj.UPTIME = upTime; //记录时间 dj.LOGTIME = DateTime.Now; djs.Add(dj); upTime = upTime.AddMinutes(60); //如果存在报警 if (isAlarm == 1) { alarmDjs.Add(dj); } } new BLL.DjLiquid().insert(djs); new BLL.DjLiquid().saveSZAlarmInfo(alarmDjs); // new BLL.DjLiquid().updateDevStatus(session.MacID); session.Logger.Info("液位监测仪器:" + session.MacID + "液位数据已经保存! "); //TODO LIST:下发上传数据返回帧 byte[] asck = { 0x50, 0x00, 0x09, 0x02, 0x00, 0x00, 0x34, 0x22, 0x03 }; string head = "LSLEVDATA:"; byte[] btHead = System.Text.Encoding.Default.GetBytes(head); byte[] result = new byte[asck.Length + btHead.Length]; Buffer.BlockCopy(btHead, 0, result, 0, btHead.Length); Buffer.BlockCopy(asck, 0, result, btHead.Length, asck.Length); session.Send(result, 0, result.Length); } catch (Exception e) { session.Logger.Error("液位数据已经保存失败" + requestInfo.Body); session.Logger.Error(e.ToString()); } finally { } }